diff options
author | Andrew Jorgensen <ajorgensen@novell.com> | 2009-07-22 00:38:59 +0400 |
---|---|---|
committer | Andrew Jorgensen <ajorgensen@novell.com> | 2009-07-22 00:38:59 +0400 |
commit | 3b1cee23d6f2f69f8444a5a1def4051028abff5f (patch) | |
tree | 16847f365240e9e2b7664928482bcc4739dd8b29 | |
parent | 7f2a05475526ed5234d3ecf3028eab0336d6b5d3 (diff) |
Security fix for CVE-2009-0217
svn path=/branches/mono-2-4-2/mcs/; revision=138331
-rw-r--r-- | mcs/class/System.Security/System.Security.Cryptography.Xml/SignedXml.cs | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/SignedXml.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/SignedXml.cs index 68adec70c92..aef613ce495 100644 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/SignedXml.cs +++ b/mcs/class/System.Security/System.Security.Cryptography.Xml/SignedXml.cs @@ -595,17 +595,28 @@ namespace System.Security.Cryptography.Xml { return false; byte[] actual = macAlg.ComputeHash (s); - // HMAC signature may be partial + // HMAC signature may be partial and specified by <HMACOutputLength> if (m_signature.SignedInfo.SignatureLength != null) { - int length = actual.Length; - try { - // SignatureLength is in bits - length = (Int32.Parse (m_signature.SignedInfo.SignatureLength) >> 3); - } - catch { - } - - if (length != actual.Length) { + int length = Int32.Parse (m_signature.SignedInfo.SignatureLength); + // we only support signatures with a multiple of 8 bits + // and the value must match the signature length + if ((length & 7) != 0) + throw new CryptographicException ("Signature length must be a multiple of 8 bits."); + + // SignatureLength is in bits (and we works on bytes, only in multiple of 8 bits) + // and both values must match for a signature to be valid + length >>= 3; + if (length != m_signature.SignatureValue.Length) + throw new CryptographicException ("Invalid signature length."); + + // is the length "big" enough to make the signature meaningful ? + // we use a minimum of 80 bits (10 bytes) or half the HMAC normal output length + // e.g. HMACMD5 output 128 bits but our minimum is 80 bits (not 64 bits) + int minimum = Math.Max (10, actual.Length / 2); + if (length < minimum) + throw new CryptographicException ("HMAC signature is too small"); + + if (length < actual.Length) { byte[] trunked = new byte [length]; Buffer.BlockCopy (actual, 0, trunked, 0, length); actual = trunked; |