Skip to content

Bump minimum swift-crypto v2 version to 2.0.1 #3859

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

Merged
merged 2 commits into from
Nov 15, 2021

Conversation

yim-lee
Copy link
Contributor

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

Motivation:

Test and upgrade to the latest swift-crypto 2.0.1 release, which
includes a BoringSSL update: apple/swift-crypto#95

Modifications:

Tests that use real certs, which execute the OCSP code path, crash on Linux (swift:5.5 and swift:5.5-focal docker images). (rdar://85280061)

The crash happens on L351 of CertificatePolicy.swift (BoringSSLOCSPClient.checkStatus) because response, an OCSP_RESPONSE pointer, is NULL. It is NULL because the logic in BoringSSL's crypto/asn1/asn1_lib.c has changed (google/boringssl@ee510f5), so the return value needs to be handled differently in PackageCollectionsSigningLibc/asn1/a_d2i_fp.c.

I also don't think this change is correct: google/boringssl@efab69b#diff-dc711de78524fcd1edcc461a96ca36b80cac1bf03a67287a9b434f772a6f4e3dR170.

  • Guard against NULL OCSP response in BoringSSLOCSPClient.
  • Update logic in PackageCollectionsSigningLibc/asn1/a_d2i_fp.c:
    • Add ASN1_get_object_without_inf and asn1_get_length_without_inf, copied from BoringSSL but reverting the "0x80 fix", such that we use the same logic regardless of swift-crypto version. We can probably remove them later when we switch over to swift-crypto 2.x completely (unless I'm correct the 0x80 fix).
    • Remove inf in asn1_d2i_read_bio.
    • Note that there are ASN1_get_object_with_inf and asn1_get_length_with_inf too. We can use these instead to keep the same behavior as swift-crypt 2.0.0 and less. I will delete these if reviewers are ok with the current approach.

Motivation:

Test and upgrade to the latest swift-crypto [2.0.1](https://github.com/apple/swift-crypto/releases/tag/2.0.1) release, which
includes a BoringSSL update: apple/swift-crypto#95

Modifications:

Tests that use real certs, which execute the OCSP code path, crash on Linux (`swift:5.5` and `swift:5.5-focal` docker images). (rdar://85280061)

The crash happens on L351 of `CertificatePolicy.swift` (`BoringSSLOCSPClient.checkStatus`) because `response`, an `OCSP_RESPONSE` pointer, is `NULL`. It is `NULL` because the logic in BoringSSL's `crypto/asn1/asn1_lib.c` has changed (google/boringssl@ee510f5), so the return value needs to be handled differently in `PackageCollectionsSigningLibc/asn1/a_d2i_fp.c`.

I also don't think this change is correct: google/boringssl@efab69b#diff-dc711de78524fcd1edcc461a96ca36b80cac1bf03a67287a9b434f772a6f4e3dR170.

- Guard against `NULL` OCSP response in `BoringSSLOCSPClient`.
- Update logic in `PackageCollectionsSigningLibc/asn1/a_d2i_fp.c`:
  - Add `ASN1_get_object_without_inf` and `asn1_get_length_without_inf`, copied from [BoringSSL](https://github.com/google/boringssl/blob/ee510f58895c6a88b59f1b66a94939d08ebdfe5b/crypto/asn1/asn1_lib.c) but reverting the ["0x80 fix"](google/boringssl@efab69b#diff-dc711de78524fcd1edcc461a96ca36b80cac1bf03a67287a9b434f772a6f4e3dR170), such that we use the same logic regardless of swift-crypto version. We can probably remove them later when we switch over to swift-crypto 2.x completely (unless I'm correct the 0x80 fix).
  - Remove `inf` in `asn1_d2i_read_bio`.
  - Note that there are `ASN1_get_object_with_inf` and `asn1_get_length_with_inf` too. We can use these instead to keep the same behavior as swift-crypt 2.0.0 and less. I will delete these if reviewers are ok with the current approach.
@yim-lee
Copy link
Contributor Author

yim-lee commented Nov 11, 2021

@swift-ci please smoke test

@yim-lee
Copy link
Contributor Author

yim-lee commented Nov 11, 2021

@Lukasa I would appreciate if you can take a look at this as well. Thanks!

@tomerd
Copy link
Contributor

tomerd commented Nov 11, 2021

linux CI failure on asyncTest expected until CI gets newer toolchain cc @shahmishal

@shahmishal
Copy link
Member

We have a new toolchain, please re-request testing.

@tomerd
Copy link
Contributor

tomerd commented Nov 11, 2021

@swift-ci please smoke test linux

@@ -54,7 +54,7 @@ automatic linking type with `-auto` suffix appended to product's name.
let autoProducts = [swiftPMProduct, swiftPMDataModelProduct]

let useSwiftCryptoV2 = ProcessInfo.processInfo.environment["SWIFTPM_USE_SWIFT_CRYPTO_V2"] != nil
Copy link
Member

Choose a reason for hiding this comment

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

Are there any plans to update build-script and the CI to swift-crypto v2? Since this variable is not set, I think it's still testing against 1.1.5.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this variable is not set, I think it's still testing against 1.1.5

Right, SwiftPM is still using swift-crypto v1.

Are there any plans to update build-script and the CI to swift-crypto v2?

No specific timeline yet. So far I've been testing locally (to do additional test cases that CI can't cover) whenever there's a new swift-crypto release. When we are ready to upgrade to v2 we'll probably remove this env var and stick with build-script.

Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Looks fine aside from the memory leak.

@yim-lee
Copy link
Contributor Author

yim-lee commented Nov 12, 2021

@swift-ci please smoke test

@yim-lee yim-lee merged commit 56dfe45 into swiftlang:main Nov 15, 2021
@yim-lee yim-lee deleted the swift-crypto-2.0.1 branch November 15, 2021 22:35
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.

6 participants