@@ -79,6 +79,14 @@ struct PlainDIArgs {
7979 /// Available values: filesystem, tpm.
8080 #[ clap( long) ]
8181 key_ref : String ,
82+
83+ /// Path to the sign key for DI protocol.
84+ #[ clap( long) ]
85+ sign_key_path : Option < String > ,
86+
87+ /// Path to the hmac key for DI protocol.
88+ #[ clap( long) ]
89+ hmac_key_path : Option < String > ,
8290}
8391
8492#[ derive( Args , Debug ) ]
@@ -330,9 +338,10 @@ async fn main() -> Result<()> {
330338 }
331339 iface = args. iface ;
332340
333- keyref = KeyReference :: str_key ( args. key_ref )
334- . await
335- . context ( "Error determining key for DI" ) ?;
341+ keyref =
342+ KeyReference :: str_key ( args. key_ref , args. sign_key_path , args. hmac_key_path )
343+ . await
344+ . context ( "Error determining key for DI" ) ?;
336345 client = ServiceClient :: new ( ProtocolVersion :: Version1_1 , & url) ;
337346 }
338347 Commands :: NoPlainDI ( args) => {
@@ -687,6 +696,10 @@ impl KeyReference {
687696 let sign_key_path = env:: var ( "DI_SIGN_KEY_PATH" ) . context ( "No DI sign key path set" ) ?;
688697 let hmac_key_path = env:: var ( "DI_HMAC_KEY_PATH" ) . context ( "No DI HMAC key path set" ) ?;
689698
699+ KeyReference :: key_filesystem ( sign_key_path, hmac_key_path) . await
700+ }
701+
702+ async fn key_filesystem ( sign_key_path : String , hmac_key_path : String ) -> Result < Self > {
690703 let sign_key = fs:: read ( & sign_key_path)
691704 . with_context ( || format ! ( "Error reading sign key from {}" , & sign_key_path) ) ?;
692705 let hmac_key = fs:: read ( & hmac_key_path)
@@ -709,10 +722,21 @@ impl KeyReference {
709722 }
710723 }
711724
712- async fn str_key ( key : String ) -> Result < Self > {
725+ async fn str_key (
726+ key : String ,
727+ sign_key_path : Option < String > ,
728+ hmac_key_path : Option < String > ,
729+ ) -> Result < Self > {
713730 let key_storage_type = KeyStorageType :: from_str ( & key) . context ( "Invalid sroage type" ) ?;
714731 match key_storage_type {
715- KeyStorageType :: FileSystem => KeyReference :: env_key_filesystem ( ) . await ,
732+ KeyStorageType :: FileSystem => match ( sign_key_path, hmac_key_path) {
733+ ( Some ( _) , None ) => bail ! ( "--sign-key-path is requird for filesystem key reference" ) ,
734+ ( None , Some ( _) ) => bail ! ( "--hmac-key-path is requird for filesystem key reference" ) ,
735+ ( None , None ) => bail ! (
736+ "--sign-key-path and --hmac-key-path are requird for filesystem key reference"
737+ ) ,
738+ ( Some ( s) , Some ( h) ) => KeyReference :: key_filesystem ( s, h) . await ,
739+ } ,
716740 _ => bail ! ( format!( "Unsupported key storage type {key_storage_type:?}" ) ) ,
717741 }
718742 }
0 commit comments