@@ -8,8 +8,7 @@ use std::collections::HashMap;
8
8
9
9
use base64:: { engine:: general_purpose:: STANDARD , Engine } ;
10
10
use bitwarden_crypto:: {
11
- AsymmetricCryptoKey , CryptoError , EncString , Kdf , KeyDecryptable , KeyEncryptable , MasterKey ,
12
- SigningKey , SymmetricCryptoKey , UnsignedSharedKey , UserKey ,
11
+ AsymmetricCryptoKey , AsymmetricPublicCryptoKey , CryptoError , EncString , Kdf , KeyDecryptable , KeyEncryptable , MasterKey , SignatureAlgorithm , SignedPublicKeyOwnershipClaim , SigningKey , SymmetricCryptoKey , UnsignedSharedKey , UserKey
13
12
} ;
14
13
use schemars:: JsonSchema ;
15
14
use serde:: { Deserialize , Serialize } ;
@@ -18,7 +17,7 @@ use {tsify_next::Tsify, wasm_bindgen::prelude::*};
18
17
19
18
use crate :: {
20
19
client:: { encryption_settings:: EncryptionSettingsError , LoginMethod , UserLoginMethod } ,
21
- key_management:: SymmetricKeyId ,
20
+ key_management:: { AsymmetricKeyId , SymmetricKeyId } ,
22
21
Client , NotAuthenticatedError , VaultLockedError , WrongPasswordError ,
23
22
} ;
24
23
@@ -558,27 +557,47 @@ pub(super) fn verify_asymmetric_keys(
558
557
#[ serde( rename_all = "camelCase" , deny_unknown_fields) ]
559
558
#[ cfg_attr( feature = "uniffi" , derive( uniffi:: Record ) ) ]
560
559
#[ cfg_attr( feature = "wasm" , derive( Tsify ) , tsify( into_wasm_abi, from_wasm_abi) ) ]
561
- pub struct MakeSigningKeysResponse {
560
+ pub struct MakeUserSigningKeysResponse {
562
561
/// The verifying key
563
562
verifying_key : String ,
564
563
/// Signing key, encrypted with a symmetric key (user key, org key)
565
564
signing_key : EncString ,
565
+
566
+ /// A signed object claiming ownership of a public key. This ties the public key to the signature key
567
+ signed_public_key_ownership_claim : String ,
566
568
}
567
569
568
- pub fn make_signing_keys ( wrapping_key : String ) -> Result < MakeSigningKeysResponse , CryptoError > {
569
- let wrapping_key = SymmetricCryptoKey :: try_from ( wrapping_key) ?;
570
+ /// Makes a new set of signing keys for a user. This also creates a signed public-key ownership claim for the currently used public key.
571
+ #[ allow( deprecated) ]
572
+ pub fn make_user_signing_keys ( client : & Client ) -> Result < MakeUserSigningKeysResponse , CryptoError > {
573
+ let key_store = client. internal . get_key_store ( ) ;
574
+ let ctx = key_store. context ( ) ;
575
+ let public_key = ctx
576
+ . dangerous_get_asymmetric_key ( AsymmetricKeyId :: UserPrivateKey )
577
+ . map_err ( |_| CryptoError :: InvalidKey ) ?
578
+ . to_public_der ( ) ?;
579
+ let public_key = AsymmetricPublicCryptoKey :: from_der ( & public_key)
580
+ . map_err ( |_| CryptoError :: InvalidKey ) ?;
581
+
582
+ let wrapping_key = ctx
583
+ . dangerous_get_symmetric_key ( SymmetricKeyId :: User )
584
+ . map_err ( |_| CryptoError :: InvalidKey ) ?;
570
585
let signature_keypair = SigningKey :: make_ed25519 ( ) . unwrap ( ) ;
571
586
// This needs to be changed to use the correct cose content format before rolling out to real
572
587
// accounts
573
588
let encrypted_signing_key = signature_keypair
574
- . to_cose ( ) ?
575
- . encrypt_with_key ( & wrapping_key) ?;
589
+ . to_cose ( ) ?;
576
590
let serialized_verifying_key = signature_keypair. to_verifying_key ( ) . to_cose ( ) ?;
577
591
let serialized_verifying_key_b64 = STANDARD . encode ( serialized_verifying_key) ;
592
+ let signed_public_key_ownership_claim = SignedPublicKeyOwnershipClaim :: make_claim_with_key (
593
+ & public_key,
594
+ & signature_keypair,
595
+ ) ?;
578
596
579
- Ok ( MakeSigningKeysResponse {
597
+ Ok ( MakeUserSigningKeysResponse {
580
598
verifying_key : serialized_verifying_key_b64,
581
- signing_key : encrypted_signing_key,
599
+ signing_key : encrypted_signing_key. encrypt_with_key ( wrapping_key) ?,
600
+ signed_public_key_ownership_claim : STANDARD . encode ( signed_public_key_ownership_claim. as_bytes ( ) ) ,
582
601
} )
583
602
}
584
603
@@ -867,14 +886,6 @@ mod tests {
867
886
assert ! ( !private_key. is_empty( ) ) ;
868
887
}
869
888
870
- #[ test]
871
- fn test_make_signing_keys ( ) {
872
- let user_key = SymmetricCryptoKey :: make_aes256_cbc_hmac_key ( ) ;
873
- let response = make_signing_keys ( user_key. to_base64 ( ) ) . unwrap ( ) ;
874
- assert ! ( !response. verifying_key. is_empty( ) ) ;
875
- let _: Vec < u8 > = response. signing_key . decrypt_with_key ( & user_key) . unwrap ( ) ;
876
- }
877
-
878
889
#[ test]
879
890
fn test_verify_asymmetric_keys_success ( ) {
880
891
let ( user_key, key_pair) = setup_asymmetric_keys_test ( ) ;
0 commit comments