├── .github ├── dependabot.yml └── workflows │ └── build.yml ├── .gitignore ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-CCADB ├── LICENSE-MIT ├── README.md ├── webpki-ccadb ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md └── src │ ├── data │ └── DigiCertGlobalRootCA.pem │ └── lib.rs ├── webpki-root-certs ├── Cargo.toml ├── LICENSE ├── README.md ├── src │ └── lib.rs └── tests │ ├── codegen.rs │ └── smoketest.rs └── webpki-roots ├── Cargo.toml ├── LICENSE ├── README.md ├── src └── lib.rs └── tests ├── codegen.rs ├── data └── tubitak │ ├── inter.der │ ├── root.der │ └── subj.der └── verify.rs /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: cargo 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 10 8 | - package-ecosystem: github-actions 9 | directory: "/" 10 | schedule: 11 | interval: weekly 12 | open-pull-requests-limit: 10 13 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: webpki-roots 2 | 3 | on: 4 | push: 5 | branches: ['main', 'ci/*'] 6 | pull_request: 7 | schedule: 8 | - cron: '0 18 * * *' 9 | workflow_dispatch: 10 | 11 | jobs: 12 | build: 13 | name: Build+test 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Checkout sources 17 | uses: actions/checkout@v4 18 | with: 19 | persist-credentials: false 20 | 21 | - name: Install stable toolchain 22 | uses: dtolnay/rust-toolchain@stable 23 | 24 | - name: cargo build (debug; default features) 25 | run: cargo build --all-targets 26 | 27 | - name: cargo fmt 28 | run: cargo fmt -- --check 29 | 30 | - name: cargo clippy 31 | run: cargo clippy --all-targets -- -D warnings 32 | 33 | - name: cargo test (debug; default features) 34 | run: cargo test 35 | 36 | semver: 37 | name: Check semver compatibility 38 | runs-on: ubuntu-latest 39 | steps: 40 | - name: Checkout sources 41 | uses: actions/checkout@v4 42 | with: 43 | persist-credentials: false 44 | 45 | - name: Check semver 46 | uses: obi1kenobi/cargo-semver-checks-action@v2 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | cabundle.pem 3 | Cargo.lock 4 | fetched.pem 5 | *.pyc 6 | .idea 7 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["webpki-ccadb", "webpki-root-certs", "webpki-roots"] 3 | resolver = "2" 4 | 5 | [workspace.package] 6 | edition = "2021" 7 | homepage = "https://github.com/rustls/webpki-roots" 8 | repository = "https://github.com/rustls/webpki-roots" 9 | 10 | [workspace.dependencies] 11 | hex = "0.4.3" 12 | pki-types = { package = "rustls-pki-types", version = "1.8", default-features = false } 13 | webpki = { package = "rustls-webpki", version = "0.102", features = ["alloc"] } 14 | x509-parser = "0.17.0" 15 | yasna = "0.5.2" 16 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2023 Dirkjan Ochtman 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-CCADB: -------------------------------------------------------------------------------- 1 | # Community Data License Agreement - Permissive - Version 2.0 2 | 3 | This is the Community Data License Agreement - Permissive, Version 4 | 2.0 (the "agreement"). Data Provider(s) and Data Recipient(s) agree 5 | as follows: 6 | 7 | ## 1. Provision of the Data 8 | 9 | 1.1. A Data Recipient may use, modify, and share the Data made 10 | available by Data Provider(s) under this agreement if that Data 11 | Recipient follows the terms of this agreement. 12 | 13 | 1.2. This agreement does not impose any restriction on a Data 14 | Recipient's use, modification, or sharing of any portions of the 15 | Data that are in the public domain or that may be used, modified, 16 | or shared under any other legal exception or limitation. 17 | 18 | ## 2. Conditions for Sharing Data 19 | 20 | 2.1. A Data Recipient may share Data, with or without modifications, so 21 | long as the Data Recipient makes available the text of this agreement 22 | with the shared Data. 23 | 24 | ## 3. No Restrictions on Results 25 | 26 | 3.1. This agreement does not impose any restriction or obligations 27 | with respect to the use, modification, or sharing of Results. 28 | 29 | ## 4. No Warranty; Limitation of Liability 30 | 31 | 4.1. All Data Recipients receive the Data subject to the following 32 | terms: 33 | 34 | THE DATA IS PROVIDED ON AN "AS IS" BASIS, WITHOUT REPRESENTATIONS, 35 | WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED 36 | INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, 37 | NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 38 | 39 | NO DATA PROVIDER SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, 40 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING 41 | WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF 42 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 43 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE DATA OR RESULTS, 44 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 45 | 46 | ## 5. Definitions 47 | 48 | 5.1. "Data" means the material received by a Data Recipient under 49 | this agreement. 50 | 51 | 5.2. "Data Provider" means any person who is the source of Data 52 | provided under this agreement and in reliance on a Data Recipient's 53 | agreement to its terms. 54 | 55 | 5.3. "Data Recipient" means any person who receives Data directly 56 | or indirectly from a Data Provider and agrees to the terms of this 57 | agreement. 58 | 59 | 5.4. "Results" means any outcome obtained by computational analysis 60 | of Data, including for example machine learning models and models' 61 | insights. 62 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2023 Dirkjan Ochtman 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This workspace contains the crates `webpki-roots`, `webpki-root-certs` and `webpki-ccadb`. 2 | 3 | The `webpki-roots` crate contains Mozilla's trusted root certificates for use with 4 | the [webpki](https://github.com/rustls/webpki) or [rustls](https://github.com/rustls/rustls) crates. 5 | 6 | The `webpki-root-certs` is similar to `webpki-roots`, but for use with other projects 7 | that require the full self-signed X.509 certificate for each trusted root. This is 8 | unnecessary overhead for `webpki` and `rustls` and you should prefer using 9 | `webpki-roots` for these projects. 10 | 11 | The `webpki-ccadb` crate populates the root certificates for the webpki-roots crate 12 | using the data provided by the [Common CA Database (CCADB)](https://www.ccadb.org/). 13 | Inspired by [certifi.io](https://certifi.io/en/latest/). 14 | 15 | [![webpki-roots](https://github.com/rustls/webpki-roots/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/rustls/webpki-roots/actions/workflows/build.yml) 16 | [![Crate](https://img.shields.io/crates/v/webpki-roots.svg)](https://crates.io/crates/webpki-roots) 17 | 18 | # Warning 19 | 20 | These libraries are suitable for use in applications that can always be recompiled and instantly deployed. 21 | For applications that are deployed to end-users and cannot be recompiled, or which need certification 22 | before deployment, consider a library that uses the platform native certificate verifier such as 23 | [rustls-platform-verifier]. This has the additional benefit of supporting OS provided CA constraints 24 | and revocation data. 25 | 26 | [rustls-platform-verifier]: https://docs.rs/rustls-platform-verifier 27 | 28 | # License 29 | 30 | The underlying data is from Common CA Database (CCADB) and is used under the CDLA-2.0-Permissive 31 | license. See [CCADB Data Usage Terms](https://www.ccadb.org/rootstores/usage#ccadb-data-usage-terms). 32 | The data in `webpki-roots` and `webpki-root-certs` is a derived work of the CCADB data. 33 | 34 | The tooling in `webpki-ccadb` is licensed under both MIT and Apache licenses. 35 | -------------------------------------------------------------------------------- /webpki-ccadb/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "webpki-ccadb" 3 | version = "0.1.0" 4 | edition = { workspace = true } 5 | readme = "README.md" 6 | license = "MIT OR Apache-2.0" 7 | homepage = { workspace = true } 8 | repository = { workspace = true } 9 | description = "Common CA Database (CCADB) interface for use with webpki-roots" 10 | 11 | [dependencies] 12 | chrono = { version = "0.4.26", default-features = false, features = ["clock"] } 13 | csv = "1.2.2" 14 | hex = { workspace = true } 15 | num-bigint = "0.4.3" 16 | pki-types = { workspace = true } 17 | reqwest = { version = "0.12", features = ["rustls-tls-manual-roots"] } 18 | rustls-pemfile = "2.0.0" 19 | serde = { version = "1.0.183", features = ["derive"] } 20 | webpki = { workspace = true } 21 | x509-parser = { workspace = true } 22 | yasna = { workspace = true } 23 | -------------------------------------------------------------------------------- /webpki-ccadb/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /webpki-ccadb/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /webpki-ccadb/README.md: -------------------------------------------------------------------------------- 1 | # webpki-ccadb 2 | This is a crate to fetch Mozilla's root certificates for use with 3 | [webpki-roots](https://github.com/rustls/webpki-roots) crate. 4 | 5 | This crate is inspired by [certifi.io](https://certifi.io/en/latest/) and 6 | uses the data provided by the [Common CA Database (CCADB)](https://www.ccadb.org/). 7 | 8 | [![webpki-ccadb](https://github.com/rustls/webpki-roots/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/rustls/webpki-roots/actions/workflows/build.yml) 9 | [![Crate](https://img.shields.io/crates/v/webpki-ccadb.svg)](https://crates.io/crates/webpki-ccadb) 10 | -------------------------------------------------------------------------------- /webpki-ccadb/src/data/DigiCertGlobalRootCA.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh 3 | MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 4 | d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD 5 | QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT 6 | MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j 7 | b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG 8 | 9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB 9 | CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97 10 | nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt 11 | 43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P 12 | T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4 13 | gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO 14 | BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR 15 | TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw 16 | DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr 17 | hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg 18 | 06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF 19 | PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls 20 | YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk 21 | CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4= 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /webpki-ccadb/src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::cmp::Ordering; 2 | use std::collections::{BTreeMap, HashSet}; 3 | use std::ops::Add; 4 | 5 | use chrono::{Duration, NaiveDate, Utc}; 6 | use num_bigint::BigUint; 7 | use pki_types::CertificateDer; 8 | use serde::Deserialize; 9 | 10 | // Fetch root certificate data from the CCADB server. 11 | // 12 | // Returns an ordered BTreeMap of the root certificates, keyed by the SHA256 fingerprint of the 13 | // certificate. Panics if there are any duplicate fingerprints. 14 | pub async fn fetch_ccadb_roots() -> BTreeMap { 15 | // Configure a Reqwest client that only trusts the CA certificate expected to be the 16 | // root of trust for the CCADB server. 17 | // 18 | // If we see Unknown CA TLS validation failures from the Reqwest client in the future it 19 | // likely indicates that the upstream service has changed certificate authorities. In this 20 | // case the vendored root CA will need to be updated. You can find the current root in use with 21 | // Chrome by: 22 | // 1. Navigating to `https://ccadb-public.secure.force.com/mozilla/` 23 | // 2. Clicking the lock icon. 24 | // 3. Clicking "Connection is secure" 25 | // 4. Clicking "Certificate is valid" 26 | // 5. Clicking the "Details" tab. 27 | // 6. Selecting the topmost "System Trust" entry. 28 | // 7. Clicking "Export..." and saving the certificate to `webpki-roots/webpki-ccadb/src/data/`. 29 | // 8. Committing the updated .pem root CA, and updating the `include_bytes!` path. 30 | let root = include_bytes!("data/DigiCertGlobalRootCA.pem"); 31 | let root = reqwest::Certificate::from_pem(root).unwrap(); 32 | let client = reqwest::Client::builder() 33 | .user_agent(format!("webpki-ccadb/v{}", env!("CARGO_PKG_VERSION"))) 34 | .add_root_certificate(root) 35 | .build() 36 | .unwrap(); 37 | 38 | let ccadb_url = 39 | "https://ccadb.my.salesforce-sites.com/mozilla/IncludedCACertificateReportPEMCSV"; 40 | eprintln!("fetching {ccadb_url}..."); 41 | 42 | let req = client.get(ccadb_url).build().unwrap(); 43 | let csv_data = client 44 | .execute(req) 45 | .await 46 | .expect("failed to fetch CSV") 47 | .text() 48 | .await 49 | .unwrap(); 50 | 51 | // Parse the CSV metadata. 52 | let metadata = csv::ReaderBuilder::new() 53 | .has_headers(true) 54 | .from_reader(csv_data.as_bytes()) 55 | .into_deserialize::() 56 | .collect::, _>>() 57 | .unwrap(); 58 | 59 | // Filter for just roots we trust for TLS. 60 | let trusted_tls_roots = metadata 61 | .into_iter() 62 | .filter(CertificateMetadata::trusted_for_tls) 63 | .collect::>(); 64 | 65 | // Create an ordered BTreeMap of the roots, panicking for any duplicates. 66 | let mut tls_roots_map = BTreeMap::new(); 67 | for root in trusted_tls_roots { 68 | match tls_roots_map.get(&root.sha256_fingerprint) { 69 | Some(_) => { 70 | panic!("duplicate fingerprint {}", root.sha256_fingerprint); 71 | } 72 | None => { 73 | tls_roots_map.insert(root.sha256_fingerprint.clone(), root); 74 | } 75 | } 76 | } 77 | 78 | tls_roots_map 79 | } 80 | 81 | #[derive(Debug, Clone, Hash, Eq, PartialEq, Deserialize)] 82 | pub struct CertificateMetadata { 83 | #[serde(rename = "Common Name or Certificate Name")] 84 | pub common_name_or_certificate_name: String, 85 | 86 | #[serde(rename = "Certificate Serial Number")] 87 | pub certificate_serial_number: String, 88 | 89 | #[serde(rename = "SHA-256 Fingerprint")] 90 | pub sha256_fingerprint: String, 91 | 92 | #[serde(rename = "Trust Bits")] 93 | pub trust_bits: String, 94 | 95 | #[serde(rename = "Distrust for TLS After Date")] 96 | pub distrust_for_tls_after_date: String, 97 | 98 | #[serde(rename = "Mozilla Applied Constraints")] 99 | pub mozilla_applied_constraints: String, 100 | 101 | #[serde(rename = "PEM Info")] 102 | pub pem_info: String, 103 | } 104 | 105 | impl CertificateMetadata { 106 | /// Returns true if-and-only-if the issuer certificate should be considered trusted to issue TLS 107 | /// certificates. 108 | /// 109 | /// In practice this means it must have valid TrustBits that include TrustBits::Websites, 110 | /// and if the certificate has a distrust for TLS after date, that it's in the past or 111 | /// within a 398-day grace period, and that the fingerprint isn't in the EXCLUDED_FINGERPRINTS 112 | /// list. 113 | /// 114 | /// This grace period allows extant certificates issued before the distrust date to 115 | /// remain valid for their lifetime. At the time of writing the CA/B forum baseline 116 | /// reqs[0] peg this to 398 days (§ 6.3.2). 117 | /// 118 | /// [0]: 119 | fn trusted_for_tls(&self) -> bool { 120 | // If the fingerprint is in the excluded list, it's not trusted based on policy 121 | // we're imposing ourselves. 122 | if EXCLUDED_FINGERPRINTS.contains(&self.sha256_fingerprint.as_str()) { 123 | return false; 124 | } 125 | 126 | let has_tls_trust_bit = self.trust_bits().contains(&TrustBits::Websites); 127 | 128 | match (has_tls_trust_bit, self.tls_distrust_after()) { 129 | // No website trust bit - not trusted for tls. 130 | (false, _) => false, 131 | // Has website trust bit, no distrust after - trusted for tls. 132 | (true, None) => true, 133 | // Trust bit, populated distrust after - check if we're within the grace period. 134 | (true, Some(distrust_after)) => { 135 | Utc::now().naive_utc() < distrust_after.add(Duration::days(398)).into() 136 | } 137 | } 138 | } 139 | 140 | /// Return the Mozilla applied constraints for the certificate (if any). The constraints 141 | /// will be encoded in the DER form expected by the webpki crate's TrustAnchor representation. 142 | pub fn mozilla_applied_constraints(&self) -> Option> { 143 | if self.mozilla_applied_constraints.is_empty() { 144 | return None; 145 | } 146 | 147 | // NOTE: To date there's only one CA with a applied constraints value, and it has only one 148 | // permitted subtree constraint imposed. It's not clear how multiple constraints would be 149 | // expressed. This method makes a best guess but may need to be revisited in the future. 150 | // https://groups.google.com/a/ccadb.org/g/public/c/TlDivISPVT4/m/jbWGuM4YAgAJ 151 | let included_subtrees = self.mozilla_applied_constraints.split(','); 152 | 153 | // Important: the webpki representation of name constraints elides: 154 | // - the outer BITSTRING of the X.509 extension value. 155 | // - the outer NameConstraints SEQUENCE over the permitted/excluded subtrees. 156 | // 157 | // See https://www.rfc-editor.org/rfc/rfc5280#section-4.2.1.10 158 | let der = yasna::construct_der(|writer| { 159 | // permittedSubtrees [0] 160 | writer.write_tagged_implicit(yasna::Tag::context(0), |writer| { 161 | // GeneralSubtrees 162 | writer.write_sequence(|writer| { 163 | for included_subtree in included_subtrees { 164 | // base GeneralName 165 | writer.next().write_sequence(|writer| { 166 | writer 167 | .next() 168 | // DnsName 169 | .write_tagged_implicit(yasna::Tag::context(2), |writer| { 170 | writer 171 | .write_ia5_string(included_subtree.trim_start_matches('*')) 172 | }) 173 | }) 174 | // minimum [0] (absent, 0 default) 175 | // maximum [1] (must be omitted). 176 | } 177 | }) 178 | }) 179 | }); 180 | 181 | Some(der) 182 | } 183 | 184 | /// Return the NaiveDate after which this certificate should not be trusted for TLS (if any). 185 | /// Panics if there is a distrust for TLS after date value that can not be parsed. 186 | fn tls_distrust_after(&self) -> Option { 187 | match &self.distrust_for_tls_after_date { 188 | date if date.is_empty() => None, 189 | date => Some( 190 | NaiveDate::parse_from_str(date, "%Y.%m.%d") 191 | .unwrap_or_else(|_| panic!("invalid distrust for tls after date: {date:?}")), 192 | ), 193 | } 194 | } 195 | 196 | /// Returns the DER encoding of the certificate contained in the metadata PEM. Panics if 197 | /// there is an error, or no certificate in the PEM content. 198 | pub fn der(&self) -> CertificateDer<'static> { 199 | rustls_pemfile::certs(&mut self.pem().as_bytes()) 200 | .next() 201 | .unwrap() 202 | .expect("invalid PEM") 203 | } 204 | 205 | /// Returns the serial number for the certificate. Panics if the certificate serial number 206 | /// from the metadata can not be parsed as a base 16 unsigned big integer. 207 | pub fn serial(&self) -> BigUint { 208 | BigUint::parse_bytes(self.certificate_serial_number.as_bytes(), 16) 209 | .expect("invalid certificate serial number") 210 | } 211 | 212 | /// Returns the colon separated string with the metadata SHA256 fingerprint for the 213 | /// certificate. Panics if the sha256 fingerprint from the metadata can't be decoded. 214 | pub fn sha256_fp(&self) -> String { 215 | x509_parser::utils::format_serial( 216 | &hex::decode(&self.sha256_fingerprint).expect("invalid sha256 fingerprint"), 217 | ) 218 | } 219 | 220 | /// Returns the set of trust bits expressed for this certificate. Panics if the raw 221 | /// trust bits are invalid/unknown. 222 | fn trust_bits(&self) -> HashSet { 223 | let bits = self 224 | .trust_bits 225 | .split(';') 226 | .map(TrustBits::from) 227 | .collect::>(); 228 | if bits.contains(&TrustBits::AllTrustBitsTurnedOff) && bits.len() > 1 { 229 | panic!( 230 | "unexpected trust bits: AllTrustBitsTurnedOff \ 231 | is mutually exclusive (found {bits:?})" 232 | ); 233 | } 234 | bits 235 | } 236 | 237 | /// Returns the PEM metadata for the certificate with the leading/trailing single quotes 238 | /// removed. 239 | pub fn pem(&self) -> &str { 240 | self.pem_info.as_str().trim_matches('\'') 241 | } 242 | } 243 | 244 | impl PartialOrd for CertificateMetadata { 245 | fn partial_cmp(&self, other: &Self) -> Option { 246 | Some(self.sha256_fingerprint.cmp(&other.sha256_fingerprint)) 247 | } 248 | } 249 | 250 | impl Ord for CertificateMetadata { 251 | fn cmp(&self, other: &Self) -> Ordering { 252 | self.sha256_fingerprint.cmp(&other.sha256_fingerprint) 253 | } 254 | } 255 | 256 | #[derive(Debug, Hash, Eq, PartialEq, Clone, Copy)] 257 | #[non_exhaustive] 258 | /// TrustBits describe the possible Mozilla root certificate trust bits. 259 | pub enum TrustBits { 260 | /// certificate is trusted for Websites (e.g. TLS). 261 | Websites, 262 | /// certificate is trusted for Email (e.g. S/MIME). 263 | Email, 264 | /// certificate is trusted for code signing 265 | Code, 266 | /// certificate is not trusted for anything 267 | AllTrustBitsTurnedOff, 268 | } 269 | 270 | impl From<&str> for TrustBits { 271 | fn from(value: &str) -> Self { 272 | match value { 273 | "Websites" => TrustBits::Websites, 274 | "Email" => TrustBits::Email, 275 | "Code" => TrustBits::Code, 276 | "All Trust Bits Turned Off" => TrustBits::AllTrustBitsTurnedOff, 277 | val => panic!("unknown trust bit: {val:?}"), 278 | } 279 | } 280 | } 281 | 282 | static EXCLUDED_FINGERPRINTS: &[&str] = &[ 283 | // CN=GLOBALTRUST 2020 O=e-commerce monitoring GmbH 284 | // This CA is being distrusted by the Mozilla root program for TLS certificates issued after 2024.06.30. 285 | // but since it has <100 extant trusted certificates we exclude it from the generated root bundle 286 | // immediately. 287 | "9A296A5182D1D451A2E37F439B74DAAFA267523329F90F9A0D2007C334E23C9A", 288 | ]; 289 | 290 | #[cfg(test)] 291 | mod tests { 292 | use super::*; 293 | 294 | #[test] 295 | fn test_trusted_for_tls() { 296 | let mut metadata = CertificateMetadata { 297 | common_name_or_certificate_name: "Test".to_string(), 298 | certificate_serial_number: "1".to_string(), 299 | sha256_fingerprint: "1".to_string(), 300 | trust_bits: "Websites".to_string(), 301 | distrust_for_tls_after_date: "".to_string(), 302 | mozilla_applied_constraints: "".to_string(), 303 | pem_info: "".to_string(), 304 | }; 305 | // Trust bit set for Websites, no distrust date. 306 | assert!(metadata.trusted_for_tls()); 307 | 308 | // Trust bit _not_ set for Websites. 309 | metadata.trust_bits = "Email".to_string(); 310 | assert!(!metadata.trusted_for_tls()); 311 | 312 | // Trust bit set for Websites, no distrut date. 313 | metadata.trust_bits = "Websites;Email".to_string(); 314 | assert!(metadata.trusted_for_tls()); 315 | 316 | // Trust bit set for Websites, distrust date far in the past. 317 | metadata.trust_bits = "Websites".to_string(); 318 | metadata.distrust_for_tls_after_date = "2000.01.01".to_string(); 319 | assert!(!metadata.trusted_for_tls()); 320 | 321 | // Trust bit set for Websites, distrust date in the future. 322 | let now = Utc::now().naive_utc(); 323 | let future_distrust = now.add(Duration::days(365 * 5)); 324 | metadata.distrust_for_tls_after_date = future_distrust.format("%Y.%m.%d").to_string(); 325 | assert!(metadata.trusted_for_tls()); 326 | 327 | // Trust bit set for Websites, distrust date has passed, but within grace period. 328 | let past_distrust = now.add(Duration::days(-397)); 329 | metadata.distrust_for_tls_after_date = past_distrust.format("%Y.%m.%d").to_string(); 330 | assert!(metadata.trusted_for_tls()); 331 | 332 | // Trust bit set for Websites, distrust date has passed, outside grace period. 333 | let past_distrust = now.add(Duration::days(-398)); 334 | metadata.distrust_for_tls_after_date = past_distrust.format("%Y.%m.%d").to_string(); 335 | assert!(!metadata.trusted_for_tls()); 336 | 337 | // Certificate FP is excluded. 338 | metadata.sha256_fingerprint = EXCLUDED_FINGERPRINTS[0].to_string(); 339 | assert!(!metadata.trusted_for_tls()); 340 | } 341 | } 342 | -------------------------------------------------------------------------------- /webpki-root-certs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "webpki-root-certs" 3 | version = "1.0.1" 4 | edition.workspace = true 5 | readme = "README.md" 6 | license = "CDLA-Permissive-2.0" 7 | homepage.workspace = true 8 | repository.workspace = true 9 | description = "Mozilla trusted certificate authorities in self-signed X.509 format for use with crates other than webpki" 10 | 11 | [dependencies] 12 | pki-types = { workspace = true } 13 | 14 | [dev-dependencies] 15 | hex = { workspace = true } 16 | percent-encoding = "2.3" 17 | ring = "0.17.0" 18 | tokio = { version = "1", features = ["macros", "rt-multi-thread"] } 19 | webpki = { workspace = true } 20 | webpki-ccadb = { path = "../webpki-ccadb" } 21 | x509-parser = { workspace = true } 22 | -------------------------------------------------------------------------------- /webpki-root-certs/LICENSE: -------------------------------------------------------------------------------- 1 | ../LICENSE-CCADB -------------------------------------------------------------------------------- /webpki-root-certs/README.md: -------------------------------------------------------------------------------- 1 | # webpki-root-certs 2 | 3 | This is a crate containing Mozilla's trusted root certificates in self-signed 4 | X.509 certificate format. 5 | 6 | **If you are using `webpki` or `rustls` you should prefer `webpki-roots` - it is 7 | more space efficient and easier to use.** 8 | 9 | This crate is inspired by [certifi.io](https://certifi.io/en/latest/) and uses the data provided by the 10 | [Common CA Database (CCADB)](https://www.ccadb.org/). 11 | 12 | # About 13 | 14 | The `webpki` and `rustls` ecosystem represent trust anchors with the 15 | `webpki::TrustAnchor` type, containing only the data used as inputs for the [RFC 16 | 5280] certificate path validation algorithm. In some instances (e.g. when 17 | interacting with native platform certificate verifiers) it may be required to 18 | provide trust anchors as full X.509 self-signed certificates. 19 | 20 | Compared to `webpki-roots` this crate contains the full self-signed certificate 21 | DER data for each trust anchor is included in `webpki_roots`. 22 | 23 | [RFC 5280]: https://www.rfc-editor.org/rfc/rfc5280#section-6 24 | 25 | # License 26 | 27 | The underlying data is used via the [CCADB Data Usage Terms](https://www.ccadb.org/rootstores/usage#ccadb-data-usage-terms) (see [`LICENSE`](LICENSE)). 28 | The data in this crate is a derived work of the CCADB data. 29 | 30 | # Regenerating sources 31 | 32 | Sources are generated in an integration test, in `tests/codegen.rs`. The test 33 | will fail if the sources are out of date relative to upstream, and update 34 | `src/lib.rs` if so. The code is generated in deterministic order so changes 35 | to the source should only result from upstream changes. 36 | -------------------------------------------------------------------------------- /webpki-root-certs/tests/codegen.rs: -------------------------------------------------------------------------------- 1 | use std::fmt::Write; 2 | use std::fs; 3 | 4 | use ring::digest; 5 | 6 | use webpki_ccadb::fetch_ccadb_roots; 7 | 8 | #[tokio::test] 9 | async fn new_generated_code_is_fresh() { 10 | let tls_roots_map = fetch_ccadb_roots().await; 11 | let mut code = String::with_capacity(256 * 1_024); 12 | code.push_str(HEADER); 13 | code.push_str("pub const TLS_SERVER_ROOT_CERTS: &[CertificateDer<'static>] = &[\n"); 14 | 15 | let mut encoded_cert_der = String::new(); 16 | for root in tls_roots_map.values() { 17 | // Verify the DER FP matches the metadata FP. 18 | let der = root.der(); 19 | let calculated_fp = digest::digest(&digest::SHA256, &der); 20 | let metadata_fp = hex::decode(&root.sha256_fingerprint).expect("malformed fingerprint"); 21 | assert_eq!(calculated_fp.as_ref(), metadata_fp.as_slice()); 22 | 23 | write!(&mut encoded_cert_der, "b\"").unwrap(); 24 | for &b in root.der().as_ref() { 25 | encoded_cert_der.push_str(&format!("\\x{b:02X}")); 26 | } 27 | encoded_cert_der.push('"'); 28 | 29 | code.push_str(&format!( 30 | " // {:?}\n", 31 | root.common_name_or_certificate_name 32 | )); 33 | code.push_str(&format!( 34 | " CertificateDer::from_slice({encoded_cert_der}),\n" 35 | )); 36 | encoded_cert_der.clear(); 37 | } 38 | code.push_str("];\n"); 39 | 40 | // Check that the generated code matches the checked-in code 41 | let old = fs::read_to_string("src/lib.rs").unwrap(); 42 | if old != code { 43 | fs::write("src/lib.rs", code).unwrap(); 44 | panic!("generated code changed"); 45 | } 46 | } 47 | 48 | const HEADER: &str = r#"//! A compiled-in copy of the full X.509 root certificates trusted by Mozilla. 49 | //! 50 | //! You should generally prefer to use [`webpki-roots`] when using [`rustls`] or [`webpki`] as it is 51 | //! more space efficient and convenient for that use. 52 | //! 53 | //! This library is suitable for use in applications that can always be recompiled and instantly deployed. 54 | //! For applications that are deployed to end-users and cannot be recompiled, or which need certification 55 | //! before deployment, consider a library that uses the platform native certificate verifier such as 56 | //! [`rustls-platform-verifier`]. This has the additional benefit of supporting OS provided CA constraints 57 | //! and revocation data. 58 | //! 59 | //! [`webpki-roots`]: https://docs.rs/webpki-roots 60 | //! [`webpki`]: https://docs.rs/rustls-webpki 61 | //! [`rustls`]: https://docs.rs/rustls 62 | //! [`rustls-platform-verifier`]: https://docs.rs/rustls-platform-verifier 63 | // 64 | // This library is automatically generated from the Mozilla 65 | // IncludedCACertificateReportPEMCSV report via ccadb.org. Don't edit it. 66 | // 67 | // The generation is done deterministically so you can verify it 68 | // yourself by inspecting and re-running the generation process. 69 | 70 | #![no_std] 71 | #![forbid(unsafe_code, unstable_features)] 72 | #![deny( 73 | elided_lifetimes_in_paths, 74 | trivial_casts, 75 | trivial_numeric_casts, 76 | unused_import_braces, 77 | unused_extern_crates, 78 | unused_qualifications 79 | )] 80 | 81 | use pki_types::CertificateDer; 82 | 83 | "#; 84 | -------------------------------------------------------------------------------- /webpki-root-certs/tests/smoketest.rs: -------------------------------------------------------------------------------- 1 | #[test] 2 | fn test_trust_anchor_der() { 3 | // Simple smoke-test that: 4 | // a) parses each TLS server root DER w/ x509-parser. 5 | // b) verifies the parsed cert is a CA certificate. 6 | // c) verifies the DER can be converted to a webpki trust anchor. 7 | for root in webpki_root_certs::TLS_SERVER_ROOT_CERTS { 8 | let (rest, cert) = x509_parser::parse_x509_certificate(root.as_ref()).unwrap(); 9 | assert!(rest.is_empty()); 10 | assert!(cert.is_ca()); 11 | webpki::anchor_from_trusted_cert(root).unwrap(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /webpki-roots/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "webpki-roots" 3 | version = "1.0.1" 4 | edition = { workspace = true } 5 | readme = "README.md" 6 | license = "CDLA-Permissive-2.0" 7 | homepage = { workspace = true } 8 | repository = { workspace = true } 9 | description = "Mozilla's CA root certificates for use with webpki" 10 | 11 | [dependencies] 12 | pki-types = { workspace = true } 13 | 14 | [dev-dependencies] 15 | hex = { workspace = true } 16 | percent-encoding = "2.3" 17 | rcgen = "0.13" 18 | ring = "0.17.0" 19 | rustls = "0.23" 20 | tokio = { version = "1", features = ["macros", "rt-multi-thread"] } 21 | webpki = { workspace = true } 22 | webpki-ccadb = { path = "../webpki-ccadb" } 23 | x509-parser = { workspace = true } 24 | yasna = { workspace = true } 25 | -------------------------------------------------------------------------------- /webpki-roots/LICENSE: -------------------------------------------------------------------------------- 1 | ../LICENSE-CCADB -------------------------------------------------------------------------------- /webpki-roots/README.md: -------------------------------------------------------------------------------- 1 | # webpki-roots 2 | This is a crate containing Mozilla's root certificates for use with 3 | the [webpki](https://github.com/rustls/webpki) or 4 | [rustls](https://github.com/rustls/rustls) crates. 5 | 6 | This crate is inspired by [certifi.io](https://certifi.io/en/latest/) and 7 | uses the data provided by the [Common CA Database (CCADB)](https://www.ccadb.org/). 8 | 9 | [![webpki-roots](https://github.com/rustls/webpki-roots/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/rustls/webpki-roots/actions/workflows/build.yml) 10 | [![Crate](https://img.shields.io/crates/v/webpki-roots.svg)](https://crates.io/crates/webpki-roots) 11 | 12 | # License 13 | The underlying data is used via the [CCADB Data Usage Terms](https://www.ccadb.org/rootstores/usage#ccadb-data-usage-terms) (see [`LICENSE`](LICENSE)). 14 | The data in this crate is a derived work of the CCADB data. 15 | 16 | # Regenerating sources 17 | Sources are generated in an integration test, in `tests/codegen.rs`. The test 18 | will fail if the sources are out of date relative to upstream, and update 19 | `src/lib.rs` if so. The code is generated in deterministic order so changes 20 | to the source should only result from upstream changes. 21 | -------------------------------------------------------------------------------- /webpki-roots/tests/codegen.rs: -------------------------------------------------------------------------------- 1 | use std::ascii::escape_default; 2 | use std::fmt::Write; 3 | use std::fs; 4 | 5 | use pki_types::CertificateDer; 6 | use ring::digest; 7 | use webpki::anchor_from_trusted_cert; 8 | use webpki_ccadb::fetch_ccadb_roots; 9 | use x509_parser::prelude::AttributeTypeAndValue; 10 | use x509_parser::x509::X509Name; 11 | 12 | #[tokio::test] 13 | async fn new_generated_code_is_fresh() { 14 | let tls_roots_map = fetch_ccadb_roots().await; 15 | let mut code = String::with_capacity(256 * 1_024); 16 | code.push_str(HEADER); 17 | code.push_str("pub const TLS_SERVER_ROOTS: &[TrustAnchor<'static>] = &[\n"); 18 | let (mut subject, mut spki, mut name_constraints) = 19 | (String::new(), String::new(), String::new()); 20 | 21 | for root in tls_roots_map.values() { 22 | // Verify the DER FP matches the metadata FP. 23 | let der = root.der(); 24 | let calculated_fp = digest::digest(&digest::SHA256, &der); 25 | let metadata_fp = hex::decode(&root.sha256_fingerprint).expect("malformed fingerprint"); 26 | assert_eq!(calculated_fp.as_ref(), metadata_fp.as_slice()); 27 | 28 | let ta_der = CertificateDer::from(der.as_ref()); 29 | let ta = anchor_from_trusted_cert(&ta_der).expect("malformed trust anchor der"); 30 | subject.clear(); 31 | for &b in ta.subject.as_ref() { 32 | write!(&mut subject, "{}", escape_default(b)).unwrap(); 33 | } 34 | 35 | spki.clear(); 36 | for &b in ta.subject_public_key_info.as_ref() { 37 | write!(&mut spki, "{}", escape_default(b)).unwrap(); 38 | } 39 | 40 | name_constraints.clear(); 41 | if let Some(nc) = &root.mozilla_applied_constraints() { 42 | for &b in nc.iter() { 43 | write!(&mut name_constraints, "{}", escape_default(b)).unwrap(); 44 | } 45 | } 46 | 47 | let (_, parsed_cert) = 48 | x509_parser::parse_x509_certificate(&der).expect("malformed x509 der"); 49 | let issuer = name_to_string(parsed_cert.issuer()); 50 | let subject_str = name_to_string(parsed_cert.subject()); 51 | let label = root.common_name_or_certificate_name.clone(); 52 | let serial = root.serial().to_string(); 53 | let sha256_fp = root.sha256_fp(); 54 | 55 | // Write comment 56 | code.push_str(" /*\n"); 57 | code.push_str(&format!(" * Issuer: {issuer}\n")); 58 | code.push_str(&format!(" * Subject: {subject_str}\n")); 59 | code.push_str(&format!(" * Label: {label:?}\n")); 60 | code.push_str(&format!(" * Serial: {serial}\n")); 61 | code.push_str(&format!(" * SHA256 Fingerprint: {sha256_fp}\n")); 62 | for ln in root.pem().lines() { 63 | code.push_str(" * "); 64 | code.push_str(ln.trim()); 65 | code.push('\n'); 66 | } 67 | code.push_str(" */\n"); 68 | 69 | // Write the code 70 | code.push_str(" TrustAnchor {\n"); 71 | code.write_fmt(format_args!( 72 | " subject: Der::from_slice(b\"{subject}\"),\n" 73 | )) 74 | .unwrap(); 75 | code.write_fmt(format_args!( 76 | " subject_public_key_info: Der::from_slice(b\"{spki}\"),\n" 77 | )) 78 | .unwrap(); 79 | match name_constraints.is_empty() { 80 | false => code 81 | .write_fmt(format_args!( 82 | " name_constraints: Some(Der::from_slice(b\"{name_constraints}\"))\n" 83 | )) 84 | .unwrap(), 85 | true => code.push_str(" name_constraints: None\n"), 86 | } 87 | code.push_str(" },\n\n"); 88 | } 89 | code.push_str("];\n"); 90 | 91 | // Check that the generated code matches the checked-in code 92 | let old = fs::read_to_string("src/lib.rs").unwrap(); 93 | if old != code { 94 | fs::write("src/lib.rs", code).unwrap(); 95 | panic!("generated code changed"); 96 | } 97 | } 98 | 99 | /// The built-in x509_parser::X509Name Display impl uses a different sort order than 100 | /// the one historically used by mkcert.org^[0]. We re-create that sort order here to 101 | /// avoid unnecessary churn in the generated code. 102 | /// 103 | /// [0]: 104 | fn name_to_string(name: &X509Name) -> String { 105 | let mut ret = String::with_capacity(256); 106 | 107 | if let Some(cn) = name 108 | .iter_common_name() 109 | .next() 110 | .and_then(|cn| cn.as_str().ok()) 111 | { 112 | write!(ret, "CN={cn}").unwrap(); 113 | } 114 | 115 | let mut append_attrs = |attrs: Vec<&AttributeTypeAndValue>, label| { 116 | let str_parts = attrs 117 | .iter() 118 | .filter_map(|attr| attr.as_str().ok()) 119 | .collect::>() 120 | .join("/"); 121 | if !str_parts.is_empty() { 122 | if !ret.is_empty() { 123 | ret.push(' '); 124 | } 125 | write!(ret, "{label}={str_parts}").unwrap(); 126 | } 127 | }; 128 | 129 | append_attrs(name.iter_organization().collect(), "O"); 130 | append_attrs(name.iter_organizational_unit().collect(), "OU"); 131 | 132 | ret 133 | } 134 | 135 | const HEADER: &str = r#"//! A compiled-in copy of the root certificates trusted by Mozilla. 136 | //! 137 | //! To use this library with rustls 0.22: 138 | //! 139 | //! ```rust 140 | //! let root_store = rustls::RootCertStore { 141 | //! roots: webpki_roots::TLS_SERVER_ROOTS.to_vec(), 142 | //! }; 143 | //! ``` 144 | //! 145 | //! This library is suitable for use in applications that can always be recompiled and instantly deployed. 146 | //! For applications that are deployed to end-users and cannot be recompiled, or which need certification 147 | //! before deployment, consider a library that uses the platform native certificate verifier such as 148 | //! [rustls-platform-verifier]. This has the additional benefit of supporting OS provided CA constraints 149 | //! and revocation data. 150 | //! 151 | //! [rustls-platform-verifier]: https://docs.rs/rustls-platform-verifier 152 | // 153 | // This library is automatically generated from the Mozilla 154 | // IncludedCACertificateReportPEMCSV report via ccadb.org. Don't edit it. 155 | // 156 | // The generation is done deterministically so you can verify it 157 | // yourself by inspecting and re-running the generation process. 158 | 159 | #![no_std] 160 | #![forbid(unsafe_code, unstable_features)] 161 | #![deny( 162 | elided_lifetimes_in_paths, 163 | trivial_casts, 164 | trivial_numeric_casts, 165 | unused_import_braces, 166 | unused_extern_crates, 167 | unused_qualifications 168 | )] 169 | 170 | use pki_types::{Der, TrustAnchor}; 171 | 172 | "#; 173 | -------------------------------------------------------------------------------- /webpki-roots/tests/data/tubitak/inter.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rustls/webpki-roots/dd51e4d9369cab16a8dc59e39ae9e088a5c19731/webpki-roots/tests/data/tubitak/inter.der -------------------------------------------------------------------------------- /webpki-roots/tests/data/tubitak/root.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rustls/webpki-roots/dd51e4d9369cab16a8dc59e39ae9e088a5c19731/webpki-roots/tests/data/tubitak/root.der -------------------------------------------------------------------------------- /webpki-roots/tests/data/tubitak/subj.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rustls/webpki-roots/dd51e4d9369cab16a8dc59e39ae9e088a5c19731/webpki-roots/tests/data/tubitak/subj.der -------------------------------------------------------------------------------- /webpki-roots/tests/verify.rs: -------------------------------------------------------------------------------- 1 | use core::time::Duration; 2 | use std::convert::TryFrom; 3 | 4 | use pki_types::{CertificateDer, ServerName, SignatureVerificationAlgorithm, UnixTime}; 5 | use rcgen::{ 6 | BasicConstraints, Certificate, CertificateParams, DnType, IsCa, KeyPair, KeyUsagePurpose, 7 | }; 8 | use webpki::{anchor_from_trusted_cert, EndEntityCert, Error, KeyUsage}; 9 | use x509_parser::extensions::{GeneralName, NameConstraints as X509ParserNameConstraints}; 10 | use x509_parser::prelude::FromDer; 11 | 12 | use webpki_roots::TLS_SERVER_ROOTS; 13 | 14 | #[test] 15 | fn name_constraints() { 16 | for name_constraints in TLS_SERVER_ROOTS 17 | .iter() 18 | .filter_map(|ta| ta.name_constraints.as_ref()) 19 | { 20 | let time = UnixTime::since_unix_epoch(Duration::from_secs(0x40000000)); // Time matching rcgen default. 21 | let test_case = ConstraintTest::new(name_constraints.as_ref()); 22 | let trust_anchors = &[anchor_from_trusted_cert(&test_case.trust_anchor).unwrap()]; 23 | 24 | // Each permitted EE should verify without error. 25 | for permitted_ee in test_case.permitted_certs { 26 | webpki::EndEntityCert::try_from(&permitted_ee) 27 | .unwrap() 28 | .verify_for_usage( 29 | ALL_ALGORITHMS, 30 | trust_anchors, 31 | &[], 32 | time, 33 | KeyUsage::server_auth(), 34 | None, 35 | None, 36 | ) 37 | .unwrap(); 38 | } 39 | 40 | // Each forbidden EE should fail to verify with the expected name constraint error. 41 | for forbidden_ee in test_case.forbidden_certs { 42 | let ee = EndEntityCert::try_from(&forbidden_ee).unwrap(); 43 | let result = ee.verify_for_usage( 44 | ALL_ALGORITHMS, 45 | trust_anchors, 46 | &[], 47 | time, 48 | KeyUsage::server_auth(), 49 | None, 50 | None, 51 | ); 52 | assert!(matches!(result, Err(Error::NameConstraintViolation))); 53 | } 54 | } 55 | } 56 | 57 | struct ConstraintTest { 58 | trust_anchor: CertificateDer<'static>, 59 | permitted_certs: Vec>, 60 | forbidden_certs: Vec>, 61 | } 62 | 63 | impl ConstraintTest { 64 | fn new(webpki_name_constraints: &[u8]) -> Self { 65 | // Create a trust anchor CA certificate that has the name constraints we want to test. 66 | let mut trust_anchor = CertificateParams::new([]).unwrap(); 67 | trust_anchor 68 | .distinguished_name 69 | .push(DnType::CommonName, "Name Constraint Test CA"); 70 | trust_anchor.is_ca = IsCa::Ca(BasicConstraints::Unconstrained); 71 | trust_anchor.key_usages = vec![ 72 | KeyUsagePurpose::KeyCertSign, 73 | KeyUsagePurpose::DigitalSignature, 74 | ]; 75 | let name_constraints = rcgen_name_constraints(webpki_name_constraints); 76 | trust_anchor.name_constraints = Some(name_constraints.clone()); 77 | let key_pair = KeyPair::generate().unwrap(); 78 | let trust_anchor = trust_anchor.self_signed(&key_pair).unwrap(); 79 | 80 | let certs_for_subtrees = |suffix| { 81 | name_constraints 82 | .permitted_subtrees 83 | .iter() 84 | .filter_map(|subtree| match subtree { 85 | rcgen::GeneralSubtree::DnsName(dns_name) => Some(rcgen_ee_for_name( 86 | format!("valid{dns_name}{suffix}"), 87 | &trust_anchor, 88 | &key_pair, 89 | )), 90 | _ => None, 91 | }) 92 | .collect() 93 | }; 94 | 95 | Self { 96 | // For each permitted subtree in the name constraints, issue an end entity certificate 97 | // that contains a DNS name matching the permitted subtree base. 98 | permitted_certs: certs_for_subtrees(""), 99 | // For each permitted subtree in the name constraints, issue an end entity certificate 100 | // that contains a DNS name that will **not** match the permitted subtree base. 101 | forbidden_certs: certs_for_subtrees(".invalid"), 102 | trust_anchor: trust_anchor.into(), 103 | } 104 | } 105 | } 106 | 107 | fn rcgen_ee_for_name( 108 | name: String, 109 | issuer: &Certificate, 110 | issuer_key: &KeyPair, 111 | ) -> CertificateDer<'static> { 112 | let mut ee = CertificateParams::new(vec![name.clone()]).unwrap(); 113 | ee.distinguished_name.push(DnType::CommonName, name); 114 | ee.is_ca = IsCa::NoCa; 115 | let key_pair = KeyPair::generate().unwrap(); 116 | ee.signed_by(&key_pair, issuer, issuer_key).unwrap().into() 117 | } 118 | 119 | /// Convert the webpki trust anchor DER encoding of name constraints to rcgen NameConstraints. 120 | fn rcgen_name_constraints(der: &[u8]) -> rcgen::NameConstraints { 121 | // x509 parser expects the outer SEQUENCE that the webpki trust anchor representation elides 122 | // so wrap the DER up. 123 | let wrapped_der = yasna::construct_der(|writer| { 124 | writer.write_sequence(|writer| { 125 | writer.next().write_der(der); 126 | }) 127 | }); 128 | 129 | // Constraints should parse with no trailing data. 130 | let (trailing, constraints) = X509ParserNameConstraints::from_der(&wrapped_der).unwrap(); 131 | assert!( 132 | trailing.is_empty(), 133 | "unexpected trailing DER in name constraint" 134 | ); 135 | 136 | // There should be at least one permitted subtree. 137 | assert!( 138 | constraints.permitted_subtrees.is_some(), 139 | "empty permitted subtrees in constraints" 140 | ); 141 | 142 | // We don't expect any excluded subtrees as this time. 143 | assert!(constraints.excluded_subtrees.is_none()); 144 | 145 | // Collect all of the DNS names from the x509-parser representation, mapping to the rcgen 146 | // representation usable in cert parameters. We don't expect to find any other types of general 147 | // name and x509-parser doesn't parse the subtree minimum and maximum (which we would assert to 148 | // be missing for proper encoding anyway). 149 | let permitted_subtrees = match constraints.permitted_subtrees { 150 | None => Vec::default(), 151 | Some(subtrees) => subtrees 152 | .iter() 153 | .map(|subtree| match &subtree.base { 154 | GeneralName::DNSName(base) => rcgen::GeneralSubtree::DnsName(base.to_string()), 155 | name => panic!("unexpected subtree base general name type: {name}"), 156 | }) 157 | .collect(), 158 | }; 159 | 160 | rcgen::NameConstraints { 161 | permitted_subtrees, 162 | excluded_subtrees: Vec::default(), 163 | } 164 | } 165 | 166 | #[test] 167 | fn tubitak_name_constraint_works() { 168 | let root = CertificateDer::from(&include_bytes!("data/tubitak/root.der")[..]); 169 | let inter = CertificateDer::from(&include_bytes!("data/tubitak/inter.der")[..]); 170 | let subj = CertificateDer::from(&include_bytes!("data/tubitak/subj.der")[..]); 171 | 172 | let roots = [anchor_from_trusted_cert(&root).unwrap().to_owned()]; 173 | let now = UnixTime::since_unix_epoch(Duration::from_secs(1493668479)); 174 | let cert = EndEntityCert::try_from(&subj).unwrap(); 175 | cert.verify_for_usage( 176 | ALL_ALGORITHMS, 177 | &roots, 178 | &[inter, root], 179 | now, 180 | KeyUsage::server_auth(), 181 | None, 182 | None, 183 | ) 184 | .unwrap(); 185 | 186 | let subject = ServerName::try_from("testssl.kamusm.gov.tr").unwrap(); 187 | cert.verify_is_valid_for_subject_name(&subject).unwrap(); 188 | } 189 | 190 | static ALL_ALGORITHMS: &[&dyn SignatureVerificationAlgorithm] = &[ 191 | webpki::ring::ECDSA_P256_SHA256, 192 | webpki::ring::ECDSA_P256_SHA384, 193 | webpki::ring::ECDSA_P384_SHA256, 194 | webpki::ring::ECDSA_P384_SHA384, 195 | webpki::ring::RSA_PKCS1_2048_8192_SHA256, 196 | webpki::ring::RSA_PKCS1_2048_8192_SHA384, 197 | webpki::ring::RSA_PKCS1_2048_8192_SHA512, 198 | webpki::ring::RSA_PKCS1_3072_8192_SHA384, 199 | webpki::ring::RSA_PSS_2048_8192_SHA256_LEGACY_KEY, 200 | webpki::ring::RSA_PSS_2048_8192_SHA384_LEGACY_KEY, 201 | webpki::ring::RSA_PSS_2048_8192_SHA512_LEGACY_KEY, 202 | ]; 203 | --------------------------------------------------------------------------------