📄 dev_attr.c
字号:
*valuePtr = errorInfo->errorCode;
return( CRYPT_OK );
}
case CRYPT_DEVINFO_LOGGEDIN:
if( deviceInfoPtr->flags & DEVICE_REMOVABLE )
{
int status;
/* If it's a removable device the user could implicitly log
out by removing it so we have to perform an explicit
check to see whether it's still there */
status = deviceInfoPtr->controlFunction( deviceInfoPtr,
CRYPT_DEVINFO_LOGGEDIN, NULL, 0, NULL );
if( cryptStatusError( status ) )
return( status );
assert( !isMessageObjectUnlocked( messageExtInfo ) );
}
*valuePtr = ( deviceInfoPtr->flags & DEVICE_LOGGEDIN ) ? \
TRUE : FALSE;
return( CRYPT_OK );
}
retIntError();
}
/* Get a string attribute */
CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 4 ) ) \
int getDeviceAttributeS( INOUT DEVICE_INFO *deviceInfoPtr,
INOUT MESSAGE_DATA *msgData,
IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE attribute,
MESSAGE_FUNCTION_EXTINFO *messageExtInfo )
{
assert( isWritePtr( deviceInfoPtr, sizeof( DEVICE_INFO ) ) );
assert( isWritePtr( msgData, sizeof( MESSAGE_DATA ) ) );
assert( isWritePtr( messageExtInfo, \
sizeof( MESSAGE_FUNCTION_EXTINFO ) ) );
REQUIRES( isAttribute( attribute ) || \
isInternalAttribute( attribute ) );
switch( attribute )
{
case CRYPT_ATTRIBUTE_INT_ERRORMESSAGE:
{
ERROR_INFO *errorInfo;
switch( deviceInfoPtr->type )
{
case CRYPT_DEVICE_PKCS11:
errorInfo = &deviceInfoPtr->devicePKCS11->errorInfo;
break;
case CRYPT_DEVICE_FORTEZZA:
errorInfo = &deviceInfoPtr->deviceFortezza->errorInfo;
break;
case CRYPT_DEVICE_CRYPTOAPI:
errorInfo = &deviceInfoPtr->deviceCryptoAPI->errorInfo;
break;
default:
return( exitErrorNotFound( deviceInfoPtr,
CRYPT_ATTRIBUTE_INT_ERRORMESSAGE ) );
}
if( errorInfo->errorStringLength )
return( exitErrorNotFound( deviceInfoPtr,
CRYPT_ATTRIBUTE_INT_ERRORMESSAGE ) );
return( attributeCopy( msgData, errorInfo->errorString,
errorInfo->errorStringLength ) );
}
case CRYPT_DEVINFO_LABEL:
if( deviceInfoPtr->label == NULL )
return( exitErrorNotFound( deviceInfoPtr,
CRYPT_DEVINFO_LABEL ) );
return( attributeCopy( msgData, deviceInfoPtr->label,
strlen( deviceInfoPtr->label ) ) );
case CRYPT_IATTRIBUTE_RANDOM:
if( deviceInfoPtr->getRandomFunction == NULL )
return( CRYPT_ERROR_RANDOM );
return( getRandomChecked( deviceInfoPtr, msgData->data,
msgData->length, messageExtInfo ) );
case CRYPT_IATTRIBUTE_RANDOM_NZ:
if( deviceInfoPtr->getRandomFunction == NULL )
return( CRYPT_ERROR_RANDOM );
return( getRandomNonzero( deviceInfoPtr, msgData->data,
msgData->length, messageExtInfo ) );
case CRYPT_IATTRIBUTE_RANDOM_NONCE:
if( deviceInfoPtr->getRandomFunction == NULL )
return( CRYPT_ERROR_RANDOM );
return( deviceInfoPtr->controlFunction( deviceInfoPtr,
CRYPT_IATTRIBUTE_RANDOM_NONCE,
msgData->data,
msgData->length,
messageExtInfo ) );
case CRYPT_IATTRIBUTE_TIME:
{
time_t *timePtr = msgData->data;
int status;
/* If the device doesn't contain a time source we can't provide
time information */
if( !( deviceInfoPtr->flags & DEVICE_TIME ) )
return( CRYPT_ERROR_NOTAVAIL );
/* Get the time from the device */
status = deviceInfoPtr->controlFunction( deviceInfoPtr,
CRYPT_IATTRIBUTE_TIME,
msgData->data,
msgData->length, NULL );
if( cryptStatusError( status ) )
return( status );
/* Perform a sanity check on the returned value, if it's too far
out then we don't trust it */
if( *timePtr <= MIN_TIME_VALUE )
{
*timePtr = 0;
return( CRYPT_ERROR_NOTAVAIL );
}
return( CRYPT_OK );
}
}
retIntError();
}
/****************************************************************************
* *
* Set Attributes *
* *
****************************************************************************/
/* Set a numeric/boolean attribute */
CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 4 ) ) \
int setDeviceAttribute( INOUT DEVICE_INFO *deviceInfoPtr,
IN_INT_Z const int value,
IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE attribute,
MESSAGE_FUNCTION_EXTINFO *messageExtInfo )
{
assert( isWritePtr( deviceInfoPtr, sizeof( DEVICE_INFO ) ) );
assert( isWritePtr( messageExtInfo, \
sizeof( MESSAGE_FUNCTION_EXTINFO ) ) );
REQUIRES( value >= 0 && value < MAX_INTLENGTH );
REQUIRES( isAttribute( attribute ) || \
isInternalAttribute( attribute ) );
/* Send the control information to the device */
return( deviceInfoPtr->controlFunction( deviceInfoPtr, attribute, NULL,
value, messageExtInfo ) );
}
/* Set a string attribute */
CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 5 ) ) \
int setDeviceAttributeS( INOUT DEVICE_INFO *deviceInfoPtr,
IN_BUFFER( dataLength ) const void *data,
IN_LENGTH const int dataLength,
IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE attribute,
MESSAGE_FUNCTION_EXTINFO *messageExtInfo )
{
int status;
assert( isWritePtr( deviceInfoPtr, sizeof( DEVICE_INFO ) ) );
assert( isReadPtr( data, dataLength ) );
assert( isWritePtr( messageExtInfo, \
sizeof( MESSAGE_FUNCTION_EXTINFO ) ) );
REQUIRES( dataLength > 0 && dataLength < MAX_INTLENGTH );
REQUIRES( isAttribute( attribute ) || \
isInternalAttribute( attribute ) );
/* If the user is logging on to the device we have to perform a bit of
extra processing */
if( attribute == CRYPT_DEVINFO_AUTHENT_USER || \
attribute == CRYPT_DEVINFO_AUTHENT_SUPERVISOR )
{
/* Make sure that a login is actually required for the device */
if( !( deviceInfoPtr->flags & DEVICE_NEEDSLOGIN ) )
return( exitErrorInited( deviceInfoPtr, attribute ) );
/* Send the logon information to the device */
status = deviceInfoPtr->controlFunction( deviceInfoPtr, attribute,
( void * ) data, dataLength,
messageExtInfo );
if( cryptStatusError( status ) )
return( status );
assert( !isMessageObjectUnlocked( messageExtInfo ) );
/* The user has logged in, if the token has a hardware RNG grab 256
bits of entropy and send it to the system device. Since we have
no idea how good this entropy is (it could be just a DES-based
PRNG using a static key or even an LFSR, which some smart cards
use) we don't set any entropy quality indication */
if( deviceInfoPtr->getRandomFunction != NULL )
{
BYTE buffer[ 32 + 8 ];
status = deviceInfoPtr->getRandomFunction( deviceInfoPtr,
buffer, 32, NULL );
if( cryptStatusOK( status ) )
{
MESSAGE_DATA msgData2;
setMessageData( &msgData2, buffer, 32 );
( void ) krnlSendMessage( SYSTEM_OBJECT_HANDLE,
IMESSAGE_SETATTRIBUTE_S, &msgData2,
CRYPT_IATTRIBUTE_ENTROPY );
}
zeroise( buffer, 32 );
}
return( CRYPT_OK );
}
/* Send the control information to the device */
return( deviceInfoPtr->controlFunction( deviceInfoPtr, attribute,
( void * ) data, dataLength,
messageExtInfo ) );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -