@@ -32,7 +32,8 @@ use compact_jwt::traits::JwsSignable;
32
32
use compact_jwt:: Jws ;
33
33
#[ cfg( feature = "broker" ) ]
34
34
use kanidm_hsm_crypto:: {
35
- BoxedDynTpm , IdentityKey , KeyAlgorithm , LoadableIdentityKey , MachineKey , SealedData , Tpm ,
35
+ BoxedDynTpm , IdentityKey , KeyAlgorithm , LoadableIdentityKey , MachineKey , PinValue , SealedData ,
36
+ Tpm ,
36
37
} ;
37
38
#[ cfg( feature = "broker" ) ]
38
39
use kanidm_hsm_crypto:: { LoadableMsOapxbcRsaKey , MsOapxbcRsaKey } ;
@@ -1904,7 +1905,7 @@ impl BrokerClientApplication {
1904
1905
) -> Result < IdentityKey , MsalError > {
1905
1906
match & self . cert_key {
1906
1907
Some ( cert_key) => {
1907
- let cert_key = tpm. identity_key_load ( machine_key, cert_key)
1908
+ let cert_key = tpm. identity_key_load ( machine_key, None , cert_key)
1908
1909
. map_err ( |e| {
1909
1910
MsalError :: TPMFail ( format ! ( "Failed to load IdentityKey: {:?}" , e) )
1910
1911
} ) ?;
@@ -1956,7 +1957,7 @@ impl BrokerClientApplication {
1956
1957
. await ?;
1957
1958
// Create the transport and cert keys
1958
1959
let loadable_cert_key = tpm
1959
- . identity_key_create ( machine_key, KeyAlgorithm :: Rsa2048 )
1960
+ . identity_key_create ( machine_key, None , KeyAlgorithm :: Rsa2048 )
1960
1961
. map_err ( |e| MsalError :: TPMFail ( format ! ( "Failed creating certificate key: {:?}" , e) ) ) ?;
1961
1962
let loadable_transport_key = tpm
1962
1963
. msoapxbc_rsa_key_create ( machine_key)
@@ -1966,6 +1967,7 @@ impl BrokerClientApplication {
1966
1967
// Create the CSR
1967
1968
let csr_der = match tpm. identity_key_certificate_request (
1968
1969
machine_key,
1970
+ None ,
1969
1971
& loadable_cert_key,
1970
1972
"7E980AD9-B86D-4306-9425-9AC066FB014A" ,
1971
1973
) {
@@ -2009,6 +2011,7 @@ impl BrokerClientApplication {
2009
2011
2010
2012
let new_loadable_cert_key = match tpm. identity_key_associate_certificate (
2011
2013
machine_key,
2014
+ None ,
2012
2015
& loadable_cert_key,
2013
2016
& cert
2014
2017
. to_der ( )
@@ -2801,24 +2804,26 @@ impl BrokerClientApplication {
2801
2804
/// acquire_token_by_username_password_for_device_enrollment
2802
2805
/// or acquire_token_by_device_flow.
2803
2806
///
2804
- /// * `key` - An optional existing LoadableIdentityKey, if not provided
2805
- /// one will be created.
2806
- ///
2807
2807
/// * `tpm` - The tpm object.
2808
2808
///
2809
2809
/// * `machine_key` - The TPM MachineKey associated with this application.
2810
2810
///
2811
+ /// * `pin` - The PIN code which will be used to unlock the key.
2812
+ ///
2811
2813
/// # Returns
2812
2814
/// * Success: Either the existing LoadableIdentityKey, or a new created
2813
2815
/// key if none was provided.
2814
2816
/// * Failure: An MsalError, indicating the failure.
2815
2817
pub async fn provision_hello_for_business_key (
2816
2818
& self ,
2817
2819
token : & UserToken ,
2818
- key : Option < LoadableIdentityKey > ,
2819
2820
tpm : & mut BoxedDynTpm ,
2820
2821
machine_key : & MachineKey ,
2822
+ pin : & str ,
2821
2823
) -> Result < LoadableIdentityKey , MsalError > {
2824
+ let pin = PinValue :: new ( pin)
2825
+ . map_err ( |e| MsalError :: TPMFail ( format ! ( "Failed setting pin value: {:?}" , e) ) ) ?;
2826
+
2822
2827
// Discover the KeyProvisioningService
2823
2828
let access_token = match & token. access_token {
2824
2829
Some ( access_token) => access_token. clone ( ) ,
@@ -2864,17 +2869,14 @@ impl BrokerClientApplication {
2864
2869
)
2865
2870
. await ?;
2866
2871
2867
- // Use an existing key, or create a new hello key (using the TPM)
2868
- let loadable_win_hello_key = match key {
2869
- Some ( loadable_win_hello_key) => loadable_win_hello_key,
2870
- None => tpm
2871
- . identity_key_create ( machine_key, KeyAlgorithm :: Rsa2048 )
2872
- . map_err ( |e| {
2873
- MsalError :: TPMFail ( format ! ( "Failed creating Windows Hello Key: {:?}" , e) )
2874
- } ) ?,
2875
- } ;
2872
+ // Create a new hello key (using the TPM)
2873
+ let loadable_win_hello_key = tpm
2874
+ . identity_key_create ( machine_key, Some ( & pin) , KeyAlgorithm :: Rsa2048 )
2875
+ . map_err ( |e| {
2876
+ MsalError :: TPMFail ( format ! ( "Failed creating Windows Hello Key: {:?}" , e) )
2877
+ } ) ?;
2876
2878
let win_hello_key = tpm
2877
- . identity_key_load ( machine_key, & loadable_win_hello_key)
2879
+ . identity_key_load ( machine_key, Some ( & pin ) , & loadable_win_hello_key)
2878
2880
. map_err ( |e| {
2879
2881
MsalError :: TPMFail ( format ! ( "Failed loading Windows Hello Key: {:?}" , e) )
2880
2882
} ) ?;
@@ -2946,6 +2948,8 @@ impl BrokerClientApplication {
2946
2948
///
2947
2949
/// * `machine_key` - The TPM MachineKey associated with this application.
2948
2950
///
2951
+ /// * `pin` - The PIN code required to unlock the key.
2952
+ ///
2949
2953
/// # Returns
2950
2954
/// * Success: A UserToken containing an access_token.
2951
2955
/// * Failure: An MsalError, indicating the failure.
@@ -2956,9 +2960,19 @@ impl BrokerClientApplication {
2956
2960
scopes : Vec < & str > ,
2957
2961
tpm : & mut BoxedDynTpm ,
2958
2962
machine_key : & MachineKey ,
2963
+ pin : & str ,
2959
2964
) -> Result < UserToken , MsalError > {
2965
+ let pin = PinValue :: new ( pin)
2966
+ . map_err ( |e| MsalError :: TPMFail ( format ! ( "Failed setting pin value: {:?}" , e) ) ) ?;
2967
+
2960
2968
let prt = self
2961
- . acquire_user_prt_by_hello_for_business_key_internal ( username, key, tpm, machine_key)
2969
+ . acquire_user_prt_by_hello_for_business_key_internal (
2970
+ username,
2971
+ key,
2972
+ tpm,
2973
+ machine_key,
2974
+ & pin,
2975
+ )
2962
2976
. await ?;
2963
2977
let transport_key = self . transport_key ( tpm, machine_key) ?;
2964
2978
let session_key = prt. session_key ( ) ?;
@@ -2984,10 +2998,11 @@ impl BrokerClientApplication {
2984
2998
loadable_key : & LoadableIdentityKey ,
2985
2999
tpm : & mut BoxedDynTpm ,
2986
3000
machine_key : & MachineKey ,
3001
+ pin : & PinValue ,
2987
3002
) -> Result < Jws , MsalError > {
2988
3003
let nonce = self . request_nonce ( ) . await ?;
2989
3004
let key = tpm
2990
- . identity_key_load ( machine_key, loadable_key)
3005
+ . identity_key_load ( machine_key, Some ( pin ) , loadable_key)
2991
3006
. map_err ( |e| MsalError :: TPMFail ( format ! ( "{:?}" , e) ) ) ?;
2992
3007
let win_hello_pub_der = tpm. identity_key_public_as_der ( & key) . map_err ( |e| {
2993
3008
MsalError :: TPMFail ( format ! ( "Failed getting Windows Hello Key as der: {:?}" , e) )
@@ -3056,9 +3071,10 @@ impl BrokerClientApplication {
3056
3071
key : & LoadableIdentityKey ,
3057
3072
tpm : & mut BoxedDynTpm ,
3058
3073
machine_key : & MachineKey ,
3074
+ pin : & PinValue ,
3059
3075
) -> Result < PrimaryRefreshToken , MsalError > {
3060
3076
let jwt = self
3061
- . build_jwt_by_hello_for_business_key ( username, key, tpm, machine_key)
3077
+ . build_jwt_by_hello_for_business_key ( username, key, tpm, machine_key, pin )
3062
3078
. await ?;
3063
3079
let signed_jwt = self . sign_jwt ( & jwt, tpm, machine_key) . await ?;
3064
3080
@@ -3078,6 +3094,8 @@ impl BrokerClientApplication {
3078
3094
///
3079
3095
/// * `machine_key` - The TPM MachineKey associated with this application.
3080
3096
///
3097
+ /// * `pin` - The PIN code required to unlock the key.
3098
+ ///
3081
3099
/// # Returns
3082
3100
/// * Success: An encrypted PrimaryRefreshToken, containing a refresh_token and tgt.
3083
3101
/// * Failure: An MsalError, indicating the failure.
@@ -3087,9 +3105,19 @@ impl BrokerClientApplication {
3087
3105
key : & LoadableIdentityKey ,
3088
3106
tpm : & mut BoxedDynTpm ,
3089
3107
machine_key : & MachineKey ,
3108
+ pin : & str ,
3090
3109
) -> Result < SealedData , MsalError > {
3110
+ let pin = PinValue :: new ( pin)
3111
+ . map_err ( |e| MsalError :: TPMFail ( format ! ( "Failed setting pin value: {:?}" , e) ) ) ?;
3112
+
3091
3113
let prt = self
3092
- . acquire_user_prt_by_hello_for_business_key_internal ( username, key, tpm, machine_key)
3114
+ . acquire_user_prt_by_hello_for_business_key_internal (
3115
+ username,
3116
+ key,
3117
+ tpm,
3118
+ machine_key,
3119
+ & pin,
3120
+ )
3093
3121
. await ?;
3094
3122
let transport_key = self . transport_key ( tpm, machine_key) ?;
3095
3123
self . seal_user_prt ( & prt, tpm, & transport_key)
0 commit comments