Skip to content

Commit

Permalink
Remove length limit on PKINIT PKCS#12 prompt
Browse files Browse the repository at this point in the history
Long pathnames can trigger the 128-byte prompt length limit in
pkinit_get_certs_pkcs12.  Use asprintf instead of snprintf.  Also
check the result of the prompter invocation.

(cherry picked from commit 3c330ea)

ticket: 8134 (new)
version_fixed: 1.12.3
status: resolved
  • Loading branch information
greghudson authored and tlyu committed Feb 10, 2015
1 parent 7cd2e47 commit e4c312e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4293,6 +4293,7 @@ pkinit_get_certs_pkcs12(krb5_context context,
krb5_principal princ)
{
krb5_error_code retval = KRB5KDC_ERR_PREAUTH_FAILED;
char *prompt_string = NULL;
X509 *x = NULL;
PKCS12 *p12 = NULL;
int ret;
Expand Down Expand Up @@ -4333,8 +4334,7 @@ pkinit_get_certs_pkcs12(krb5_context context,
krb5_data rdat;
krb5_prompt kprompt;
krb5_prompt_type prompt_type;
int r = 0;
char prompt_string[128];
krb5_error_code r;
char prompt_reply[128];
char *prompt_prefix = _("Pass phrase for");
char *p12name = reassemble_pkcs12_name(idopts->cert_filename);
Expand Down Expand Up @@ -4366,11 +4366,9 @@ pkinit_get_certs_pkcs12(krb5_context context,
rdat.data = prompt_reply;
rdat.length = sizeof(prompt_reply);

r = snprintf(prompt_string, sizeof(prompt_string), "%s %s",
prompt_prefix, idopts->cert_filename);
if (r >= (int)sizeof(prompt_string)) {
pkiDebug("Prompt string, '%s %s', is too long!\n",
prompt_prefix, idopts->cert_filename);
if (asprintf(&prompt_string, "%s %s", prompt_prefix,
idopts->cert_filename) < 0) {
prompt_string = NULL;
goto cleanup;
}
kprompt.prompt = prompt_string;
Expand All @@ -4382,6 +4380,10 @@ pkinit_get_certs_pkcs12(krb5_context context,
r = (*id_cryptoctx->prompter)(context, id_cryptoctx->prompter_data,
NULL, NULL, 1, &kprompt);
k5int_set_prompt_types(context, 0);
if (r) {
pkiDebug("Failed to prompt for PKCS12 password");
goto cleanup;
}
}

ret = PKCS12_parse(p12, rdat.data, &y, &x, NULL);
Expand All @@ -4406,6 +4408,7 @@ pkinit_get_certs_pkcs12(krb5_context context,
retval = 0;

cleanup:
free(prompt_string);
if (p12)
PKCS12_free(p12);
if (retval) {
Expand Down

0 comments on commit e4c312e

Please sign in to comment.