xref: /titanic_44/usr/src/lib/libpkg/common/keystore.h (revision 5c51f1241dbbdf2656d0e10011981411ed0c9673)
1*5c51f124SMoriah Waterland /*
2*5c51f124SMoriah Waterland  * CDDL HEADER START
3*5c51f124SMoriah Waterland  *
4*5c51f124SMoriah Waterland  * The contents of this file are subject to the terms of the
5*5c51f124SMoriah Waterland  * Common Development and Distribution License (the "License").
6*5c51f124SMoriah Waterland  * You may not use this file except in compliance with the License.
7*5c51f124SMoriah Waterland  *
8*5c51f124SMoriah Waterland  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5c51f124SMoriah Waterland  * or http://www.opensolaris.org/os/licensing.
10*5c51f124SMoriah Waterland  * See the License for the specific language governing permissions
11*5c51f124SMoriah Waterland  * and limitations under the License.
12*5c51f124SMoriah Waterland  *
13*5c51f124SMoriah Waterland  * When distributing Covered Code, include this CDDL HEADER in each
14*5c51f124SMoriah Waterland  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5c51f124SMoriah Waterland  * If applicable, add the following below this CDDL HEADER, with the
16*5c51f124SMoriah Waterland  * fields enclosed by brackets "[]" replaced with your own identifying
17*5c51f124SMoriah Waterland  * information: Portions Copyright [yyyy] [name of copyright owner]
18*5c51f124SMoriah Waterland  *
19*5c51f124SMoriah Waterland  * CDDL HEADER END
20*5c51f124SMoriah Waterland  */
21*5c51f124SMoriah Waterland 
22*5c51f124SMoriah Waterland /*
23*5c51f124SMoriah Waterland  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*5c51f124SMoriah Waterland  * Use is subject to license terms.
25*5c51f124SMoriah Waterland  */
26*5c51f124SMoriah Waterland 
27*5c51f124SMoriah Waterland #ifndef _KEYSTORE_H
28*5c51f124SMoriah Waterland #define	_KEYSTORE_H
29*5c51f124SMoriah Waterland 
30*5c51f124SMoriah Waterland 
31*5c51f124SMoriah Waterland /*
32*5c51f124SMoriah Waterland  * Module:	keystore.h
33*5c51f124SMoriah Waterland  * Description:	This module contains the structure definitions for processing
34*5c51f124SMoriah Waterland  *		package keystore files.
35*5c51f124SMoriah Waterland  */
36*5c51f124SMoriah Waterland 
37*5c51f124SMoriah Waterland #ifdef __cplusplus
38*5c51f124SMoriah Waterland extern "C" {
39*5c51f124SMoriah Waterland #endif
40*5c51f124SMoriah Waterland 
41*5c51f124SMoriah Waterland #include <openssl/evp.h>
42*5c51f124SMoriah Waterland #include <openssl/x509.h>
43*5c51f124SMoriah Waterland #include "pkgerr.h"
44*5c51f124SMoriah Waterland 
45*5c51f124SMoriah Waterland /* keystore structures */
46*5c51f124SMoriah Waterland 
47*5c51f124SMoriah Waterland /* this opaque type represents a keystore */
48*5c51f124SMoriah Waterland typedef void *keystore_handle_t;
49*5c51f124SMoriah Waterland 
50*5c51f124SMoriah Waterland /* flags passed to open_keystore */
51*5c51f124SMoriah Waterland 
52*5c51f124SMoriah Waterland /* opens keystore read-only.  Attempts to modify results in an error */
53*5c51f124SMoriah Waterland #define	KEYSTORE_ACCESS_READONLY	0x00000001L
54*5c51f124SMoriah Waterland 
55*5c51f124SMoriah Waterland /* opens keystore read-write */
56*5c51f124SMoriah Waterland #define	KEYSTORE_ACCESS_READWRITE	0x00000002L
57*5c51f124SMoriah Waterland 
58*5c51f124SMoriah Waterland /*
59*5c51f124SMoriah Waterland  * tells open_keystore to fall back to app-generic paths in the case that
60*5c51f124SMoriah Waterland  * the app-specific paths do not exist.
61*5c51f124SMoriah Waterland  */
62*5c51f124SMoriah Waterland #define	KEYSTORE_PATH_SOFT		0x00000010L
63*5c51f124SMoriah Waterland 
64*5c51f124SMoriah Waterland /*
65*5c51f124SMoriah Waterland  * tells open_keystore to use the app-specific paths no matter what,
66*5c51f124SMoriah Waterland  * failing if they cannot be used for any reason.
67*5c51f124SMoriah Waterland  */
68*5c51f124SMoriah Waterland #define	KEYSTORE_PATH_HARD		0x00000020L
69*5c51f124SMoriah Waterland 
70*5c51f124SMoriah Waterland /* masks off various types of flags */
71*5c51f124SMoriah Waterland #define	KEYSTORE_ACCESS_MASK		0x0000000FL
72*5c51f124SMoriah Waterland #define	KEYSTORE_PATH_MASK		0x000000F0L
73*5c51f124SMoriah Waterland 
74*5c51f124SMoriah Waterland /* default is read-only, soft */
75*5c51f124SMoriah Waterland #define	KEYSTORE_DFLT_FLAGS \
76*5c51f124SMoriah Waterland 		(KEYSTORE_ACCESS_READONLY|KEYSTORE_PATH_SOFT)
77*5c51f124SMoriah Waterland 
78*5c51f124SMoriah Waterland /*
79*5c51f124SMoriah Waterland  * possible encoding formats used by the library, used
80*5c51f124SMoriah Waterland  * by print_cert
81*5c51f124SMoriah Waterland  */
82*5c51f124SMoriah Waterland typedef enum {
83*5c51f124SMoriah Waterland 	KEYSTORE_FORMAT_PEM,
84*5c51f124SMoriah Waterland 	KEYSTORE_FORMAT_DER,
85*5c51f124SMoriah Waterland 	KEYSTORE_FORMAT_TEXT
86*5c51f124SMoriah Waterland } keystore_encoding_format_t;
87*5c51f124SMoriah Waterland 
88*5c51f124SMoriah Waterland /*
89*5c51f124SMoriah Waterland  * structure passed back to password callback for determining how
90*5c51f124SMoriah Waterland  * to prompt for passphrase, and where to record errors
91*5c51f124SMoriah Waterland  */
92*5c51f124SMoriah Waterland typedef struct {
93*5c51f124SMoriah Waterland 	PKG_ERR	*err;
94*5c51f124SMoriah Waterland } keystore_passphrase_data;
95*5c51f124SMoriah Waterland 
96*5c51f124SMoriah Waterland 
97*5c51f124SMoriah Waterland /* max length of a passphrase.  One could use a short story! */
98*5c51f124SMoriah Waterland #define	KEYSTORE_PASS_MAX	1024
99*5c51f124SMoriah Waterland 
100*5c51f124SMoriah Waterland /* callback for collecting passphrase when open_keystore() is called */
101*5c51f124SMoriah Waterland typedef int keystore_passphrase_cb(char *, int, int, void *);
102*5c51f124SMoriah Waterland 
103*5c51f124SMoriah Waterland /* names of the individual files within the keystore path */
104*5c51f124SMoriah Waterland #define	TRUSTSTORE		"truststore"
105*5c51f124SMoriah Waterland #define	KEYSTORE		"keystore"
106*5c51f124SMoriah Waterland #define	CERTSTORE		"certstore"
107*5c51f124SMoriah Waterland 
108*5c51f124SMoriah Waterland /* keystore.c */
109*5c51f124SMoriah Waterland extern int		open_keystore(PKG_ERR *, char *, char *,
110*5c51f124SMoriah Waterland     keystore_passphrase_cb, long flags, keystore_handle_t *);
111*5c51f124SMoriah Waterland 
112*5c51f124SMoriah Waterland extern int		print_certs(PKG_ERR *, keystore_handle_t, char *,
113*5c51f124SMoriah Waterland     keystore_encoding_format_t, FILE *);
114*5c51f124SMoriah Waterland 
115*5c51f124SMoriah Waterland extern int		check_cert(PKG_ERR *, X509 *);
116*5c51f124SMoriah Waterland 
117*5c51f124SMoriah Waterland extern int		check_cert_and_key(PKG_ERR *, X509 *, EVP_PKEY *);
118*5c51f124SMoriah Waterland 
119*5c51f124SMoriah Waterland extern int		print_cert(PKG_ERR *, X509 *,
120*5c51f124SMoriah Waterland     keystore_encoding_format_t, char *, boolean_t, FILE *);
121*5c51f124SMoriah Waterland 
122*5c51f124SMoriah Waterland extern int		close_keystore(PKG_ERR *, keystore_handle_t,
123*5c51f124SMoriah Waterland     keystore_passphrase_cb);
124*5c51f124SMoriah Waterland 
125*5c51f124SMoriah Waterland extern int		merge_ca_cert(PKG_ERR *, X509 *, keystore_handle_t);
126*5c51f124SMoriah Waterland extern int		merge_cert_and_key(PKG_ERR *, X509 *, EVP_PKEY *,
127*5c51f124SMoriah Waterland     char *, keystore_handle_t);
128*5c51f124SMoriah Waterland 
129*5c51f124SMoriah Waterland extern int		delete_cert_and_keys(PKG_ERR *, keystore_handle_t,
130*5c51f124SMoriah Waterland     char *);
131*5c51f124SMoriah Waterland 
132*5c51f124SMoriah Waterland extern int		find_key_cert_pair(PKG_ERR *, keystore_handle_t,
133*5c51f124SMoriah Waterland     char *, EVP_PKEY **, X509 **);
134*5c51f124SMoriah Waterland 
135*5c51f124SMoriah Waterland extern int		find_ca_certs(PKG_ERR *, keystore_handle_t,
136*5c51f124SMoriah Waterland     STACK_OF(X509) **);
137*5c51f124SMoriah Waterland 
138*5c51f124SMoriah Waterland extern int		find_cl_certs(PKG_ERR *, keystore_handle_t,
139*5c51f124SMoriah Waterland     STACK_OF(X509) **);
140*5c51f124SMoriah Waterland 
141*5c51f124SMoriah Waterland #ifdef __cplusplus
142*5c51f124SMoriah Waterland }
143*5c51f124SMoriah Waterland #endif
144*5c51f124SMoriah Waterland 
145*5c51f124SMoriah Waterland #endif /* _KEYSTORE_H */
146