Links

Keys and Vaults

Ockam Vaults store secret cryptographic keys in hardware and cloud key management systems. These keys remain behind a stricter security boundary and can be used without being revealed.
Ockam Identities, Credentials, and Secure Channels rely on cryptographic proofs of possession of specific secret keys. Ockam Vaults safely store these secret keys in cryptographic hardware and cloud key management systems.

Serialization

1
// The types below that are annotated with #[derive(Encode, Decode)] are
2
// serialized using [CBOR](1). The various annotations and their effects on the
3
// encoding are defined in the [minicbor_derive](3) crate.
4
//
5
// #[derive(Encode, Decode)] on structs and enums implies #[cbor(array)]
6
// and CBOR [array encoding](4). The #[n(..)] annotation specifies the index
7
// position of the field in the CBOR encoded array.
8
//
9
// #[cbor(transparent)] annotation on structs with exactly one field forwards
10
// the respective encode and decode calls to the inner type, i.e. the resulting
11
// CBOR representation will be identical to the one of the inner type.
12
//
13
// [1]: https://www.rfc-editor.org/rfc/rfc8949.html
14
// [2]: https://docs.rs/minicbor/latest/minicbor
15
// [3]: https://docs.rs/minicbor-derive/latest/minicbor_derive/index.html
16
// [4]: https://docs.rs/minicbor-derive/latest/minicbor_derive/index.html#array-encoding
17
use minicbor::{Decode, Encode};

Signatures

