Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Pouliot <sebastien@ximian.com>2004-07-09 05:58:38 +0400
committerSebastien Pouliot <sebastien@ximian.com>2004-07-09 05:58:38 +0400
commit5639cacb2cc86f6b0927fa2b654fd4dfc1e045aa (patch)
tree356beb0747fc9a55c8dbed2c2a2dd5472bc48a4f /mcs/class/System.Security/System.Security.Cryptography.Pkcs
parent87fcf57b04350f5eba794abf362623924463726c (diff)
2004-07-08 Sebastien Pouliot <sebastien@ximian.com>
* ContentInfo.cs: Added finalizer. * CmsRecipient.cs: New. Replace Pkcs7Recipient (from 1.2). * CmsRecipientCollection.cs: New. Replace Pkcs7RecipientCollection (from 1.2). * CmsRecipientEnumerator.cs: New. Replace Pkcs7RecipientEnumerator (from 1.2). * CmsSigner.cs: New. Replace Pkcs7Signer (from 1.2). * EnvelopedCms.cs: New. Replace EnvelopedPkcs7 (from 1.2). * KeyAgreeRecipientInfo.cs: Fixed internal constructor. * Pkcs9Attribute.cs: Now inherit from AsnEncodedData. Fixed constructors. * Pkcs9DocumentDescription.cs: Sealed class and fixed API. * Pkcs9DocumentName.cs: Sealed class and fixed API. * Pkcs9SigningTime.cs: Sealed class and fixed API. * PublicKeyInfo.cs: Sealed class. * RecipientInfo.cs: Removed protected constructor. * RecipientInfoCollection.cs: Sealed class. * RecipientInfoEnumerator.cs: Sealed class. * SignedCms.cs: New. Replace SignedPkcs7 (from 1.2). * SignerInfo.cs: Sealed class and fixed API. * SignerInfoCollection.cs: Sealed class and fixed CopyTo. * SignerInfoEnumerator.cs: Sealed class. * SubjectIdentifier.cs: Sealed class. * SubjectIdentifierOrKey.cs: Sealed class. * SubjectIdentifierType.cs: Fixed enum and added [Serializable]. svn path=/trunk/mcs/; revision=30907
Diffstat (limited to 'mcs/class/System.Security/System.Security.Cryptography.Pkcs')
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/ChangeLog28
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsRecipient.cs77
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsRecipientCollection.cs114
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsRecipientEnumerator.cs72
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsSigner.cs130
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/ContentInfo.cs6
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/EnvelopedCms.cs246
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/KeyAgreeRecipientInfo.cs14
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9Attribute.cs33
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9DocumentDescription.cs34
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9DocumentName.cs34
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9SigningTime.cs36
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/RecipientInfo.cs10
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/RecipientInfoCollection.cs9
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/RecipientInfoEnumerator.cs9
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/SignedCms.cs297
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfo.cs55
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfoCollection.cs14
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfoEnumerator.cs9
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/SubjectIdentifier.cs9
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/SubjectIdentifierOrKey.cs7
-rwxr-xr-xmcs/class/System.Security/System.Security.Cryptography.Pkcs/SubjectIdentifierType.cs14
22 files changed, 1161 insertions, 96 deletions
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ChangeLog b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ChangeLog
index dd8e202c8c0..be2804894f9 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ChangeLog
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ChangeLog
@@ -1,3 +1,31 @@
+2004-07-08 Sebastien Pouliot <sebastien@ximian.com>
+
+ * ContentInfo.cs: Added finalizer.
+ * CmsRecipient.cs: New. Replace Pkcs7Recipient (from 1.2).
+ * CmsRecipientCollection.cs: New. Replace Pkcs7RecipientCollection
+ (from 1.2).
+ * CmsRecipientEnumerator.cs: New. Replace Pkcs7RecipientEnumerator
+ (from 1.2).
+ * CmsSigner.cs: New. Replace Pkcs7Signer (from 1.2).
+ * EnvelopedCms.cs: New. Replace EnvelopedPkcs7 (from 1.2).
+ * KeyAgreeRecipientInfo.cs: Fixed internal constructor.
+ * Pkcs9Attribute.cs: Now inherit from AsnEncodedData. Fixed
+ constructors.
+ * Pkcs9DocumentDescription.cs: Sealed class and fixed API.
+ * Pkcs9DocumentName.cs: Sealed class and fixed API.
+ * Pkcs9SigningTime.cs: Sealed class and fixed API.
+ * PublicKeyInfo.cs: Sealed class.
+ * RecipientInfo.cs: Removed protected constructor.
+ * RecipientInfoCollection.cs: Sealed class.
+ * RecipientInfoEnumerator.cs: Sealed class.
+ * SignedCms.cs: New. Replace SignedPkcs7 (from 1.2).
+ * SignerInfo.cs: Sealed class and fixed API.
+ * SignerInfoCollection.cs: Sealed class and fixed CopyTo.
+ * SignerInfoEnumerator.cs: Sealed class.
+ * SubjectIdentifier.cs: Sealed class.
+ * SubjectIdentifierOrKey.cs: Sealed class.
+ * SubjectIdentifierType.cs: Fixed enum and added [Serializable].
+
2004-07-07 Sebastien Pouliot <sebastien@ximian.com>
* AlgorithmIdentifier.cs: Added missing #if NET_2_0.
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsRecipient.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsRecipient.cs
new file mode 100755
index 00000000000..a76b2fe4444
--- /dev/null
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsRecipient.cs
@@ -0,0 +1,77 @@
+//
+// System.Security.Cryptography.Pkcs.CmsRecipient
+//
+// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 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
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System;
+using System.Collections;
+using System.Security.Cryptography.X509Certificates;
+
+namespace System.Security.Cryptography.Pkcs {
+
+ public sealed class CmsRecipient {
+
+ private SubjectIdentifierType _recipient;
+ private X509CertificateEx _certificate;
+
+ // constructor
+
+ public CmsRecipient (X509CertificateEx certificate)
+ {
+ if (certificate == null)
+ throw new ArgumentNullException ("certificate");
+ _recipient = SubjectIdentifierType.IssuerAndSerialNumber;
+ _certificate = certificate;
+ }
+
+ public CmsRecipient (SubjectIdentifierType recipientIdentifierType, X509CertificateEx certificate)
+ {
+ if (certificate == null)
+ throw new ArgumentNullException ("certificate");
+
+ if (recipientIdentifierType == SubjectIdentifierType.Unknown)
+ _recipient = SubjectIdentifierType.IssuerAndSerialNumber;
+ else
+ _recipient = recipientIdentifierType;
+ _certificate = certificate;
+ }
+
+ // properties
+
+ public X509CertificateEx Certificate {
+ get { return _certificate; }
+ }
+
+ public SubjectIdentifierType RecipientIdentifierType {
+ get { return _recipient; }
+ }
+ }
+}
+
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsRecipientCollection.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsRecipientCollection.cs
new file mode 100755
index 00000000000..19ce8e13221
--- /dev/null
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsRecipientCollection.cs
@@ -0,0 +1,114 @@
+//
+// System.Security.Cryptography.Pkcs.CmsRecipientCollection
+//
+// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 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
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System;
+using System.Collections;
+using System.Security.Cryptography.X509Certificates;
+
+namespace System.Security.Cryptography.Pkcs {
+
+ public sealed class CmsRecipientCollection : ICollection, IEnumerable {
+
+ private ArrayList _list;
+
+ // constructors
+
+ public CmsRecipientCollection ()
+ {
+ _list = new ArrayList ();
+ }
+
+ public CmsRecipientCollection (CmsRecipient recipient) : base ()
+ {
+ _list.Add (recipient);
+ }
+
+ public CmsRecipientCollection (SubjectIdentifierType recipientIdentifierType, X509CertificateExCollection certificates) : base ()
+ {
+ foreach (X509CertificateEx x509 in certificates) {
+ CmsRecipient p7r = new CmsRecipient (recipientIdentifierType, x509);
+ _list.Add (p7r);
+ }
+ }
+
+ // properties
+
+ public int Count {
+ get { return _list.Count; }
+ }
+
+ public bool IsSynchronized {
+ get { return _list.IsSynchronized; }
+ }
+
+ public CmsRecipient this [int index] {
+ get { return (CmsRecipient) _list [index]; }
+ }
+
+ public object SyncRoot {
+ get { return _list.SyncRoot; }
+ }
+
+ // methods
+
+ public int Add (CmsRecipient recipient)
+ {
+ return _list.Add (recipient);
+ }
+
+ public void CopyTo (Array array, int index)
+ {
+ _list.CopyTo (array, index);
+ }
+
+ public void CopyTo (CmsRecipient[] array, int index)
+ {
+ _list.CopyTo (array, index);
+ }
+
+ public CmsRecipientEnumerator GetEnumerator ()
+ {
+ return new CmsRecipientEnumerator (_list);
+ }
+
+ IEnumerator IEnumerable.GetEnumerator ()
+ {
+ return new CmsRecipientEnumerator (_list);
+ }
+
+ public void Remove (CmsRecipient recipient)
+ {
+ _list.Remove (recipient);
+ }
+ }
+}
+
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsRecipientEnumerator.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsRecipientEnumerator.cs
new file mode 100755
index 00000000000..a3bc1a13d04
--- /dev/null
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsRecipientEnumerator.cs
@@ -0,0 +1,72 @@
+//
+// System.Security.Cryptography.Pkcs.CmsRecipientEnumerator
+//
+// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 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
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System;
+using System.Collections;
+
+namespace System.Security.Cryptography.Pkcs {
+
+ public sealed class CmsRecipientEnumerator : IEnumerator {
+
+ private IEnumerator enumerator;
+
+ // constructors
+
+ internal CmsRecipientEnumerator (IEnumerable enumerable)
+ {
+ enumerator = enumerable.GetEnumerator ();
+ }
+
+ // properties
+
+ public CmsRecipient Current {
+ get { return (CmsRecipient) enumerator.Current; }
+ }
+
+ object IEnumerator.Current {
+ get { return enumerator.Current; }
+ }
+
+ // methods
+
+ public bool MoveNext ()
+ {
+ return enumerator.MoveNext ();
+ }
+
+ public void Reset ()
+ {
+ enumerator.Reset ();
+ }
+ }
+}
+
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsSigner.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsSigner.cs
new file mode 100755
index 00000000000..1cfc75ae646
--- /dev/null
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/CmsSigner.cs
@@ -0,0 +1,130 @@
+//
+// System.Security.Cryptography.Pkcs.CmsSigner
+//
+// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 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
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System;
+using System.Security.Cryptography.X509Certificates;
+
+namespace System.Security.Cryptography.Pkcs {
+
+ public sealed class CmsSigner {
+
+ private SubjectIdentifierType _signer;
+ private X509CertificateEx _certificate;
+ private X509CertificateExCollection _coll;
+ private Oid _digest;
+ private X509IncludeOption _options;
+ private CryptographicAttributeCollection _signed;
+ private CryptographicAttributeCollection _unsigned;
+
+ // constructors
+
+ public CmsSigner ()
+ {
+ _signer = SubjectIdentifierType.IssuerAndSerialNumber;
+ _digest = new Oid ("1.3.14.3.2.26");
+ _options = X509IncludeOption.ExcludeRoot;
+ _signed = new CryptographicAttributeCollection ();
+ _unsigned = new CryptographicAttributeCollection ();
+ _coll = new X509CertificateExCollection ();
+ }
+
+ public CmsSigner (SubjectIdentifierType signerIdentifierType) : this ()
+ {
+ if (signerIdentifierType == SubjectIdentifierType.Unknown)
+ _signer = SubjectIdentifierType.IssuerAndSerialNumber;
+ else
+ _signer = signerIdentifierType;
+ }
+
+ public CmsSigner (SubjectIdentifierType signerIdentifierType, X509CertificateEx certificate)
+ : this (signerIdentifierType)
+ {
+// FIXME: compatibility with fx 1.2.3400.0
+// if (certificate == null)
+// throw new ArgumentNullException ("certificate");
+ _certificate = certificate;
+ }
+
+ public CmsSigner (X509CertificateEx certificate) : this ()
+ {
+// FIXME: compatibility with fx 1.2.3400.0
+// if (certificate == null)
+// throw new ArgumentNullException ("certificate");
+ _certificate = certificate;
+ }
+
+ [MonoTODO]
+ public CmsSigner (CspParameters parameters) : this ()
+ {
+ }
+
+ // properties
+
+ public CryptographicAttributeCollection SignedAttributes {
+ get { return _signed; }
+ }
+
+ public X509CertificateEx Certificate {
+ get { return _certificate; }
+ set { _certificate = value; }
+ }
+
+ public X509CertificateExCollection Certificates {
+ get { return _coll; }
+ }
+
+ public Oid DigestAlgorithm {
+ get { return _digest; }
+ set { _digest = value; }
+ }
+
+ public X509IncludeOption IncludeOption {
+ get { return _options; }
+ set { _options = value; }
+ }
+
+ public SubjectIdentifierType SignerIdentifierType {
+ get { return _signer; }
+ set {
+ if (value == SubjectIdentifierType.Unknown)
+ throw new ArgumentException ("value");
+
+ _signer = value;
+ }
+ }
+
+ public CryptographicAttributeCollection UnsignedAttributes {
+ get { return _unsigned; }
+ }
+ }
+}
+
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ContentInfo.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ContentInfo.cs
index 23e9822e144..b5e9d25162e 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ContentInfo.cs
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/ContentInfo.cs
@@ -1,5 +1,5 @@
//
-// ContentInfo.cs - System.Security.Cryptography.Pkcs.ContentInfo
+// System.Security.Cryptography.Pkcs.ContentInfo
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
@@ -67,6 +67,10 @@ namespace System.Security.Cryptography.Pkcs {
_content = content;
}
+ ~ContentInfo ()
+ {
+ }
+
// properties
public byte[] Content {
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/EnvelopedCms.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/EnvelopedCms.cs
new file mode 100755
index 00000000000..6b1536e2516
--- /dev/null
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/EnvelopedCms.cs
@@ -0,0 +1,246 @@
+//
+// System.Security.Cryptography.Pkcs.EnvelopedCms
+//
+// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 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
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System;
+using System.Collections;
+using System.Security.Cryptography.X509Certificates;
+using System.Security.Cryptography.Xml;
+using System.Text;
+
+using Mono.Security;
+
+namespace System.Security.Cryptography.Pkcs {
+
+ // References
+ // a. PKCS #7: Cryptographic Message Syntax, Version 1.5, Section 10
+ // http://www.faqs.org/rfcs/rfc2315.html
+
+ public sealed class EnvelopedCms {
+
+ private ContentInfo _content;
+ private AlgorithmIdentifier _identifier;
+ private X509CertificateExCollection _certs;
+ private RecipientInfoCollection _recipients;
+ private CryptographicAttributeCollection _uattribs;
+ private SubjectIdentifierType _idType;
+ private int _version;
+
+ // constructors
+
+ public EnvelopedCms ()
+ {
+ _certs = new X509CertificateExCollection ();
+ _recipients = new RecipientInfoCollection ();
+ _uattribs = new CryptographicAttributeCollection ();
+ }
+
+ public EnvelopedCms (ContentInfo content) : this ()
+ {
+ if (content == null)
+ throw new ArgumentNullException ("content");
+
+ _content = content;
+ }
+
+ public EnvelopedCms (ContentInfo contentInfo, AlgorithmIdentifier encryptionAlgorithm)
+ : this (contentInfo)
+ {
+ if (encryptionAlgorithm == null)
+ throw new ArgumentNullException ("encryptionAlgorithm");
+
+ _identifier = encryptionAlgorithm;
+ }
+
+ public EnvelopedCms (SubjectIdentifierType recipientIdentifierType, ContentInfo contentInfo)
+ : this (contentInfo)
+ {
+ _idType = recipientIdentifierType;
+ _version = ((_idType == SubjectIdentifierType.SubjectKeyIdentifier) ? 2 : 0);
+ }
+
+ public EnvelopedCms (SubjectIdentifierType recipientIdentifierType, ContentInfo contentInfo, AlgorithmIdentifier encryptionAlgorithm)
+ : this (contentInfo, encryptionAlgorithm)
+ {
+ _idType = recipientIdentifierType;
+ _version = ((_idType == SubjectIdentifierType.SubjectKeyIdentifier) ? 2 : 0);
+ }
+
+ // properties
+
+ public X509CertificateExCollection Certificates {
+ get { return _certs; }
+ }
+
+ public AlgorithmIdentifier ContentEncryptionAlgorithm {
+ get {
+ if (_identifier == null)
+ _identifier = new AlgorithmIdentifier ();
+ return _identifier;
+ }
+ }
+
+ public ContentInfo ContentInfo {
+ get {
+ if (_content == null) {
+ Oid oid = new Oid (PKCS7.Oid.data);
+ _content = new ContentInfo (oid, new byte [0]);
+ }
+ return _content;
+ }
+ }
+
+ public RecipientInfoCollection RecipientInfos {
+ get { return _recipients; }
+ }
+
+ public CryptographicAttributeCollection UnprotectedAttributes {
+ get { return _uattribs; }
+ }
+
+ public int Version {
+ get { return _version; }
+ }
+
+ // methods
+
+ private X509IssuerSerial GetIssuerSerial (string issuer, byte[] serial)
+ {
+ X509IssuerSerial xis = new X509IssuerSerial ();
+ xis.IssuerName = issuer;
+ StringBuilder sb = new StringBuilder ();
+ foreach (byte b in serial)
+ sb.Append (b.ToString ("X2"));
+ xis.SerialNumber = sb.ToString ();
+ return xis;
+ }
+
+ [MonoTODO]
+ public void Decode (byte[] encodedMessage)
+ {
+ if (encodedMessage == null)
+ throw new ArgumentNullException ("encodedMessage");
+
+ PKCS7.ContentInfo ci = new PKCS7.ContentInfo (encodedMessage);
+ if (ci.ContentType != PKCS7.Oid.envelopedData)
+ throw new Exception ("");
+
+ PKCS7.EnvelopedData ed = new PKCS7.EnvelopedData (ci.Content);
+
+ Oid oid = new Oid (ed.ContentInfo.ContentType);
+ _content = new ContentInfo (oid, new byte [0]); //ed.ContentInfo.Content.Value);
+
+ foreach (PKCS7.RecipientInfo ri in ed.RecipientInfos) {
+ Oid o = new Oid (ri.Oid);
+ AlgorithmIdentifier ai = new AlgorithmIdentifier (o);
+ SubjectIdentifier si = null;
+ if (ri.SubjectKeyIdentifier != null) {
+ si = new SubjectIdentifier (SubjectIdentifierType.SubjectKeyIdentifier, ri.SubjectKeyIdentifier);
+ }
+ else if ((ri.Issuer != null) && (ri.Serial != null)) {
+ X509IssuerSerial xis = GetIssuerSerial (ri.Issuer, ri.Serial);
+ si = new SubjectIdentifier (SubjectIdentifierType.IssuerAndSerialNumber, (object)xis);
+ }
+
+ KeyTransRecipientInfo _keyTrans = new KeyTransRecipientInfo (ri.Key, ai, si, ri.Version);
+ _recipients.Add (_keyTrans);
+ }
+
+ // TODO - Certificates
+ // TODO - UnprotectedAttributes
+
+ _version = ed.Version;
+ }
+
+ [MonoTODO]
+ public void Decrypt ()
+ {
+ throw new InvalidOperationException ("not encrypted");
+ }
+
+ [MonoTODO]
+ public void Decrypt (RecipientInfo recipientInfo)
+ {
+ if (recipientInfo == null)
+ throw new ArgumentNullException ("recipientInfo");
+ Decrypt ();
+ }
+
+ [MonoTODO]
+ public void Decrypt (RecipientInfo recipientInfo, X509CertificateExCollection extraStore)
+ {
+ if (recipientInfo == null)
+ throw new ArgumentNullException ("recipientInfo");
+ if (extraStore == null)
+ throw new ArgumentNullException ("extraStore");
+ Decrypt ();
+ }
+
+ [MonoTODO]
+ public void Decrypt (X509CertificateExCollection extraStore)
+ {
+ if (extraStore == null)
+ throw new ArgumentNullException ("extraStore");
+ Decrypt ();
+ }
+
+ [MonoTODO]
+ public byte[] Encode ()
+ {
+ throw new InvalidOperationException ("not encrypted");
+ }
+
+ [MonoTODO]
+ public void Encrypt ()
+ {
+ if ((_content.Content == null) || (_content.Content.Length == 0))
+ throw new CryptographicException ("no content to encrypt");
+ }
+
+ [MonoTODO]
+ public void Encrypt (CmsRecipient recipient)
+ {
+ if (recipient == null)
+ throw new ArgumentNullException ("recipient");
+ // TODO
+ Encrypt ();
+ }
+
+ [MonoTODO]
+ public void Encrypt (CmsRecipientCollection recipients)
+ {
+ if (recipients == null)
+ throw new ArgumentNullException ("recipients");
+ // ? foreach on Encrypt CmsRecipient ?
+ }
+ }
+}
+
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/KeyAgreeRecipientInfo.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/KeyAgreeRecipientInfo.cs
index abdcc8e9512..c3418b6e508 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/KeyAgreeRecipientInfo.cs
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/KeyAgreeRecipientInfo.cs
@@ -2,11 +2,10 @@
// KeyAgreeRecipientInfo.cs - System.Security.Cryptography.Pkcs.KeyAgreeRecipientInfo
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
+// Copyright (C) 2004 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
@@ -37,8 +36,11 @@ namespace System.Security.Cryptography.Pkcs {
[MonoTODO]
public sealed class KeyAgreeRecipientInfo : RecipientInfo {
- // only accessible from EnvelopedPkcs7.RecipientInfos
- internal KeyAgreeRecipientInfo () {}
+ // only accessible from EnvelopedCms.RecipientInfos
+ internal KeyAgreeRecipientInfo ()
+ : base (RecipientInfoType.KeyAgreement)
+ {
+ }
public DateTime Date {
get { return DateTime.MinValue; }
@@ -70,4 +72,4 @@ namespace System.Security.Cryptography.Pkcs {
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9Attribute.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9Attribute.cs
index dff8e295f10..931ee9e2efb 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9Attribute.cs
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9Attribute.cs
@@ -2,11 +2,10 @@
// Pkcs9Attribute.cs - System.Security.Cryptography.Pkcs.Pkcs9Attribute
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
+// Copyright (C) 2004 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
@@ -35,16 +34,34 @@ using System.Collections;
namespace System.Security.Cryptography.Pkcs {
- public class Pkcs9Attribute : CryptographicAttribute {
+ public class Pkcs9Attribute : AsnEncodedData {
// constructors
- public Pkcs9Attribute (Oid oid) : base (oid) {}
+ public Pkcs9Attribute ()
+ : base ()
+ {
+ }
+
+ public Pkcs9Attribute (AsnEncodedData asnEncodedData)
+ : base (asnEncodedData)
+ {
+ }
+
+ public Pkcs9Attribute (Oid oid, byte[] encodedData)
+ : base (oid, encodedData)
+ {
+ }
- public Pkcs9Attribute (Oid oid, ArrayList values) : base (oid, values) {}
+ public Pkcs9Attribute (string oid, byte[] encodedData)
+ : base (oid, encodedData)
+ {
+ }
- public Pkcs9Attribute (Oid oid, object value) : base (oid, value) {}
+ public new Oid Oid {
+ get { return base.Oid; }
+ }
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9DocumentDescription.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9DocumentDescription.cs
index 7654254c00b..af6668fc62b 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9DocumentDescription.cs
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9DocumentDescription.cs
@@ -2,11 +2,10 @@
// Pkcs9DocumentDescription.cs - System.Security.Cryptography.Pkcs.Pkcs9DocumentDescription
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
+// Copyright (C) 2004 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
@@ -31,16 +30,39 @@
#if NET_2_0
using System;
+using System.Text;
namespace System.Security.Cryptography.Pkcs {
- public class Pkcs9DocumentDescription : Pkcs9Attribute {
+ public sealed class Pkcs9DocumentDescription : Pkcs9Attribute {
private const string oid = "1.3.6.1.4.1.311.88.2.2";
+ private string _desc;
+
+ [MonoTODO ("encode for RawData using Mono.Security")]
+ public Pkcs9DocumentDescription ()
+ : base (new Oid (oid), null)
+ {
+ }
+
+ [MonoTODO ("encode for RawData using Mono.Security")]
public Pkcs9DocumentDescription (string documentDescription)
- : base (new Oid (oid), documentDescription) {}
+ : base (new Oid (oid), Encoding.Unicode.GetBytes (documentDescription))
+ {
+ _desc = documentDescription;
+ }
+
+ [MonoTODO ("decode using Mono.Security")]
+ public Pkcs9DocumentDescription (byte[] encodedDocumentDescription)
+ : base (new Oid (oid), encodedDocumentDescription)
+ {
+ }
+
+ public string DocumentDescription {
+ get { return _desc; }
+ }
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9DocumentName.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9DocumentName.cs
index 60a917efff2..f1653eb3802 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9DocumentName.cs
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9DocumentName.cs
@@ -2,11 +2,10 @@
// Pkcs9DocumentName.cs - System.Security.Cryptography.Pkcs.Pkcs9DocumentName
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
+// Copyright (C) 2004 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
@@ -31,16 +30,39 @@
#if NET_2_0
using System;
+using System.Text;
namespace System.Security.Cryptography.Pkcs {
- public class Pkcs9DocumentName : Pkcs9Attribute {
+ public sealed class Pkcs9DocumentName : Pkcs9Attribute {
private const string oid = "1.3.6.1.4.1.311.88.2.1";
+ private string _name;
+
+ [MonoTODO ("encode for RawData using Mono.Security")]
+ public Pkcs9DocumentName ()
+ : base (new Oid (oid), null)
+ {
+ }
+
+ [MonoTODO ("encode for RawData using Mono.Security")]
public Pkcs9DocumentName (string documentName)
- : base (new Oid (oid), documentName) {}
+ : base (new Oid (oid), Encoding.Unicode.GetBytes (documentName))
+ {
+ _name = documentName;
+ }
+
+ [MonoTODO ("decode using Mono.Security")]
+ public Pkcs9DocumentName (byte[] encodedDocumentName)
+ : base (new Oid (oid), encodedDocumentName)
+ {
+ }
+
+ public string DocumentName {
+ get { return _name; }
+ }
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9SigningTime.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9SigningTime.cs
index 9ecb5d73a8f..fb24b4bc769 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9SigningTime.cs
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/Pkcs9SigningTime.cs
@@ -2,11 +2,10 @@
// Pkcs9SigningTime.cs - System.Security.Cryptography.Pkcs.Pkcs9SigningTime
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
+// Copyright (C) 2004 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,16 +33,37 @@ using System;
namespace System.Security.Cryptography.Pkcs {
- public class Pkcs9SigningTime : Pkcs9Attribute {
+ public sealed class Pkcs9SigningTime : Pkcs9Attribute {
private const string oid = "1.2.840.113549.1.9.5";
private const string name = "Signing Time";
- public Pkcs9SigningTime () : this (DateTime.Now) {}
+ private DateTime _signingTime;
+
+ [MonoTODO ("encode for RawData using Mono.Security")]
+ public Pkcs9SigningTime ()
+ : base (new Oid (oid, name), null)
+ {
+ _signingTime = DateTime.Now;
+ }
+
+ [MonoTODO ("encode for RawData using Mono.Security")]
+ public Pkcs9SigningTime (DateTime signingTime)
+ : base (new Oid (oid, name), null)
+ {
+ _signingTime = signingTime;
+ }
+
+ [MonoTODO ("decode using Mono.Security")]
+ public Pkcs9SigningTime (byte[] encodedSigningTime)
+ : base (new Oid (oid, name), null)
+ {
+ }
- public Pkcs9SigningTime (DateTime signingTime)
- : base (new Oid (oid, name), signingTime) {}
+ public DateTime SigningTime {
+ get { return _signingTime; }
+ }
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/RecipientInfo.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/RecipientInfo.cs
index 3f1489fa0cc..3d843fec940 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/RecipientInfo.cs
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/RecipientInfo.cs
@@ -2,11 +2,10 @@
// RecipientInfo.cs - System.Security.Cryptography.Pkcs.RecipientInfo
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
+// Copyright (C) 2004 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
@@ -40,9 +39,6 @@ namespace System.Security.Cryptography.Pkcs {
// constructors
- protected RecipientInfo () {}
-
-
// documented as protected at http://longhorn.msdn.microsoft.com
// but not present in the 1.2 beta SDK
internal RecipientInfo (RecipientInfoType recipInfoType)
@@ -66,4 +62,4 @@ namespace System.Security.Cryptography.Pkcs {
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/RecipientInfoCollection.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/RecipientInfoCollection.cs
index 7e56687e875..bf64f1742a1 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/RecipientInfoCollection.cs
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/RecipientInfoCollection.cs
@@ -2,11 +2,10 @@
// RecipientInfoCollection.cs - System.Security.Cryptography.Pkcs.RecipientInfoCollection
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
+// Copyright (C) 2004 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
@@ -35,7 +34,7 @@ using System.Collections;
namespace System.Security.Cryptography.Pkcs {
- public class RecipientInfoCollection : ICollection {
+ public sealed class RecipientInfoCollection : ICollection {
private ArrayList _list;
@@ -92,4 +91,4 @@ namespace System.Security.Cryptography.Pkcs {
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/RecipientInfoEnumerator.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/RecipientInfoEnumerator.cs
index c052f7962bd..95468d8c094 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/RecipientInfoEnumerator.cs
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/RecipientInfoEnumerator.cs
@@ -2,11 +2,10 @@
// RecipientInfoEnumerator.cs - System.Security.Cryptography.Pkcs.RecipientInfoEnumerator
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
+// Copyright (C) 2004 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
@@ -35,7 +34,7 @@ using System.Collections;
namespace System.Security.Cryptography.Pkcs {
- public class RecipientInfoEnumerator : IEnumerator {
+ public sealed class RecipientInfoEnumerator : IEnumerator {
private IEnumerator enumerator;
@@ -70,4 +69,4 @@ namespace System.Security.Cryptography.Pkcs {
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignedCms.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignedCms.cs
new file mode 100755
index 00000000000..28e9c0ce836
--- /dev/null
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignedCms.cs
@@ -0,0 +1,297 @@
+//
+// System.Security.Cryptography.Pkcs.SignedCms
+//
+// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 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
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System;
+using System.Security.Cryptography.X509Certificates;
+using System.Security.Cryptography.Xml;
+using System.Text;
+
+using Mono.Security;
+using Mono.Security.X509;
+
+namespace System.Security.Cryptography.Pkcs {
+
+ public sealed class SignedCms {
+
+ private ContentInfo _content;
+ private bool _detached;
+ private SignerInfoCollection _info;
+ private X509CertificateExCollection _certs;
+ private SubjectIdentifierType _type;
+ private int _version;
+
+ // constructors
+
+ public SignedCms ()
+ {
+ _certs = new X509CertificateExCollection ();
+ _info = new SignerInfoCollection ();
+ }
+
+ public SignedCms (ContentInfo content)
+ : this (content, false)
+ {
+ }
+
+ public SignedCms (ContentInfo content, bool detached)
+ : this ()
+ {
+ if (content == null)
+ throw new ArgumentNullException ("content");
+
+ _content = content;
+ _detached = detached;
+ }
+
+ public SignedCms (SubjectIdentifierType signerIdentifierType) : this ()
+ {
+ _type = signerIdentifierType;
+ _version = ((_type == SubjectIdentifierType.SubjectKeyIdentifier) ? 2 : 0);
+ }
+
+ public SignedCms (SubjectIdentifierType signerIdentifierType, ContentInfo content)
+ : this (content, false)
+ {
+ _type = signerIdentifierType;
+ _version = ((_type == SubjectIdentifierType.SubjectKeyIdentifier) ? 2 : 0);
+ }
+
+ public SignedCms (SubjectIdentifierType signerIdentifierType, ContentInfo content, bool detached)
+ : this (content, detached)
+ {
+ _type = signerIdentifierType;
+ _version = ((_type == SubjectIdentifierType.SubjectKeyIdentifier) ? 2 : 0);
+ }
+
+ // properties
+
+ public X509CertificateExCollection Certificates {
+ get { return _certs; }
+ }
+
+ public ContentInfo ContentInfo {
+ get {
+ if (_content == null) {
+ Oid oid = new Oid (PKCS7.Oid.data);
+ _content = new ContentInfo (oid, new byte [0]);
+ }
+ return _content;
+ }
+ }
+
+ public bool Detached {
+ get { return _detached; }
+ }
+
+ public SignerInfoCollection SignerInfos {
+ get { return _info; }
+ }
+
+ public int Version {
+ get { return _version; }
+ }
+
+ // methods
+
+ public void CheckSignature (bool verifySignatureOnly)
+ {
+ foreach (SignerInfo si in _info) {
+ si.CheckSignature (verifySignatureOnly);
+ }
+ }
+
+ public void CheckSignature (X509CertificateExCollection extraStore, bool verifySignatureOnly)
+ {
+ foreach (SignerInfo si in _info) {
+ si.CheckSignature (extraStore, verifySignatureOnly);
+ }
+ }
+
+ [MonoTODO]
+ public void CheckHash ()
+ {
+ throw new InvalidOperationException ("");
+ }
+
+ [MonoTODO]
+ public void ComputeSignature ()
+ {
+ throw new CryptographicException ("");
+ }
+
+ [MonoTODO]
+ public void ComputeSignature (CmsSigner signer)
+ {
+ ComputeSignature ();
+ }
+
+ [MonoTODO]
+ public void ComputeSignature (CmsSigner signer, bool silent)
+ {
+ ComputeSignature ();
+ }
+
+ private string ToString (byte[] array)
+ {
+ StringBuilder sb = new StringBuilder ();
+ foreach (byte b in array)
+ sb.Append (b.ToString ("X2"));
+ return sb.ToString ();
+ }
+
+ private byte[] GetKeyIdentifier (Mono.Security.X509.X509Certificate x509)
+ {
+ // if present in certificate return value of the SubjectKeyIdentifier
+ Mono.Security.X509.X509Extension extn = x509.Extensions ["2.5.29.14"];
+ if (extn != null) {
+ ASN1 bs = new ASN1 (extn.Value.Value);
+ return bs.Value;
+ }
+ // strangely DEPRECATED keyAttributes isn't used here (like KeyUsage)
+
+ // if not then we must calculate the SubjectKeyIdentifier ourselve
+ // Note: MS does that hash on the complete subjectPublicKeyInfo (unlike PKIX)
+ // http://groups.google.ca/groups?selm=e7RqM%24plCHA.1488%40tkmsftngp02&oe=UTF-8&output=gplain
+ ASN1 subjectPublicKeyInfo = new ASN1 (0x30);
+ ASN1 algo = subjectPublicKeyInfo.Add (new ASN1 (0x30));
+ algo.Add (new ASN1 (CryptoConfig.EncodeOID (x509.KeyAlgorithm)));
+ // FIXME: does it work for DSA certs (without an 2.5.29.14 extension ?)
+ algo.Add (new ASN1 (x509.KeyAlgorithmParameters));
+ byte[] pubkey = x509.PublicKey;
+ byte[] bsvalue = new byte [pubkey.Length + 1]; // add unused bits (0) before the public key
+ Array.Copy (pubkey, 0, bsvalue, 1, pubkey.Length);
+ subjectPublicKeyInfo.Add (new ASN1 (0x03, bsvalue));
+ SHA1 sha = SHA1.Create ();
+ return sha.ComputeHash (subjectPublicKeyInfo.GetBytes ());
+ }
+
+ [MonoTODO("incomplete - missing attributes")]
+ public void Decode (byte[] encodedMessage)
+ {
+ PKCS7.ContentInfo ci = new PKCS7.ContentInfo (encodedMessage);
+ if (ci.ContentType != PKCS7.Oid.signedData)
+ throw new Exception ("");
+
+ PKCS7.SignedData sd = new PKCS7.SignedData (ci.Content);
+ SubjectIdentifierType type = SubjectIdentifierType.Unknown;
+ object o = null;
+
+ X509CertificateEx x509 = null;
+ if (sd.SignerInfo.Certificate != null) {
+ x509 = new X509CertificateEx (sd.SignerInfo.Certificate.RawData);
+ }
+ else if ((sd.SignerInfo.IssuerName != null) && (sd.SignerInfo.SerialNumber != null)) {
+ byte[] serial = sd.SignerInfo.SerialNumber;
+ Array.Reverse (serial); // ???
+ type = SubjectIdentifierType.IssuerAndSerialNumber;
+ X509IssuerSerial xis = new X509IssuerSerial ();
+ xis.IssuerName = sd.SignerInfo.IssuerName;
+ xis.SerialNumber = ToString (serial);
+ 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) {
+ x509 = new X509CertificateEx (x.RawData);
+ break;
+ }
+ }
+ }
+ }
+ else if (sd.SignerInfo.SubjectKeyIdentifier != null) {
+ string ski = ToString (sd.SignerInfo.SubjectKeyIdentifier);
+ 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) {
+ x509 = new X509CertificateEx (x.RawData);
+ break;
+ }
+ }
+ }
+
+ SignerInfo si = new SignerInfo (sd.SignerInfo.HashName, x509, type, o, sd.SignerInfo.Version);
+ // si.AuthenticatedAttributes
+ // si.UnauthenticatedAttributes
+ _info.Add (si);
+
+ ASN1 content = sd.ContentInfo.Content;
+ Oid oid = new Oid (sd.ContentInfo.ContentType);
+ _content = new ContentInfo (oid, content[0].Value);
+
+ foreach (Mono.Security.X509.X509Certificate x in sd.Certificates) {
+ _certs.Add (new X509CertificateEx (x.RawData));
+ }
+
+ _version = sd.Version;
+ }
+
+ [MonoTODO]
+ public byte[] Encode ()
+ {
+ Mono.Security.X509.X509Certificate x509 = null;
+/* Cms.SignerInfo si = new Cms.SignerInfo ();
+ switch (_type) {
+ case SubjectIdentifierType.SubjectKeyIdentifier:
+ si.SubjectKeyIdentifier = GetKeyIdentifier (x509);
+ break;
+ default:
+ // SubjectIdentifierType.IssuerAndSerialNumber
+ si.IssuerName = x509.IssuerName;
+ si.SerialNumber = x509.SerialNumber;
+ break;
+ }
+
+ Cms.SignedData sd = new Cms.SignedData ();
+ sd.Version = _version;
+ sd.SignerInfo = si;
+
+ Cms.ContentInfo ci = new Cms.ContentInfo (Cms.signedData);
+ ci.Content = sd.ASN1;
+ return ci.GetBytes ();*/
+ return null;
+ }
+
+ // counterSsignerInfo -> counterSignerInfo
+ [MonoTODO]
+ public void RemoveSignature (SignerInfo counterSsignerInfo)
+ {
+ }
+
+ [MonoTODO]
+ public void RemoveSignature (int index)
+ {
+ }
+ }
+}
+
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfo.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfo.cs
index ebdc227db4c..0dcb60e5eff 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfo.cs
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfo.cs
@@ -2,11 +2,10 @@
// SignerInfo.cs - System.Security.Cryptography.Pkcs.SignerInfo
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
+// Copyright (C) 2004 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
@@ -35,14 +34,14 @@ using System.Security.Cryptography.X509Certificates;
namespace System.Security.Cryptography.Pkcs {
- public class SignerInfo {
+ public sealed class SignerInfo {
private SubjectIdentifier _signer;
private X509CertificateEx _certificate;
private Oid _digest;
private SignerInfoCollection _counter;
- private Pkcs9AttributeCollection _auth;
- private Pkcs9AttributeCollection _unauth;
+ private CryptographicAttributeCollection _signed;
+ private CryptographicAttributeCollection _unsigned;
private int _version;
// only accessible from SignedPkcs7.SignerInfos
@@ -51,16 +50,16 @@ namespace System.Security.Cryptography.Pkcs {
_digest = new Oid (hashOid);
_certificate = certificate;
_counter = new SignerInfoCollection ();
- _auth = new Pkcs9AttributeCollection ();
- _unauth = new Pkcs9AttributeCollection ();
+ _signed = new CryptographicAttributeCollection ();
+ _unsigned = new CryptographicAttributeCollection ();
_signer = new SubjectIdentifier (type, o);
_version = version;
}
// properties
- public Pkcs9AttributeCollection AuthenticatedAttributes {
- get { return _auth; }
+ public CryptographicAttributeCollection SignedAttributes {
+ get { return _signed; }
}
public X509CertificateEx Certificate {
@@ -79,8 +78,8 @@ namespace System.Security.Cryptography.Pkcs {
get { return _signer; }
}
- public Pkcs9AttributeCollection UnauthenticatedAttributes {
- get { return _unauth; }
+ public CryptographicAttributeCollection UnsignedAttributes {
+ get { return _unsigned; }
}
public int Version {
@@ -90,20 +89,40 @@ namespace System.Security.Cryptography.Pkcs {
// methods
[MonoTODO]
- public void CheckSignature (bool verifySignatureOnly) {}
+ public void CheckHash ()
+ {
+ }
+
+ [MonoTODO]
+ public void CheckSignature (bool verifySignatureOnly)
+ {
+ }
+
+ [MonoTODO]
+ public void CheckSignature (X509CertificateExCollection extraStore, bool verifySignatureOnly)
+ {
+ }
[MonoTODO]
- public void CheckSignature (X509CertificateExCollection extraStore, bool verifySignatureOnly) {}
+ public void ComputeCounterSignature ()
+ {
+ }
[MonoTODO]
- public void ComputeCounterSignature () {}
+ public void ComputeCounterSignature (CmsSigner signer)
+ {
+ }
[MonoTODO]
- public void ComputeCounterSignature (Pkcs7Signer signer) {}
+ public void RemoveCounterSignature (SignerInfo counterSignerInfo)
+ {
+ }
[MonoTODO]
- public void RemoveCounterSignature (SignerInfo counterSignerInfo) {}
+ public void RemoveCounterSignature (int index)
+ {
+ }
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfoCollection.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfoCollection.cs
index 1f0d38253a7..a5bd5dd2a3f 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfoCollection.cs
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfoCollection.cs
@@ -2,11 +2,10 @@
// SignerInfoCollection.cs - System.Security.Cryptography.Pkcs.SignerInfoCollection
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
+// Copyright (C) 2004 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
@@ -35,7 +34,7 @@ using System.Collections;
namespace System.Security.Cryptography.Pkcs {
- public class SignerInfoCollection : ICollection {
+ public sealed class SignerInfoCollection : ICollection {
private ArrayList _list;
@@ -75,7 +74,10 @@ namespace System.Security.Cryptography.Pkcs {
_list.CopyTo (array, index);
}
- public void CopyTo (RecipientInfo[] array, int index) {}
+ [MonoTODO]
+ public void CopyTo (SignerInfo[] array, int index)
+ {
+ }
public SignerInfoEnumerator GetEnumerator ()
{
@@ -89,4 +91,4 @@ namespace System.Security.Cryptography.Pkcs {
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfoEnumerator.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfoEnumerator.cs
index 06897991e4e..53e756f3cb0 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfoEnumerator.cs
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SignerInfoEnumerator.cs
@@ -2,11 +2,10 @@
// SignerInfoEnumerator.cs - System.Security.Cryptography.Pkcs.SignerInfoEnumerator
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
+// Copyright (C) 2004 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
@@ -35,7 +34,7 @@ using System.Collections;
namespace System.Security.Cryptography.Pkcs {
- public class SignerInfoEnumerator : IEnumerator {
+ public sealed class SignerInfoEnumerator : IEnumerator {
private IEnumerator enumerator;
@@ -70,4 +69,4 @@ namespace System.Security.Cryptography.Pkcs {
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SubjectIdentifier.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SubjectIdentifier.cs
index 2e143958094..a6c3ec5541c 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SubjectIdentifier.cs
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SubjectIdentifier.cs
@@ -2,11 +2,10 @@
// SubjectIdentifier.cs - System.Security.Cryptography.Pkcs.SubjectIdentifier
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
+// Copyright (C) 2004 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,7 +33,7 @@ using System;
namespace System.Security.Cryptography.Pkcs {
- public class SubjectIdentifier {
+ public sealed class SubjectIdentifier {
private SubjectIdentifierType _type;
private object _value;
@@ -57,4 +56,4 @@ namespace System.Security.Cryptography.Pkcs {
}
}
-#endif \ No newline at end of file
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SubjectIdentifierOrKey.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SubjectIdentifierOrKey.cs
index 1488cb261bb..9b56a4dec5b 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SubjectIdentifierOrKey.cs
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SubjectIdentifierOrKey.cs
@@ -2,11 +2,10 @@
// SubjectIdentifierOrKey.cs - System.Security.Cryptography.Pkcs.SubjectIdentifierOrKey
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
+// Copyright (C) 2004 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,7 +33,7 @@ using System;
namespace System.Security.Cryptography.Pkcs {
- public class SubjectIdentifierOrKey {
+ public sealed class SubjectIdentifierOrKey {
private SubjectIdentifierOrKeyType _type;
private object _value;
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SubjectIdentifierType.cs b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SubjectIdentifierType.cs
index 22527d325d8..934ebad4b30 100755
--- a/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SubjectIdentifierType.cs
+++ b/mcs/class/System.Security/System.Security.Cryptography.Pkcs/SubjectIdentifierType.cs
@@ -1,12 +1,11 @@
//
-// SubjectIdentifierType.cs - System.Security.Cryptography.Pkcs.SubjectIdentifierType
+// System.Security.Cryptography.Pkcs.SubjectIdentifierType
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
+// Copyright (C) 2004 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,11 +33,14 @@ using System;
namespace System.Security.Cryptography.Pkcs {
+ [Serializable]
public enum SubjectIdentifierType {
Unknown,
IssuerAndSerialNumber,
- SubjectKeyIdentifier
+ SubjectKeyIdentifier,
+ [Obsolete] HashOnly,
+ NoSignature = 3
}
}
-#endif \ No newline at end of file
+#endif