1df8bdeb3Sjohnz /* 2df8bdeb3Sjohnz * CDDL HEADER START 3df8bdeb3Sjohnz * 4df8bdeb3Sjohnz * The contents of this file are subject to the terms of the 5df8bdeb3Sjohnz * Common Development and Distribution License (the "License"). 6df8bdeb3Sjohnz * You may not use this file except in compliance with the License. 7df8bdeb3Sjohnz * 8df8bdeb3Sjohnz * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9df8bdeb3Sjohnz * or http://www.opensolaris.org/os/licensing. 10df8bdeb3Sjohnz * See the License for the specific language governing permissions 11df8bdeb3Sjohnz * and limitations under the License. 12df8bdeb3Sjohnz * 13df8bdeb3Sjohnz * When distributing Covered Code, include this CDDL HEADER in each 14df8bdeb3Sjohnz * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15df8bdeb3Sjohnz * If applicable, add the following below this CDDL HEADER, with the 16df8bdeb3Sjohnz * fields enclosed by brackets "[]" replaced with your own identifying 17df8bdeb3Sjohnz * information: Portions Copyright [yyyy] [name of copyright owner] 18df8bdeb3Sjohnz * 19df8bdeb3Sjohnz * CDDL HEADER END 20df8bdeb3Sjohnz */ 21df8bdeb3Sjohnz 22df8bdeb3Sjohnz /* 23*9b009fc1SValerie Bubb Fenwick * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 24df8bdeb3Sjohnz */ 25df8bdeb3Sjohnz 26df8bdeb3Sjohnz #ifndef _LIBELFSIGN_H 27df8bdeb3Sjohnz #define _LIBELFSIGN_H 28df8bdeb3Sjohnz 29df8bdeb3Sjohnz #ifdef __cplusplus 30df8bdeb3Sjohnz extern "C" { 31df8bdeb3Sjohnz #endif 32df8bdeb3Sjohnz 33df8bdeb3Sjohnz /* 34df8bdeb3Sjohnz * libelfsign Private Interfaces 35*9b009fc1SValerie Bubb Fenwick * This header file should not be shipped as part of Solaris binary or 36df8bdeb3Sjohnz * source products. 37df8bdeb3Sjohnz */ 38df8bdeb3Sjohnz 39df8bdeb3Sjohnz #include <sys/crypto/elfsign.h> 40df8bdeb3Sjohnz #include <libelf.h> 41df8bdeb3Sjohnz #include <fcntl.h> 42df8bdeb3Sjohnz #include <md5.h> 43df8bdeb3Sjohnz #include <sha1.h> 44df8bdeb3Sjohnz #include <kmfapi.h> 45df8bdeb3Sjohnz 46df8bdeb3Sjohnz /* 47df8bdeb3Sjohnz * Certificate-related definitions 48df8bdeb3Sjohnz */ 49df8bdeb3Sjohnz #define ELFSIGN_CRYPTO "Solaris Cryptographic Framework" 50df8bdeb3Sjohnz #define USAGELIMITED "OU=UsageLimited" 51df8bdeb3Sjohnz 52df8bdeb3Sjohnz typedef enum ELFCert_VStatus_e { 53df8bdeb3Sjohnz E_UNCHECKED, 54df8bdeb3Sjohnz E_OK, 55df8bdeb3Sjohnz E_IS_TA, 56df8bdeb3Sjohnz E_FAILED 57df8bdeb3Sjohnz } ELFCert_VStatus_t; 58df8bdeb3Sjohnz 59df8bdeb3Sjohnz typedef struct ELFCert_s { 60df8bdeb3Sjohnz ELFCert_VStatus_t c_verified; 61df8bdeb3Sjohnz char *c_subject; 62df8bdeb3Sjohnz char *c_issuer; 63df8bdeb3Sjohnz KMF_X509_DER_CERT c_cert; 64df8bdeb3Sjohnz KMF_KEY_HANDLE c_privatekey; 65df8bdeb3Sjohnz } *ELFCert_t; 66df8bdeb3Sjohnz 67df8bdeb3Sjohnz #define CRYPTO_CERTS_DIR "/etc/crypto/certs" 68df8bdeb3Sjohnz #define ETC_CERTS_DIR "/etc/certs" 69df8bdeb3Sjohnz 70df8bdeb3Sjohnz /* 71df8bdeb3Sjohnz * libelfsign actions 72df8bdeb3Sjohnz */ 73df8bdeb3Sjohnz enum ES_ACTION { 74df8bdeb3Sjohnz ES_GET, 75df8bdeb3Sjohnz ES_GET_CRYPTO, 7673556491SAnthony Scarpino ES_GET_FIPS140, 77df8bdeb3Sjohnz ES_UPDATE, 78df8bdeb3Sjohnz ES_UPDATE_RSA_MD5_SHA1, 79df8bdeb3Sjohnz ES_UPDATE_RSA_SHA1 80df8bdeb3Sjohnz }; 81df8bdeb3Sjohnz #define ES_ACTISUPDATE(a) ((a) >= ES_UPDATE) 82df8bdeb3Sjohnz 83df8bdeb3Sjohnz /* 84df8bdeb3Sjohnz * Context for elfsign operation 85df8bdeb3Sjohnz */ 86df8bdeb3Sjohnz struct ELFsign_s { 87df8bdeb3Sjohnz Elf *es_elf; 88df8bdeb3Sjohnz char *es_pathname; 89df8bdeb3Sjohnz char *es_certpath; 90df8bdeb3Sjohnz int es_fd; 91df8bdeb3Sjohnz size_t es_shstrndx; 92df8bdeb3Sjohnz enum ES_ACTION es_action; 93df8bdeb3Sjohnz KMF_KEY_HANDLE es_privatekey; 94df8bdeb3Sjohnz filesig_vers_t es_version; 95df8bdeb3Sjohnz boolean_t es_same_endian; 96df8bdeb3Sjohnz boolean_t es_has_phdr; 97df8bdeb3Sjohnz char es_ei_class; 98df8bdeb3Sjohnz struct flock es_flock; 99df8bdeb3Sjohnz KMF_HANDLE_T es_kmfhandle; 100df8bdeb3Sjohnz void *es_callbackctx; 101df8bdeb3Sjohnz void (*es_sigvercallback)(void *, void *, size_t, ELFCert_t); 102df8bdeb3Sjohnz void (*es_certCAcallback)(void *, ELFCert_t, char *); 103df8bdeb3Sjohnz void (*es_certvercallback)(void *, ELFCert_t, ELFCert_t); 104df8bdeb3Sjohnz }; 105df8bdeb3Sjohnz 106df8bdeb3Sjohnz #define ES_FMT_RSA_MD5_SHA1 "rsa_md5_sha1" 107df8bdeb3Sjohnz #define ES_FMT_RSA_SHA1 "rsa_sha1" 108df8bdeb3Sjohnz 109df8bdeb3Sjohnz /* 110df8bdeb3Sjohnz * ELF signature handling 111df8bdeb3Sjohnz */ 112df8bdeb3Sjohnz typedef struct ELFsign_s *ELFsign_t; 113df8bdeb3Sjohnz struct ELFsign_sig_info { 114df8bdeb3Sjohnz char *esi_format; 115df8bdeb3Sjohnz char *esi_signer; 116df8bdeb3Sjohnz time_t esi_time; 117df8bdeb3Sjohnz }; 118df8bdeb3Sjohnz 119df8bdeb3Sjohnz extern struct filesignatures *elfsign_insert_dso(ELFsign_t ess, 120df8bdeb3Sjohnz struct filesignatures *fsp, const char *dn, int dn_len, 121df8bdeb3Sjohnz const uchar_t *sig, int sig_len, const char *oid, int oid_len); 122df8bdeb3Sjohnz extern filesig_vers_t elfsign_extract_sig(ELFsign_t ess, 123df8bdeb3Sjohnz struct filesignatures *fsp, uchar_t *sig, size_t *sig_len); 124df8bdeb3Sjohnz extern ELFsign_status_t elfsign_begin(const char *, 125df8bdeb3Sjohnz enum ES_ACTION, ELFsign_t *); 126df8bdeb3Sjohnz extern void elfsign_end(ELFsign_t ess); 127df8bdeb3Sjohnz extern ELFsign_status_t elfsign_setcertpath(ELFsign_t ess, const char *path); 128df8bdeb3Sjohnz extern ELFsign_status_t elfsign_verify_signature(ELFsign_t ess, 129df8bdeb3Sjohnz struct ELFsign_sig_info **esipp); 130df8bdeb3Sjohnz extern ELFsign_status_t elfsign_hash(ELFsign_t ess, uchar_t *hash, 131df8bdeb3Sjohnz size_t *hash_len); 132df8bdeb3Sjohnz extern ELFsign_status_t elfsign_hash_mem_resident(ELFsign_t ess, 133df8bdeb3Sjohnz uchar_t *hash, size_t *hash_len); 134df8bdeb3Sjohnz extern void elfsign_buffer_len(ELFsign_t ess, size_t *ip, uchar_t *cp, 135df8bdeb3Sjohnz enum ES_ACTION action); 136df8bdeb3Sjohnz 137df8bdeb3Sjohnz extern void elfsign_setcallbackctx(ELFsign_t ess, void *ctx); 138df8bdeb3Sjohnz extern void elfsign_setsigvercallback(ELFsign_t ess, 139df8bdeb3Sjohnz void (*cb)(void *, void *, size_t, ELFCert_t)); 140df8bdeb3Sjohnz extern ELFsign_status_t elfsign_signatures(ELFsign_t ess, 141df8bdeb3Sjohnz struct filesignatures **fspp, size_t *fs_len, enum ES_ACTION action); 142df8bdeb3Sjohnz 143df8bdeb3Sjohnz extern char const *elfsign_strerror(ELFsign_status_t); 144df8bdeb3Sjohnz extern boolean_t elfsign_sig_info(struct filesignatures *fssp, 145df8bdeb3Sjohnz struct ELFsign_sig_info **esipp); 146df8bdeb3Sjohnz extern void elfsign_sig_info_free(struct ELFsign_sig_info *); 147df8bdeb3Sjohnz 148df8bdeb3Sjohnz /* 149df8bdeb3Sjohnz * ELF "Certificate Library" 150df8bdeb3Sjohnz */ 151df8bdeb3Sjohnz 152df8bdeb3Sjohnz extern const char _PATH_ELFSIGN_CERTS[]; 153df8bdeb3Sjohnz 154df8bdeb3Sjohnz #define ELFCERT_MAX_DN_LEN 255 155df8bdeb3Sjohnz 156df8bdeb3Sjohnz extern boolean_t elfcertlib_init(ELFsign_t); 157df8bdeb3Sjohnz extern void elfcertlib_fini(ELFsign_t); 158df8bdeb3Sjohnz extern boolean_t elfcertlib_settoken(ELFsign_t, char *); 159df8bdeb3Sjohnz extern void elfcertlib_setcertCAcallback(ELFsign_t ess, 160df8bdeb3Sjohnz void (*cb)(void *, ELFCert_t, char *)); 161df8bdeb3Sjohnz extern void elfcertlib_setcertvercallback(ELFsign_t ess, 162df8bdeb3Sjohnz void (*cb)(void *, ELFCert_t, ELFCert_t)); 163df8bdeb3Sjohnz 164df8bdeb3Sjohnz extern boolean_t elfcertlib_getcert(ELFsign_t ess, char *cert_pathname, 165df8bdeb3Sjohnz char *signer_DN, ELFCert_t *certp, enum ES_ACTION action); 166df8bdeb3Sjohnz extern void elfcertlib_releasecert(ELFsign_t, ELFCert_t); 167df8bdeb3Sjohnz extern char *elfcertlib_getdn(ELFCert_t cert); 168df8bdeb3Sjohnz extern char *elfcertlib_getissuer(ELFCert_t cert); 169df8bdeb3Sjohnz 170df8bdeb3Sjohnz extern boolean_t elfcertlib_loadprivatekey(ELFsign_t ess, ELFCert_t cert, 171df8bdeb3Sjohnz const char *path); 172df8bdeb3Sjohnz extern boolean_t elfcertlib_loadtokenkey(ELFsign_t ess, ELFCert_t cert, 173df8bdeb3Sjohnz const char *token_id, const char *pin); 174df8bdeb3Sjohnz 175df8bdeb3Sjohnz extern boolean_t elfcertlib_sign(ELFsign_t ess, ELFCert_t cert, 176df8bdeb3Sjohnz const uchar_t *data, size_t data_len, uchar_t *sig, 177df8bdeb3Sjohnz size_t *sig_len); 178df8bdeb3Sjohnz 179df8bdeb3Sjohnz extern boolean_t elfcertlib_verifycert(ELFsign_t ess, ELFCert_t cert); 180df8bdeb3Sjohnz extern boolean_t elfcertlib_verifysig(ELFsign_t ess, ELFCert_t cert, 181df8bdeb3Sjohnz const uchar_t *sig, size_t sig_len, 182df8bdeb3Sjohnz const uchar_t *data, size_t data_len); 183df8bdeb3Sjohnz 184df8bdeb3Sjohnz #ifdef __cplusplus 185df8bdeb3Sjohnz } 186df8bdeb3Sjohnz #endif 187df8bdeb3Sjohnz 188df8bdeb3Sjohnz #endif /* _LIBELFSIGN_H */ 189