From 54f8bd4764ba45c92d7cdd5604d293cb4b5f12d4 Mon Sep 17 00:00:00 2001 From: Nathaniel McCallum Date: Mon, 21 Feb 2022 09:50:23 -0500 Subject: [PATCH 1/2] Merge pkcs10 crate into x509 Signed-off-by: Nathaniel McCallum --- .github/workflows/pkcs10.yml | 70 ------ Cargo.lock | 11 - Cargo.toml | 1 - pkcs10/CHANGELOG.md | 5 - pkcs10/Cargo.toml | 31 --- pkcs10/LICENSE-APACHE | 201 ------------------ pkcs10/LICENSE-MIT | 25 --- pkcs10/README.md | 81 ------- pkcs10/src/document.rs | 88 -------- pkcs10/src/info.rs | 42 ---- pkcs10/src/lib.rs | 55 ----- pkcs10/src/version.rs | 14 -- x509/Cargo.toml | 2 +- x509/src/lib.rs | 1 + x509/src/request.rs | 85 ++++++++ {pkcs10 => x509}/tests/certreq.rs | 35 +-- .../tests/examples/rsa2048-crt.der | Bin .../tests/examples/rsa2048-crt.pem | 0 .../tests/examples/rsa2048-csr.der | Bin .../tests/examples/rsa2048-csr.pem | 0 .../tests/examples/rsa2048-prv.der | Bin .../tests/examples/rsa2048-prv.pem | 0 22 files changed, 88 insertions(+), 659 deletions(-) delete mode 100644 .github/workflows/pkcs10.yml delete mode 100644 pkcs10/CHANGELOG.md delete mode 100644 pkcs10/Cargo.toml delete mode 100644 pkcs10/LICENSE-APACHE delete mode 100644 pkcs10/LICENSE-MIT delete mode 100644 pkcs10/README.md delete mode 100644 pkcs10/src/document.rs delete mode 100644 pkcs10/src/info.rs delete mode 100644 pkcs10/src/lib.rs delete mode 100644 pkcs10/src/version.rs create mode 100644 x509/src/request.rs rename {pkcs10 => x509}/tests/certreq.rs (81%) rename {pkcs10 => x509}/tests/examples/rsa2048-crt.der (100%) rename {pkcs10 => x509}/tests/examples/rsa2048-crt.pem (100%) rename {pkcs10 => x509}/tests/examples/rsa2048-csr.der (100%) rename {pkcs10 => x509}/tests/examples/rsa2048-csr.pem (100%) rename {pkcs10 => x509}/tests/examples/rsa2048-prv.der (100%) rename {pkcs10 => x509}/tests/examples/rsa2048-prv.pem (100%) diff --git a/.github/workflows/pkcs10.yml b/.github/workflows/pkcs10.yml deleted file mode 100644 index 8d66a50c4..000000000 --- a/.github/workflows/pkcs10.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: pkcs10 - -on: - pull_request: - paths: - - "base64ct/**" - - "const-oid/**" - - "der/**" - - "pem-rfc7468/**" - - "pkcs10/**" - - "spki/**" - - "x501/**" - - "x509/**" - - "Cargo.*" - push: - branches: master - -defaults: - run: - working-directory: pkcs10 - -env: - CARGO_INCREMENTAL: 0 - RUSTFLAGS: "-Dwarnings" - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - 1.57.0 # MSRV - - stable - target: - - thumbv7em-none-eabi - - wasm32-unknown-unknown - steps: - - uses: actions/checkout@v2 - - uses: RustCrypto/actions/cargo-cache@master - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.rust }} - target: ${{ matrix.target }} - override: true - - run: cargo build --target ${{ matrix.target }} --no-default-features - - run: cargo build --target ${{ matrix.target }} --no-default-features --features pem - - minimal-versions: - uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master - with: - working-directory: ${{ github.workflow }} - - test: - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - 1.57.0 # MSRV - - stable - steps: - - uses: actions/checkout@v2 - - uses: RustCrypto/actions/cargo-cache@master - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.rust }} - override: true - - uses: RustCrypto/actions/cargo-hack-install@master - - run: cargo hack test --feature-powerset diff --git a/Cargo.lock b/Cargo.lock index d41e75948..e5bfdbaec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -550,17 +550,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "pkcs10" -version = "0.0.0" -dependencies = [ - "der", - "hex-literal", - "spki", - "x501", - "x509", -] - [[package]] name = "pkcs5" version = "0.5.0-pre" diff --git a/Cargo.toml b/Cargo.toml index d39358e34..e6853394b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ members = [ "pkcs5", "pkcs7", "pkcs8", - "pkcs10", "sec1", "spki", "ssh-key", diff --git a/pkcs10/CHANGELOG.md b/pkcs10/CHANGELOG.md deleted file mode 100644 index d6637e049..000000000 --- a/pkcs10/CHANGELOG.md +++ /dev/null @@ -1,5 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). diff --git a/pkcs10/Cargo.toml b/pkcs10/Cargo.toml deleted file mode 100644 index a66cadf7d..000000000 --- a/pkcs10/Cargo.toml +++ /dev/null @@ -1,31 +0,0 @@ -[package] -name = "pkcs10" -version = "0.0.0" -description = """ -Pure Rust implementation of Public-Key Cryptography Standards (PKCS) #10: -Certification Request Syntax Specification (RFC 5208). -""" -authors = ["RustCrypto Developers"] -license = "Apache-2.0 OR MIT" -repository = "https://github.com/RustCrypto/formats/tree/master/pkcs10" -categories = ["cryptography", "data-structures", "encoding", "no-std", "parser-implementations"] -keywords = ["crypto", "pkcs", "certification", "request", "csr", "certificate"] -readme = "README.md" -edition = "2021" -rust-version = "1.56" - -[dev-dependencies] -x509 = { version = "0.0.1", path = "../x509" } -hex-literal = "0.3" - -[dependencies] -der = { version = "=0.6.0-pre.1", features = ["oid", "derive", "alloc"], path = "../der" } -spki = { version = "=0.6.0-pre.0", path = "../spki" } -x501 = { version = "=0.1.0-pre.0", path = "../x501" } - -[features] -pem = ["der/pem", "spki/pem"] - -[package.metadata.docs.rs] -all-features = true -rustdoc-args = ["--cfg", "docsrs"] diff --git a/pkcs10/LICENSE-APACHE b/pkcs10/LICENSE-APACHE deleted file mode 100644 index 78173fa2e..000000000 --- a/pkcs10/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/pkcs10/LICENSE-MIT b/pkcs10/LICENSE-MIT deleted file mode 100644 index b9d3eff60..000000000 --- a/pkcs10/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2020-2021 The RustCrypto Project Developers - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/pkcs10/README.md b/pkcs10/README.md deleted file mode 100644 index 77e0e03d0..000000000 --- a/pkcs10/README.md +++ /dev/null @@ -1,81 +0,0 @@ -# [RustCrypto]: PKCS#10 (Certification Requests) - -[![crate][crate-image]][crate-link] -[![Docs][docs-image]][docs-link] -[![Build Status][build-image]][build-link] -![Apache2/MIT licensed][license-image] -![Rust Version][rustc-image] -[![Project Chat][chat-image]][chat-link] - -Pure Rust implementation of Public-Key Cryptography Standards (PKCS) #10: -Certification Request Syntax Specification ([RFC 2986]). - -[Documentation][docs-link] - -## About PKCS#10 - -PKCS#10 is a format for certification requests (sometimes called certificate -signing requests). This format usually contains a public key. - -You can identify a PKCS#10 request encoded as PEM (i.e. text) by the -following: - -```text ------BEGIN CERTIFICATE REQUEST----- -``` - -PKCS#10 certification requests can also be serialized in an ASN.1-based binary -format. The PEM text encoding is a Base64 representation of this format. - -## Supported Algorithms - -This crate is implemented in an algorithm-agnostic manner with the goal of -enabling PKCS#10 support for any algorithm. - -That said, it has been tested for interoperability against keys generated by -OpenSSL for the following algorithms: - -- RSA (`id-rsaEncryption`) - -Please open an issue if you encounter trouble using it with a particular -algorithm, including the ones listed above or other algorithms. - -## Minimum Supported Rust Version - -This crate requires **Rust 1.56** at a minimum. - -We may change the MSRV in the future, but it will be accompanied by a minor -version bump. - -## License - -Licensed under either of: - - * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) - * [MIT license](http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in the work by you, as defined in the Apache-2.0 license, shall be -dual licensed as above, without any additional terms or conditions. - -[//]: # (badges) - -[crate-image]: https://img.shields.io/crates/v/pkcs10.svg -[crate-link]: https://crates.io/crates/pkcs10 -[docs-image]: https://docs.rs/pkcs10/badge.svg -[docs-link]: https://docs.rs/pkcs10/ -[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.56+-blue.svg -[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg -[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/300570-formats -[build-image]: https://github.com/RustCrypto/formats/workflows/pkcs10/badge.svg?branch=master&event=push -[build-link]: https://github.com/RustCrypto/formats/actions - -[//]: # (links) - -[RustCrypto]: https://github.com/rustcrypto -[RFC 2986]: https://tools.ietf.org/html/rfc2986 diff --git a/pkcs10/src/document.rs b/pkcs10/src/document.rs deleted file mode 100644 index fd3823d96..000000000 --- a/pkcs10/src/document.rs +++ /dev/null @@ -1,88 +0,0 @@ -//! Certification request document. - -use super::CertReq; - -use alloc::vec::Vec; -use core::fmt; - -use der::{Decodable, Document}; - -#[cfg(feature = "pem")] -use {core::str::FromStr, der::pem}; - -/// Certification request document. -/// -/// This type provides storage for [`CertReq`] encoded as ASN.1 -/// DER with the invariant that the contained-document is "well-formed", i.e. -/// it will parse successfully according to this crate's parsing rules. -#[derive(Clone)] -pub struct CertReqDocument(Vec); - -impl<'a> Document<'a> for CertReqDocument { - type Message = CertReq<'a>; - const SENSITIVE: bool = false; -} - -impl AsRef<[u8]> for CertReqDocument { - fn as_ref(&self) -> &[u8] { - self.0.as_ref() - } -} - -impl TryFrom<&[u8]> for CertReqDocument { - type Error = der::Error; - - fn try_from(bytes: &[u8]) -> Result { - bytes.to_vec().try_into() - } -} - -impl TryFrom> for CertReqDocument { - type Error = der::Error; - - fn try_from(cr: CertReq<'_>) -> Result { - Self::try_from(&cr) - } -} - -impl TryFrom<&CertReq<'_>> for CertReqDocument { - type Error = der::Error; - - fn try_from(cr: &CertReq<'_>) -> Result { - Self::from_msg(cr) - } -} - -impl TryFrom> for CertReqDocument { - type Error = der::Error; - - fn try_from(bytes: Vec) -> der::Result { - // Ensure document is well-formed - CertReq::from_der(bytes.as_slice())?; - Ok(Self(bytes)) - } -} - -impl fmt::Debug for CertReqDocument { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt.debug_tuple("CertReqDocument") - .field(&self.decode()) - .finish() - } -} - -#[cfg(feature = "pem")] -#[cfg_attr(docsrs, doc(cfg(feature = "pem")))] -impl FromStr for CertReqDocument { - type Err = der::Error; - - fn from_str(s: &str) -> Result { - Self::from_pem(s) - } -} - -#[cfg(feature = "pem")] -#[cfg_attr(docsrs, doc(cfg(feature = "pem")))] -impl pem::PemLabel for CertReqDocument { - const TYPE_LABEL: &'static str = "CERTIFICATE REQUEST"; -} diff --git a/pkcs10/src/info.rs b/pkcs10/src/info.rs deleted file mode 100644 index f75ef7eac..000000000 --- a/pkcs10/src/info.rs +++ /dev/null @@ -1,42 +0,0 @@ -use super::Version; - -use der::{Decodable, Sequence}; -use spki::SubjectPublicKeyInfo; -use x501::attr::Attributes; -use x501::name::Name; - -/// PKCS#10 `CertificationRequestInfo` as defined in [RFC 2986 Section 4]. -/// -/// ```text -/// CertificationRequestInfo ::= SEQUENCE { -/// version INTEGER { v1(0) } (v1,...), -/// subject Name, -/// subjectPKInfo SubjectPublicKeyInfo{{ PKInfoAlgorithms }}, -/// attributes [0] Attributes{{ CRIAttributes }} -/// } -/// ``` -/// -/// [RFC 2986 Section 4]: https://datatracker.ietf.org/doc/html/rfc2986#section-4 -#[derive(Clone, Debug, PartialEq, Eq, Sequence)] -pub struct CertReqInfo<'a> { - /// Certification request version. - pub version: Version, - - /// Subject name. - pub subject: Name<'a>, - - /// Subject public key info. - pub public_key: SubjectPublicKeyInfo<'a>, - - /// Request attributes. - #[asn1(context_specific = "0", tag_mode = "IMPLICIT")] - pub attributes: Attributes<'a>, -} - -impl<'a> TryFrom<&'a [u8]> for CertReqInfo<'a> { - type Error = der::Error; - - fn try_from(bytes: &'a [u8]) -> Result { - Self::from_der(bytes) - } -} diff --git a/pkcs10/src/lib.rs b/pkcs10/src/lib.rs deleted file mode 100644 index 0e5687db3..000000000 --- a/pkcs10/src/lib.rs +++ /dev/null @@ -1,55 +0,0 @@ -#![no_std] -#![cfg_attr(docsrs, feature(doc_cfg))] -#![doc = include_str!("../README.md")] -#![doc( - html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg", - html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg", - html_root_url = "https://docs.rs/pkcs10/0.0.0" -)] -#![forbid(unsafe_code, clippy::unwrap_used)] -#![warn(missing_docs, rust_2018_idioms, unused_qualifications)] - -extern crate alloc; - -mod document; -mod info; -mod version; - -pub use document::CertReqDocument; -pub use info::CertReqInfo; -pub use version::Version; - -use der::asn1::BitString; -use der::{Decodable, Sequence}; -use spki::AlgorithmIdentifier; - -/// PKCS#10 `CertificationRequest` as defined in [RFC 2986 Section 4]. -/// -/// ```text -/// CertificationRequest ::= SEQUENCE { -/// certificationRequestInfo CertificationRequestInfo, -/// signatureAlgorithm AlgorithmIdentifier{{ SignatureAlgorithms }}, -/// signature BIT STRING -/// } -/// ``` -/// -/// [RFC 2986 Section 4]: https://datatracker.ietf.org/doc/html/rfc2986#section-4 -#[derive(Clone, Debug, PartialEq, Eq, Sequence)] -pub struct CertReq<'a> { - /// Certification request information. - pub info: CertReqInfo<'a>, - - /// Signature algorithm identifier. - pub algorithm: AlgorithmIdentifier<'a>, - - /// Signature. - pub signature: BitString<'a>, -} - -impl<'a> TryFrom<&'a [u8]> for CertReq<'a> { - type Error = der::Error; - - fn try_from(bytes: &'a [u8]) -> Result { - Self::from_der(bytes) - } -} diff --git a/pkcs10/src/version.rs b/pkcs10/src/version.rs deleted file mode 100644 index 079b9feba..000000000 --- a/pkcs10/src/version.rs +++ /dev/null @@ -1,14 +0,0 @@ -//! Certification request information version identifier. - -use der::Enumerated; - -/// Version identifier for certification request information. -/// -/// (RFC 2986 designates `0` as the only valid version) -#[derive(Clone, Debug, Copy, PartialEq, Eq, Enumerated)] -#[asn1(type = "INTEGER")] -#[repr(u8)] -pub enum Version { - /// Denotes PKCS#8 v1 - V1 = 0, -} diff --git a/x509/Cargo.toml b/x509/Cargo.toml index f8d5b1a1c..585d4e402 100644 --- a/x509/Cargo.toml +++ b/x509/Cargo.toml @@ -25,7 +25,7 @@ hex-literal = "0.3" rstest = "0.12.0" [features] -std = ["der/std"] +std = ["der/std", "spki/std"] [package.metadata.docs.rs] all-features = true diff --git a/x509/src/lib.rs b/x509/src/lib.rs index f9b20b37a..0ff37074b 100644 --- a/x509/src/lib.rs +++ b/x509/src/lib.rs @@ -16,6 +16,7 @@ extern crate std; pub mod anchor; pub mod ext; +pub mod request; mod certificate; diff --git a/x509/src/request.rs b/x509/src/request.rs new file mode 100644 index 000000000..e0429100a --- /dev/null +++ b/x509/src/request.rs @@ -0,0 +1,85 @@ +//! PKCS#10 Certification Request types + +use der::asn1::BitString; +use der::{Decodable, Enumerated, Sequence}; +use spki::{AlgorithmIdentifier, SubjectPublicKeyInfo}; +use x501::attr::Attributes; +use x501::name::Name; + +/// Version identifier for certification request information. +/// +/// (RFC 2986 designates `0` as the only valid version) +#[derive(Clone, Debug, Copy, PartialEq, Eq, Enumerated)] +#[asn1(type = "INTEGER")] +#[repr(u8)] +pub enum Version { + /// Denotes PKCS#8 v1 + V1 = 0, +} + +/// PKCS#10 `CertificationRequestInfo` as defined in [RFC 2986 Section 4]. +/// +/// ```text +/// CertificationRequestInfo ::= SEQUENCE { +/// version INTEGER { v1(0) } (v1,...), +/// subject Name, +/// subjectPKInfo SubjectPublicKeyInfo{{ PKInfoAlgorithms }}, +/// attributes [0] Attributes{{ CRIAttributes }} +/// } +/// ``` +/// +/// [RFC 2986 Section 4]: https://datatracker.ietf.org/doc/html/rfc2986#section-4 +#[derive(Clone, Debug, PartialEq, Eq, Sequence)] +pub struct CertReqInfo<'a> { + /// Certification request version. + pub version: Version, + + /// Subject name. + pub subject: Name<'a>, + + /// Subject public key info. + pub public_key: SubjectPublicKeyInfo<'a>, + + /// Request attributes. + #[asn1(context_specific = "0", tag_mode = "IMPLICIT")] + pub attributes: Attributes<'a>, +} + +impl<'a> TryFrom<&'a [u8]> for CertReqInfo<'a> { + type Error = der::Error; + + fn try_from(bytes: &'a [u8]) -> Result { + Self::from_der(bytes) + } +} + +/// PKCS#10 `CertificationRequest` as defined in [RFC 2986 Section 4]. +/// +/// ```text +/// CertificationRequest ::= SEQUENCE { +/// certificationRequestInfo CertificationRequestInfo, +/// signatureAlgorithm AlgorithmIdentifier{{ SignatureAlgorithms }}, +/// signature BIT STRING +/// } +/// ``` +/// +/// [RFC 2986 Section 4]: https://datatracker.ietf.org/doc/html/rfc2986#section-4 +#[derive(Clone, Debug, PartialEq, Eq, Sequence)] +pub struct CertReq<'a> { + /// Certification request information. + pub info: CertReqInfo<'a>, + + /// Signature algorithm identifier. + pub algorithm: AlgorithmIdentifier<'a>, + + /// Signature. + pub signature: BitString<'a>, +} + +impl<'a> TryFrom<&'a [u8]> for CertReq<'a> { + type Error = der::Error; + + fn try_from(bytes: &'a [u8]) -> Result { + Self::from_der(bytes) + } +} diff --git a/pkcs10/tests/certreq.rs b/x509/tests/certreq.rs similarity index 81% rename from pkcs10/tests/certreq.rs rename to x509/tests/certreq.rs index c3f2a63b3..0e504feb8 100644 --- a/pkcs10/tests/certreq.rs +++ b/x509/tests/certreq.rs @@ -2,13 +2,7 @@ use der::{Encodable, Tag, Tagged}; use hex_literal::hex; -use pkcs10::{CertReq, Version}; - -#[cfg(feature = "pem")] -use der::Document; - -#[cfg(feature = "pem")] -use pkcs10::CertReqDocument; +use x509::request::{CertReq, Version}; const RSA_KEY: &[u8] = &hex!("3082010A0282010100BF59F7FE716DDE47C73579CA846EFA8D30AB3612E0D6A524204A72CA8E50C9F459513DF0D73331BED3D7A2DA7A362719E471EE6A9D87827D1024ED44605AB9B48F3B808C5E173B9F3EC4003D57F1718489F5C7A0421C46FBD527A40AB4BA6B9DB16A545D1ECF6E2A5633BD80594EBA4AFEE71F63E1D357C64E9A3FF6B83746A885C373F3527987E4C2B4AF7FE4D4EA16405E5E15285DD938823AA18E2634BAFE847A761CAFABB0401D3FA03A07A9D097CBB0C77156CCFE36131DADF1C109C2823972F0AF21A35F358E788304C0C78B951739D91FABFFD07AA8CD4F69746B3D0EB4587469F9D39F4FBDC761200DFB27DAF69562311D8B191B7EEFAAE2F8D6F8EB0203010001"); const RSA_SIG: &[u8] = &hex!("2B053CFE81C6542176BD70B373A5FC8DC1F1806A5AB10D25E36690EED1DF57AD5F18EC0CCF165F000245B14157141224B431EC6715EFE937F66B892D11EDF8858EDF67ACCAE9701A2244BECA80705D7CC292BAD9B02001E4572EE492B08473D5AF59CC83DDA1DE5C2BF470FD784495070A9C5AF8EA9A4060C1DBC5C4690CC8DF6D528C55D82EC9C0DF3046BBCAE7542025D7EE170788C9C234132703290A31AC2700E55339590226D5E582EC61869862769FD85B45F287FFDD6DB530995D31F94D7D2C26EF3F48A182C3026CC698F382A72F1A11E3C689953055DAC0DFEBE9CDB163CA3AF33FFC4DA0F6B84B9D7CDD4321CCECD4BAC528DEFF9715FFD9D4731E"); @@ -16,10 +10,6 @@ const RSA_SIG: &[u8] = &hex!("2B053CFE81C6542176BD70B373A5FC8DC1F1806A5AB10D25E3 /// RSA-2048 `CertReq` encoded as ASN.1 DER const RSA_2048_DER_EXAMPLE: &[u8] = include_bytes!("examples/rsa2048-csr.der"); -/// RSA-2048 PKCS#8 public key encoded as PEM -#[cfg(feature = "pem")] -const RSA_2048_PEM_EXAMPLE: &str = include_str!("examples/rsa2048-csr.pem"); - const NAMES: &[(&str, &str)] = &[ ("2.5.4.3", "example.com"), ("2.5.4.7", "Los Angeles"), @@ -84,17 +74,6 @@ fn decode_rsa_2048_der() { assert_eq!(cr.signature.as_bytes().unwrap(), RSA_SIG); } -#[test] -#[cfg(feature = "pem")] -fn decode_rsa_2048_pem() { - let doc: CertReqDocument = RSA_2048_PEM_EXAMPLE.parse().unwrap(); - assert_eq!(doc.as_ref(), RSA_2048_DER_EXAMPLE); - - // Ensure `CertReqDocument` parses successfully - let cr = CertReq::try_from(RSA_2048_DER_EXAMPLE).unwrap(); - assert_eq!(doc.decode(), cr); -} - // The following tests currently fail because of a bug in the `der` crate; // specifically, the `IMPLICIT` tagging on `CertReqInfo::attributes`. @@ -104,15 +83,3 @@ fn encode_rsa_2048_der() { let cr_encoded = cr.to_vec().unwrap(); assert_eq!(RSA_2048_DER_EXAMPLE, cr_encoded.as_slice()); } - -#[test] -#[cfg(feature = "pem")] -fn encode_rsa_2048_pem() { - let cr = CertReq::try_from(RSA_2048_DER_EXAMPLE).unwrap(); - let cr_encoded = CertReqDocument::try_from(cr) - .unwrap() - .to_pem(Default::default()) - .unwrap(); - - assert_eq!(RSA_2048_PEM_EXAMPLE, cr_encoded); -} diff --git a/pkcs10/tests/examples/rsa2048-crt.der b/x509/tests/examples/rsa2048-crt.der similarity index 100% rename from pkcs10/tests/examples/rsa2048-crt.der rename to x509/tests/examples/rsa2048-crt.der diff --git a/pkcs10/tests/examples/rsa2048-crt.pem b/x509/tests/examples/rsa2048-crt.pem similarity index 100% rename from pkcs10/tests/examples/rsa2048-crt.pem rename to x509/tests/examples/rsa2048-crt.pem diff --git a/pkcs10/tests/examples/rsa2048-csr.der b/x509/tests/examples/rsa2048-csr.der similarity index 100% rename from pkcs10/tests/examples/rsa2048-csr.der rename to x509/tests/examples/rsa2048-csr.der diff --git a/pkcs10/tests/examples/rsa2048-csr.pem b/x509/tests/examples/rsa2048-csr.pem similarity index 100% rename from pkcs10/tests/examples/rsa2048-csr.pem rename to x509/tests/examples/rsa2048-csr.pem diff --git a/pkcs10/tests/examples/rsa2048-prv.der b/x509/tests/examples/rsa2048-prv.der similarity index 100% rename from pkcs10/tests/examples/rsa2048-prv.der rename to x509/tests/examples/rsa2048-prv.der diff --git a/pkcs10/tests/examples/rsa2048-prv.pem b/x509/tests/examples/rsa2048-prv.pem similarity index 100% rename from pkcs10/tests/examples/rsa2048-prv.pem rename to x509/tests/examples/rsa2048-prv.pem From a665ac0b73a0e0f701036ba00d281a73cefedf91 Mon Sep 17 00:00:00 2001 From: Nathaniel McCallum Date: Mon, 21 Feb 2022 10:03:30 -0500 Subject: [PATCH 2/2] Merge x501 crate into x509 Signed-off-by: Nathaniel McCallum --- .github/workflows/x501.yml | 65 ---------- .github/workflows/x509.yml | 1 - Cargo.lock | 9 -- Cargo.toml | 1 - x501/CHANGELOG.md | 5 - x501/Cargo.toml | 25 ---- x501/LICENSE-APACHE | 201 ------------------------------ x501/LICENSE-MIT | 25 ---- x501/README.md | 67 ---------- x501/src/lib.rs | 16 --- x509/Cargo.toml | 1 - x509/src/anchor.rs | 7 +- {x501 => x509}/src/attr.rs | 0 x509/src/certificate.rs | 3 +- x509/src/ext/pkix.rs | 3 +- x509/src/ext/pkix/name/dp.rs | 2 +- x509/src/ext/pkix/name/general.rs | 2 +- x509/src/lib.rs | 3 + {x501 => x509}/src/name.rs | 0 x509/src/request.rs | 4 +- {x501 => x509}/src/time.rs | 0 {x501 => x509}/tests/name.rs | 6 +- x509/tests/pkix_extensions.rs | 2 +- {x501 => x509}/tests/validity.rs | 2 +- 24 files changed, 19 insertions(+), 431 deletions(-) delete mode 100644 .github/workflows/x501.yml delete mode 100644 x501/CHANGELOG.md delete mode 100644 x501/Cargo.toml delete mode 100644 x501/LICENSE-APACHE delete mode 100644 x501/LICENSE-MIT delete mode 100644 x501/README.md delete mode 100644 x501/src/lib.rs rename {x501 => x509}/src/attr.rs (100%) rename {x501 => x509}/src/name.rs (100%) rename {x501 => x509}/src/time.rs (100%) rename {x501 => x509}/tests/name.rs (97%) rename {x501 => x509}/tests/validity.rs (99%) diff --git a/.github/workflows/x501.yml b/.github/workflows/x501.yml deleted file mode 100644 index 2e2fb0ccc..000000000 --- a/.github/workflows/x501.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: x501 - -on: - pull_request: - paths: - - "const-oid/**" - - "der/**" - - "x501/**" - - "Cargo.*" - push: - branches: master - -defaults: - run: - working-directory: x501 - -env: - CARGO_INCREMENTAL: 0 - RUSTFLAGS: "-Dwarnings" - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - 1.57.0 # MSRV - - stable - target: - - thumbv7em-none-eabi - - wasm32-unknown-unknown - steps: - - uses: actions/checkout@v2 - - uses: RustCrypto/actions/cargo-cache@master - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.rust }} - target: ${{ matrix.target }} - override: true - - uses: RustCrypto/actions/cargo-hack-install@master - - run: cargo hack build --target ${{ matrix.target }} --feature-powerset --exclude-features std - - minimal-versions: - uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master - with: - working-directory: ${{ github.workflow }} - - test: - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - 1.57.0 # MSRV - - stable - steps: - - uses: actions/checkout@v2 - - uses: RustCrypto/actions/cargo-cache@master - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.rust }} - override: true - - uses: RustCrypto/actions/cargo-hack-install@master - - run: cargo hack test --feature-powerset diff --git a/.github/workflows/x509.yml b/.github/workflows/x509.yml index 0f608afa6..7a24fbfc4 100644 --- a/.github/workflows/x509.yml +++ b/.github/workflows/x509.yml @@ -6,7 +6,6 @@ on: - "const-oid/**" - "der/**" - "spki/**" - - "x501/**" - "x509/**" - "Cargo.*" push: diff --git a/Cargo.lock b/Cargo.lock index e5bfdbaec..6120dd7d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1212,14 +1212,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "x501" -version = "0.1.0-pre.0" -dependencies = [ - "der", - "hex-literal", -] - [[package]] name = "x509" version = "0.0.1" @@ -1229,7 +1221,6 @@ dependencies = [ "hex-literal", "rstest", "spki", - "x501", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index e6853394b..fd3318139 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ members = [ "tai64", "tls_codec", "tls_codec/derive", - "x501", "x509" ] diff --git a/x501/CHANGELOG.md b/x501/CHANGELOG.md deleted file mode 100644 index d6637e049..000000000 --- a/x501/CHANGELOG.md +++ /dev/null @@ -1,5 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). diff --git a/x501/Cargo.toml b/x501/Cargo.toml deleted file mode 100644 index d3afb0cf2..000000000 --- a/x501/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "x501" -version = "0.1.0-pre.0" # Also update html_root_url in lib.rs when bumping this -edition = "2021" -description = "Pure Rust implementation of some of the types defined in X.501" -authors = ["RustCrypto Developers"] -license = "Apache-2.0 OR MIT" -repository = "https://github.com/RustCrypto/formats/tree/master/x509" -categories = ["cryptography", "data-structures", "encoding", "no-std"] -keywords = ["crypto"] -readme = "README.md" -rust-version = "1.56" - -[dev-dependencies] -hex-literal = "0.3" - -[dependencies] -der = { version = "=0.6.0-pre.1", features = ["derive", "alloc", "oid"], path = "../der" } - -[features] -std = ["der/std"] - -[package.metadata.docs.rs] -all-features = true -rustdoc-args = ["--cfg", "docsrs"] diff --git a/x501/LICENSE-APACHE b/x501/LICENSE-APACHE deleted file mode 100644 index 78173fa2e..000000000 --- a/x501/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/x501/LICENSE-MIT b/x501/LICENSE-MIT deleted file mode 100644 index b9d3eff60..000000000 --- a/x501/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2020-2021 The RustCrypto Project Developers - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/x501/README.md b/x501/README.md deleted file mode 100644 index 820945bbc..000000000 --- a/x501/README.md +++ /dev/null @@ -1,67 +0,0 @@ -# [RustCrypto]: X.501 (Directory Services Types) - -[![crate][crate-image]][crate-link] -[![Docs][docs-image]][docs-link] -[![Build Status][build-image]][build-link] -![Apache2/MIT licensed][license-image] -![Rust Version][rustc-image] -[![Project Chat][chat-image]][chat-link] - -Pure Rust implementation of X.501 Types. - -[Documentation][docs-link] - -## About X.501 - -X.501 is a series of standards originally specified in [ISO/IEC 9594] and -subsequently used in numerous standards such as [RFC 2986] and [RFC 5280]. -The most common modern use of these types is in X.509 certificates and related -standards. - -### Conformity Note - -Many of the types in this crate are defined in both [ISO/IEC 9594] and IETF -standards such as [RFC 2986] and [RFC 5280]. Where types differ between these -standards, this crate conforms to the IETF standards. - -## Minimum Supported Rust Version - -This crate requires **Rust 1.56** at a minimum. - -We may change the MSRV in the future, but it will be accompanied by a minor -version bump. - -## License - -Licensed under either of: - - * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) - * [MIT license](http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in the work by you, as defined in the Apache-2.0 license, shall be -dual licensed as above, without any additional terms or conditions. - -[//]: # (badges) - -[crate-image]: https://img.shields.io/crates/v/x500.svg -[crate-link]: https://crates.io/crates/x500 -[docs-image]: https://docs.rs/x500/badge.svg -[docs-link]: https://docs.rs/x500/ -[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.56+-blue.svg -[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg -[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/300570-formats -[build-image]: https://github.com/RustCrypto/formats/workflows/x500/badge.svg?branch=master&event=push -[build-link]: https://github.com/RustCrypto/formats/actions - -[//]: # (links) - -[RustCrypto]: https://github.com/rustcrypto -[RFC 2986]: https://tools.ietf.org/html/rfc2986 -[RFC 5280]: https://tools.ietf.org/html/rfc5280 -[ISO/IEC 9594]: https://www.iso.org/standard/72557.html diff --git a/x501/src/lib.rs b/x501/src/lib.rs deleted file mode 100644 index b7b369aa0..000000000 --- a/x501/src/lib.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg_attr(docsrs, feature(doc_cfg))] -#![doc = include_str!("../README.md")] -#![doc( - html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg", - html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg", - html_root_url = "https://docs.rs/x501/0.1.0-pre.0" -)] -#![forbid(unsafe_code)] -#![warn(missing_docs, rust_2018_idioms)] - -extern crate alloc; - -pub mod attr; -pub mod name; -pub mod time; diff --git a/x509/Cargo.toml b/x509/Cargo.toml index 585d4e402..a18ec4746 100644 --- a/x509/Cargo.toml +++ b/x509/Cargo.toml @@ -18,7 +18,6 @@ rust-version = "1.56" der = { version = "=0.6.0-pre.1", features = ["derive", "alloc", "flagset"], path = "../der" } flagset = { version = "0.4.3" } spki = { version = "=0.6.0-pre.0", path = "../spki" } -x501 = { version = "=0.1.0-pre.0", path = "../x501" } [dev-dependencies] hex-literal = "0.3" diff --git a/x509/src/anchor.rs b/x509/src/anchor.rs index 71942ff57..25ee21112 100644 --- a/x509/src/anchor.rs +++ b/x509/src/anchor.rs @@ -1,14 +1,13 @@ //! Trust anchor-related structures as defined in RFC 5914 -use crate::ext::pkix::certpolicy::CertificatePolicies; -use crate::ext::pkix::NameConstraints; -use crate::{ext::Extensions, Certificate, TbsCertificate}; +use crate::ext::pkix::{certpolicy::CertificatePolicies, NameConstraints}; +use crate::{ext::Extensions, name::Name}; +use crate::{Certificate, TbsCertificate}; use der::asn1::{OctetString, Utf8String}; use der::{Choice, Enumerated, Sequence}; use flagset::{flags, FlagSet}; use spki::SubjectPublicKeyInfo; -use x501::name::Name; /// Version identifier for TrustAnchorInfo #[derive(Clone, Debug, Copy, PartialEq, Eq, Enumerated)] diff --git a/x501/src/attr.rs b/x509/src/attr.rs similarity index 100% rename from x501/src/attr.rs rename to x509/src/attr.rs diff --git a/x509/src/certificate.rs b/x509/src/certificate.rs index fe81780d3..791dc38fd 100644 --- a/x509/src/certificate.rs +++ b/x509/src/certificate.rs @@ -1,7 +1,8 @@ +use crate::{name::Name, time::Validity}; + use der::asn1::{BitString, UIntBytes}; use der::{Enumerated, Sequence}; use spki::{AlgorithmIdentifier, SubjectPublicKeyInfo}; -use x501::{name::Name, time::Validity}; /// Certificate `Version` as defined in [RFC 5280 Section 4.1]. /// diff --git a/x509/src/ext/pkix.rs b/x509/src/ext/pkix.rs index 2a24f3aed..27c9755e4 100644 --- a/x509/src/ext/pkix.rs +++ b/x509/src/ext/pkix.rs @@ -11,6 +11,8 @@ mod authkeyid; mod keyusage; mod policymap; +use crate::attr::AttributeTypeAndValue; + pub use access::{AccessDescription, AuthorityInfoAccessSyntax, SubjectInfoAccessSyntax}; pub use authkeyid::AuthorityKeyIdentifier; pub use certpolicy::CertificatePolicies; @@ -25,7 +27,6 @@ pub use policymap::{PolicyMapping, PolicyMappings}; use alloc::vec::Vec; use der::asn1::OctetString; -use x501::attr::AttributeTypeAndValue; /// SubjectKeyIdentifier as defined in [RFC 5280 Section 4.2.1.2]. /// diff --git a/x509/src/ext/pkix/name/dp.rs b/x509/src/ext/pkix/name/dp.rs index adc1980e0..3cfdf969a 100644 --- a/x509/src/ext/pkix/name/dp.rs +++ b/x509/src/ext/pkix/name/dp.rs @@ -1,7 +1,7 @@ use super::GeneralNames; +use crate::name::RelativeDistinguishedName; use der::Choice; -use x501::name::RelativeDistinguishedName; /// DistributionPointName as defined in [RFC 5280 Section 4.2.1.13]. /// diff --git a/x509/src/ext/pkix/name/general.rs b/x509/src/ext/pkix/name/general.rs index 3ef393ccb..1b3c02e48 100644 --- a/x509/src/ext/pkix/name/general.rs +++ b/x509/src/ext/pkix/name/general.rs @@ -1,10 +1,10 @@ //! GeneralNames as defined in [RFC 5280 Section 4.2.1.6]. use super::{EdiPartyName, OtherName}; +use crate::name::Name; use der::asn1::{Ia5String, ObjectIdentifier, OctetString}; use der::Choice; -use x501::name::Name; /// GeneralNames as defined in [RFC 5280 Section 4.2.1.6]. /// diff --git a/x509/src/lib.rs b/x509/src/lib.rs index 0ff37074b..cf02acca0 100644 --- a/x509/src/lib.rs +++ b/x509/src/lib.rs @@ -15,8 +15,11 @@ extern crate alloc; extern crate std; pub mod anchor; +pub mod attr; pub mod ext; +pub mod name; pub mod request; +pub mod time; mod certificate; diff --git a/x501/src/name.rs b/x509/src/name.rs similarity index 100% rename from x501/src/name.rs rename to x509/src/name.rs diff --git a/x509/src/request.rs b/x509/src/request.rs index e0429100a..1955933a6 100644 --- a/x509/src/request.rs +++ b/x509/src/request.rs @@ -1,10 +1,10 @@ //! PKCS#10 Certification Request types +use crate::{attr::Attributes, name::Name}; + use der::asn1::BitString; use der::{Decodable, Enumerated, Sequence}; use spki::{AlgorithmIdentifier, SubjectPublicKeyInfo}; -use x501::attr::Attributes; -use x501::name::Name; /// Version identifier for certification request information. /// diff --git a/x501/src/time.rs b/x509/src/time.rs similarity index 100% rename from x501/src/time.rs rename to x509/src/time.rs diff --git a/x501/tests/name.rs b/x509/tests/name.rs similarity index 97% rename from x501/tests/name.rs rename to x509/tests/name.rs index b5e616287..8347d916d 100644 --- a/x501/tests/name.rs +++ b/x509/tests/name.rs @@ -1,8 +1,8 @@ //! Name tests -//use der::asn1::{SetOf, SequenceOfIter, SequenceOf}; -use der::{Decodable, Encodable, Tag, Tagged}; //, Encodable}; + +use der::{Decodable, Encodable, Tag, Tagged}; use hex_literal::hex; -use x501::name::{Name, RelativeDistinguishedName}; //, AttributeTypeAndValue; +use x509::name::{Name, RelativeDistinguishedName}; #[test] fn decode_name() { diff --git a/x509/tests/pkix_extensions.rs b/x509/tests/pkix_extensions.rs index ac826befe..b79720a8a 100644 --- a/x509/tests/pkix_extensions.rs +++ b/x509/tests/pkix_extensions.rs @@ -2,12 +2,12 @@ use der::asn1::{BitString, UIntBytes}; use der::{Decodable, Encodable, ErrorKind, Length, Tag, Tagged}; use hex_literal::hex; -use x501::name::Name; use x509::ext::other::{OcspNoCheck, PivNaciIndicator}; use x509::ext::pkix::crl::dp::{DistributionPoint, ReasonFlags, Reasons}; use x509::ext::pkix::name::{DistributionPointName, GeneralName, GeneralNames}; use x509::ext::pkix::{oids::*, *}; use x509::ext::Extensions; +use x509::name::Name; use x509::{Certificate, Version}; fn spin_over_exts<'a>(exts: Extensions<'a>) { diff --git a/x501/tests/validity.rs b/x509/tests/validity.rs similarity index 99% rename from x501/tests/validity.rs rename to x509/tests/validity.rs index 15e6f1241..50562b03c 100644 --- a/x501/tests/validity.rs +++ b/x509/tests/validity.rs @@ -2,7 +2,7 @@ use der::Encodable; use hex_literal::hex; -use x501::time::Validity; +use x509::time::Validity; #[test] fn decode_validity() {