Ver código fonte

2003-03-06 Sebastien Pouliot <[email protected]>

	* 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
Sebastien Pouliot 23 anos atrás
pai
commit
8d979f1d63

+ 6 - 0
mcs/tools/security/ChangeLog

@@ -2,4 +2,10 @@
 
 	* AssemblyInfo.cs: New. Global assembly attributes (version and 
 	  copyright) for security tools.
+	* 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.
 	* README: New. Important information about the Mono's security tools
+	* 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.

+ 43 - 46
mcs/tools/security/cert2spc.cs

@@ -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;
 	}
 }
 

+ 30 - 0
mcs/tools/security/makefile

@@ -0,0 +1,30 @@
+CSC=csc.exe
+CSCFLAGS=/nologo /debug+ /debug:full /out:$@
+SECFLAGS=/r:../../class/lib/Mono.Security.dll
+
+windows: linux
+
+linux: cert2spc.exe secutil.exe
+
+cert2spc.exe: cert2spc.cs AssemblyInfo.cs
+	$(CSC) $(CSCFLAGS) $(SECFLAGS) cert2spc.cs AssemblyInfo.cs
+
+chktrust.exe: chktrust.cs AssemblyInfo.cs
+	$(CSC) $(CSCFLAGS) $(SECFLAGS) chktrust.cs AssemblyInfo.cs 
+
+makecert.exe: MakeCert.cs AssemblyInfo.cs
+	$(CSC) $(CSCFLAGS) $(SECFLAGS) MakeCert.cs AssemblyInfo.cs 
+
+secutil.exe: secutil.cs AssemblyInfo.cs
+	$(CSC) $(CSCFLAGS) secutil.cs AssemblyInfo.cs 
+
+signcode.exe: signcode.cs AssemblyInfo.cs
+	$(CSC) $(CSCFLAGS) $(SECFLAGS) signcode.cs AssemblyInfo.cs 
+
+sn.exe: sn.cs AssemblyInfo.cs
+	$(CSC) $(CSCFLAGS) $(SECFLAGS) sn.cs AssemblyInfo.cs
+
+clean:
+	rm -f *.exe *.pdb *.dbg *.dll
+
+dummy:

+ 78 - 0
mcs/tools/security/sectools.build

@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+
+<!-- NAnt build file for Security Tools -->
+
+<project name="sectools" default="build">
+	<property name="debug" value="false"/>
+
+	<target name="build">
+		<csc target="exe" output="cert2spc.exe" debug="${debug}">
+			<arg value="/r:..\..\class\lib\System.dll"/>
+			<arg value="/r:..\..\class\lib\Mono.Security.dll"/>
+			<sources basedir=".">
+				<includes name="AssemblyInfo.cs"/>
+				<includes name="cert2spc.cs"/>
+			</sources>
+		</csc>
+		<!-- csc target="exe" output="chktrust.exe" debug="${debug}">
+			<arg value="/r:..\..\class\lib\System.dll"/>
+			<arg value="/r:..\..\class\lib\Mono.Security.dll"/>
+			<sources basedir=".">
+				<includes name="AssemblyInfo.cs"/>
+				<includes name="chktrust.cs"/>
+			</sources>
+		</csc>
+		<csc target="exe" output="makecert.exe" debug="${debug}">
+			<arg value="/r:..\..\class\lib\System.dll"/>
+			<arg value="/r:..\..\class\lib\Mono.Security.dll"/>
+			<sources basedir=".">
+				<includes name="AssemblyInfo.cs"/>
+				<includes name="MakeCert.cs"/>
+			</sources>
+		</csc -->
+		<csc target="exe" output="secutil.exe" debug="${debug}">
+			<sources basedir=".">
+				<includes name="AssemblyInfo.cs"/>
+				<includes name="secutil.cs"/>
+			</sources>
+		</csc>
+		<!-- csc target="exe" output="signcode.exe" debug="${debug}">
+			<arg value="/r:..\..\class\lib\Mono.Security.dll"/>
+			<sources basedir=".">
+				<includes name="AssemblyInfo.cs"/>
+				<includes name="signcode.cs"/>
+			</sources>
+		</csc>
+		<csc target="exe" output="sn.exe" debug="${debug}">
+			<arg value="/r:..\..\class\lib\Mono.Security.dll"/>
+			<sources basedir=".">
+				<includes name="AssemblyInfo.cs"/>
+				<includes name="sn.cs"/>
+			</sources>
+		</csc -->
+	</target>
+
+	<target name="sign">
+		<!-- sign (strongname) all tools -->
+		<exec program="D:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Bin\sn.exe" commandline="-R secutil.exe sectools.snk"/>
+		<!-- sign (authenticode) all tools -->
+	</target>
+
+	<target name="test">
+	</target>
+
+	<target name="clean">
+		<delete file="cert2spc.exe" failonerror="false"/>
+		<delete file="cert2spc.pdb" failonerror="false"/>
+		<delete file="chktrust.exe" failonerror="false"/>
+		<delete file="chktrust.pdb" failonerror="false"/>
+		<delete file="makecert.exe" failonerror="false"/>
+		<delete file="makecert.pdb" failonerror="false"/>
+		<delete file="secutil.exe" failonerror="false"/>
+		<delete file="secutil.pdb" failonerror="false"/>
+		<delete file="signcode.exe" failonerror="false"/>
+		<delete file="signcode.pdb" failonerror="false"/>
+		<delete file="sn.exe" failonerror="false"/>
+		<delete file="sn.pdb" failonerror="false"/>
+	</target>
+</project>

+ 2 - 6
mcs/tools/security/secutil.cs

@@ -4,7 +4,7 @@
 // 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;
@@ -14,10 +14,6 @@ using System.Security.Cryptography.X509Certificates;
 
 [assembly: AssemblyTitle("Mono SecUtil")]
 [assembly: AssemblyDescription("Extract strongname and X509 certificates from assemblies.")]
-[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")]
 
 namespace Mono.Tools {
 
@@ -99,7 +95,7 @@ class SecUtil {
 		Console.WriteLine ("secutil -array");
 		Console.WriteLine ("\tShow data in a decimal array (default){0}", Environment.NewLine);
 		Console.WriteLine ("secutil -v");
-		Console.WriteLine ("secutil -vbcode");
+		Console.WriteLine ("secutil -vbmode");
 		Console.WriteLine ("\tShow data in a VisualBasic friendly format{0}", Environment.NewLine);
 		Console.WriteLine ("secutil -c");
 		Console.WriteLine ("secutil -cmode");