📄 cryptack.h
字号:
/****************************************************************************
* *
* Keyset ACLs *
* Copyright Peter Gutmann 1999-2003 *
* *
****************************************************************************/
#ifndef _CRYPTACK_DEFINED
#define _CRYPTACK_DEFINED
/* Key management ACL information. These work in the same general way as the
crypto mechanism ACL checks enforced by the kernel. The ACL entries are:
Valid keyset types for R/W/D access.
Valid keyset types for getFirst/Next access.
Valid keyset types for query access.
Valid object types to write.
Valid key management flags in the mechanism info.
Access type for which an ID parameter is required.
Access type for which a password (or other aux.info) is required
[ Specific object types requires for some keyset types ]
The access-type entries are used for parameter checking and represent all
access types for which these parameters are required, even if those
access types aren't currently allowed by the valid access types entry.
This is to allow them to be enabled by changing only the valid access
types entry without having to update the other two entries as well.
In addition, there are a few access types (specifically getFirst/Next and
private key reads) for which the semantics of password/aux info use are
complex enough that we have to hardcode them, leaving only a
representative entry in the ACL definition. Examples of this are keyset
vs. crypto device reads (keysets usually need passwords while a logged-
in device doesn't), speculative reads from the keyset to determine
presence (which doesn't require a password), and so on.
The (optional) specific object types entry is required for some keysets
that require a specific object (typically a certificate or cert chain)
rather than just a generic PKC context for the overall keyset item type */
static const FAR_BSS KEYMGMT_ACL keyManagementACL[] = {
MK_KEYACL( KEYMGMT_ITEM_NONE, /* No item type */
/*RWD*/ ST_NONE,
/*FnQ*/ ST_NONE,
/*Obj*/ ST_NONE,
/*Flg*/ KEYMGMT_FLAG_NONE,
ACCESS_KEYSET_xxxxx, ACCESS_KEYSET_xxxxx ),
MK_KEYACL_EX( KEYMGMT_ITEM_PUBLICKEY, /* Access public key */
/* R */ ST_KEYSET_ANY | ST_DEV_FORT | ST_DEV_P11,
/* W */ ST_KEYSET_FILE | ST_KEYSET_DBMS | ST_KEYSET_LDAP | ST_DEV_FORT | ST_DEV_P11,
/* D */ ST_KEYSET_FILE | ST_KEYSET_DBMS | ST_KEYSET_LDAP | ST_DEV_FORT | ST_DEV_P11,
/* Fn*/ ST_KEYSET_FILE | ST_KEYSET_DBMS | ST_KEYSET_DBMS_STORE | ST_DEV_FORT,
/* Q */ ST_KEYSET_DBMS | ST_KEYSET_DBMS_STORE | ST_KEYSET_LDAP,
/*Obj*/ ST_CTX_PKC | ST_CERT_CERT | ST_CERT_CERTCHAIN,
/*Flg*/ KEYMGMT_FLAG_CHECK_ONLY | KEYMGMT_FLAG_LABEL_ONLY | KEYMGMT_MASK_CERTOPTIONS,
ACCESS_KEYSET_FxRxD, ACCESS_KEYSET_FNxxx,
ST_KEYSET_DBMS | ST_KEYSET_DBMS_STORE | ST_KEYSET_LDAP | \
ST_DEV_FORT | ST_DEV_P11,
ST_CERT_CERT | ST_CERT_CERTCHAIN ),
MK_KEYACL_RWD( KEYMGMT_ITEM_PRIVATEKEY, /* Access private key */
/* R */ ST_KEYSET_FILE | ST_KEYSET_FILE_PARTIAL | ST_DEV_FORT | ST_DEV_P11,
/* W */ ST_KEYSET_FILE | ST_DEV_FORT | ST_DEV_P11,
/* D */ ST_KEYSET_FILE | ST_DEV_FORT | ST_DEV_P11,
/*FnQ*/ ST_NONE, ST_NONE,
/*Obj*/ ST_CTX_PKC,
/*Flg*/ KEYMGMT_FLAG_CHECK_ONLY | KEYMGMT_FLAG_LABEL_ONLY | KEYMGMT_MASK_USAGEOPTIONS,
ACCESS_KEYSET_xxRxD, ACCESS_KEYSET_xxXXx ),
MK_KEYACL( KEYMGMT_ITEM_SECRETKEY, /* Access secret key */
/*RWD*/ ST_KEYSET_FILE,
/*FnQ*/ ST_NONE,
/*Obj*/ ST_CTX_CONV,
/*Flg*/ KEYMGMT_FLAG_NONE,
ACCESS_KEYSET_xxRxD, ACCESS_KEYSET_xxRWx ),
MK_KEYACL_RWD( KEYMGMT_ITEM_REQUEST, /* Access cert request */
/*RWD*/ ST_KEYSET_DBMS_STORE, ST_KEYSET_DBMS_STORE, ST_NONE,
/*FnQ*/ ST_NONE, ST_KEYSET_DBMS_STORE,
/*Obj*/ ST_CERT_CERTREQ | ST_CERT_REQ_CERT | ST_CERT_REQ_REV,
/*Flg*/ KEYMGMT_FLAG_UPDATE,
ACCESS_KEYSET_FxRxD, ACCESS_KEYSET_FNxxx ),
MK_KEYACL_RWD( KEYMGMT_ITEM_PKIUSER, /* Access PKI user info */
/*RWD*/ ST_KEYSET_DBMS_STORE, ST_KEYSET_DBMS_STORE, ST_NONE,
/*FnQ*/ ST_NONE, ST_NONE,
/*Obj*/ ST_CERT_PKIUSER,
/*Flg*/ KEYMGMT_FLAG_GETISSUER,
ACCESS_KEYSET_FxRxD, ACCESS_KEYSET_FNxxx ),
MK_KEYACL_RWD( KEYMGMT_ITEM_REVOCATIONINFO, /* Access revocation info/CRL */
/*RWD*/ ST_KEYSET_DBMS | ST_KEYSET_DBMS_STORE, ST_KEYSET_DBMS, ST_NONE,
/*FnQ*/ ST_NONE, ST_NONE,
/*Obj*/ ST_CERT_CRL,
/*Flg*/ KEYMGMT_FLAG_CHECK_ONLY,
ACCESS_KEYSET_FxRxD, ACCESS_KEYSET_FNxxx ),
MK_KEYACL_RWD( KEYMGMT_ITEM_DATA, /* Other data (for PKCS #15 tokens) */
/*RWD*/ ST_KEYSET_FILE, ST_KEYSET_FILE, ST_NONE,
/*FnQ*/ ST_NONE, ST_NONE,
/*Obj*/ ST_NONE,
/*Flg*/ KEYMGMT_FLAG_NONE,
ACCESS_KEYSET_xxRWD, ACCESS_KEYSET_FNxxx ),
MK_KEYACL( KEYMGMT_ITEM_LAST, /* Last item type */
/*RWD*/ ST_NONE,
/*FnQ*/ ST_NONE,
/*Obj*/ ST_NONE,
/*Flg*/ KEYMGMT_FLAG_NONE,
ACCESS_KEYSET_xxxxx, ACCESS_KEYSET_xxxxx )
};
/* It's a keyset action message, check the access conditions for the mechanism
objects */
static int preDispatchCheckKeysetAccess( const int objectHandle,
const MESSAGE_TYPE message,
const void *messageDataPtr,
const int messageValue,
const void *dummy )
{
const MESSAGE_TYPE localMessage = message & MESSAGE_MASK;
const MESSAGE_KEYMGMT_INFO *mechanismInfo = \
( MESSAGE_KEYMGMT_INFO * ) messageDataPtr;
const KEYMGMT_ACL *keymgmtACL = \
&keyManagementACL[ messageValue ];
const int accessType = \
( localMessage == MESSAGE_KEY_GETKEY ) ? ACCESS_FLAG_R : \
( localMessage == MESSAGE_KEY_SETKEY ) ? ACCESS_FLAG_W : \
( localMessage == MESSAGE_KEY_DELETEKEY ) ? ACCESS_FLAG_D : \
( localMessage == MESSAGE_KEY_GETFIRSTCERT ) ? ACCESS_FLAG_F : \
( localMessage == MESSAGE_KEY_GETNEXTCERT ) ? ACCESS_FLAG_N : 0;
OBJECT_SUBTYPE subType;
int paramObjectHandle;
/* Preconditions */
PRE( isValidObject( objectHandle ) );
PRE( localMessage == MESSAGE_KEY_GETKEY || \
localMessage == MESSAGE_KEY_SETKEY || \
localMessage == MESSAGE_KEY_DELETEKEY || \
localMessage == MESSAGE_KEY_GETFIRSTCERT || \
localMessage == MESSAGE_KEY_GETNEXTCERT );
PRE( messageDataPtr != NULL );
PRE( messageValue > KEYMGMT_ITEM_NONE && \
messageValue < KEYMGMT_ITEM_LAST );
PRE( keymgmtACL->itemType == messageValue );
PRE( accessType != 0 );
/* Perform a combined check to ensure the item type being accessed is
appropriate for this keyset type and the access type is valid */
subType = objectST( objectHandle );
switch( localMessage )
{
case MESSAGE_KEY_GETKEY:
if( !isValidSubtype( keymgmtACL->keysetR_subTypeA, subType ) && \
!isValidSubtype( keymgmtACL->keysetR_subTypeB, subType ) )
return( CRYPT_ARGERROR_OBJECT );
break;
case MESSAGE_KEY_SETKEY:
if( !isValidSubtype( keymgmtACL->keysetW_subTypeA, subType ) && \
!isValidSubtype( keymgmtACL->keysetW_subTypeB, subType ) )
return( CRYPT_ARGERROR_OBJECT );
break;
case MESSAGE_KEY_DELETEKEY:
if( !isValidSubtype( keymgmtACL->keysetD_subTypeA, subType ) && \
!isValidSubtype( keymgmtACL->keysetD_subTypeB, subType ) )
return( CRYPT_ARGERROR_OBJECT );
break;
case MESSAGE_KEY_GETFIRSTCERT:
case MESSAGE_KEY_GETNEXTCERT:
/* The two special-purpose accesses are differentiated by whether
there's state information provided. For a general query the
result set is determined by an initially-submitted query
which is followed by a sequence of fetches. For a getFirst/
getNext the results are determined by a cert identifier with
state held externally in the location pointed to by the
auxiliary info pointer */
if( mechanismInfo->auxInfo == NULL )
{
/* Keyset query. We report this as an arg error since we'll
have been passed a CRYPT_KEYID_NONE or empty keyID, this
is more sensible than an object error since there's
nothing wrong with the object, the problem is that
there's no keyID present */
if( !isValidSubtype( keymgmtACL->keysetQ_subTypeA, subType ) && \
!isValidSubtype( keymgmtACL->keysetQ_subTypeB, subType ) )
return( ( mechanismInfo->keyIDtype == CRYPT_KEYID_NONE ) ? \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -