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

Implement TOFU for package downloads #3890

Merged
merged 1 commit into from
Dec 9, 2021
Merged

Conversation

yim-lee
Copy link
Contributor

@yim-lee yim-lee commented Nov 30, 2021

This is a continuation of #3879.

Wire up fingerprint storage such that it is used for integrity checks of package downloads. Fingerprint must match previously recorded value (if any) or else it would result in an error.

  • Registry downloads
  • Git clones
  • Option (strictFingerprintChecking) to ignore TOFU failures (i.e., error -> warning)
  • .swiftpm/security/fingerprints/

@yim-lee yim-lee marked this pull request as draft November 30, 2021 22:31
@yim-lee
Copy link
Contributor Author

yim-lee commented Nov 30, 2021

@swift-ci please smoke test

@yim-lee yim-lee marked this pull request as ready for review December 1, 2021 19:07
@yim-lee yim-lee changed the title [Draft] Implement TOFU for package downloads Implement TOFU for package downloads Dec 1, 2021
@yim-lee
Copy link
Contributor Author

yim-lee commented Dec 1, 2021

@swift-ci please smoke test

private let jsonDecoder: JSONDecoder

public init(configuration: RegistryConfiguration,
identityResolver: IdentityResolver,
customArchiverProvider: ((FileSystem) -> Archiver)? = nil,
customHTTPClient: HTTPClient? = nil,
authorizationProvider: HTTPClientAuthorizationProvider? = nil)
authorizationProvider: HTTPClientAuthorizationProvider? = nil,
fingerprintStorage: PackageFingerprintStorage? = nil)
Copy link
Contributor

@tomerd tomerd Dec 1, 2021

Choose a reason for hiding this comment

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

should authorizationProvider and fingerprintStorage be non-optional? they feel like they should be required (ie they are not customization like customHTTPClient which is optional). If this was made optional for unit tests, we can create extensions in the test module to make it easier to construct while keeping the main constructor "correct"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only reason fingerprintStorage is optional is because sharedCacheDirectory is optional. What should we default storage path to in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fingerprintStorage is non-optional 036385b

Copy link
Contributor

@tomerd tomerd left a comment

Choose a reason for hiding this comment

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

this is great. some suggestions / questions inline

@yim-lee
Copy link
Contributor Author

yim-lee commented Dec 2, 2021

cc @andyp-apple and @robertlacroix

@tomerd
Copy link
Contributor

tomerd commented Dec 2, 2021

very nice 👍

guard revision.identifier == fingerprint.value else {
throw StringError("Source control fingerprint \(revision.identifier) for \(self.package) version=\(version) does not match previously recorded value \(fingerprint.value)")
}
}

/// Returns revision for the given tag.
Copy link
Contributor

Choose a reason for hiding this comment

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

can this new private now?

@yim-lee
Copy link
Contributor Author

yim-lee commented Dec 3, 2021

@swift-ci please smoke test

@yim-lee
Copy link
Contributor Author

yim-lee commented Dec 4, 2021

@swift-ci please smoke test

}

// The revision (i.e., hash) must match that in fingerprint storage otherwise the integrity check fails
if revision.identifier != fingerprint.value {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this check move to L169 (inside the first case basically)?

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 could be, but then any error thrown would get caught in the catch block (if you recall the code was checking for StringError specifically) and the code wouldn't be as clean.

Copy link
Contributor

@tomerd tomerd left a comment

Choose a reason for hiding this comment

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

nice!

Wire up fingerprint storage such that it is used for integrity checks of package downloads. Fingerprint must match previously recorded value (if any) or else it would result in an error.
@yim-lee
Copy link
Contributor Author

yim-lee commented Dec 9, 2021

@swift-ci please smoke test

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