培训考核三期,新版培训,网页版培训登录器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

70 lines
2.8 KiB

#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Cms;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
{
public class CertificateConfirmationContentBuilder
{
private static readonly DefaultSignatureAlgorithmIdentifierFinder sigAlgFinder = new DefaultSignatureAlgorithmIdentifierFinder();
private readonly DefaultDigestAlgorithmIdentifierFinder digestAlgFinder;
private readonly IList acceptedCerts = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
private readonly IList acceptedReqIds = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
public CertificateConfirmationContentBuilder()
: this(new DefaultDigestAlgorithmIdentifierFinder())
{
}
public CertificateConfirmationContentBuilder(DefaultDigestAlgorithmIdentifierFinder digestAlgFinder)
{
this.digestAlgFinder = digestAlgFinder;
}
public CertificateConfirmationContentBuilder AddAcceptedCertificate(X509Certificate certHolder,
BigInteger certReqId)
{
acceptedCerts.Add(certHolder);
acceptedReqIds.Add(certReqId);
return this;
}
public CertificateConfirmationContent Build()
{
Asn1EncodableVector v = new Asn1EncodableVector();
for (int i = 0; i != acceptedCerts.Count; i++)
{
X509Certificate cert = (X509Certificate)acceptedCerts[i];
BigInteger reqId = (BigInteger)acceptedReqIds[i];
AlgorithmIdentifier algorithmIdentifier = sigAlgFinder.Find(cert.SigAlgName);
AlgorithmIdentifier digAlg = 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)),
digestAlgFinder);
}
}
}
#pragma warning restore
#endif