summary refs log tree commit diff
path: root/crypto/src/cmp
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-07-27 18:49:31 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-07-27 18:49:31 +0700
commita41e9dbc22fda83c4e81e5f3c56d49b1fa124e3f (patch)
treec63951f0ed67be114833bec65256e5e03174dbe6 /crypto/src/cmp
parentRefactoring around stream calculators (diff)
downloadBouncyCastle.NET-ed25519-a41e9dbc22fda83c4e81e5f3c56d49b1fa124e3f.tar.xz
CMP, CRMF updates from bc-java
Diffstat (limited to 'crypto/src/cmp')
-rw-r--r--crypto/src/cmp/CertificateConfirmationContent.cs2
-rw-r--r--crypto/src/cmp/ProtectedPkiMessage.cs4
-rw-r--r--crypto/src/cmp/ProtectedPkiMessageBuilder.cs31
3 files changed, 20 insertions, 17 deletions
diff --git a/crypto/src/cmp/CertificateConfirmationContent.cs b/crypto/src/cmp/CertificateConfirmationContent.cs
index 262a28531..edd4a28ed 100644
--- a/crypto/src/cmp/CertificateConfirmationContent.cs
+++ b/crypto/src/cmp/CertificateConfirmationContent.cs
@@ -14,7 +14,7 @@ namespace Org.BouncyCastle.Cmp
             IDigestAlgorithmFinder digestAlgorithmFinder)
         {
             if (!IsCertificateConfirmationContent(pkiBody.Type))
-                throw new ArgumentException("content of PkiBody wrong type: " + pkiBody.Type);
+                throw new ArgumentException("content of PKIBody wrong type: " + pkiBody.Type);
 
             var content = CertConfirmContent.GetInstance(pkiBody.Content);
 
diff --git a/crypto/src/cmp/ProtectedPkiMessage.cs b/crypto/src/cmp/ProtectedPkiMessage.cs
index a7fdd35a9..9e442c426 100644
--- a/crypto/src/cmp/ProtectedPkiMessage.cs
+++ b/crypto/src/cmp/ProtectedPkiMessage.cs
@@ -102,6 +102,9 @@ namespace Org.BouncyCastle.Cmp
         /// <exception cref="InvalidOperationException">if algorithm not MAC based, or an exception is thrown verifying the MAC.</exception>
         public virtual bool Verify(PKMacBuilder pkMacBuilder, char[] password)
         {
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+            return Verify(pkMacBuilder, password.AsSpan());
+#else
             var protectionAlgorithm = m_pkiMessage.Header.ProtectionAlg;
 
             if (!CmpObjectIdentifiers.passwordBasedMac.Equals(protectionAlgorithm.Algorithm))
@@ -113,6 +116,7 @@ namespace Org.BouncyCastle.Cmp
             var macFactory = pkMacBuilder.Build(password);
 
             return X509Utilities.VerifyMac(macFactory, CreateProtected(), m_pkiMessage.Protection);
+#endif
         }
 
 #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
diff --git a/crypto/src/cmp/ProtectedPkiMessageBuilder.cs b/crypto/src/cmp/ProtectedPkiMessageBuilder.cs
index ff4af5573..27d2cd0a1 100644
--- a/crypto/src/cmp/ProtectedPkiMessageBuilder.cs
+++ b/crypto/src/cmp/ProtectedPkiMessageBuilder.cs
@@ -4,6 +4,7 @@ using System.Collections.Generic;
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cmp;
 using Org.BouncyCastle.Asn1.X509;
+using Org.BouncyCastle.Crmf;
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.X509;
 
@@ -86,25 +87,23 @@ namespace Org.BouncyCastle.Cmp
             return this;
         }
 
-        // TODO[crmf] Add CertificateReqMessages
-        //public ProtectedPkiMessageBuilder SetBody(int bodyType, CertificateReqMessages certificateReqMessages)
-        //{
-        //    if (!CertificateReqMessages.IsCertificateRequestMessages(bodyType))
-        //        throw new ArgumentException("body type " + bodyType + " does not match CMP type CertReqMessages");
+        public ProtectedPkiMessageBuilder SetBody(int bodyType, CertificateReqMessages certificateReqMessages)
+        {
+            if (!CertificateReqMessages.IsCertificateRequestMessages(bodyType))
+                throw new ArgumentException("body type " + bodyType + " does not match CMP type CertReqMessages");
 
-        //    m_body = new PkiBody(bodyType, certificateReqMessages.ToAsn1Structure());
-        //    return this;
-        //}
+            m_body = new PkiBody(bodyType, certificateReqMessages.ToAsn1Structure());
+            return this;
+        }
 
-        // TODO[crmf] Add CertificateRepMessage
-        //public ProtectedPkiMessageBuilder SetBody(int bodyType, CertificateRepMessage certificateRepMessage)
-        //{
-        //    if (!CertificateRepMessage.IsCertificateRepMessage(bodyType))
-        //        throw new ArgumentException("body type " + bodyType + " does not match CMP type CertRepMessage");
+        public ProtectedPkiMessageBuilder SetBody(int bodyType, CertificateRepMessage certificateRepMessage)
+        {
+            if (!CertificateRepMessage.IsCertificateRepMessage(bodyType))
+                throw new ArgumentException("body type " + bodyType + " does not match CMP type CertRepMessage");
 
-        //    m_body = new PkiBody(bodyType, certificateRepMessage.ToAsn1Structure());
-        //    return this;
-        //}
+            m_body = new PkiBody(bodyType, certificateRepMessage.ToAsn1Structure());
+            return this;
+        }
 
         public ProtectedPkiMessageBuilder SetBody(int bodyType,
             CertificateConfirmationContent certificateConfirmationContent)