Skip to content

Integrate swift-certificates library #6216

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 4 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ if(FIND_PM_DEPS)
find_package(ArgumentParser CONFIG REQUIRED)
find_package(SwiftDriver CONFIG REQUIRED)
find_package(SwiftCollections CONFIG REQUIRED)
find_package(SwiftCertificates CONFIG REQUIRED)
find_package(SwiftCrypto CONFIG REQUIRED)
endif()

find_package(dispatch QUIET)
Expand Down
21 changes: 21 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,34 @@ Clone the following repositories beside the SwiftPM directory:
For example, if the latest tag is 1.0.1:
```sh
$> git clone https://github.com/apple/swift-collections --branch 1.0.1
```

7. [swift-crypto] and check out tag with the [latest version](https://github.com/apple/swift-crypto/tags).

For example, if the latest tag is 2.3.0:
```sh
$> git clone https://github.com/apple/swift-crypto --branch 2.3.0
```

8. [swift-asn1]
```sh
$> git clone https://github.com/apple/swift-asn1
```

9. [swift-certificates]
```sh
$> git clone https://github.com/apple/swift-certificates
```

[swift-argument-parser]: https://github.com/apple/swift-argument-parser
[swift-collections]: https://github.com/apple/swift-collections
[swift-driver]: https://github.com/apple/swift-driver
[swift-llbuild]: https://github.com/apple/swift-llbuild
[swift-system]: https://github.com/apple/swift-system
[swift-tools-support-core]: https://github.com/apple/swift-tools-support-core
[swift-crypto]: https://github.com/apple/swift-crypto
[swift-asn1]: https://github.com/apple/swift-asn1
[swift-certificates]: https://github.com/apple/swift-certificates
[Yams]: https://github.com/jpsim/yams


Expand Down
18 changes: 6 additions & 12 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ automatic linking type with `-auto` suffix appended to product's name.
*/
let autoProducts = [swiftPMProduct, swiftPMDataModelProduct]

let useSwiftCryptoV2 = ProcessInfo.processInfo.environment["SWIFTPM_USE_SWIFT_CRYPTO_V1"] == nil
let minimumCryptoVersion: Version = useSwiftCryptoV2 ? "2.2.3" : "1.1.7"
var swiftSettings: [SwiftSetting] = []
if useSwiftCryptoV2 {
swiftSettings.append(.define("CRYPTO_v2"))
}

var packageCollectionsSigningTargets = [Target]()
var packageCollectionsSigningDeps: [Target.Dependency] = [
"Basics",
Expand Down Expand Up @@ -96,8 +89,7 @@ packageCollectionsSigningTargets.append(
.target(
/** Package collections signing */
name: "PackageCollectionsSigning",
dependencies: packageCollectionsSigningDeps,
swiftSettings: swiftSettings
dependencies: packageCollectionsSigningDeps
)
)

Expand Down Expand Up @@ -294,10 +286,10 @@ let package = Package(
.target(
name: "PackageSigning",
dependencies: [
// TODO: uncomment once we resolve build problems
// .product(name: "Crypto", package: "swift-crypto"),
.product(name: "Crypto", package: "swift-crypto"),
"Basics",
"PackageModel",
.product(name: "X509", package: "swift-certificates"),
],
exclude: ["CMakeLists.txt"]
),
Expand Down Expand Up @@ -730,9 +722,10 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
// dependency version changes here with those projects.
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "1.2.2")),
.package(url: "https://github.com/apple/swift-driver.git", .branch(relatedDependenciesBranch)),
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: minimumCryptoVersion)),
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: "2.3.0")),
.package(url: "https://github.com/apple/swift-system.git", .upToNextMinor(from: "1.1.1")),
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMinor(from: "1.0.1")),
.package(url: "https://github.com/apple/swift-certificates.git", branch: "main"),
]
} else {
package.dependencies += [
Expand All @@ -742,6 +735,7 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
.package(path: "../swift-crypto"),
.package(path: "../swift-system"),
.package(path: "../swift-collections"),
.package(path: "../swift-certificates"),
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@ struct CoreCertificate {

#elseif os(Linux) || os(Windows) || os(Android)
final class BoringSSLCertificate {
#if CRYPTO_v2
typealias Pointer = OpaquePointer
#else
typealias Pointer = UnsafeMutablePointer<X509>
#endif

private let underlying: Pointer

Expand Down Expand Up @@ -203,11 +199,7 @@ final class BoringSSLCertificate {
}

private extension CertificateName {
#if CRYPTO_v2
typealias Pointer = OpaquePointer
#else
typealias Pointer = UnsafeMutablePointer<X509_NAME>
#endif

init(x509Name: Pointer) {
func getStringValue(from name: Pointer, of nid: CInt) -> String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@ extension CertificatePolicy {
}

#elseif os(Linux) || os(Windows) || os(Android)
#if CRYPTO_v2
typealias BoringSSLVerifyCallback = @convention(c) (CInt, OpaquePointer?) -> CInt
#else
typealias BoringSSLVerifyCallback = @convention(c) (CInt, UnsafeMutablePointer<X509_STORE_CTX>?) -> CInt
#endif

/// Verifies a certificate chain.
///
Expand Down
5 changes: 4 additions & 1 deletion Utilities/Docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This source file is part of the Swift open source project
#
# Copyright (c) 2021 Apple Inc. and the Swift project authors
# Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -36,10 +36,13 @@ services:
- ../../../swift-tools-support-core:/code/swift-tools-support-core:z
- ../../../yams:/code/yams:z
- ../../../swift-argument-parser:/code/swift-argument-parser:z
- ../../../swift-crypto:/code/swift-crypto:z
- ../../../swift-driver:/code/swift-driver:z
- ../../../swift-llbuild:/code/llbuild:z
- ../../../swift-system:/code/swift-system:z
- ../../../swift-collections:/code/swift-collections:z
- ../../../swift-asn1:/code/swift-asn1:z
- ../../../swift-certificates:/code/swift-certificates:z
working_dir: /code/swift-package-manager
cap_drop:
- CAP_NET_RAW
Expand Down
29 changes: 23 additions & 6 deletions Utilities/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
This source file is part of the Swift open source project
//
// Copyright (c) 2014-2021 Apple Inc. and the Swift project authors
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -184,9 +184,12 @@ def parse_global_args(args):
args.source_dirs["tsc"] = os.path.join(args.project_root, "..", "swift-tools-support-core")
args.source_dirs["yams"] = os.path.join(args.project_root, "..", "yams")
args.source_dirs["swift-argument-parser"] = os.path.join(args.project_root, "..", "swift-argument-parser")
args.source_dirs["swift-crypto"] = os.path.join(args.project_root, "..", "swift-crypto")
args.source_dirs["swift-driver"] = os.path.join(args.project_root, "..", "swift-driver")
args.source_dirs["swift-system"] = os.path.join(args.project_root, "..", "swift-system")
args.source_dirs["swift-collections"] = os.path.join(args.project_root, "..", "swift-collections")
args.source_dirs["swift-certificates"] = os.path.join(args.project_root, "..", "swift-certificates")
args.source_dirs["swift-asn1"] = os.path.join(args.project_root, "..", "swift-asn1")
args.source_root = os.path.join(args.project_root, "Sources")

if platform.system() == 'Darwin':
Expand Down Expand Up @@ -351,6 +354,11 @@ def build(args):
]
build_dependency(args, "swift-driver", swift_driver_cmake_flags)
build_dependency(args, "swift-collections")
build_dependency(args, "swift-crypto")
build_dependency(args, "swift-asn1")
build_dependency(args, "swift-certificates",
["-DSwiftASN1_DIR=" + os.path.join(args.build_dirs["swift-asn1"], "cmake/modules"),
"-DSwiftCrypto_DIR=" + os.path.join(args.build_dirs["swift-crypto"], "cmake/modules")])
build_swiftpm_with_cmake(args)

build_swiftpm_with_swiftpm(args,integrated_swift_driver=False)
Expand Down Expand Up @@ -592,11 +600,14 @@ def build_swiftpm_with_cmake(args):

cmake_flags = [
get_llbuild_cmake_arg(args),
"-DTSC_DIR=" + os.path.join(args.build_dirs["tsc"], "cmake/modules"),
"-DArgumentParser_DIR=" + os.path.join(args.build_dirs["swift-argument-parser"], "cmake/modules"),
"-DSwiftDriver_DIR=" + os.path.join(args.build_dirs["swift-driver"], "cmake/modules"),
"-DSwiftSystem_DIR=" + os.path.join(args.build_dirs["swift-system"], "cmake/modules"),
"-DSwiftCollections_DIR=" + os.path.join(args.build_dirs["swift-collections"], "cmake/modules"),
"-DTSC_DIR=" + os.path.join(args.build_dirs["tsc"], "cmake/modules"),
"-DArgumentParser_DIR=" + os.path.join(args.build_dirs["swift-argument-parser"], "cmake/modules"),
"-DSwiftDriver_DIR=" + os.path.join(args.build_dirs["swift-driver"], "cmake/modules"),
"-DSwiftSystem_DIR=" + os.path.join(args.build_dirs["swift-system"], "cmake/modules"),
"-DSwiftCollections_DIR=" + os.path.join(args.build_dirs["swift-collections"], "cmake/modules"),
"-DSwiftCrypto_DIR=" + os.path.join(args.build_dirs["swift-crypto"], "cmake/modules"),
"-DSwiftASN1_DIR=" + os.path.join(args.build_dirs["swift-asn1"], "cmake/modules"),
"-DSwiftCertificates_DIR=" + os.path.join(args.build_dirs["swift-certificates"], "cmake/modules"),
]

if platform.system() == 'Darwin':
Expand All @@ -611,9 +622,12 @@ def build_swiftpm_with_cmake(args):
if platform.system() == "Darwin":
add_rpath_for_cmake_build(args, os.path.join(args.build_dirs["yams"], "lib"))
add_rpath_for_cmake_build(args, os.path.join(args.build_dirs["swift-argument-parser"], "lib"))
add_rpath_for_cmake_build(args, os.path.join(args.build_dirs["swift-crypto"], "lib"))
add_rpath_for_cmake_build(args, os.path.join(args.build_dirs["swift-driver"], "lib"))
add_rpath_for_cmake_build(args, os.path.join(args.build_dirs["swift-system"], "lib"))
add_rpath_for_cmake_build(args, os.path.join(args.build_dirs["swift-collections"], "lib"))
add_rpath_for_cmake_build(args, os.path.join(args.build_dirs["swift-asn1"], "lib"))
add_rpath_for_cmake_build(args, os.path.join(args.build_dirs["swift-certificates"], "lib"))

# rpaths for compatibility libraries
for lib_path in get_swift_backdeploy_library_paths(args):
Expand Down Expand Up @@ -724,9 +738,12 @@ def get_swiftpm_env_cmd(args):
os.path.join(args.build_dirs["llbuild"], "lib"),
os.path.join(args.build_dirs["yams"], "lib"),
os.path.join(args.build_dirs["swift-argument-parser"], "lib"),
os.path.join(args.build_dirs["swift-crypto"], "lib"),
os.path.join(args.build_dirs["swift-driver"], "lib"),
os.path.join(args.build_dirs["swift-system"], "lib"),
os.path.join(args.build_dirs["swift-collections"], "lib"),
os.path.join(args.build_dirs["swift-asn1"], "lib"),
os.path.join(args.build_dirs["swift-certificates"], "lib"),
] + args.target_info["paths"]["runtimeLibraryPaths"])

if platform.system() == 'Darwin':
Expand Down