public async Task TimestampData_WithValidInput_ReturnsTimestamp() { var logger = new TestLogger(); var timestampService = await _testFixture.GetDefaultTrustedTimestampServiceAsync(); var timestampProvider = new Rfc3161TimestampProvider(timestampService.Url); var data = "Test data to be signed and timestamped"; using (var authorCert = new X509Certificate2(_trustedTestCert.Source.Cert)) { var signedCms = SigningTestUtility.GenerateSignedCms(authorCert, Encoding.ASCII.GetBytes(data)); var signatureValue = signedCms.Encode(); var request = new TimestampRequest { SigningSpec = SigningSpecifications.V1, TimestampHashAlgorithm = Common.HashAlgorithmName.SHA256, Signature = signatureValue }; // Act var timestampedData = timestampProvider.TimestampData(request, logger, CancellationToken.None); var timestampedCms = new SignedCms(); timestampedCms.Decode(timestampedData); // Assert timestampedData.Should().NotBeNull(); timestampedCms.Should().NotBeNull(); timestampedCms.Detached.Should().BeFalse(); timestampedCms.ContentInfo.Should().NotBeNull(); timestampedCms.SignerInfos.Count.Should().Be(1); timestampedCms.SignerInfos[0].UnsignedAttributes.Count.Should().Be(1); timestampedCms.SignerInfos[0].UnsignedAttributes[0].Oid.Value.Should().Be(Oids.SignatureTimeStampTokenAttribute); } }
public void Rfc3161TimestampProvider_Success() { // Arrange var logger = new TestLogger(); var timestampProvider = new Rfc3161TimestampProvider(new Uri(_testTimestampServer)); var data = "Test data to be signed and timestamped"; using (var authorCert = new X509Certificate2(_trustedTestCert.Source.Cert)) { var signedCms = SigningTestUtility.GenerateSignedCms(authorCert, Encoding.ASCII.GetBytes(data)); var signatureValue = signedCms.Encode(); var request = new TimestampRequest { Certificate = authorCert, SigningSpec = SigningSpecifications.V1, TimestampHashAlgorithm = Common.HashAlgorithmName.SHA256, SignatureValue = signatureValue }; // Act var timestampedData = timestampProvider.TimestampData(request, logger, CancellationToken.None); var timestampedCms = new SignedCms(); timestampedCms.Decode(timestampedData); // Assert timestampedData.Should().NotBeNull(); timestampedCms.Should().NotBeNull(); timestampedCms.Detached.Should().BeFalse(); timestampedCms.ContentInfo.Should().NotBeNull(); timestampedCms.Certificates.Count.Should().Be(1); timestampedCms.SignerInfos.Count.Should().Be(1); timestampedCms.SignerInfos[0].UnsignedAttributes.Count.Should().Be(1); timestampedCms.SignerInfos[0].UnsignedAttributes[0].Oid.Value.Should().Be(Oids.SignatureTimeStampTokenAttributeOid); } }