private static TimeStampResp readTimeStampResp( Asn1InputStream input) { try { return(TimeStampResp.GetInstance(input.ReadObject())); } catch (ArgumentException e) { throw new TspException("malformed timestamp response: " + e, e); } catch (InvalidCastException e) { throw new TspException("malformed timestamp response: " + e, e); } catch (EndOfStreamException e) { //jbonilla - TSA del BCE por alguna razón devuelve "null\n" string resp = ""; if (input.CanSeek && input.CanRead && input.Length > 0) { input.Seek(0, SeekOrigin.Begin); resp = Strings.FromByteArray( Org.BouncyCastle.Utilities.IO.Streams.ReadAll(input)); } throw new TspException("malformed timestamp response: " + resp + " " + e.Message, e); } }
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); } }
public TimeStampResponse(TimeStampResp resp) { this.resp = resp; if (resp.TimeStampToken != null) { timeStampToken = new TimeStampToken(resp.TimeStampToken); } }
public TimeStampResponse Generate( TimeStampRequest request, BigInteger serialNumber, DateTime genTime) { TimeStampResp resp; try { request.Validate(acceptedAlgorithms, acceptedPolicies, acceptedExtensions); status = PkiStatus.Granted; this.addStatusString("Operation Okay"); PkiStatusInfo pkiStatusInfo = getPkiStatusInfo(); ContentInfo tstTokenContentInfo; try { TimeStampToken token = tokenGenerator.Generate(request, serialNumber, genTime); byte[] encoded = token.ToCmsSignedData().GetEncoded(); tstTokenContentInfo = ContentInfo.GetInstance(Asn1Object.FromByteArray(encoded)); } catch (IOException ioEx) { throw new TspException( "Timestamp token received cannot be converted to ContentInfo", ioEx); } 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) { throw new TspException("created badly formatted response!"); } }
public override void Respond(HttpListenerContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (!string.Equals(context.Request.ContentType, RequestContentType, StringComparison.OrdinalIgnoreCase)) { context.Response.StatusCode = 400; return; } var bytes = ReadRequestBody(context.Request); var request = new TimeStampRequest(bytes); PkiStatusInfo statusInfo; BcContentInfo timeStampToken = null; if (_options.ReturnFailure) { statusInfo = new PkiStatusInfo( (int)PkiStatus.Rejection, new PkiFreeText(new DerUtf8String("Unsupported algorithm")), new PkiFailureInfo(PkiFailureInfo.BadAlg)); } else { statusInfo = new PkiStatusInfo((int)PkiStatus.Granted); var generalizedTime = DateTime.UtcNow; if (_options.GeneralizedTime.HasValue) { generalizedTime = _options.GeneralizedTime.Value.UtcDateTime; } CmsSignedData timestamp = GenerateTimestamp(request, _nextSerialNumber, generalizedTime); timeStampToken = timestamp.ContentInfo; } _serialNumbers.Add(_nextSerialNumber); _nextSerialNumber = _nextSerialNumber.Add(BigInteger.One); context.Response.ContentType = ResponseContentType; var response = new TimeStampResp(statusInfo, timeStampToken); WriteResponseBody(context.Response, response.GetEncoded()); }
private static TimeStampResp readTimeStampResp(Asn1InputStream input) { try { return(TimeStampResp.GetInstance(input.ReadObject())); } catch (ArgumentException ex) { throw new TspException("malformed timestamp response: " + ex, ex); } catch (InvalidCastException ex2) { throw new TspException("malformed timestamp response: " + ex2, ex2); } }
public TimeStampResponse Generate(TimeStampRequest request, BigInteger serialNumber, DateTimeObject genTime) { //IL_0076: Expected O, but got Unknown //IL_00cf: Expected O, but got Unknown TimeStampResp resp; try { if (genTime == null) { throw new TspValidationException("The time source is not available.", 512); } request.Validate(acceptedAlgorithms, acceptedPolicies, acceptedExtensions); status = PkiStatus.Granted; AddStatusString("Operation Okay"); PkiStatusInfo pkiStatusInfo = GetPkiStatusInfo(); ContentInfo instance; try { TimeStampToken timeStampToken = tokenGenerator.Generate(request, serialNumber, genTime.Value); byte[] encoded = timeStampToken.ToCmsSignedData().GetEncoded(); instance = ContentInfo.GetInstance(Asn1Object.FromByteArray(encoded)); } catch (IOException val) { IOException e = val; throw new TspException("Timestamp token received cannot be converted to ContentInfo", (global::System.Exception)(object) e); } resp = new TimeStampResp(pkiStatusInfo, instance); } catch (TspValidationException ex) { status = PkiStatus.Rejection; SetFailInfoField(ex.FailureCode); AddStatusString(((global::System.Exception)ex).get_Message()); PkiStatusInfo pkiStatusInfo2 = GetPkiStatusInfo(); resp = new TimeStampResp(pkiStatusInfo2, null); } try { return(new TimeStampResponse(resp)); } catch (IOException val2) { IOException e2 = val2; throw new TspException("created badly formatted response!", (global::System.Exception)(object) e2); } }
public TimeStampResponse Generate(TimeStampRequest request, BigInteger serialNumber, DateTimeObject genTime) { TimeStampResp resp; try { if (genTime == null) { throw new TspValidationException("The time source is not available.", 512); } request.Validate(this.acceptedAlgorithms, this.acceptedPolicies, this.acceptedExtensions); this.status = PkiStatus.Granted; this.AddStatusString("Operation Okay"); PkiStatusInfo pkiStatusInfo = this.GetPkiStatusInfo(); ContentInfo instance; try { TimeStampToken timeStampToken = this.tokenGenerator.Generate(request, serialNumber, genTime.Value); byte[] encoded = timeStampToken.ToCmsSignedData().GetEncoded(); instance = ContentInfo.GetInstance(Asn1Object.FromByteArray(encoded)); } catch (IOException e) { throw new TspException("Timestamp token received cannot be converted to ContentInfo", e); } resp = new TimeStampResp(pkiStatusInfo, instance); } catch (TspValidationException ex) { this.status = PkiStatus.Rejection; this.SetFailInfoField(ex.FailureCode); this.AddStatusString(ex.Message); PkiStatusInfo pkiStatusInfo2 = this.GetPkiStatusInfo(); resp = new TimeStampResp(pkiStatusInfo2, null); } TimeStampResponse result; try { result = new TimeStampResponse(resp); } catch (IOException e2) { throw new TspException("created badly formatted response!", e2); } return(result); }
private static TimeStampResp readTimeStampResp(Asn1InputStream input) { //IL_000f: Expected O, but got Unknown //IL_0022: Expected O, but got Unknown try { return(TimeStampResp.GetInstance(input.ReadObject())); } catch (ArgumentException val) { ArgumentException val2 = val; throw new TspException(string.Concat((object)"malformed timestamp response: ", (object)val2), (global::System.Exception)(object) val2); } catch (InvalidCastException val3) { InvalidCastException val4 = val3; throw new TspException(string.Concat((object)"malformed timestamp response: ", (object)val4), (global::System.Exception)(object) val4); } }
public TimeStampResponse GenerateFailResponse(PkiStatus status, int failInfoField, string statusString) { this.status = status; SetFailInfoField(failInfoField); if (statusString != null) { AddStatusString(statusString); } PkiStatusInfo pkiStatusInfo = GetPkiStatusInfo(); TimeStampResp resp = new TimeStampResp(pkiStatusInfo, null); try { return(new TimeStampResponse(resp)); } catch (IOException e) { throw new TspException("created badly formatted response!", e); } }
public TimeStampResponse GenerateFailResponse(PkiStatus status, int failInfoField, string statusString) { //IL_0031: Expected O, but got Unknown this.status = status; SetFailInfoField(failInfoField); if (statusString != null) { AddStatusString(statusString); } PkiStatusInfo pkiStatusInfo = GetPkiStatusInfo(); TimeStampResp resp = new TimeStampResp(pkiStatusInfo, null); try { return(new TimeStampResponse(resp)); } catch (IOException val) { IOException e = val; throw new TspException("created badly formatted response!", (global::System.Exception)(object) e); } }