mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交Unity 联机Pro
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Cms;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
|
||||
{
|
||||
public class CertificateConfirmationContent
|
||||
{
|
||||
private readonly DefaultDigestAlgorithmIdentifierFinder m_digestAlgFinder;
|
||||
private readonly CertConfirmContent m_content;
|
||||
|
||||
public CertificateConfirmationContent(CertConfirmContent content)
|
||||
{
|
||||
this.m_content = content;
|
||||
}
|
||||
|
||||
public CertificateConfirmationContent(CertConfirmContent content,
|
||||
DefaultDigestAlgorithmIdentifierFinder digestAlgFinder)
|
||||
{
|
||||
this.m_content = content;
|
||||
this.m_digestAlgFinder = digestAlgFinder;
|
||||
}
|
||||
|
||||
public CertConfirmContent ToAsn1Structure()
|
||||
{
|
||||
return m_content;
|
||||
}
|
||||
|
||||
public CertificateStatus[] GetStatusMessages()
|
||||
{
|
||||
CertStatus[] statusArray = m_content.ToCertStatusArray();
|
||||
CertificateStatus[] ret = new CertificateStatus[statusArray.Length];
|
||||
for (int i = 0; i != ret.Length; i++)
|
||||
{
|
||||
ret[i] = new CertificateStatus(m_digestAlgFinder, statusArray[i]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f35656e52bb4e2848bb77febb18c71b2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,69 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System.Collections.Generic;
|
||||
|
||||
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.Math;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
|
||||
|
||||
namespace BestHTTP.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
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d16c3d50c5b29fd40a259ac7f6f67869
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,46 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
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 CertificateStatus
|
||||
{
|
||||
private static readonly DefaultSignatureAlgorithmIdentifierFinder sigAlgFinder = new DefaultSignatureAlgorithmIdentifierFinder();
|
||||
|
||||
private readonly DefaultDigestAlgorithmIdentifierFinder digestAlgFinder;
|
||||
private readonly CertStatus certStatus;
|
||||
|
||||
public CertificateStatus(DefaultDigestAlgorithmIdentifierFinder digestAlgFinder, CertStatus certStatus)
|
||||
{
|
||||
this.digestAlgFinder = digestAlgFinder;
|
||||
this.certStatus = certStatus;
|
||||
}
|
||||
|
||||
public virtual PkiStatusInfo StatusInfo => certStatus.StatusInfo;
|
||||
|
||||
public virtual BigInteger CertRequestID => certStatus.CertReqID.Value;
|
||||
|
||||
public virtual bool IsVerified(X509Certificate cert)
|
||||
{
|
||||
AlgorithmIdentifier digAlg = digestAlgFinder.Find(sigAlgFinder.Find(cert.SigAlgName));
|
||||
if (null == digAlg)
|
||||
throw new CmpException("cannot find algorithm for digest from signature " + cert.SigAlgName);
|
||||
|
||||
byte[] digest = DigestUtilities.CalculateDigest(digAlg.Algorithm, cert.GetEncoded());
|
||||
|
||||
return Arrays.ConstantTimeAreEqual(certStatus.CertHash.GetOctets(), digest);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b49242607e5a6d4ab596d2eeb0a2403
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
|
||||
{
|
||||
[Serializable]
|
||||
public class CmpException
|
||||
: Exception
|
||||
{
|
||||
public CmpException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public CmpException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public CmpException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected CmpException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 521d6298e5b1cbb4c803d6940b4e5a72
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,49 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
|
||||
{
|
||||
public class GeneralPkiMessage
|
||||
{
|
||||
private readonly PkiMessage m_pkiMessage;
|
||||
|
||||
private static PkiMessage ParseBytes(byte[] encoding)
|
||||
{
|
||||
return PkiMessage.GetInstance(Asn1Object.FromByteArray(encoding));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap a PKIMessage ASN.1 structure.
|
||||
/// </summary>
|
||||
/// <param name="pkiMessage">PKI message.</param>
|
||||
public GeneralPkiMessage(PkiMessage pkiMessage)
|
||||
{
|
||||
this.m_pkiMessage = pkiMessage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a PKIMessage from the passed in bytes.
|
||||
/// </summary>
|
||||
/// <param name="encoding">BER/DER encoding of the PKIMessage</param>
|
||||
public GeneralPkiMessage(byte[] encoding)
|
||||
: this(ParseBytes(encoding))
|
||||
{
|
||||
}
|
||||
|
||||
public virtual PkiHeader Header => m_pkiMessage.Header;
|
||||
|
||||
public virtual PkiBody Body => m_pkiMessage.Body;
|
||||
|
||||
/// <summary>
|
||||
/// Return true if this message has protection bits on it. A return value of true
|
||||
/// indicates the message can be used to construct a ProtectedPKIMessage.
|
||||
/// </summary>
|
||||
public virtual bool HasProtection => m_pkiMessage.Protection != null;
|
||||
|
||||
public virtual PkiMessage ToAsn1Structure() => m_pkiMessage;
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed5a9dc6dafd3254d89c31fd2f933dbf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,141 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
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.Crmf;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrapper for a PKIMessage with protection attached to it.
|
||||
/// </summary>
|
||||
public class ProtectedPkiMessage
|
||||
{
|
||||
private readonly PkiMessage m_pkiMessage;
|
||||
|
||||
/// <summary>
|
||||
/// Wrap a general message.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentException">If the general message does not have protection.</exception>
|
||||
/// <param name="pkiMessage">The General message</param>
|
||||
public ProtectedPkiMessage(GeneralPkiMessage pkiMessage)
|
||||
{
|
||||
if (!pkiMessage.HasProtection)
|
||||
throw new ArgumentException("GeneralPkiMessage not protected");
|
||||
|
||||
this.m_pkiMessage = pkiMessage.ToAsn1Structure();
|
||||
}
|
||||
|
||||
// TODO[cmp] Make internal? (Has test that uses it)
|
||||
/// <summary>
|
||||
/// Wrap a PKI message.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentException">If the PKI message does not have protection.</exception>
|
||||
/// <param name="pkiMessage">The PKI message</param>
|
||||
public ProtectedPkiMessage(PkiMessage pkiMessage)
|
||||
{
|
||||
if (null == pkiMessage.Header.ProtectionAlg)
|
||||
throw new ArgumentException("PkiMessage not protected");
|
||||
|
||||
this.m_pkiMessage = pkiMessage;
|
||||
}
|
||||
|
||||
/// <summary>Message header</summary>
|
||||
public virtual PkiHeader Header => m_pkiMessage.Header;
|
||||
|
||||
/// <summary>Message body</summary>
|
||||
public virtual PkiBody Body => m_pkiMessage.Body;
|
||||
|
||||
/// <summary>
|
||||
/// Return the underlying ASN.1 structure contained in this object.
|
||||
/// </summary>
|
||||
/// <returns>PkiMessage structure</returns>
|
||||
public virtual PkiMessage ToAsn1Message() => m_pkiMessage;
|
||||
|
||||
/// <summary>
|
||||
/// Determine whether the message is protected by a password based MAC. Use verify(PKMACBuilder, char[])
|
||||
/// to verify the message if this method returns true.
|
||||
/// </summary>
|
||||
/// <returns>true if protection MAC PBE based, false otherwise.</returns>
|
||||
public virtual bool HasPasswordBasedMacProtected
|
||||
{
|
||||
get { return CmpObjectIdentifiers.passwordBasedMac.Equals(Header.ProtectionAlg.Algorithm); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the extra certificates associated with this message.
|
||||
/// </summary>
|
||||
/// <returns>an array of extra certificates, zero length if none present.</returns>
|
||||
public virtual X509Certificate[] GetCertificates()
|
||||
{
|
||||
CmpCertificate[] certs = m_pkiMessage.GetExtraCerts();
|
||||
if (null == certs)
|
||||
return new X509Certificate[0];
|
||||
|
||||
X509Certificate[] result = new X509Certificate[certs.Length];
|
||||
for (int t = 0; t < certs.Length; t++)
|
||||
{
|
||||
result[t] = new X509Certificate(certs[t].X509v3PKCert);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify a message with a public key based signature attached.
|
||||
/// </summary>
|
||||
/// <param name="verifierFactory">a factory of signature verifiers.</param>
|
||||
/// <returns>true if the provider is able to create a verifier that validates the signature, false otherwise.</returns>
|
||||
public virtual bool Verify(IVerifierFactory verifierFactory)
|
||||
{
|
||||
IStreamCalculator<IVerifier> streamCalculator = verifierFactory.CreateCalculator();
|
||||
|
||||
IVerifier result = Process(streamCalculator);
|
||||
|
||||
return result.IsVerified(m_pkiMessage.Protection.GetBytes());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify a message with password based MAC protection.
|
||||
/// </summary>
|
||||
/// <param name="pkMacBuilder">MAC builder that can be used to construct the appropriate MacCalculator</param>
|
||||
/// <param name="password">the MAC password</param>
|
||||
/// <returns>true if the passed in password and MAC builder verify the message, false otherwise.</returns>
|
||||
/// <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 (!CmpObjectIdentifiers.passwordBasedMac.Equals(m_pkiMessage.Header.ProtectionAlg.Algorithm))
|
||||
throw new InvalidOperationException("protection algorithm is not mac based");
|
||||
|
||||
PbmParameter parameter = PbmParameter.GetInstance(m_pkiMessage.Header.ProtectionAlg.Parameters);
|
||||
|
||||
pkMacBuilder.SetParameters(parameter);
|
||||
|
||||
IBlockResult result = Process(pkMacBuilder.Build(password).CreateCalculator());
|
||||
|
||||
return Arrays.ConstantTimeAreEqual(result.Collect(), m_pkiMessage.Protection.GetBytes());
|
||||
}
|
||||
|
||||
private TResult Process<TResult>(IStreamCalculator<TResult> streamCalculator)
|
||||
{
|
||||
Asn1EncodableVector avec = new Asn1EncodableVector();
|
||||
avec.Add(m_pkiMessage.Header);
|
||||
avec.Add(m_pkiMessage.Body);
|
||||
byte[] enc = new DerSequence(avec).GetDerEncoded();
|
||||
|
||||
using (var stream = streamCalculator.Stream)
|
||||
{
|
||||
stream.Write(enc, 0, enc.Length);
|
||||
}
|
||||
|
||||
return streamCalculator.GetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6288a4eaf3dd8274fb93f532c1ed08ee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,161 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
|
||||
{
|
||||
public sealed class ProtectedPkiMessageBuilder
|
||||
{
|
||||
private readonly PkiHeaderBuilder m_hdrBuilder;
|
||||
private PkiBody body;
|
||||
private readonly List<InfoTypeAndValue> generalInfos = new List<InfoTypeAndValue>();
|
||||
private readonly List<X509Certificate> extraCerts = new List<X509Certificate>();
|
||||
|
||||
public ProtectedPkiMessageBuilder(GeneralName sender, GeneralName recipient)
|
||||
: this(PkiHeader.CMP_2000, sender, recipient)
|
||||
{
|
||||
}
|
||||
|
||||
public ProtectedPkiMessageBuilder(int pvno, GeneralName sender, GeneralName recipient)
|
||||
{
|
||||
m_hdrBuilder = new PkiHeaderBuilder(pvno, sender, recipient);
|
||||
}
|
||||
|
||||
public ProtectedPkiMessageBuilder SetTransactionId(byte[] tid)
|
||||
{
|
||||
m_hdrBuilder.SetTransactionID(tid);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProtectedPkiMessageBuilder SetFreeText(PkiFreeText freeText)
|
||||
{
|
||||
m_hdrBuilder.SetFreeText(freeText);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProtectedPkiMessageBuilder AddGeneralInfo(InfoTypeAndValue genInfo)
|
||||
{
|
||||
generalInfos.Add(genInfo);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProtectedPkiMessageBuilder SetMessageTime(DateTime time)
|
||||
{
|
||||
m_hdrBuilder.SetMessageTime(new Asn1GeneralizedTime(time));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProtectedPkiMessageBuilder SetMessageTime(Asn1GeneralizedTime generalizedTime)
|
||||
{
|
||||
m_hdrBuilder.SetMessageTime(generalizedTime);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProtectedPkiMessageBuilder SetRecipKID(byte[] id)
|
||||
{
|
||||
m_hdrBuilder.SetRecipKID(id);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProtectedPkiMessageBuilder SetRecipNonce(byte[] nonce)
|
||||
{
|
||||
m_hdrBuilder.SetRecipNonce(nonce);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProtectedPkiMessageBuilder SetSenderKID(byte[] id)
|
||||
{
|
||||
m_hdrBuilder.SetSenderKID(id);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProtectedPkiMessageBuilder SetSenderNonce(byte[] nonce)
|
||||
{
|
||||
m_hdrBuilder.SetSenderNonce(nonce);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProtectedPkiMessageBuilder SetBody(PkiBody body)
|
||||
{
|
||||
this.body = body;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProtectedPkiMessageBuilder AddCmpCertificate(X509Certificate certificate)
|
||||
{
|
||||
extraCerts.Add(certificate);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProtectedPkiMessage Build(ISignatureFactory signatureFactory)
|
||||
{
|
||||
if (null == body)
|
||||
throw new InvalidOperationException("body must be set before building");
|
||||
|
||||
IStreamCalculator<IBlockResult> calculator = signatureFactory.CreateCalculator();
|
||||
|
||||
if (!(signatureFactory.AlgorithmDetails is AlgorithmIdentifier algorithmDetails))
|
||||
throw new ArgumentException("AlgorithmDetails is not AlgorithmIdentifier");
|
||||
|
||||
FinalizeHeader(algorithmDetails);
|
||||
PkiHeader header = m_hdrBuilder.Build();
|
||||
DerBitString protection = new DerBitString(CalculateSignature(calculator, header, body));
|
||||
return FinalizeMessage(header, protection);
|
||||
}
|
||||
|
||||
public ProtectedPkiMessage Build(IMacFactory macFactory)
|
||||
{
|
||||
if (null == body)
|
||||
throw new InvalidOperationException("body must be set before building");
|
||||
|
||||
IStreamCalculator<IBlockResult> calculator = macFactory.CreateCalculator();
|
||||
|
||||
if (!(macFactory.AlgorithmDetails is AlgorithmIdentifier algorithmDetails))
|
||||
throw new ArgumentException("AlgorithmDetails is not AlgorithmIdentifier");
|
||||
|
||||
FinalizeHeader(algorithmDetails);
|
||||
PkiHeader header = m_hdrBuilder.Build();
|
||||
DerBitString protection = new DerBitString(CalculateSignature(calculator, header, body));
|
||||
return FinalizeMessage(header, protection);
|
||||
}
|
||||
|
||||
private void FinalizeHeader(AlgorithmIdentifier algorithmIdentifier)
|
||||
{
|
||||
m_hdrBuilder.SetProtectionAlg(algorithmIdentifier);
|
||||
if (generalInfos.Count > 0)
|
||||
{
|
||||
m_hdrBuilder.SetGeneralInfo(generalInfos.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
private ProtectedPkiMessage FinalizeMessage(PkiHeader header, DerBitString protection)
|
||||
{
|
||||
if (extraCerts.Count < 1)
|
||||
return new ProtectedPkiMessage(new PkiMessage(header, body, protection));
|
||||
|
||||
CmpCertificate[] cmpCertificates = new CmpCertificate[extraCerts.Count];
|
||||
for (int i = 0; i < cmpCertificates.Length; i++)
|
||||
{
|
||||
cmpCertificates[i] = new CmpCertificate(extraCerts[i].CertificateStructure);
|
||||
}
|
||||
|
||||
return new ProtectedPkiMessage(new PkiMessage(header, body, protection, cmpCertificates));
|
||||
}
|
||||
|
||||
private byte[] CalculateSignature(IStreamCalculator<IBlockResult> signer, PkiHeader header, PkiBody body)
|
||||
{
|
||||
new DerSequence(header, body).EncodeTo(signer.Stream);
|
||||
return signer.GetResult().Collect();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02044adf55171f74f8ba47909d15c277
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,28 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
|
||||
{
|
||||
public struct RevocationDetails
|
||||
{
|
||||
private readonly RevDetails m_revDetails;
|
||||
|
||||
public RevocationDetails(RevDetails revDetails)
|
||||
{
|
||||
m_revDetails = revDetails;
|
||||
}
|
||||
|
||||
public X509Name Subject => m_revDetails.CertDetails.Subject;
|
||||
|
||||
public X509Name Issuer => m_revDetails.CertDetails.Issuer;
|
||||
|
||||
public BigInteger SerialNumber => m_revDetails.CertDetails.SerialNumber.Value;
|
||||
|
||||
public RevDetails ToASN1Structure() => m_revDetails;
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0720348074c92e846ad33801abe028a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,62 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
|
||||
{
|
||||
public sealed class RevocationDetailsBuilder
|
||||
{
|
||||
private readonly CertTemplateBuilder m_templateBuilder = new CertTemplateBuilder();
|
||||
|
||||
public RevocationDetailsBuilder SetPublicKey(SubjectPublicKeyInfo publicKey)
|
||||
{
|
||||
if (publicKey != null)
|
||||
{
|
||||
m_templateBuilder.SetPublicKey(publicKey);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public RevocationDetailsBuilder SetIssuer(X509Name issuer)
|
||||
{
|
||||
if (issuer != null)
|
||||
{
|
||||
m_templateBuilder.SetIssuer(issuer);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public RevocationDetailsBuilder SetSerialNumber(BigInteger serialNumber)
|
||||
{
|
||||
if (serialNumber != null)
|
||||
{
|
||||
m_templateBuilder.SetSerialNumber(new DerInteger(serialNumber));
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public RevocationDetailsBuilder SetSubject(X509Name subject)
|
||||
{
|
||||
if (subject != null)
|
||||
{
|
||||
m_templateBuilder.SetSubject(subject);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public RevocationDetails Build()
|
||||
{
|
||||
return new RevocationDetails(new RevDetails(m_templateBuilder.Build()));
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2587caf391202c04e8316616ff922461
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user