@@ -119,11 +119,15 @@ def parse_args():
119
119
)
120
120
parser_generate_key .add_argument (
121
121
'-p' , '--pin-policy' , type = PinPolicy .from_str (PinPolicy ),
122
- help = 'YubiKey PIN policy' , default = PinPolicy .ONCE , choices = list (PinPolicy ),
122
+ help = 'YubiKey PIN policy' , default = PinPolicy .DEFAULT , choices = list (PinPolicy ),
123
123
)
124
124
parser_generate_key .add_argument (
125
125
'-t' , '--touch-policy' , type = TouchPolicy .from_str (TouchPolicy ),
126
- help = 'YubiKey touch policy' , default = TouchPolicy .ALWAYS , choices = list (TouchPolicy ),
126
+ help = 'YubiKey touch policy' , default = TouchPolicy .DEFAULT , choices = list (TouchPolicy ),
127
+ )
128
+ parser_generate_key .add_argument (
129
+ '-m' , '--prompt-management-key' , action = 'store_true' ,
130
+ help = 'Prompt for management key' ,
127
131
)
128
132
129
133
# "upload-key" action
@@ -154,9 +158,13 @@ def parse_args():
154
158
help = 'Token lifetime, in seconds' ,
155
159
)
156
160
parser_token .add_argument (
157
- '-t' , '--token-type' , type = TokenType , choices = list (TokenType ),
161
+ '-t' , '--token-type' , type = TokenType . from_str ( TokenType ) , choices = list (TokenType ),
158
162
help = 'Token type, in seconds' , default = TokenType .ACCESS ,
159
163
)
164
+ parser_token .add_argument (
165
+ '-m' , '--prompt-management-key' , action = 'store_true' ,
166
+ help = 'Prompt for management key' ,
167
+ )
160
168
161
169
return parser .parse_args ()
162
170
@@ -167,22 +175,22 @@ def get_yubikey():
167
175
return YubiKey (dev .driver )
168
176
169
177
170
- def authenticate (yubikey : YubiKey ):
178
+ def authenticate (yubikey : YubiKey , prompt_management_key : bool ):
171
179
""" Authenticates user to the YubiKey """
172
180
print ('Authenticating...' )
173
181
pin = getpass ('Enter PIN: ' )
174
182
yubikey .verify (pin , touch_callback = prompt_for_touch )
175
183
176
- mgmt_key = getpass ('Enter management key [blank to use default key] : ' )
177
- mgmt_key = mgmt_key or DEFAULT_MANAGEMENT_KEY
184
+ mgmt_key = getpass ('Enter management key: ' ) \
185
+ if prompt_management_key else DEFAULT_MANAGEMENT_KEY
178
186
yubikey .authenticate (mgmt_key , touch_callback = prompt_for_touch )
179
187
180
188
181
- def gen_private_key (yubikey : YubiKey , slot : SLOT ,
189
+ def gen_private_key (yubikey : YubiKey , slot : SLOT , prompt_management_key : bool ,
182
190
pin_policy : PIN_POLICY , touch_policy : TOUCH_POLICY ,
183
191
subject : str , valid_days : int ):
184
192
""" Generates a private key and certificate on the YubiKey """
185
- authenticate (yubikey )
193
+ authenticate (yubikey , prompt_management_key )
186
194
187
195
print ('Generating private key...' )
188
196
public_key = yubikey .generate_key (
@@ -231,10 +239,10 @@ def json_b64encode(obj: dict):
231
239
return b64encode_str (json_str )
232
240
233
241
234
- def get_id_token (yubikey : YubiKey , slot : SLOT , service_account_email : str ,
235
- scopes : List [str ], token_lifetime : int ):
242
+ def get_id_token (yubikey : YubiKey , slot : SLOT , prompt_management_key : bool ,
243
+ service_account_email : str , scopes : List [str ], token_lifetime : int ):
236
244
""" Generates a Google ID token with a YubiKey """
237
- authenticate (yubikey )
245
+ authenticate (yubikey , prompt_management_key )
238
246
239
247
iat = time ()
240
248
header = {
@@ -277,7 +285,7 @@ def main():
277
285
278
286
if args .action == str (Action .GENERATE_KEY ):
279
287
gen_private_key (
280
- yubikey , args .slot ,
288
+ yubikey , args .slot , args . prompt_management_key ,
281
289
args .pin_policy , args .touch_policy ,
282
290
args .subject , args .valid_days ,
283
291
)
@@ -287,8 +295,8 @@ def main():
287
295
print (f'Key id: { key_id } ' )
288
296
else :
289
297
id_token = get_id_token (
290
- yubikey , args .slot , args .service_account_email ,
291
- args .scopes , args .token_lifetime ,
298
+ yubikey , args .slot , args .prompt_management_key ,
299
+ args .service_account_email , args . scopes , args .token_lifetime ,
292
300
)
293
301
if args .token_type == TokenType .ACCESS :
294
302
print (get_access_token (id_token ))
0 commit comments