xref: /titanic_51/usr/src/common/net/wanboot/p12aux.h (revision 2a446632681882e5dfe50f2f301401588f1ce734)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2002, 2003 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
279a686fbcSPaul Dagnelie /*
289a686fbcSPaul Dagnelie  * Copyright (c) 2015 by Delphix. All rights reserved.
299a686fbcSPaul Dagnelie  */
309a686fbcSPaul Dagnelie 
317c478bd9Sstevel@tonic-gate #ifndef	_P12AUX_H
327c478bd9Sstevel@tonic-gate #define	_P12AUX_H
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <openssl/pkcs12.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * I really hate to do this.  It's pretty gross, but go ahead and use the
427c478bd9Sstevel@tonic-gate  * macros and functions already defined to provide new EVP_PKEY-specific
437c478bd9Sstevel@tonic-gate  * macros, for use within this file only.
447c478bd9Sstevel@tonic-gate  *
457c478bd9Sstevel@tonic-gate  * My apologies.
467c478bd9Sstevel@tonic-gate  */
47*2a446632SRobert Mustacchi /* CSTYLED */
48*2a446632SRobert Mustacchi DECLARE_STACK_OF(EVP_PKEY)
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #define	sk_EVP_PKEY_new_null() SKM_sk_new_null(EVP_PKEY)
517c478bd9Sstevel@tonic-gate #define	sk_EVP_PKEY_free(st) SKM_sk_free(EVP_PKEY, (st))
527c478bd9Sstevel@tonic-gate #define	sk_EVP_PKEY_num(st) SKM_sk_num(EVP_PKEY, (st))
537c478bd9Sstevel@tonic-gate #define	sk_EVP_PKEY_value(st, i) SKM_sk_value(EVP_PKEY, (st), (i))
547c478bd9Sstevel@tonic-gate #define	sk_EVP_PKEY_push(st, val) SKM_sk_push(EVP_PKEY, (st), (val))
557c478bd9Sstevel@tonic-gate #define	sk_EVP_PKEY_find(st, val) SKM_sk_find(EVP_PKEY, (st), (val))
567c478bd9Sstevel@tonic-gate #define	sk_EVP_PKEY_delete(st, i) SKM_sk_delete(EVP_PKEY, (st), (i))
577c478bd9Sstevel@tonic-gate #define	sk_EVP_PKEY_delete_ptr(st, ptr) SKM_sk_delete_ptr(EVP_PKEY, (st), (ptr))
587c478bd9Sstevel@tonic-gate #define	sk_EVP_PKEY_insert(st, val, i) SKM_sk_insert(EVP_PKEY, (st), (val), (i))
597c478bd9Sstevel@tonic-gate #define	sk_EVP_PKEY_pop_free(st, free_func) SKM_sk_pop_free(EVP_PKEY, (st), \
607c478bd9Sstevel@tonic-gate 	    (free_func))
617c478bd9Sstevel@tonic-gate #define	sk_EVP_PKEY_pop(st) SKM_sk_pop(EVP_PKEY, (st))
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  * This type indicates what to do with an attribute being returned.
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate typedef enum {
677c478bd9Sstevel@tonic-gate 	GETDO_COPY = 1,		/* Simply return the value of the attribute */
687c478bd9Sstevel@tonic-gate 	GETDO_DEL		/* Delete the attribute at the same time. */
697c478bd9Sstevel@tonic-gate } getdo_actions_t;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * The following is used to call the sunw_print_times function which is
737c478bd9Sstevel@tonic-gate  * described at the bottom of the page.
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate typedef enum {
767c478bd9Sstevel@tonic-gate 	PRNT_NOT_BEFORE = 1,	/* Print 'not before' date */
777c478bd9Sstevel@tonic-gate 	PRNT_NOT_AFTER,		/* Print 'not after' date */
787c478bd9Sstevel@tonic-gate 	PRNT_BOTH		/* Prints both dates */
797c478bd9Sstevel@tonic-gate } prnt_actions_t;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * For sunw_pkcs12_parse, the following are values for bits that indicate
837c478bd9Sstevel@tonic-gate  * various types of searches/matching to do. Any of these values can be
847c478bd9Sstevel@tonic-gate  * OR'd together. However, the order in which an attempt will be made
857c478bd9Sstevel@tonic-gate  * to satisfy them is the order in which they are listed below. The
867c478bd9Sstevel@tonic-gate  * exception is DO_NONE. It should not be OR'd with any other value.
877c478bd9Sstevel@tonic-gate  */
887c478bd9Sstevel@tonic-gate #define	DO_NONE		0x00	/* Don't even try to match */
897c478bd9Sstevel@tonic-gate #define	DO_FIND_KEYID	0x01	/* 1st cert, key with matching localkeyid */
907c478bd9Sstevel@tonic-gate #define	DO_FIND_FN	0x02	/* 1st cert, key with matching friendlyname */
917c478bd9Sstevel@tonic-gate #define	DO_FIRST_PAIR	0x04	/* Return first matching cert/key pair found */
927c478bd9Sstevel@tonic-gate #define	DO_LAST_PAIR	0x08	/* Return last matching cert/key pair found */
937c478bd9Sstevel@tonic-gate #define	DO_UNMATCHING	0x10	/* Return first cert and/or key */
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /* Bits returned, which indicate what values were found. */
967c478bd9Sstevel@tonic-gate #define	FOUND_PKEY	0x01	/* Found one or more private key */
977c478bd9Sstevel@tonic-gate #define	FOUND_CERT	0x02	/* Found one or more client certificate */
987c478bd9Sstevel@tonic-gate #define	FOUND_CA_CERTS	0x04	/* Added at least one cert to the CA list */
997c478bd9Sstevel@tonic-gate #define	FOUND_XPKEY	0x08	/* Found at least one private key which does */
1007c478bd9Sstevel@tonic-gate 				/* not match a certificate in the certs list */
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate  * sunw_cryto_init() does crypto-specific initialization.
1047c478bd9Sstevel@tonic-gate  *
1057c478bd9Sstevel@tonic-gate  * Arguments:
1067c478bd9Sstevel@tonic-gate  *   None.
1077c478bd9Sstevel@tonic-gate  *
1087c478bd9Sstevel@tonic-gate  * Returns:
1097c478bd9Sstevel@tonic-gate  *   None.
1107c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate void sunw_crypto_init(void);
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate  * sunw_PKCS12_parse() parses a pkcs#12 structure and returns component parts.
1157c478bd9Sstevel@tonic-gate  *
1167c478bd9Sstevel@tonic-gate  * Parse and decrypt a PKCS#12 structure returning user key, user cert and/or
1177c478bd9Sstevel@tonic-gate  * other (CA) certs. Note either ca should be NULL, *ca should be NULL,
1187c478bd9Sstevel@tonic-gate  * or it should point to a valid STACK_OF(X509) structure. pkey and cert can
1197c478bd9Sstevel@tonic-gate  * be passed uninitialized.
1207c478bd9Sstevel@tonic-gate  *
1217c478bd9Sstevel@tonic-gate  * Arguments:
1227c478bd9Sstevel@tonic-gate  *   p12      - Structure with pkcs12 info to be parsed
1237c478bd9Sstevel@tonic-gate  *   pass     - Pass phrase for the private key and entire pkcs12 wad (possibly
1247c478bd9Sstevel@tonic-gate  *              empty) or NULL if there is none.
1257c478bd9Sstevel@tonic-gate  *   matchty  - Info about which certs/keys to return if many are in the file.
1267c478bd9Sstevel@tonic-gate  *   keyid_str- If private key localkeyids are to match a predetermined value,
1277c478bd9Sstevel@tonic-gate  *              the value to match.
1287c478bd9Sstevel@tonic-gate  *   keyid_len- Length of the keyid byte string.
1297c478bd9Sstevel@tonic-gate  *   name_str - If friendlynames are to match a predetermined value, the value
1307c478bd9Sstevel@tonic-gate  *              to match.
1317c478bd9Sstevel@tonic-gate  *   pkey     - Points to location pointing to the private key returned.
1327c478bd9Sstevel@tonic-gate  *   cert     - Points to locaiton which points to the client cert returned
1337c478bd9Sstevel@tonic-gate  *   ca       - Points to location that points to a stack of 'certificate
1347c478bd9Sstevel@tonic-gate  *              authority' certs (possibly including trust anchors).
1357c478bd9Sstevel@tonic-gate  *
1367c478bd9Sstevel@tonic-gate  * Match based on the value of 'matchty' and the contents of 'keyid_str'
1377c478bd9Sstevel@tonic-gate  * and/or 'name_str', as appropriate.  Go through the lists of certs and
1387c478bd9Sstevel@tonic-gate  * private keys which were taken from the pkcs12 structure, looking for
1397c478bd9Sstevel@tonic-gate  * matches of the requested type.  This function only searches the lists of
1407c478bd9Sstevel@tonic-gate  * matching private keys and client certificates.  Kinds of matches allowed,
1417c478bd9Sstevel@tonic-gate  * and the order in which they will be checked, are:
1427c478bd9Sstevel@tonic-gate  *
1437c478bd9Sstevel@tonic-gate  *   1) Find the key and/or cert whose localkeyid attributes matches 'cmpstr'
1447c478bd9Sstevel@tonic-gate  *   2) Find the key and/or cert whose friendlyname attributes matches 'cmpstr'
1457c478bd9Sstevel@tonic-gate  *   3) Return the first matching key/cert pair found.
1467c478bd9Sstevel@tonic-gate  *   4) Return the last matching key/cert pair found.
1477c478bd9Sstevel@tonic-gate  *   5) Return whatever cert and/or key are available, even unmatching.
1487c478bd9Sstevel@tonic-gate  *
1497c478bd9Sstevel@tonic-gate  *   Append the certs which do not have matching private keys and which were
1507c478bd9Sstevel@tonic-gate  *   not selected to the CA list.
1517c478bd9Sstevel@tonic-gate  *
1527c478bd9Sstevel@tonic-gate  * If none of the bits are set, no client certs or private keys will be
1537c478bd9Sstevel@tonic-gate  * returned.  CA (aka trust anchor) certs can be.
1547c478bd9Sstevel@tonic-gate  *
1557c478bd9Sstevel@tonic-gate  * Notes: If #3 is selected, then #4 will never occur.  CA certs will be
1567c478bd9Sstevel@tonic-gate  * selected after a cert/key pairs are isolated.
1577c478bd9Sstevel@tonic-gate  *
1587c478bd9Sstevel@tonic-gate  * Returns:
1597c478bd9Sstevel@tonic-gate  *  <  0 - An error returned.  Call ERR_get_error() to get errors information.
1607c478bd9Sstevel@tonic-gate  *         Where possible, memory has been freed.
1617c478bd9Sstevel@tonic-gate  *  >= 0 - Objects were found and returned.  Which objects are indicated by
1627c478bd9Sstevel@tonic-gate  *         which bits are set (FOUND_PKEY, FOUND_CERT, FOUND_CA_CERTS).
1637c478bd9Sstevel@tonic-gate  */
1647c478bd9Sstevel@tonic-gate int sunw_PKCS12_parse(PKCS12 *, const char *, int, char *, int, char *,
1657c478bd9Sstevel@tonic-gate     EVP_PKEY **, X509 **, STACK_OF(X509) **);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate  * sunw_PKCS12_create() creates a pkcs#12 structure and given component parts.
1707c478bd9Sstevel@tonic-gate  *
1717c478bd9Sstevel@tonic-gate  * Given one or more of user private key, user cert and/or other (CA) certs,
1727c478bd9Sstevel@tonic-gate  * return an encrypted PKCS12 structure containing them.
1737c478bd9Sstevel@tonic-gate  *
1747c478bd9Sstevel@tonic-gate  * Arguments:
1757c478bd9Sstevel@tonic-gate  *   pass     - Pass phrase for the pkcs12 structure and private key (possibly
1767c478bd9Sstevel@tonic-gate  *              empty) or NULL if there is none.  It will be used to encrypt
1777c478bd9Sstevel@tonic-gate  *              both the private key(s) and as the pass phrase for the whole
1787c478bd9Sstevel@tonic-gate  *              pkcs12 wad.
1797c478bd9Sstevel@tonic-gate  *   pkey     - Points to stack of private keys.
1807c478bd9Sstevel@tonic-gate  *   cert     - Points to stack of client (public ke) certs
1817c478bd9Sstevel@tonic-gate  *   ca       - Points to stack of 'certificate authority' certs (or trust
1827c478bd9Sstevel@tonic-gate  *              anchors).
1837c478bd9Sstevel@tonic-gate  *
1847c478bd9Sstevel@tonic-gate  *   Note that any of these may be NULL.
1857c478bd9Sstevel@tonic-gate  *
1867c478bd9Sstevel@tonic-gate  * Returns:
1877c478bd9Sstevel@tonic-gate  *   NULL     - An error occurred.
1887c478bd9Sstevel@tonic-gate  *   != NULL  - Address of PKCS12 structure.  The user is responsible for
1897c478bd9Sstevel@tonic-gate  *              freeing the memory when done.
1907c478bd9Sstevel@tonic-gate  */
1917c478bd9Sstevel@tonic-gate PKCS12 *sunw_PKCS12_create(const char *, STACK_OF(EVP_PKEY) *, STACK_OF(X509) *,
1927c478bd9Sstevel@tonic-gate     STACK_OF(X509) *);
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate /*
1967c478bd9Sstevel@tonic-gate  * sunw_split_certs() - Given a list of certs and a list of private keys,
1977c478bd9Sstevel@tonic-gate  *     moves certs which match one of the keys to a different stack.
1987c478bd9Sstevel@tonic-gate  *
1997c478bd9Sstevel@tonic-gate  * Arguments:
2007c478bd9Sstevel@tonic-gate  *   allkeys  - Points to a stack of private keys to search.
2017c478bd9Sstevel@tonic-gate  *   allcerts - Points to a stack of certs to be searched.
2027c478bd9Sstevel@tonic-gate  *   keycerts - Points to address of a stack of certs with matching private
2037c478bd9Sstevel@tonic-gate  *              keys.  They are moved from 'allcerts'.  This may not be NULL
2047c478bd9Sstevel@tonic-gate  *              when called.  If *keycerts is NULL upon entry, a new stack will
2057c478bd9Sstevel@tonic-gate  *              be allocated.  Otherwise, it must be a valid STACK_OF(509).
2067c478bd9Sstevel@tonic-gate  *   nocerts  - Points to address of a stack for keys which have no matching
2077c478bd9Sstevel@tonic-gate  *              certs.  Keys are moved from 'allkeys' here when they have no
2087c478bd9Sstevel@tonic-gate  *              matching certs.  If this is NULL, matchless keys will be
2097c478bd9Sstevel@tonic-gate  *              discarded.
2107c478bd9Sstevel@tonic-gate  *
2117c478bd9Sstevel@tonic-gate  *   Notes:  If an error occurs while moving certs, the cert being move may be
2127c478bd9Sstevel@tonic-gate  *   lost.  'keycerts' may only contain part of the matching certs.  The number
2137c478bd9Sstevel@tonic-gate  *   of certs successfully moved can be found by checking sk_X509_num(keycerts).
2147c478bd9Sstevel@tonic-gate  *
2157c478bd9Sstevel@tonic-gate  *   If there is a key which does not have a matching cert, it is moved to
2167c478bd9Sstevel@tonic-gate  *   the list nocerts.
2177c478bd9Sstevel@tonic-gate  *
2187c478bd9Sstevel@tonic-gate  *   If all certs are removed from 'certs' and/or 'pkeys', it will be the
2197c478bd9Sstevel@tonic-gate  *   caller's responsibility to free the empty stacks.
2207c478bd9Sstevel@tonic-gate  *
2217c478bd9Sstevel@tonic-gate  * Returns:
2227c478bd9Sstevel@tonic-gate  *  <  0 - An error returned.  Call ERR_get_error() to get errors information.
2237c478bd9Sstevel@tonic-gate  *         Where possible, memory has been freed.
2247c478bd9Sstevel@tonic-gate  *  >= 0 - The number of certs moved from 'cert' to 'pkcerts'.
2257c478bd9Sstevel@tonic-gate  */
2267c478bd9Sstevel@tonic-gate int sunw_split_certs(STACK_OF(EVP_PKEY) *, STACK_OF(X509) *, STACK_OF(X509) **,
2277c478bd9Sstevel@tonic-gate     STACK_OF(EVP_PKEY) **);
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate /*
2307c478bd9Sstevel@tonic-gate  * sunw_evp_pkey_free() Given an EVP_PKEY structure, free any attributes
2317c478bd9Sstevel@tonic-gate  *     that are attached.  Then free the EVP_PKEY itself.
2327c478bd9Sstevel@tonic-gate  *
2337c478bd9Sstevel@tonic-gate  *     This is the replacement for EVP_PKEY_free() for the sunw stuff.
2347c478bd9Sstevel@tonic-gate  *     It should be used in places where EVP_PKEY_free would be used,
2357c478bd9Sstevel@tonic-gate  *     including calls to sk_EVP_PKEY_pop_free().
2367c478bd9Sstevel@tonic-gate  *
2377c478bd9Sstevel@tonic-gate  * Arguments:
2387c478bd9Sstevel@tonic-gate  *   pkey     - Entry which potentially has attributes to be freed.
2397c478bd9Sstevel@tonic-gate  *
2407c478bd9Sstevel@tonic-gate  * Returns:
2417c478bd9Sstevel@tonic-gate  *   None.
2427c478bd9Sstevel@tonic-gate  */
2437c478bd9Sstevel@tonic-gate void sunw_evp_pkey_free(EVP_PKEY *);
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate /*
2467c478bd9Sstevel@tonic-gate  * sunw_set_localkeyid() sets the localkeyid in a cert, a private key or
2477c478bd9Sstevel@tonic-gate  *     both.  Any existing localkeyid will be discarded.
2487c478bd9Sstevel@tonic-gate  *
2497c478bd9Sstevel@tonic-gate  * Arguments:
2507c478bd9Sstevel@tonic-gate  *   keyid_str- A byte string with the localkeyid to set
2517c478bd9Sstevel@tonic-gate  *   keyid_len- Length of the keyid byte string.
2527c478bd9Sstevel@tonic-gate  *   pkey     - Points to a private key to set the keyidstr in.
2537c478bd9Sstevel@tonic-gate  *   cert     - Points to a cert to set the keyidstr in.
2547c478bd9Sstevel@tonic-gate  *
2557c478bd9Sstevel@tonic-gate  * Note that setting a keyid into a cert which will not be written out as
2567c478bd9Sstevel@tonic-gate  * a PKCS12 cert is pointless since it will be lost.
2577c478bd9Sstevel@tonic-gate  *
2587c478bd9Sstevel@tonic-gate  * Returns:
2597c478bd9Sstevel@tonic-gate  *   0        - Success.
2607c478bd9Sstevel@tonic-gate  *   < 0      - An error occurred.  It was probably an error in allocating
2617c478bd9Sstevel@tonic-gate  *              memory.  The error will be set in the error stack.  Call
2627c478bd9Sstevel@tonic-gate  *              ERR_get_error() to get specific information.
2637c478bd9Sstevel@tonic-gate  */
2647c478bd9Sstevel@tonic-gate int sunw_set_localkeyid(const char *, int, EVP_PKEY *, X509 *);
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate /*
2687c478bd9Sstevel@tonic-gate  * sunw_get_pkey_localkeyid() gets the localkeyid from a private key.  It can
2697c478bd9Sstevel@tonic-gate  *     optionally remove the value found.
2707c478bd9Sstevel@tonic-gate  *
2717c478bd9Sstevel@tonic-gate  * Arguments:
2727c478bd9Sstevel@tonic-gate  *   dowhat   - What to do with the attributes (remove them or copy them).
2737c478bd9Sstevel@tonic-gate  *   pkey     - Points to a private key to set the keyidstr in.
2747c478bd9Sstevel@tonic-gate  *   keyid_str- Points to a location which will receive the pointer to
2757c478bd9Sstevel@tonic-gate  *              a byte string containing the binary localkeyid.  Note that
2767c478bd9Sstevel@tonic-gate  *              this is a copy, and the caller must free it.
2777c478bd9Sstevel@tonic-gate  *   keyid_len- Length of keyid_str.
2787c478bd9Sstevel@tonic-gate  *
2797c478bd9Sstevel@tonic-gate  * Returns:
2807c478bd9Sstevel@tonic-gate  *   >= 0     - The number of characters in the keyid returned.
2817c478bd9Sstevel@tonic-gate  *   < 0      - An error occurred.  It was probably an error in allocating
2827c478bd9Sstevel@tonic-gate  *              memory.  The error will be set in the error stack.  Call
2837c478bd9Sstevel@tonic-gate  *              ERR_get_error() to get specific information.
2847c478bd9Sstevel@tonic-gate  */
2857c478bd9Sstevel@tonic-gate int sunw_get_pkey_localkeyid(getdo_actions_t, EVP_PKEY *, char **, int *);
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate /*
2897c478bd9Sstevel@tonic-gate  * sunw_get_pkey_fname() gets the friendlyName from a private key.  It can
2907c478bd9Sstevel@tonic-gate  *     optionally remove the value found.
2917c478bd9Sstevel@tonic-gate  *
2927c478bd9Sstevel@tonic-gate  * Arguments:
2937c478bd9Sstevel@tonic-gate  *   dowhat   - What to do with the attributes (remove them or just return
2947c478bd9Sstevel@tonic-gate  *              them).
2957c478bd9Sstevel@tonic-gate  *   pkey     - Points to a private key to get the keyid from
2967c478bd9Sstevel@tonic-gate  *   fname    - Points to a location which will receive the pointer to a
2977c478bd9Sstevel@tonic-gate  *              byte string with the ASCII friendlyname
2987c478bd9Sstevel@tonic-gate  *
2997c478bd9Sstevel@tonic-gate  * Returns:
3007c478bd9Sstevel@tonic-gate  *   >= 0     - The number of characters in the keyid returned.
3017c478bd9Sstevel@tonic-gate  *   < 0      - An error occurred.  It was probably an error in allocating
3027c478bd9Sstevel@tonic-gate  *              memory.  The error will be set in the error stack.  Call
3037c478bd9Sstevel@tonic-gate  *              ERR_get_error() to get specific information.
3047c478bd9Sstevel@tonic-gate  */
3057c478bd9Sstevel@tonic-gate int sunw_get_pkey_fname(getdo_actions_t, EVP_PKEY *, char **);
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate /*
3097c478bd9Sstevel@tonic-gate  * sunw_find_localkeyid() searches stacks of certs and private keys, and
3107c478bd9Sstevel@tonic-gate  *     returns the first matching cert/private key found.
3117c478bd9Sstevel@tonic-gate  *
3127c478bd9Sstevel@tonic-gate  * Look for a keyid in a stack of certs.  if 'certs' is NULL and 'pkeys' is
3137c478bd9Sstevel@tonic-gate  * not NULL, search the list of private keys.  Move the matching cert to
3147c478bd9Sstevel@tonic-gate  * 'matching_cert' and its matching private key to 'matching_pkey'.  If no
3157c478bd9Sstevel@tonic-gate  * cert or keys match, no match occurred.
3167c478bd9Sstevel@tonic-gate  *
3177c478bd9Sstevel@tonic-gate  * Arguments:
3187c478bd9Sstevel@tonic-gate  *   keyid_str- A byte string with the localkeyid to match
3197c478bd9Sstevel@tonic-gate  *   keyid_len- Length of the keyid byte string.
3207c478bd9Sstevel@tonic-gate  *   pkeys    - Points to a stack of private keys which match the certs.
3217c478bd9Sstevel@tonic-gate  *              This may be NULL, in which case no keys are returned.
3227c478bd9Sstevel@tonic-gate  *   certs    - Points to a stack of certs to search.  If NULL, search the
3237c478bd9Sstevel@tonic-gate  *              stack of keys instead.
3247c478bd9Sstevel@tonic-gate  *   matching_pkey
3257c478bd9Sstevel@tonic-gate  *            - Pointer to receive address of first matching pkey found.
3267c478bd9Sstevel@tonic-gate  *              'matching_pkey' must not be NULL; '*matching_pkey' will be
3277c478bd9Sstevel@tonic-gate  *              reset.
3287c478bd9Sstevel@tonic-gate  *   matching_cert
3297c478bd9Sstevel@tonic-gate  *            - Pointer to receive address of first matching cert found.
3307c478bd9Sstevel@tonic-gate  *              'matching_cert' must not be NULL; '*matching_cert' will be
3317c478bd9Sstevel@tonic-gate  *              reset.
3327c478bd9Sstevel@tonic-gate  *
3337c478bd9Sstevel@tonic-gate  * Returns:
3347c478bd9Sstevel@tonic-gate  *  <  0 - An error returned.  Call ERR_get_error() to get errors information.
3357c478bd9Sstevel@tonic-gate  *         Where possible, memory has been freed.
3367c478bd9Sstevel@tonic-gate  *  >= 0 - Objects were found and returned.  Which objects are indicated by
3377c478bd9Sstevel@tonic-gate  *         which bits are set (FOUND_PKEY and/or FOUND_CERT).
3387c478bd9Sstevel@tonic-gate  */
3397c478bd9Sstevel@tonic-gate int sunw_find_localkeyid(char *, int, STACK_OF(EVP_PKEY) *, STACK_OF(X509) *,
3407c478bd9Sstevel@tonic-gate     EVP_PKEY **, X509 **);
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate /*
3447c478bd9Sstevel@tonic-gate  * sunw_find_fname() searches stacks of certs and private keys for one with
3457c478bd9Sstevel@tonic-gate  *     a matching friendlyname and returns the first matching cert/private
3467c478bd9Sstevel@tonic-gate  *     key found.
3477c478bd9Sstevel@tonic-gate  *
3487c478bd9Sstevel@tonic-gate  * Look for a friendlyname in a stack of certs.  if 'certs' is NULL and 'pkeys'
3497c478bd9Sstevel@tonic-gate  * is not NULL, search the list of private keys.  Move the matching cert to
3507c478bd9Sstevel@tonic-gate  * 'matching_cert' and its matching private key to 'matching_pkey'.  If no
3517c478bd9Sstevel@tonic-gate  * cert or keys match, no match occurred.
3527c478bd9Sstevel@tonic-gate  *
3537c478bd9Sstevel@tonic-gate  * Arguments:
3547c478bd9Sstevel@tonic-gate  *   fname    - Friendlyname to find (NULL-terminated ASCII string).
3557c478bd9Sstevel@tonic-gate  *   pkeys    - Points to a stack of private keys which match the certs.
3567c478bd9Sstevel@tonic-gate  *              This may be NULL, in which case no keys are returned.
3577c478bd9Sstevel@tonic-gate  *   certs    - Points to a stack of certs to search.  If NULL, search the
3587c478bd9Sstevel@tonic-gate  *              stack of keys instead.
3597c478bd9Sstevel@tonic-gate  *   matching_pkey
3607c478bd9Sstevel@tonic-gate  *            - Pointer to receive address of first matching pkey found.
3617c478bd9Sstevel@tonic-gate  *   matching_cert
3627c478bd9Sstevel@tonic-gate  *            - Pointer to receive address of first matching cert found.
3637c478bd9Sstevel@tonic-gate  *
3647c478bd9Sstevel@tonic-gate  * Returns:
3657c478bd9Sstevel@tonic-gate  *  <  0 - An error returned.  Call ERR_get_error() to get errors information.
3667c478bd9Sstevel@tonic-gate  *         Where possible, memory has been freed.
3677c478bd9Sstevel@tonic-gate  *  >= 0 - Objects were found and returned.  Which objects are indicated by
3687c478bd9Sstevel@tonic-gate  *         which bits are set (FOUND_PKEY and/or FOUND_CERT).
3697c478bd9Sstevel@tonic-gate  */
3707c478bd9Sstevel@tonic-gate int sunw_find_fname(char *, STACK_OF(EVP_PKEY) *, STACK_OF(X509) *, EVP_PKEY **,
3717c478bd9Sstevel@tonic-gate     X509 **);
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate /*
3757c478bd9Sstevel@tonic-gate  * sunw_print_times() formats and prints cert times to the given file.
3767c478bd9Sstevel@tonic-gate  *
3777c478bd9Sstevel@tonic-gate  * The label is printed on one line. One or both dates are printed on
3787c478bd9Sstevel@tonic-gate  * the following line or two, each with it's own indented label in the
3797c478bd9Sstevel@tonic-gate  * format:
3807c478bd9Sstevel@tonic-gate  *
3817c478bd9Sstevel@tonic-gate  *    label
3827c478bd9Sstevel@tonic-gate  *      'not before' date: whatever
3837c478bd9Sstevel@tonic-gate  *      'not after' date:  whatever
3847c478bd9Sstevel@tonic-gate  *
3857c478bd9Sstevel@tonic-gate  * Arguments:
3867c478bd9Sstevel@tonic-gate  *   fp       - file pointer for file to write to.
3877c478bd9Sstevel@tonic-gate  *   dowhat   - what field(s) to print.
3887c478bd9Sstevel@tonic-gate  *   label    - Label to use.  If NULL, no line will be printed.
3897c478bd9Sstevel@tonic-gate  *   cert     - Points to a client or CA cert to check
3907c478bd9Sstevel@tonic-gate  *
3917c478bd9Sstevel@tonic-gate  * Returns:
3927c478bd9Sstevel@tonic-gate  *  <  0 - An error occured.
3937c478bd9Sstevel@tonic-gate  *  >= 0 - Number of lines written.
3947c478bd9Sstevel@tonic-gate  */
3957c478bd9Sstevel@tonic-gate int sunw_print_times(FILE *, prnt_actions_t, char *, X509 *);
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate /*
3997c478bd9Sstevel@tonic-gate  * sunw_check_keys() compares the public key in the certificate and a
4007c478bd9Sstevel@tonic-gate  *     private key to ensure that they match.
4017c478bd9Sstevel@tonic-gate  *
4027c478bd9Sstevel@tonic-gate  * Arguments:
4037c478bd9Sstevel@tonic-gate  *   cert     - Points to a certificate.
4047c478bd9Sstevel@tonic-gate  *   pkey     - Points to a private key.
4057c478bd9Sstevel@tonic-gate  *
4067c478bd9Sstevel@tonic-gate  * Returns:
4077c478bd9Sstevel@tonic-gate  *  == 0 - These do not match.
4087c478bd9Sstevel@tonic-gate  *  != 0 - The cert's public key and the private key match.
4097c478bd9Sstevel@tonic-gate  */
4107c478bd9Sstevel@tonic-gate int sunw_check_keys(X509 *, EVP_PKEY *);
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate /*
4147c478bd9Sstevel@tonic-gate  * sunw_issuer_attrs - Given a cert, return the issuer-specific attributes
4157c478bd9Sstevel@tonic-gate  *     as one ASCII string.
4167c478bd9Sstevel@tonic-gate  *
4177c478bd9Sstevel@tonic-gate  * Arguments:
4187c478bd9Sstevel@tonic-gate  *   cert     - Cert to process
4197c478bd9Sstevel@tonic-gate  *   buf      - If non-NULL, buffer to receive string.  If NULL, one will
4207c478bd9Sstevel@tonic-gate  *              be allocated and its value will be returned to the caller.
4217c478bd9Sstevel@tonic-gate  *   len      - If 'buff' is non-null, the buffer's length.
4227c478bd9Sstevel@tonic-gate  *
4237c478bd9Sstevel@tonic-gate  * This returns an ASCII string with all issuer-related attributes in one
4247c478bd9Sstevel@tonic-gate  * string separated by '/' characters.  Each attribute begins with its name
4257c478bd9Sstevel@tonic-gate  * and an equal sign.  Two attributes (ATTR1 and Attr2) would have the
4267c478bd9Sstevel@tonic-gate  * following form:
4277c478bd9Sstevel@tonic-gate  *
4287c478bd9Sstevel@tonic-gate  *         ATTR1=attr_value/ATTR2=attr2_value
4297c478bd9Sstevel@tonic-gate  *
4307c478bd9Sstevel@tonic-gate  * Returns:
4317c478bd9Sstevel@tonic-gate  *   != NULL  - Pointer to the ASCII string containing the issuer-related
4327c478bd9Sstevel@tonic-gate  *              attributes.  If the 'buf' argument was NULL, this is a
4337c478bd9Sstevel@tonic-gate  *              dynamically-allocated buffer and the caller will have the
4347c478bd9Sstevel@tonic-gate  *              responsibility for freeing it.
4357c478bd9Sstevel@tonic-gate  *   NULL     - Memory needed to be allocated but could not be.  Errors
4367c478bd9Sstevel@tonic-gate  *              are set on the error stack.
4377c478bd9Sstevel@tonic-gate  */
4387c478bd9Sstevel@tonic-gate char *sunw_issuer_attrs(X509 *cert, char *buf, int len);
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate /*
4427c478bd9Sstevel@tonic-gate  * sunw_subject_attrs - Given a cert, return the subject-specific attributes
4437c478bd9Sstevel@tonic-gate  *     as one ASCII string.
4447c478bd9Sstevel@tonic-gate  *
4457c478bd9Sstevel@tonic-gate  * Arguments:
4467c478bd9Sstevel@tonic-gate  *   cert     - Cert to process
4477c478bd9Sstevel@tonic-gate  *   buf      - If non-NULL, buffer to receive string.  If NULL, one will
4487c478bd9Sstevel@tonic-gate  *              be allocated and its value will be returned to the caller.
4497c478bd9Sstevel@tonic-gate  *   len      - If 'buff' is non-null, the buffer's length.
4507c478bd9Sstevel@tonic-gate  *
4517c478bd9Sstevel@tonic-gate  * This returns an ASCII string with all subject-related attributes in one
4527c478bd9Sstevel@tonic-gate  * string separated by '/' characters.  Each attribute begins with its name
4537c478bd9Sstevel@tonic-gate  * and an equal sign.  Two attributes (ATTR1 and Attr2) would have the
4547c478bd9Sstevel@tonic-gate  * following form:
4557c478bd9Sstevel@tonic-gate  *
4567c478bd9Sstevel@tonic-gate  *         ATTR1=attr_value/ATTR2=attr2_value
4577c478bd9Sstevel@tonic-gate  *
4587c478bd9Sstevel@tonic-gate  * Returns:
4597c478bd9Sstevel@tonic-gate  *   != NULL  - Pointer to the ASCII string containing the subject-related
4607c478bd9Sstevel@tonic-gate  *              attributes.  If the 'buf' argument was NULL, this is a
4617c478bd9Sstevel@tonic-gate  *              dynamically-allocated buffer and the caller will have the
4627c478bd9Sstevel@tonic-gate  *              responsibility for freeing it.
4637c478bd9Sstevel@tonic-gate  *   NULL     - Memory needed to be allocated but could not be.  Errors
4647c478bd9Sstevel@tonic-gate  *              are set on the error stack.
4657c478bd9Sstevel@tonic-gate  */
4667c478bd9Sstevel@tonic-gate char *sunw_subject_attrs(X509 *cert, char *buf, int len);
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate /*
4697c478bd9Sstevel@tonic-gate  * sunw_append_keys - Given two stacks of private keys, remove the keys from
4707c478bd9Sstevel@tonic-gate  *      the second stack and append them to the first.  Both stacks must exist
4717c478bd9Sstevel@tonic-gate  *      at time of call.
4727c478bd9Sstevel@tonic-gate  *
4737c478bd9Sstevel@tonic-gate  * Arguments:
4747c478bd9Sstevel@tonic-gate  *   dst 	- the stack to receive the keys from 'src'
4757c478bd9Sstevel@tonic-gate  *   src	- the stack whose keys are to be moved.
4767c478bd9Sstevel@tonic-gate  *
4777c478bd9Sstevel@tonic-gate  * Returns:
4787c478bd9Sstevel@tonic-gate  *   -1  	- An error occurred.  The error status is set.
4797c478bd9Sstevel@tonic-gate  *   >= 0       - The number of keys that were copied.
4807c478bd9Sstevel@tonic-gate  */
4817c478bd9Sstevel@tonic-gate int sunw_append_keys(STACK_OF(EVP_PKEY) *, STACK_OF(EVP_PKEY) *);
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4857c478bd9Sstevel@tonic-gate }
4867c478bd9Sstevel@tonic-gate #endif
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate #endif	/* _P12AUX_H */
489