Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Pouliot <sebastien@ximian.com>2003-03-07 06:04:42 +0300
committerSebastien Pouliot <sebastien@ximian.com>2003-03-07 06:04:42 +0300
commit8d979f1d63f00df0cfe7cf8a2da1b28ca55aecff (patch)
tree9946935326b1b9b10c014f6fb47cdca891c146b5 /mcs/tools/security/cert2spc.cs
parent811c42fb59f2e20d0778abf668b7b90afba17e5f (diff)
2003-03-06 Sebastien Pouliot <spouliot@videotron.ca>
* cert2spc.cs: Update to use the new PKCS7 class (from Mono.Security assembly) and AssemblyInfo.cs. Older version was located in /mcs/tools. * makefile: New. PROTOTYPE makefile (not tested) for Linux. * secutil.cs: Updated to use AssemblyInfo.cs. Older version was located in /mcs/tools. * sectools.build: New. NAnt build file to build all security tools. svn path=/trunk/mcs/; revision=12277
Diffstat (limited to 'mcs/tools/security/cert2spc.cs')
-rw-r--r--mcs/tools/security/cert2spc.cs89
1 files changed, 43 insertions, 46 deletions
diff --git a/mcs/tools/security/cert2spc.cs b/mcs/tools/security/cert2spc.cs
index d398e770a53..6e01de1d2ac 100644
--- a/mcs/tools/security/cert2spc.cs
+++ b/mcs/tools/security/cert2spc.cs
@@ -4,20 +4,18 @@
// Author:
// Sebastien Pouliot (spouliot@motus.com)
//
-// (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;
}
}