version 1.228, 2015/10/13 16:15:21 |
version 1.229, 2015/11/15 22:26:49 |
|
|
static int sign_and_send_pubkey(Authctxt *, Identity *); |
static int sign_and_send_pubkey(Authctxt *, Identity *); |
static void pubkey_prepare(Authctxt *); |
static void pubkey_prepare(Authctxt *); |
static void pubkey_cleanup(Authctxt *); |
static void pubkey_cleanup(Authctxt *); |
static Key *load_identity_file(char *, int); |
static Key *load_identity_file(Identity *); |
|
|
static Authmethod *authmethod_get(char *authlist); |
static Authmethod *authmethod_get(char *authlist); |
static Authmethod *authmethod_lookup(const char *name); |
static Authmethod *authmethod_lookup(const char *name); |
|
|
return (sshkey_sign(id->key, sigp, lenp, data, datalen, |
return (sshkey_sign(id->key, sigp, lenp, data, datalen, |
compat)); |
compat)); |
/* load the private key from the file */ |
/* load the private key from the file */ |
if ((prv = load_identity_file(id->filename, id->userprovided)) == NULL) |
if ((prv = load_identity_file(id)) == NULL) |
return (-1); /* XXX return decent error code */ |
return (-1); /* XXX return decent error code */ |
ret = sshkey_sign(prv, sigp, lenp, data, datalen, compat); |
ret = sshkey_sign(prv, sigp, lenp, data, datalen, compat); |
sshkey_free(prv); |
sshkey_free(prv); |
|
|
} |
} |
|
|
static Key * |
static Key * |
load_identity_file(char *filename, int userprovided) |
load_identity_file(Identity *id) |
{ |
{ |
Key *private; |
Key *private; |
char prompt[300], *passphrase; |
char prompt[300], *passphrase, *comment; |
int r, perm_ok = 0, quit = 0, i; |
int r, perm_ok = 0, quit = 0, i; |
struct stat st; |
struct stat st; |
|
|
if (stat(filename, &st) < 0) { |
if (stat(id->filename, &st) < 0) { |
(userprovided ? logit : debug3)("no such identity: %s: %s", |
(id->userprovided ? logit : debug3)("no such identity: %s: %s", |
filename, strerror(errno)); |
id->filename, strerror(errno)); |
return NULL; |
return NULL; |
} |
} |
snprintf(prompt, sizeof prompt, |
snprintf(prompt, sizeof prompt, |
"Enter passphrase for key '%.100s': ", filename); |
"Enter passphrase for key '%.100s': ", id->filename); |
for (i = 0; i <= options.number_of_password_prompts; i++) { |
for (i = 0; i <= options.number_of_password_prompts; i++) { |
if (i == 0) |
if (i == 0) |
passphrase = ""; |
passphrase = ""; |
|
|
break; |
break; |
} |
} |
} |
} |
switch ((r = sshkey_load_private_type(KEY_UNSPEC, filename, |
switch ((r = sshkey_load_private_type(KEY_UNSPEC, id->filename, |
passphrase, &private, NULL, &perm_ok))) { |
passphrase, &private, &comment, &perm_ok))) { |
case 0: |
case 0: |
break; |
break; |
case SSH_ERR_KEY_WRONG_PASSPHRASE: |
case SSH_ERR_KEY_WRONG_PASSPHRASE: |
|
|
case SSH_ERR_SYSTEM_ERROR: |
case SSH_ERR_SYSTEM_ERROR: |
if (errno == ENOENT) { |
if (errno == ENOENT) { |
debug2("Load key \"%s\": %s", |
debug2("Load key \"%s\": %s", |
filename, ssh_err(r)); |
id->filename, ssh_err(r)); |
quit = 1; |
quit = 1; |
break; |
break; |
} |
} |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
default: |
default: |
error("Load key \"%s\": %s", filename, ssh_err(r)); |
error("Load key \"%s\": %s", id->filename, ssh_err(r)); |
quit = 1; |
quit = 1; |
break; |
break; |
} |
} |
|
if (!quit && private != NULL && !id->agent_fd && |
|
!(id->key && id->isprivate)) |
|
maybe_add_key_to_agent(id->filename, private, comment, |
|
passphrase); |
if (i > 0) { |
if (i > 0) { |
explicit_bzero(passphrase, strlen(passphrase)); |
explicit_bzero(passphrase, strlen(passphrase)); |
free(passphrase); |
free(passphrase); |
} |
} |
|
if (comment) |
|
free(comment); |
if (private != NULL || quit) |
if (private != NULL || quit) |
break; |
break; |
} |
} |
|
|
} |
} |
} else { |
} else { |
debug("Trying private key: %s", id->filename); |
debug("Trying private key: %s", id->filename); |
id->key = load_identity_file(id->filename, |
id->key = load_identity_file(id); |
id->userprovided); |
|
if (id->key != NULL) { |
if (id->key != NULL) { |
if (try_identity(id)) { |
if (try_identity(id)) { |
id->isprivate = 1; |
id->isprivate = 1; |