Skip to content

Commit 2d6bc92

Browse files
authored
Show SHA256 everywhere. (#10331)
* Ensure we show SHA256 instead of SHA1 hashes. * Fix some tests that were missed.
1 parent 8144598 commit 2d6bc92

9 files changed

Lines changed: 24 additions & 23 deletions

File tree

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -9,14 +9,14 @@ namespace NuGet.Services.Validation.Issues
99
public sealed class UnauthorizedCertificateFailure : ValidationIssue
1010
{
1111
[JsonConstructor]
12-
public UnauthorizedCertificateFailure(string sha1Thumbprint)
12+
public UnauthorizedCertificateFailure(string sha256Thumbprint)
1313
{
14-
Sha1Thumbprint = sha1Thumbprint ?? throw new ArgumentNullException(nameof(sha1Thumbprint));
14+
Sha256Thumbprint = sha256Thumbprint ?? throw new ArgumentNullException(nameof(sha256Thumbprint));
1515
}
1616

1717
public override ValidationIssueCode IssueCode => ValidationIssueCode.PackageIsSignedWithUnauthorizedCertificate;
1818

1919
[JsonProperty("t", Required = Required.Always)]
20-
public string Sha1Thumbprint { get; }
20+
public string Sha256Thumbprint { get; }
2121
}
22-
}
22+
}

src/NuGetGallery.Core/Extensions/ValidationIssueExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -52,7 +52,7 @@ public static string ToMarkdownString(this ValidationIssue validationIssue, stri
5252
return "This package must be signed with a registered certificate. [Read more...](https://aka.ms/nuget-signed-ref)";
5353
case ValidationIssueCode.PackageIsSignedWithUnauthorizedCertificate:
5454
var certIssue = (UnauthorizedCertificateFailure)validationIssue;
55-
return $"The package was signed, but the signing certificate {(certIssue != null ? $"(SHA-1 thumbprint {certIssue.Sha1Thumbprint})" : "")} is not associated with your account. You must register this certificate to publish signed packages. [Read more...](https://aka.ms/nuget-signed-ref)";
55+
return $"The package was signed, but the signing certificate {(certIssue != null ? $"(SHA-256 thumbprint {certIssue.Sha256Thumbprint})" : "")} is not associated with your account. You must register this certificate to publish signed packages. [Read more...](https://aka.ms/nuget-signed-ref)";
5656
case ValidationIssueCode.SymbolErrorCode_ChecksumDoesNotMatch:
5757
return "The checksum does not match for the dll(s) and corresponding pdb(s).";
5858
case ValidationIssueCode.SymbolErrorCode_MatchingAssemblyNotFound:
@@ -68,4 +68,4 @@ public static string ToMarkdownString(this ValidationIssue validationIssue, stri
6868
}
6969
}
7070
}
71-
}
71+
}

src/NuGetGallery/Views/Packages/_ValidationIssue.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
{
5454
var typedIssue = (UnauthorizedCertificateFailure)Model;
5555
<text>
56-
The package was signed, but the signing certificate (SHA-1 thumbprint @typedIssue.Sha1Thumbprint) is not associated with your account.
56+
The package was signed, but the signing certificate (SHA-256 thumbprint @typedIssue.Sha256Thumbprint) is not associated with your account.
5757
You must register this certificate to publish signed packages. <a href="https://aka.ms/nuget-signed-ref">Read more...</a>
5858
</text>
5959
break;
@@ -88,4 +88,4 @@
8888
There was an unknown failure when validating your package.
8989
</text>
9090
break;
91-
}
91+
}

src/StatusAggregator/Job.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public static X509Certificate2 GetCertificateFromConfiguration(string certSecret
359359
certificate = new X509Certificate2(certBytes);
360360
}
361361

362-
logger.LogInformation("Successfully parsed certificate with SHA-1 thumbprint {Thumbprint}", certificate.Thumbprint);
362+
logger.LogInformation("Successfully parsed certificate with SHA-256 thumbprint {SHA256Thumbprint}", certificate.ComputeSHA256Thumbprint());
363363
return certificate;
364364
}
365365
}

src/StatusAggregator/StatusAggregator.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<ProjectReference Include="..\NuGet.Jobs.Common\NuGet.Jobs.Common.csproj" />
88
<ProjectReference Include="..\NuGet.Services.Incidents\NuGet.Services.Incidents.csproj" />
99
<ProjectReference Include="..\NuGet.Services.Status.Table\NuGet.Services.Status.Table.csproj" />
10+
<ProjectReference Include="..\Validation.PackageSigning.Core\Validation.PackageSigning.Core.csproj" />
1011
</ItemGroup>
1112
<ItemGroup>
1213
<None Include="Scripts\*" />

src/Validation.PackageSigning.ProcessSignature/SignatureValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -652,7 +652,7 @@ private async Task<SignatureValidatorResult> ValidatePackageRegistrationSigningR
652652

653653
return await RejectAsync(
654654
context,
655-
new UnauthorizedCertificateFailure(signingCertificate.Thumbprint.ToLowerInvariant()));
655+
new UnauthorizedCertificateFailure(signingFingerprint.ToLowerInvariant()));
656656
}
657657
}
658658

tests/NuGet.Services.Validation.Issues.Tests/ValidationIssuesFacts.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -217,7 +217,7 @@ public void UnauthorizedCertificateFailureDeserialization()
217217
// Assert
218218
Assert.NotNull(result);
219219
Assert.Equal(ValidationIssueCode.PackageIsSignedWithUnauthorizedCertificate, result.IssueCode);
220-
Assert.Equal("thumbprint", result.Sha1Thumbprint);
220+
Assert.Equal("thumbprint", result.Sha256Thumbprint);
221221
}
222222

223223
private PackageValidationIssue CreatePackageValidationIssue(ValidationIssueCode issueCode, string data)

tests/NuGetGallery.Facts/Infrastructure/Mail/MarkdownMessageServiceFacts.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -1372,7 +1372,7 @@ private static string ParseValidationIssue(ValidationIssue validationIssue, stri
13721372
return "This package must be signed with a registered certificate. [Read more...](https://aka.ms/nuget-signed-ref)";
13731373
case ValidationIssueCode.PackageIsSignedWithUnauthorizedCertificate:
13741374
var certIssue = (UnauthorizedCertificateFailure)validationIssue;
1375-
return $"The package was signed, but the signing certificate (SHA-1 thumbprint {certIssue.Sha1Thumbprint}) is not associated with your account. You must register this certificate to publish signed packages. [Read more...](https://aka.ms/nuget-signed-ref)";
1375+
return $"The package was signed, but the signing certificate (SHA-256 thumbprint {certIssue.Sha256Thumbprint}) is not associated with your account. You must register this certificate to publish signed packages. [Read more...](https://aka.ms/nuget-signed-ref)";
13761376
default:
13771377
return "There was an unknown failure when validating your package.";
13781378
}
@@ -2315,7 +2315,7 @@ private static string ParseValidationIssue(ValidationIssue validationIssue, stri
23152315
return "This package must be signed with a registered certificate. [Read more...](https://aka.ms/nuget-signed-ref)";
23162316
case ValidationIssueCode.PackageIsSignedWithUnauthorizedCertificate:
23172317
var certIssue = (UnauthorizedCertificateFailure)validationIssue;
2318-
return $"The package was signed, but the signing certificate (SHA-1 thumbprint {certIssue.Sha1Thumbprint}) is not associated with your account. You must register this certificate to publish signed packages. [Read more...](https://aka.ms/nuget-signed-ref)";
2318+
return $"The package was signed, but the signing certificate (SHA-256 thumbprint {certIssue.Sha256Thumbprint}) is not associated with your account. You must register this certificate to publish signed packages. [Read more...](https://aka.ms/nuget-signed-ref)";
23192319
case ValidationIssueCode.SymbolErrorCode_ChecksumDoesNotMatch:
23202320
return "The checksum does not match for the dll(s) and corresponding pdb(s).";
23212321
case ValidationIssueCode.SymbolErrorCode_MatchingAssemblyNotFound:
@@ -2552,4 +2552,4 @@ private static void AssertMessageSentToMembersOfOrganizationWithPermissionOnly(M
25522552
Assert.Equal(membersAllowedToAct.Count(m => m.EmailAllowed), message.To.Count());
25532553
}
25542554
}
2555-
}
2555+
}

tests/Validation.PackageSigning.ProcessSignature.Tests/SignatureValidatorFacts.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -478,7 +478,7 @@ public async Task RejectsSignedPackagesWithUnknownCertificates(PackageStatus pac
478478
Assert.Single(result.Issues);
479479
var issue = Assert.IsType<UnauthorizedCertificateFailure>(result.Issues[0]);
480480
Assert.Equal(ValidationIssueCode.PackageIsSignedWithUnauthorizedCertificate, issue.IssueCode);
481-
Assert.Equal(TestResources.Leaf2Sha1Thumbprint, issue.Sha1Thumbprint);
481+
Assert.Equal(TestResources.Leaf1Thumbprint, issue.Sha256Thumbprint);
482482
}
483483

484484
[Fact]
@@ -883,7 +883,7 @@ public async Task StripsAndRejectsPackagesWithRepositorySignatureWhenPackageIsAu
883883
Assert.Single(result.Issues);
884884
var issue = Assert.IsType<UnauthorizedCertificateFailure>(result.Issues[0]);
885885
Assert.Equal(ValidationIssueCode.PackageIsSignedWithUnauthorizedCertificate, issue.IssueCode);
886-
Assert.Equal(TestResources.Leaf2Sha1Thumbprint, issue.Sha1Thumbprint);
886+
Assert.Equal(TestResources.Leaf1Thumbprint, issue.Sha256Thumbprint);
887887
}
888888

889889
[Fact]
@@ -1001,4 +1001,4 @@ public async Task WhenPackageRequiresUnsignedPackages_AcceptsUnsignedPackages()
10011001
}
10021002
}
10031003
}
1004-
}
1004+
}

0 commit comments

Comments
 (0)