199ebb4caSwyllys /* 299ebb4caSwyllys * CDDL HEADER START 399ebb4caSwyllys * 499ebb4caSwyllys * The contents of this file are subject to the terms of the 599ebb4caSwyllys * Common Development and Distribution License (the "License"). 699ebb4caSwyllys * You may not use this file except in compliance with the License. 799ebb4caSwyllys * 899ebb4caSwyllys * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 999ebb4caSwyllys * or http://www.opensolaris.org/os/licensing. 1099ebb4caSwyllys * See the License for the specific language governing permissions 1199ebb4caSwyllys * and limitations under the License. 1299ebb4caSwyllys * 1399ebb4caSwyllys * When distributing Covered Code, include this CDDL HEADER in each 1499ebb4caSwyllys * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1599ebb4caSwyllys * If applicable, add the following below this CDDL HEADER, with the 1699ebb4caSwyllys * fields enclosed by brackets "[]" replaced with your own identifying 1799ebb4caSwyllys * information: Portions Copyright [yyyy] [name of copyright owner] 1899ebb4caSwyllys * 1999ebb4caSwyllys * CDDL HEADER END 2099ebb4caSwyllys */ 2199ebb4caSwyllys /* 22*d00756ccSwyllys * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 2399ebb4caSwyllys * Use is subject to license terms. 2499ebb4caSwyllys */ 2599ebb4caSwyllys #ifndef _KMFAPIP_H 2699ebb4caSwyllys #define _KMFAPIP_H 2799ebb4caSwyllys 2899ebb4caSwyllys #pragma ident "%Z%%M% %I% %E% SMI" 2999ebb4caSwyllys 3099ebb4caSwyllys #include <kmfapi.h> 3199ebb4caSwyllys #include <kmfpolicy.h> 3299ebb4caSwyllys 3399ebb4caSwyllys #ifdef __cplusplus 3499ebb4caSwyllys extern "C" { 3599ebb4caSwyllys #endif 3699ebb4caSwyllys 3799ebb4caSwyllys /* Plugin function table */ 3899ebb4caSwyllys typedef struct { 3999ebb4caSwyllys ushort_t version; 4099ebb4caSwyllys KMF_RETURN (*ConfigureKeystore) ( 4199ebb4caSwyllys KMF_HANDLE_T, 4230a5e8faSwyllys int, 4330a5e8faSwyllys KMF_ATTRIBUTE *); 4499ebb4caSwyllys 4599ebb4caSwyllys KMF_RETURN (*FindCert) ( 4699ebb4caSwyllys KMF_HANDLE_T, 4730a5e8faSwyllys int, 4830a5e8faSwyllys KMF_ATTRIBUTE *); 4999ebb4caSwyllys 5099ebb4caSwyllys void (*FreeKMFCert) ( 5199ebb4caSwyllys KMF_HANDLE_T, 5299ebb4caSwyllys KMF_X509_DER_CERT *); 5399ebb4caSwyllys 5499ebb4caSwyllys KMF_RETURN (*StoreCert) ( 5599ebb4caSwyllys KMF_HANDLE_T, 5630a5e8faSwyllys int, KMF_ATTRIBUTE *); 5799ebb4caSwyllys 5899ebb4caSwyllys KMF_RETURN (*ImportCert) ( 5999ebb4caSwyllys KMF_HANDLE_T, 6030a5e8faSwyllys int, KMF_ATTRIBUTE *); 6199ebb4caSwyllys 6299ebb4caSwyllys KMF_RETURN (*ImportCRL) ( 6399ebb4caSwyllys KMF_HANDLE_T, 6430a5e8faSwyllys int, KMF_ATTRIBUTE *); 6599ebb4caSwyllys 6699ebb4caSwyllys KMF_RETURN (*DeleteCert) ( 6799ebb4caSwyllys KMF_HANDLE_T, 6830a5e8faSwyllys int, KMF_ATTRIBUTE *); 6999ebb4caSwyllys 7099ebb4caSwyllys KMF_RETURN (*DeleteCRL) ( 7199ebb4caSwyllys KMF_HANDLE_T, 7230a5e8faSwyllys int, KMF_ATTRIBUTE *); 7399ebb4caSwyllys 7499ebb4caSwyllys KMF_RETURN (*CreateKeypair) ( 7599ebb4caSwyllys KMF_HANDLE_T, 7630a5e8faSwyllys int, 7730a5e8faSwyllys KMF_ATTRIBUTE *); 7899ebb4caSwyllys 7999ebb4caSwyllys KMF_RETURN (*FindKey) ( 8099ebb4caSwyllys KMF_HANDLE_T, 8130a5e8faSwyllys int, 8230a5e8faSwyllys KMF_ATTRIBUTE *); 8399ebb4caSwyllys 8499ebb4caSwyllys KMF_RETURN (*EncodePubkeyData) ( 8599ebb4caSwyllys KMF_HANDLE_T, 8699ebb4caSwyllys KMF_KEY_HANDLE *, 8799ebb4caSwyllys KMF_DATA *); 8899ebb4caSwyllys 8999ebb4caSwyllys KMF_RETURN (*SignData) ( 9099ebb4caSwyllys KMF_HANDLE_T, 9199ebb4caSwyllys KMF_KEY_HANDLE *, 9299ebb4caSwyllys KMF_OID *, 9399ebb4caSwyllys KMF_DATA *, 9499ebb4caSwyllys KMF_DATA *); 9599ebb4caSwyllys 9699ebb4caSwyllys KMF_RETURN (*DeleteKey) ( 9799ebb4caSwyllys KMF_HANDLE_T, 9830a5e8faSwyllys int, 9930a5e8faSwyllys KMF_ATTRIBUTE *); 10099ebb4caSwyllys 10199ebb4caSwyllys KMF_RETURN (*ListCRL) ( 10299ebb4caSwyllys KMF_HANDLE_T, 10330a5e8faSwyllys int, KMF_ATTRIBUTE *); 10499ebb4caSwyllys 10599ebb4caSwyllys KMF_RETURN (*FindCRL) ( 10699ebb4caSwyllys KMF_HANDLE_T, 10730a5e8faSwyllys int, KMF_ATTRIBUTE *); 10899ebb4caSwyllys 10999ebb4caSwyllys KMF_RETURN (*FindCertInCRL) ( 11099ebb4caSwyllys KMF_HANDLE_T, 11130a5e8faSwyllys int, KMF_ATTRIBUTE *); 11299ebb4caSwyllys 11399ebb4caSwyllys KMF_RETURN (*GetErrorString) ( 11499ebb4caSwyllys KMF_HANDLE_T, 11599ebb4caSwyllys char **); 11699ebb4caSwyllys 11730a5e8faSwyllys KMF_RETURN (*FindPrikeyByCert) ( 11899ebb4caSwyllys KMF_HANDLE_T, 11930a5e8faSwyllys int, 12030a5e8faSwyllys KMF_ATTRIBUTE *); 12199ebb4caSwyllys 12299ebb4caSwyllys KMF_RETURN (*DecryptData) ( 12399ebb4caSwyllys KMF_HANDLE_T, 12499ebb4caSwyllys KMF_KEY_HANDLE *, 12599ebb4caSwyllys KMF_OID *, 12699ebb4caSwyllys KMF_DATA *, 12799ebb4caSwyllys KMF_DATA *); 12899ebb4caSwyllys 12930a5e8faSwyllys KMF_RETURN (*ExportPK12)( 13099ebb4caSwyllys KMF_HANDLE_T, 13130a5e8faSwyllys int, 13230a5e8faSwyllys KMF_ATTRIBUTE *); 13399ebb4caSwyllys 13499ebb4caSwyllys KMF_RETURN (*CreateSymKey) ( 13599ebb4caSwyllys KMF_HANDLE_T, 13630a5e8faSwyllys int, 13730a5e8faSwyllys KMF_ATTRIBUTE *); 13899ebb4caSwyllys 13999ebb4caSwyllys KMF_RETURN (*GetSymKeyValue) ( 14099ebb4caSwyllys KMF_HANDLE_T, 14199ebb4caSwyllys KMF_KEY_HANDLE *, 14299ebb4caSwyllys KMF_RAW_SYM_KEY *); 14399ebb4caSwyllys 14499ebb4caSwyllys KMF_RETURN (*SetTokenPin) ( 14599ebb4caSwyllys KMF_HANDLE_T, 14630a5e8faSwyllys int, KMF_ATTRIBUTE *); 14799ebb4caSwyllys 14802744e81Swyllys KMF_RETURN (*VerifyDataWithCert) ( 14902744e81Swyllys KMF_HANDLE_T, 15002744e81Swyllys KMF_ALGORITHM_INDEX, 15102744e81Swyllys KMF_DATA *, 15202744e81Swyllys KMF_DATA *, 15302744e81Swyllys KMF_DATA *); 15402744e81Swyllys 15530a5e8faSwyllys KMF_RETURN (*StoreKey) ( 15630a5e8faSwyllys KMF_HANDLE_T, 15730a5e8faSwyllys int, 15830a5e8faSwyllys KMF_ATTRIBUTE *); 15930a5e8faSwyllys 16099ebb4caSwyllys void (*Finalize) (); 16199ebb4caSwyllys 16299ebb4caSwyllys } KMF_PLUGIN_FUNCLIST; 16399ebb4caSwyllys 16499ebb4caSwyllys typedef struct { 16530a5e8faSwyllys KMF_ATTR_TYPE type; 16630a5e8faSwyllys boolean_t null_value_ok; /* Is the pValue required */ 16730a5e8faSwyllys uint32_t minlen; 16830a5e8faSwyllys uint32_t maxlen; 16930a5e8faSwyllys } KMF_ATTRIBUTE_TESTER; 17030a5e8faSwyllys 17130a5e8faSwyllys typedef struct { 17299ebb4caSwyllys KMF_KEYSTORE_TYPE type; 17399ebb4caSwyllys char *applications; 17499ebb4caSwyllys char *path; 17599ebb4caSwyllys void *dldesc; 17699ebb4caSwyllys KMF_PLUGIN_FUNCLIST *funclist; 17799ebb4caSwyllys } KMF_PLUGIN; 17899ebb4caSwyllys 17999ebb4caSwyllys typedef struct _KMF_PLUGIN_LIST { 18099ebb4caSwyllys KMF_PLUGIN *plugin; 18199ebb4caSwyllys struct _KMF_PLUGIN_LIST *next; 18299ebb4caSwyllys } KMF_PLUGIN_LIST; 18399ebb4caSwyllys 18499ebb4caSwyllys typedef struct _kmf_handle { 18599ebb4caSwyllys /* 18630a5e8faSwyllys * session handle opened by kmf_select_token() to talk 18799ebb4caSwyllys * to a specific slot in Crypto framework. It is used 18899ebb4caSwyllys * by pkcs11 plugin module. 18999ebb4caSwyllys */ 19099ebb4caSwyllys CK_SESSION_HANDLE pk11handle; 19199ebb4caSwyllys KMF_ERROR lasterr; 19299ebb4caSwyllys KMF_POLICY_RECORD *policy; 19399ebb4caSwyllys KMF_PLUGIN_LIST *plugins; 19499ebb4caSwyllys } KMF_HANDLE; 19599ebb4caSwyllys 19699ebb4caSwyllys #define CLEAR_ERROR(h, rv) { \ 19799ebb4caSwyllys if (h == NULL) { \ 19899ebb4caSwyllys rv = KMF_ERR_BAD_PARAMETER; \ 19999ebb4caSwyllys } else { \ 20099ebb4caSwyllys h->lasterr.errcode = 0; \ 20199ebb4caSwyllys h->lasterr.kstype = 0; \ 20299ebb4caSwyllys rv = KMF_OK; \ 20399ebb4caSwyllys } \ 20499ebb4caSwyllys } 20599ebb4caSwyllys 20699ebb4caSwyllys #define KMF_PLUGIN_INIT_SYMBOL "KMF_Plugin_Initialize" 20799ebb4caSwyllys 20899ebb4caSwyllys #ifndef KMF_PLUGIN_PATH 20999ebb4caSwyllys #if defined(__sparcv9) 21099ebb4caSwyllys #define KMF_PLUGIN_PATH "/usr/lib/security/sparcv9/" 21199ebb4caSwyllys #elif defined(__sparc) 21299ebb4caSwyllys #define KMF_PLUGIN_PATH "/usr/lib/security/" 21399ebb4caSwyllys #elif defined(__i386) 21499ebb4caSwyllys #define KMF_PLUGIN_PATH "/usr/lib/security/" 21599ebb4caSwyllys #elif defined(__amd64) 21699ebb4caSwyllys #define KMF_PLUGIN_PATH "/usr/lib/security/amd64/" 21799ebb4caSwyllys #endif 21899ebb4caSwyllys #endif /* !KMF_PLUGIN_PATH */ 21999ebb4caSwyllys 22099ebb4caSwyllys KMF_PLUGIN_FUNCLIST *KMF_Plugin_Initialize(); 22199ebb4caSwyllys 222*d00756ccSwyllys extern KMF_RETURN 223*d00756ccSwyllys VerifyDataWithKey(KMF_HANDLE_T, KMF_DATA *, KMF_ALGORITHM_INDEX, 224*d00756ccSwyllys KMF_DATA *, KMF_DATA *); 22599ebb4caSwyllys 226*d00756ccSwyllys extern KMF_BOOL pkcs_algid_to_keytype( 22799ebb4caSwyllys KMF_ALGORITHM_INDEX, CK_KEY_TYPE *); 22899ebb4caSwyllys 229*d00756ccSwyllys extern KMF_RETURN PKCS_VerifyData( 23099ebb4caSwyllys KMF_HANDLE *, 23199ebb4caSwyllys KMF_ALGORITHM_INDEX, 23299ebb4caSwyllys KMF_X509_SPKI *, 23399ebb4caSwyllys KMF_DATA *, KMF_DATA *); 23499ebb4caSwyllys 235*d00756ccSwyllys extern KMF_RETURN PKCS_EncryptData( 23699ebb4caSwyllys KMF_HANDLE *, 23799ebb4caSwyllys KMF_ALGORITHM_INDEX, 23899ebb4caSwyllys KMF_X509_SPKI *, 23999ebb4caSwyllys KMF_DATA *, 24099ebb4caSwyllys KMF_DATA *); 24199ebb4caSwyllys 242*d00756ccSwyllys extern KMF_PLUGIN *FindPlugin(KMF_HANDLE_T, KMF_KEYSTORE_TYPE); 24399ebb4caSwyllys 244*d00756ccSwyllys extern KMF_BOOL IsEqualOid(KMF_OID *, KMF_OID *); 24599ebb4caSwyllys 246*d00756ccSwyllys extern KMF_RETURN copy_algoid(KMF_X509_ALGORITHM_IDENTIFIER *destid, 24730a5e8faSwyllys KMF_X509_ALGORITHM_IDENTIFIER *srcid); 24830a5e8faSwyllys 249*d00756ccSwyllys extern KMF_OID *x509_algid_to_algoid(KMF_ALGORITHM_INDEX); 250*d00756ccSwyllys extern KMF_ALGORITHM_INDEX x509_algoid_to_algid(KMF_OID *); 25130a5e8faSwyllys 252*d00756ccSwyllys extern KMF_RETURN PKCS_AcquirePublicKeyHandle(CK_SESSION_HANDLE ckSession, 25302744e81Swyllys const KMF_X509_SPKI *, CK_KEY_TYPE, CK_OBJECT_HANDLE *, 25402744e81Swyllys KMF_BOOL *); 25502744e81Swyllys 256*d00756ccSwyllys extern KMF_RETURN GetIDFromSPKI(KMF_X509_SPKI *, KMF_DATA *); 257*d00756ccSwyllys extern KMF_RETURN kmf_select_token(KMF_HANDLE_T, char *, int); 258*d00756ccSwyllys extern KMF_RETURN kmf_set_altname(KMF_X509_EXTENSIONS *, 25999ebb4caSwyllys KMF_OID *, int, KMF_GENERALNAMECHOICES, char *); 260*d00756ccSwyllys extern KMF_RETURN GetSequenceContents(char *, size_t, char **, size_t *); 261*d00756ccSwyllys extern KMF_X509_EXTENSION *FindExtn(KMF_X509_EXTENSIONS *, KMF_OID *); 262*d00756ccSwyllys extern KMF_RETURN add_an_extension(KMF_X509_EXTENSIONS *exts, 26399ebb4caSwyllys KMF_X509_EXTENSION *newextn); 264*d00756ccSwyllys extern KMF_RETURN set_integer(KMF_DATA *, void *, int); 265*d00756ccSwyllys extern void free_keyidlist(KMF_OID *, int); 266*d00756ccSwyllys extern KMF_RETURN copy_data(KMF_DATA *, KMF_DATA *); 267*d00756ccSwyllys extern void Cleanup_PK11_Session(KMF_HANDLE_T handle); 268*d00756ccSwyllys extern void free_dp_name(KMF_CRL_DIST_POINT *); 269*d00756ccSwyllys extern void free_dp(KMF_CRL_DIST_POINT *); 270*d00756ccSwyllys extern KMF_RETURN set_key_usage_extension(KMF_X509_EXTENSIONS *, 27199ebb4caSwyllys int, uint32_t); 272*d00756ccSwyllys extern KMF_RETURN init_pk11(); 273*d00756ccSwyllys extern KMF_RETURN test_attributes(int, KMF_ATTRIBUTE_TESTER *, 27430a5e8faSwyllys int, KMF_ATTRIBUTE_TESTER *, int, KMF_ATTRIBUTE *); 27599ebb4caSwyllys 27699ebb4caSwyllys /* Indexes into the key parts array for RSA keys */ 27799ebb4caSwyllys #define KMF_RSA_MODULUS (0) 27899ebb4caSwyllys #define KMF_RSA_PUBLIC_EXPONENT (1) 27999ebb4caSwyllys #define KMF_RSA_PRIVATE_EXPONENT (2) 28099ebb4caSwyllys #define KMF_RSA_PRIME1 (3) 28199ebb4caSwyllys #define KMF_RSA_PRIME2 (4) 28299ebb4caSwyllys #define KMF_RSA_EXPONENT1 (5) 28399ebb4caSwyllys #define KMF_RSA_EXPONENT2 (6) 28499ebb4caSwyllys #define KMF_RSA_COEFFICIENT (7) 28599ebb4caSwyllys 28699ebb4caSwyllys /* Key part counts for RSA keys */ 28799ebb4caSwyllys #define KMF_NUMBER_RSA_PUBLIC_KEY_PARTS (2) 28899ebb4caSwyllys #define KMF_NUMBER_RSA_PRIVATE_KEY_PARTS (8) 28999ebb4caSwyllys 29099ebb4caSwyllys /* Key part counts for DSA keys */ 29199ebb4caSwyllys #define KMF_NUMBER_DSA_PUBLIC_KEY_PARTS (4) 29299ebb4caSwyllys #define KMF_NUMBER_DSA_PRIVATE_KEY_PARTS (4) 29399ebb4caSwyllys 29499ebb4caSwyllys /* Indexes into the key parts array for DSA keys */ 29599ebb4caSwyllys #define KMF_DSA_PRIME (0) 29699ebb4caSwyllys #define KMF_DSA_SUB_PRIME (1) 29799ebb4caSwyllys #define KMF_DSA_BASE (2) 29899ebb4caSwyllys #define KMF_DSA_PUBLIC_VALUE (3) 29999ebb4caSwyllys 30099ebb4caSwyllys #ifndef max 30199ebb4caSwyllys #define max(a, b) ((a) < (b) ? (b) : (a)) 30299ebb4caSwyllys #endif 30399ebb4caSwyllys 30499ebb4caSwyllys /* Maximum key parts for all algorithms */ 30599ebb4caSwyllys #define KMF_MAX_PUBLIC_KEY_PARTS \ 30699ebb4caSwyllys (max(KMF_NUMBER_RSA_PUBLIC_KEY_PARTS, \ 30799ebb4caSwyllys KMF_NUMBER_DSA_PUBLIC_KEY_PARTS)) 30899ebb4caSwyllys 30999ebb4caSwyllys #define KMF_MAX_PRIVATE_KEY_PARTS \ 31099ebb4caSwyllys (max(KMF_NUMBER_RSA_PRIVATE_KEY_PARTS, \ 31199ebb4caSwyllys KMF_NUMBER_DSA_PRIVATE_KEY_PARTS)) 31299ebb4caSwyllys 31399ebb4caSwyllys #define KMF_MAX_KEY_PARTS \ 31499ebb4caSwyllys (max(KMF_MAX_PUBLIC_KEY_PARTS, KMF_MAX_PRIVATE_KEY_PARTS)) 31599ebb4caSwyllys 31699ebb4caSwyllys typedef enum { 31799ebb4caSwyllys KMF_ALGMODE_NONE = 0, 31899ebb4caSwyllys KMF_ALGMODE_CUSTOM, 31999ebb4caSwyllys KMF_ALGMODE_PUBLIC_KEY, 32099ebb4caSwyllys KMF_ALGMODE_PRIVATE_KEY, 32199ebb4caSwyllys KMF_ALGMODE_PKCS1_EMSA_V15 32299ebb4caSwyllys } KMF_SIGNATURE_MODE; 32399ebb4caSwyllys 32499ebb4caSwyllys #define KMF_CERT_PRINTABLE_LEN 1024 32599ebb4caSwyllys #define SHA1_HASH_LENGTH 20 32699ebb4caSwyllys 32799ebb4caSwyllys #define OCSPREQ_TEMPNAME "/tmp/ocsp.reqXXXXXX" 32899ebb4caSwyllys #define OCSPRESP_TEMPNAME "/tmp/ocsp.respXXXXXX" 32999ebb4caSwyllys 330431deaa0Shylee #define _PATH_KMF_CONF "/etc/crypto/kmf.conf" 331431deaa0Shylee #define CONF_MODULEPATH "modulepath=" 332431deaa0Shylee #define CONF_OPTION "option=" 333431deaa0Shylee 334431deaa0Shylee typedef struct { 335431deaa0Shylee char *keystore; 336431deaa0Shylee char *modulepath; 337431deaa0Shylee char *option; 338431deaa0Shylee KMF_KEYSTORE_TYPE kstype; 339431deaa0Shylee } conf_entry_t; 340431deaa0Shylee 341431deaa0Shylee typedef struct conf_entrylist { 342431deaa0Shylee conf_entry_t *entry; 343431deaa0Shylee struct conf_entrylist *next; 344431deaa0Shylee } conf_entrylist_t; 345431deaa0Shylee 346431deaa0Shylee 347431deaa0Shylee extern KMF_RETURN get_entrylist(conf_entrylist_t **); 348431deaa0Shylee extern void free_entrylist(conf_entrylist_t *); 349431deaa0Shylee extern void free_entry(conf_entry_t *); 350431deaa0Shylee extern conf_entry_t *dup_entry(conf_entry_t *); 351*d00756ccSwyllys extern boolean_t is_valid_keystore_type(KMF_KEYSTORE_TYPE); 352*d00756ccSwyllys extern KMF_BOOL is_eku_present(KMF_X509EXT_EKU *, KMF_OID *); 353*d00756ccSwyllys extern KMF_RETURN parse_eku_data(const KMF_DATA *, KMF_X509EXT_EKU *); 354431deaa0Shylee 35599ebb4caSwyllys #ifdef __cplusplus 35699ebb4caSwyllys } 35799ebb4caSwyllys #endif 35899ebb4caSwyllys #endif /* _KMFAPIP_H */ 359