// 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-2007 Novell, Inc (http://www.novell.com)
//
using System;
Console.WriteLine ("Usage: signcode [options] filename{0}", Environment.NewLine);
Console.WriteLine ("\t-spc spc\tSoftware Publisher Certificate file");
Console.WriteLine ("\t-v pvk\t\tPrivate Key file");
- Console.WriteLine ("\t-a md5 | sha1\tHash Algorithm (default: MD5)");
+ Console.WriteLine ("\t-a sha1 | md5\tHash Algorithm (default: SHA1)");
Console.WriteLine ("\t-$ indivisual | commercial\tSignature type");
Console.WriteLine ("\t-n description\tDescription for the signed file");
Console.WriteLine ("\t-i url\tURL for the signed file");
return null;
}
- PrivateKey pvk = PrivateKey.CreateFromFile (keyfile);
- if (pvk.Encrypted) {
+ try {
+ PrivateKey pvk = PrivateKey.CreateFromFile (keyfile);
+ rsa = pvk.RSA;
+ }
+ catch (CryptographicException) {
Console.WriteLine ("Enter password for {0}: ", keyfile);
string password = Console.ReadLine ();
- pvk = PrivateKey.CreateFromFile (keyfile, password);
- if (pvk.RSA == null)
+ try {
+ PrivateKey pvk = PrivateKey.CreateFromFile (keyfile, password);
+ rsa = pvk.RSA;
+ }
+ catch (CryptographicException) {
Console.WriteLine ("Invalid password!");
+ }
}
- rsa = pvk.RSA;
}
else {
rsa = new RSACryptoServiceProvider (csp);
string auth = args [i++].ToLower ();
switch (auth) {
case "individual":
- af.Authority = Authority.Commercial;
+ af.Authority = Authority.Individual;
break;
case "commercial":
- af.Authority = Authority.Individual;
+ af.Authority = Authority.Commercial;
break;
default:
Console.WriteLine ("Unknown authority {0}", auth);
Console.WriteLine ("No certificates available to sign the assembly.");
return 1;
}
- af.Certificates.AddRange (certs);\r
-\r
- if (!af.Sign (tbsFilename)) {\r
- Console.WriteLine ("Couldn't sign file '{0}'.", tbsFilename);\r
- return 1;\r
- }\r
- } else if (af.TimestampUrl != null) {\r
- bool ts = false;\r
- // only timestamp an already signed file\r
- for (int j = 0; j < timestampRetry && !ts; j++) {\r
- ts = af.Timestamp (tbsFilename);\r
- // wait (unless it's the last try) and retry\r
- if (!ts && (j < timestampRetry - 1)) {\r
- Console.WriteLine ("Couldn't timestamp file '{0}', will retry in {1} ms", tbsFilename, timestampDelay);\r
- Thread.Sleep (timestampDelay);\r
- }\r
- }\r
- if (!ts) {\r
- Console.WriteLine ("Couldn't timestamp file '{0}' after {1} retries.", tbsFilename, timestampRetry);\r
- return 1;\r
- }\r
- } else {\r
- Help ();\r
- return 1;\r
- }\r
-\r
+ af.Certificates.AddRange (certs);
+
+ if (!af.Sign (tbsFilename)) {
+ Console.WriteLine ("Couldn't sign file '{0}'.", tbsFilename);
+ return 1;
+ }
+ } else if (af.TimestampUrl != null) {
+ bool ts = false;
+ // only timestamp an already signed file
+ for (int j = 0; j < timestampRetry && !ts; j++) {
+ ts = af.Timestamp (tbsFilename);
+ // wait (unless it's the last try) and retry
+ if (!ts && (j < timestampRetry - 1)) {
+ Console.WriteLine ("Couldn't timestamp file '{0}', will retry in {1} ms", tbsFilename, timestampDelay);
+ Thread.Sleep (timestampDelay);
+ }
+ }
+ if (!ts) {
+ Console.WriteLine ("Couldn't timestamp file '{0}' after {1} retries.", tbsFilename, timestampRetry);
+ return 1;
+ }
+ } else {
+ Help ();
+ return 1;
+ }
+
Console.WriteLine ("Success");
return 0;
}