@@ -85,7 +85,7 @@ convert_blob(struct agent_connection* con, const char *blob, DWORD blen, char **
85
85
86
86
#define REG_KEY_SDDL L"D:P(A;; GA;;; SY)(A;; GA;;; BA)"
87
87
88
- int
88
+ static int
89
89
process_add_identity (struct sshbuf * request , struct sshbuf * response , struct agent_connection * con ) {
90
90
struct sshkey * key = NULL ;
91
91
int r = 0 , blob_len , eblob_len , request_invalid = 0 , success = 0 ;
@@ -114,7 +114,7 @@ process_add_identity(struct sshbuf* request, struct sshbuf* response, struct age
114
114
convert_blob (con , blob , blob_len , & eblob , & eblob_len , 1 ) != 0 ||
115
115
((thumbprint = sshkey_fingerprint (key , SSH_FP_HASH_DEFAULT , SSH_FP_DEFAULT )) == NULL ) ||
116
116
get_user_root (con , & user_root ) != 0 ||
117
- RegCreateKeyExW (user_root , SSHD_KEYS_ROOT , 0 , 0 , 0 , KEY_WRITE | KEY_WOW64_64KEY , & sa , & reg , NULL ) != 0 ||
117
+ RegCreateKeyExW (user_root , SSH_KEYS_ROOT , 0 , 0 , 0 , KEY_WRITE | KEY_WOW64_64KEY , & sa , & reg , NULL ) != 0 ||
118
118
RegCreateKeyExA (reg , thumbprint , 0 , 0 , 0 , KEY_WRITE | KEY_WOW64_64KEY , & sa , & sub , NULL ) != 0 ||
119
119
RegSetValueExW (sub , NULL , 0 , REG_BINARY , eblob , eblob_len ) != 0 ||
120
120
RegSetValueExW (sub , L"pub" , 0 , REG_BINARY , pubkey_blob , pubkey_blob_len ) != 0 ||
@@ -171,7 +171,7 @@ static int sign_blob(const struct sshkey *pubkey, u_char ** sig, size_t *siglen,
171
171
172
172
if ((thumbprint = sshkey_fingerprint (pubkey , SSH_FP_HASH_DEFAULT , SSH_FP_DEFAULT )) == NULL ||
173
173
get_user_root (con , & user_root ) != 0 ||
174
- RegOpenKeyExW (user_root , SSHD_KEYS_ROOT ,
174
+ RegOpenKeyExW (user_root , SSH_KEYS_ROOT ,
175
175
0 , STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_WOW64_64KEY | KEY_ENUMERATE_SUB_KEYS , & reg ) != 0 ||
176
176
RegOpenKeyExA (reg , thumbprint , 0 ,
177
177
STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_WOW64_64KEY , & sub ) != 0 ||
@@ -209,7 +209,7 @@ static int sign_blob(const struct sshkey *pubkey, u_char ** sig, size_t *siglen,
209
209
return success ? 0 : -1 ;
210
210
}
211
211
212
- int
212
+ static int
213
213
process_sign_request (struct sshbuf * request , struct sshbuf * response , struct agent_connection * con ) {
214
214
u_char * blob , * data , * signature = NULL ;
215
215
size_t blen , dlen , slen = 0 ;
@@ -254,21 +254,48 @@ process_sign_request(struct sshbuf* request, struct sshbuf* response, struct age
254
254
return r ;
255
255
}
256
256
257
- int
257
+ static int
258
+ process_remove_all (struct sshbuf * request , struct sshbuf * response , struct agent_connection * con ) {
259
+ HKEY user_root = 0 , root = 0 ;
260
+ int r = 0 ;
261
+
262
+ if (get_user_root (con , & user_root ) != 0 ||
263
+ RegOpenKeyExW (user_root , SSH_ROOT , 0 , STANDARD_RIGHTS_READ | KEY_ENUMERATE_SUB_KEYS | KEY_WOW64_64KEY , & root ) != 0 ) {
264
+ goto done ;
265
+ }
266
+
267
+ RegDeleteKeyExW (root , SSH_KEYS_KEY , KEY_WOW64_64KEY , 0 );
268
+ done :
269
+ r = 0 ;
270
+ if (sshbuf_put_u8 (response , SSH_AGENT_SUCCESS ) != 0 )
271
+ r = -1 ;
272
+
273
+ if (user_root )
274
+ RegCloseKey (user_root );
275
+ if (root )
276
+ RegCloseKey (root );
277
+ return r ;
278
+ }
279
+
280
+ static int
258
281
process_request_identities (struct sshbuf * request , struct sshbuf * response , struct agent_connection * con ) {
259
- int count = 0 , index = 0 , success = 0 ;
282
+ int count = 0 , index = 0 , success = 0 , r = 0 ;
260
283
HKEY root = NULL , sub = NULL , user_root = 0 ;
261
284
char * count_ptr = NULL ;
262
285
wchar_t sub_name [MAX_KEY_LENGTH ];
263
286
DWORD sub_name_len = MAX_KEY_LENGTH ;
264
- char * regdata = NULL ;
265
- DWORD regdatalen = 0 , key_count = 0 ;
287
+ char * pkblob = NULL , * comment = NULL ;
288
+ DWORD regdatalen = 0 , commentlen = 0 , key_count = 0 ;
266
289
struct sshbuf * identities ;
267
290
268
- if ((identities = sshbuf_new ()) == NULL ||
269
- get_user_root (con , & user_root ) != 0 ||
270
- RegOpenKeyExW (user_root , SSHD_KEYS_ROOT , 0 , STANDARD_RIGHTS_READ | KEY_ENUMERATE_SUB_KEYS | KEY_WOW64_64KEY , & root ) != 0 )
291
+ if ((identities = sshbuf_new ()) == NULL )
292
+ goto done ;
293
+
294
+ if ( get_user_root (con , & user_root ) != 0 ||
295
+ RegOpenKeyExW (user_root , SSH_KEYS_ROOT , 0 , STANDARD_RIGHTS_READ | KEY_ENUMERATE_SUB_KEYS | KEY_WOW64_64KEY , & root ) != 0 ) {
296
+ success = 1 ;
271
297
goto done ;
298
+ }
272
299
273
300
while (1 ) {
274
301
sub_name_len = MAX_KEY_LENGTH ;
@@ -277,79 +304,48 @@ process_request_identities(struct sshbuf* request, struct sshbuf* response, stru
277
304
sub = NULL ;
278
305
}
279
306
if (RegEnumKeyExW (root , index ++ , sub_name , & sub_name_len , NULL , NULL , NULL , NULL ) == 0 ) {
280
- if (RegOpenKeyExW (root , sub_name , 0 , KEY_QUERY_VALUE , & sub ) == 0 ) {
281
- if (RegQueryValueExW (sub , L"pub" , 0 , NULL , NULL , & regdatalen ) == 0 ) {
282
-
283
-
284
- if (r == ERROR_MORE_DATA ) {
285
- r = 0 ;
286
- if (regdata )
287
- free (regdata );
288
- if ((regdata = malloc (regdatalen )) == NULL ) {
289
- r = ENOMEM ;
290
- goto done ;
291
- }
292
- if ((r = RegQueryValueExW (sub , L"pub" , 0 , NULL , regdata , & regdatalen )) != 0 )
293
- goto done ;
294
-
295
- }
296
- else {
297
- r = EOTHER ;
298
- goto done ;
299
- }
300
- }
301
-
302
- if ((r = sshbuf_put_string (identities , regdata , regdatalen )) != 0 )
303
- goto done ;
304
-
305
- if ((r = RegQueryValueExW (sub , L"comment" , 0 , NULL , regdata , & regdatalen )) != 0 ) {
306
- if (r == ERROR_MORE_DATA ) {
307
- r = 0 ;
308
- if (regdata )
309
- free (regdata );
310
- if ((regdata = malloc (regdatalen )) == NULL ) {
311
- r = ENOMEM ;
312
- goto done ;
313
- }
314
- if ((r = RegQueryValueExW (sub , L"comment" , 0 , NULL , regdata , & regdatalen )) != 0 )
315
- goto done ;
316
-
317
- }
318
- else {
319
- r = EOTHER ;
320
- goto done ;
321
- }
322
- }
323
- if ((r = sshbuf_put_string (identities , regdata , regdatalen )) != 0 )
307
+ if (RegOpenKeyExW (root , sub_name , 0 , KEY_QUERY_VALUE | KEY_WOW64_64KEY , & sub ) == 0 &&
308
+ RegQueryValueExW (sub , L"pub" , 0 , NULL , NULL , & regdatalen ) == 0 &&
309
+ RegQueryValueExW (sub , L"comment" , 0 , NULL , NULL , & commentlen ) == 0 ) {
310
+ if (pkblob )
311
+ free (pkblob );
312
+ if (comment )
313
+ free (comment );
314
+ pkblob = NULL ;
315
+ comment = NULL ;
316
+
317
+ if ((pkblob = malloc (regdatalen )) == NULL ||
318
+ (comment = malloc (commentlen )) == NULL ||
319
+ RegQueryValueExW (sub , L"pub" , 0 , NULL , pkblob , & regdatalen ) != 0 ||
320
+ RegQueryValueExW (sub , L"comment" , 0 , NULL , comment , & commentlen ) != 0 ||
321
+ sshbuf_put_string (identities , pkblob , regdatalen ) != 0 ||
322
+ sshbuf_put_string (identities , comment , commentlen ) != 0 )
324
323
goto done ;
324
+
325
325
key_count ++ ;
326
-
327
- }
328
- else if (r == ERROR_FILE_NOT_FOUND ) {
329
- r = 0 ;
330
- continue ;
331
326
}
332
- else
333
- goto done ;
334
- }
335
- else if (r == ERROR_NO_MORE_ITEMS ) {
336
- r = 0 ;
337
- break ;
338
327
}
339
328
else
340
- goto done ;
329
+ break ;
341
330
342
331
}
343
332
344
- if (((r = sshbuf_put_u8 (response , SSH2_AGENT_IDENTITIES_ANSWER )) != 0 )
345
- || ((r = sshbuf_put_u32 (response , key_count )) != 0 )
346
- || ((r = sshbuf_putb (response , identities )) != 0 ))
347
- goto done ;
348
-
349
-
333
+ success = 1 ;
350
334
done :
351
- if (regdata )
352
- free (regdata );
335
+ r = 0 ;
336
+ if (success ) {
337
+ if (sshbuf_put_u8 (response , SSH2_AGENT_IDENTITIES_ANSWER ) != 0 ||
338
+ sshbuf_put_u32 (response , key_count ) != 0 ||
339
+ sshbuf_putb (response , identities ) != 0 )
340
+ goto done ;
341
+ }
342
+ else
343
+ r = -1 ;
344
+
345
+ if (pkblob )
346
+ free (pkblob );
347
+ if (comment )
348
+ free (comment );
353
349
if (identities )
354
350
sshbuf_free (identities );
355
351
if (user_root )
@@ -375,6 +371,10 @@ int process_keyagent_request(struct sshbuf* request, struct sshbuf* response, st
375
371
return process_request_identities (request , response , con );
376
372
case SSH2_AGENTC_SIGN_REQUEST :
377
373
return process_sign_request (request , response , con );
374
+ case SSH2_AGENTC_REMOVE_IDENTITY :
375
+
376
+ case SSH2_AGENTC_REMOVE_ALL_IDENTITIES :
377
+ return process_remove_all (request , response , con );
378
378
default :
379
379
debug ("unknown key agent request %d" , type );
380
380
return EINVAL ;
0 commit comments