// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2006,2008 Novell, Inc (http://www.novell.com)
//
using System;
return new StrongName (data).RSA;
}
catch {
- if (data [0] != 0x30)
+ if (data.Length == 0 || data [0] != 0x30)
throw;
// this could be a PFX file
Console.Write ("Enter password for private key (will be visible when typed): ");
return false;
}
#endif
- static bool ReSign (string assemblyName, RSA key)
+ static bool ReSign (string assemblyName, RSA key, bool quiet)
{
// this doesn't load the assembly (well it unloads it ;)
// http://weblogs.asp.net/nunitaddin/posts/9991.aspx
if (same) {
bool signed = sign.Sign (assemblyName);
- Console.WriteLine (signed ? "Assembly {0} signed." : "Couldn't sign the assembly {0}.",
- assemblyName);
+ if (!quiet || !signed) {
+ Console.WriteLine (signed ? "Assembly {0} signed." : "Couldn't sign the assembly {0}.",
+ assemblyName);
+ }
return signed;
}
return false;
}
- static int Verify (string assemblyName, bool forceVerification)
+ static int Verify (string assemblyName, bool forceVerification, bool quiet)
{
// this doesn't load the assembly (well it unloads it ;)
// http://weblogs.asp.net/nunitaddin/posts/9991.aspx
RSA rsa = CryptoConvert.FromCapiPublicKeyBlob (publicKey, 12);
StrongName sn = new StrongName (rsa);
if (sn.Verify (assemblyName)) {
- Console.WriteLine ("Assembly {0} is strongnamed.", assemblyName);
+ if (!quiet)
+ Console.WriteLine ("Assembly {0} is strongnamed.", assemblyName);
return 0;
}
else {
- Console.WriteLine ("Assembly {0} isn't strongnamed", assemblyName);
+ Console.WriteLine ("Assembly {0} is delay-signed but not strongnamed", assemblyName);
return 1;
}
}
Console.WriteLine (" -k keypair.snk{0}\tCreate a new keypair in the specified file", Environment.NewLine);
Console.WriteLine (" -R assembly keypair.snk{0}\tResign the assembly with the specified StrongName key file", Environment.NewLine);
Console.WriteLine (" -Rc assembly container{0}\tResign the assembly with the specified CSP container", Environment.NewLine);
- Console.WriteLine (" -t file{0}\tShow the public key from the specified file", Environment.NewLine);
+ Console.WriteLine (" -t file{0}\tShow the public key token from the specified file", Environment.NewLine);
Console.WriteLine (" -tp file{0}\tShow the public key and pk token from the specified file", Environment.NewLine);
- Console.WriteLine (" -T assembly{0}\tShow the public key from the specified assembly", Environment.NewLine);
+ Console.WriteLine (" -T assembly{0}\tShow the public key token from the specified assembly", Environment.NewLine);
Console.WriteLine (" -Tp assembly{0}\tShow the public key and pk token from the specified assembly", Environment.NewLine);
Console.WriteLine (" -v assembly{0}\tVerify the specified assembly signature", Environment.NewLine);
Console.WriteLine (" -vf assembly{0}\tVerify the specified assembly signature (even if disabled).", Environment.NewLine);
break;
case "-R":
string filename = args [i++];
- if (! ReSign (filename, GetKeyFromFile (args [i])))
+ if (! ReSign (filename, GetKeyFromFile (args [i]), quiet))
return 1;
break;
case "-Rc":
filename = args [i++];
csp.KeyContainerName = args [i];
rsa = new RSACryptoServiceProvider (csp);
- if (! ReSign (filename, rsa))
+ if (! ReSign (filename, rsa, quiet))
return 1;
break;
case "-t":
break;
case "-v":
filename = args [i++];
- return Verify (filename, false);
+ return Verify (filename, false, quiet);
case "-vf":
filename = args [i++];
- return Verify (filename, true); // force verification
+ return Verify (filename, true, quiet); // force verification
case "-Vl":
Console.WriteLine (new StrongNameManager ().ToString ());
break;
Console.WriteLine ("ERROR: Invalid number of parameters.{0}", Environment.NewLine);
Help (null);
}
+ catch (CryptographicException ce) {
+ Console.WriteLine ("ERROR: {0}", ce.Message);
+ }
catch (Exception e) {
Console.WriteLine ("ERROR: Unknown error during processing: {0}", e);
}