From 6614f7fda643ebb09a1c21979a067fab17c3ab6c Mon Sep 17 00:00:00 2001 From: Megan Woods Date: Tue, 15 Jan 2019 14:55:39 +1100 Subject: Updated C# doc. Removed EJBCA EnrollmentTest as it s not viable to produce an example on .Net Framework 2.0 --- crypto/src/cmp/ProtectedPkiMessage.cs | 81 +++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 22 deletions(-) (limited to 'crypto/src/cmp/ProtectedPkiMessage.cs') diff --git a/crypto/src/cmp/ProtectedPkiMessage.cs b/crypto/src/cmp/ProtectedPkiMessage.cs index 159f08722..d3cf4a524 100644 --- a/crypto/src/cmp/ProtectedPkiMessage.cs +++ b/crypto/src/cmp/ProtectedPkiMessage.cs @@ -1,30 +1,30 @@ using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.X509; using System; -using System.Collections.Generic; -using System.Text; using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.Cmp; -using Org.BouncyCastle.Asn1.Crmf; -using Org.BouncyCastle.Asn1.Pkcs; using Org.BouncyCastle.Crypto; -using Org.BouncyCastle.Crypto.Operators; -using Org.BouncyCastle.Crypto.Paddings; using Org.BouncyCastle.Utilities; -using Org.BouncyCastle.Utilities.Encoders; + using Org.BouncyCastle.Crmf; namespace Org.BouncyCastle.Cmp { - + /// + /// Wrapper for a PKIMessage with protection attached to it. + /// public class ProtectedPkiMessage { private PkiMessage pkiMessage; - + /// + /// Wrap a general message. + /// + /// If the general message does not have protection. + /// The General message public ProtectedPkiMessage(GeneralPKIMessage pkiMessage) { - + if (!pkiMessage.HasProtection) { throw new ArgumentException("pki message not protected"); @@ -32,7 +32,12 @@ namespace Org.BouncyCastle.Cmp this.pkiMessage = pkiMessage.ToAsn1Structure(); } - + + /// + /// Wrap a PKI message. + /// + /// If the PKI message does not have protection. + /// The PKI message public ProtectedPkiMessage(PkiMessage pkiMessage) { if (pkiMessage.Header.ProtectionAlg == null) @@ -43,13 +48,33 @@ namespace Org.BouncyCastle.Cmp this.pkiMessage = pkiMessage; } + /// + /// Message header + /// public PkiHeader Header { get { return pkiMessage.Header; } } + + /// + /// Message Body + /// public PkiBody Body { get { return pkiMessage.Body; } } + /// + /// Return the underlying ASN.1 structure contained in this object. + /// + /// PKI Message structure public PkiMessage ToAsn1Message() { return pkiMessage; } + /// + /// Determine whether the message is protected by a password based MAC. Use verify(PKMACBuilder, char[]) + /// to verify the message if this method returns true. + /// + /// true if protection MAC PBE based, false otherwise. public bool HasPasswordBasedMacProtected { get { return Header.ProtectionAlg.Algorithm.Equals(CmpObjectIdentifiers.passwordBasedMac); } } + /// + /// Return the extra certificates associated with this message. + /// + /// an array of extra certificates, zero length if none present. public X509Certificate[] GetCertificates() { CmpCertificate[] certs = pkiMessage.GetExtraCerts(); @@ -60,7 +85,7 @@ namespace Org.BouncyCastle.Cmp } X509Certificate[] res = new X509Certificate[certs.Length]; - for (int t=0; t + /// Verify a message with a public key based signature attached. + /// + /// a factory of signature verifiers. + /// true if the provider is able to create a verifier that validates the signature, false otherwise. public bool Verify(IVerifierFactory verifierFactory) { IStreamCalculator streamCalculator = verifierFactory.CreateCalculator(); @@ -79,18 +109,25 @@ namespace Org.BouncyCastle.Cmp private Object Process(IStreamCalculator streamCalculator) { - Asn1EncodableVector avec = new Asn1EncodableVector(); - avec.Add(pkiMessage.Header); - avec.Add(pkiMessage.Body); - byte[] enc = new DerSequence(avec).GetDerEncoded(); - - streamCalculator.Stream.Write(enc,0,enc.Length); - streamCalculator.Stream.Flush(); - streamCalculator.Stream.Close(); - - return streamCalculator.GetResult(); + Asn1EncodableVector avec = new Asn1EncodableVector(); + avec.Add(pkiMessage.Header); + avec.Add(pkiMessage.Body); + byte[] enc = new DerSequence(avec).GetDerEncoded(); + + streamCalculator.Stream.Write(enc, 0, enc.Length); + streamCalculator.Stream.Flush(); + streamCalculator.Stream.Close(); + + return streamCalculator.GetResult(); } + /// + /// Verify a message with password based MAC protection. + /// + /// MAC builder that can be used to construct the appropriate MacCalculator + /// the MAC password + /// true if the passed in password and MAC builder verify the message, false otherwise. + /// if algorithm not MAC based, or an exception is thrown verifying the MAC. public bool Verify(PKMacBuilder pkMacBuilder, char[] password) { if (!CmpObjectIdentifiers.passwordBasedMac.Equals(pkiMessage.Header.ProtectionAlg.Algorithm)) -- cgit 1.4.1