public async Task <IRfc3161TimestampToken> SubmitRequestAsync(Uri timestampUri, TimeSpan timeout) { if (timestampUri == null) { throw new ArgumentNullException(nameof(timestampUri)); } if (!timestampUri.IsAbsoluteUri) { throw new ArgumentException( Strings.AnAbsoluteUriIsRequired, nameof(timestampUri)); } if (timestampUri.Scheme != Uri.UriSchemeHttp && timestampUri.Scheme != Uri.UriSchemeHttps) { throw new ArgumentException( Strings.HttpOrHttpsIsRequired, nameof(timestampUri)); } using (var content = new ReadOnlyMemoryContent(_rfc3161TimestampRequest.Encode())) { content.Headers.ContentType = new MediaTypeHeaderValue("application/timestamp-query"); using (HttpResponseMessage httpResponse = await HttpClient.PostAsync(timestampUri, content)) { if (!httpResponse.IsSuccessStatusCode) { throw new CryptographicException( string.Format( CultureInfo.CurrentCulture, Strings.TimestampServiceRespondedError, (int)httpResponse.StatusCode, httpResponse.ReasonPhrase)); } if (!string.Equals(httpResponse.Content.Headers.ContentType.MediaType, "application/timestamp-response", StringComparison.OrdinalIgnoreCase)) { throw new CryptographicException(Strings.TimestampServiceRespondedInvalidFormat); } var data = await httpResponse.Content.ReadAsByteArrayAsync(); System.Security.Cryptography.Pkcs.Rfc3161TimestampToken response = _rfc3161TimestampRequest.ProcessResponse(data, out var _); var timestampToken = new Rfc3161TimestampTokenNetstandard21Wrapper(response); return(timestampToken); } } }
public static IRfc3161TimestampToken Create( IRfc3161TimestampTokenInfo tstInfo, X509Certificate2 signerCertificate, X509Certificate2Collection additionalCerts, byte[] encoded) { if (tstInfo == null) { throw new ArgumentNullException(nameof(tstInfo)); } if (signerCertificate == null) { throw new ArgumentNullException(nameof(signerCertificate)); } if (additionalCerts == null) { throw new ArgumentNullException(nameof(additionalCerts)); } if (encoded == null) { throw new ArgumentNullException(nameof(encoded)); } #if IS_SIGNING_SUPPORTED IRfc3161TimestampToken iRfc3161TimestampToken = null; #if IS_DESKTOP iRfc3161TimestampToken = new Rfc3161TimestampTokenNet472Wrapper( tstInfo, signerCertificate, additionalCerts, encoded); #else iRfc3161TimestampToken = new Rfc3161TimestampTokenNetstandard21Wrapper( tstInfo, signerCertificate, additionalCerts, encoded); #endif return(iRfc3161TimestampToken); #else throw new NotSupportedException(); #endif }