📄 testlib.c
字号:
if( cryptStatusOK( cryptQueryCapability( cryptAlgo, NULL ) ) && \
!testLowlevel( CRYPT_UNUSED, cryptAlgo, FALSE ) )
goto errorExit;
/* Test the public-key encryption routines */
for( cryptAlgo = CRYPT_ALGO_FIRST_PKC;
cryptAlgo <= CRYPT_ALGO_LAST_PKC; cryptAlgo++ )
if( cryptStatusOK( cryptQueryCapability( cryptAlgo, NULL ) ) && \
!testLowlevel( CRYPT_UNUSED, cryptAlgo, FALSE ) )
goto errorExit;
/* Test the hash routines */
for( cryptAlgo = CRYPT_ALGO_FIRST_HASH;
cryptAlgo <= CRYPT_ALGO_LAST_HASH; cryptAlgo++ )
if( cryptStatusOK( cryptQueryCapability( cryptAlgo, NULL ) ) && \
!testLowlevel( CRYPT_UNUSED, cryptAlgo, FALSE ) )
goto errorExit;
/* Test the MAC routines */
for( cryptAlgo = CRYPT_ALGO_FIRST_MAC;
cryptAlgo <= CRYPT_ALGO_LAST_MAC; cryptAlgo++ )
if( cryptStatusOK( cryptQueryCapability( cryptAlgo, NULL ) ) && \
!testLowlevel( CRYPT_UNUSED, cryptAlgo, FALSE ) )
goto errorExit;
putchar( '\n' );
#else
puts( "Skipping test of low-level encryption routines...\n" );
#endif /* TEST_LOWLEVEL */
/* Test the randomness-gathering routines */
#ifdef TEST_RANDOM
if( !testRandomRoutines() )
{
puts( "The self-test will proceed without using a strong random "
"number source.\n" );
/* Kludge the randomness routines so we can continue the self-tests */
cryptAddRandom( "a", 1 );
}
#else
puts( "Skipping test of randomness routines...\n" );
#endif /* TEST_RANDOM */
/* Test the configuration options routines */
#ifdef TEST_CONFIG
for( i = 0; configOption[ i ].option != CRYPT_ATTRIBUTE_NONE; i++ )
{
if( configOption[ i ].isNumeric )
{
int value;
cryptGetAttribute( CRYPT_UNUSED, configOption[ i ].option, &value );
printf( "%s = %d.\n", configOption[ i ].name, value );
}
else
{
char buffer[ 256 ];
int length;
cryptGetAttributeString( CRYPT_UNUSED, configOption[ i ].option,
buffer, &length );
buffer[ length ] = '\0';
printf( "%s = %s.\n", configOption[ i ].name, buffer );
}
}
putchar( '\n' );
#else
puts( "Skipping display of config options...\n" );
#endif /* TEST_CONFIG */
/* Test the crypto device routines */
#ifdef TEST_DEVICE
status = testDevices();
if( status == CRYPT_ERROR_NOTAVAIL )
puts( "Handling for crypto devices doesn't appear to be enabled in "
"this build of\ncryptlib.\n" );
else
if( !status )
goto errorExit;
#else
puts( "Skipping test of crypto device routines...\n" );
#endif /* TEST_DEVICE */
/* Test the mid-level routines. This is implemented as a series of
separate function calls rather than a monolithic
if( a || b || c || ... ) block to make testing easier */
#ifdef TEST_MIDLEVEL
if( !testLargeBufferEncrypt() )
goto errorExit;
if( !testDeriveKey() )
goto errorExit;
if( !testConventionalExportImport() )
goto errorExit;
if( !testMACExportImport() )
goto errorExit;
if( !testKeyExportImport() )
goto errorExit;
if( !testSignData() )
goto errorExit;
/* Disabled for now since there's no useful DH mechanism defined in any
standard. Note that KEA is still tested via the Fortezza device test
if( !testKeyAgreement() )
goto errorExit; */
if( !testKeygen() )
goto errorExit;
if( !testKeygenAsync() )
goto errorExit;
/* No need for putchar, mid-level functions leave a blank line at end */
#else
puts( "Skipping test of mid-level encryption routines...\n" );
#endif /* TEST_MIDLEVEL */
/* Test the certificate management routines */
#ifdef TEST_CERT
if( !testCert() )
goto errorExit;
if( !testCACert() )
goto errorExit;
if( !testXyzzyCert() )
goto errorExit;
if( !testComplexCert() )
goto errorExit;
if( !testCertExtension() )
goto errorExit;
if( !testCustomDNCert() )
goto errorExit;
if( !testSETCert() )
goto errorExit;
if( !testAttributeCert() )
goto errorExit;
if( !testCertRequest() )
goto errorExit;
if( !testComplexCertRequest() )
goto errorExit;
if( !testCRMFRequest() )
goto errorExit;
if( !testComplexCRMFRequest() )
goto errorExit;
if( !testCRL() )
goto errorExit;
if( !testComplexCRL() )
goto errorExit;
if( !testRevRequest() )
goto errorExit;
if( !testCertChain() )
goto errorExit;
if( !testCMSAttributes() )
goto errorExit;
if( !testOCSPReqResp() )
goto errorExit;
if( !testCertImport() )
goto errorExit;
if( !testCertReqImport() )
goto errorExit;
if( !testCRLImport() )
goto errorExit;
if( !testCertChainImport() )
goto errorExit;
if( !testOCSPImport() )
goto errorExit;
#else
puts( "Skipping test of certificate managment routines...\n" );
#endif /* TEST_CERT */
/* Test the keyset read routines */
#ifdef TEST_KEYSET
if( !testGetPGPPublicKey() )
goto errorExit;
if( !testGetPGPPrivateKey() )
goto errorExit;
if( !testGetOpenPGPPublicKey() )
goto errorExit;
if( !testGetOpenPGPPrivateKey() )
goto errorExit;
if( !testGetBorkenKey() )
goto errorExit;
if( !testReadWriteFileKey() )
goto errorExit;
if( !testReadFilePublicKey() )
goto errorExit;
if( !testDeleteFileKey() )
goto errorExit;
if( !testUpdateFileCert() )
goto errorExit;
if( !testReadFileCert() )
goto errorExit;
if( !testWriteFileCertChain() )
goto errorExit;
if( !testReadFileCertChain() )
goto errorExit;
if( !testSingleStepFileCert() )
goto errorExit;
if( !testDoubleCertFile() )
goto errorExit;
if( !testRenewedCertFile() )
goto errorExit;
status = testWriteCert();
if( status == CRYPT_ERROR_NOTAVAIL )
puts( "Handling for certificate databases doesn't appear to be "
"enabled in this\nbuild of cryptlib, skipping the test of "
"the certificate database routines.\n" );
else
if( status )
{
if( !testReadCert() )
goto errorExit;
if( !testKeysetQuery() )
goto errorExit;
/* The database plugin test will usually fail unless the user has
set up a plugin, so we don't check the return value */
testWriteCertDbx();
}
/* For the following tests we may have read access but not write access,
so we test a read of known-present certs before trying a write -
unlike the local keysets we don't need to add a cert before we can try
reading it */
status = testReadCertLDAP();
if( status == CRYPT_ERROR_NOTAVAIL )
puts( "Handling for LDAP certificate directories doesn't appear to "
"be enabled in\nthis build of cryptlib, skipping the test of "
"the certificate directory\nroutines.\n" );
else
/* LDAP access can fail if the directory doesn't use the standard
du jour, so we don't treat a failure as a fatal error */
if( status )
{
/* LDAP writes are even worse than LDAP reads, so we don't
treat failures here as fatal either */
testWriteCertLDAP();
}
status = testReadCertURL();
if( status == CRYPT_ERROR_NOTAVAIL )
puts( "Handling for fetching certificates from web pages doesn't "
"appear to be\nenabled in this build of cryptlib, skipping "
"the test of the HTTP routines.\n" );
#else
puts( "Skipping test of keyset read routines...\n" );
#endif /* TEST_KEYSET */
/* Test the certificate processing and CA cert management functionality */
#ifdef TEST_CERTPROCESS
if( !testCertProcess() )
goto errorExit;
status = testCertManagement();
if( status == CRYPT_ERROR_NOTAVAIL )
puts( "Handling for CA certificate stores doesn't appear to be "
"enabled in this\nbuild of cryptlib, skipping the test of "
"the certificate management routines.\n" );
else
if( !status )
goto errorExit;
#else
puts( "Skipping test of certificate handling/CA management...\n" );
#endif /* TEST_CERTPROCESS */
/* Test the high-level routines (these are similar to the mid-level
routines but rely on things like certificate management to work) */
#ifdef TEST_HIGHLEVEL
if( !testKeyExportImportCMS() )
goto errorExit;
if( !testSignDataCMS() )
goto errorExit;
#endif /* TEST_HIGHLEVEL */
/* Test the enveloping routines */
#ifdef TEST_ENVELOPE
if( !testEnvelopeData() )
goto errorExit;
if( !testLargeBufferEnvelopeData() )
goto errorExit;
if( !testEnvelopeCompress() )
goto errorExit;
if( !testEnvelopeCompressedDataImport() )
goto errorExit;
if( !testEnvelopeSessionCrypt() )
goto errorExit;
if( !testEnvelopeCrypt() )
goto errorExit;
if( !testEnvelopeCryptImport() )
goto errorExit;
if( !testEnvelopePKCCrypt() )
goto errorExit;
if( !testEnvelopePKCCryptImport() )
goto errorExit;
if( !testEnvelopeSign() )
goto errorExit;
if( !testEnvelopeSignedDataImport() )
goto errorExit;
if( !testEnvelopeAuthenticate() )
goto errorExit;
if( !testCMSEnvelopePKCCrypt() )
goto errorExit;
if( !testCMSEnvelopePKCCryptDoubleCert() )
goto errorExit;
if( !testCMSEnvelopeSign() )
goto errorExit;
if( !testCMSEnvelopeDetachedSig() )
goto errorExit;
if( !testCMSEnvelopeSignedDataImport() )
goto errorExit;
#else
puts( "Skipping test of enveloping routines...\n" );
#endif /* TEST_ENVELOPE */
/* Test the session routines */
#ifdef TEST_SESSION
status = testSessionSSHv1();
if( status == CRYPT_ERROR_NOTAVAIL )
puts( "Network access doesn't appear to be enabled in this build of "
"cryptlib,\nskipping the test of the secure session routines.\n" );
else
{
if( !status )
goto errorExit;
if( !testSessionSSHv2() )
goto errorExit;
if( !testSessionSSL() )
goto errorExit;
if( !testSessionTLS() )
goto errorExit;
if( !testSessionOCSP() )
goto errorExit;
if( !testSessionTSP() )
goto errorExit;
if( !testSessionEnvTSP() )
goto errorExit;
if( !testSessionCMP() )
goto errorExit;
/* Test local client/server sessions. These require a threaded OS
and are aliased to nops on non-threaded systems */
if( !testSessionSSHClientServer() )
goto errorExit;
if( !testSessionSSLClientServer() )
goto errorExit;
if( !testSessionSSLClientCertClientServer() )
goto errorExit;
if( !testSessionTLSClientServer() )
goto errorExit;
if( !testSessionOCSPClientServer() )
goto errorExit;
if( !testSessionTSPClientServer() )
goto errorExit;
if( !testSessionCMPClientServer() )
goto errorExit;
}
#endif /* TEST_SESSION */
/* Test the user routines */
#ifdef TEST_USER
if( !testUser() )
goto errorExit;
#endif /* TEST_USER */
/* Shut down cryptlib */
status = cryptEnd();
if( cryptStatusError( status ) )
{
if( status == CRYPT_ERROR_INCOMPLETE )
puts( "cryptEnd() failed with error code CRYPT_ERROR_INCOMPLETE, "
"a code path in the\nself-test code resulted in an error "
"return without a full cleanup of objects." );
else
printf( "cryptEnd() failed with error code %d.\n", status );
goto errorExit1;
}
puts( "All tests concluded successfully." );
return( EXIT_SUCCESS );
/* All errors end up here */
#if defined( TEST_LOWLEVEL ) || defined( TEST_MIDLEVEL ) || \
defined( TEST_DEVICE ) || defined( TEST_CERT ) || \
defined( TEST_KEYSET ) || defined( TEST_CERTPROCESS ) || \
defined( TEST_CERTMANAGEMENT ) || defined( TEST_HIGHLEVEL ) || \
defined( TEST_ENVELOPE ) || defined( TEST_SESSION ) || \
defined( TEST_SESSION ) || defined( TEST_USER )
errorExit:
cryptEnd();
#endif /* Eliminate compiler warning about unreferenced label */
errorExit1:
puts( "\nTh
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -