From: Greg Hudson Date: Tue, 6 Mar 2018 05:14:49 +0000 (-0500) Subject: Use libkrb5support hex decoder in PKINIT X-Git-Tag: krb5-1.17-beta1~172 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec58ba020721844c7070f22c1e5da56a9812da85;p=thirdparty%2Fkrb5.git Use libkrb5support hex decoder in PKINIT In pkinit_crypto_openssl.c, remove hex_string_to_bin() (recently added for ease of backporting) and instead use k5_hex_decode() in pkinit_get_certs_pkcs11(). Change the type of cert_id and cert_id_len in pkinit_identity_crypto_context to avoid needing type conversion intermediates. --- diff --git a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c index 3a1180d9ca..b4bfd635bd 100644 --- a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c +++ b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c @@ -31,6 +31,7 @@ #include "pkinit_crypto_openssl.h" #include "k5-buf.h" +#include "k5-hex.h" #include #include #include @@ -4636,43 +4637,6 @@ reassemble_pkcs11_name(pkinit_identity_opts *idopts) return ret; } -static int -hex_string_to_bin(const char *str, int *bin_len_out, CK_BYTE **bin_out) -{ - size_t str_len, i; - CK_BYTE *bin; - char *endptr, tmp[3] = { '\0', '\0', '\0' }; - long val; - - *bin_len_out = 0; - *bin_out = NULL; - - str_len = strlen(str); - if (str_len % 2 != 0) - return EINVAL; - bin = malloc(str_len / 2); - if (bin == NULL) - return ENOMEM; - - errno = 0; - for (i = 0; i < str_len / 2; i++) { - tmp[0] = str[i * 2]; - tmp[1] = str[i * 2 + 1]; - - val = strtol(tmp, &endptr, 16); - if (val < 0 || val > 255 || errno != 0 || endptr != &tmp[2]) { - free(bin); - return EINVAL; - } - - bin[i] = (CK_BYTE)val; - } - - *bin_len_out = str_len / 2; - *bin_out = bin; - return 0; -} - static krb5_error_code pkinit_get_certs_pkcs11(krb5_context context, pkinit_plg_crypto_context plg_cryptoctx, @@ -4715,9 +4679,8 @@ pkinit_get_certs_pkcs11(krb5_context context, } /* Convert the ascii cert_id string into a binary blob */ if (idopts->cert_id_string != NULL) { - r = hex_string_to_bin(idopts->cert_id_string, - &id_cryptoctx->cert_id_len, - &id_cryptoctx->cert_id); + r = k5_hex_decode(idopts->cert_id_string, + &id_cryptoctx->cert_id, &id_cryptoctx->cert_id_len); if (r != 0) { pkiDebug("Failed to convert certid string [%s]\n", idopts->cert_id_string); diff --git a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.h b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.h index 7411348fab..957c3def45 100644 --- a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.h +++ b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.h @@ -87,8 +87,8 @@ struct _pkinit_identity_crypto_context { void *p11_module; CK_SESSION_HANDLE session; CK_FUNCTION_LIST_PTR p11; - CK_BYTE_PTR cert_id; - int cert_id_len; + uint8_t *cert_id; + size_t cert_id_len; CK_MECHANISM_TYPE mech; #endif krb5_boolean defer_id_prompt;