Author: spouliot
Date: 2007-01-12 14:30:42 -0500 (Fri, 12 Jan 2007)
New Revision: 70936

Modified:
   
trunk/mcs/class/Mono.Security/Mono.Security.Authenticode/AuthenticodeFormatter.cs
   trunk/mcs/class/Mono.Security/Mono.Security.Authenticode/ChangeLog
Log:
2007-01-12  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * AuthenticodeFormatter.cs: The ASN.1 structure must be padded to a
        multiple of 8 bytes, else the signature is invalid - even if the hash 
        is correct!



Modified: 
trunk/mcs/class/Mono.Security/Mono.Security.Authenticode/AuthenticodeFormatter.cs
===================================================================
--- 
trunk/mcs/class/Mono.Security/Mono.Security.Authenticode/AuthenticodeFormatter.cs
   2007-01-12 18:54:38 UTC (rev 70935)
+++ 
trunk/mcs/class/Mono.Security/Mono.Security.Authenticode/AuthenticodeFormatter.cs
   2007-01-12 19:30:42 UTC (rev 70936)
@@ -5,7 +5,7 @@
 //     Sebastien Pouliot <[EMAIL PROTECTED]>
 //
 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004, 2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004, 2006-2007 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
@@ -272,6 +272,7 @@
                                int addsize = (filesize & 7);
                                if (addsize > 0)
                                        addsize = 8 - addsize;
+
                                // IMAGE_DIRECTORY_ENTRY_SECURITY (offset, size)
                                byte[] data = BitConverterLE.GetBytes (filesize 
+ addsize);
                                file[PEOffset + 152] = data[0];
@@ -279,7 +280,10 @@
                                file[PEOffset + 154] = data[2];
                                file[PEOffset + 155] = data[3];
                                int size = asn.Length + 8;
-                               data = BitConverterLE.GetBytes (size);
+                               int addsize_signature = (size & 7);
+                               if (addsize_signature > 0)
+                                       addsize_signature = 8 - 
addsize_signature;
+                               data = BitConverterLE.GetBytes (size + 
addsize_signature);
                                file[PEOffset + 156] = data[0];
                                file[PEOffset + 157] = data[1];
                                file[PEOffset + 158] = data[2];
@@ -294,6 +298,10 @@
                                data = BitConverterLE.GetBytes (0x00020200);    
// magic
                                fs.Write (data, 0, data.Length);
                                fs.Write (asn, 0, asn.Length);
+                               if (addsize_signature > 0) {
+                                       byte[] fillup = new 
byte[addsize_signature];
+                                       fs.Write (fillup, 0, fillup.Length);
+                               }
                                fs.Close ();
                        }
                        return true;

Modified: trunk/mcs/class/Mono.Security/Mono.Security.Authenticode/ChangeLog
===================================================================
--- trunk/mcs/class/Mono.Security/Mono.Security.Authenticode/ChangeLog  
2007-01-12 18:54:38 UTC (rev 70935)
+++ trunk/mcs/class/Mono.Security/Mono.Security.Authenticode/ChangeLog  
2007-01-12 19:30:42 UTC (rev 70936)
@@ -1,3 +1,9 @@
+2007-01-12  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * AuthenticodeFormatter.cs: The ASN.1 structure must be padded to a
+       multiple of 8 bytes, else the signature is invalid - even if the hash 
+       is correct!
+
 2006-12-14  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * AuthenticodeBase.cs: Support (strip) COFF symbol table when 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to