|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the SwiftNIO open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2019-2021 Apple Inc. and the SwiftNIO project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of SwiftNIO project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +#if os(Android) |
| 16 | +/// The path to the root CA bundle directory. |
| 17 | +/// |
| 18 | +/// May be nil if we could not find the root CA bundle directory. |
| 19 | +internal let rootCADirectoryPath: String? = locateRootCADirectory() |
| 20 | + |
| 21 | +/// This is a list of root CA directory search paths. |
| 22 | +/// |
| 23 | +/// This list contains paths as validated against several distributions. If you are aware of a CA bundle on a specific distribution |
| 24 | +/// that is not present here, please open a pull request that adds the appropriate search path. |
| 25 | +/// Some distributions do not ship CA directories: as such, it is not a problem if a distribution that is present in rootCAFileSearchPaths |
| 26 | +/// is not present in this list. |
| 27 | +//see https://android.googlesource.com/platform/frameworks/base/+/8b192b19f264a8829eac2cfaf0b73f6fc188d933%5E%21/#F0 |
| 28 | +private let rootCADirectorySearchPaths = [ |
| 29 | + "/apex/com.android.conscrypt/cacerts", // >= Android14 |
| 30 | + "/system/etc/security/cacerts", // < Android14 |
| 31 | +] |
| 32 | + |
| 33 | +private func locateRootCADirectory() -> String? { |
| 34 | + return rootCADirectorySearchPaths.first(where: { FileSystemObject.pathType(path: $0) == .directory }) |
| 35 | +} |
| 36 | +#endif |
0 commit comments