Author: spouliot
Date: 2005-05-03 13:55:44 -0400 (Tue, 03 May 2005)
New Revision: 43970

Modified:
   trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ChangeLog
   
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsSigner.cs
   
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ContentInfo.cs
   
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/EnvelopedCms.cs
   
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/KeyTransRecipientInfo.cs
   
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9ContentType.cs
   
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9MessageDigest.cs
   
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignedCms.cs
   
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfo.cs
   
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfoCollection.cs
Log:
2005-05-03  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * CmsSigner.cs: Removed old FIXME.
        * ContentInfo.cs: Better detection (but still less strict than MS).
        * EnvelopedCms.cs: Avoid possible NullReferenceException in Encrypt.
        * KeyTransRecipientInfo.cs: Minor editing updates.
        * Pkcs9ContentType.cs: Added encoding/decoding of the content 
        information (OID).
        * Pkcs9MessageDigest.cs: Added encoding/decoding of the digest.
        * SignedCms.cs: Version set to 0 (default). Serial numbers are 
        reversed here (Fx isn't very consistant in this regard).
        * SignerInfo.cs: Convert the hash name to an OID.
        * SignerInfoCollection.cs: Completed class.



Modified: 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ChangeLog
===================================================================
--- trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ChangeLog 
2005-05-03 17:53:51 UTC (rev 43969)
+++ trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ChangeLog 
2005-05-03 17:55:44 UTC (rev 43970)
@@ -1,3 +1,17 @@
+2005-05-03  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * CmsSigner.cs: Removed old FIXME.
+       * ContentInfo.cs: Better detection (but still less strict than MS).
+       * EnvelopedCms.cs: Avoid possible NullReferenceException in Encrypt.
+       * KeyTransRecipientInfo.cs: Minor editing updates.
+       * Pkcs9ContentType.cs: Added encoding/decoding of the content 
+       information (OID).
+       * Pkcs9MessageDigest.cs: Added encoding/decoding of the digest.
+       * SignedCms.cs: Version set to 0 (default). Serial numbers are 
+       reversed here (Fx isn't very consistant in this regard).
+       * SignerInfo.cs: Convert the hash name to an OID.
+       * SignerInfoCollection.cs: Completed class.
+
 2005-04-26  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * AlgorithmIdentifier.cs: Removed FIXME - seems "by design".

Modified: 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsSigner.cs
===================================================================
--- 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsSigner.cs  
    2005-05-03 17:53:51 UTC (rev 43969)
+++ 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsSigner.cs  
    2005-05-03 17:55:44 UTC (rev 43970)
@@ -66,17 +66,11 @@
                public CmsSigner (SubjectIdentifierType signerIdentifierType, 
X509Certificate2 certificate) 
                        : this (signerIdentifierType)
                {
-// FIXME: compatibility with fx 1.2.3400.0
-//                     if (certificate == null)
-//                             throw new ArgumentNullException ("certificate");
                        _certificate = certificate;
                }
 
                public CmsSigner (X509Certificate2 certificate) : this ()
                {
-// FIXME: compatibility with fx 1.2.3400.0
-//                     if (certificate == null)
-//                             throw new ArgumentNullException ("certificate");
                        _certificate = certificate;
                }
 

Modified: 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ContentInfo.cs
===================================================================
--- 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ContentInfo.cs
    2005-05-03 17:53:51 UTC (rev 43969)
+++ 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ContentInfo.cs
    2005-05-03 17:55:44 UTC (rev 43970)
@@ -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-2005 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
@@ -29,9 +29,6 @@
 
 #if NET_2_0
 
-using System;
-using System.Security.Cryptography;
-
 using Mono.Security;
 
 namespace System.Security.Cryptography.Pkcs {
@@ -74,7 +71,7 @@
                // properties
 
                public byte[] Content { 
-                       get { return _content; }
+                       get { return (byte[]) _content.Clone (); }
                }
 
                public Oid ContentType { 
@@ -83,7 +80,7 @@
 
                // static methods
 
-               [MonoTODO("Incomplete OID support")]
+               [MonoTODO ("MS is stricter than us about the content 
structure")]
                public static Oid GetContentType (byte[] encodedMessage)
                {
                        if (encodedMessage == null)
@@ -92,15 +89,21 @@
                        try {
                                PKCS7.ContentInfo ci = new PKCS7.ContentInfo 
(encodedMessage);
                                switch (ci.ContentType) {
-                                       // TODO - there are probably more - 
need testing
-                                       case PKCS7.Oid.signedData:
-                                               return new Oid (ci.ContentType);
-                                       default:
-                                               throw new 
CryptographicException ("Bad ASN1 - invalid OID");
+                               case PKCS7.Oid.data:
+                               case PKCS7.Oid.signedData:              // see 
SignedCms class
+                               case PKCS7.Oid.envelopedData:           // see 
EnvelopedCms class
+                               case PKCS7.Oid.digestedData:
+                               case PKCS7.Oid.encryptedData:
+                                       return new Oid (ci.ContentType);
+                               default:
+                                       // Note: the constructor will accept 
any "valid" OID (but that 
+                                       // doesn't mean it's a valid 
ContentType structure - ASN.1 wise).
+                                       string msg = Locale.GetText ("Bad ASN1 
- invalid OID '{0}'");
+                                       throw new CryptographicException 
(String.Format (msg, ci.ContentType));
                                }
                        }
                        catch (Exception e) {
-                               throw new CryptographicException ("Bad ASN1 - 
invalid structure", e);
+                               throw new CryptographicException 
(Locale.GetText ("Bad ASN1 - invalid structure"), e);
                        }
                }
        }

Modified: 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/EnvelopedCms.cs
===================================================================
--- 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/EnvelopedCms.cs
   2005-05-03 17:53:51 UTC (rev 43969)
+++ 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/EnvelopedCms.cs
   2005-05-03 17:55:44 UTC (rev 43970)
@@ -219,7 +219,7 @@
                [MonoTODO]
                public void Encrypt () 
                {
-                       if ((_content.Content == null) || 
(_content.Content.Length == 0))
+                       if ((_content == null) || (_content.Content == null) || 
(_content.Content.Length == 0))
                                throw new CryptographicException ("no content 
to encrypt");
                }
 

Modified: 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/KeyTransRecipientInfo.cs
===================================================================
--- 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/KeyTransRecipientInfo.cs
  2005-05-03 17:53:51 UTC (rev 43969)
+++ 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/KeyTransRecipientInfo.cs
  2005-05-03 17:55:44 UTC (rev 43970)
@@ -2,12 +2,11 @@
 // KeyTransRecipientInfo.cs - 
System.Security.Cryptography.Pkcs.KeyTransRecipientInfo
 //
 // Author:
-//     Sebastien Pouliot ([EMAIL PROTECTED])
+//     Sebastien Pouliot  <[EMAIL PROTECTED]>
 //
 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004-2005 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
 // "Software"), to deal in the Software without restriction, including
@@ -30,7 +29,6 @@
 
 #if NET_2_0
 
-using System;
 using System.Collections;
 
 namespace System.Security.Cryptography.Pkcs {
@@ -42,7 +40,7 @@
                private SubjectIdentifier _recipientIdentifier;
                private int _version;
 
-               // only accessible from EnvelopedPkcs7.RecipientInfos
+               // only accessible from EnvelopedCms.RecipientInfos
                internal KeyTransRecipientInfo (byte[] encryptedKey, 
AlgorithmIdentifier keyEncryptionAlgorithm, SubjectIdentifier 
recipientIdentifier, int version)
                        : base (RecipientInfoType.KeyTransport)
                {
@@ -70,4 +68,4 @@
        }
 }
 
-#endif
\ No newline at end of file
+#endif

Modified: 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9ContentType.cs
===================================================================
--- 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9ContentType.cs
       2005-05-03 17:53:51 UTC (rev 43969)
+++ 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9ContentType.cs
       2005-05-03 17:55:44 UTC (rev 43970)
@@ -30,15 +30,17 @@
 
 #if NET_2_0
 
+using Mono.Security;
+
 namespace System.Security.Cryptography.Pkcs {
 
-       [MonoTODO ("missing internals")]
        public sealed class Pkcs9ContentType : Pkcs9AttributeObject {
 
                internal const string oid = "1.2.840.113549.1.9.3";
                internal const string friendlyName = "Content Type";
 
                private Oid _contentType;
+               private byte[] _encoded;
 
                // constructors
 
@@ -46,6 +48,7 @@
                {
                        // Pkcs9Attribute remove the "set" accessor on Oid :-(
                        (this as AsnEncodedData).Oid = new Oid (oid, 
friendlyName);
+                       _encoded = null;
                }
 
                internal Pkcs9ContentType (string contentType) 
@@ -53,6 +56,7 @@
                        (this as AsnEncodedData).Oid = new Oid (oid, 
friendlyName);
                        _contentType = new Oid (contentType);
                        RawData = Encode ();
+                       _encoded = null;
                }
 
                internal Pkcs9ContentType (byte[] encodedContentType) 
@@ -68,7 +72,11 @@
                // properties
 
                public Oid ContentType {
-                       get { return _contentType; }
+                       get {
+                               if (_encoded != null)
+                                       Decode (_encoded);
+                               return _contentType;
+                       }
                }
 
                // methods
@@ -76,20 +84,26 @@
                public override void CopyFrom (AsnEncodedData asnEncodedData)
                {
                        base.CopyFrom (asnEncodedData);
-                       Decode (this.RawData);
+                       _encoded = asnEncodedData.RawData;
                }
 
                // internal stuff
 
                internal void Decode (byte[] attribute)
                {
-                       _contentType = null;
+                       if ((attribute == null) || (attribute [0] != 0x06))
+                               throw new CryptographicException 
(Locale.GetText ("Expected an OID."));
+
+                       ASN1 oid = new ASN1 (attribute);
+                       _contentType = new Oid (ASN1Convert.ToOid (oid));
+                       _encoded = null;
                }
 
-               // TODO
                internal byte[] Encode ()
                {
-                       return null;
+                       if (_contentType == null)
+                               return null;
+                       return ASN1Convert.FromOid 
(_contentType.Value).GetBytes ();
                }
        }
 }

Modified: 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9MessageDigest.cs
===================================================================
--- 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9MessageDigest.cs
     2005-05-03 17:53:51 UTC (rev 43969)
+++ 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9MessageDigest.cs
     2005-05-03 17:55:44 UTC (rev 43970)
@@ -30,15 +30,17 @@
 
 #if NET_2_0
 
+using Mono.Security;
+
 namespace System.Security.Cryptography.Pkcs {
 
-       [MonoTODO ("missing internals")]
        public sealed class Pkcs9MessageDigest : Pkcs9AttributeObject {
 
                internal const string oid = "1.2.840.113549.1.9.4";
                internal const string friendlyName = "Message Digest";
 
                private byte[] _messageDigest;
+               private byte[] _encoded;
 
                // constructors
 
@@ -46,6 +48,7 @@
                {
                        // Pkcs9Attribute remove the "set" accessor on Oid :-(
                        (this as AsnEncodedData).Oid = new Oid (oid, 
friendlyName);
+                       _encoded = null;
                }
 
                internal Pkcs9MessageDigest (byte[] messageDigest, bool 
encoded) 
@@ -67,7 +70,12 @@
                // properties
 
                public byte[] MessageDigest {
-                       get { return _messageDigest; }
+                       get {
+                               if (_encoded != null)
+                                       Decode (_encoded);
+                               // FIXME: beta2 returns a reference
+                               return _messageDigest;
+                       }
                }
 
                // methods
@@ -75,21 +83,25 @@
                public override void CopyFrom (AsnEncodedData asnEncodedData)
                {
                        base.CopyFrom (asnEncodedData);
-                       Decode (this.RawData);
+                       _encoded = asnEncodedData.RawData;
                }
 
                // internal stuff
 
                internal void Decode (byte[] attribute)
                {
-                       // TODO
-                       _messageDigest = null;
+                       if ((attribute == null) || (attribute [0] != 0x04))
+                               throw new CryptographicException 
(Locale.GetText ("Expected an OCTETSTRING."));
+
+                       ASN1 md = new ASN1 (attribute);
+                       _messageDigest = md.Value;
+                       _encoded  = null;
                }
 
                internal byte[] Encode ()
                {
-                       // TODO
-                       return null;
+                       ASN1 md = new ASN1 (0x04, _messageDigest);
+                       return md.GetBytes ();
                }
        }
 }

Modified: 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignedCms.cs
===================================================================
--- 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignedCms.cs  
    2005-05-03 17:53:51 UTC (rev 43969)
+++ 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignedCms.cs  
    2005-05-03 17:55:44 UTC (rev 43970)
@@ -73,21 +73,21 @@
                public SignedCms (SubjectIdentifierType signerIdentifierType) : 
this ()
                {
                        _type = signerIdentifierType;
-                       _version = ((_type == 
SubjectIdentifierType.SubjectKeyIdentifier) ? 2 : 0);
+                       _version = 0;
                }
 
                public SignedCms (SubjectIdentifierType signerIdentifierType, 
ContentInfo content) 
                        : this (content, false) 
                {
                        _type = signerIdentifierType;
-                       _version = ((_type == 
SubjectIdentifierType.SubjectKeyIdentifier) ? 2 : 0);
+                       _version = 0;
                }
 
                public SignedCms (SubjectIdentifierType signerIdentifierType, 
ContentInfo content, bool detached) 
                        : this (content, detached) 
                {
                        _type = signerIdentifierType;
-                       _version = ((_type == 
SubjectIdentifierType.SubjectKeyIdentifier) ? 2 : 0);
+                       _version = 0;
                }
 
                // properties
@@ -158,11 +158,16 @@
                        ComputeSignature ();
                }
 
-               private string ToString (byte[] array) 
+               private string ToString (byte[] array, bool reverse) 
                {
                        StringBuilder sb = new StringBuilder ();
-                       foreach (byte b in array)
-                               sb.Append (b.ToString ("X2"));
+                       if (reverse) {
+                               for (int i=array.Length - 1; i >= 0; i--)
+                                       sb.Append (array [i].ToString ("X2"));
+                       } else {
+                               for (int i=0; i < array.Length; i++)
+                                       sb.Append (array [i].ToString ("X2"));
+                       }
                        return sb.ToString ();
                }
 
@@ -213,12 +218,12 @@
                                type = 
SubjectIdentifierType.IssuerAndSerialNumber;
                                X509IssuerSerial xis = new X509IssuerSerial ();
                                xis.IssuerName = sd.SignerInfo.IssuerName;
-                               xis.SerialNumber = ToString (serial);
+                               xis.SerialNumber = ToString (serial, true);
                                o = xis;
                                // TODO: move to a FindCertificate (issuer, 
serial, collection)
                                foreach (Mono.Security.X509.X509Certificate x 
in sd.Certificates) {
                                        if (x.IssuerName == 
sd.SignerInfo.IssuerName) {
-                                               if (ToString (x.SerialNumber) 
== xis.SerialNumber) {
+                                               if (ToString (x.SerialNumber, 
true) == xis.SerialNumber) {
                                                        x509 = new 
X509Certificate2 (x.RawData);
                                                        break;
                                                }
@@ -226,12 +231,12 @@
                                }
                        }
                        else if (sd.SignerInfo.SubjectKeyIdentifier != null) {
-                               string ski = ToString 
(sd.SignerInfo.SubjectKeyIdentifier);
+                               string ski = ToString 
(sd.SignerInfo.SubjectKeyIdentifier, false);
                                type = 
SubjectIdentifierType.SubjectKeyIdentifier;
                                o = (object) ski;
                                // TODO: move to a FindCertificate (ski, 
collection)
                                foreach (Mono.Security.X509.X509Certificate x 
in sd.Certificates) {
-                                       if (ToString (GetKeyIdentifier (x)) == 
ski) {
+                                       if (ToString (GetKeyIdentifier (x), 
false) == ski) {
                                                x509 = new X509Certificate2 
(x.RawData);
                                                break;
                                        }

Modified: 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfo.cs
===================================================================
--- 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfo.cs 
    2005-05-03 17:53:51 UTC (rev 43969)
+++ 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfo.cs 
    2005-05-03 17:55:44 UTC (rev 43970)
@@ -44,9 +44,9 @@
                private int _version;
 
                // only accessible from SignedPkcs7.SignerInfos
-               internal SignerInfo (string hashOid, X509Certificate2 
certificate, SubjectIdentifierType type, object o, int version)
+               internal SignerInfo (string hashName, X509Certificate2 
certificate, SubjectIdentifierType type, object o, int version)
                {
-                       _digest = new Oid (hashOid);
+                       _digest = new Oid (CryptoConfig.MapNameToOID 
(hashName));
                        _certificate = certificate;
                        _counter = new SignerInfoCollection ();
                        _signed = new CryptographicAttributeObjectCollection ();

Modified: 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfoCollection.cs
===================================================================
--- 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfoCollection.cs
   2005-05-03 17:53:51 UTC (rev 43969)
+++ 
trunk/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfoCollection.cs
   2005-05-03 17:55:44 UTC (rev 43970)
@@ -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-2005 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
@@ -29,7 +29,6 @@
 
 #if NET_2_0
 
-using System;
 using System.Collections;
 
 namespace System.Security.Cryptography.Pkcs {
@@ -51,7 +50,7 @@
                }
 
                public bool IsSynchronized {
-                       get { return _list.IsSynchronized; }
+                       get { return false; }   // as documented
                }
 
                public SignerInfo this [int index] {
@@ -71,12 +70,22 @@
 
                public void CopyTo (Array array, int index) 
                {
+                       if (array == null)
+                               throw new ArgumentNullException ("array");
+                       if ((index < 0) || (index >= array.Length))
+                               throw new ArgumentOutOfRangeException ("index");
+
                        _list.CopyTo (array, index);
                }
 
-               [MonoTODO]
                public void CopyTo (SignerInfo[] array, int index)
                {
+                       if (array == null)
+                               throw new ArgumentNullException ("array");
+                       if ((index < 0) || (index >= array.Length))
+                               throw new ArgumentOutOfRangeException ("index");
+
+                       _list.CopyTo (array, index);
                }
 
                public SignerInfoEnumerator GetEnumerator ()

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

Reply via email to