📄 cryptack.h
字号:
CRYPT_ARGERROR_NUM1 : CRYPT_ARGERROR_STR1 );
}
else
{
/* getFirst/next. We can report an object error here since
this message is only sent internally */
if( !isValidSubtype( keymgmtACL->keysetFN_subTypeA, subType ) && \
!isValidSubtype( keymgmtACL->keysetFN_subTypeB, subType ) )
return( CRYPT_ARGERROR_OBJECT );
/* Inner precondition: The state information points to an
integer value containing a reference to the currently
fetched object */
PRE( mechanismInfo->auxInfo != NULL && \
mechanismInfo->auxInfoLength == sizeof( int ) );
}
break;
default:
assert( NOTREACHED );
}
/* Make sure there's ID information present if required */
if( keymgmtACL->idUseFlags & accessType )
{
if( mechanismInfo->keyIDtype == CRYPT_KEYID_NONE )
return( CRYPT_ARGERROR_NUM1 );
if( mechanismInfo->keyID == NULL || mechanismInfo->keyIDlength < 1 )
return( CRYPT_ARGERROR_STR1 );
}
/* Make sure there's a password present/not present if required. We
only check for incorrect parameters here if they were supplied by the
user, non-user-supplied parameters (which come from within cryptlib)
are checked by an assertion later on. For keyset objects the
password is optional on reads since it may be a label-only read or an
opportunistic read that tries to read the key without a password
initially and falls back to retrying with a password if this fails,
for device objects the password is never used since it was supplied
when the user logged on to the device.
Since the semantics of passwords for private keys are too complex to
express with a simple ACL entry, this check is hardcoded */
if( messageValue == KEYMGMT_ITEM_PRIVATEKEY )
{
if( objectTable[ objectHandle ].type == OBJECT_TYPE_KEYSET )
{
if( localMessage == MESSAGE_KEY_SETKEY && \
( mechanismInfo->auxInfo == NULL || \
mechanismInfo->auxInfoLength < 1 ) )
/* Private key writes to a keyset must provide a password */
return( CRYPT_ARGERROR_STR1 );
}
else
if( ( mechanismInfo->auxInfo != NULL || \
mechanismInfo->auxInfoLength != 0 ) )
/* Private key access to a device doesn't use a password */
return( ( keymgmtACL->idUseFlags & accessType ) ? \
CRYPT_ARGERROR_STR2 : CRYPT_ARGERROR_STR1 );
}
/* Inner precondition: Only allowed flags are set, there's only one of
the usage preference flags set, and the object handle to get/set is
not present if not required (the presence and validity check when it
is required is performed further down) */
PRE( !( ~keymgmtACL->allowedFlags & mechanismInfo->flags ) );
PRE( mechanismInfo->flags >= KEYMGMT_FLAG_NONE && \
mechanismInfo->flags < KEYMGMT_FLAG_LAST );
PRE( ( mechanismInfo->flags & KEYMGMT_MASK_USAGEOPTIONS ) != \
KEYMGMT_MASK_USAGEOPTIONS );
PRE( localMessage == MESSAGE_KEY_SETKEY || \
mechanismInfo->cryptHandle == CRYPT_ERROR );
/* Inner precondition: There's ID information and a password/aux.data
present/not present as required. For a private key read the password
is optional so we don't check it, for a getFirst/getNext the aux.data
(a pointer to query state) is used when assembling a cert chain (state
held in the cert) and not used when performing a general query (state
held in the keyset) */
PRE( ( ( keymgmtACL->idUseFlags & accessType ) && \
mechanismInfo->keyIDtype != CRYPT_KEYID_NONE && \
mechanismInfo->keyID != NULL && \
mechanismInfo->keyIDlength >= 1 ) ||
( !( keymgmtACL->idUseFlags & accessType ) && \
mechanismInfo->keyIDtype == CRYPT_KEYID_NONE && \
mechanismInfo->keyID == NULL && \
mechanismInfo->keyIDlength == 0 ) );
PRE( ( messageValue == KEYMGMT_ITEM_PRIVATEKEY && \
localMessage == MESSAGE_KEY_GETKEY ) ||
localMessage == MESSAGE_KEY_GETFIRSTCERT ||
localMessage == MESSAGE_KEY_GETNEXTCERT ||
( ( keymgmtACL->pwUseFlags & accessType ) && \
mechanismInfo->auxInfo != NULL && \
mechanismInfo->auxInfoLength >= 1 ) ||
( !( keymgmtACL->pwUseFlags & accessType ) && \
mechanismInfo->auxInfo == NULL && \
mechanismInfo->auxInfoLength == 0 ) );
/* Perform message-type-specific checking of parameters */
switch( localMessage )
{
case MESSAGE_KEY_GETKEY:
break;
case MESSAGE_KEY_SETKEY:
/* Make sure the object being set is valid and its type is
appropriate for this key management item (and via previous
checks, keyset) type. Note that this checks for inclusion in
the set of valid objects, in particular a public-key context
can have almost any type of certificate object attached but
will still be regarded as valid since the context meets the
check requirements. More specific object checks are performed
further on */
paramObjectHandle = mechanismInfo->cryptHandle;
if( !isValidObject( paramObjectHandle ) || \
!isSameOwningObject( objectHandle, paramObjectHandle ) )
return( CRYPT_ARGERROR_NUM1 );
subType = objectST( paramObjectHandle );
if( !isValidSubtype( keymgmtACL->objSubTypeA, subType ) && \
!isValidSubtype( keymgmtACL->objSubTypeB, subType ) )
{
/* If we're only allowed to add contexts, this could be a
cert object with an associated context, in which case
we look for an associated context and try again */
if( keymgmtACL->objSubTypeA != ST_CTX_PKC )
return( CRYPT_ARGERROR_NUM1 );
paramObjectHandle = findTargetType( paramObjectHandle,
OBJECT_TYPE_CONTEXT );
if( cryptStatusError( paramObjectHandle ) || \
objectST( paramObjectHandle ) != ST_CTX_PKC )
return( CRYPT_ARGERROR_NUM1 );
}
if( !isInHighState( paramObjectHandle ) && \
!( subType == ST_CERT_PKIUSER || subType == ST_CERT_REQ_REV ) )
/* PKI user info and revocation requests aren't signed. Like
private key password semantics, these are a bit too
complex to express in the ACL so they're hardcoded */
return( CRYPT_ARGERROR_NUM1 );
/* If we don't need to perform an specific-object check, we're
done */
subType = objectST( objectHandle );
if( !isValidSubtype( keymgmtACL->specificKeysetSubTypeA, subType ) && \
!isValidSubtype( keymgmtACL->specificKeysetSubTypeB, subType ) )
break;
/* We need a specific cert type for this keyset, make sure we've
been passed this and not just a generic PKC-equivalent
object */
paramObjectHandle = findTargetType( mechanismInfo->cryptHandle,
OBJECT_TYPE_CERTIFICATE );
if( cryptStatusError( paramObjectHandle ) )
return( CRYPT_ARGERROR_NUM1 );
subType = objectST( paramObjectHandle );
if( !isValidSubtype( keymgmtACL->specificObjSubTypeA, subType ) && \
!isValidSubtype( keymgmtACL->specificObjSubTypeB, subType ) )
return( CRYPT_ARGERROR_NUM1 );
if( !isInHighState( paramObjectHandle ) )
return( CRYPT_ARGERROR_NUM1 );
break;
case MESSAGE_KEY_DELETEKEY:
break;
case MESSAGE_KEY_GETFIRSTCERT:
break;
case MESSAGE_KEY_GETNEXTCERT:
break;
default:
assert( NOTREACHED );
}
/* Postcondition: The access and parameters are valid and the object
being passed in is of the correct type if present. We don't
explicitly state this since it's just regurgitating the checks
already performed above */
return( CRYPT_OK );
}
#endif /* _CRYPTACK_DEFINED */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -