diff --git a/.github/workflows/pkcs10.yml b/.github/workflows/pkcs10.yml index 0ed155f69..7a65caac4 100644 --- a/.github/workflows/pkcs10.yml +++ b/.github/workflows/pkcs10.yml @@ -9,6 +9,7 @@ on: - "pem-rfc7468/**" - "pkcs10/**" - "spki/**" + - "x501/**" - "x509/**" - "Cargo.*" push: diff --git a/.github/workflows/x501.yml b/.github/workflows/x501.yml new file mode 100644 index 000000000..6f886e056 --- /dev/null +++ b/.github/workflows/x501.yml @@ -0,0 +1,58 @@ +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@v1 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + target: ${{ matrix.target }} + override: true + - run: cargo install cargo-hack + - run: cargo hack build --release --target ${{ matrix.target }} --feature-powerset + + test: + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - 1.57.0 # MSRV + - stable + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + override: true + - run: cargo install cargo-hack + - run: cargo hack test --release --feature-powerset diff --git a/.github/workflows/x509.yml b/.github/workflows/x509.yml index 9d4f42d29..1f185824f 100644 --- a/.github/workflows/x509.yml +++ b/.github/workflows/x509.yml @@ -6,6 +6,7 @@ on: - "const-oid/**" - "der/**" - "spki/**" + - "x501/**" - "x509/**" - "Cargo.*" push: diff --git a/Cargo.lock b/Cargo.lock index 5dd86745e..742536ba7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -537,6 +537,7 @@ dependencies = [ "der", "hex-literal", "spki", + "x501", "x509", ] @@ -1199,6 +1200,14 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "x501" +version = "0.1.0" +dependencies = [ + "der", + "hex-literal", +] + [[package]] name = "x509" version = "0.0.1" @@ -1206,6 +1215,7 @@ dependencies = [ "der", "hex-literal", "spki", + "x501", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 1e37abceb..db7e3434e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,5 +19,6 @@ members = [ "tai64", "tls_codec", "tls_codec/derive", + "x501", "x509" ] diff --git a/pkcs10/Cargo.toml b/pkcs10/Cargo.toml index b262402e8..2b18f42a2 100644 --- a/pkcs10/Cargo.toml +++ b/pkcs10/Cargo.toml @@ -15,12 +15,13 @@ 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.0", features = ["oid", "derive", "alloc"], path = "../der" } spki = { version = "0.6.0-pre", path = "../spki" } -x509 = { version = "0.0.1", path = "../x509" } +x501 = { version = "0.1.0", path = "../x501" } [features] pem = ["der/pem", "spki/pem"] diff --git a/pkcs10/src/info.rs b/pkcs10/src/info.rs index 5a23bddb0..bcc648276 100644 --- a/pkcs10/src/info.rs +++ b/pkcs10/src/info.rs @@ -1,5 +1,8 @@ use super::{Attributes, Version}; + use der::{Decodable, Sequence}; +use spki::SubjectPublicKeyInfo; +use x501::name::Name; /// PKCS#10 `CertificationRequestInfo` as defined in [RFC 2986 Section 4]. /// @@ -19,10 +22,10 @@ pub struct CertReqInfo<'a> { pub version: Version, /// Subject name. - pub subject: x509::Name<'a>, + pub subject: Name<'a>, /// Subject public key info. - pub public_key: spki::SubjectPublicKeyInfo<'a>, + pub public_key: SubjectPublicKeyInfo<'a>, /// Request attributes. #[asn1(context_specific = "0", tag_mode = "IMPLICIT")] diff --git a/x501/CHANGELOG.md b/x501/CHANGELOG.md new file mode 100644 index 000000000..d6637e049 --- /dev/null +++ b/x501/CHANGELOG.md @@ -0,0 +1,5 @@ +# 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 new file mode 100644 index 000000000..e1737f7af --- /dev/null +++ b/x501/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "x501" +version = "0.1.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", "X.501"] +readme = "README.md" +rust-version = "1.56" + +[dev-dependencies] +hex-literal = "0.3" + +[dependencies] +der = { version = "=0.6.0-pre.0", features = ["derive", "alloc", "oid"], path = "../der" } + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] diff --git a/x501/LICENSE-APACHE b/x501/LICENSE-APACHE new file mode 100644 index 000000000..78173fa2e --- /dev/null +++ b/x501/LICENSE-APACHE @@ -0,0 +1,201 @@ + 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 new file mode 100644 index 000000000..b9d3eff60 --- /dev/null +++ b/x501/LICENSE-MIT @@ -0,0 +1,25 @@ +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 new file mode 100644 index 000000000..ad12fb0ca --- /dev/null +++ b/x501/README.md @@ -0,0 +1,59 @@ +# [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. + +## 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 diff --git a/x501/src/attr.rs b/x501/src/attr.rs new file mode 100644 index 000000000..706b5e6ee --- /dev/null +++ b/x501/src/attr.rs @@ -0,0 +1,89 @@ +//! Attribute-related definitions as defined in X.501 (and updated by RFC 5280). + +use der::asn1::{Any, ObjectIdentifier, SetOfVec}; +use der::{Decodable, Sequence, ValueOrd}; + +/// X.501 `AttributeType` as defined in [RFC 5280 Appendix A.1]. +/// +/// ```text +/// AttributeType ::= OBJECT IDENTIFIER +/// ``` +/// +/// [RFC 5280 Appendix A.1]: https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1 +pub type AttributeType = ObjectIdentifier; + +/// X.501 `AttributeValue` as defined in [RFC 5280 Appendix A.1]. +/// +/// ```text +/// AttributeValue ::= ANY +/// ``` +/// +/// [RFC 5280 Appendix A.1]: https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1 +pub type AttributeValue<'a> = Any<'a>; + +/// X.501 `Attribute` as defined in [RFC 5280 Appendix A.1]. +/// +/// ```text +/// Attribute ::= SEQUENCE { +/// type AttributeType, +/// values SET OF AttributeValue -- at least one value is required +/// } +/// ``` +/// +/// Note that [RFC 2986 Section 4] defines a constrained version of this type: +/// +/// ```text +/// Attribute { ATTRIBUTE:IOSet } ::= SEQUENCE { +/// type ATTRIBUTE.&id({IOSet}), +/// values SET SIZE(1..MAX) OF ATTRIBUTE.&Type({IOSet}{@type}) +/// } +/// ``` +/// +/// The unconstrained version should be preferred. +/// +/// [RFC 2986 Section 4]: https://datatracker.ietf.org/doc/html/rfc2986#section-4 +/// [RFC 5280 Appendix A.1]: https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1 +#[derive(Clone, Debug, PartialEq, Eq, Sequence, ValueOrd)] +pub struct Attribute<'a> { + /// Attribute type (OID). + pub kind: AttributeType, + + /// Attribute values. + pub values: SetOfVec>, +} + +impl<'a> TryFrom<&'a [u8]> for Attribute<'a> { + type Error = der::Error; + + fn try_from(bytes: &'a [u8]) -> Result { + Self::from_der(bytes) + } +} + +/// X.501 `Attributes` as defined in [RFC 2986 Section 4]. +/// +/// ```text +/// Attributes { ATTRIBUTE:IOSet } ::= SET OF Attribute{{ IOSet }} +/// ``` +/// +/// [RFC 2986 Section 4]: https://datatracker.ietf.org/doc/html/rfc2986#section-4 +pub type Attributes<'a> = SetOfVec>; + +/// X.501 `AttributeTypeAndValue` as defined in [RFC 5280 Appendix A.1]. +/// +/// ```text +/// AttributeTypeAndValue ::= SEQUENCE { +/// type AttributeType, +/// value AttributeValue +/// } +/// ``` +/// +/// [RFC 5280 Appendix A.1]: https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1 +#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Sequence, ValueOrd)] +pub struct AttributeTypeAndValue<'a> { + /// OID describing the type of the attribute + pub oid: AttributeType, + + /// Value of the attribute + pub value: Any<'a>, +} diff --git a/x501/src/lib.rs b/x501/src/lib.rs new file mode 100644 index 000000000..add9ed332 --- /dev/null +++ b/x501/src/lib.rs @@ -0,0 +1,15 @@ +#![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" +)] +#![forbid(unsafe_code)] +#![warn(missing_docs, rust_2018_idioms)] + +extern crate alloc; + +pub mod attr; +pub mod name; diff --git a/x501/src/name.rs b/x501/src/name.rs new file mode 100644 index 000000000..98a65538c --- /dev/null +++ b/x501/src/name.rs @@ -0,0 +1,58 @@ +//! Name-related definitions as defined in X.501 (and updated by RFC 5280). + +use crate::attr::AttributeTypeAndValue; + +use der::asn1::SetOfVec; + +/// X.501 Name as defined in [RFC 5280 Section 4.1.2.4]. X.501 Name is used to represent distinguished names. +/// +/// ```text +/// Name ::= CHOICE { rdnSequence RDNSequence } +/// ``` +/// +/// [RFC 5280 Section 4.1.2.4]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4 +pub type Name<'a> = RdnSequence<'a>; + +/// X.501 RDNSequence as defined in [RFC 5280 Section 4.1.2.4]. +/// +/// ```text +/// RDNSequence ::= SEQUENCE OF RelativeDistinguishedName +/// ``` +/// +/// [RFC 5280 Section 4.1.2.4]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4 +pub type RdnSequence<'a> = alloc::vec::Vec>; + +/// X.501 DistinguishedName as defined in [RFC 5280 Section 4.1.2.4]. +/// +/// ```text +/// DistinguishedName ::= RDNSequence +/// ``` +/// +/// [RFC 5280 Section 4.1.2.4]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4 +pub type DistinguishedName<'a> = RdnSequence<'a>; + +/// RelativeDistinguishedName as defined in [RFC 5280 Section 4.1.2.4]. +/// +/// ```text +/// RelativeDistinguishedName ::= SET SIZE (1..MAX) OF AttributeTypeAndValue +/// ``` +/// +/// Note that we follow the more common definition above. This technically +/// differs from the definition in X.501, which is: +/// +/// ```text +/// RelativeDistinguishedName ::= SET SIZE (1..MAX) OF AttributeTypeAndDistinguishedValue +/// +/// AttributeTypeAndDistinguishedValue ::= SEQUENCE { +/// type ATTRIBUTE.&id ({SupportedAttributes}), +/// value ATTRIBUTE.&Type({SupportedAttributes}{@type}), +/// primaryDistinguished BOOLEAN DEFAULT TRUE, +/// valuesWithContext SET SIZE (1..MAX) OF SEQUENCE { +/// distingAttrValue [0] ATTRIBUTE.&Type ({SupportedAttributes}{@type}) OPTIONAL, +/// contextList SET SIZE (1..MAX) OF Context +/// } OPTIONAL +/// } +/// ``` +/// +/// [RFC 5280 Section 4.1.2.4]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4 +pub type RelativeDistinguishedName<'a> = SetOfVec>; diff --git a/x509/tests/name.rs b/x501/tests/name.rs similarity index 98% rename from x509/tests/name.rs rename to x501/tests/name.rs index afd5ea3d4..b5e616287 100644 --- a/x509/tests/name.rs +++ b/x501/tests/name.rs @@ -2,7 +2,7 @@ //use der::asn1::{SetOf, SequenceOfIter, SequenceOf}; use der::{Decodable, Encodable, Tag, Tagged}; //, Encodable}; use hex_literal::hex; -use x509::{Name, RelativeDistinguishedName}; //, AttributeTypeAndValue; +use x501::name::{Name, RelativeDistinguishedName}; //, AttributeTypeAndValue; #[test] fn decode_name() { diff --git a/x509/Cargo.toml b/x509/Cargo.toml index c1af71c2b..a6f299572 100644 --- a/x509/Cargo.toml +++ b/x509/Cargo.toml @@ -17,6 +17,7 @@ rust-version = "1.56" [dependencies] der = { version = "=0.6.0-pre.0", features = ["derive", "alloc"], path = "../der" } spki = { version = "=0.6.0-pre", path = "../spki" } +x501 = { version = "0.1.0", path = "../x501" } [dev-dependencies] hex-literal = "0.3" diff --git a/x509/src/attribute.rs b/x509/src/attribute.rs deleted file mode 100644 index 5ad09416c..000000000 --- a/x509/src/attribute.rs +++ /dev/null @@ -1,28 +0,0 @@ -//! X.509 Attributes - -use der::{ - asn1::{Any, ObjectIdentifier}, - Sequence, ValueOrd, -}; - -/// Attribute type/value pairs as defined in [RFC 5280 Section 4.1.2.4]. -/// -/// ```text -/// AttributeTypeAndValue ::= SEQUENCE { -/// type AttributeType, -/// value AttributeValue } -/// -/// AttributeType ::= OBJECT IDENTIFIER -/// -/// AttributeValue ::= ANY -- DEFINED BY AttributeType -/// ``` -/// -/// [RFC 5280 Section 4.1.2.4]: https://tools.ietf.org/html/rfc5280#section-4.1.2.4 -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Sequence, ValueOrd)] -pub struct AttributeTypeAndValue<'a> { - /// OID describing the type of the attribute - pub oid: ObjectIdentifier, - - /// Value of the attribute - pub value: Any<'a>, -} diff --git a/x509/src/certificate.rs b/x509/src/certificate.rs index 85ac1cfc4..72cbd2005 100644 --- a/x509/src/certificate.rs +++ b/x509/src/certificate.rs @@ -1,9 +1,11 @@ //! Certificate [`Certificate`] and TBSCertificate [`TBSCertificate`] as defined in RFC 5280 -use crate::{Name, Validity}; +use crate::Validity; + use der::asn1::{BitString, ContextSpecific, ObjectIdentifier, UIntBytes}; use der::{Sequence, TagMode, TagNumber}; use spki::{AlgorithmIdentifier, SubjectPublicKeyInfo}; +use x501::name::Name; /// returns false in support of integer DEFAULT fields set to 0 pub fn default_zero_u8() -> u8 { diff --git a/x509/src/general_name.rs b/x509/src/general_name.rs index 480e7304c..0fbde987b 100644 --- a/x509/src/general_name.rs +++ b/x509/src/general_name.rs @@ -1,10 +1,10 @@ //! GeneralNames as defined in [RFC 5280 Section 4.2.1.6]. -use crate::Name; use alloc::string::ToString; use alloc::vec::Vec; use der::asn1::{Any, ContextSpecific, Ia5String, ObjectIdentifier, OctetString}; use der::{Decodable, DecodeValue, Decoder, ErrorKind, Length, Sequence, TagMode, TagNumber}; +use x501::name::Name; /// OtherName as defined in [RFC 5280 Section 4.2.1.6] in support of the Subject Alternative Name extension. /// diff --git a/x509/src/lib.rs b/x509/src/lib.rs index 746a7da82..84cd41292 100644 --- a/x509/src/lib.rs +++ b/x509/src/lib.rs @@ -14,19 +14,17 @@ extern crate alloc; #[cfg(feature = "std")] extern crate std; -mod attribute; mod certificate; pub mod extensions_utils; mod general_name; pub mod pkix_extensions; pub mod pkix_oids; -mod rdn; mod time; mod validity; pub use crate::{ - attribute::AttributeTypeAndValue, certificate::*, extensions_utils::*, general_name::*, - pkix_extensions::*, pkix_oids::*, rdn::*, time::Time, validity::Validity, + certificate::*, extensions_utils::*, general_name::*, pkix_extensions::*, pkix_oids::*, + time::Time, validity::Validity, }; pub use der::{self, asn1::ObjectIdentifier}; pub use spki::{self, AlgorithmIdentifier, SubjectPublicKeyInfo}; diff --git a/x509/src/pkix_extensions.rs b/x509/src/pkix_extensions.rs index be00ff5a5..9ac5eef4e 100644 --- a/x509/src/pkix_extensions.rs +++ b/x509/src/pkix_extensions.rs @@ -1,9 +1,9 @@ //! Extensions [`Extensions`] as defined in RFC 5280 +use crate::default_zero; use crate::general_name::GeneralName; use crate::general_name::GeneralNames; -use crate::RelativeDistinguishedName; -use crate::{default_zero, AttributeTypeAndValue}; + use alloc::vec::Vec; use der::asn1::{ Any, BitString, ContextSpecific, GeneralizedTime, Ia5String, Null, ObjectIdentifier, @@ -13,6 +13,8 @@ use der::{ Choice, Decodable, DecodeValue, Decoder, Encodable, EncodeValue, Enumerated, ErrorKind, FixedTag, Length, Sequence, Tag, TagMode, TagNumber, }; +use x501::attr::AttributeTypeAndValue; +use x501::name::RelativeDistinguishedName; /// DisplayText as defined in [RFC 5280 Section 4.2.1.4] in support of the Certificate Policies extension. /// diff --git a/x509/src/rdn.rs b/x509/src/rdn.rs deleted file mode 100644 index 3df0c8ff6..000000000 --- a/x509/src/rdn.rs +++ /dev/null @@ -1,35 +0,0 @@ -//! Name-related definitions as defined in RFC 5280. - -use crate::AttributeTypeAndValue; -use der::asn1::SetOf; - -/// RelativeDistinguishedName as defined in [RFC 5280 Section 4.1.2.4]. -/// -/// ```text -/// RelativeDistinguishedName ::= SET SIZE (1..MAX) OF AttributeTypeAndValue -/// ``` -/// -/// [RFC 5280 Section 4.1.2.4]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4 -pub type RelativeDistinguishedName<'a> = SetOf, 3>; -// TODO - make dynamic -//pub type RelativeDistinguishedName<'a> = alloc::vec::Vec>; - -/// RDNSequence as defined in [RFC 5280 Section 4.1.2.4]. -/// -/// ```text -/// RDNSequence ::= SEQUENCE OF RelativeDistinguishedName -/// ``` -/// -/// [RFC 5280 Section 4.1.2.4]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4 -pub type RDNSequence<'a> = alloc::vec::Vec>; - -/// X.501 Name as defined in [RFC 5280 Section 4.1.2.4]. X.501 Name is used to represent distinguished names. -/// -/// ```text -/// Name ::= CHOICE { rdnSequence RDNSequence } -/// ``` -/// -/// [RFC 5280 Section 4.1.2.4]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4 -pub type Name<'a> = RDNSequence<'a>; - -//TODO - Name to string function diff --git a/x509/tests/pkix_extensions.rs b/x509/tests/pkix_extensions.rs index 811216ea4..262147468 100644 --- a/x509/tests/pkix_extensions.rs +++ b/x509/tests/pkix_extensions.rs @@ -2,7 +2,7 @@ use der::asn1::{BitString, UIntBytes, Utf8String}; use der::{Decodable, Encodable, ErrorKind, Length, Tag, Tagged}; use hex_literal::hex; -#[cfg(feature = "alloc")] +use x501::name::Name; use x509::KeyUsage; use x509::*; use x509::{