Skip to content

Commit ea2c52f

Browse files
committed
Add key attestation operations
This commit adds the types for the new key attestation operations and their conversions to/from protobuf. Signed-off-by: Ionut Mihalcea <[email protected]>
1 parent e5b7f17 commit ea2c52f

12 files changed

+1071
-15
lines changed

src/operations/attest_key.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2021 Contributors to the Parsec project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
//! # AttestKey operation
4+
//!
5+
//! Produce an attestation token as proof that the given
6+
//! key was produced and is stored in the hardware backend.
7+
use derivative::Derivative;
8+
use zeroize::Zeroizing;
9+
10+
/// Native operation for key attestation
11+
#[derive(Derivative)]
12+
#[derivative(Debug)]
13+
#[non_exhaustive]
14+
pub enum Operation {
15+
/// Attestation via TPM 2.0 ActivateCredential operation
16+
ActivateCredential {
17+
/// Name of key to be attested
18+
attested_key_name: String,
19+
/// Blob of data representing the encrypted credential
20+
#[derivative(Debug = "ignore")]
21+
credential_blob: Zeroizing<Vec<u8>>,
22+
/// Blob of data representing the encrypted secret
23+
#[derivative(Debug = "ignore")]
24+
secret: Zeroizing<Vec<u8>>,
25+
/// Name of key to be used for attesting
26+
attesting_key_name: Option<String>,
27+
},
28+
}
29+
30+
/// Native result of key attestation
31+
#[derive(Derivative)]
32+
#[derivative(Debug)]
33+
#[non_exhaustive]
34+
pub enum Result {
35+
/// Result of attestation via TPM 2.0 ActivateCredential operation
36+
ActivateCredential {
37+
/// Decrypted credential
38+
#[derivative(Debug = "ignore")]
39+
credential: Zeroizing<Vec<u8>>,
40+
},
41+
}

src/operations/mod.rs

+40
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub mod delete_client;
3333
pub mod list_clients;
3434
pub mod psa_generate_random;
3535
pub mod psa_raw_key_agreement;
36+
pub mod attest_key;
37+
pub mod prepare_key_attestation;
3638

3739
pub use psa_crypto::types::algorithm as psa_algorithm;
3840
pub use psa_crypto::types::key as psa_key_attributes;
@@ -91,6 +93,10 @@ pub enum NativeOperation {
9193
PsaSignMessage(psa_sign_message::Operation),
9294
/// PsaVerifyMessage operation
9395
PsaVerifyMessage(psa_verify_message::Operation),
96+
/// AttestKey operation
97+
AttestKey(attest_key::Operation),
98+
/// PrepareKeyAttestation operation
99+
PrepareKeyAttestation(prepare_key_attestation::Operation),
94100
}
95101

96102
impl NativeOperation {
@@ -121,6 +127,8 @@ impl NativeOperation {
121127
NativeOperation::PsaRawKeyAgreement(_) => Opcode::PsaRawKeyAgreement,
122128
NativeOperation::PsaSignMessage(_) => Opcode::PsaSignMessage,
123129
NativeOperation::PsaVerifyMessage(_) => Opcode::PsaVerifyMessage,
130+
NativeOperation::AttestKey(_) => Opcode::AttestKey,
131+
NativeOperation::PrepareKeyAttestation(_) => Opcode::PrepareKeyAttestation,
124132
}
125133
}
126134
}
@@ -177,6 +185,10 @@ pub enum NativeResult {
177185
PsaSignMessage(psa_sign_message::Result),
178186
/// PsaVerifyMessage result
179187
PsaVerifyMessage(psa_verify_message::Result),
188+
/// AttestKey result
189+
AttestKey(attest_key::Result),
190+
/// AttestKey result
191+
PrepareKeyAttestation(prepare_key_attestation::Result),
180192
}
181193

182194
impl NativeResult {
@@ -207,6 +219,8 @@ impl NativeResult {
207219
NativeResult::PsaRawKeyAgreement(_) => Opcode::PsaRawKeyAgreement,
208220
NativeResult::PsaSignMessage(_) => Opcode::PsaSignMessage,
209221
NativeResult::PsaVerifyMessage(_) => Opcode::PsaVerifyMessage,
222+
NativeResult::AttestKey(_) => Opcode::AttestKey,
223+
NativeResult::PrepareKeyAttestation(_) => Opcode::PrepareKeyAttestation,
210224
}
211225
}
212226
}
@@ -367,22 +381,36 @@ impl From<psa_hash_compare::Operation> for NativeOperation {
367381
NativeOperation::PsaHashCompare(op)
368382
}
369383
}
384+
370385
impl From<psa_raw_key_agreement::Operation> for NativeOperation {
371386
fn from(op: psa_raw_key_agreement::Operation) -> Self {
372387
NativeOperation::PsaRawKeyAgreement(op)
373388
}
374389
}
390+
375391
impl From<psa_sign_message::Operation> for NativeOperation {
376392
fn from(op: psa_sign_message::Operation) -> Self {
377393
NativeOperation::PsaSignMessage(op)
378394
}
379395
}
396+
380397
impl From<psa_verify_message::Operation> for NativeOperation {
381398
fn from(op: psa_verify_message::Operation) -> Self {
382399
NativeOperation::PsaVerifyMessage(op)
383400
}
384401
}
385402

403+
impl From<attest_key::Operation> for NativeOperation {
404+
fn from(op: attest_key::Operation) -> Self {
405+
NativeOperation::AttestKey(op)
406+
}
407+
}
408+
impl From<prepare_key_attestation::Operation> for NativeOperation {
409+
fn from(op: prepare_key_attestation::Operation) -> Self {
410+
NativeOperation::PrepareKeyAttestation(op)
411+
}
412+
}
413+
386414
impl From<list_providers::Result> for NativeResult {
387415
fn from(op: list_providers::Result) -> Self {
388416
NativeResult::ListProviders(op)
@@ -526,3 +554,15 @@ impl From<psa_verify_message::Result> for NativeResult {
526554
NativeResult::PsaVerifyMessage(op)
527555
}
528556
}
557+
558+
impl From<attest_key::Result> for NativeResult {
559+
fn from(op: attest_key::Result) -> Self {
560+
NativeResult::AttestKey(op)
561+
}
562+
}
563+
564+
impl From<prepare_key_attestation::Result> for NativeResult {
565+
fn from(op: prepare_key_attestation::Result) -> Self {
566+
NativeResult::PrepareKeyAttestation(op)
567+
}
568+
}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2021 Contributors to the Parsec project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
//! # PrepareKeyAttestation operation
4+
//!
5+
//! Produce any parameters required for the AttestKey operation
6+
use derivative::Derivative;
7+
use zeroize::Zeroizing;
8+
9+
/// Native operation for retrieving key attestation parameters
10+
#[derive(Debug)]
11+
#[non_exhaustive]
12+
pub enum Operation {
13+
/// Get parameters for TPM 2.0 ActivateCredential operation
14+
ActivateCredential {
15+
/// Name of key to be attested
16+
attested_key_name: String,
17+
/// Name of key to be used for attesting
18+
attesting_key_name: Option<String>,
19+
},
20+
}
21+
22+
/// Native result of retrieving key attestation parameters
23+
#[derive(Derivative)]
24+
#[derivative(Debug)]
25+
#[non_exhaustive]
26+
pub enum Result {
27+
/// Parameters for TPM 2.0 ActivateCredential operation
28+
ActivateCredential {
29+
/// TPM name of key to be attested
30+
#[derivative(Debug = "ignore")]
31+
name: Zeroizing<Vec<u8>>,
32+
/// TPM public key parameters of object to be attested
33+
#[derivative(Debug = "ignore")]
34+
public: Zeroizing<Vec<u8>>,
35+
/// Public part of attesting key
36+
#[derivative(Debug = "ignore")]
37+
attesting_key_pub: Zeroizing<Vec<u8>>,
38+
},
39+
}

0 commit comments

Comments
 (0)