This commit is contained in:
2026-06-15 18:18:16 +08:00
parent 97c9fba14e
commit 2b9f134e5f
4164 changed files with 386922 additions and 79 deletions

View File

@@ -0,0 +1,124 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Tsp
{
public class Accuracy
: Asn1Encodable
{
private readonly DerInteger seconds;
private readonly DerInteger millis;
private readonly DerInteger micros;
// constants
protected const int MinMillis = 1;
protected const int MaxMillis = 999;
protected const int MinMicros = 1;
protected const int MaxMicros = 999;
public Accuracy(
DerInteger seconds,
DerInteger millis,
DerInteger micros)
{
if (null != millis)
{
int millisValue = millis.IntValueExact;
if (millisValue < MinMillis || millisValue > MaxMillis)
throw new ArgumentException("Invalid millis field : not in (1..999)");
}
if (null != micros)
{
int microsValue = micros.IntValueExact;
if (microsValue < MinMicros || microsValue > MaxMicros)
throw new ArgumentException("Invalid micros field : not in (1..999)");
}
this.seconds = seconds;
this.millis = millis;
this.micros = micros;
}
private Accuracy(
Asn1Sequence seq)
{
for (int i = 0; i < seq.Count; ++i)
{
// seconds
if (seq[i] is DerInteger)
{
seconds = (DerInteger) seq[i];
}
else if (seq[i] is Asn1TaggedObject)
{
Asn1TaggedObject extra = (Asn1TaggedObject)seq[i];
switch (extra.TagNo)
{
case 0:
millis = DerInteger.GetInstance(extra, false);
int millisValue = millis.IntValueExact;
if (millisValue < MinMillis || millisValue > MaxMillis)
throw new ArgumentException("Invalid millis field : not in (1..999)");
break;
case 1:
micros = DerInteger.GetInstance(extra, false);
int microsValue = micros.IntValueExact;
if (microsValue < MinMicros || microsValue > MaxMicros)
throw new ArgumentException("Invalid micros field : not in (1..999)");
break;
default:
throw new ArgumentException("Invalid tag number");
}
}
}
}
public static Accuracy GetInstance(object obj)
{
if (obj is Accuracy)
return (Accuracy)obj;
if (obj == null)
return null;
return new Accuracy(Asn1Sequence.GetInstance(obj));
}
public DerInteger Seconds
{
get { return seconds; }
}
public DerInteger Millis
{
get { return millis; }
}
public DerInteger Micros
{
get { return micros; }
}
/**
* <pre>
* Accuracy ::= SEQUENCE {
* seconds INTEGER OPTIONAL,
* millis [0] INTEGER (1..999) OPTIONAL,
* micros [1] INTEGER (1..999) OPTIONAL
* }
* </pre>
*/
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector();
v.AddOptional(seconds);
v.AddOptionalTagged(false, 0, millis);
v.AddOptionalTagged(false, 1, micros);
return new DerSequence(v);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 339f04e74f343d046bf59842f2d0d8dc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,67 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Tsp
{
public class MessageImprint
: Asn1Encodable
{
private readonly AlgorithmIdentifier hashAlgorithm;
private readonly byte[] hashedMessage;
public static MessageImprint GetInstance(object obj)
{
if (obj is MessageImprint)
return (MessageImprint)obj;
if (obj == null)
return null;
return new MessageImprint(Asn1Sequence.GetInstance(obj));
}
private MessageImprint(
Asn1Sequence seq)
{
if (seq.Count != 2)
throw new ArgumentException("Wrong number of elements in sequence", "seq");
this.hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[0]);
this.hashedMessage = Asn1OctetString.GetInstance(seq[1]).GetOctets();
}
public MessageImprint(
AlgorithmIdentifier hashAlgorithm,
byte[] hashedMessage)
{
this.hashAlgorithm = hashAlgorithm;
this.hashedMessage = hashedMessage;
}
public AlgorithmIdentifier HashAlgorithm
{
get { return hashAlgorithm; }
}
public byte[] GetHashedMessage()
{
return hashedMessage;
}
/**
* <pre>
* MessageImprint ::= SEQUENCE {
* hashAlgorithm AlgorithmIdentifier,
* hashedMessage OCTET STRING }
* </pre>
*/
public override Asn1Object ToAsn1Object()
{
return new DerSequence(hashAlgorithm, new DerOctetString(hashedMessage));
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 719e3daffbac95e4e8246f1394328bcb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,211 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Tsp
{
public class TstInfo
: Asn1Encodable
{
private readonly DerInteger version;
private readonly DerObjectIdentifier tsaPolicyId;
private readonly MessageImprint messageImprint;
private readonly DerInteger serialNumber;
private readonly Asn1GeneralizedTime genTime;
private readonly Accuracy accuracy;
private readonly DerBoolean ordering;
private readonly DerInteger nonce;
private readonly GeneralName tsa;
private readonly X509Extensions extensions;
public static TstInfo GetInstance(object obj)
{
if (obj is TstInfo)
return (TstInfo)obj;
if (obj == null)
return null;
return new TstInfo(Asn1Sequence.GetInstance(obj));
}
private TstInfo(Asn1Sequence seq)
{
var e = seq.GetEnumerator();
// version
e.MoveNext();
version = DerInteger.GetInstance(e.Current);
// tsaPolicy
e.MoveNext();
tsaPolicyId = DerObjectIdentifier.GetInstance(e.Current);
// messageImprint
e.MoveNext();
messageImprint = MessageImprint.GetInstance(e.Current);
// serialNumber
e.MoveNext();
serialNumber = DerInteger.GetInstance(e.Current);
// genTime
e.MoveNext();
genTime = Asn1GeneralizedTime.GetInstance(e.Current);
// default for ordering
ordering = DerBoolean.False;
while (e.MoveNext())
{
Asn1Object o = (Asn1Object) e.Current;
if (o is Asn1TaggedObject)
{
DerTaggedObject tagged = (DerTaggedObject) o;
switch (tagged.TagNo)
{
case 0:
tsa = GeneralName.GetInstance(tagged, true);
break;
case 1:
extensions = X509Extensions.GetInstance(tagged, false);
break;
default:
throw new ArgumentException("Unknown tag value " + tagged.TagNo);
}
}
if (o is DerSequence)
{
accuracy = Accuracy.GetInstance(o);
}
if (o is DerBoolean)
{
ordering = DerBoolean.GetInstance(o);
}
if (o is DerInteger)
{
nonce = DerInteger.GetInstance(o);
}
}
}
public TstInfo(
DerObjectIdentifier tsaPolicyId,
MessageImprint messageImprint,
DerInteger serialNumber,
Asn1GeneralizedTime genTime,
Accuracy accuracy,
DerBoolean ordering,
DerInteger nonce,
GeneralName tsa,
X509Extensions extensions)
{
this.version = new DerInteger(1);
this.tsaPolicyId = tsaPolicyId;
this.messageImprint = messageImprint;
this.serialNumber = serialNumber;
this.genTime = genTime;
this.accuracy = accuracy;
this.ordering = ordering;
this.nonce = nonce;
this.tsa = tsa;
this.extensions = extensions;
}
public DerInteger Version
{
get { return version; }
}
public MessageImprint MessageImprint
{
get { return messageImprint; }
}
public DerObjectIdentifier Policy
{
get { return tsaPolicyId; }
}
public DerInteger SerialNumber
{
get { return serialNumber; }
}
public Accuracy Accuracy
{
get { return accuracy; }
}
public Asn1GeneralizedTime GenTime
{
get { return genTime; }
}
public DerBoolean Ordering
{
get { return ordering; }
}
public DerInteger Nonce
{
get { return nonce; }
}
public GeneralName Tsa
{
get { return tsa; }
}
public X509Extensions Extensions
{
get { return extensions; }
}
/**
* <pre>
*
* TstInfo ::= SEQUENCE {
* version INTEGER { v1(1) },
* policy TSAPolicyId,
* messageImprint MessageImprint,
* -- MUST have the same value as the similar field in
* -- TimeStampReq
* serialNumber INTEGER,
* -- Time-Stamping users MUST be ready to accommodate integers
* -- up to 160 bits.
* genTime GeneralizedTime,
* accuracy Accuracy OPTIONAL,
* ordering BOOLEAN DEFAULT FALSE,
* nonce INTEGER OPTIONAL,
* -- MUST be present if the similar field was present
* -- in TimeStampReq. In that case it MUST have the same value.
* tsa [0] GeneralName OPTIONAL,
* extensions [1] IMPLICIT Extensions OPTIONAL }
*
* </pre>
*/
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector(version, tsaPolicyId, messageImprint, serialNumber, genTime);
v.AddOptional(accuracy);
if (ordering != null && ordering.IsTrue)
{
v.Add(ordering);
}
v.AddOptional(nonce);
v.AddOptionalTagged(true, 0, tsa);
v.AddOptionalTagged(false, 1, extensions);
return new DerSequence(v);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c26676e066f194640955a4f6305afe44
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,147 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Tsp
{
public class TimeStampReq
: Asn1Encodable
{
private readonly DerInteger version;
private readonly MessageImprint messageImprint;
private readonly DerObjectIdentifier tsaPolicy;
private readonly DerInteger nonce;
private readonly DerBoolean certReq;
private readonly X509Extensions extensions;
public static TimeStampReq GetInstance(object obj)
{
if (obj is TimeStampReq)
return (TimeStampReq)obj;
if (obj == null)
return null;
return new TimeStampReq(Asn1Sequence.GetInstance(obj));
}
private TimeStampReq(
Asn1Sequence seq)
{
int nbObjects = seq.Count;
int seqStart = 0;
// version
version = DerInteger.GetInstance(seq[seqStart++]);
// messageImprint
messageImprint = MessageImprint.GetInstance(seq[seqStart++]);
for (int opt = seqStart; opt < nbObjects; opt++)
{
// tsaPolicy
if (seq[opt] is DerObjectIdentifier)
{
tsaPolicy = DerObjectIdentifier.GetInstance(seq[opt]);
}
// nonce
else if (seq[opt] is DerInteger)
{
nonce = DerInteger.GetInstance(seq[opt]);
}
// certReq
else if (seq[opt] is DerBoolean)
{
certReq = DerBoolean.GetInstance(seq[opt]);
}
// extensions
else if (seq[opt] is Asn1TaggedObject)
{
Asn1TaggedObject tagged = (Asn1TaggedObject) seq[opt];
if (tagged.TagNo == 0)
{
extensions = X509Extensions.GetInstance(tagged, false);
}
}
}
}
public TimeStampReq(
MessageImprint messageImprint,
DerObjectIdentifier tsaPolicy,
DerInteger nonce,
DerBoolean certReq,
X509Extensions extensions)
{
// default
this.version = new DerInteger(1);
this.messageImprint = messageImprint;
this.tsaPolicy = tsaPolicy;
this.nonce = nonce;
this.certReq = certReq;
this.extensions = extensions;
}
public DerInteger Version
{
get { return version; }
}
public MessageImprint MessageImprint
{
get { return messageImprint; }
}
public DerObjectIdentifier ReqPolicy
{
get { return tsaPolicy; }
}
public DerInteger Nonce
{
get { return nonce; }
}
public DerBoolean CertReq
{
get { return certReq; }
}
public X509Extensions Extensions
{
get { return extensions; }
}
/**
* <pre>
* TimeStampReq ::= SEQUENCE {
* version INTEGER { v1(1) },
* messageImprint MessageImprint,
* --a hash algorithm OID and the hash value of the data to be
* --time-stamped
* reqPolicy TSAPolicyId OPTIONAL,
* nonce INTEGER OPTIONAL,
* certReq BOOLEAN DEFAULT FALSE,
* extensions [0] IMPLICIT Extensions OPTIONAL
* }
* </pre>
*/
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector(version, messageImprint);
v.AddOptional(tsaPolicy, nonce);
if (certReq != null && certReq.IsTrue)
{
v.Add(certReq);
}
v.AddOptionalTagged(false, 0, extensions);
return new DerSequence(v);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b405c6ff9d4440344986dd831d6ee912
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,71 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Tsp
{
public class TimeStampResp
: Asn1Encodable
{
private readonly PkiStatusInfo pkiStatusInfo;
private readonly ContentInfo timeStampToken;
public static TimeStampResp GetInstance(object obj)
{
if (obj is TimeStampResp)
return (TimeStampResp)obj;
if (obj == null)
return null;
return new TimeStampResp(Asn1Sequence.GetInstance(obj));
}
private TimeStampResp(
Asn1Sequence seq)
{
this.pkiStatusInfo = PkiStatusInfo.GetInstance(seq[0]);
if (seq.Count > 1)
{
this.timeStampToken = ContentInfo.GetInstance(seq[1]);
}
}
public TimeStampResp(
PkiStatusInfo pkiStatusInfo,
ContentInfo timeStampToken)
{
this.pkiStatusInfo = pkiStatusInfo;
this.timeStampToken = timeStampToken;
}
public PkiStatusInfo Status
{
get { return pkiStatusInfo; }
}
public ContentInfo TimeStampToken
{
get { return timeStampToken; }
}
/**
* <pre>
* TimeStampResp ::= SEQUENCE {
* status PkiStatusInfo,
* timeStampToken TimeStampToken OPTIONAL }
* </pre>
*/
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector(pkiStatusInfo);
v.AddOptional(timeStampToken);
return new DerSequence(v);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 628c4af6da9dda340a36d4b4df1c13f5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: