11 #if defined( INC_ALL )
23 assert( cmd->
noArgs == 2 );
39 static int cmdCertMgmt(
void *stateInfo,
COMMAND_INFO *cmd )
47 assert( cmd->
noArgs == 4 );
55 if( cmd->
arg[ 1 ] < CRYPT_CERTACTION_FIRST_USER || \
56 cmd->
arg[ 1 ] > CRYPT_CERTACTION_LAST_USER )
77 &certMgmtInfo, cmd->
arg[ 1 ] );
83 static int cmdCertSign(
void *stateInfo,
COMMAND_INFO *cmd )
87 assert( cmd->
noArgs == 2 );
102 static int cmdCreateObject(
void *stateInfo,
COMMAND_INFO *cmd )
122 switch( cmd->
arg[ 1 ] )
125 assert( cmd->
noArgs == 3 );
128 cmd->
arg[ 2 ] >= CRYPT_ALGO_LAST_EXTERNAL ) && \
134 assert( cmd->
noArgs == 3 );
137 cmd->
arg[ 2 ] >= CRYPT_CERTTYPE_LAST_EXTERNAL )
142 assert( cmd->
noArgs == 3 );
158 assert( cmd->
noArgs == 4 );
167 cmd->
arg[ 3 ] >= CRYPT_KEYOPT_LAST_EXTERNAL )
176 assert( cmd->
noArgs == 3 );
179 cmd->
arg[ 2 ] >= CRYPT_FORMAT_LAST_EXTERNAL )
184 assert( cmd->
noArgs == 3 );
192 assert( cmd->
noArgs == 2 );
212 owner = cmd->
arg[ 0 ];
220 createInfo.
arg2 = cmd->
arg[ 3 ];
223 createInfo.strArg1 = cmd->
strArg[ 0 ];
227 createInfo.strArg2 = cmd->
strArg[ 1 ];
240 &createInfo, cmd->
arg[ 1 ] );
279 static int cmdCreateObjectIndirect(
void *stateInfo,
COMMAND_INFO *cmd )
286 assert( cmd->
noArgs == 2 );
328 static int cmdDecrypt(
void *stateInfo,
COMMAND_INFO *cmd )
334 assert( cmd->
noArgs == 1 );
405 static int cmdDeleteAttribute(
void *stateInfo,
COMMAND_INFO *cmd )
409 assert( cmd->
noArgs == 2 );
444 static int cmdDeleteKey(
void *stateInfo,
COMMAND_INFO *cmd )
460 cmd->
arg[ 1 ] >= CRYPT_KEYID_LAST_EXTERNAL )
486 &deletekeyInfo, itemType ) );
489 static int cmdDestroyObject(
void *stateInfo,
COMMAND_INFO *cmd )
493 assert( cmd->
noArgs == 1 );
508 static int cmdEncrypt(
void *stateInfo,
COMMAND_INFO *cmd )
514 assert( cmd->
noArgs == 1 );
600 static int cmdExportObject(
void *stateInfo,
COMMAND_INFO *cmd )
608 assert( cmd->
noArgs == 2 );
612 cmd->
strArg[ 0 ] != NULL );
620 cmd->
arg[ 1 ] >= CRYPT_CERTFORMAT_LAST_EXTERNAL )
632 &msgData, cmd->
arg[ 1 ] );
640 &msgData, cmd->
arg[ 1 ] );
675 static int cmdFlushData(
void *stateInfo,
COMMAND_INFO *cmd )
682 assert( cmd->
noArgs == 1 );
698 static int cmdGenKey(
void *stateInfo,
COMMAND_INFO *cmd )
702 assert( cmd->
noArgs == 1 );
714 static int cmdGetAttribute(
void *stateInfo,
COMMAND_INFO *cmd )
769 &cmd->
arg[ 0 ], cmd->
arg[ 1 ] ) );
781 &msgData, cmd->
arg[ 1 ] );
790 msgData.data = cmd->
strArg[ 0 ];
800 &msgData, cmd->
arg[ 1 ] );
807 static int cmdGetKey(
void *stateInfo,
COMMAND_INFO *cmd )
816 assert( cmd->
noArgs == 3 );
837 cmd->
arg[ 2 ] >= CRYPT_KEYID_LAST_EXTERNAL )
889 static int cmdPopData(
void *stateInfo,
COMMAND_INFO *cmd )
896 assert( cmd->
noArgs == 2 );
904 if( cmd->
arg[ 1 ] < 1 )
916 static int cmdPushData(
void *stateInfo,
COMMAND_INFO *cmd )
923 assert( cmd->
noArgs == 1 );
944 static int cmdQueryCapability(
void *stateInfo,
COMMAND_INFO *cmd )
952 assert( cmd->
noArgs == 2 );
956 cmd->
strArg[ 0 ] != NULL );
965 cmd->
arg[ 1 ] >= CRYPT_ALGO_LAST_EXTERNAL )
981 &queryInfo, cmd->
arg[ 1 ] );
991 memcpy( cmd->
strArg[ 0 ], &queryInfo,
1002 static int cmdServerQuery(
void *stateInfo,
COMMAND_INFO *cmd )
1008 assert( cmd->
noArgs == 0 );
1023 static int cmdSetAttribute(
void *stateInfo,
COMMAND_INFO *cmd )
1093 &msgData, cmd->
arg[ 1 ] ) );
1096 static int cmdSetKey(
void *stateInfo,
COMMAND_INFO *cmd )
1099 int itemType = ( cmd->
noStrArgs == 1 ) ? \
1151 &setkeyInfo, itemType ) );
1159 NULL, NULL, cmdServerQuery, cmdCreateObject, cmdCreateObjectIndirect,
1160 cmdExportObject, cmdDestroyObject, cmdQueryCapability, cmdGenKey,
1161 cmdEncrypt, cmdDecrypt, cmdGetAttribute, cmdSetAttribute,
1162 cmdDeleteAttribute, cmdGetKey, cmdSetKey, cmdDeleteKey, cmdPushData,
1163 cmdPopData, cmdFlushData, cmdCertSign, cmdCertCheck, cmdCertMgmt };
1191 for( i = 0; i < cmd.
noArgs; i++ )
1200 bufPtr += COMMAND_WORDSIZE + cmd.
strArgLen[ i ];
1225 cmd.
strArg[ 0 ] = bufPtr;
1238 status = commandHandlers[ cmd.
type ]( NULL, &cmd );
1306 static void serverTransact(
void *clientBuffer )
1308 #ifdef CONFIG_CONSERVE_MEMORY
1309 static BYTE *serverBuffer = NULL;
1320 #ifdef CONFIG_CONSERVE_MEMORY
1321 if( serverBuffer == NULL && \
1322 ( serverBuffer =
clAlloc(
"serverTransact", \
1325 memset( clientBuffer, 0, 16 );
1334 memcpy( serverBuffer, clientBuffer, length + COMMAND_FIXED_DATA_SIZE );
1335 processCommand( serverBuffer );
1337 memcpy( clientBuffer, serverBuffer, length + COMMAND_FIXED_DATA_SIZE );
1347 BYTE *payloadStartPtr, *payloadPtr;
1351 const BOOLEAN isDataCommand = \
1356 cmd->strArgLen[ 0 ] + cmd->
strArgLen[ 1 ];
1367 if( !isDataCommand && \
1379 for( i = 0; i < sentCmd.
noStrArgs; i++ )
1381 if( sentCmd.
strArgLen[ i ] > maxLength )
1398 for( i = 0; i < sentCmd.
noArgs; i++ )
1403 for( i = 0; i < sentCmd.
noStrArgs; i++ )
1405 const int argLength = sentCmd.
strArgLen[ i ];
1415 serverTransact( buffer );
1416 memcpy( header, buffer, COMMAND_FIXED_DATA_SIZE );
1431 for( i = 0; i < cmd->
noArgs; i++ )
1440 bufPtr += COMMAND_WORDSIZE + cmd->
strArgLen[ i ];
1451 const int status = cmd->
arg[ 0 ];
1453 cmd->
arg[ 0 ] = cmd->
arg[ 1 ];
1458 return( cmd->
arg[ 0 ] );
1461 for( i = 1; i < cmd->
noArgs; i++ )
1462 cmd->
arg[ i - 1 ] = cmd->
arg[ i ];
1487 payloadPtr = sentCmd.
strArg[ 0 ];
1502 ( COMMAND_WORDSIZE * 2 ) );
1507 ( COMMAND_WORDSIZE * 2 ) + fragmentLength );
1514 memcpy( payloadStartPtr + COMMAND_WORDSIZE, payloadPtr,
1520 serverTransact( buffer );
1521 memcpy( header, buffer, COMMAND_FIXED_DATA_SIZE );
1563 getMessageWord( bufPtr + COMMAND_WORDSIZE );
1565 if( bytesCopied < 0 )
1584 if( resultLength <= 0 )
1586 if( resultLength == 0 )
1595 cmd->
arg[ 0 ] += resultLength;
1600 memcpy( payloadPtr, payloadStartPtr + COMMAND_WORDSIZE,
1605 if( resultLength < fragmentLength )
1606 dataLength = resultLength;
1616 if( resultLength != fragmentLength )
1621 memcpy( payloadPtr, payloadStartPtr + COMMAND_WORDSIZE,
1629 resultLength = fragmentLength;
1634 payloadPtr += resultLength;
1635 dataLength -= resultLength;
1637 while( dataLength > 0 );
1656 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
1681 if( attribute <= CRYPT_CERTINFO_LAST_NAME )
1683 if( attribute < CRYPT_CERTINFO_FIRST_NAME )
1705 if( attribute <= CRYPT_CERTINFO_LAST_EXTENSION )
1730 if( attribute <= CRYPT_CERTINFO_LAST_CMS )
1781 #define nativeStrlen( string ) strlen( string )
1782 #define nativeToCryptlibString( dest, destMaxLen, src, length ) \
1783 ebcdicToAscii( dest, src, length )
1784 #define cryptlibToNativeString( dest, destMaxLen, src, length ) \
1785 asciiToEbcdic( dest, src, length )
1787 #define nativeStrlen( string ) wcslen( string )
1788 #define nativeToCryptlibString( dest, destMaxLen, src, length ) \
1789 unicodeToAscii( dest, destMaxLen, src, length )
1790 #define cryptlibToNativeString( dest, destMaxLen, src, length ) \
1791 asciiToUnicode( dest, destMaxLen, src, length )
1807 #define strParamLen nativeStrlen
1809 #define strParamLen strlen
1829 static int mapError(
const ERRORMAP *errorMap,
const int errorMapSize,
1864 for( i = 0; errorMap[ i ] !=
ARG_LAST && \
1865 i < errorMapSize; i++ )
1867 if( errorMap[ i ] == type && !count-- )
1870 if( i >= errorMapSize )
1932 cryptAlgo >= CRYPT_ALGO_LAST_EXTERNAL ) && \
1948 *cryptContext = cmd.
arg[ 0 ];
1976 cryptAlgo >= CRYPT_ALGO_LAST_EXTERNAL ) && \
1986 cmd.
arg[ 0 ] = device;
1991 *cryptContext = cmd.
arg[ 0 ];
2019 certType >= CRYPT_CERTTYPE_LAST_EXTERNAL )
2034 *certificate = cmd.
arg[ 0 ];
2054 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
2057 const char *namePtr =
name;
2075 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
2079 name, nativeStrlen( name ) + 1 );
2082 namePtr = nameBuffer;
2087 if( namePtr != NULL )
2103 cmd.
strArg[ 0 ] = (
void * ) namePtr;
2108 *device = cmd.
arg[ 0 ];
2136 formatType >= CRYPT_FORMAT_LAST_EXTERNAL )
2151 *envelope = cmd.
arg[ 0 ];
2171 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
2174 const char *namePtr =
name;
2191 options >= CRYPT_KEYOPT_LAST_EXTERNAL )
2196 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
2198 name, nativeStrlen( name ) + 1 );
2218 cmd.
strArg[ 0 ] = (
void * ) namePtr;
2223 *keyset = cmd.
arg[ 0 ];
2262 cmd.
arg[ 2 ] = sessionType;
2266 *session = cmd.
arg[ 0 ];
2284 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
2304 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
2306 name, nativeStrlen( name ) + 1 );
2310 password, nativeStrlen( password ) + 1 );
2320 strlen( passwordPtr ) );
2321 if( passwordLen <= 0 )
2330 cmd.
strArg[ 0 ] = (
void * ) namePtr;
2332 cmd.
strArg[ 1 ] = (
void * ) passwordPtr;
2337 *user = cmd.
arg[ 0 ];
2439 *value = cmd.
arg[ 0 ];
2469 *( (
BYTE * ) value ) =
'\0';
2486 *valueLength = ( value == NULL ) ? cmd.
arg[ 0 ] : cmd.
strArgLen[ 0 ];
2487 #
if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
2488 if( value != NULL && *valueLength > 0 && \
2489 needsTranslation( attributeType ) )
2495 memcpy( buffer, value, *valueLength );
2497 buffer, *valueLength );
2498 #ifdef UNICODE_CHARS
2499 *valueLength *=
sizeof(
wchar_t );
2553 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
2583 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
2584 if( needsTranslation( attributeType ) )
2587 value, valueLength );
2590 value = valueBuffer;
2591 #ifdef UNICODE_CHARS
2597 #if defined( __WINDOWS__ ) && defined( __WIN32__ ) && !defined( __WIN64__ )
2623 length !=
sizeof( time_t ) )
2626 time_t time64, time32;
2630 if( length != 4 && length != 8 )
2639 time64 = *( (
unsigned int * ) value );
2640 timeValuePtr = &time64;
2646 const __int64 timeValue = *( ( __int64 * ) value );
2647 if( timeValue < MIN_TIME_VALUE || timeValue >= ULONG_MAX )
2649 time32 = *( ( time_t * ) value );
2650 timeValuePtr = &time32;
2655 cmd.
strArg[ 0 ] = (
void * ) timeValuePtr;
2671 cmd.
strArg[ 0 ] = (
void * ) value;
2766 if( length > 0 && !
isReadPtr( buffer, length ) )
2772 cmd.
strArg[ 0 ] = ( length == 0 ) ?
"" : buffer;
2917 if( !
isReadPtr( certObject, certObjectLength ) )
2933 cmd.
strArg[ 0 ] = (
void * ) certObject;
2938 *certificate = cmd.
arg[ 0 ];
2959 if( certObject != NULL )
2964 if( !
isWritePtr( certObject, certObjectMaxLength ) )
2972 certFormatType >= CRYPT_CERTFORMAT_LAST_EXTERNAL )
2979 if( certObject == NULL )
2985 cmd.
arg[ 1 ] = certFormatType;
2991 *certObjectLength = ( certObject == NULL ) ? \
2993 #
if defined( EBCDIC_CHARS )
2998 certObject != NULL )
3002 cryptlibToNativeString( certObject, certObjectMaxLength,
3003 certObject, *certObjectLength );
3053 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3056 const char *keyIDPtr =
keyID;
3059 int keyIDlen = 0,
status;
3082 keyIDtype >= CRYPT_KEYID_LAST_EXTERNAL )
3097 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3101 keyID, nativeStrlen( keyID ) + 1 );
3104 keyIDPtr = keyIDBuffer;
3109 if( keyIDPtr != NULL )
3137 cmd.
strArg[ 0 ] = (
void * ) keyIDPtr;
3142 *certificate = cmd.
arg[ 0 ];
3159 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3162 const char *keyIDPtr =
keyID;
3176 keyIDtype >= CRYPT_KEYID_LAST_EXTERNAL )
3183 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3185 keyID, nativeStrlen( keyID ) + 1 );
3210 cmd.
strArg[ 0 ] = (
void * ) keyIDPtr;
3233 if( certificate != NULL )
3239 if( action < CRYPT_CERTACTION_FIRST_USER || \
3240 action > CRYPT_CERTACTION_LAST_USER )
3257 if( certificate == NULL )
3260 cmd.
arg[ 1 ] = action;
3262 cmd.
arg[ 3 ] = certRequest;
3266 *certificate = cmd.
arg[ 0 ];
3298 if( bytesCopied == NULL )
3302 bytesCopied = &
dummy;
3308 cmd.
arg[ 0 ] = envelope;
3309 cmd.
strArg[ 0 ] = (
void * ) buffer;
3312 *bytesCopied = cmd.
arg[ 0 ];
3338 memset( buffer, 0,
min( length, 16 ) );
3345 cmd.
arg[ 0 ] = envelope;
3347 cmd.
strArg[ 0 ] = (
void * ) buffer;
3374 cmd.
arg[ 0 ] = envelope;
3400 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3403 const char *keyIDPtr =
keyID;
3405 int keyIDlen = 0,
status;
3416 keyIDtype >= CRYPT_KEYID_LAST_EXTERNAL )
3431 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3435 keyID, nativeStrlen( keyID ) + 1 );
3438 keyIDPtr = keyIDBuffer;
3443 if( keyIDPtr != NULL )
3455 cmd.
strArg[ 0 ] = (
void * ) keyIDPtr;
3460 *cryptKey = cmd.
arg[ 0 ];
3477 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3492 keyIDtype >= CRYPT_KEYID_LAST_EXTERNAL )
3498 if( password != NULL && \
3504 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3506 keyID, nativeStrlen( keyID ) + 1 );
3509 if( password != NULL )
3512 password, nativeStrlen( password ) + 1 );
3515 passwordPtr = passwordBuffer;
3523 if( passwordPtr != NULL )
3526 strlen( passwordPtr ) );
3527 if( passwordLen <= 0 )
3536 cmd.
strArg[ 0 ] = (
void * ) keyIDPtr;
3538 cmd.
strArg[ 1 ] = (
void * ) passwordPtr;
3541 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3546 *cryptContext = cmd.
arg[ 0 ];
3563 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3578 keyIDtype >= CRYPT_KEYID_LAST_EXTERNAL )
3584 if( password != NULL && \
3590 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3592 keyID, nativeStrlen( keyID ) + 1 );
3595 if( password != NULL )
3598 password, nativeStrlen( password ) + 1 );
3601 passwordPtr = passwordBuffer;
3609 if( passwordPtr != NULL )
3612 strlen( passwordPtr ) );
3613 if( passwordLen <= 0 )
3622 cmd.
strArg[ 0 ] = (
void * ) keyIDPtr;
3624 cmd.
strArg[ 1 ] = (
void * ) passwordPtr;
3627 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3632 *cryptContext = cmd.
arg[ 0 ];
3677 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3680 const char *passwordPtr =
password;
3689 if( password != NULL && \
3696 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3697 if( password != NULL )
3700 password, nativeStrlen( password ) + 1 );
3703 passwordPtr = passwordBuffer;
3708 if( passwordPtr != NULL )
3711 strlen( passwordPtr ) );
3712 if( passwordLen <= 0 )
3720 cmd.
strArg[ 0 ] = (
void * ) passwordPtr;
3723 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3743 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3746 const char *keyIDPtr =
keyID;
3754 keyIDtype >= CRYPT_KEYID_LAST_EXTERNAL )
3761 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3763 keyID, nativeStrlen( keyID ) + 1 );
3777 cmd.
strArg[ 0 ] = (
void * ) keyIDPtr;
3813 cryptAlgo >= CRYPT_ALGO_LAST_EXTERNAL )
3815 if( cryptQueryInfo != NULL )
3829 if( cryptQueryInfo == NULL )
3835 cmd.
strArg[ 0 ] = cryptQueryInfo;
3840 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3841 if( cryptQueryInfo != NULL )
3844 const int algoNameLength = \
3845 strlen( (
char * ) cryptQueryInfo->algoName ) + 1;
3847 memcpy( buffer, cryptQueryInfo->algoName, algoNameLength );
3848 cryptlibToNativeString( cryptQueryInfo->algoName,
3874 cryptAlgo >= CRYPT_ALGO_LAST_EXTERNAL )
3876 if( cryptQueryInfo != NULL )
3885 if( cryptQueryInfo == NULL )
3890 cmd.
arg[ 0 ] = device;
3892 cmd.
strArg[ 0 ] = cryptQueryInfo;
3897 #if defined( EBCDIC_CHARS ) || defined( UNICODE_CHARS )
3898 if( cryptQueryInfo != NULL )
3901 const int algoNameLength = \
3902 strlen( (
char * ) cryptQueryInfo->algoName ) + 1;
3904 memcpy( buffer, cryptQueryInfo->algoName, algoNameLength );
3905 cryptlibToNativeString( cryptQueryInfo->algoName,
3923 if( randomData == NULL )
3931 if( randomDataLength <= 0 || randomDataLength >=
MAX_INTLENGTH )
3933 if( !
isReadPtr( randomData, randomDataLength ) )
3945 if( randomData != NULL )
3949 #if defined( __WINDOWS__ ) && !defined( NDEBUG )
3950 if( randomDataLength == 5 && !memcmp( randomData,
"xyzzy", 5 ) )
3952 BYTE buffer[ 256 + 8 ];
3954 memset( buffer,
'*', 256 );
3957 &msgData, CRYPT_IATTRIBUTE_ENTROPY );
3959 &kludge, CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
3967 CRYPT_IATTRIBUTE_ENTROPY ) );
3974 CRYPT_IATTRIBUTE_RANDOM_POLL ) );
3981 #ifndef USE_CERTIFICATES
4018 #if !defined( NDEBUG ) && 0
4020 #include "docs/cryptapi_ext.c"
4024 #ifdef CONFIG_SUITEB_TESTS
4030 int sslSuiteBTestConfig(
const int magicValue );
4032 C_RET cryptSuiteBTestConfig(
C_IN int magicValue )
4034 return( sslSuiteBTestConfig( magicValue ) );