-
Notifications
You must be signed in to change notification settings - Fork 159
cms: Implement types from RFC 6031 - Cryptographic Message Syntax (CMS) Symmetric Key Package Content Type #1952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
callumadair
wants to merge
10
commits into
RustCrypto:master
Choose a base branch
from
callumadair:add-rfc-6031
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
063b192
first implementation of the symmetric key package types
callumadair 765505c
first implementation of the pksc attribute types
callumadair efddb0a
add missing doc comment
callumadair 2635d0e
Accept suggestion for `s_keys`
callumadair e7adeb3
add asn1 type definition for onesymmetrickey
callumadair 3976edc
change min and max in ChallengeFormat to intrefs due their potential …
callumadair 5d1721a
replace Utf8StringRef values with String as appropriate.
callumadair 761fed3
Remove redundant lifetimes as suggested by reviewer
callumadair 6a185bc
fix doc comment with suggestion
callumadair d44073c
add enums for string values using declarative macro provided by Arthu…
callumadair File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,237 @@ | ||
//! SymmetricKeyPackage types | ||
|
||
use alloc::{string::String, vec::Vec}; | ||
use der::{Enumerated, Sequence, asn1::OctetString}; | ||
use x509_cert::attr::Attribute; | ||
|
||
/// The `SymmetricKeyPackage` type is defined in [RFC 6031 Section 2.0]. | ||
/// | ||
/// ```text | ||
/// SymmetricKeyPackage ::= SEQUENCE { | ||
/// version KeyPkgVersion DEFAULT v1, | ||
/// sKeyPkgAttrs [0] SEQUENCE SIZE (1..MAX) OF Attribute | ||
/// {{ SKeyPkgAttributes }} OPTIONAL, | ||
/// sKeys SymmetricKeys, | ||
/// ... } | ||
/// ``` | ||
/// | ||
/// [RFC 6031 Section 2.0]: https://datatracker.ietf.org/doc/html/rfc6031#section-2 | ||
#[derive(Sequence, PartialEq, Eq)] | ||
#[allow(missing_docs)] | ||
pub struct SymmetricKeyPackage { | ||
#[asn1(default = "Default::default")] | ||
pub version: KeyPkgVersion, | ||
#[asn1(context_specific = "0", tag_mode = "IMPLICIT", optional = "true")] | ||
pub s_key_pkg_attrs: Option<Vec<Attribute>>, | ||
pub s_keys: SymmetricKeys, | ||
} | ||
|
||
/// The `SymmetricKeys` type is defined in [RFC 6031 Section 2.0]. | ||
/// | ||
/// ```text | ||
/// SymmetricKeys ::= SEQUENCE SIZE (1..MAX) OF OneSymmetricKey | ||
/// ``` | ||
/// | ||
/// [RFC 6031 Section 2.0]: https://datatracker.ietf.org/doc/html/rfc6031#section-2 | ||
pub type SymmetricKeys = Vec<OneSymmetricKey>; | ||
|
||
/// The `OneSymmetricKey` type is defined in [RFC 6031 Section 2.0]. | ||
/// | ||
/// ```text | ||
/// OneSymmetricKey ::= SEQUENCE { | ||
/// sKeyAttrs SEQUENCE SIZE (1..MAX) OF Attribute | ||
/// {{ SKeyAttributes }} OPTIONAL, | ||
/// sKey OCTET STRING OPTIONAL } | ||
/// ( WITH COMPONENTS { ..., sKeyAttrs PRESENT } | | ||
/// WITH COMPONENTS { ..., sKey PRESENT } ) | ||
/// ``` | ||
/// | ||
/// [RFC 6031 Section 2.0]: https://datatracker.ietf.org/doc/html/rfc6031#section-2 | ||
#[derive(Sequence, PartialEq, Eq)] | ||
#[allow(missing_docs)] | ||
pub struct OneSymmetricKey { | ||
pub s_key_attrs: Vec<Attribute>, | ||
#[asn1(optional = "true")] | ||
pub s_key: Option<OctetString>, | ||
} | ||
|
||
/// The `KeyPkgVersion` type is defined in [RFC 6031 Section 2.0]. | ||
/// | ||
/// ```text | ||
/// KeyPkgVersion ::= INTEGER { v1(1) } ( v1, ... ) | ||
/// ``` | ||
/// [RFC 6031 Section 2.0]: https://datatracker.ietf.org/doc/html/rfc6031#section-2 | ||
#[derive(Default, Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Enumerated)] | ||
#[asn1(type = "INTEGER")] | ||
#[repr(u8)] | ||
#[allow(missing_docs)] | ||
pub enum KeyPkgVersion { | ||
#[default] | ||
V1 = 1, | ||
} | ||
|
||
// todo: determine if all the types below should live in another file such as attr.rs | ||
|
||
/// The `FriendlyName` type is defined in [RFC 6031 Section 3.2.6]. | ||
/// | ||
/// ```text | ||
/// FriendlyName ::= SEQUENCE { | ||
/// friendlyName UTF8String, | ||
/// friendlyNameLangTag UTF8String OPTIONAL } | ||
/// ``` | ||
/// | ||
/// [RFC 6031 Section 3.2.6]: https://datatracker.ietf.org/doc/html/rfc6031#section-3.2.6 | ||
#[derive(Sequence, PartialEq, Eq)] | ||
#[allow(missing_docs)] | ||
pub struct FriendlyName { | ||
pub friendly_name: String, | ||
#[asn1(optional = "true")] | ||
pub friendly_name_lang_tag: Option<String>, | ||
} | ||
|
||
/// The `PSKCAlgorithmParameters` type is defined in [RFC 6031 Section 3.2.7]. | ||
/// | ||
/// ```text | ||
/// PSKCAlgorithmParameters ::= CHOICE { | ||
/// suite UTF8String, | ||
/// challengeFormat [0] ChallengeFormat, | ||
/// responseFormat [1] ResponseFormat, | ||
/// ... } | ||
/// ``` | ||
/// | ||
/// [RFC 6031 Section 3.2.7]: https://datatracker.ietf.org/doc/html/rfc6031#section-3.2.7 | ||
#[derive(Sequence, PartialEq, Eq)] | ||
#[allow(missing_docs)] | ||
pub struct PSKCAlgorithmParameters<'range> { | ||
pub suite: String, | ||
pub challenge_format: ChallengeFormat<'range>, | ||
callumadair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub response_format: ResponseFormat, | ||
} | ||
|
||
/// The `ChallengeFormat` type is defined in [RFC 6031 Section 3.2.7]. | ||
/// | ||
/// ```text | ||
/// ChallengeFormat ::= SEQUENCE { | ||
/// encoding Encoding, | ||
/// checkDigit BOOLEAN DEFAULT FALSE, | ||
/// min INTEGER (0..MAX), | ||
/// max INTEGER (0..MAX), | ||
/// ... } | ||
/// ``` | ||
/// | ||
/// [RFC 6031 Section 3.2.7]: https://datatracker.ietf.org/doc/html/rfc6031#section-3.2.7 | ||
#[derive(Sequence, PartialEq, Eq)] | ||
#[allow(missing_docs)] | ||
pub struct ChallengeFormat<'range> { | ||
pub encoding: Encoding, | ||
#[asn1(default = "Default::default")] | ||
pub check_digit: bool, | ||
pub min: der::asn1::IntRef<'range>, | ||
pub max: der::asn1::IntRef<'range>, | ||
callumadair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/// The `Encoding` type is defined in [RFC 6031 Section 3.2.7]. | ||
/// | ||
/// ```text | ||
/// Encoding ::= UTF8STRING ("DECIMAL" | "HEXADECIMAL" | | ||
/// "ALPHANUMERIC" |"BASE64" |"BINARY") | ||
/// ``` | ||
/// | ||
/// [RFC 6031 Section 3.2.7]: https://datatracker.ietf.org/doc/html/rfc6031#section-3.2.7 | ||
pub type Encoding = String; | ||
|
||
/// The `ResponseFormat` type is defined in [RFC 6031 Section 3.2.7]. | ||
/// | ||
/// ```text | ||
/// ResponseFormat ::= SEQUENCE { | ||
/// encoding Encoding, | ||
/// length INTEGER (0..MAX), | ||
/// checkDigit BOOLEAN DEFAULT FALSE, | ||
/// ... } | ||
/// ``` | ||
/// | ||
/// [RFC 6031 Section 3.2.7]: https://datatracker.ietf.org/doc/html/rfc6031#section-3.2.7 | ||
#[derive(Sequence, PartialEq, Eq)] | ||
#[allow(missing_docs)] | ||
pub struct ResponseFormat { | ||
pub encoding: Encoding, | ||
pub length: u32, | ||
#[asn1(default = "Default::default")] | ||
pub check_digit: bool, | ||
} | ||
|
||
/// The `ValueMac` type is defined in [RFC 6031 Section 3.2.12]. | ||
/// | ||
/// ```text | ||
/// ValueMac ::= SEQUENCE { | ||
/// macAlgorithm UTF8String, | ||
/// mac UTF8String } | ||
/// ``` | ||
/// | ||
/// [RFC 6031 Section 3.2.12]: https://datatracker.ietf.org/doc/html/rfc6031#section-3.2.12 | ||
#[derive(Sequence, PartialEq, Eq)] | ||
#[allow(missing_docs)] | ||
pub struct ValueMac { | ||
pub mac_algorithm: String, | ||
pub mac: String, | ||
} | ||
|
||
/// The `PSKCKeyUsages` type is defined in [RFC 6031 Section 3.3.4]. | ||
/// | ||
/// ```text | ||
/// PSKCKeyUsages ::= SEQUENCE OF PSKCKeyUsage | ||
/// ``` | ||
/// | ||
/// [RFC 6031 Section 3.3.4]: https://datatracker.ietf.org/doc/html/rfc6031#section-3.3.4 | ||
pub type PSKCKeyUsages<'keys_usage> = Vec<PSKCKeyUsage<'keys_usage>>; | ||
callumadair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// The `PSKCKeyUsage` type is defined in [RFC 6031 Section 3.3.4]. | ||
/// | ||
/// ```text | ||
/// PSKCKeyUsage ::= UTF8String ("OTP" | "CR" | "Encrypt" | | ||
/// "Integrity" | "Verify" | "Unlock" | "Decrypt" | | ||
/// "KeyWrap" | "Unwrap" | "Derive" | "Generate") | ||
/// ``` | ||
/// | ||
/// [RFC 6031 Section 3.3.4]: https://datatracker.ietf.org/doc/html/rfc6031#section-3.3.4 | ||
pub type PSKCKeyUsage<'pskc_key_usage> = String; | ||
callumadair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// The `PINPolicy` type is defined in [RFC 6031 Section 3.3.5] | ||
/// | ||
/// ```text | ||
/// PINPolicy ::= SEQUENCE { | ||
/// pinKeyId [0] UTF8String OPTIONAL, | ||
/// pinUsageMode [1] PINUsageMode, | ||
/// maxFailedAttempts [2] INTEGER (0..MAX) OPTIONAL, | ||
/// minLength [3] INTEGER (0..MAX) OPTIONAL, | ||
/// maxLength [4] INTEGER (0..MAX) OPTIONAL, | ||
/// pinEncoding [5] Encoding OPTIONAL } | ||
/// | ||
callumadair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// | ||
/// [RFC 6031 Section 3.3.5]: https://datatracker.ietf.org/doc/html/rfc6031#section-3.3.5 | ||
#[derive(Sequence, PartialEq, Eq)] | ||
#[allow(missing_docs)] | ||
pub struct PINPolicy { | ||
#[asn1(context_specific = "0", tag_mode = "IMPLICIT", optional = "true")] | ||
pub pin_key_id: Option<String>, | ||
#[asn1(context_specific = "1", tag_mode = "IMPLICIT")] | ||
pub pin_usage_mode: PINUsageMode, | ||
#[asn1(context_specific = "2", tag_mode = "IMPLICIT", optional = "true")] | ||
pub max_failed_attempts: Option<u32>, | ||
#[asn1(context_specific = "3", tag_mode = "IMPLICIT", optional = "true")] | ||
pub min_length: Option<u32>, | ||
#[asn1(context_specific = "4", tag_mode = "IMPLICIT", optional = "true")] | ||
pub max_length: Option<u32>, | ||
#[asn1(context_specific = "5", tag_mode = "IMPLICIT", optional = "true")] | ||
pub pin_encoding: Option<Encoding>, | ||
} | ||
|
||
/// The `PINUsageMode` type is defined in [RFC 6031 Section 3.3.5] | ||
/// | ||
/// ```text | ||
/// PINUsageMode ::= UTF8String ("Local" | "Prepend" | "Append" | | ||
/// "Algorithmic") | ||
/// ``` | ||
/// | ||
/// [RFC 6031 Section 3.3.5]: https://datatracker.ietf.org/doc/html/rfc6031#section-3.3.5 | ||
pub type PINUsageMode = String; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.