2008-12-23 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Tue, 23 Dec 2008 18:53:29 +0000 (18:53 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Tue, 23 Dec 2008 18:53:29 +0000 (18:53 -0000)
* SoftwarePublisherCertificate.cs: Support PKCS7 files that with
PEM headers around the base64 content.
[Fix bug #457658]

svn path=/trunk/mcs/; revision=122048

mcs/class/Mono.Security/Mono.Security.Authenticode/ChangeLog
mcs/class/Mono.Security/Mono.Security.Authenticode/SoftwarePublisherCertificate.cs

index 6829895825883e014bf4ab57b11bdfb83ae30ce2..b6b94272fce3306faf605ba09f77d95f3a23b70e 100644 (file)
@@ -1,3 +1,9 @@
+2008-12-23  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * SoftwarePublisherCertificate.cs: Support PKCS7 files that with 
+       PEM headers around the base64 content.
+       [Fix bug #457658]
+
 2008-05-16  Sebastien Pouliot  <sebastien@ximian.com>
 
        * AuthenticodeFormatter.cs: Throw an NotSupportedException if we're
index 0a87385dc93f958080e310026c5556bd93608fa9..bc64ddc888361efb891b2e4f27a3ab0ce6f533ef 100644 (file)
@@ -6,9 +6,7 @@
 //     Sebastien Pouliot <sebastien@ximian.com>
 //
 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
-//
-
+// Copyright (C) 2004,2008 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -34,6 +32,7 @@ using System;
 using System.Collections;
 using System.Globalization;
 using System.IO;
+using System.Security.Cryptography;
 using System.Text;
 
 using Mono.Security;
@@ -97,14 +96,12 @@ namespace Mono.Security.Authenticode {
                                return null;
 
                        if (data [0] != 0x30) {
-                               // this isn't an ASN.1 SEQUENCE (so not legal)
-                               if (data [1] == 0x00) {
-                                       // this could be base64/unicode (e.g. VeriSign)
-                                       data = Convert.FromBase64String (Encoding.Unicode.GetString (data));
+                               // this isn't an ASN.1 SEQUENCE (so not legal), check for PEM/base64 encoding
+                               try {
+                                       data = PEM (data);
                                }
-                               else {
-                                       // default to base64/ascii
-                                       data = Convert.FromBase64String (Encoding.ASCII.GetString (data));
+                               catch (Exception ex) {
+                                       throw new CryptographicException ("Invalid encoding", ex);
                                }
                        }
 #if DEBUG
@@ -115,5 +112,18 @@ namespace Mono.Security.Authenticode {
 #endif
                        return new SoftwarePublisherCertificate (data);
                }
+
+               const string header = "-----BEGIN PKCS7-----";
+               const string footer = "-----END PKCS7-----";
+
+               static byte[] PEM (byte[] data) 
+               {
+                       // this could be base64/unicode (e.g. VeriSign) otherwise default to ASCII
+                       string pem = (data [1] == 0x00) ? Encoding.Unicode.GetString (data) : Encoding.ASCII.GetString (data);
+                       int start = pem.IndexOf (header) + header.Length;
+                       int end = pem.IndexOf (footer, start);
+                       string base64 = ((start == -1) || (end == -1)) ? pem : pem.Substring (start, (end - start));
+                       return Convert.FromBase64String (base64);
+               }
        }
 }