From 86ede6b714e8b0715dac8c7c092c425cf84f197b Mon Sep 17 00:00:00 2001 From: Kartheek Penagamuri <52756182+kartheekp-ms@users.noreply.github.com> Date: Thu, 4 Jun 2020 12:45:18 -0700 Subject: [PATCH] added GetNonce() to IRfc3161TimestampRequest interface (#3427) --- .../Signing/Timestamp/IRfc3161TimestampRequest.cs | 6 ++++++ .../Signing/Timestamp/Rfc3161TimestampProvider.cs | 3 ++- .../Timestamp/Rfc3161TimestampRequestNet472Wrapper.cs | 5 +++++ .../Rfc3161TimestampRequestNetstandard21Wrapper.cs | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/IRfc3161TimestampRequest.cs b/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/IRfc3161TimestampRequest.cs index 5c0b661cdee..c3af6d089ce 100644 --- a/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/IRfc3161TimestampRequest.cs +++ b/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/IRfc3161TimestampRequest.cs @@ -9,5 +9,11 @@ namespace NuGet.Packaging.Signing internal interface IRfc3161TimestampRequest { Task SubmitRequestAsync(Uri timestampUri, TimeSpan timeout); + + /// + /// Gets the nonce for this timestamp request. + /// + /// The nonce for this timestamp request as byte[], if one was present; otherwise, null + byte[] GetNonce(); } } diff --git a/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampProvider.cs b/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampProvider.cs index e67713f5988..e4e47a6055e 100644 --- a/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampProvider.cs +++ b/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampProvider.cs @@ -103,7 +103,8 @@ public async Task GetTimestampAsync(TimestampRequest request, ILogger RequestTimeout); // quick check for response validity - ValidateTimestampResponse(nonce, request.HashedMessage, timestampToken); + var normalizedNonce = rfc3161TimestampRequest.GetNonce(); + ValidateTimestampResponse(normalizedNonce, request.HashedMessage, timestampToken); var timestampCms = timestampToken.AsSignedCms(); ValidateTimestampCms(request.SigningSpecifications, timestampCms, timestampToken); diff --git a/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampRequestNet472Wrapper.cs b/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampRequestNet472Wrapper.cs index 3df66efde6a..05f722de653 100644 --- a/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampRequestNet472Wrapper.cs +++ b/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampRequestNet472Wrapper.cs @@ -34,6 +34,11 @@ public Task SubmitRequestAsync(Uri timestampUri, TimeSpa { return Task.FromResult(_rfc3161TimestampRequest.SubmitRequest(timestampUri, timeout)); } + + public byte[] GetNonce() + { + return _rfc3161TimestampRequest.GetNonce(); + } } #endif } diff --git a/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampRequestNetstandard21Wrapper.cs b/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampRequestNetstandard21Wrapper.cs index 6bbf67cab7c..3348b53c268 100644 --- a/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampRequestNetstandard21Wrapper.cs +++ b/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampRequestNetstandard21Wrapper.cs @@ -85,6 +85,12 @@ public async Task SubmitRequestAsync(Uri timestampUri, T } } } + + public byte[] GetNonce() + { + ReadOnlyMemory? normalizedNonce = _rfc3161TimestampRequest.GetNonce(); + return normalizedNonce.HasValue ? normalizedNonce.Value.ToArray() : null; + } } #endif }