Skip to content

Commit 9530d64

Browse files
authored
Merge pull request #213 from puiterwijk/esapi_rebase
Rebase on new tss_esapi
2 parents 50d6af5 + 603408c commit 9530d64

File tree

8 files changed

+41
-22
lines changed

8 files changed

+41
-22
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ log = { version = "0.4.8", features = ["serde"] }
3333
pkcs11 = { version = "0.4.0", optional = true }
3434
picky-asn1-der = { version = "0.2.2", optional = true }
3535
picky-asn1 = { version = "0.2.1", optional = true }
36-
tss-esapi = { version = "4.0.5-alpha.1", optional = true }
36+
tss-esapi = { version = "4.0.6-alpha.1", optional = true }
3737
bincode = "1.1.4"
3838
structopt = "0.3.5"
3939
derivative = "2.1.1"

e2e_tests/tests/per_provider/normal_tests/export_public_key.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn check_export_public_possible() -> Result<()> {
7474
bits: 1024,
7575
policy: Policy {
7676
usage_flags: UsageFlags {
77-
sign_hash: false,
77+
sign_hash: true,
7878
verify_hash: false,
7979
sign_message: false,
8080
verify_message: false,

e2e_tests/tests/per_provider/normal_tests/key_attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn wrong_usage_flags() {
7171
usage_flags: UsageFlags {
7272
// Forbid signing
7373
sign_hash: false,
74-
verify_hash: false,
74+
verify_hash: true,
7575
sign_message: false,
7676
verify_message: false,
7777
export: false,

src/providers/tpm_provider/asym_sign.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use log::error;
77
use parsec_interface::operations::psa_algorithm::*;
88
use parsec_interface::operations::{psa_sign_hash, psa_verify_hash};
99
use parsec_interface::requests::{ProviderID, ResponseStatus, Result};
10+
use std::convert::TryFrom;
11+
use tss_esapi::structures::{Auth, Digest};
1012

1113
impl TpmProvider {
1214
pub(super) fn psa_sign_hash_internal(
@@ -46,8 +48,11 @@ impl TpmProvider {
4648
let signature = esapi_context
4749
.sign(
4850
password_context.context,
49-
&password_context.auth_value,
50-
&op.hash,
51+
Some(
52+
Auth::try_from(password_context.auth_value)
53+
.map_err(utils::to_response_status)?,
54+
),
55+
Digest::try_from((*op.hash).clone()).map_err(utils::to_response_status)?,
5156
)
5257
.map_err(|e| {
5358
if crate::utils::GlobalConfig::log_error_details() {
@@ -98,7 +103,11 @@ impl TpmProvider {
98103
let signature = utils::parsec_to_tpm_signature(op.signature, key_attributes, op.alg)?;
99104

100105
let _ = esapi_context
101-
.verify_signature(password_context.context, &op.hash, signature)
106+
.verify_signature(
107+
password_context.context,
108+
Digest::try_from((*op.hash).clone()).map_err(utils::to_response_status)?,
109+
signature,
110+
)
102111
.map_err(utils::to_response_status)?;
103112

104113
Ok(psa_verify_hash::Result {})

src/providers/tpm_provider/key_management.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,20 @@ impl TpmProvider {
8888
.expect("ESAPI Context lock poisoned");
8989

9090
let (key_context, auth_value) = esapi_context
91-
.create_signing_key(utils::parsec_to_tpm_params(attributes)?, AUTH_VAL_LEN)
91+
.create_key(utils::parsec_to_tpm_params(attributes)?, AUTH_VAL_LEN)
9292
.map_err(|e| {
9393
format_error!("Error creating a RSA signing key", e);
9494
utils::to_response_status(e)
9595
})?;
96+
// We hardcode the AUTH_VAL_LEN, so we can assume there is an auth_value
97+
let auth_value = auth_value.unwrap();
9698

9799
insert_password_context(
98100
&mut *store_handle,
99101
key_triple,
100102
PasswordContext {
101103
context: key_context,
102-
auth_value,
104+
auth_value: auth_value.value().to_vec(),
103105
},
104106
attributes,
105107
)?;

src/providers/tpm_provider/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use std::collections::HashSet;
1919
use std::io::ErrorKind;
2020
use std::str::FromStr;
2121
use std::sync::{Arc, Mutex, RwLock};
22-
use tss_esapi::utils::algorithm_specifiers::Cipher;
23-
use tss_esapi::utils::tcti::Tcti;
22+
use tss_esapi::constants::algorithm::{Cipher, HashingAlgorithm};
23+
use tss_esapi::Tcti;
2424
use uuid::Uuid;
2525

2626
mod asym_sign;
@@ -269,9 +269,7 @@ impl TpmProviderBuilder {
269269
.with_root_key_auth_size(ROOT_KEY_AUTH_SIZE)
270270
.with_hierarchy_auth(hierarchy_auth)
271271
.with_hierarchy(tss_esapi::utils::Hierarchy::Owner)
272-
.with_session_hash_alg(
273-
tss_esapi::utils::algorithm_specifiers::HashingAlgorithm::Sha256.into(),
274-
)
272+
.with_session_hash_alg(HashingAlgorithm::Sha256.into())
275273
.with_default_context_cipher(default_cipher)
276274
.build()
277275
.map_err(|e| {

src/providers/tpm_provider/utils.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ use picky_asn1_x509::RSAPublicKey;
1010
use serde::{Deserialize, Serialize};
1111
use std::convert::TryInto;
1212
use tss_esapi::abstraction::transient::KeyParams;
13-
use tss_esapi::response_code::{Error, Tss2ResponseCodeKind};
14-
use tss_esapi::utils::algorithm_specifiers::{EllipticCurve, HashingAlgorithm};
13+
use tss_esapi::constants::algorithm::{EllipticCurve, HashingAlgorithm};
14+
use tss_esapi::constants::response_code::Tss2ResponseCodeKind;
1515
use tss_esapi::utils::{AsymSchemeUnion, PublicKey, Signature, SignatureData, TpmsContext};
16+
use tss_esapi::Error;
1617
use zeroize::Zeroizing;
1718
const PUBLIC_EXPONENT: [u8; 3] = [0x01, 0x00, 0x01];
1819

@@ -99,11 +100,20 @@ pub fn parsec_to_tpm_params(attributes: Attributes) -> Result<KeyParams> {
99100
x @ 1024 | x @ 2048 | x @ 3072 | x @ 4096 => x.try_into().unwrap(), // will not fail on the matched values
100101
_ => return Err(ResponseStatus::PsaErrorInvalidArgument),
101102
};
102-
Ok(KeyParams::Rsa {
103-
size,
104-
scheme: convert_asym_scheme_to_tpm(attributes.policy.permitted_algorithms)?,
105-
pub_exponent: 0,
106-
})
103+
if attributes.is_encrypt_permitted() || attributes.is_decrypt_permitted() {
104+
Ok(KeyParams::RsaEncrypt {
105+
size,
106+
pub_exponent: 0,
107+
})
108+
} else if attributes.is_hash_signable() || attributes.is_hash_verifiable() {
109+
Ok(KeyParams::RsaSign {
110+
size,
111+
scheme: convert_asym_scheme_to_tpm(attributes.policy.permitted_algorithms)?,
112+
pub_exponent: 0,
113+
})
114+
} else {
115+
Err(ResponseStatus::PsaErrorNotSupported)
116+
}
107117
}
108118
Type::EccKeyPair { .. } => Ok(KeyParams::Ecc {
109119
scheme: convert_asym_scheme_to_tpm(attributes.policy.permitted_algorithms)?,

0 commit comments

Comments
 (0)