Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor AllowListVerificationProvider #2454

Merged
merged 6 commits into from
Oct 9, 2018
Merged

Conversation

PatoBeltran
Copy link
Contributor

@PatoBeltran PatoBeltran commented Oct 3, 2018

Bug

Fixes: Fourth part of NuGet/Home#6961

Fix

Refactored AllowListVerificationProvider to only receive one list and be used multiple times if needed.

Removed allow lists from SignedPackageVerifierSettings since they only apply for the AllowListVerificationProvider and should not be part of the settings.

Created a ClientPolicyContext to store the data related to the signature verification with the appropriate client policies.

This PR does not include any functional changes to the verification behavior.

@PatoBeltran PatoBeltran self-assigned this Oct 3, 2018
@PatoBeltran PatoBeltran force-pushed the dev-pb-allowUntrusted branch 2 times, most recently from aa2e608 to 43fdc99 Compare October 4, 2018 18:47
@PatoBeltran PatoBeltran changed the title [WIP] Refactor AllowListVerificationProvider and using allowUntrustedRoot in chain validation [WIP] Refactor AllowListVerificationProvider Oct 4, 2018
@PatoBeltran PatoBeltran force-pushed the dev-pb-allowUntrusted branch 2 times, most recently from 1217003 to f47311b Compare October 4, 2018 20:45
@PatoBeltran PatoBeltran changed the title [WIP] Refactor AllowListVerificationProvider Refactor AllowListVerificationProvider Oct 4, 2018
@PatoBeltran PatoBeltran force-pushed the dev-pb-allowUntrusted branch 2 times, most recently from 8021b23 to 16c4598 Compare October 5, 2018 22:59
@PatoBeltran PatoBeltran force-pushed the dev-pb-allowUntrusted branch from 16c4598 to 60b8736 Compare October 8, 2018 02:25
Copy link
Member

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall.
Couple of small questions.

src/NuGet.Core/NuGet.Commands/Strings.resx Show resolved Hide resolved
/// <summary>
/// Require AllowList to not be null or empty
/// </summary>
public bool RequireNonEmptyAllowList { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need this?

Doesn't SignatureValidationMode already tell you whether it can non-empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not strictly necessary since we calculate it from the SignatureValidationMode (here). I thought it was good for the sake of readability. Do you think we should remove this and just use the Policy attribute for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I'd prefer that.

<value>A list of trusted signers is required but none was found.</value>
</data>
<data name="DefaultError_NoMatchInAllowList" xml:space="preserve">
<value>The package signature certificate fingerprint does not match any certificate fingerprint in allow list.</value>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: in the allow list.

Copy link
Member

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

Copy link
Contributor

@jainaashish jainaashish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

verificationProviders.Add(new AllowListVerificationProvider(
repositoryAllowList,
repositorySignatureInfo.AllRepositorySigned,
Strings.Error_NoRepoAllowList,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you really need to pass these string literals? it's confusing to understand the message or meaning of these strings...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our context, this verification provided is used in two different ways. One is to verify that a package is signed by the certificate that the repository announces, and the other is to verify that the package is allowed by the client. These strings are used to give a more detailed error message in the case of failure for the different usages of this provider.

Do you think there is a better way to accomplish this? Will adding named parameters to this call improve the readability?


var allowListResults = await Task.WhenAll(certificateListVertificationRequests.Select(r => VerifyAllowList(r, settings.AllowUntrusted)));
_emptyListErrorMessage = string.IsNullOrEmpty(emptyListErrorMessage) ? Strings.DefaultError_EmptyAllowList : emptyListErrorMessage;
_noMatchErrorMessage = string.IsNullOrEmpty(noMatchErrorMessage) ? Strings.DefaultError_NoMatchInAllowList : noMatchErrorMessage;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont understand the purpose of these strings literals... but seems very vague


return new SignedPackageVerificationResult(GetValidity(allowListResults), signature, allowListResults.SelectMany(r => r.Issues));
public Task<PackageVerificationResult> GetTrustResultAsync(ISignedPackageReader package, PrimarySignature signature, SignedPackageVerifierSettings settings, CancellationToken token)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if you really need async here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to implement the ISignatureVerificationProvider interface. All verification providers work this way

@PatoBeltran PatoBeltran merged commit f7143c4 into dev Oct 9, 2018
@PatoBeltran PatoBeltran deleted the dev-pb-allowUntrusted branch October 9, 2018 20:32
PatoBeltran added a commit that referenced this pull request Oct 17, 2018
* SignedPackageVerifierSettings should not have allowList information

* allowListVerificationProvider should only receive one allowList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants