📄 test.h
字号:
#if defined( TEST_SESSION_LOOPBACK ) && !defined( WINDOWS_THREADS )
#undef TEST_SESSION_LOOPBACK
#endif /* OSes with threading support */
/* Define various portable data types and functions needed for the threaded
loopback tests */
#if defined( WINDOWS_THREADS )
#define THREAD_HANDLE HANDLE
#define THREAD_EXIT() _endthreadex( 0 ); return( 0 )
#define THREAD_SELF() GetCurrentThreadId()
typedef unsigned ( __stdcall *THREAD_FUNC )( void *arg );
#elif defined( UNIX_THREADS )
#define THREAD_HANDLE pthread_t
#define THREAD_EXIT() pthread_exit( ( void * ) 0 ); return( 0 )
#define THREAD_SELF() pthread_self()
typedef void * ( *THREAD_FUNC )( void *arg );
#else
#define THREAD_HANDLE int
#define THREAD_EXIT()
#define THREAD_SELF() 0
typedef void ( *THREAD_FUNC )( void *arg );
#endif /* OS-specific threading functions */
/* The maximum number of threads that we can fire up in the multithreaded
tests */
#define MAX_NO_THREADS 10
/* Try and detect OSes that have widechar support */
#if ( defined( __WINDOWS__ ) && \
!( defined( __WIN16__ ) || defined( __BORLANDC__ ) ) ) || \
defined( __linux__ ) || \
( defined( sun ) && ( OSVERSION > 4 ) ) || defined( __osf__ )
#define HAS_WIDECHAR
#endif /* OSes with widechar support */
/* If we're running on an EBCDIC system, ensure that we're compiled in
EBCDIC mode to test the conversion of character strings */
#if defined( __MVS__ ) || defined( __VMCMS__ )
#pragma convlit( suspend )
#endif /* IBM big iron */
#if defined( __ILEC400__ )
#pragma convert( 0 )
#endif /* IBM medium iron */
/* If we're compiling under QNX, make enums a fixed size rather than using
the variable-length values that the Watcom compiler defaults to */
#if defined( __QNX__ ) && defined( __WATCOMC__ )
#pragma enum int
#endif /* QNX and Watcom C */
/* The key size to use for the PKC routines. This is the minimum allowed by
cryptlib, it speeds up the various tests but shouldn't be used in
practice */
#define PKC_KEYSIZE 512
/* Since the handling of filenames can get unwieldy when we have large
numbers of similar files, we use a function to map a filename template
and number into an actual filename rather the having to use huge
numbers of defines */
#ifdef UNICODE_STRINGS
void filenameFromTemplate( char *buffer, const wchar_t *fileTemplate,
const int count );
void filenameParamFromTemplate( wchar_t *buffer,
const wchar_t *fileTemplate,
const int count );
const char *convertFileName( const C_STR fileName );
#else
#define filenameFromTemplate( buffer, fileTemplate, count ) \
sprintf( buffer, fileTemplate, count )
#define filenameParamFromTemplate( buffer, fileTemplate, count ) \
sprintf( buffer, fileTemplate, count )
#define convertFileName( fileName ) fileName
#endif /* Unicode vs. ASCII */
/* A structure that allows us to specify a collection of extension
components. This is used when adding a collection of extensions to a
cert */
typedef enum { IS_VOID, IS_NUMERIC, IS_STRING, IS_WCSTRING,
IS_TIME } COMPONENT_TYPE;
typedef struct {
const CRYPT_ATTRIBUTE_TYPE type;/* Extension component ID */
const COMPONENT_TYPE componentType; /* Component type */
const int numericValue; /* Value if numeric */
const void *stringValue; /* Value if string */
const time_t timeValue; /* Value if time */
} CERT_DATA;
/****************************************************************************
* *
* Naming *
* *
****************************************************************************/
/* Pull in the OS-specific file names for the test data */
#ifdef _MSC_VER
#include "filename.h"
#else
#include "test/filename.h"
#endif /* Braindamaged MSC include handling */
/* When we're using common code to handle a variety of key file types for
key read/encryption/signing tests, we need to distinguish between the
different key files to use. The following types are handled in the test
code */
typedef enum { KEYFILE_NONE, KEYFILE_X509, KEYFILE_PGP, KEYFILE_OPENPGP,
KEYFILE_OPENPGP_HASH, KEYFILE_OPENPGP_AES,
KEYFILE_OPENPGP_RSA, KEYFILE_NAIPGP,
KEYFILE_OPENPGP_PARTIAL } KEYFILE_TYPE;
/* The generic password for private keys */
#define TEST_PRIVKEY_PASSWORD TEXT( "test" )
/* The database keyset type and name. Under Windoze we use ODBC, for
anything else we use the first database which is enabled by a preprocessor
define, defaulting to an internal plugin (which doesn't have to be
available, if it's not present we continue after printing a warning) */
#if defined( _MSC_VER )
#define DATABASE_KEYSET_TYPE CRYPT_KEYSET_ODBC
#define CERTSTORE_KEYSET_TYPE CRYPT_KEYSET_ODBC_STORE
#elif defined( DBX_DATABASE )
#define DATABASE_KEYSET_TYPE CRYPT_KEYSET_DATABASE
#define CERTSTORE_KEYSET_TYPE CRYPT_KEYSET_DATABASE_STORE
#elif defined( DBX_PLUGIN )
#define DATABASE_KEYSET_TYPE CRYPT_KEYSET_PLUGIN
#define CERTSTORE_KEYSET_TYPE CRYPT_KEYSET_PLUGIN_STORE
#else
#define DATABASE_KEYSET_TYPE CRYPT_KEYSET_DATABASE
#define CERTSTORE_KEYSET_TYPE CRYPT_KEYSET_DATABASE_STORE
#endif /* Various database backends */
#define DATABASE_KEYSET_NAME TEXT( "testkeys" )
#define DATABASE_KEYSET_NAME_ASCII "testkeys"
#define CERTSTORE_KEYSET_NAME TEXT( "testcertstore" )
#define CERTSTORE_KEYSET_NAME_ASCII "testcertstore"
#define DATABASE_PLUGIN_KEYSET_NAME TEXT( "localhost:6500" )
#define DATABASE_PLUGIN_KEYSET_NAME_ASCII "localhost:6500"
/* The HTTP keyset names (actually URLs for pages containing a cert and
CRL). We can't get either Verisign or Thawte root certs because both
require you to provide all sorts of personal information and click on a
legal agreement before you can download them (!!!), so we use the CAcert
root instead */
#define HTTP_KEYSET_CERT_NAME TEXT( "www.cacert.org/certs/root.der" )
#define HTTP_KEYSET_CRL_NAME TEXT( "crl.verisign.com/Class1Individual.crl" )
#define HTTP_KEYSET_HUGECRL_NAME TEXT( "crl.verisign.com/RSASecureServer.crl" )
/* Assorted default server names and authentication information, and the PKI
SRV server (redirecting to mail.cryptoapps.com:8080). There are so many
TSP, OCSP, and CMP servers, and they never stay around for long, that we
allow remapping in the functions where the secure session tests are
performed */
#define SSH_USER_NAME TEXT( "test" )
#define SSH_PASSWORD TEXT( "test" )
#define SSL_USER_NAME TEXT( "test" )
#define SSL_PASSWORD TEXT( "test" )
#define PKI_SRV_NAME TEXT( "_pkiboot._tcp.cryptoapps.com" )
#define TSP_DEFAULTSERVER_NAME TEXT( "http://www.edelweb.fr/cgi-bin/service-tsp" )
/* Labels for the various public-key objects. These are needed when the
underlying implementation creates persistent objects (eg keys held in PKCS
#11 tokens) that need to be identified */
#define RSA_PUBKEY_LABEL TEXT( "Test RSA public key" )
#define RSA_PRIVKEY_LABEL TEXT( "Test RSA private key" )
#define RSA_BIG_PRIVKEY_LABEL TEXT( "Test RSA big private key" )
#define DSA_PUBKEY_LABEL TEXT( "Test DSA sigcheck key" )
#define DSA_PRIVKEY_LABEL TEXT( "Test DSA signing key" )
#define ELGAMAL_PUBKEY_LABEL TEXT( "Test Elgamal public key" )
#define ELGAMAL_PRIVKEY_LABEL TEXT( "Test Elgamal private key" )
#define DH_KEY1_LABEL TEXT( "Test DH key #1" )
#define DH_KEY2_LABEL TEXT( "Test DH key #2" )
#define ECDSA_PUBKEY_LABEL TEXT( "Test ECDSA sigcheck key" )
#define ECDSA_PRIVKEY_LABEL TEXT( "Test ECDSA signing key" )
#define CA_PRIVKEY_LABEL TEXT( "Test RSA private key" )
#define USER_PRIVKEY_LABEL TEXT( "Test user key" )
#define USER_EMAIL TEXT( "dave@wetaburgers.com" )
#define DUAL_SIGNKEY_LABEL TEXT( "Test signing key" )
#define DUAL_ENCRYPTKEY_LABEL TEXT( "Test encryption key" )
#define SYMMETRIC_KEY_LABEL TEXT( "Test symmetric key" )
/****************************************************************************
* *
* Utility Functions *
* *
****************************************************************************/
/* Prototypes for functions in utils.c */
const C_STR getKeyfileName( const KEYFILE_TYPE type,
const BOOLEAN isPrivKey );
const C_STR getKeyfilePassword( const KEYFILE_TYPE type );
const C_STR getKeyfileUserID( const KEYFILE_TYPE type,
const BOOLEAN isPrivKey );
void printErrorAttributeInfo( const CRYPT_CERTIFICATE certificate );
int displayAttributes( const CRYPT_HANDLE cryptHandle );
int printCertInfo( const CRYPT_CERTIFICATE certificate );
int printCertChainInfo( const CRYPT_CERTIFICATE certChain );
void printExtError( const CRYPT_HANDLE cryptHandle,
const char *functionName, const int functionStatus,
const int lineNo );
int importCertFile( CRYPT_CERTIFICATE *cryptCert, const C_STR fileName );
int importCertFromTemplate( CRYPT_CERTIFICATE *cryptCert,
const C_STR fileTemplate, const int number );
int addCertFields( const CRYPT_CERTIFICATE certificate,
const CERT_DATA *certData, const int lineNo );
int checkFileAccess( void );
int checkNetworkAccess( void );
int getPublicKey( CRYPT_CONTEXT *cryptContext, const C_STR keysetName,
const C_STR keyName );
int getPrivateKey( CRYPT_CONTEXT *cryptContext, const C_STR keysetName,
const C_STR keyName, const C_STR password );
void debugDump( const char *fileName, const void *data,
const int dataLength );
int printConnectInfo( const CRYPT_SESSION cryptSession );
int printSecurityInfo( const CRYPT_SESSION cryptSession,
const BOOLEAN isServer,
const BOOLEAN showFingerprint );
int printFingerprint( const CRYPT_SESSION cryptSession,
const BOOLEAN isServer );
BOOLEAN setLocalConnect( const CRYPT_SESSION cryptSession, const int port );
int activatePersistentServerSession( const CRYPT_SESSION cryptSession,
const BOOLEAN showOperationType );
/* Threading support functions, in utils.c */
void createMutex( void );
void acquireMutex( void );
void releaseMutex( void );
int waitMutex( void );
void destroyMutex( void );
#if defined( WINDOWS_THREADS )
void waitForThread( const HANDLE hThread );
#elif defined( UNIX_THREADS )
void waitForThread( const pthread_t hThread );
#else
void waitForThread( const int hThread );
#endif /* Systems with threading support */
int multiThreadDispatch( THREAD_FUNC clientFunction,
THREAD_FUNC serverFunction, const int noThreads );
/* Exit with an error message, in utils.c. attrErrorExit() prints the
locus and type, extErrorExit() prints the extended error code and
message */
BOOLEAN attrErrorExit( const CRYPT_HANDLE cryptHandle,
const char *functionName, const int errorCode,
const int lineNumber );
BOOLEAN extErrorExit( const CRYPT_HANDLE cryptHandle,
const char *functionName, const int errorCode,
const int lineNumber );
/* Prototypes for functions in certs.c */
BOOLEAN certErrorExit( const CRYPT_HANDLE cryptHandle,
const char *functionName, const int errorCode,
const int lineNumber );
int setRootTrust( const CRYPT_CERTIFICATE cryptCertChain,
BOOLEAN *oldTrustValue, const BOOLEAN newTrustValue );
/* Prototypes for functions in testlib.c */
#if defined( UNIX_THREADS ) || defined( WINDOWS_THREADS ) || defined( OS2_THREADS )
void delayThread( const int seconds );
#else
#define delayThread( x )
#endif /* Systems with threading support */
CRYPT_ALGO_TYPE selectCipher( const CRYPT_ALGO_TYPE algorithm );
/* Prototypes for functions in lowlvl.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -