// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
+// Copyright (C) 2004,2006-2007 Novell, Inc (http://www.novell.com)
//
using System;
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);
CspParameters csp = new CspParameters ();
string pvkFilename = null;
string spcFilename = null;
- int timestampRetry = 0;
+ int timestampRetry = 1;
int timestampDelay = 0;
bool sign = true;
AuthenticodeFormatter af = new AuthenticodeFormatter ();
int i = 0;
- while (i < args.Length) {
+ while (i < args.Length - 1) {
switch (args[i++]) {
case "-spc":
spcFilename = args [i++];
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);
case "-jp":
Console.WriteLine ("Unsupported option {0}", args[i-1]);
return 1;
+ // other options
+ case "-?":
+ Help ();
+ return 0;
}
}
Console.WriteLine ("No certificates available to sign the assembly.");
return 1;
}
- af.Certificates.AddRange (certs);
-
- af.Sign (tbsFilename);
- }
-/* TODO
- if (af.TimestampURL != null) {
- for (int j=0; j < timestampRetry + 1; j++) {
- if (!af.Timestamp (tbsFilename)) {
- Thread.Sleep (timestampDelay);
- continue;
- }
- break;
- }
- }*/
- // temp
- if ((timestampRetry > 0) || (timestampDelay > 0)) {
- Console.WriteLine ("Timestamp retries and delays aren't implemented.");
- }
+ 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
+ Console.WriteLine ("Success");
return 0;
}
}