2N/A/*
2N/A * ====================================================================
2N/A * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
2N/A *
2N/A * Redistribution and use in source and binary forms, with or without
2N/A * modification, are permitted provided that the following conditions
2N/A * are met:
2N/A *
2N/A * 1. Redistributions of source code must retain the above copyright
2N/A * notice, this list of conditions and the following disclaimer.
2N/A *
2N/A * 2. Redistributions in binary form must reproduce the above copyright
2N/A * notice, this list of conditions and the following disclaimer in
2N/A * the documentation and/or other materials provided with the
2N/A * distribution.
2N/A *
2N/A * 3. All advertising materials mentioning features or use of this
2N/A * software must display the following acknowledgment:
2N/A * "This product includes software developed by the OpenSSL Project
2N/A * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
2N/A *
2N/A * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
2N/A * endorse or promote products derived from this software without
2N/A * prior written permission. For written permission, please contact
2N/A * licensing@OpenSSL.org.
2N/A *
2N/A * 5. Products derived from this software may not be called "OpenSSL"
2N/A * nor may "OpenSSL" appear in their names without prior written
2N/A * permission of the OpenSSL Project.
2N/A *
2N/A * 6. Redistributions of any form whatsoever must retain the following
2N/A * acknowledgment:
2N/A * "This product includes software developed by the OpenSSL Project
2N/A * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
2N/A *
2N/A * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
2N/A * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
2N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2N/A * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2N/A * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2N/A * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2N/A * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2N/A * OF THE POSSIBILITY OF SUCH DAMAGE.
2N/A * ====================================================================
2N/A *
2N/A * This product includes cryptographic software written by Eric Young
2N/A * (eay@cryptsoft.com). This product includes software written by Tim
2N/A * Hudson (tjh@cryptsoft.com).
2N/A *
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#ifndef _P12LIB_H
2N/A#define _P12LIB_H
2N/A
2N/A
2N/A#include <openssl/pkcs12.h>
2N/A#include <openssl/pem.h>
2N/A
2N/A/*
2N/A * PKCS12 file routines borrowed from SNT's libwanboot.
2N/A */
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/A/* These declarations allow us to make stacks of EVP_PKEY objects */
2N/ADECLARE_STACK_OF(EVP_PKEY)
2N/A#define sk_EVP_PKEY_new_null() SKM_sk_new_null(EVP_PKEY)
2N/A#define sk_EVP_PKEY_free(st) SKM_sk_free(EVP_PKEY, (st))
2N/A#define sk_EVP_PKEY_num(st) SKM_sk_num(EVP_PKEY, (st))
2N/A#define sk_EVP_PKEY_value(st, i) SKM_sk_value(EVP_PKEY, (st), (i))
2N/A#define sk_EVP_PKEY_push(st, val) SKM_sk_push(EVP_PKEY, (st), (val))
2N/A#define sk_EVP_PKEY_find(st, val) SKM_sk_find(EVP_PKEY, (st), (val))
2N/A#define sk_EVP_PKEY_delete(st, i) SKM_sk_delete(EVP_PKEY, (st), (i))
2N/A#define sk_EVP_PKEY_delete_ptr(st, ptr) SKM_sk_delete_ptr(EVP_PKEY, (st), (ptr))
2N/A#define sk_EVP_PKEY_insert(st, val, i) SKM_sk_insert(EVP_PKEY, (st), (val), (i))
2N/A#define sk_EVP_PKEY_pop_free(st, free_func) SKM_sk_pop_free(EVP_PKEY, (st), \
2N/A (free_func))
2N/A#define sk_EVP_PKEY_pop(st) SKM_sk_pop(EVP_PKEY, (st))
2N/A
2N/A/* Error reporting routines required by OpenSSL */
2N/A#define SUNW_LIB_NAME "SUNW_PKCS12"
2N/A#define SUNWerr(f, r) ERR_SUNW_error((f), (r), __FILE__, __LINE__)
2N/A
2N/A/* Error codes for the SUNW functions. */
2N/A/* OpenSSL prefers codes to start at 100 */
2N/A
2N/A/* Function codes. */
2N/Atypedef enum {
2N/A SUNW_F_USE_X509CERT = 100,
2N/A SUNW_F_USE_PKEY,
2N/A SUNW_F_USE_TASTORE,
2N/A SUNW_F_USE_CERTFILE,
2N/A SUNW_F_USE_KEYFILE,
2N/A SUNW_F_USE_TRUSTFILE,
2N/A SUNW_F_READ_FILE,
2N/A SUNW_F_DOPARSE,
2N/A SUNW_F_PKCS12_PARSE,
2N/A SUNW_F_PKCS12_CONTENTS,
2N/A SUNW_F_PARSE_ONE_BAG,
2N/A SUNW_F_PKCS12_CREATE,
2N/A SUNW_F_SPLIT_CERTS,
2N/A SUNW_F_FIND_LOCALKEYID,
2N/A SUNW_F_SET_LOCALKEYID,
2N/A SUNW_F_SET_FNAME,
2N/A SUNW_F_GET_LOCALKEYID,
2N/A SUNW_F_GET_PKEY_FNAME,
2N/A SUNW_F_APPEND_KEYS,
2N/A SUNW_F_PEM_CONTENTS,
2N/A SUNW_F_PEM_INFO,
2N/A SUNW_F_ASC2BMPSTRING,
2N/A SUNW_F_UTF82ASCSTR,
2N/A SUNW_F_FINDATTR,
2N/A SUNW_F_TYPE2ATTRIB,
2N/A SUNW_F_MOVE_CERTS,
2N/A SUNW_F_FIND_FNAME,
2N/A SUNW_F_PARSE_OUTER,
2N/A SUNW_F_CHECKFILE
2N/A} sunw_err_func_t;
2N/A
2N/A/* Reason codes. */
2N/Atypedef enum {
2N/A SUNW_R_INVALID_ARG = 100,
2N/A SUNW_R_MEMORY_FAILURE,
2N/A SUNW_R_MAC_VERIFY_FAILURE,
2N/A SUNW_R_MAC_CREATE_FAILURE,
2N/A SUNW_R_BAD_FILETYPE,
2N/A SUNW_R_BAD_PKEY,
2N/A SUNW_R_BAD_PKEYTYPE,
2N/A SUNW_R_PKEY_READ_ERR,
2N/A SUNW_R_NO_TRUST_ANCHOR,
2N/A SUNW_R_READ_TRUST_ERR,
2N/A SUNW_R_ADD_TRUST_ERR,
2N/A SUNW_R_PKCS12_PARSE_ERR,
2N/A SUNW_R_PKCS12_CREATE_ERR,
2N/A SUNW_R_PARSE_BAG_ERR,
2N/A SUNW_R_MAKE_BAG_ERR,
2N/A SUNW_R_BAD_CERTTYPE,
2N/A SUNW_R_PARSE_CERT_ERR,
2N/A SUNW_R_BAD_LKID,
2N/A SUNW_R_SET_LKID_ERR,
2N/A SUNW_R_BAD_FNAME,
2N/A SUNW_R_SET_FNAME_ERR,
2N/A SUNW_R_BAD_TRUST,
2N/A SUNW_R_BAD_BAGTYPE,
2N/A SUNW_R_CERT_ERR,
2N/A SUNW_R_PKEY_ERR,
2N/A SUNW_R_READ_ERR,
2N/A SUNW_R_ADD_ATTR_ERR,
2N/A SUNW_R_STR_CONVERT_ERR,
2N/A SUNW_R_PKCS12_EMPTY_ERR,
2N/A SUNW_R_PASSWORD_ERR
2N/A} sunw_err_reason_t;
2N/A
2N/A/*
2N/A * Type of checking to perform when calling sunw_check_cert_times
2N/A */
2N/Atypedef enum {
2N/A CHK_NOT_BEFORE = 1, /* Check 'not before' date */
2N/A CHK_NOT_AFTER, /* Check 'not after' date */
2N/A CHK_BOTH /* Check both dates */
2N/A} chk_actions_t;
2N/A
2N/A/*
2N/A * Return type for sunw_check_cert_times
2N/A */
2N/Atypedef enum {
2N/A CHKERR_TIME_OK = 0, /* Current time meets requested checks */
2N/A CHKERR_TIME_BEFORE_BAD, /* 'not before' field is invalid */
2N/A CHKERR_TIME_AFTER_BAD, /* 'not after' field is invalid */
2N/A CHKERR_TIME_IS_BEFORE, /* Current time is before 'not before' */
2N/A CHKERR_TIME_HAS_EXPIRED /* Current time is after 'not after' */
2N/A} chk_errs_t;
2N/A
2N/A/*
2N/A * This type indicates what to do with an attribute being returned.
2N/A */
2N/Atypedef enum {
2N/A GETDO_COPY = 1, /* Simply return the value of the attribute */
2N/A GETDO_DEL /* Delete the attribute at the same time. */
2N/A} getdo_actions_t;
2N/A
2N/A/*
2N/A * For sunw_pkcs12_parse, the following are values for bits that indicate
2N/A * various types of searches/matching to do. Any of these values can be
2N/A * OR'd together. However, the order in which an attempt will be made
2N/A * to satisfy them is the order in which they are listed below. The
2N/A * exception is DO_NONE. It should not be OR'd with any other value.
2N/A */
2N/A#define DO_NONE 0x00 /* Don't even try to match */
2N/A#define DO_FIND_KEYID 0x01 /* 1st cert, key with matching localkeyid */
2N/A#define DO_FIND_FN 0x02 /* 1st cert, key with matching friendlyname */
2N/A#define DO_FIRST_PAIR 0x04 /* Return first matching cert/key pair found */
2N/A#define DO_LAST_PAIR 0x08 /* Return last matching cert/key pair found */
2N/A#define DO_UNMATCHING 0x10 /* Return first cert and/or key */
2N/A
2N/A/* Bits returned, which indicate what values were found. */
2N/A#define FOUND_PKEY 0x01 /* Found one or more private key */
2N/A#define FOUND_CERT 0x02 /* Found one or more client certificate */
2N/A#define FOUND_CA_CERTS 0x04 /* Added at least one cert to the CA list */
2N/A#define FOUND_XPKEY 0x08 /* Found at least one private key which does */
2N/A /* not match a certificate in the certs list */
2N/A
2N/A/* p12lib.c */
2N/APKCS12 *sunw_PKCS12_create(const char *, STACK_OF(EVP_PKEY) *,
2N/A STACK_OF(X509) *, STACK_OF(X509) *);
2N/A
2N/Aint sunw_split_certs(STACK_OF(EVP_PKEY) *, STACK_OF(X509) *,
2N/A STACK_OF(X509) **, STACK_OF(EVP_PKEY) **);
2N/A
2N/Avoid sunw_evp_pkey_free(EVP_PKEY *);
2N/Aint sunw_set_localkeyid(const char *, int, EVP_PKEY *, X509 *);
2N/Aint sunw_get_pkey_localkeyid(getdo_actions_t, EVP_PKEY *, char **, int *);
2N/Aint sunw_get_pkey_fname(getdo_actions_t, EVP_PKEY *, char **);
2N/Aint sunw_find_localkeyid(char *, int, STACK_OF(EVP_PKEY) *,
2N/A STACK_OF(X509) *, EVP_PKEY **, X509 **);
2N/Aint sunw_find_fname(char *, STACK_OF(EVP_PKEY) *, STACK_OF(X509) *,
2N/A EVP_PKEY **, X509 **);
2N/Aint sunw_set_fname(const char *, EVP_PKEY *, X509 *);
2N/Aint sunw_check_keys(X509 *, EVP_PKEY *);
2N/A
2N/Achk_errs_t sunw_check_cert_times(chk_actions_t, X509 *);
2N/Aextern void ERR_SUNW_error(int function, int reason, char *file, int line);
2N/Aextern void ERR_load_SUNW_strings(void);
2N/Aint sunw_PKCS12_contents(PKCS12 *, const char *,
2N/A STACK_OF(EVP_PKEY) **, STACK_OF(X509) **);
2N/Aint sunw_get_cert_fname(getdo_actions_t, X509 *, char **);
2N/Aint sunw_PEM_contents(FILE *, pem_password_cb, void *,
2N/A STACK_OF(EVP_PKEY) **, STACK_OF(X509) **);
2N/A
2N/A#ifdef __cplusplus
2N/A}
2N/A#endif
2N/A
2N/A#endif /* _P12LIB_H */