1*9781SMoriah.Waterland@Sun.COM /* 2*9781SMoriah.Waterland@Sun.COM * ==================================================================== 3*9781SMoriah.Waterland@Sun.COM * Copyright (c) 1999 The OpenSSL Project. All rights reserved. 4*9781SMoriah.Waterland@Sun.COM * 5*9781SMoriah.Waterland@Sun.COM * Redistribution and use in source and binary forms, with or without 6*9781SMoriah.Waterland@Sun.COM * modification, are permitted provided that the following conditions 7*9781SMoriah.Waterland@Sun.COM * are met: 8*9781SMoriah.Waterland@Sun.COM * 9*9781SMoriah.Waterland@Sun.COM * 1. Redistributions of source code must retain the above copyright 10*9781SMoriah.Waterland@Sun.COM * notice, this list of conditions and the following disclaimer. 11*9781SMoriah.Waterland@Sun.COM * 12*9781SMoriah.Waterland@Sun.COM * 2. Redistributions in binary form must reproduce the above copyright 13*9781SMoriah.Waterland@Sun.COM * notice, this list of conditions and the following disclaimer in 14*9781SMoriah.Waterland@Sun.COM * the documentation and/or other materials provided with the 15*9781SMoriah.Waterland@Sun.COM * distribution. 16*9781SMoriah.Waterland@Sun.COM * 17*9781SMoriah.Waterland@Sun.COM * 3. All advertising materials mentioning features or use of this 18*9781SMoriah.Waterland@Sun.COM * software must display the following acknowledgment: 19*9781SMoriah.Waterland@Sun.COM * "This product includes software developed by the OpenSSL Project 20*9781SMoriah.Waterland@Sun.COM * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 21*9781SMoriah.Waterland@Sun.COM * 22*9781SMoriah.Waterland@Sun.COM * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 23*9781SMoriah.Waterland@Sun.COM * endorse or promote products derived from this software without 24*9781SMoriah.Waterland@Sun.COM * prior written permission. For written permission, please contact 25*9781SMoriah.Waterland@Sun.COM * licensing@OpenSSL.org. 26*9781SMoriah.Waterland@Sun.COM * 27*9781SMoriah.Waterland@Sun.COM * 5. Products derived from this software may not be called "OpenSSL" 28*9781SMoriah.Waterland@Sun.COM * nor may "OpenSSL" appear in their names without prior written 29*9781SMoriah.Waterland@Sun.COM * permission of the OpenSSL Project. 30*9781SMoriah.Waterland@Sun.COM * 31*9781SMoriah.Waterland@Sun.COM * 6. Redistributions of any form whatsoever must retain the following 32*9781SMoriah.Waterland@Sun.COM * acknowledgment: 33*9781SMoriah.Waterland@Sun.COM * "This product includes software developed by the OpenSSL Project 34*9781SMoriah.Waterland@Sun.COM * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 35*9781SMoriah.Waterland@Sun.COM * 36*9781SMoriah.Waterland@Sun.COM * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 37*9781SMoriah.Waterland@Sun.COM * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38*9781SMoriah.Waterland@Sun.COM * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 39*9781SMoriah.Waterland@Sun.COM * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 40*9781SMoriah.Waterland@Sun.COM * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41*9781SMoriah.Waterland@Sun.COM * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 42*9781SMoriah.Waterland@Sun.COM * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 43*9781SMoriah.Waterland@Sun.COM * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 44*9781SMoriah.Waterland@Sun.COM * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 45*9781SMoriah.Waterland@Sun.COM * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 46*9781SMoriah.Waterland@Sun.COM * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 47*9781SMoriah.Waterland@Sun.COM * OF THE POSSIBILITY OF SUCH DAMAGE. 48*9781SMoriah.Waterland@Sun.COM * ==================================================================== 49*9781SMoriah.Waterland@Sun.COM * 50*9781SMoriah.Waterland@Sun.COM * This product includes cryptographic software written by Eric Young 51*9781SMoriah.Waterland@Sun.COM * (eay@cryptsoft.com). This product includes software written by Tim 52*9781SMoriah.Waterland@Sun.COM * Hudson (tjh@cryptsoft.com). 53*9781SMoriah.Waterland@Sun.COM * 54*9781SMoriah.Waterland@Sun.COM */ 55*9781SMoriah.Waterland@Sun.COM 56*9781SMoriah.Waterland@Sun.COM /* 57*9781SMoriah.Waterland@Sun.COM * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 58*9781SMoriah.Waterland@Sun.COM * Use is subject to license terms. 59*9781SMoriah.Waterland@Sun.COM */ 60*9781SMoriah.Waterland@Sun.COM 61*9781SMoriah.Waterland@Sun.COM #ifndef _P12LIB_H 62*9781SMoriah.Waterland@Sun.COM #define _P12LIB_H 63*9781SMoriah.Waterland@Sun.COM 64*9781SMoriah.Waterland@Sun.COM 65*9781SMoriah.Waterland@Sun.COM #include <openssl/pkcs12.h> 66*9781SMoriah.Waterland@Sun.COM #include <openssl/pem.h> 67*9781SMoriah.Waterland@Sun.COM 68*9781SMoriah.Waterland@Sun.COM /* 69*9781SMoriah.Waterland@Sun.COM * PKCS12 file routines borrowed from SNT's libwanboot. 70*9781SMoriah.Waterland@Sun.COM */ 71*9781SMoriah.Waterland@Sun.COM 72*9781SMoriah.Waterland@Sun.COM #ifdef __cplusplus 73*9781SMoriah.Waterland@Sun.COM extern "C" { 74*9781SMoriah.Waterland@Sun.COM #endif 75*9781SMoriah.Waterland@Sun.COM 76*9781SMoriah.Waterland@Sun.COM /* These declarations allow us to make stacks of EVP_PKEY objects */ 77*9781SMoriah.Waterland@Sun.COM DECLARE_STACK_OF(EVP_PKEY) 78*9781SMoriah.Waterland@Sun.COM #define sk_EVP_PKEY_new_null() SKM_sk_new_null(EVP_PKEY) 79*9781SMoriah.Waterland@Sun.COM #define sk_EVP_PKEY_free(st) SKM_sk_free(EVP_PKEY, (st)) 80*9781SMoriah.Waterland@Sun.COM #define sk_EVP_PKEY_num(st) SKM_sk_num(EVP_PKEY, (st)) 81*9781SMoriah.Waterland@Sun.COM #define sk_EVP_PKEY_value(st, i) SKM_sk_value(EVP_PKEY, (st), (i)) 82*9781SMoriah.Waterland@Sun.COM #define sk_EVP_PKEY_push(st, val) SKM_sk_push(EVP_PKEY, (st), (val)) 83*9781SMoriah.Waterland@Sun.COM #define sk_EVP_PKEY_find(st, val) SKM_sk_find(EVP_PKEY, (st), (val)) 84*9781SMoriah.Waterland@Sun.COM #define sk_EVP_PKEY_delete(st, i) SKM_sk_delete(EVP_PKEY, (st), (i)) 85*9781SMoriah.Waterland@Sun.COM #define sk_EVP_PKEY_delete_ptr(st, ptr) SKM_sk_delete_ptr(EVP_PKEY, (st), (ptr)) 86*9781SMoriah.Waterland@Sun.COM #define sk_EVP_PKEY_insert(st, val, i) SKM_sk_insert(EVP_PKEY, (st), (val), (i)) 87*9781SMoriah.Waterland@Sun.COM #define sk_EVP_PKEY_pop_free(st, free_func) SKM_sk_pop_free(EVP_PKEY, (st), \ 88*9781SMoriah.Waterland@Sun.COM (free_func)) 89*9781SMoriah.Waterland@Sun.COM #define sk_EVP_PKEY_pop(st) SKM_sk_pop(EVP_PKEY, (st)) 90*9781SMoriah.Waterland@Sun.COM 91*9781SMoriah.Waterland@Sun.COM /* Error reporting routines required by OpenSSL */ 92*9781SMoriah.Waterland@Sun.COM #define SUNW_LIB_NAME "SUNW_PKCS12" 93*9781SMoriah.Waterland@Sun.COM #define SUNWerr(f, r) ERR_SUNW_error((f), (r), __FILE__, __LINE__) 94*9781SMoriah.Waterland@Sun.COM 95*9781SMoriah.Waterland@Sun.COM /* Error codes for the SUNW functions. */ 96*9781SMoriah.Waterland@Sun.COM /* OpenSSL prefers codes to start at 100 */ 97*9781SMoriah.Waterland@Sun.COM 98*9781SMoriah.Waterland@Sun.COM /* Function codes. */ 99*9781SMoriah.Waterland@Sun.COM typedef enum { 100*9781SMoriah.Waterland@Sun.COM SUNW_F_USE_X509CERT = 100, 101*9781SMoriah.Waterland@Sun.COM SUNW_F_USE_PKEY, 102*9781SMoriah.Waterland@Sun.COM SUNW_F_USE_TASTORE, 103*9781SMoriah.Waterland@Sun.COM SUNW_F_USE_CERTFILE, 104*9781SMoriah.Waterland@Sun.COM SUNW_F_USE_KEYFILE, 105*9781SMoriah.Waterland@Sun.COM SUNW_F_USE_TRUSTFILE, 106*9781SMoriah.Waterland@Sun.COM SUNW_F_READ_FILE, 107*9781SMoriah.Waterland@Sun.COM SUNW_F_DOPARSE, 108*9781SMoriah.Waterland@Sun.COM SUNW_F_PKCS12_PARSE, 109*9781SMoriah.Waterland@Sun.COM SUNW_F_PKCS12_CONTENTS, 110*9781SMoriah.Waterland@Sun.COM SUNW_F_PARSE_ONE_BAG, 111*9781SMoriah.Waterland@Sun.COM SUNW_F_PKCS12_CREATE, 112*9781SMoriah.Waterland@Sun.COM SUNW_F_SPLIT_CERTS, 113*9781SMoriah.Waterland@Sun.COM SUNW_F_FIND_LOCALKEYID, 114*9781SMoriah.Waterland@Sun.COM SUNW_F_SET_LOCALKEYID, 115*9781SMoriah.Waterland@Sun.COM SUNW_F_SET_FNAME, 116*9781SMoriah.Waterland@Sun.COM SUNW_F_GET_LOCALKEYID, 117*9781SMoriah.Waterland@Sun.COM SUNW_F_GET_PKEY_FNAME, 118*9781SMoriah.Waterland@Sun.COM SUNW_F_APPEND_KEYS, 119*9781SMoriah.Waterland@Sun.COM SUNW_F_PEM_CONTENTS, 120*9781SMoriah.Waterland@Sun.COM SUNW_F_PEM_INFO, 121*9781SMoriah.Waterland@Sun.COM SUNW_F_ASC2BMPSTRING, 122*9781SMoriah.Waterland@Sun.COM SUNW_F_UTF82ASCSTR, 123*9781SMoriah.Waterland@Sun.COM SUNW_F_FINDATTR, 124*9781SMoriah.Waterland@Sun.COM SUNW_F_TYPE2ATTRIB, 125*9781SMoriah.Waterland@Sun.COM SUNW_F_MOVE_CERTS, 126*9781SMoriah.Waterland@Sun.COM SUNW_F_FIND_FNAME, 127*9781SMoriah.Waterland@Sun.COM SUNW_F_PARSE_OUTER, 128*9781SMoriah.Waterland@Sun.COM SUNW_F_CHECKFILE 129*9781SMoriah.Waterland@Sun.COM } sunw_err_func_t; 130*9781SMoriah.Waterland@Sun.COM 131*9781SMoriah.Waterland@Sun.COM /* Reason codes. */ 132*9781SMoriah.Waterland@Sun.COM typedef enum { 133*9781SMoriah.Waterland@Sun.COM SUNW_R_INVALID_ARG = 100, 134*9781SMoriah.Waterland@Sun.COM SUNW_R_MEMORY_FAILURE, 135*9781SMoriah.Waterland@Sun.COM SUNW_R_MAC_VERIFY_FAILURE, 136*9781SMoriah.Waterland@Sun.COM SUNW_R_MAC_CREATE_FAILURE, 137*9781SMoriah.Waterland@Sun.COM SUNW_R_BAD_FILETYPE, 138*9781SMoriah.Waterland@Sun.COM SUNW_R_BAD_PKEY, 139*9781SMoriah.Waterland@Sun.COM SUNW_R_BAD_PKEYTYPE, 140*9781SMoriah.Waterland@Sun.COM SUNW_R_PKEY_READ_ERR, 141*9781SMoriah.Waterland@Sun.COM SUNW_R_NO_TRUST_ANCHOR, 142*9781SMoriah.Waterland@Sun.COM SUNW_R_READ_TRUST_ERR, 143*9781SMoriah.Waterland@Sun.COM SUNW_R_ADD_TRUST_ERR, 144*9781SMoriah.Waterland@Sun.COM SUNW_R_PKCS12_PARSE_ERR, 145*9781SMoriah.Waterland@Sun.COM SUNW_R_PKCS12_CREATE_ERR, 146*9781SMoriah.Waterland@Sun.COM SUNW_R_PARSE_BAG_ERR, 147*9781SMoriah.Waterland@Sun.COM SUNW_R_MAKE_BAG_ERR, 148*9781SMoriah.Waterland@Sun.COM SUNW_R_BAD_CERTTYPE, 149*9781SMoriah.Waterland@Sun.COM SUNW_R_PARSE_CERT_ERR, 150*9781SMoriah.Waterland@Sun.COM SUNW_R_BAD_LKID, 151*9781SMoriah.Waterland@Sun.COM SUNW_R_SET_LKID_ERR, 152*9781SMoriah.Waterland@Sun.COM SUNW_R_BAD_FNAME, 153*9781SMoriah.Waterland@Sun.COM SUNW_R_SET_FNAME_ERR, 154*9781SMoriah.Waterland@Sun.COM SUNW_R_BAD_TRUST, 155*9781SMoriah.Waterland@Sun.COM SUNW_R_BAD_BAGTYPE, 156*9781SMoriah.Waterland@Sun.COM SUNW_R_CERT_ERR, 157*9781SMoriah.Waterland@Sun.COM SUNW_R_PKEY_ERR, 158*9781SMoriah.Waterland@Sun.COM SUNW_R_READ_ERR, 159*9781SMoriah.Waterland@Sun.COM SUNW_R_ADD_ATTR_ERR, 160*9781SMoriah.Waterland@Sun.COM SUNW_R_STR_CONVERT_ERR, 161*9781SMoriah.Waterland@Sun.COM SUNW_R_PKCS12_EMPTY_ERR, 162*9781SMoriah.Waterland@Sun.COM SUNW_R_PASSWORD_ERR 163*9781SMoriah.Waterland@Sun.COM } sunw_err_reason_t; 164*9781SMoriah.Waterland@Sun.COM 165*9781SMoriah.Waterland@Sun.COM /* 166*9781SMoriah.Waterland@Sun.COM * Type of checking to perform when calling sunw_check_cert_times 167*9781SMoriah.Waterland@Sun.COM */ 168*9781SMoriah.Waterland@Sun.COM typedef enum { 169*9781SMoriah.Waterland@Sun.COM CHK_NOT_BEFORE = 1, /* Check 'not before' date */ 170*9781SMoriah.Waterland@Sun.COM CHK_NOT_AFTER, /* Check 'not after' date */ 171*9781SMoriah.Waterland@Sun.COM CHK_BOTH /* Check both dates */ 172*9781SMoriah.Waterland@Sun.COM } chk_actions_t; 173*9781SMoriah.Waterland@Sun.COM 174*9781SMoriah.Waterland@Sun.COM /* 175*9781SMoriah.Waterland@Sun.COM * Return type for sunw_check_cert_times 176*9781SMoriah.Waterland@Sun.COM */ 177*9781SMoriah.Waterland@Sun.COM typedef enum { 178*9781SMoriah.Waterland@Sun.COM CHKERR_TIME_OK = 0, /* Current time meets requested checks */ 179*9781SMoriah.Waterland@Sun.COM CHKERR_TIME_BEFORE_BAD, /* 'not before' field is invalid */ 180*9781SMoriah.Waterland@Sun.COM CHKERR_TIME_AFTER_BAD, /* 'not after' field is invalid */ 181*9781SMoriah.Waterland@Sun.COM CHKERR_TIME_IS_BEFORE, /* Current time is before 'not before' */ 182*9781SMoriah.Waterland@Sun.COM CHKERR_TIME_HAS_EXPIRED /* Current time is after 'not after' */ 183*9781SMoriah.Waterland@Sun.COM } chk_errs_t; 184*9781SMoriah.Waterland@Sun.COM 185*9781SMoriah.Waterland@Sun.COM /* 186*9781SMoriah.Waterland@Sun.COM * This type indicates what to do with an attribute being returned. 187*9781SMoriah.Waterland@Sun.COM */ 188*9781SMoriah.Waterland@Sun.COM typedef enum { 189*9781SMoriah.Waterland@Sun.COM GETDO_COPY = 1, /* Simply return the value of the attribute */ 190*9781SMoriah.Waterland@Sun.COM GETDO_DEL /* Delete the attribute at the same time. */ 191*9781SMoriah.Waterland@Sun.COM } getdo_actions_t; 192*9781SMoriah.Waterland@Sun.COM 193*9781SMoriah.Waterland@Sun.COM /* 194*9781SMoriah.Waterland@Sun.COM * For sunw_pkcs12_parse, the following are values for bits that indicate 195*9781SMoriah.Waterland@Sun.COM * various types of searches/matching to do. Any of these values can be 196*9781SMoriah.Waterland@Sun.COM * OR'd together. However, the order in which an attempt will be made 197*9781SMoriah.Waterland@Sun.COM * to satisfy them is the order in which they are listed below. The 198*9781SMoriah.Waterland@Sun.COM * exception is DO_NONE. It should not be OR'd with any other value. 199*9781SMoriah.Waterland@Sun.COM */ 200*9781SMoriah.Waterland@Sun.COM #define DO_NONE 0x00 /* Don't even try to match */ 201*9781SMoriah.Waterland@Sun.COM #define DO_FIND_KEYID 0x01 /* 1st cert, key with matching localkeyid */ 202*9781SMoriah.Waterland@Sun.COM #define DO_FIND_FN 0x02 /* 1st cert, key with matching friendlyname */ 203*9781SMoriah.Waterland@Sun.COM #define DO_FIRST_PAIR 0x04 /* Return first matching cert/key pair found */ 204*9781SMoriah.Waterland@Sun.COM #define DO_LAST_PAIR 0x08 /* Return last matching cert/key pair found */ 205*9781SMoriah.Waterland@Sun.COM #define DO_UNMATCHING 0x10 /* Return first cert and/or key */ 206*9781SMoriah.Waterland@Sun.COM 207*9781SMoriah.Waterland@Sun.COM /* Bits returned, which indicate what values were found. */ 208*9781SMoriah.Waterland@Sun.COM #define FOUND_PKEY 0x01 /* Found one or more private key */ 209*9781SMoriah.Waterland@Sun.COM #define FOUND_CERT 0x02 /* Found one or more client certificate */ 210*9781SMoriah.Waterland@Sun.COM #define FOUND_CA_CERTS 0x04 /* Added at least one cert to the CA list */ 211*9781SMoriah.Waterland@Sun.COM #define FOUND_XPKEY 0x08 /* Found at least one private key which does */ 212*9781SMoriah.Waterland@Sun.COM /* not match a certificate in the certs list */ 213*9781SMoriah.Waterland@Sun.COM 214*9781SMoriah.Waterland@Sun.COM /* p12lib.c */ 215*9781SMoriah.Waterland@Sun.COM PKCS12 *sunw_PKCS12_create(const char *, STACK_OF(EVP_PKEY) *, 216*9781SMoriah.Waterland@Sun.COM STACK_OF(X509) *, STACK_OF(X509) *); 217*9781SMoriah.Waterland@Sun.COM 218*9781SMoriah.Waterland@Sun.COM int sunw_split_certs(STACK_OF(EVP_PKEY) *, STACK_OF(X509) *, 219*9781SMoriah.Waterland@Sun.COM STACK_OF(X509) **, STACK_OF(EVP_PKEY) **); 220*9781SMoriah.Waterland@Sun.COM 221*9781SMoriah.Waterland@Sun.COM void sunw_evp_pkey_free(EVP_PKEY *); 222*9781SMoriah.Waterland@Sun.COM int sunw_set_localkeyid(const char *, int, EVP_PKEY *, X509 *); 223*9781SMoriah.Waterland@Sun.COM int sunw_get_pkey_localkeyid(getdo_actions_t, EVP_PKEY *, char **, int *); 224*9781SMoriah.Waterland@Sun.COM int sunw_get_pkey_fname(getdo_actions_t, EVP_PKEY *, char **); 225*9781SMoriah.Waterland@Sun.COM int sunw_find_localkeyid(char *, int, STACK_OF(EVP_PKEY) *, 226*9781SMoriah.Waterland@Sun.COM STACK_OF(X509) *, EVP_PKEY **, X509 **); 227*9781SMoriah.Waterland@Sun.COM int sunw_find_fname(char *, STACK_OF(EVP_PKEY) *, STACK_OF(X509) *, 228*9781SMoriah.Waterland@Sun.COM EVP_PKEY **, X509 **); 229*9781SMoriah.Waterland@Sun.COM int sunw_set_fname(const char *, EVP_PKEY *, X509 *); 230*9781SMoriah.Waterland@Sun.COM int sunw_check_keys(X509 *, EVP_PKEY *); 231*9781SMoriah.Waterland@Sun.COM 232*9781SMoriah.Waterland@Sun.COM chk_errs_t sunw_check_cert_times(chk_actions_t, X509 *); 233*9781SMoriah.Waterland@Sun.COM extern void ERR_SUNW_error(int function, int reason, char *file, int line); 234*9781SMoriah.Waterland@Sun.COM extern void ERR_load_SUNW_strings(void); 235*9781SMoriah.Waterland@Sun.COM int sunw_PKCS12_contents(PKCS12 *, const char *, 236*9781SMoriah.Waterland@Sun.COM STACK_OF(EVP_PKEY) **, STACK_OF(X509) **); 237*9781SMoriah.Waterland@Sun.COM int sunw_get_cert_fname(getdo_actions_t, X509 *, char **); 238*9781SMoriah.Waterland@Sun.COM int sunw_PEM_contents(FILE *, pem_password_cb, void *, 239*9781SMoriah.Waterland@Sun.COM STACK_OF(EVP_PKEY) **, STACK_OF(X509) **); 240*9781SMoriah.Waterland@Sun.COM 241*9781SMoriah.Waterland@Sun.COM #ifdef __cplusplus 242*9781SMoriah.Waterland@Sun.COM } 243*9781SMoriah.Waterland@Sun.COM #endif 244*9781SMoriah.Waterland@Sun.COM 245*9781SMoriah.Waterland@Sun.COM #endif /* _P12LIB_H */ 246