|
|
@@ -4,20 +4,18 @@
|
|
|
// Author:
|
|
|
// Sebastien Pouliot ([email protected])
|
|
|
//
|
|
|
-// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
|
|
|
+// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
|
|
//
|
|
|
|
|
|
using System;
|
|
|
using System.IO;
|
|
|
using System.Reflection;
|
|
|
-using Mono.Security.ASN1;
|
|
|
+using System.Security.Cryptography.X509Certificates;
|
|
|
+
|
|
|
+using Mono.Security.Authenticode;
|
|
|
|
|
|
[assembly: AssemblyTitle("Mono Cert2Spc")]
|
|
|
-[assembly: AssemblyDescription("Transform a chain of certificate into an Authenticode(TM) \"Software Publisher Certificate\"")]
|
|
|
-[assembly: AssemblyCompany("Sébastien Pouliot, Motus Technologies")]
|
|
|
-[assembly: AssemblyProduct("Open Source Tools for .NET")]
|
|
|
-[assembly: AssemblyCopyright("Copyright 2002 Motus Technologies. Released under BSD license.")]
|
|
|
-[assembly: AssemblyVersion("0.17.99.0")]
|
|
|
+[assembly: AssemblyDescription("Transform a set of X.509 certificates and CRLs into an Authenticode(TM) \"Software Publisher Certificate\"")]
|
|
|
|
|
|
namespace Mono.Tools {
|
|
|
|
|
|
@@ -45,58 +43,56 @@ class Cert2Spc {
|
|
|
Console.WriteLine ("Usage: cert2spc certificate|crl [certificate|crl] [...] outputfile.spc{0}", Environment.NewLine);
|
|
|
}
|
|
|
|
|
|
- static void Process (string[] args)
|
|
|
+ // until we have real CRL support
|
|
|
+ static byte[] GetFile (string filename)
|
|
|
+ {
|
|
|
+ FileStream fs = File.Open (filename, FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
|
+ byte[] data = new byte [fs.Length];
|
|
|
+ fs.Read (data, 0, data.Length);
|
|
|
+ fs.Close ();
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ static int Process (string[] args)
|
|
|
{
|
|
|
- if (args.Length < 2) {
|
|
|
+ int nargs = args.Length - 1;
|
|
|
+ if (nargs < 1) {
|
|
|
error = "At least one input and output files must be specified";
|
|
|
- return;
|
|
|
+ return 1;
|
|
|
}
|
|
|
|
|
|
- string outFile = args [args.Length - 1];
|
|
|
- // build certificate/crl list
|
|
|
- ASN1 listOfCerts = new ASN1 (0xA0, null);
|
|
|
+ string output = args [nargs];
|
|
|
+ SoftwarePublisherCertificate spc = new SoftwarePublisherCertificate ();
|
|
|
+
|
|
|
for (int i=0; i < args.Length - 1; i++) {
|
|
|
- FileStream fs = new FileStream (args[i], FileMode.Open, FileAccess.Read);
|
|
|
- byte[] cert = new byte [fs.Length];
|
|
|
- fs.Read (cert, 0, cert.Length);
|
|
|
- listOfCerts.Add (new ASN1(cert));
|
|
|
+ switch (Path.GetExtension (args[i]).ToLower ()) {
|
|
|
+ case ".cer":
|
|
|
+ case ".crt":
|
|
|
+ spc.Certificates.Add (X509Certificate.CreateFromCertFile (args[i]));
|
|
|
+ break;
|
|
|
+ case ".crl":
|
|
|
+ spc.CRLs.Add (GetFile (args[i]));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ error = "Unknown file extension : " + args[i];
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // compose header
|
|
|
- ASN1 integer = new ASN1 (0x02, null);
|
|
|
- integer.Value = new byte[1];
|
|
|
- integer.Value[0] = 1;
|
|
|
-
|
|
|
- ASN1 seqOID = new ASN1 (0x30, null);
|
|
|
- seqOID.Add (new OID ("1.2.840.113549.1.7.1"));
|
|
|
-
|
|
|
- ASN1 sequence = new ASN1 (0x30, null);
|
|
|
- sequence.Add (integer);
|
|
|
- sequence.Add (new ASN1 (0x31, null)); // empty set
|
|
|
- sequence.Add (seqOID);
|
|
|
- sequence.Add (listOfCerts);
|
|
|
- sequence.Add (new ASN1 (0x31, null)); // empty set
|
|
|
-
|
|
|
- ASN1 a0 = new ASN1 (0xA0, null);
|
|
|
- a0.Add (sequence);
|
|
|
-
|
|
|
- ASN1 spc = new ASN1 (0x30, null);
|
|
|
- spc.Add (new OID ("1.2.840.113549.1.7.2"));
|
|
|
- spc.Add (a0);
|
|
|
-
|
|
|
- // write output file
|
|
|
- FileStream spcFile = new FileStream (outFile, FileMode.Create, FileAccess.Write);
|
|
|
- byte[] rawSpc = spc.GetBytes ();
|
|
|
- spcFile.Write (rawSpc, 0, rawSpc.Length);
|
|
|
- spcFile.Close ();
|
|
|
+ FileStream fs = File.Open (output, FileMode.Create, FileAccess.Write);
|
|
|
+ byte[] data = spc.GetBytes ();
|
|
|
+ fs.Write (data, 0, data.Length);
|
|
|
+ fs.Close ();
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
[STAThread]
|
|
|
- static void Main (string[] args)
|
|
|
+ static int Main (string[] args)
|
|
|
{
|
|
|
+ int result = 1;
|
|
|
try {
|
|
|
Header();
|
|
|
- Process (args);
|
|
|
+ result = Process (args);
|
|
|
|
|
|
if (error == null)
|
|
|
Console.WriteLine ("Success");
|
|
|
@@ -109,6 +105,7 @@ class Cert2Spc {
|
|
|
Console.WriteLine ("Error: " + e.ToString ());
|
|
|
Help ();
|
|
|
}
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|
|
|
|