4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
34 * libelfsign Private Interfaces
35 * This header file should not be shipped as part of Solaris binary or
39 #include <sys/crypto/elfsign.h>
47 * Certificate-related definitions
49 #define ELFSIGN_CRYPTO "Solaris Cryptographic Framework"
50 #define USAGELIMITED "OU=UsageLimited"
52 typedef enum ELFCert_VStatus_e
{
59 typedef struct ELFCert_s
{
60 ELFCert_VStatus_t c_verified
;
63 KMF_X509_DER_CERT c_cert
;
64 KMF_KEY_HANDLE c_privatekey
;
67 #define CRYPTO_CERTS_DIR "/etc/crypto/certs"
68 #define ETC_CERTS_DIR "/etc/certs"
78 ES_UPDATE_RSA_MD5_SHA1
,
81 #define ES_ACTISUPDATE(a) ((a) >= ES_UPDATE)
84 * Context for elfsign operation
92 enum ES_ACTION es_action
;
93 KMF_KEY_HANDLE es_privatekey
;
94 filesig_vers_t es_version
;
95 boolean_t es_same_endian
;
96 boolean_t es_has_phdr
;
98 struct flock es_flock
;
99 KMF_HANDLE_T es_kmfhandle
;
100 void *es_callbackctx
;
101 void (*es_sigvercallback
)(void *, void *, size_t, ELFCert_t
);
102 void (*es_certCAcallback
)(void *, ELFCert_t
, char *);
103 void (*es_certvercallback
)(void *, ELFCert_t
, ELFCert_t
);
106 #define ES_FMT_RSA_MD5_SHA1 "rsa_md5_sha1"
107 #define ES_FMT_RSA_SHA1 "rsa_sha1"
110 * ELF signature handling
112 typedef struct ELFsign_s
*ELFsign_t
;
113 struct ELFsign_sig_info
{
119 extern struct filesignatures
*elfsign_insert_dso(ELFsign_t ess
,
120 struct filesignatures
*fsp
, const char *dn
, int dn_len
,
121 const uchar_t
*sig
, int sig_len
, const char *oid
, int oid_len
);
122 extern filesig_vers_t
elfsign_extract_sig(ELFsign_t ess
,
123 struct filesignatures
*fsp
, uchar_t
*sig
, size_t *sig_len
);
124 extern ELFsign_status_t
elfsign_begin(const char *,
125 enum ES_ACTION
, ELFsign_t
*);
126 extern void elfsign_end(ELFsign_t ess
);
127 extern ELFsign_status_t
elfsign_setcertpath(ELFsign_t ess
, const char *path
);
128 extern ELFsign_status_t
elfsign_verify_signature(ELFsign_t ess
,
129 struct ELFsign_sig_info
**esipp
);
130 extern ELFsign_status_t
elfsign_hash(ELFsign_t ess
, uchar_t
*hash
,
132 extern ELFsign_status_t
elfsign_hash_mem_resident(ELFsign_t ess
,
133 uchar_t
*hash
, size_t *hash_len
);
134 extern void elfsign_buffer_len(ELFsign_t ess
, size_t *ip
, uchar_t
*cp
,
135 enum ES_ACTION action
);
137 extern void elfsign_setcallbackctx(ELFsign_t ess
, void *ctx
);
138 extern void elfsign_setsigvercallback(ELFsign_t ess
,
139 void (*cb
)(void *, void *, size_t, ELFCert_t
));
140 extern ELFsign_status_t
elfsign_signatures(ELFsign_t ess
,
141 struct filesignatures
**fspp
, size_t *fs_len
, enum ES_ACTION action
);
143 extern char const *elfsign_strerror(ELFsign_status_t
);
144 extern boolean_t
elfsign_sig_info(struct filesignatures
*fssp
,
145 struct ELFsign_sig_info
**esipp
);
146 extern void elfsign_sig_info_free(struct ELFsign_sig_info
*);
149 * ELF "Certificate Library"
152 extern const char _PATH_ELFSIGN_CERTS
[];
154 #define ELFCERT_MAX_DN_LEN 255
156 extern boolean_t
elfcertlib_init(ELFsign_t
);
157 extern void elfcertlib_fini(ELFsign_t
);
158 extern boolean_t
elfcertlib_settoken(ELFsign_t
, char *);
159 extern void elfcertlib_setcertCAcallback(ELFsign_t ess
,
160 void (*cb
)(void *, ELFCert_t
, char *));
161 extern void elfcertlib_setcertvercallback(ELFsign_t ess
,
162 void (*cb
)(void *, ELFCert_t
, ELFCert_t
));
164 extern boolean_t
elfcertlib_getcert(ELFsign_t ess
, char *cert_pathname
,
165 char *signer_DN
, ELFCert_t
*certp
, enum ES_ACTION action
);
166 extern void elfcertlib_releasecert(ELFsign_t
, ELFCert_t
);
167 extern char *elfcertlib_getdn(ELFCert_t cert
);
168 extern char *elfcertlib_getissuer(ELFCert_t cert
);
170 extern boolean_t
elfcertlib_loadprivatekey(ELFsign_t ess
, ELFCert_t cert
,
172 extern boolean_t
elfcertlib_loadtokenkey(ELFsign_t ess
, ELFCert_t cert
,
173 const char *token_id
, const char *pin
);
175 extern boolean_t
elfcertlib_sign(ELFsign_t ess
, ELFCert_t cert
,
176 const uchar_t
*data
, size_t data_len
, uchar_t
*sig
,
179 extern boolean_t
elfcertlib_verifycert(ELFsign_t ess
, ELFCert_t cert
);
180 extern boolean_t
elfcertlib_verifysig(ELFsign_t ess
, ELFCert_t cert
,
181 const uchar_t
*sig
, size_t sig_len
,
182 const uchar_t
*data
, size_t data_len
);
188 #endif /* _LIBELFSIGN_H */