Author: spouliot
Date: 2007-04-26 16:48:59 -0400 (Thu, 26 Apr 2007)
New Revision: 76356
Modified:
trunk/mcs/class/corlib/Mono.Security.Authenticode/AuthenticodeBase.cs
trunk/mcs/class/corlib/Mono.Security.Authenticode/AuthenticodeDeformatter.cs
trunk/mcs/class/corlib/Mono.Security.Authenticode/ChangeLog
Log:
2007-04-26 Sebastien Pouliot <[EMAIL PROTECTED]>
* AuthenticodeBase.cs: Synch with latest Mono.Security version
* AuthenticodeDeformatter.cs: Synch with latest Mono.Security version
Modified: trunk/mcs/class/corlib/Mono.Security.Authenticode/AuthenticodeBase.cs
===================================================================
--- trunk/mcs/class/corlib/Mono.Security.Authenticode/AuthenticodeBase.cs
2007-04-26 20:38:48 UTC (rev 76355)
+++ trunk/mcs/class/corlib/Mono.Security.Authenticode/AuthenticodeBase.cs
2007-04-26 20:48:59 UTC (rev 76356)
@@ -5,7 +5,7 @@
// Sebastien Pouliot <[EMAIL PROTECTED]>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004, 2006 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
@@ -63,12 +63,37 @@
private int peOffset;
private int dirSecurityOffset;
private int dirSecuritySize;
+ private int coffSymbolTableOffset;
public AuthenticodeBase ()
{
fileblock = new byte [4096];
}
+ internal int PEOffset {
+ get {
+ if (blockNo < 1)
+ ReadFirstBlock ();
+ return peOffset;
+ }
+ }
+
+ internal int CoffSymbolTableOffset {
+ get {
+ if (blockNo < 1)
+ ReadFirstBlock ();
+ return coffSymbolTableOffset;
+ }
+ }
+
+ internal int SecurityOffset {
+ get {
+ if (blockNo < 1)
+ ReadFirstBlock ();
+ return dirSecurityOffset;
+ }
+ }
+
internal void Open (string filename)
{
if (fs != null)
@@ -117,13 +142,18 @@
// 2. Read between DOS header and first part of PE
header
// 2.1. Check for magic PE at start of header
- if (BitConverterLE.ToUInt16 (fileblock, peOffset) !=
0x4550)
+ // PE - NT header ('P' 'E' 0x00 0x00)
+ if (BitConverterLE.ToUInt32 (fileblock, peOffset) !=
0x4550)
return false;
// 2.2. Locate IMAGE_DIRECTORY_ENTRY_SECURITY (offset
and size)
dirSecurityOffset = BitConverterLE.ToInt32 (fileblock,
peOffset + 152);
dirSecuritySize = BitConverterLE.ToInt32 (fileblock,
peOffset + 156);
+ // COFF symbol tables are deprecated - we'll strip them
if we see them!
+ // (otherwise the signature won't work on MS and we
don't want to support COFF for that)
+ coffSymbolTableOffset = BitConverterLE.ToInt32
(fileblock, peOffset + 12);
+
return true;
}
@@ -143,7 +173,6 @@
return null;
}
- // returns null if the file isn't signed
internal byte[] GetHash (HashAlgorithm hash)
{
if (blockNo < 1)
@@ -151,7 +180,8 @@
fs.Position = blockLength;
// hash the rest of the file
- long n = fs.Length - blockLength;
+ long n;
+ int addsize = 0;
// minus any authenticode signature (with 8 bytes
header)
if (dirSecurityOffset > 0) {
// it is also possible that the signature block
@@ -159,9 +189,32 @@
if (dirSecurityOffset < blockLength) {
blockLength = dirSecurityOffset;
n = 0;
+ } else {
+ n = dirSecurityOffset - blockLength;
}
- else
- n -= (dirSecuritySize);
+ } else if (coffSymbolTableOffset > 0) {
+ fileblock[PEOffset + 12] = 0;
+ fileblock[PEOffset + 13] = 0;
+ fileblock[PEOffset + 14] = 0;
+ fileblock[PEOffset + 15] = 0;
+ fileblock[PEOffset + 16] = 0;
+ fileblock[PEOffset + 17] = 0;
+ fileblock[PEOffset + 18] = 0;
+ fileblock[PEOffset + 19] = 0;
+ // it is also possible that the signature block
+ // starts within the block in memory (small EXE)
+ if (coffSymbolTableOffset < blockLength) {
+ blockLength = coffSymbolTableOffset;
+ n = 0;
+ } else {
+ n = coffSymbolTableOffset - blockLength;
+ }
+ } else {
+ addsize = (int) (fs.Length & 7);
+ if (addsize > 0)
+ addsize = 8 - addsize;
+
+ n = fs.Length - blockLength;
}
// Authenticode(r) gymnastics
@@ -199,7 +252,13 @@
// remainder
if (fs.Read (fileblock, 0, remainder) !=
remainder)
return null;
- hash.TransformFinalBlock (fileblock, 0,
remainder);
+
+ if (addsize > 0) {
+ hash.TransformBlock (fileblock, 0,
remainder, fileblock, 0);
+ hash.TransformFinalBlock (new byte
[addsize], 0, addsize);
+ } else {
+ hash.TransformFinalBlock (fileblock, 0,
remainder);
+ }
}
return hash.Hash;
}
Modified:
trunk/mcs/class/corlib/Mono.Security.Authenticode/AuthenticodeDeformatter.cs
===================================================================
---
trunk/mcs/class/corlib/Mono.Security.Authenticode/AuthenticodeDeformatter.cs
2007-04-26 20:38:48 UTC (rev 76355)
+++
trunk/mcs/class/corlib/Mono.Security.Authenticode/AuthenticodeDeformatter.cs
2007-04-26 20:48:59 UTC (rev 76356)
@@ -5,7 +5,7 @@
// Sebastien Pouliot <[EMAIL PROTECTED]>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2006 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
@@ -140,7 +140,8 @@
return false;
}
- reason = 0;
+ if (reason == -1)
+ reason = 0;
return true;
}
@@ -167,24 +168,24 @@
private bool CheckSignature (string fileName)
{
filename = fileName;
- base.Open (filename);
- entry = base.GetSecurityEntry ();
+ Open (filename);
+ entry = GetSecurityEntry ();
if (entry == null) {
// no signature is present
reason = 1;
- base.Close ();
+ Close ();
return false;
}
PKCS7.ContentInfo ci = new PKCS7.ContentInfo (entry);
if (ci.ContentType != PKCS7.Oid.signedData) {
- base.Close ();
+ Close ();
return false;
}
PKCS7.SignedData sd = new PKCS7.SignedData (ci.Content);
if (sd.ContentInfo.ContentType !=
spcIndirectDataContext) {
- base.Close ();
+ Close ();
return false;
}
@@ -205,10 +206,10 @@
break;
default:
reason = 5;
- base.Close ();
+ Close ();
return false;
}
- base.Close ();
+ Close ();
if (!signedHash.CompareValue (hash)) {
reason = 2;
@@ -319,21 +320,26 @@
}
}
- for (int i=0; i <
sd.SignerInfo.UnauthenticatedAttributes.Count; i++) {
- ASN1 attr = (ASN1)
sd.SignerInfo.UnauthenticatedAttributes [i];
- string oid = ASN1Convert.ToOid (attr [0]);
- switch (oid) {
+ // timestamp signature is optional
+ if (sd.SignerInfo.UnauthenticatedAttributes.Count == 0)
{
+ trustedTimestampRoot = true;
+ } else {
+ for (int i = 0; i <
sd.SignerInfo.UnauthenticatedAttributes.Count; i++) {
+ ASN1 attr = (ASN1)
sd.SignerInfo.UnauthenticatedAttributes[i];
+ string oid = ASN1Convert.ToOid
(attr[0]);
+ switch (oid) {
case PKCS7.Oid.countersignature:
// SEQUENCE {
// OBJECT IDENTIFIER
// countersignature (1 2
840 113549 1 9 6)
// SET {
- PKCS7.SignerInfo cs = new
PKCS7.SignerInfo (attr [1]);
+ PKCS7.SignerInfo cs = new
PKCS7.SignerInfo (attr[1]);
trustedTimestampRoot =
VerifyCounterSignature (cs, signature);
break;
default:
// we don't support other
unauthenticated attributes
break;
+ }
}
}
Modified: trunk/mcs/class/corlib/Mono.Security.Authenticode/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Mono.Security.Authenticode/ChangeLog 2007-04-26
20:38:48 UTC (rev 76355)
+++ trunk/mcs/class/corlib/Mono.Security.Authenticode/ChangeLog 2007-04-26
20:48:59 UTC (rev 76356)
@@ -1,3 +1,8 @@
+2007-04-26 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * AuthenticodeBase.cs: Synch with latest Mono.Security version
+ * AuthenticodeDeformatter.cs: Synch with latest Mono.Security version
+
2006-11-08 Sebastien Pouliot <[EMAIL PROTECTED]>
* AuthenticodeDeformatter.cs: Return (find) the SigningCertificate
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches