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