@@ -811,20 +811,30 @@ public int run(BIBO bibo, String[] argv) {
811811 // By default we try to change an existing key
812812 boolean replace = true ;
813813
814+ String kdf = PlaintextKeys .kdf_templates .getOrDefault (args .valueOf (OPT_LOCK_KDF ), args .valueOf (OPT_LOCK_KDF ));
815+
816+
817+ // XXX: remove the combined "keys or master" interfaces from PlaintextKeys
818+ final Optional <GPCardKeys > lockKey ;
814819 // Get new key values
815- Optional <GPCardKeys > lockKey = keyFromPlugin (args .valueOf (OPT_LOCK ));
820+ if (args .has (OPT_LOCK )) {
821+ lockKey = keyFromPlugin (args .valueOf (OPT_LOCK ));
822+ } else if (args .has (OPT_LOCK_ENC ) && args .has (OPT_LOCK_MAC ) && args .has (OPT_LOCK_DEK )) {
823+ lockKey = Optional .of (PlaintextKeys .fromKeys (args .valueOf (OPT_LOCK_ENC ).value (), args .valueOf (OPT_LOCK_MAC ).value (), args .valueOf (OPT_LOCK_DEK ).value ()));
824+ } else {
825+ throw new IllegalArgumentException ("Use either --lock or --lock-enc/mac/dek" );
826+ }
816827
817- String kdf = PlaintextKeys .kdf_templates .getOrDefault (args .valueOf (OPT_LOCK_KDF ), args .valueOf (OPT_LOCK_KDF ));
818828 // From provider
819- newKeys = lockKey .
820- orElseGet (() -> PlaintextKeys .fromBytes (args .valueOf (OPT_LOCK_ENC ).value (), args .valueOf (OPT_LOCK_MAC ).value (), args .valueOf (OPT_LOCK_DEK ).value (), HexBytes .v (args .valueOf (OPT_LOCK )).v (), kdf , null , args .valueOf (OPT_NEW_KEY_VERSION )).
821- orElseThrow (() -> new IllegalArgumentException ("Can not lock without keys :)" )));
822-
829+ newKeys = lockKey .orElseThrow (() -> new IllegalArgumentException ("Can not lock without keys :)" ));
823830 if (newKeys instanceof PlaintextKeys ) {
824831 // Adjust the mode and version with plaintext keys
825832 PlaintextKeys pk = (PlaintextKeys ) newKeys ;
826833 List <GPKeyInfo > current = gp .getKeyInfoTemplate ();
827- // By default use key version 1
834+ if (kdf != null ) {
835+ pk .setDiversifier (kdf );
836+ }
837+ // By default, use key version 1
828838 final int keyver ;
829839 if (args .has (OPT_NEW_KEY_VERSION )) {
830840 keyver = args .valueOf (OPT_NEW_KEY_VERSION );
@@ -833,7 +843,7 @@ public int run(BIBO bibo, String[] argv) {
833843 replace = false ;
834844 }
835845 } else {
836- if (current .size () == 0 || gp .getScpKeyVersion () == 255 ) {
846+ if (current .isEmpty () || gp .getScpKeyVersion () == 255 ) {
837847 keyver = 1 ;
838848 replace = false ;
839849 } else {
0 commit comments