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 20*269e59f9SJan Pechanec * 21*269e59f9SJan Pechanec * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. 2299ebb4caSwyllys */ 2399ebb4caSwyllys #ifndef _KMFAPIP_H 2499ebb4caSwyllys #define _KMFAPIP_H 2599ebb4caSwyllys 2699ebb4caSwyllys #include <kmfapi.h> 2799ebb4caSwyllys #include <kmfpolicy.h> 2899ebb4caSwyllys 2999ebb4caSwyllys #ifdef __cplusplus 3099ebb4caSwyllys extern "C" { 3199ebb4caSwyllys #endif 3299ebb4caSwyllys 3399ebb4caSwyllys /* Plugin function table */ 3499ebb4caSwyllys typedef struct { 3599ebb4caSwyllys ushort_t version; 3699ebb4caSwyllys KMF_RETURN (*ConfigureKeystore) ( 3799ebb4caSwyllys KMF_HANDLE_T, 3830a5e8faSwyllys int, 3930a5e8faSwyllys KMF_ATTRIBUTE *); 4099ebb4caSwyllys 4199ebb4caSwyllys KMF_RETURN (*FindCert) ( 4299ebb4caSwyllys KMF_HANDLE_T, 4330a5e8faSwyllys int, 4430a5e8faSwyllys KMF_ATTRIBUTE *); 4599ebb4caSwyllys 4699ebb4caSwyllys void (*FreeKMFCert) ( 4799ebb4caSwyllys KMF_HANDLE_T, 4899ebb4caSwyllys KMF_X509_DER_CERT *); 4999ebb4caSwyllys 5099ebb4caSwyllys KMF_RETURN (*StoreCert) ( 5199ebb4caSwyllys KMF_HANDLE_T, 5230a5e8faSwyllys int, KMF_ATTRIBUTE *); 5399ebb4caSwyllys 5499ebb4caSwyllys KMF_RETURN (*ImportCert) ( 5599ebb4caSwyllys KMF_HANDLE_T, 5630a5e8faSwyllys int, KMF_ATTRIBUTE *); 5799ebb4caSwyllys 5899ebb4caSwyllys KMF_RETURN (*ImportCRL) ( 5999ebb4caSwyllys KMF_HANDLE_T, 6030a5e8faSwyllys int, KMF_ATTRIBUTE *); 6199ebb4caSwyllys 6299ebb4caSwyllys KMF_RETURN (*DeleteCert) ( 6399ebb4caSwyllys KMF_HANDLE_T, 6430a5e8faSwyllys int, KMF_ATTRIBUTE *); 6599ebb4caSwyllys 6699ebb4caSwyllys KMF_RETURN (*DeleteCRL) ( 6799ebb4caSwyllys KMF_HANDLE_T, 6830a5e8faSwyllys int, KMF_ATTRIBUTE *); 6999ebb4caSwyllys 7099ebb4caSwyllys KMF_RETURN (*CreateKeypair) ( 7199ebb4caSwyllys KMF_HANDLE_T, 7230a5e8faSwyllys int, 7330a5e8faSwyllys KMF_ATTRIBUTE *); 7499ebb4caSwyllys 7599ebb4caSwyllys KMF_RETURN (*FindKey) ( 7699ebb4caSwyllys KMF_HANDLE_T, 7730a5e8faSwyllys int, 7830a5e8faSwyllys KMF_ATTRIBUTE *); 7999ebb4caSwyllys 8099ebb4caSwyllys KMF_RETURN (*EncodePubkeyData) ( 8199ebb4caSwyllys KMF_HANDLE_T, 8299ebb4caSwyllys KMF_KEY_HANDLE *, 8399ebb4caSwyllys KMF_DATA *); 8499ebb4caSwyllys 8599ebb4caSwyllys KMF_RETURN (*SignData) ( 8699ebb4caSwyllys KMF_HANDLE_T, 8799ebb4caSwyllys KMF_KEY_HANDLE *, 8899ebb4caSwyllys KMF_OID *, 8999ebb4caSwyllys KMF_DATA *, 9099ebb4caSwyllys KMF_DATA *); 9199ebb4caSwyllys 9299ebb4caSwyllys KMF_RETURN (*DeleteKey) ( 9399ebb4caSwyllys KMF_HANDLE_T, 9430a5e8faSwyllys int, 9530a5e8faSwyllys KMF_ATTRIBUTE *); 9699ebb4caSwyllys 9799ebb4caSwyllys KMF_RETURN (*ListCRL) ( 9899ebb4caSwyllys KMF_HANDLE_T, 9930a5e8faSwyllys int, KMF_ATTRIBUTE *); 10099ebb4caSwyllys 10199ebb4caSwyllys KMF_RETURN (*FindCRL) ( 10299ebb4caSwyllys KMF_HANDLE_T, 10330a5e8faSwyllys int, KMF_ATTRIBUTE *); 10499ebb4caSwyllys 10599ebb4caSwyllys KMF_RETURN (*FindCertInCRL) ( 10699ebb4caSwyllys KMF_HANDLE_T, 10730a5e8faSwyllys int, KMF_ATTRIBUTE *); 10899ebb4caSwyllys 10999ebb4caSwyllys KMF_RETURN (*GetErrorString) ( 11099ebb4caSwyllys KMF_HANDLE_T, 11199ebb4caSwyllys char **); 11299ebb4caSwyllys 11330a5e8faSwyllys KMF_RETURN (*FindPrikeyByCert) ( 11499ebb4caSwyllys KMF_HANDLE_T, 11530a5e8faSwyllys int, 11630a5e8faSwyllys KMF_ATTRIBUTE *); 11799ebb4caSwyllys 11899ebb4caSwyllys KMF_RETURN (*DecryptData) ( 11999ebb4caSwyllys KMF_HANDLE_T, 12099ebb4caSwyllys KMF_KEY_HANDLE *, 12199ebb4caSwyllys KMF_OID *, 12299ebb4caSwyllys KMF_DATA *, 12399ebb4caSwyllys KMF_DATA *); 12499ebb4caSwyllys 12530a5e8faSwyllys KMF_RETURN (*ExportPK12)( 12699ebb4caSwyllys KMF_HANDLE_T, 12730a5e8faSwyllys int, 12830a5e8faSwyllys KMF_ATTRIBUTE *); 12999ebb4caSwyllys 13099ebb4caSwyllys KMF_RETURN (*CreateSymKey) ( 13199ebb4caSwyllys KMF_HANDLE_T, 13230a5e8faSwyllys int, 13330a5e8faSwyllys KMF_ATTRIBUTE *); 13499ebb4caSwyllys 13599ebb4caSwyllys KMF_RETURN (*GetSymKeyValue) ( 13699ebb4caSwyllys KMF_HANDLE_T, 13799ebb4caSwyllys KMF_KEY_HANDLE *, 13899ebb4caSwyllys KMF_RAW_SYM_KEY *); 13999ebb4caSwyllys 14099ebb4caSwyllys KMF_RETURN (*SetTokenPin) ( 14199ebb4caSwyllys KMF_HANDLE_T, 14230a5e8faSwyllys int, KMF_ATTRIBUTE *); 14399ebb4caSwyllys 14430a5e8faSwyllys KMF_RETURN (*StoreKey) ( 14530a5e8faSwyllys KMF_HANDLE_T, 14630a5e8faSwyllys int, 14730a5e8faSwyllys KMF_ATTRIBUTE *); 14830a5e8faSwyllys 14999ebb4caSwyllys void (*Finalize) (); 15099ebb4caSwyllys 15199ebb4caSwyllys } KMF_PLUGIN_FUNCLIST; 15299ebb4caSwyllys 15399ebb4caSwyllys typedef struct { 15430a5e8faSwyllys KMF_ATTR_TYPE type; 15530a5e8faSwyllys boolean_t null_value_ok; /* Is the pValue required */ 15630a5e8faSwyllys uint32_t minlen; 15730a5e8faSwyllys uint32_t maxlen; 15830a5e8faSwyllys } KMF_ATTRIBUTE_TESTER; 15930a5e8faSwyllys 16030a5e8faSwyllys typedef struct { 16199ebb4caSwyllys KMF_KEYSTORE_TYPE type; 16299ebb4caSwyllys char *applications; 16399ebb4caSwyllys char *path; 16499ebb4caSwyllys void *dldesc; 16599ebb4caSwyllys KMF_PLUGIN_FUNCLIST *funclist; 16699ebb4caSwyllys } KMF_PLUGIN; 16799ebb4caSwyllys 16899ebb4caSwyllys typedef struct _KMF_PLUGIN_LIST { 16999ebb4caSwyllys KMF_PLUGIN *plugin; 17099ebb4caSwyllys struct _KMF_PLUGIN_LIST *next; 17199ebb4caSwyllys } KMF_PLUGIN_LIST; 17299ebb4caSwyllys 17399ebb4caSwyllys typedef struct _kmf_handle { 17499ebb4caSwyllys /* 17530a5e8faSwyllys * session handle opened by kmf_select_token() to talk 17699ebb4caSwyllys * to a specific slot in Crypto framework. It is used 17799ebb4caSwyllys * by pkcs11 plugin module. 17899ebb4caSwyllys */ 17999ebb4caSwyllys CK_SESSION_HANDLE pk11handle; 18099ebb4caSwyllys KMF_ERROR lasterr; 18199ebb4caSwyllys KMF_POLICY_RECORD *policy; 18299ebb4caSwyllys KMF_PLUGIN_LIST *plugins; 183*269e59f9SJan Pechanec KMF_MAPPER_STATE *mapstate; 18499ebb4caSwyllys } KMF_HANDLE; 18599ebb4caSwyllys 18699ebb4caSwyllys #define CLEAR_ERROR(h, rv) { \ 18799ebb4caSwyllys if (h == NULL) { \ 18899ebb4caSwyllys rv = KMF_ERR_BAD_PARAMETER; \ 18999ebb4caSwyllys } else { \ 19099ebb4caSwyllys h->lasterr.errcode = 0; \ 19199ebb4caSwyllys h->lasterr.kstype = 0; \ 19299ebb4caSwyllys rv = KMF_OK; \ 19399ebb4caSwyllys } \ 19499ebb4caSwyllys } 19599ebb4caSwyllys 19699ebb4caSwyllys #define KMF_PLUGIN_INIT_SYMBOL "KMF_Plugin_Initialize" 19799ebb4caSwyllys 19899ebb4caSwyllys #ifndef KMF_PLUGIN_PATH 19999ebb4caSwyllys #if defined(__sparcv9) 200257873cfSJohn.Zolnowsky@Sun.COM #define KMF_PLUGIN_PATH "/lib/crypto/sparcv9/" 20199ebb4caSwyllys #elif defined(__sparc) 202257873cfSJohn.Zolnowsky@Sun.COM #define KMF_PLUGIN_PATH "/lib/crypto/" 20399ebb4caSwyllys #elif defined(__i386) 204257873cfSJohn.Zolnowsky@Sun.COM #define KMF_PLUGIN_PATH "/lib/crypto/" 20599ebb4caSwyllys #elif defined(__amd64) 206257873cfSJohn.Zolnowsky@Sun.COM #define KMF_PLUGIN_PATH "/lib/crypto/amd64/" 20799ebb4caSwyllys #endif 20899ebb4caSwyllys #endif /* !KMF_PLUGIN_PATH */ 20999ebb4caSwyllys 21099ebb4caSwyllys KMF_PLUGIN_FUNCLIST *KMF_Plugin_Initialize(); 21199ebb4caSwyllys 212d00756ccSwyllys extern KMF_RETURN 213d00756ccSwyllys VerifyDataWithKey(KMF_HANDLE_T, KMF_DATA *, KMF_ALGORITHM_INDEX, 214d00756ccSwyllys KMF_DATA *, KMF_DATA *); 21599ebb4caSwyllys 216d00756ccSwyllys extern KMF_BOOL pkcs_algid_to_keytype( 21799ebb4caSwyllys KMF_ALGORITHM_INDEX, CK_KEY_TYPE *); 21899ebb4caSwyllys 219e65e5c2dSWyllys Ingersoll extern KMF_RETURN PKCS_DigestData(KMF_HANDLE_T, 220e65e5c2dSWyllys Ingersoll CK_SESSION_HANDLE, CK_MECHANISM_TYPE, 221e65e5c2dSWyllys Ingersoll KMF_DATA *, KMF_DATA *, boolean_t); 222e65e5c2dSWyllys Ingersoll 223d00756ccSwyllys extern KMF_RETURN PKCS_VerifyData( 22499ebb4caSwyllys KMF_HANDLE *, 22599ebb4caSwyllys KMF_ALGORITHM_INDEX, 22699ebb4caSwyllys KMF_X509_SPKI *, 22799ebb4caSwyllys KMF_DATA *, KMF_DATA *); 22899ebb4caSwyllys 229d00756ccSwyllys extern KMF_RETURN PKCS_EncryptData( 23099ebb4caSwyllys KMF_HANDLE *, 23199ebb4caSwyllys KMF_ALGORITHM_INDEX, 23299ebb4caSwyllys KMF_X509_SPKI *, 23399ebb4caSwyllys KMF_DATA *, 23499ebb4caSwyllys KMF_DATA *); 23599ebb4caSwyllys 236d00756ccSwyllys extern KMF_PLUGIN *FindPlugin(KMF_HANDLE_T, KMF_KEYSTORE_TYPE); 23799ebb4caSwyllys 238d00756ccSwyllys extern KMF_BOOL IsEqualOid(KMF_OID *, KMF_OID *); 23999ebb4caSwyllys 240d00756ccSwyllys extern KMF_RETURN copy_algoid(KMF_X509_ALGORITHM_IDENTIFIER *destid, 24130a5e8faSwyllys KMF_X509_ALGORITHM_IDENTIFIER *srcid); 24230a5e8faSwyllys 243d00756ccSwyllys extern KMF_OID *x509_algid_to_algoid(KMF_ALGORITHM_INDEX); 244d00756ccSwyllys extern KMF_ALGORITHM_INDEX x509_algoid_to_algid(KMF_OID *); 24530a5e8faSwyllys 246d00756ccSwyllys extern KMF_RETURN GetIDFromSPKI(KMF_X509_SPKI *, KMF_DATA *); 247d00756ccSwyllys extern KMF_RETURN kmf_select_token(KMF_HANDLE_T, char *, int); 248d00756ccSwyllys extern KMF_RETURN kmf_set_altname(KMF_X509_EXTENSIONS *, 24999ebb4caSwyllys KMF_OID *, int, KMF_GENERALNAMECHOICES, char *); 250d00756ccSwyllys extern KMF_RETURN GetSequenceContents(char *, size_t, char **, size_t *); 251d00756ccSwyllys extern KMF_X509_EXTENSION *FindExtn(KMF_X509_EXTENSIONS *, KMF_OID *); 252d00756ccSwyllys extern KMF_RETURN add_an_extension(KMF_X509_EXTENSIONS *exts, 25399ebb4caSwyllys KMF_X509_EXTENSION *newextn); 254d00756ccSwyllys extern KMF_RETURN set_integer(KMF_DATA *, void *, int); 255d00756ccSwyllys extern void free_keyidlist(KMF_OID *, int); 256d00756ccSwyllys extern KMF_RETURN copy_data(KMF_DATA *, KMF_DATA *); 257d00756ccSwyllys extern void Cleanup_PK11_Session(KMF_HANDLE_T handle); 258d00756ccSwyllys extern void free_dp_name(KMF_CRL_DIST_POINT *); 259d00756ccSwyllys extern void free_dp(KMF_CRL_DIST_POINT *); 260d00756ccSwyllys extern KMF_RETURN set_key_usage_extension(KMF_X509_EXTENSIONS *, 26199ebb4caSwyllys int, uint32_t); 262d00756ccSwyllys extern KMF_RETURN init_pk11(); 263d00756ccSwyllys extern KMF_RETURN test_attributes(int, KMF_ATTRIBUTE_TESTER *, 26430a5e8faSwyllys int, KMF_ATTRIBUTE_TESTER *, int, KMF_ATTRIBUTE *); 26599ebb4caSwyllys 26699ebb4caSwyllys /* Indexes into the key parts array for RSA keys */ 26799ebb4caSwyllys #define KMF_RSA_MODULUS (0) 26899ebb4caSwyllys #define KMF_RSA_PUBLIC_EXPONENT (1) 26999ebb4caSwyllys #define KMF_RSA_PRIVATE_EXPONENT (2) 27099ebb4caSwyllys #define KMF_RSA_PRIME1 (3) 27199ebb4caSwyllys #define KMF_RSA_PRIME2 (4) 27299ebb4caSwyllys #define KMF_RSA_EXPONENT1 (5) 27399ebb4caSwyllys #define KMF_RSA_EXPONENT2 (6) 27499ebb4caSwyllys #define KMF_RSA_COEFFICIENT (7) 27599ebb4caSwyllys 27699ebb4caSwyllys /* Key part counts for RSA keys */ 27799ebb4caSwyllys #define KMF_NUMBER_RSA_PUBLIC_KEY_PARTS (2) 27899ebb4caSwyllys #define KMF_NUMBER_RSA_PRIVATE_KEY_PARTS (8) 27999ebb4caSwyllys 28099ebb4caSwyllys /* Key part counts for DSA keys */ 28199ebb4caSwyllys #define KMF_NUMBER_DSA_PUBLIC_KEY_PARTS (4) 28299ebb4caSwyllys #define KMF_NUMBER_DSA_PRIVATE_KEY_PARTS (4) 28399ebb4caSwyllys 28499ebb4caSwyllys /* Indexes into the key parts array for DSA keys */ 28599ebb4caSwyllys #define KMF_DSA_PRIME (0) 28699ebb4caSwyllys #define KMF_DSA_SUB_PRIME (1) 28799ebb4caSwyllys #define KMF_DSA_BASE (2) 28899ebb4caSwyllys #define KMF_DSA_PUBLIC_VALUE (3) 28999ebb4caSwyllys 290e65e5c2dSWyllys Ingersoll #define KMF_ECDSA_PARAMS (0) 291e65e5c2dSWyllys Ingersoll #define KMF_ECDSA_POINT (1) 292e65e5c2dSWyllys Ingersoll 29399ebb4caSwyllys #ifndef max 29499ebb4caSwyllys #define max(a, b) ((a) < (b) ? (b) : (a)) 29599ebb4caSwyllys #endif 29699ebb4caSwyllys 29799ebb4caSwyllys /* Maximum key parts for all algorithms */ 29899ebb4caSwyllys #define KMF_MAX_PUBLIC_KEY_PARTS \ 29999ebb4caSwyllys (max(KMF_NUMBER_RSA_PUBLIC_KEY_PARTS, \ 30099ebb4caSwyllys KMF_NUMBER_DSA_PUBLIC_KEY_PARTS)) 30199ebb4caSwyllys 30299ebb4caSwyllys #define KMF_MAX_PRIVATE_KEY_PARTS \ 30399ebb4caSwyllys (max(KMF_NUMBER_RSA_PRIVATE_KEY_PARTS, \ 30499ebb4caSwyllys KMF_NUMBER_DSA_PRIVATE_KEY_PARTS)) 30599ebb4caSwyllys 30699ebb4caSwyllys #define KMF_MAX_KEY_PARTS \ 30799ebb4caSwyllys (max(KMF_MAX_PUBLIC_KEY_PARTS, KMF_MAX_PRIVATE_KEY_PARTS)) 30899ebb4caSwyllys 30999ebb4caSwyllys typedef enum { 31099ebb4caSwyllys KMF_ALGMODE_NONE = 0, 31199ebb4caSwyllys KMF_ALGMODE_CUSTOM, 31299ebb4caSwyllys KMF_ALGMODE_PUBLIC_KEY, 31399ebb4caSwyllys KMF_ALGMODE_PRIVATE_KEY, 31499ebb4caSwyllys KMF_ALGMODE_PKCS1_EMSA_V15 31599ebb4caSwyllys } KMF_SIGNATURE_MODE; 31699ebb4caSwyllys 31799ebb4caSwyllys #define KMF_CERT_PRINTABLE_LEN 1024 31899ebb4caSwyllys #define SHA1_HASH_LENGTH 20 31999ebb4caSwyllys 32099ebb4caSwyllys #define OCSPREQ_TEMPNAME "/tmp/ocsp.reqXXXXXX" 32199ebb4caSwyllys #define OCSPRESP_TEMPNAME "/tmp/ocsp.respXXXXXX" 32299ebb4caSwyllys 323431deaa0Shylee #define _PATH_KMF_CONF "/etc/crypto/kmf.conf" 324431deaa0Shylee #define CONF_MODULEPATH "modulepath=" 325431deaa0Shylee #define CONF_OPTION "option=" 326431deaa0Shylee 327431deaa0Shylee typedef struct { 328431deaa0Shylee char *keystore; 329431deaa0Shylee char *modulepath; 330431deaa0Shylee char *option; 331431deaa0Shylee KMF_KEYSTORE_TYPE kstype; 332431deaa0Shylee } conf_entry_t; 333431deaa0Shylee 334431deaa0Shylee typedef struct conf_entrylist { 335431deaa0Shylee conf_entry_t *entry; 336431deaa0Shylee struct conf_entrylist *next; 337431deaa0Shylee } conf_entrylist_t; 338431deaa0Shylee 339e65e5c2dSWyllys Ingersoll extern KMF_RETURN get_pk11_data(KMF_ALGORITHM_INDEX, 340e65e5c2dSWyllys Ingersoll CK_KEY_TYPE *, CK_MECHANISM_TYPE *, CK_MECHANISM_TYPE *, boolean_t); 341e65e5c2dSWyllys Ingersoll extern KMF_RETURN kmf_create_pk11_session(CK_SESSION_HANDLE *, 342e65e5c2dSWyllys Ingersoll CK_MECHANISM_TYPE, CK_FLAGS); 343431deaa0Shylee extern KMF_RETURN get_entrylist(conf_entrylist_t **); 344431deaa0Shylee extern void free_entrylist(conf_entrylist_t *); 345431deaa0Shylee extern void free_entry(conf_entry_t *); 346431deaa0Shylee extern conf_entry_t *dup_entry(conf_entry_t *); 347d00756ccSwyllys extern boolean_t is_valid_keystore_type(KMF_KEYSTORE_TYPE); 348d00756ccSwyllys extern KMF_BOOL is_eku_present(KMF_X509EXT_EKU *, KMF_OID *); 349d00756ccSwyllys extern KMF_RETURN parse_eku_data(const KMF_DATA *, KMF_X509EXT_EKU *); 350*269e59f9SJan Pechanec extern KMF_RETURN copy_extension_data(KMF_X509_EXTENSION *, 351*269e59f9SJan Pechanec KMF_X509_EXTENSION *); 352*269e59f9SJan Pechanec extern char *get_mapper_pathname(char *, char *); 353431deaa0Shylee 35499ebb4caSwyllys #ifdef __cplusplus 35599ebb4caSwyllys } 35699ebb4caSwyllys #endif 35799ebb4caSwyllys #endif /* _KMFAPIP_H */ 358