Vaults can cryptographically sign data. We support two types of Signatures: EdDSA signatures using Curve 25519 and ECDSA signatures using SHA256 + Curve P-256.
Our preferred signature scheme is EdDSA signatures using Curve 25519 which are also call Ed25519 signatures. ECDSA is only supported because as of this writing Cloud KMS services don't support Ed25519.
1
/// A cryptographic signature.
2
#[derive(Encode, Decode)]
3
pub enum Signature {
4
/// An EdDSA signature using Curve 25519.
5
#[n(0)]
6
EdDSACurve25519(#[n(0)] EdDSACurve25519Signature),
7
8
/// An ECDSA signature using SHA-256 and Curve P-256.
9
#[n(1)]
10
ECDSASHA256CurveP256(#[n(0)] ECDSASHA256CurveP256Signature),
11
}
12
13
/// An EdDSA Signature using Curve25519.
14
///
15
/// - EdDSA Signature as defined [here][1].
16
/// - Curve25519 as defined in [here][2].
17
///
18
/// [1]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-5.pdf
19
/// [2]: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-186.pdf
20
#[derive(Encode, Decode)]
21
#[cbor(transparent)]
22
pub struct EdDSACurve25519Signature(#[cbor(n(0), with = "minicbor::bytes")] pub [u8; 64]);
23
24
/// An ECDSA Signature using SHA256 and Curve P-256.
25
///
26
/// - ECDSA Signature as defined [here][1].
27
/// - SHA256 as defined [here][2].
28
/// - Curve P-256 as defined [here][3].
29
///
30
/// [1]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-5.pdf
31
/// [2]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
32
/// [3]: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-186.pdf
33
#[derive(Encode, Decode)]
34
#[cbor(transparent)]
35
pub struct ECDSASHA256CurveP256Signature(#[cbor(n(0), with = "minicbor::bytes")] pub [u8; 64]);

Public Keys

In addition to VerifyingPublicKeys for the above two signature schemes we also support X25519PublicKeys for ECDH in Ockam Secure Channels using X25519.
1
/// A public key for verifying signatures.
2
#[derive(Encode, Decode)]
3
pub enum VerifyingPublicKey {
4
/// Curve25519 Public Key for verifying EdDSA signatures.
5
#[n(0)]
6
EdDSACurve25519(#[n(0)] EdDSACurve25519PublicKey),
7
8
/// Curve P-256 Public Key for verifying ECDSA SHA256 signatures.
9
#[n(1)]
10
ECDSASHA256CurveP256(#[n(0)] ECDSASHA256CurveP256PublicKey),
11
}
12
13
/// A Curve25519 Public Key that is only used for EdDSA signatures.
14
///
15
/// - EdDSA Signature as defined [here][1] and [here][2].
16
/// - Curve25519 as defined [here][3].
17
///
18
/// [1]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-5.pdf
19
/// [2]: https://ed25519.cr.yp.to/papers.html
20
/// [2]: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-186.pdf
21
#[derive(Encode, Decode)]
22
#[cbor(transparent)]
23
pub struct EdDSACurve25519PublicKey(#[cbor(n(0), with = "minicbor::bytes")] pub [u8; 32]);
24
25
/// A Curve P-256 Public Key that is only used for ECDSA SHA256 signatures.
26
///
27
/// This type only supports the uncompressed form which is 65 bytes and
28
/// has the first byte - 0x04. The uncompressed form is defined [here][1] in
29
/// section 2.3.3.
30
///
31
/// - ECDSA Signature as defined [here][2].
32
/// - SHA256 as defined [here][3].
33
/// - Curve P-256 as defined [here][4].
34
///
35
/// [1]: https://www.secg.org/SEC1-Ver-1.0.pdf
36
/// [2]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-5.pdf
37
/// [3]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
38
/// [4]: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-186.pdf
39
#[derive(Encode, Decode)]
40
#[cbor(transparent)]
41
pub struct ECDSASHA256CurveP256PublicKey(#[cbor(n(0), with = "minicbor::bytes")] pub [u8; 65]);
42
43
/// X25519 Public Key is used for ECDH.
44
///
45
/// - X25519 as defined [here][1].
46
/// - Curve25519 as defined [here][2].
47
///
48
/// [1]: https://datatracker.ietf.org/doc/html/rfc7748
49
/// [2]: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-186.pdf
50
#[derive(Encode, Decode)]
51
#[cbor(transparent)]
52
pub struct X25519PublicKey(#[cbor(n(0), with = "minicbor::bytes")] pub [u8; 32]);

Vaults and Secrets

Three rust traits - VaultForVerifyingSignatures, VaultForSigning, and VaultForSecureChannels define abstract functions that an Ockam Vault implementation can implement to support Ockam Identities, Credentials, and Secure Channels.
Identities and Credentials require VaultForVerifyingSignatures and VaultForSigning while Secure Channels require VaultForSecureChannels.

VaultForVerifyingSignatures

Implementations of VaultForVerifyingSignatures provide two simple and stateless functions that don't require any secrets so they can be usually provided in software.
1
use async_trait::async_trait;
2
3
pub struct Sha256Output([u8; 32]);
4
5
#[async_trait]
6
pub trait VaultForVerifyingSignatures: Send + Sync + 'static {
7
async fn sha256(&self, data: &[u8]) -> Result<Sha256Output>;
8
9
async fn verify_signature(
10
&self,
11
verifying_public_key: &VerifyingPublicKey,
12
data: &[u8],
13
signature: &Signature,
14
) -> Result<bool>;
15
}

VaultForSigning

Implementations of VaultForSigning enable using a secret signing key to sign Credentials, PurposeKeyAttestations, and Identity Change events. The signing key remains inside the tighter security boundary of a KMS or an HSM.
1
use ockam_core::Result;
2
3
/// A handle to a secret inside a vault.
4
pub struct HandleToSecret(Vec<u8>);
5
6
/// A handle to a signing secret key inside a vault.
7
pub enum SigningSecretKeyHandle {
8
/// Curve25519 key that is only used for EdDSA signatures.
9
EdDSACurve25519(HandleToSecret),
10
11
/// Curve P-256 key that is only used for ECDSA SHA256 signatures.
12
ECDSASHA256CurveP256(HandleToSecret),
13
}
14
15
/// An enum to represent the supported types of signing keys.
16
pub enum SigningKeyType {
17
// Curve25519 key that is only used for EdDSA signatures.
18
EdDSACurve25519,
19
20
/// Curve P-256 key that is only used for ECDSA SHA256 signatures.
21
ECDSASHA256CurveP256,
22
}
23
24
#[async_trait]
25
pub trait VaultForSigning: Send + Sync + 'static {
26
async fn sign(
27
&self,
28
signing_secret_key_handle: &SigningSecretKeyHandle,
29
data: &[u8],
30
) -> Result<Signature>;
31
32
async fn generate_signing_secret_key(
33
&self,
34
signing_key_type: SigningKeyType,
35
) -> Result<SigningSecretKeyHandle>;
36
37
async fn get_verifying_public_key(
38
&self,
39
signing_secret_key_handle: &SigningSecretKeyHandle,
40
) -> Result<VerifyingPublicKey>;
41
42
async fn get_secret_key_handle(
43
&self,
44
verifying_public_key: &VerifyingPublicKey,
45
) -> Result<SigningSecretKeyHandle>;
46
47
async fn delete_signing_secret_key(
48
&self,
49
signing_secret_key_handle: SigningSecretKeyHandle,
50
) -> Result<bool>;
51
}

VaultForSecureChannels

Implementations of VaultForSecureChannels enable using a secret X25519 key for ECDH within Ockam Secure Channels. They rely on compile time feature flags to chose between three possible combinations of primitives:
  • OCKAM_XX_25519_AES256_GCM_SHA256 enables Ockam_XX secure channel handshake with AEAD_AES_256_GCM and SHA256. This is our current default.
  • OCKAM_XX_25519_AES128_GCM_SHA256 enables Ockam_XX secure channel handshake with AEAD_AES_128_GCM and SHA256.
  • OCKAM_XX_25519_ChaChaPolyBLAKE2s enables Ockam_XX secure channel handshake with AEAD_CHACHA20_POLY1305 and Blake2s.
1
use cfg_if::cfg_if;
2
use ockam_core::compat::{collections::BTreeMap, vec::Vec};
3
4
/// A handle to X25519 secret key inside a vault.
5
///
6
/// - X25519 as defined [here][1].
7
/// - Curve25519 as defined [here][2].
8
///
9
/// [1]: https://datatracker.ietf.org/doc/html/rfc7748
10
/// [2]: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-186.pdf
11
pub struct X25519SecretKeyHandle(pub HandleToSecret);
12
13
pub struct SecretBufferHandle {
14
pub handle: HandleToSecret,
15
pub length: usize,
16
}
17
18
/// The number of hkdf outputs to produce from the hkdf function.
19
pub enum HKDFNumberOfOutputs {
20
Two,
21
Three,
22
}
23
24
cfg_if! {
25
if #[cfg(feature = "OCKAM_XX_25519_ChaChaPolyBLAKE2s")] {
26
pub struct Blake2sOutput([u8; 32]);
27
pub struct HashOutput(pub Blake2sOutput);
28
29
pub struct Blake2sHkdfOutput(Vec<SecretBufferHandle>);
30
pub struct HkdfOutput(pub Blake2sHkdfOutput);
31
32
pub struct Chacha20Poly1305SecretKeyHandle(pub HandleToSecret);
33
pub struct AeadSecretKeyHandle(pub Chacha20Poly1305SecretKeyHandle);
34
35
} else if #[cfg(feature = "OCKAM_XX_25519_AES128_GCM_SHA256")] {
36
pub struct HashOutput(pub Sha256Output);
37
38
pub struct Sha256HkdfOutput(Vec<SecretBufferHandle>);
39
pub struct HkdfOutput(pub Sha256HkdfOutput);
40
41
pub struct Aes128GcmSecretKeyHandle(pub HandleToSecret);
42
pub struct AeadSecretKeyHandle(pub Aes128GcmSecretKeyHandle);
43
44
} else {
45
// OCKAM_XX_25519_AES256_GCM_SHA256
46
pub struct HashOutput(pub Sha256Output);
47
48
pub struct Sha256HkdfOutput(Vec<SecretBufferHandle>);
49
pub struct HkdfOutput(pub Sha256HkdfOutput);
50
51
pub struct Aes256GcmSecretKeyHandle(pub HandleToSecret);
52
pub struct AeadSecretKeyHandle(pub Aes256GcmSecretKeyHandle);
53
}
54
}
55
56
#[async_trait]
57
pub trait VaultForSecureChannels: Send + Sync + 'static {
58
59
/// [1]: http://www.noiseprotocol.org/noise.html#dh-functions
60
async fn dh(
61
&self,
62
secret_key_handle: &X25519SecretKeyHandle,
63
peer_public_key: &X25519PublicKey,
64
) -> Result<SecretBufferHandle>;
65
66
/// [1]: http://www.noiseprotocol.org/noise.html#hash-functions
67
async fn hash(&self, data: &[u8]) -> Result<HashOutput>;
68
69
/// [1]: http://www.noiseprotocol.org/noise.html#hash-functions
70
async fn hkdf(
71
&self,
72
salt: &SecretBufferHandle,
73
input_key_material: Option<&SecretBufferHandle>,
74
number_of_outputs: HKDFNumberOfOutputs,
75
) -> Result<HkdfOutput>;
76
77
/// AEAD Encrypt
78
/// [1]: http://www.noiseprotocol.org/noise.html#cipher-functions
79
async fn encrypt(
80
&self,
81
secret_key_handle: &AeadSecretKeyHandle,
82
plain_text: &[u8],
83
nonce: &[u8],
84
aad: &[u8],
85
) -> Result<Vec<u8>>;
86
87
/// AEAD Decrypt
88
/// [1]: http://www.noiseprotocol.org/noise.html#cipher-functions
89
async fn decrypt(
90
&self,
91
secret_key_handle: &AeadSecretKeyHandle,
92
cipher_text: &[u8],
93
nonce: &[u8],
94
aad: &[u8],
95
) -> Result<Vec<u8>>;
96
97
async fn generate_ephemeral_x25519_secret_key(&self) -> Result<X25519SecretKeyHandle>;
98
99
async fn delete_ephemeral_x25519_secret_key(
100
&self,
101
secret_key_handle: X25519SecretKeyHandle,
102
) -> Result<bool>;
103
104
async fn get_x25519_public_key(
105
&self,
106
secret_key_handle: &X25519SecretKeyHandle,
107
) -> Result<X25519PublicKey>;
108
109
async fn get_x25519_secret_key_handle(
110
&self,
111
public_key: &X25519PublicKey,
112
) -> Result<X25519SecretKeyHandle>;
113
114
async fn import_secret_buffer(&self, buffer: Vec<u8>) -> Result<SecretBufferHandle>;
115
116
async fn delete_secret_buffer(&self, secret_buffer_handle: SecretBufferHandle) -> Result<bool>;
117
118
async fn convert_secret_buffer_to_aead_key(
119
&self,
120
secret_buffer_handle: SecretBufferHandle,
121
) -> Result<AeadSecretKeyHandle>;
122
123
async fn delete_aead_secret_key(&self, secret_key_handle: AeadSecretKeyHandle) -> Result<bool>;
124
}