diff options
Diffstat (limited to 'crypto/src/tsp')
-rw-r--r-- | crypto/src/tsp/TimeStampResponseGenerator.cs | 63 | ||||
-rw-r--r-- | crypto/src/tsp/TimeStampToken.cs | 7 | ||||
-rw-r--r-- | crypto/src/tsp/TimeStampTokenGenerator.cs | 40 |
3 files changed, 107 insertions, 3 deletions
diff --git a/crypto/src/tsp/TimeStampResponseGenerator.cs b/crypto/src/tsp/TimeStampResponseGenerator.cs index b596f8d97..69a5c098b 100644 --- a/crypto/src/tsp/TimeStampResponseGenerator.cs +++ b/crypto/src/tsp/TimeStampResponseGenerator.cs @@ -6,6 +6,7 @@ using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.Cmp; using Org.BouncyCastle.Asn1.Cms; using Org.BouncyCastle.Asn1.Tsp; +using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Math; using Org.BouncyCastle.Utilities.Date; @@ -163,6 +164,68 @@ namespace Org.BouncyCastle.Tsp } } + + public TimeStampResponse GenerateGrantedResponse( + TimeStampRequest request, + BigInteger serialNumber, + DateTimeObject genTime, + String statusString, + X509Extensions additionalExtensions) + { + TimeStampResp resp; + + try + { + if (genTime == null) + throw new TspValidationException("The time source is not available.", + PkiFailureInfo.TimeNotAvailable); + + request.Validate(acceptedAlgorithms, acceptedPolicies, acceptedExtensions); + + this.status = PkiStatus.Granted; + this.AddStatusString(statusString); + + PkiStatusInfo pkiStatusInfo = GetPkiStatusInfo(); + + ContentInfo tstTokenContentInfo; + try + { + TimeStampToken token = tokenGenerator.Generate(request, serialNumber, genTime.Value,additionalExtensions); + byte[] encoded = token.ToCmsSignedData().GetEncoded(); + + tstTokenContentInfo = ContentInfo.GetInstance(Asn1Object.FromByteArray(encoded)); + } + catch (IOException e) + { + throw new TspException("Timestamp token received cannot be converted to ContentInfo", e); + } + + resp = new TimeStampResp(pkiStatusInfo, tstTokenContentInfo); + } + catch (TspValidationException e) + { + status = PkiStatus.Rejection; + + this.SetFailInfoField(e.FailureCode); + this.AddStatusString(e.Message); + + PkiStatusInfo pkiStatusInfo = GetPkiStatusInfo(); + + resp = new TimeStampResp(pkiStatusInfo, null); + } + + try + { + return new TimeStampResponse(resp); + } + catch (IOException e) + { + throw new TspException("created badly formatted response!", e); + } + } + + + class FailInfo : DerBitString { diff --git a/crypto/src/tsp/TimeStampToken.cs b/crypto/src/tsp/TimeStampToken.cs index 0615cbd76..1245589b4 100644 --- a/crypto/src/tsp/TimeStampToken.cs +++ b/crypto/src/tsp/TimeStampToken.cs @@ -146,7 +146,12 @@ namespace Org.BouncyCastle.Tsp return tsToken.GetCrls(type); } - public IX509Store GetAttributeCertificates( + public IX509Store GetCertificates() + { + return tsToken.GetCertificates(); + } + + public IX509Store GetAttributeCertificates( string type) { return tsToken.GetAttributeCertificates(type); diff --git a/crypto/src/tsp/TimeStampTokenGenerator.cs b/crypto/src/tsp/TimeStampTokenGenerator.cs index 5badcfdd0..dad0db63b 100644 --- a/crypto/src/tsp/TimeStampTokenGenerator.cs +++ b/crypto/src/tsp/TimeStampTokenGenerator.cs @@ -253,9 +253,18 @@ namespace Org.BouncyCastle.Tsp //------------------------------------------------------------------------------ public TimeStampToken Generate( + TimeStampRequest request, + BigInteger serialNumber, + DateTime genTime) + { + return Generate(request, serialNumber, genTime, null); + } + + + public TimeStampToken Generate( TimeStampRequest request, BigInteger serialNumber, - DateTime genTime) + DateTime genTime, X509Extensions additionalExtensions) { DerObjectIdentifier digestAlgOID = new DerObjectIdentifier(request.MessageImprintAlgOid); @@ -304,6 +313,33 @@ namespace Org.BouncyCastle.Tsp tsaPolicy = new DerObjectIdentifier(request.ReqPolicy); } + + X509Extensions respExtensions = request.Extensions; + if (additionalExtensions != null) + { + X509ExtensionsGenerator extGen = new X509ExtensionsGenerator(); + + if (respExtensions != null) + { + foreach(object oid in respExtensions.ExtensionOids) + { + DerObjectIdentifier id = DerObjectIdentifier.GetInstance(oid); + extGen.AddExtension(id, respExtensions.GetExtension(DerObjectIdentifier.GetInstance(id))); + } + } + + foreach (object oid in additionalExtensions.ExtensionOids) + { + DerObjectIdentifier id = DerObjectIdentifier.GetInstance(oid); + extGen.AddExtension(id, additionalExtensions.GetExtension(DerObjectIdentifier.GetInstance(id))); + + } + + respExtensions = extGen.Generate(); + } + + + DerGeneralizedTime generalizedTime; if (resolution != Resolution.R_SECONDS) { @@ -316,7 +352,7 @@ namespace Org.BouncyCastle.Tsp TstInfo tstInfo = new TstInfo(tsaPolicy, messageImprint, new DerInteger(serialNumber), generalizedTime, accuracy, - derOrdering, nonce, tsa, request.Extensions); + derOrdering, nonce, tsa, respExtensions); try { |