summary refs log tree commit diff
path: root/crypto/src/cms
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/cms')
-rw-r--r--crypto/src/cms/CMSSignedDataParser.cs1
-rw-r--r--crypto/src/cms/DefaultSignedAttributeTableGenerator.cs39
-rw-r--r--crypto/src/cms/OriginatorInformation.cs2
-rw-r--r--crypto/src/cms/RecipientInformationStore.cs2
-rw-r--r--crypto/src/cms/SignerInfoGenerator.cs15
5 files changed, 38 insertions, 21 deletions
diff --git a/crypto/src/cms/CMSSignedDataParser.cs b/crypto/src/cms/CMSSignedDataParser.cs
index 83f87718f..8b02770d6 100644
--- a/crypto/src/cms/CMSSignedDataParser.cs
+++ b/crypto/src/cms/CMSSignedDataParser.cs
@@ -8,7 +8,6 @@ using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.IO;
 using Org.BouncyCastle.Security;
-using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.Collections;
 using Org.BouncyCastle.Utilities.IO;
 using Org.BouncyCastle.X509;
diff --git a/crypto/src/cms/DefaultSignedAttributeTableGenerator.cs b/crypto/src/cms/DefaultSignedAttributeTableGenerator.cs
index d8b668c4e..dea4de0a3 100644
--- a/crypto/src/cms/DefaultSignedAttributeTableGenerator.cs
+++ b/crypto/src/cms/DefaultSignedAttributeTableGenerator.cs
@@ -60,23 +60,22 @@ namespace Org.BouncyCastle.Cms
         private void DoCreateStandardAttributeTable(IDictionary<CmsAttributeTableParameter, object> parameters,
 			IDictionary<DerObjectIdentifier, object> std)
         {
-            // contentType will be absent if we're trying to generate a counter signature.
-
-            if (parameters.ContainsKey(CmsAttributeTableParameter.ContentType))
+            if (!std.ContainsKey(CmsAttributes.ContentType))
             {
-                if (!std.ContainsKey(CmsAttributes.ContentType))
+                // contentType will be absent if we're trying to generate a counter signature.
+                if (parameters.TryGetValue(CmsAttributeTableParameter.ContentType, out var contentType))
                 {
-                    DerObjectIdentifier contentType = (DerObjectIdentifier)
-                        parameters[CmsAttributeTableParameter.ContentType];
-                    Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(CmsAttributes.ContentType,
-                        new DerSet(contentType));
+                    Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(
+						CmsAttributes.ContentType,
+                        new DerSet((DerObjectIdentifier)contentType));
                     std[attr.AttrType] = attr;
                 }
             }
 
             if (!std.ContainsKey(CmsAttributes.SigningTime))
             {
-                Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(CmsAttributes.SigningTime,
+                Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(
+					CmsAttributes.SigningTime,
                     new DerSet(new Time(DateTime.UtcNow)));
                 std[attr.AttrType] = attr;
             }
@@ -84,17 +83,35 @@ namespace Org.BouncyCastle.Cms
             if (!std.ContainsKey(CmsAttributes.MessageDigest))
             {
                 byte[] messageDigest = (byte[])parameters[CmsAttributeTableParameter.Digest];
-                Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(CmsAttributes.MessageDigest,
+
+                Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(
+					CmsAttributes.MessageDigest,
                     new DerSet(new DerOctetString(messageDigest)));
                 std[attr.AttrType] = attr;
             }
+
+			// TODO CmsAlgorithmProtect support (see bc-fips-csharp)
+            //if (!std.ContainsKey(CmsAttributes.CmsAlgorithmProtect))
+            //{
+            //    var digestAlgorithmIdentifier = (Asn1.X509.AlgorithmIdentifier)
+            //        parameters[CmsAttributeTableParameter.DigestAlgorithmIdentifier];
+            //    var signatureAlgorithmIdentifier = (Asn1.X509.AlgorithmIdentifier)
+            //        parameters[CmsAttributeTableParameter.SignatureAlgorithmIdentifier];
+            //    var cmsAlgorithmProtection = new CmsAlgorithmProtection(
+            //        digestAlgorithmIdentifier, CmsAlgorithmProtection.Signature, signatureAlgorithmIdentifier);
+
+            //    Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(
+            //        CmsAttributes.CmsAlgorithmProtect,
+            //        new DerSet(cmsAlgorithmProtection));
+            //    std[attr.AttrType] = attr;
+            //}
         }
 
         /**
 		 * @param parameters source parameters
 		 * @return the populated attribute table
 		 */
-		public virtual AttributeTable GetAttributes(IDictionary<CmsAttributeTableParameter, object> parameters)
+        public virtual AttributeTable GetAttributes(IDictionary<CmsAttributeTableParameter, object> parameters)
 		{
             var table = CreateStandardAttributeTable(parameters);
 			return new AttributeTable(table);
diff --git a/crypto/src/cms/OriginatorInformation.cs b/crypto/src/cms/OriginatorInformation.cs
index 7186fafc3..6307cbc1f 100644
--- a/crypto/src/cms/OriginatorInformation.cs
+++ b/crypto/src/cms/OriginatorInformation.cs
@@ -10,7 +10,7 @@ namespace Org.BouncyCastle.Cms
 	{
 		private readonly OriginatorInfo originatorInfo;
 
-		internal OriginatorInformation(OriginatorInfo originatorInfo)
+        public OriginatorInformation(OriginatorInfo originatorInfo)
 		{
 			this.originatorInfo = originatorInfo;
 		}
diff --git a/crypto/src/cms/RecipientInformationStore.cs b/crypto/src/cms/RecipientInformationStore.cs
index 06d093805..281b51c79 100644
--- a/crypto/src/cms/RecipientInformationStore.cs
+++ b/crypto/src/cms/RecipientInformationStore.cs
@@ -25,7 +25,7 @@ namespace Org.BouncyCastle.Cms
 				list.Add(recipientInformation);
 			}
 
-            this.m_all = new List<RecipientInformation>(recipientInfos);
+            m_all = new List<RecipientInformation>(recipientInfos);
 		}
 
 		public RecipientInformation this[RecipientID selector]
diff --git a/crypto/src/cms/SignerInfoGenerator.cs b/crypto/src/cms/SignerInfoGenerator.cs
index 786749cb5..2fa185885 100644
--- a/crypto/src/cms/SignerInfoGenerator.cs
+++ b/crypto/src/cms/SignerInfoGenerator.cs
@@ -1,5 +1,3 @@
-using System;
-
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cms;
 using Org.BouncyCastle.Asn1.X509;
@@ -23,7 +21,8 @@ namespace Org.BouncyCastle.Cms
         internal CmsAttributeTableGenerator unsignedGen;
         private bool isDirectSignature;
 
-        internal SignerInfoGenerator(SignerIdentifier sigId, ISignatureFactory signerFactory): this(sigId, signerFactory, false)
+        internal SignerInfoGenerator(SignerIdentifier sigId, ISignatureFactory signerFactory)
+            : this(sigId, signerFactory, false)
         {
 
         }
@@ -45,7 +44,8 @@ namespace Org.BouncyCastle.Cms
             }
         }
 
-        internal SignerInfoGenerator(SignerIdentifier sigId, ISignatureFactory contentSigner, CmsAttributeTableGenerator signedGen, CmsAttributeTableGenerator unsignedGen)
+        internal SignerInfoGenerator(SignerIdentifier sigId, ISignatureFactory contentSigner,
+            CmsAttributeTableGenerator signedGen, CmsAttributeTableGenerator unsignedGen)
         {
             this.sigId = sigId;
             this.contentSigner = contentSigner;
@@ -54,7 +54,7 @@ namespace Org.BouncyCastle.Cms
             this.isDirectSignature = false;
         }
 
-        internal void setAssociatedCertificate(X509Certificate certificate)
+        internal void SetAssociatedCertificate(X509Certificate certificate)
         {
             this.certificate = certificate;
         }
@@ -130,11 +130,12 @@ namespace Org.BouncyCastle.Cms
          */
         public SignerInfoGenerator Build(ISignatureFactory contentSigner, X509Certificate certificate)
         {
-            SignerIdentifier sigId = new SignerIdentifier(new IssuerAndSerialNumber(certificate.IssuerDN, new DerInteger(certificate.SerialNumber)));
+            SignerIdentifier sigId = new SignerIdentifier(new IssuerAndSerialNumber(certificate.IssuerDN,
+                new DerInteger(certificate.SerialNumber)));
 
             SignerInfoGenerator sigInfoGen = CreateGenerator(contentSigner, sigId);
 
-            sigInfoGen.setAssociatedCertificate(certificate);
+            sigInfoGen.SetAssociatedCertificate(certificate);
 
             return sigInfoGen;
         }