2 // Cert2Spc.cs: cert2spc clone tool
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
12 using System.Reflection;
13 using Mono.Security.ASN1;
15 [assembly: AssemblyTitle("Mono Cert2Spc")]
16 [assembly: AssemblyDescription("Transform a chain of certificate into an Authenticode(TM) \"Software Publisher Certificate\"")]
17 [assembly: AssemblyCompany("Sébastien Pouliot, Motus Technologies")]
18 [assembly: AssemblyProduct("Open Source Tools for .NET")]
19 [assembly: AssemblyCopyright("Copyright 2002 Motus Technologies. Released under BSD license.")]
20 [assembly: AssemblyVersion("0.17.99.0")]
22 namespace Mono.Tools {
26 static private string error;
28 static private void Header ()
30 Assembly a = Assembly.GetExecutingAssembly ();
31 AssemblyName an = a.GetName ();
33 object [] att = a.GetCustomAttributes (typeof (AssemblyTitleAttribute), false);
34 string title = ((att.Length > 0) ? ((AssemblyTitleAttribute) att [0]).Title : "Mono SecUtil");
36 att = a.GetCustomAttributes (typeof (AssemblyCopyrightAttribute), false);
37 string copyright = ((att.Length > 0) ? ((AssemblyCopyrightAttribute) att [0]).Copyright : "");
39 Console.WriteLine ("{0} {1}", title, an.Version.ToString ());
40 Console.WriteLine ("{0}{1}", copyright, Environment.NewLine);
43 static private void Help ()
45 Console.WriteLine ("Usage: cert2spc certificate|crl [certificate|crl] [...] outputfile.spc{0}", Environment.NewLine);
48 static void Process (string[] args)
50 if (args.Length < 2) {
51 error = "At least one input and output files must be specified";
55 string outFile = args [args.Length - 1];
56 // build certificate/crl list
57 ASN1 listOfCerts = new ASN1 (0xA0, null);
58 for (int i=0; i < args.Length - 1; i++) {
59 FileStream fs = new FileStream (args[i], FileMode.Open, FileAccess.Read);
60 byte[] cert = new byte [fs.Length];
61 fs.Read (cert, 0, cert.Length);
62 listOfCerts.Add (new ASN1(cert));
66 ASN1 integer = new ASN1 (0x02, null);
67 integer.Value = new byte[1];
70 ASN1 seqOID = new ASN1 (0x30, null);
71 seqOID.Add (new OID ("1.2.840.113549.1.7.1"));
73 ASN1 sequence = new ASN1 (0x30, null);
74 sequence.Add (integer);
75 sequence.Add (new ASN1 (0x31, null)); // empty set
76 sequence.Add (seqOID);
77 sequence.Add (listOfCerts);
78 sequence.Add (new ASN1 (0x31, null)); // empty set
80 ASN1 a0 = new ASN1 (0xA0, null);
83 ASN1 spc = new ASN1 (0x30, null);
84 spc.Add (new OID ("1.2.840.113549.1.7.2"));
88 FileStream spcFile = new FileStream (outFile, FileMode.Create, FileAccess.Write);
89 byte[] rawSpc = spc.GetBytes ();
90 spcFile.Write (rawSpc, 0, rawSpc.Length);
95 static void Main (string[] args)
102 Console.WriteLine ("Success");
104 Console.WriteLine ("Error: {0}{1}", error, Environment.NewLine);
108 catch (Exception e) {
109 Console.WriteLine ("Error: " + e.ToString ());