📄 ssl.c
字号:
strcpy( fetchString, "a004 LOGIN test\r\n" );
fetchStringLen = strlen( fetchString );
#if defined( __MVS__ ) || defined( __VMCMS__ )
ebcdicToAscii( fetchString, fetchStringLen );
#endif /* EBCDIC systems */
status = cryptPushData( cryptSession, fetchString,
fetchStringLen, &bytesCopied );
if( cryptStatusOK( status ) )
status = cryptFlushData( cryptSession );
if( cryptStatusError( status ) || bytesCopied != fetchStringLen )
{
printExtError( cryptSession, "Attempt to send data to "
"server", status, __LINE__ );
cryptDestroySession( cryptSession );
return( FALSE );
}
status = cryptPopData( cryptSession, buffer, FILEBUFFER_SIZE,
&bytesCopied );
if( cryptStatusError( status ) )
{
printExtError( cryptSession, "Attempt to read data from "
"server", status, __LINE__ );
cryptDestroySession( cryptSession );
return( FALSE );
}
buffer[ bytesCopied ] = '\0';
#if defined( __MVS__ ) || defined( __VMCMS__ )
asciiToEbcdic( buffer, bytesCopied );
#endif /* EBCDIC systems */
if( testType != SSL_TEST_MULTITHREAD )
{
printf( "---- Server sent %d bytes ----\n", bytesCopied );
puts( buffer );
puts( "---- End of output ----" );
}
}
}
/* Clean up */
status = cryptDestroySession( cryptSession );
if( cryptStatusError( status ) )
{
printf( "cryptDestroySession() failed with error code %d, line %d.\n",
status, __LINE__ );
return( FALSE );
}
#if defined( __WINDOWS__ ) && !defined( _WIN32_WCE )
if( testType == SSL_TEST_STARTTLS )
{
closesocket( netSocket );
WSACleanup();
}
#endif /* __WINDOWS__ && !_WIN32_WCE */
if( sessionID != CRYPT_UNUSED )
printf( "%02d: ", sessionID );
printf( "%s%s session succeeded.\n", isServer ? "SVR: " : "",
versionStr[ version ] );
if( testType != SSL_TEST_MULTITHREAD )
putchar( '\n' );
return( TRUE );
}
int testSessionSSL( void )
{
return( connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_NORMAL, 0, CRYPT_UNUSED, FALSE ) );
}
int testSessionSSLLocalSocket( void )
{
return( connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_STARTTLS, 0, CRYPT_UNUSED, FALSE ) );
}
int testSessionSSLClientCert( void )
{
return( connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_CLIENTCERT, 0, CRYPT_UNUSED, FALSE ) );
}
int testSessionSSLSharedKey( void )
{
return( connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_PSK, 0, CRYPT_UNUSED, FALSE ) );
}
int testSessionSSLServer( void )
{
return( connectSSLTLS( CRYPT_SESSION_SSL_SERVER, SSL_TEST_NORMAL, 0, CRYPT_UNUSED, FALSE ) );
}
int testSessionSSLServerCached( void )
{
int status;
/* Run the server twice to check session cacheing. Testing this requires
manual reconnection with a browser to localhost, since it's too
complex to handle easily via a loopback test. Note that with MSIE
this will require three lots of connects rather than two, because it
handles an unknown cert by doing a resume, which consumes two lots of
sessions, and then the third one is the actual session resume */
status = connectSSLTLS( CRYPT_SESSION_SSL_SERVER, SSL_TEST_NORMAL, 0, CRYPT_UNUSED, FALSE );
if( status <= 0 )
return( status );
return( connectSSLTLS( CRYPT_SESSION_SSL_SERVER, SSL_TEST_NORMAL, 0, CRYPT_UNUSED, FALSE ) );
}
int testSessionSSLServerClientCert( void )
{
return( connectSSLTLS( CRYPT_SESSION_SSL_SERVER, SSL_TEST_CLIENTCERT, 0, CRYPT_UNUSED, FALSE ) );
}
int testSessionTLS( void )
{
return( connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_NORMAL, 1, CRYPT_UNUSED, FALSE ) );
}
int testSessionTLSServer( void )
{
return( connectSSLTLS( CRYPT_SESSION_SSL_SERVER, SSL_TEST_NORMAL, 1, CRYPT_UNUSED, FALSE ) );
}
int testSessionTLSServerSharedKey( void )
{
return( connectSSLTLS( CRYPT_SESSION_SSL_SERVER, SSL_TEST_PSK, 1, CRYPT_UNUSED, FALSE ) );
}
int testSessionTLS11( void )
{
return( connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_NORMAL, 2, CRYPT_UNUSED, FALSE ) );
}
int testSessionTLS12( void )
{
return( connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_NORMAL, 3, CRYPT_UNUSED, FALSE ) );
}
/* Perform a client/server loopback test */
#ifdef WINDOWS_THREADS
unsigned __stdcall sslServerThread( void *dummy )
{
connectSSLTLS( CRYPT_SESSION_SSL_SERVER, SSL_TEST_NORMAL, 0, CRYPT_UNUSED, TRUE );
_endthreadex( 0 );
return( 0 );
}
int testSessionSSLClientServer( void )
{
HANDLE hThread;
unsigned threadID;
int status;
/* Start the server */
createMutex();
hThread = ( HANDLE ) _beginthreadex( NULL, 0, sslServerThread,
NULL, 0, &threadID );
Sleep( 1000 );
/* Connect to the local server */
status = connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_NORMAL, 0, CRYPT_UNUSED, TRUE );
waitForThread( hThread );
destroyMutex();
return( status );
}
unsigned __stdcall sslClientCertServerThread( void *dummy )
{
connectSSLTLS( CRYPT_SESSION_SSL_SERVER, SSL_TEST_CLIENTCERT, 0, CRYPT_UNUSED, TRUE );
_endthreadex( 0 );
return( 0 );
}
int testSessionSSLClientCertClientServer( void )
{
HANDLE hThread;
unsigned threadID;
int status;
/* Start the server */
createMutex();
hThread = ( HANDLE ) _beginthreadex( NULL, 0, sslClientCertServerThread,
NULL, 0, &threadID );
Sleep( 1000 );
/* Connect to the local server */
status = connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_CLIENTCERT, 0, CRYPT_UNUSED, TRUE );
waitForThread( hThread );
destroyMutex();
return( status );
}
unsigned __stdcall tlsServerThread( void *dummy )
{
connectSSLTLS( CRYPT_SESSION_SSL_SERVER, SSL_TEST_NORMAL, 1, CRYPT_UNUSED, TRUE );
_endthreadex( 0 );
return( 0 );
}
int testSessionTLSClientServer( void )
{
HANDLE hThread;
unsigned threadID;
int status;
/* Start the server */
createMutex();
hThread = ( HANDLE ) _beginthreadex( NULL, 0, tlsServerThread,
NULL, 0, &threadID );
Sleep( 1000 );
/* Connect to the local server */
status = connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_NORMAL, 1, CRYPT_UNUSED, TRUE );
waitForThread( hThread );
destroyMutex();
return( status );
}
unsigned __stdcall tlsSharedKeyServerThread( void *dummy )
{
connectSSLTLS( CRYPT_SESSION_SSL_SERVER, SSL_TEST_PSK, 1, CRYPT_UNUSED, TRUE );
_endthreadex( 0 );
return( 0 );
}
int testSessionTLSSharedKeyClientServer( void )
{
HANDLE hThread;
unsigned threadID;
int status;
/* Start the server */
createMutex();
hThread = ( HANDLE ) _beginthreadex( NULL, 0, tlsSharedKeyServerThread,
NULL, 0, &threadID );
Sleep( 1000 );
/* Connect to the local server */
status = connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_PSK, 1, CRYPT_UNUSED, TRUE );
waitForThread( hThread );
destroyMutex();
return( status );
}
unsigned __stdcall tlsNoSharedKeyServerThread( void *arg )
{
int testType = *( ( int * ) arg );
connectSSLTLS( CRYPT_SESSION_SSL_SERVER, testType, 1, CRYPT_UNUSED, TRUE );
_endthreadex( 0 );
return( 0 );
}
int testSessionTLSNoSharedKeyClientServer( void )
{
HANDLE hThread;
unsigned threadID;
int arg, status;
/* Start the server */
createMutex();
arg = SSL_TEST_PSK_CLIONLY;
hThread = ( HANDLE ) _beginthreadex( NULL, 0, tlsNoSharedKeyServerThread,
&arg, 0, &threadID );
Sleep( 1000 );
/* Connect to the local server */
status = connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_PSK_CLIONLY, 1, CRYPT_UNUSED, TRUE );
waitForThread( hThread );
destroyMutex();
if( status != TRUE )
return( status );
/* Restart the server */
createMutex();
arg = SSL_TEST_PSK_SVRONLY;
hThread = ( HANDLE ) _beginthreadex( NULL, 0, tlsNoSharedKeyServerThread,
&arg, 0, &threadID );
Sleep( 1000 );
/* Connect to the local server */
status = connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_PSK_SVRONLY, 1, CRYPT_UNUSED, TRUE );
waitForThread( hThread );
destroyMutex();
return( status );
}
unsigned __stdcall tlsBulkTransferServerThread( void *dummy )
{
connectSSLTLS( CRYPT_SESSION_SSL_SERVER, SSL_TEST_BULKTRANSER, 1, CRYPT_UNUSED, TRUE );
_endthreadex( 0 );
return( 0 );
}
int testSessionTLSBulkTransferClientServer( void )
{
HANDLE hThread;
unsigned threadID;
int status;
/* Start the server */
createMutex();
hThread = ( HANDLE ) _beginthreadex( NULL, 0, tlsBulkTransferServerThread,
NULL, 0, &threadID );
Sleep( 1000 );
/* Connect to the local server */
status = connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_BULKTRANSER, 1, CRYPT_UNUSED, TRUE );
waitForThread( hThread );
destroyMutex();
return( status );
}
unsigned __stdcall tls11ServerThread( void *dummy )
{
connectSSLTLS( CRYPT_SESSION_SSL_SERVER, SSL_TEST_NORMAL, 2, CRYPT_UNUSED, TRUE );
_endthreadex( 0 );
return( 0 );
}
int testSessionTLS11ClientServer( void )
{
HANDLE hThread;
unsigned threadID;
int status;
/* Start the server */
createMutex();
hThread = ( HANDLE ) _beginthreadex( NULL, 0, tls11ServerThread,
NULL, 0, &threadID );
Sleep( 1000 );
/* Connect to the local server */
status = connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_NORMAL, 2, CRYPT_UNUSED, TRUE );
waitForThread( hThread );
destroyMutex();
return( status );
}
unsigned __stdcall tlsServerDualThread2( void *dummy )
{
connectSSLTLS( CRYPT_SESSION_SSL_SERVER, SSL_TEST_DUALTHREAD, 1, 0, TRUE );
_endthreadex( 0 );
return( 0 );
}
unsigned __stdcall tlsServerDualThread1( void *dummy )
{
connectSSLTLS( CRYPT_SESSION_SSL_SERVER, SSL_TEST_DUALTHREAD, 1, CRYPT_UNUSED, TRUE );
_endthreadex( 0 );
return( 0 );
}
int testSessionTLSClientServerDualThread( void )
{
HANDLE hThread;
unsigned threadID;
int status;
/* Start the server */
createMutex();
hThread = ( HANDLE ) _beginthreadex( NULL, 0, tlsServerDualThread1,
NULL, 0, &threadID );
Sleep( 1000 );
/* Connect to the local server */
status = connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_PSK, 1, CRYPT_UNUSED, TRUE );
waitForThread( hThread );
destroyMutex();
return( status );
}
unsigned __stdcall tlsServerMultiThread( void *threadIdPtr )
{
int threadID = *( ( int * ) threadIdPtr );
connectSSLTLS( CRYPT_SESSION_SSL_SERVER, SSL_TEST_MULTITHREAD, 1, threadID, TRUE );
_endthreadex( 0 );
return( 0 );
}
unsigned __stdcall tlsClientMultiThread( void *threadIdPtr )
{
int threadID = *( ( int * ) threadIdPtr );
connectSSLTLS( CRYPT_SESSION_SSL, SSL_TEST_MULTITHREAD, 1, threadID, TRUE );
_endthreadex( 0 );
return( 0 );
}
int testSessionTLSClientServerMultiThread( void )
{
return( multiThreadDispatch( tlsClientMultiThread,
tlsServerMultiThread, MAX_NO_THREADS ) );
}
#endif /* WINDOWS_THREADS */
#endif /* TEST_SESSION || TEST_SESSION_LOOPBACK */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -