- Initial commit
This commit is contained in:
69
Runtime/3rdParty/BouncyCastle/cmp/CertificateConfirmationContentBuilder.cs
vendored
Normal file
69
Runtime/3rdParty/BouncyCastle/cmp/CertificateConfirmationContentBuilder.cs
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Cms;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.X509;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Cmp
|
||||
{
|
||||
public sealed class CertificateConfirmationContentBuilder
|
||||
{
|
||||
private static readonly DefaultSignatureAlgorithmIdentifierFinder SigAlgFinder =
|
||||
new DefaultSignatureAlgorithmIdentifierFinder();
|
||||
|
||||
private readonly DefaultDigestAlgorithmIdentifierFinder m_digestAlgFinder;
|
||||
private readonly IList<X509Certificate> m_acceptedCerts = new List<X509Certificate>();
|
||||
private readonly IList<BigInteger> m_acceptedReqIDs = new List<BigInteger>();
|
||||
|
||||
public CertificateConfirmationContentBuilder()
|
||||
: this(new DefaultDigestAlgorithmIdentifierFinder())
|
||||
{
|
||||
}
|
||||
|
||||
public CertificateConfirmationContentBuilder(DefaultDigestAlgorithmIdentifierFinder digestAlgFinder)
|
||||
{
|
||||
this.m_digestAlgFinder = digestAlgFinder;
|
||||
}
|
||||
|
||||
public CertificateConfirmationContentBuilder AddAcceptedCertificate(X509Certificate certHolder,
|
||||
BigInteger certReqId)
|
||||
{
|
||||
m_acceptedCerts.Add(certHolder);
|
||||
m_acceptedReqIDs.Add(certReqId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CertificateConfirmationContent Build()
|
||||
{
|
||||
Asn1EncodableVector v = new Asn1EncodableVector();
|
||||
for (int i = 0; i != m_acceptedCerts.Count; i++)
|
||||
{
|
||||
X509Certificate cert = m_acceptedCerts[i];
|
||||
BigInteger reqID = m_acceptedReqIDs[i];
|
||||
|
||||
AlgorithmIdentifier algorithmIdentifier = SigAlgFinder.Find(cert.SigAlgName);
|
||||
if (null == algorithmIdentifier)
|
||||
throw new CmpException("cannot find algorithm identifier for signature name");
|
||||
|
||||
AlgorithmIdentifier digAlg = m_digestAlgFinder.Find(algorithmIdentifier);
|
||||
if (null == digAlg)
|
||||
throw new CmpException("cannot find algorithm for digest from signature");
|
||||
|
||||
byte[] digest = DigestUtilities.CalculateDigest(digAlg.Algorithm, cert.GetEncoded());
|
||||
|
||||
v.Add(new CertStatus(digest, reqID));
|
||||
}
|
||||
|
||||
return new CertificateConfirmationContent(CertConfirmContent.GetInstance(new DerSequence(v)),
|
||||
m_digestAlgFinder);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
Reference in New Issue
Block a user