Skip to content

Commit

Permalink
Simplify PKINIT cert iteration and selection
Browse files Browse the repository at this point in the history
Remove the pkinit_cert_handle structures and iteration functions used
during certificate matching.  Instead, make pkinit_matching.c obtain a
list of matching data objects from the crypto code, and then select a
cert based on the index into that list.

Also fix a typo in the name of crypto_retrieve_X509_key_usage().

[ghudson@mit.edu: simplified code]
  • Loading branch information
Matt Rogers authored and greghudson committed Mar 23, 2017
1 parent b619ce8 commit 01b1c0e
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 417 deletions.
75 changes: 22 additions & 53 deletions src/plugins/preauth/pkinit/pkinit_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ typedef struct _pkinit_cert_iter_info *pkinit_cert_iter_handle;
#define PKINIT_ITER_NO_MORE 0x11111111 /* XXX */

typedef struct _pkinit_cert_matching_data {
pkinit_cert_handle ch; /* cert handle for this certificate */
char *subject_dn; /* rfc2253-style subject name string */
char *issuer_dn; /* rfc2253-style issuer name string */
unsigned int ku_bits; /* key usage information */
Expand Down Expand Up @@ -458,68 +457,38 @@ krb5_error_code crypto_free_cert_info


/*
* Get number of certificates available after crypto_load_certs()
* Get a null-terminated list of certificate matching data objects for the
* certificates loaded in id_cryptoctx.
*/
krb5_error_code crypto_cert_get_count
(krb5_context context, /* IN */
pkinit_plg_crypto_context plg_cryptoctx, /* IN */
pkinit_req_crypto_context req_cryptoctx, /* IN */
pkinit_identity_crypto_context id_cryptoctx, /* IN */
int *cert_count); /* OUT */

/*
* Begin iteration over the certs loaded in crypto_load_certs()
*/
krb5_error_code crypto_cert_iteration_begin
(krb5_context context, /* IN */
pkinit_plg_crypto_context plg_cryptoctx, /* IN */
pkinit_req_crypto_context req_cryptoctx, /* IN */
pkinit_identity_crypto_context id_cryptoctx, /* IN */
pkinit_cert_iter_handle *iter_handle); /* OUT */

/*
* End iteration over the certs loaded in crypto_load_certs()
*/
krb5_error_code crypto_cert_iteration_end
(krb5_context context, /* IN */
pkinit_cert_iter_handle iter_handle); /* IN */

/*
* Get next certificate handle
*/
krb5_error_code crypto_cert_iteration_next
(krb5_context context, /* IN */
pkinit_cert_iter_handle iter_handle, /* IN */
pkinit_cert_handle *cert_handle); /* OUT */

/*
* Release cert handle
*/
krb5_error_code crypto_cert_release
(krb5_context context, /* IN */
pkinit_cert_handle cert_handle); /* IN */
krb5_error_code
crypto_cert_get_matching_data(krb5_context context,
pkinit_plg_crypto_context plg_cryptoctx,
pkinit_req_crypto_context req_cryptoctx,
pkinit_identity_crypto_context id_cryptoctx,
pkinit_cert_matching_data ***md_out);

/*
* Get certificate matching information
* Free a matching data object.
*/
krb5_error_code crypto_cert_get_matching_data
(krb5_context context, /* IN */
pkinit_cert_handle cert_handle, /* IN */
pkinit_cert_matching_data **ret_data); /* OUT */
void
crypto_cert_free_matching_data(krb5_context context,
pkinit_cert_matching_data *md);

/*
* Free certificate information
* Free a list of matching data objects.
*/
krb5_error_code crypto_cert_free_matching_data
(krb5_context context, /* IN */
pkinit_cert_matching_data *data); /* IN */
void
crypto_cert_free_matching_data_list(krb5_context context,
pkinit_cert_matching_data **matchdata);

/*
* Make the given certificate "the chosen one"
* Choose one of the certificates loaded in idctx to use for PKINIT client
* operations. cred_index must be an index into the array of matching objects
* returned by crypto_cert_get_matching_data().
*/
krb5_error_code crypto_cert_select
(krb5_context context, /* IN */
pkinit_cert_matching_data *data); /* IN */
krb5_error_code
crypto_cert_select(krb5_context context, pkinit_identity_crypto_context idctx,
size_t cred_index);

/*
* Select the default certificate as "the chosen one"
Expand Down

0 comments on commit 01b1c0e

Please sign in to comment.