dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libelfsign / common / libelfsign.h
blob27b72e18a1dcb426a34272753e42cf276f0b7d38
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
26 #ifndef _LIBELFSIGN_H
27 #define _LIBELFSIGN_H
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
34 * libelfsign Private Interfaces
35 * This header file should not be shipped as part of Solaris binary or
36 * source products.
39 #include <sys/crypto/elfsign.h>
40 #include <libelf.h>
41 #include <fcntl.h>
42 #include <md5.h>
43 #include <sha1.h>
44 #include <kmfapi.h>
47 * Certificate-related definitions
49 #define ELFSIGN_CRYPTO "Solaris Cryptographic Framework"
50 #define USAGELIMITED "OU=UsageLimited"
52 typedef enum ELFCert_VStatus_e {
53 E_UNCHECKED,
54 E_OK,
55 E_IS_TA,
56 E_FAILED
57 } ELFCert_VStatus_t;
59 typedef struct ELFCert_s {
60 ELFCert_VStatus_t c_verified;
61 char *c_subject;
62 char *c_issuer;
63 KMF_X509_DER_CERT c_cert;
64 KMF_KEY_HANDLE c_privatekey;
65 } *ELFCert_t;
67 #define CRYPTO_CERTS_DIR "/etc/crypto/certs"
68 #define ETC_CERTS_DIR "/etc/certs"
71 * libelfsign actions
73 enum ES_ACTION {
74 ES_GET,
75 ES_GET_CRYPTO,
76 ES_GET_FIPS140,
77 ES_UPDATE,
78 ES_UPDATE_RSA_MD5_SHA1,
79 ES_UPDATE_RSA_SHA1
81 #define ES_ACTISUPDATE(a) ((a) >= ES_UPDATE)
84 * Context for elfsign operation
86 struct ELFsign_s {
87 Elf *es_elf;
88 char *es_pathname;
89 char *es_certpath;
90 int es_fd;
91 size_t es_shstrndx;
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;
97 char es_ei_class;
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 {
114 char *esi_format;
115 char *esi_signer;
116 time_t esi_time;
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,
131 size_t *hash_len);
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,
171 const char *path);
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,
177 size_t *sig_len);
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);
184 #ifdef __cplusplus
186 #endif
188 #endif /* _LIBELFSIGN_H */