【发布时间】:2017-05-29 01:38:08
【问题描述】:
我在 Ubuntu 上使用 Mono。
在过去的某个时候(当我使用股票时,来自 Ubuntu 存储库的古老 monodevelop),以下方法有效:
sn -k mykey.snk- 在.csproj中,将
<AssemblyOriginatorKeyFile>设置为上面的.snk - 在同一个.csproj中,将
<SignAssembly>设置为true - 在运行时,通过模仿 the Mono sn tool 使用此源来自我验证 .exe:
private static bool IsStrongNameSigned(string fileName)
{
// For details see
// https://github.com/mono/mono/blob/master/mcs/tools/security/sn.cs
const int keySize = 12, blobSize = 148;
var an = AssemblyName.GetAssemblyName(fileName);
byte[] publicKey = an.GetPublicKey();
if (publicKey == null ||
publicKey.Length < keySize + blobSize)
return false;
using (RSA rsa = CryptoConvert.FromCapiPublicKeyBlob(
blob: publicKey, offset: keySize))
{
var sn = new StrongName(rsa);
return sn.Verify(fileName);
}
}
现在,如果我尝试上述操作,sn.Verify() 会返回 false,即使项目已明确被告知要在构建上签名。
失败的代码在 Mono.Security 中:
$ dpkg -S /usr/lib/mono/4.5-api/Mono.Security.dll
mono-devel: /usr/lib/mono/4.5-api/Mono.Security.dll
$ apt-cache show mono-devel
Package: mono-devel
Source: mono
Version: 5.0.1.1-0xamarin5+debian7b1
Architecture: all
Maintainer: Debian Mono Group <pkg-mono-group@lists.alioth.debian.org>
Installed-Size: 75560
...
经过调试,似乎具体的故障点在StrongHash。确实读取了签名,但它由一个 128 字节的全零数组组成。
我可以确认 MonoDevelop 7.1 IDE 告诉 csc 使用密钥;注意/publicsign+ 和/keyfile 的存在:
/usr/lib/mono/4.5/csc.exe /noconfig /nowarn:1701,1702,2008
/nostdlib+ /platform:anycpu32bitpreferred
/errorreport:prompt /warn:4 /define:DEBUG /errorendlocation
/preferreduilang:en-CA /highentropyva+ /reference:...\
/debug+ /debug:portable
/keyfile:/home/....snk /optimize- /out:....exe
/subsystemversion:6.00 /resource:gtk-gui/gui.stetic,gui.stetic
/target:exe /utf8output /publicsign+ ....cs
我的问题是:
- Mono 中的哪些变化现在阻止了这种方法的工作?
- 是否有更好的方法来验证程序集?
- 是构建未能对程序集进行签名,还是验证码未能找到签名?是否有一些单独的工具可以确认是哪种情况?
【问题讨论】:
标签: xamarin mono strongname