@@ -349,14 +349,28 @@ int cred_acquire_cb(git_cred **out,
349349 unsigned int allowed_types ,
350350 void * payload )
351351{
352- char * username = NULL , * password = NULL ;
352+ char * username = NULL , * password = NULL , * privkey = NULL , * pubkey = NULL ;
353353 int error = 1 ;
354354
355355 UNUSED (url );
356356 UNUSED (username_from_url );
357357 UNUSED (payload );
358358
359- if (allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT ) {
359+ if (allowed_types & GIT_CREDTYPE_SSH_KEY ) {
360+ int n ;
361+
362+ if ((error = ask (& username , "Username:" )) < 0 ||
363+ (error = ask (& privkey , "SSH Key:" )) < 0 ||
364+ (error = ask (& password , "Password:" )) < 0 )
365+ goto out ;
366+
367+ if ((n = snprintf (NULL , 0 , "%s.pub" , privkey )) < 0 ||
368+ (pubkey = malloc (n + 1 )) == NULL ||
369+ (n = snprintf (pubkey , n + 1 , "%s.pub" , privkey )) < 0 )
370+ goto out ;
371+
372+ error = git_cred_ssh_key_new (out , username , pubkey , privkey , password );
373+ } else if (allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT ) {
360374 if ((error = ask (& username , "Username:" )) < 0 ||
361375 (error = ask (& password , "Password:" )) < 0 )
362376 goto out ;
@@ -372,5 +386,7 @@ int cred_acquire_cb(git_cred **out,
372386out :
373387 free (username );
374388 free (password );
389+ free (privkey );
390+ free (pubkey );
375391 return error ;
376392}
0 commit comments