cryptlib  3.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros
test.h
Go to the documentation of this file.
1 /****************************************************************************
2 * *
3 * cryptlib Test Routines Header File *
4 * Copyright Peter Gutmann 1995-2011 *
5 * *
6 ****************************************************************************/
7 
8 /* Define the following to enable/disable various blocks of tests. Note
9  that the self-test uses a sizeable amount of automatic data, on 16-bit
10  systems it'll probably be necessary to run each test individually rather
11  than in groups as arranged below */
12 
13 #if 1
14 #define TEST_SELFTEST /* Perform internal self-test */
15 #define TEST_LOWLEVEL /* Test low-level functions */
16 #define TEST_RANDOM /* Test randomness functions */
17 #define TEST_CONFIG /* Test configuration functions */
18 #define TEST_MIDLEVEL /* Test high-level encr/sig.functions */
19 #endif /* 0 */
20 #if 1
21 #define TEST_CERT /* Test certificate management functions */
22 #define TEST_KEYSET /* Test keyset read functions */
23 #define TEST_CERTPROCESS /* Test certificate handling/CA management */
24 #endif /* 0 */
25 #if 1
26 #define TEST_HIGHLEVEL /* Test high-level encr/sig.functions */
27 #define TEST_ENVELOPE /* Test enveloping functions */
28 #endif /* 0 */
29 #if 1
30 #define TEST_SESSION /* Test session functions */
31 #define TEST_SESSION_LOOPBACK/* Test session functions via local loopback */
32 /*#define TEST_USER // Test user management functions */
33 #endif /* 0 */
34 
35 /* The crypto device tests are disabled by default since relatively few users
36  will have a crypto device set up so leaving them enabled by default would
37  just produce a cascade of device-not-present warnings */
38 
39 /* #define TEST_DEVICE */
40 #if defined( TEST_DEVICE )
41  #ifndef TEST_LOWLEVEL
42  #define TEST_LOWLEVEL
43  #endif /* TEST_LOWLEVEL */
44  #ifndef TEST_ENVELOPE
45  #define TEST_ENVELOPE
46  #endif /* TEST_ENVELOPE */
47 #endif /* Low-level and envelope tests are called by the device tests */
48 
49 /* Some of the device tests can be rather slow, the following defines disable
50  these tests for speed reasons. Note that the Fortezza test can be further
51  cut down by not performing the CAW test (which erases any existing data on
52  the card), this is turned off by default in testdev.c */
53 
54 /* #define TEST_DEVICE_FORTEZZA */
55 
56 /* DH and KEA can't be tested because they use cryptlib-internal mechanisms,
57  however by using a custom-modified cryptlib it's possible to test at
58  least part of the DH implementation. If the following is defined, the
59  DH key load will be tested */
60 
61 /* #define TEST_DH */
62 
63 /* To test the code under Windows CE:
64 
65  - If PB can't start the emulator, start it manually via Tools | Configure
66  Platform Manager | StandardSDK Emulator | Properties | Test.
67  - Before running the self-test for the first time, from the emulator
68  select Folder Sharing, share the test subdirectory, which will appear
69  as \\Storage Card\ (sharing it while an app is running may crash the
70  emulator).
71  - If eVC++ can't connect to the emulator, enable the WCE Config toolbar,
72  frob all the settings (which have only one option anyway). VC++ will
73  rebuild everything (with exactly the same settings as before), and
74  then it'll work.
75  - Only cl32ce.dll can be run in the debugger, test32ce.exe fails with
76  some unknown error code.
77  - To test the randomness polling in the emulated environment, first run
78  the Remote Kernel Tracker, which installs the ToolHelp DLL (this isn't
79  installed by default) */
80 
81 /* When commenting out code for testing, the following macro displays a
82  warning that the behaviour has been changed as well as the location of
83  the change */
84 
85 #if defined( __MVS__ ) || defined( __VMCMS__ ) || defined( __ILEC400__ )
86  #define KLUDGE_WARN( str ) \
87  { \
88  char fileName[ 1000 ]; \
89  strncpy( fileName, __FILE__, 1000 ); \
90  fileName[ 999 ] = '\0'; \
91  __atoe( fileName ); \
92  printf( "Kludging " str ", file %s, line %d.\n", fileName, __LINE__ ); \
93  }
94 #else
95  #define KLUDGE_WARN( str ) \
96  printf( "Kludging " str ", file " __FILE__ ", line %d.\n", __LINE__ );
97 #endif /* ASCII vs.EBCDIC strings */
98 
99 /* Include univerally-needed headers */
100 
101 #if defined( _WIN32_WCE ) && _WIN32_WCE < 400
102  #define assert( x )
103 #else
104  #include <assert.h>
105 #endif /* Systems without assert() */
106 #include <stdio.h>
107 #include <stdlib.h>
108 #include <string.h>
109 #include <time.h>
110 
111 /* Various useful types */
112 
113 #define BOOLEAN int
114 #define BYTE unsigned char
115 #ifndef TRUE
116  #define FALSE 0
117  #define TRUE !FALSE
118 #endif /* TRUE */
119 
120 /* Sentinel value used to denote non-data/non-values */
121 
122 #define SENTINEL -1000
123 
124 /* A dummy initialistion value used to deal with false-positive compiler
125  warnings */
126 
127 #ifndef DUMMY_INIT
128  #define DUMMY_INIT 0
129 #endif /* DUMMY_INIT */
130 
131 /* There are a few OSes broken enough not to define the standard exit codes
132  (SunOS springs to mind) so we define some sort of equivalent here just
133  in case */
134 
135 #ifndef EXIT_SUCCESS
136  #define EXIT_SUCCESS 0
137  #define EXIT_FAILURE !EXIT_SUCCESS
138 #endif /* EXIT_SUCCESS */
139 
140 /* Although min() and max() aren't in the ANSI standard, most compilers have
141  them in one form or another, but just enough don't that we need to define
142  them ourselves in some cases */
143 
144 #if !defined( min )
145  #ifdef MIN
146  #define min MIN
147  #define max MAX
148  #else
149  #define min( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
150  #define max( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
151  #endif /* Various min/max macros */
152 #endif /* !min/max */
153 
154 /* If we're using a 16-bit compiler, record this */
155 
156 #if defined( __MSDOS__ ) && !defined( __MSDOS32__ )
157  #define __MSDOS16__
158 #endif /* 16-bit DOS */
159 #if defined( _MSC_VER ) && ( _MSC_VER <= 800 )
160  #define __WIN16__
161 #endif /* 16-bit Windows */
162 
163 /* It's useful to know if we're running under Windows to enable Windows-
164  specific processing */
165 
166 #if defined( _WINDOWS ) || defined( WIN32 ) || defined( _WIN32 ) || \
167  defined( _WIN32_WCE )
168  #define __WINDOWS__
169 #endif /* _WINDOWS || WIN32 || _WIN32 */
170 
171 /* If we're running in an environment with a Unicode API, we have to be able
172  to function with both Unicode and ASCII strings */
173 
174 #ifdef __WINDOWS__
175  #if defined( _WIN32_WCE )
176  #undef TEXT
177  #define TEXT( x ) L ## x
178  #define paramStrlen( x ) ( wcslen( x ) * sizeof( wchar_t ) )
179  #define paramStrcmp( x, y ) wcscmp( x, y )
180  #define UNICODE_STRINGS
181  #elif ( defined( WIN32 ) || defined( _WIN32 ) ) && 0
182  /* Facility to test WinCE Unicode handling under Win32 */
183  #undef TEXT
184  #define TEXT( x ) L ## x
185  #define paramStrlen( x ) ( wcslen( x ) * sizeof( wchar_t ) )
186  #define paramStrcmp( x, y ) wcscmp( x, y )
187  #define UNICODE_STRINGS
188  #else
189  #undef TEXT /* Already defined in windows.h */
190  #define TEXT( x ) x
191  #define paramStrlen( x ) strlen( x )
192  #define paramStrcmp( x, y ) strcmp( x, y )
193  #endif /* Windows variants */
194 #else
195  #define TEXT( x ) x
196  #define paramStrlen( x ) strlen( x )
197  #define paramStrcmp( x, y ) strcmp( x, y )
198 #endif /* Unicode vs. ASCII API */
199 
200 /* In certain memory-starved environments we have to kludge things to help
201  the compiler along. The following define tells the compiler to move BSS
202  data outside the default data segment */
203 
204 #if defined( _MSC_VER ) && ( _MSC_VER <= 800 )
205  #define FAR_BSS far
206 #else
207  #define FAR_BSS
208 #endif /* Win16 */
209 
210 /* VS 2005 and newer warn if we use non-TR 24731 stdlib functions, since
211  this is only for the test code we disable the warnings. In addition
212  VS in 64-bit mode warns about size_t (e.g. from calling strlen()) <->
213  int conversion */
214 
215 #if defined( _MSC_VER ) && ( _MSC_VER >= 1400 )
216  #pragma warning( disable: 4267 ) /* int <-> size_t */
217  #pragma warning( disable: 4996 ) /* Non-TR 24731 stdlib use */
218 #endif /* VC++ 2005 or newer */
219 
220 /* Generic buffer size and dynamically-allocated file I/O buffer size. The
221  generic buffer has to be of a reasonable size so that we can handle
222  S/MIME signature chains, the file buffer should be less than the 16-bit
223  INT_MAX for testing on 16-bit machines and less than 32K for testing on
224  the (16-bit DOS-derived) Watcom C 10 */
225 
226 #if defined( __MSDOS16__ ) || defined( __WIN16__ )
227  #define BUFFER_SIZE 4096
228  #define FILEBUFFER_SIZE 20000
229 #elif defined( __QNX__ ) && defined( __WATCOMC__ ) && ( __WATCOMC__ < 1100 )
230  #define BUFFER_SIZE 8192
231  #define FILEBUFFER_SIZE 20000
232 #else
233  #define BUFFER_SIZE 16384
234  #define FILEBUFFER_SIZE 32768
235 #endif /* __MSDOS__ && __TURBOC__ */
236 #define FILENAME_BUFFER_SIZE 512
237 
238 /* Explicit includes needed by Palm OS, see the comment in crypt.h for more
239  details */
240 
241 #ifdef __PALMSOURCE__
242  #include <ctype.h>
243  #include <string.h>
244 #endif /* __PALMSOURCE__ */
245 
246 /* The ability to get rid of annoying warnings via the project file in BC++
247  5.0x is completely broken, the only way to do this is via pragmas in the
248  source code */
249 
250 #if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x550 )
251  #pragma warn -ucp /* Signed/unsigned char assignment */
252 #endif /* Broken BC++ 5.0x warning handling */
253 
254 /* Helper function to make tracking down errors on systems with no console a
255  bit less painful */
256 
257 #ifdef _WIN32_WCE
258  #define printf wcPrintf
259  #define puts wcPuts
260 
261  void wcPrintf( const char *format, ... );
262  void wcPuts( const char *string );
263 #endif /* Console-less environments */
264 
265 /* Try and detect OSes that have threading support, this is needed for some
266  operations like async keygen and sleep calls */
267 
268 #if( ( defined( _AIX ) || defined( __APPLE__ ) || defined( __FreeBSD__ ) || \
269  defined( __NetBSD__ ) || defined( __linux__ ) || \
270  ( defined( sun ) && ( OSVERSION > 4 ) ) ) && !defined( NO_THREADS ) )
271  #define UNIX_THREADS
272 
273  /* We need to include pthread.h at this point because any number of other
274  include files perform all sorts of peculiar and unnatural acts in order
275  to make their functions (transparently) thread-safe, triggered by the
276  detection of values defined in pthread.h. Because of this we need to
277  include it here as a rubber chicken before other files are pulled in
278  even though it's not explicitly needed */
279  #include <pthread.h>
280 #endif /* AIX || OS/X || Linux || Slowaris */
281 #if ( defined( WIN32 ) || defined( _WIN32 ) ) && !defined( _WIN32_WCE )
282  /* We don't test the loopback functionality under WinCE because the
283  _beginthreadx() vs. CreateThread() issue (normally hidden in
284  cryptos.h) causes all sorts of problems */
285  #define WINDOWS_THREADS
286  #include <process.h>
287 #endif /* Win32 */
288 #if defined( __IBMC__ ) && defined( __OS2__ )
289  #define OS2_THREADS
290 #endif /* OS/2 */
291 
292 /* The loopback sessions require threading support so we only enable their
293  use if this is present */
294 
295 #if defined( TEST_SESSION_LOOPBACK ) && !defined( WINDOWS_THREADS )
296  #undef TEST_SESSION_LOOPBACK
297 #endif /* OSes with threading support */
298 
299 /* Define various portable data types and functions needed for the threaded
300  loopback tests */
301 
302 #if defined( WINDOWS_THREADS )
303  #define THREAD_HANDLE HANDLE
304  #define THREAD_EXIT() _endthreadex( 0 ); return( 0 )
305  #define THREAD_SELF() GetCurrentThreadId()
306  typedef unsigned ( __stdcall *THREAD_FUNC )( void *arg );
307 #elif defined( UNIX_THREADS )
308  #define THREAD_HANDLE pthread_t
309  #define THREAD_EXIT() pthread_exit( ( void * ) 0 ); return( 0 )
310  #define THREAD_SELF() pthread_self()
311  typedef void * ( *THREAD_FUNC )( void *arg );
312 #else
313  #define THREAD_HANDLE int
314  #define THREAD_EXIT()
315  #define THREAD_SELF() 0
316  typedef void ( *THREAD_FUNC )( void *arg );
317 #endif /* OS-specific threading functions */
318 
319 /* The maximum number of threads that we can fire up in the multithreaded
320  tests */
321 
322 #define MAX_NO_THREADS 10
323 
324 /* Try and detect OSes that have widechar support */
325 
326 #if ( defined( __WINDOWS__ ) && \
327  !( defined( __WIN16__ ) || defined( __BORLANDC__ ) ) ) || \
328  defined( __linux__ ) || \
329  ( defined( sun ) && ( OSVERSION > 4 ) ) || defined( __osf__ )
330  #define HAS_WIDECHAR
331 #endif /* OSes with widechar support */
332 
333 /* If we're running on an EBCDIC system, ensure that we're compiled in
334  EBCDIC mode to test the conversion of character strings */
335 
336 #if defined( __MVS__ ) || defined( __VMCMS__ )
337  #pragma convlit( suspend )
338 #endif /* IBM big iron */
339 #if defined( __ILEC400__ )
340  #pragma convert( 0 )
341 #endif /* IBM medium iron */
342 
343 /* If we're compiling under QNX, make enums a fixed size rather than using
344  the variable-length values that the Watcom compiler defaults to */
345 
346 #if defined( __QNX__ ) && defined( __WATCOMC__ )
347  #pragma enum int
348 #endif /* QNX and Watcom C */
349 
350 /* The key size to use for the PKC routines. This is the minimum allowed by
351  cryptlib, it speeds up the various tests but shouldn't be used in
352  practice */
353 
354 #define PKC_KEYSIZE 512
355 
356 /* Since the handling of filenames can get unwieldy when we have large
357  numbers of similar files, we use a function to map a filename template
358  and number into an actual filename rather the having to use huge
359  numbers of defines */
360 
361 #ifdef UNICODE_STRINGS
362  void filenameFromTemplate( char *buffer, const wchar_t *fileTemplate,
363  const int count );
364  void filenameParamFromTemplate( wchar_t *buffer,
365  const wchar_t *fileTemplate,
366  const int count );
367  const char *convertFileName( const C_STR fileName );
368 #else
369  #define filenameFromTemplate( buffer, fileTemplate, count ) \
370  sprintf( buffer, fileTemplate, count )
371  #define filenameParamFromTemplate( buffer, fileTemplate, count ) \
372  sprintf( buffer, fileTemplate, count )
373  #define convertFileName( fileName ) fileName
374 #endif /* Unicode vs. ASCII */
375 
376 /* Helper functions for limited environments that are missing full stdlib
377  support */
378 
379 #if defined( _WIN32_WCE ) && _WIN32_WCE < 500
380  int remove( const char *pathname );
381 #endif /* WinCE < 5.x */
382 
383 /* A structure that allows us to specify a collection of extension
384  components. This is used when adding a collection of extensions to a
385  cert */
386 
389 
390 typedef struct {
391  const CRYPT_ATTRIBUTE_TYPE type;/* Extension component ID */
392  const COMPONENT_TYPE componentType; /* Component type */
393  const int numericValue; /* Value if numeric */
394  const void *stringValue; /* Value if string */
395  const time_t timeValue; /* Value if time */
396  } CERT_DATA;
397 
398 /****************************************************************************
399 * *
400 * Naming *
401 * *
402 ****************************************************************************/
403 
404 /* Pull in the OS-specific file names for the test data */
405 
406 #ifdef _MSC_VER
407  #include "filename.h"
408 #else
409  #include "test/filename.h"
410 #endif /* Braindamaged MSC include handling */
411 
412 /* When we're using common code to handle a variety of key file types for
413  key read/encryption/signing tests, we need to distinguish between the
414  different key files to use. The following types are handled in the test
415  code */
416 
421 
422 /* The generic password used for password-based encryption, and another one
423  for private key storage */
424 
425 #define TEST_PASSWORD TEXT( "password" )
426 #define TEST_PRIVKEY_PASSWORD TEXT( "test" )
427 
428 /* The database keyset type and name. Under Windoze we use ODBC, for
429  anything else we use the first database which is enabled by a preprocessor
430  define, defaulting to an internal plugin (which doesn't have to be
431  available, if it's not present we continue after printing a warning) */
432 
433 #if defined( _MSC_VER )
434  #define DATABASE_KEYSET_TYPE CRYPT_KEYSET_ODBC
435  #define CERTSTORE_KEYSET_TYPE CRYPT_KEYSET_ODBC_STORE
436 #elif defined( DBX_DATABASE )
437  #define DATABASE_KEYSET_TYPE CRYPT_KEYSET_DATABASE
438  #define CERTSTORE_KEYSET_TYPE CRYPT_KEYSET_DATABASE_STORE
439 #elif defined( DBX_PLUGIN )
440  #define DATABASE_KEYSET_TYPE CRYPT_KEYSET_PLUGIN
441  #define CERTSTORE_KEYSET_TYPE CRYPT_KEYSET_PLUGIN_STORE
442 #else
443  #define DATABASE_KEYSET_TYPE CRYPT_KEYSET_DATABASE
444  #define CERTSTORE_KEYSET_TYPE CRYPT_KEYSET_DATABASE_STORE
445 #endif /* Various database backends */
446 #define DATABASE_KEYSET_NAME TEXT( "testkeys" )
447 #define DATABASE_KEYSET_NAME_ASCII "testkeys"
448 #define CERTSTORE_KEYSET_NAME TEXT( "testcertstore" )
449 #define CERTSTORE_KEYSET_NAME_ASCII "testcertstore"
450 #define DATABASE_PLUGIN_KEYSET_NAME TEXT( "localhost:6500" )
451 #define DATABASE_PLUGIN_KEYSET_NAME_ASCII "localhost:6500"
452 
453 /* The HTTP keyset names (actually URLs for pages containing a cert and
454  CRL). We can't get either Verisign or Thawte root certs because both
455  require you to provide all sorts of personal information and click on a
456  legal agreement before you can download them (!!!), so we use the CAcert
457  root instead */
458 
459 #define HTTP_KEYSET_CERT_NAME TEXT( "www.cacert.org/certs/root.der" )
460 #define HTTP_KEYSET_CRL_NAME TEXT( "crl.verisign.com/Class1Individual.crl" )
461 #define HTTP_KEYSET_HUGECRL_NAME TEXT( "crl.verisign.com/RSASecureServer.crl" )
462 
463 /* Assorted default server names and authentication information, and the PKI
464  SRV server (redirecting to mail.cryptoapps.com:8080). There are so many
465  TSP, OCSP, and CMP servers, and they never stay around for long, that we
466  allow remapping in the functions where the secure session tests are
467  performed */
468 
469 #define SSH_USER_NAME TEXT( "test" )
470 #define SSH_PASSWORD TEXT( "test" )
471 #define SSL_USER_NAME TEXT( "test" )
472 #define SSL_PASSWORD TEXT( "test" )
473 #define PKI_SRV_NAME TEXT( "_pkiboot._tcp.cryptoapps.com" )
474 #define TSP_DEFAULTSERVER_NAME TEXT( "http://timestamping.edelweb.fr/service/tsp" )
475 
476 /* Labels for the various public-key objects. These are needed when the
477  underlying implementation creates persistent objects (eg keys held in PKCS
478  #11 tokens) that need to be identified */
479 
480 #define RSA_PUBKEY_LABEL TEXT( "Test RSA public key" )
481 #define RSA_PRIVKEY_LABEL TEXT( "Test RSA private key" )
482 #define RSA_BIG_PRIVKEY_LABEL TEXT( "Test RSA big private key" )
483 #define DSA_PUBKEY_LABEL TEXT( "Test DSA sigcheck key" )
484 #define DSA_PRIVKEY_LABEL TEXT( "Test DSA signing key" )
485 #define ELGAMAL_PUBKEY_LABEL TEXT( "Test Elgamal public key" )
486 #define ELGAMAL_PRIVKEY_LABEL TEXT( "Test Elgamal private key" )
487 #define DH_KEY1_LABEL TEXT( "Test DH key #1" )
488 #define DH_KEY2_LABEL TEXT( "Test DH key #2" )
489 #define ECDSA_PUBKEY_LABEL TEXT( "Test ECDSA sigcheck key" )
490 #define ECDSA_PRIVKEY_LABEL TEXT( "Test ECDSA signing key" )
491 #define CA_PRIVKEY_LABEL TEXT( "Test RSA private key" )
492 #define USER_PRIVKEY_LABEL TEXT( "Test user key" )
493 #define USER_EMAIL TEXT( "[email protected]" )
494 #define DUAL_SIGNKEY_LABEL TEXT( "Test signing key" )
495 #define DUAL_ENCRYPTKEY_LABEL TEXT( "Test encryption key" )
496 #define SYMMETRIC_KEY_LABEL TEXT( "Test symmetric key" )
497 
498 /****************************************************************************
499 * *
500 * Utility Functions *
501 * *
502 ****************************************************************************/
503 
504 /* Prototypes for functions in utils.c */
505 
507  const BOOLEAN isPrivKey );
510  const BOOLEAN isPrivKey );
516  const char *functionName, const int functionStatus,
517  const int lineNo );
518 int importCertFile( CRYPT_CERTIFICATE *cryptCert, const C_STR fileName );
520  const C_STR fileTemplate, const int number );
522  const CERT_DATA *certData, const int lineNo );
523 int checkFileAccess( void );
524 int checkNetworkAccess( void );
525 int getPublicKey( CRYPT_CONTEXT *cryptContext, const C_STR keysetName,
526  const C_STR keyName );
527 int getPrivateKey( CRYPT_CONTEXT *cryptContext, const C_STR keysetName,
528  const C_STR keyName, const C_STR password );
529 void debugDump( const char *fileName, const void *data,
530  const int dataLength );
531 int printConnectInfo( const CRYPT_SESSION cryptSession );
532 int printSecurityInfo( const CRYPT_SESSION cryptSession,
533  const BOOLEAN isServer,
534  const BOOLEAN showFingerprint,
535  const BOOLEAN showServerKeyInfo,
536  const BOOLEAN showClientCertInfo );
537 int printFingerprint( const CRYPT_SESSION cryptSession,
538  const BOOLEAN isServer );
539 BOOLEAN setLocalConnect( const CRYPT_SESSION cryptSession, const int port );
540 int activatePersistentServerSession( const CRYPT_SESSION cryptSession,
541  const BOOLEAN showOperationType );
542 
543 /* Threading support functions, in utils.c */
544 
545 void createMutex( void );
546 void acquireMutex( void );
547 void releaseMutex( void );
548 int waitMutex( void );
549 void destroyMutex( void );
550 #if defined( WINDOWS_THREADS )
551  void waitForThread( const HANDLE hThread );
552 #elif defined( UNIX_THREADS )
553  void waitForThread( const pthread_t hThread );
554 #else
555  void waitForThread( const int hThread );
556 #endif /* Systems with threading support */
557 int multiThreadDispatch( THREAD_FUNC clientFunction,
558  THREAD_FUNC serverFunction, const int noThreads );
559 
560 /* Exit with an error message, in utils.c. attrErrorExit() prints the
561  locus and type, extErrorExit() prints the extended error code and
562  message */
563 
565  const char *functionName, const int errorCode,
566  const int lineNumber );
568  const char *functionName, const int errorCode,
569  const int lineNumber );
570 
571 /* Prototypes for functions in certs.c */
572 
574  const char *functionName, const int errorCode,
575  const int lineNumber );
576 int setRootTrust( const CRYPT_CERTIFICATE cryptCertChain,
577  BOOLEAN *oldTrustValue, const BOOLEAN newTrustValue );
578 
579 /* Prototypes for functions in testlib.c */
580 
581 #if defined( UNIX_THREADS ) || defined( WINDOWS_THREADS ) || defined( OS2_THREADS )
582  void delayThread( const int seconds );
583 #else
584  #define delayThread( x )
585 #endif /* Systems with threading support */
587 
588 /* Prototypes for functions in lowlvl.c */
589 
590 BOOLEAN loadDHKey( const CRYPT_DEVICE cryptDevice,
592 BOOLEAN loadRSAContextsEx( const CRYPT_DEVICE cryptDevice,
594  CRYPT_CONTEXT *decryptContext,
595  const C_STR cryptContextLabel,
596  const C_STR decryptContextLabel,
597  const BOOLEAN useLargeKey,
598  const BOOLEAN useMinimalKey );
599 BOOLEAN loadRSAContexts( const CRYPT_DEVICE cryptDevice,
601  CRYPT_CONTEXT *decryptContext );
602 BOOLEAN loadRSAContextsLarge( const CRYPT_DEVICE cryptDevice,
604  CRYPT_CONTEXT *decryptContext );
605 BOOLEAN loadDSAContextsEx( const CRYPT_DEVICE cryptDevice,
608  const C_STR signContextLabel,
609  const C_STR sigCheckContextLabel );
610 BOOLEAN loadDSAContexts( const CRYPT_DEVICE cryptDevice,
614  CRYPT_CONTEXT *decryptContext );
615 BOOLEAN loadDHContexts( CRYPT_CONTEXT *cryptContext1,
616  CRYPT_CONTEXT *cryptContext2 );
619 void destroyContexts( const CRYPT_DEVICE cryptDevice,
621  CRYPT_CONTEXT decryptContext );
622 int testLowlevel( const CRYPT_DEVICE cryptDevice,
624  const BOOLEAN checkOnly );
626  BYTE *buffer, const BOOLEAN isDevice,
627  const BOOLEAN noWarnFail );
628 int testRSAMinimalKey( void );
629 
630 /* Prototypes for functions in envelope.c */
631 
633  const CRYPT_HANDLE decryptKeyset );
635 int testCMSEnvelopePKCCryptEx( const CRYPT_HANDLE encryptContext,
636  const CRYPT_HANDLE decryptKeyset,
637  const C_STR password, const C_STR recipient );
638 
639 /* Prototypes for functions in sreqresp.c */
640 
641 int testSessionTSPServerEx( const CRYPT_CONTEXT privKeyContext );
642 
643 /* Prototypes for functions in s_scep.c */
644 
645 int pkiGetUserInfo( C_STR userID, C_STR issuePW, C_STR revPW,
646  const C_STR userName );
647 int pkiServerInit( CRYPT_CONTEXT *cryptPrivateKey,
648  CRYPT_KEYSET *cryptCertStore, const C_STR keyFileName,
649  const C_STR keyLabel, const CERT_DATA *pkiUserData,
650  const CERT_DATA *pkiUserAltData,
651  const CERT_DATA *pkiUserCAData, const char *protocolName );
652 
653 /****************************************************************************
654 * *
655 * Test Functions *
656 * *
657 ****************************************************************************/
658 
659 /* Prototypes for functions in highlvl.c */
660 
661 int testLargeBufferEncrypt( void );
662 int testDeriveKey( void );
663 int testRandomRoutines( void );
664 int testConventionalExportImport( void );
665 int testMACExportImport( void );
666 int testKeyExportImport( void );
667 int testSignData( void );
668 int testKeygen( void );
669 int testKeygenAsync( void );
670 int testKeyExportImportCMS( void );
671 int testSignDataCMS( void );
672 
673 /* Prototypes for functions in devices.c */
674 
675 int testDevices( void );
676 int testUser( void );
677 
678 /* Prototypes for functions in keyfile.c */
679 
680 int testGetPGPPublicKey( void );
681 int testGetPGPPrivateKey( void );
682 int testReadWriteFileKey( void );
683 int testReadWriteAltFileKey( void );
684 int testImportFileKey( void );
685 int testReadFilePublicKey( void );
686 int testAddTrustedCert( void );
687 int testAddGloballyTrustedCert( void );
688 int testDeleteFileKey( void );
689 int testChangeFileKeyPassword( void );
690 int testUpdateFileCert( void );
691 int testWriteFileCertChain( void );
692 int testWriteFileLongCertChain( void );
693 int testReadFileCert( void );
694 int testReadFileCertPrivkey( void );
695 int testReadFileCertChain( void );
696 int testReadCorruptedKey( void );
697 int testSingleStepFileCert( void );
698 int testSingleStepAltFileCert( void );
699 int testDoubleCertFile( void );
700 int testRenewedCertFile( void );
701 int testReadAltFileKey( void );
702 int testReadMiscFile( void );
703 
704 /* Prototypes for functions in keydbx.c */
705 
706 int testWriteCert( void );
707 int testReadCert( void );
708 int testKeysetQuery( void );
709 int testWriteCertDbx( void );
710 int testWriteCertLDAP( void );
711 int testReadCertLDAP( void );
712 int testReadCertURL( void );
713 int testReadCertHTTP( void );
714 
715 /* Prototypes for functions in envelope.c */
716 
717 int testEnvelopeData( void );
718 int testEnvelopeDataLargeBuffer( void );
719 int testEnvelopeCompress( void );
721 int testEnvelopeSessionCrypt( void );
723 int testEnvelopeCrypt( void );
724 int testEnvelopePasswordCrypt( void );
727 int testEnvelopePKCCrypt( void );
728 int testEnvelopePKCCryptAlgo( void );
730 int testEnvelopeSign( void );
731 int testEnvelopeSignAlgo( void );
732 int testEnvelopeSignOverflow( void );
734 int testEnvelopeAuthenticate( void );
735 int testEnvelopeAuthEnc( void );
736 int testCMSEnvelopePKCCrypt( void );
739 int testCMSEnvelopeSign( void );
740 int testCMSEnvelopeDualSign( void );
741 int testCMSEnvelopeDetachedSig( void );
743 
744 /* Prototypes for functions in certs.c */
745 
746 int testBasicCert( void );
747 int testCACert( void );
748 int testXyzzyCert( void );
749 int testTextStringCert( void );
750 int testComplexCert( void );
751 int testCertExtension( void );
752 int testCustomDNCert( void );
753 int testCertAttributeHandling( void );
754 int testSETCert( void );
755 int testAttributeCert( void );
756 int testCRL( void );
757 int testComplexCRL( void );
758 int testCertChain( void );
759 int testCertRequest( void );
760 int testComplexCertRequest( void );
761 int testCRMFRequest( void );
762 int testComplexCRMFRequest( void );
763 int testRevRequest( void );
764 int testCMSAttributes( void );
765 int testRTCSReqResp( void );
766 int testOCSPReqResp( void );
767 int testPKIUser( void );
768 int testCertImport( void );
769 int testCertImportECC( void );
770 int testCertReqImport( void );
771 int testCRLImport( void );
772 int testCertChainImport( void );
773 int testOCSPImport( void );
774 int testBase64CertImport( void );
775 int testBase64CertChainImport( void );
776 int testMiscImport( void );
777 int testNonchainCert( void );
778 int testCertComplianceLevel( void );
779 int testPathProcessing( void );
780 int testPKCS1Padding( void );
781 int testCertProcess( void );
782 int testCertManagement( void );
783 
784 /* Prototypes for functions in scert.c (the EnvTSP one is actually in with
785  the enveloping code because the only way to fully exercise the TS
786  functionality is by using it to timestamp an S/MIME signature) */
787 
788 int testSessionSCEP( void );
789 int testSessionSCEPCACert( void );
790 int testSessionSCEPServer( void );
791 int testSessionCMP( void );
792 int testSessionCMPServer( void );
793 int testSessionPNPPKI( void );
794 int testSessionEnvTSP( void );
795 
796 /* Prototypes for functions in sreqresp.c */
797 
799 int testSessionRTCS( void );
800 int testSessionRTCSServer( void );
801 int testSessionOCSP( void );
802 int testSessionOCSPServer( void );
803 int testSessionTSP( void );
804 int testSessionTSPServer( void );
805 
806 /* Prototypes for functions in ssh.c */
807 
808 int testSessionUrlParse( void );
809 int testSessionAttributes( void );
810 int testSessionSSHv1( void );
811 int testSessionSSH( void );
812 int testSessionSSHClientCert( void );
813 int testSessionSSHPortforward( void );
814 int testSessionSSHExec( void );
815 int testSessionSSH_SFTP( void );
816 int testSessionSSHv1Server( void );
817 int testSessionSSHServer( void );
818 int testSessionSSH_SFTPServer( void );
819 
820 /* Prototypes for functions in ssl.c */
821 
822 int testSessionSSL( void );
823 int testSessionSSLLocalSocket( void );
824 int testSessionSSLClientCert( void );
825 int testSessionSSLSharedKey( void );
826 int testSessionSSLServer( void );
827 int testSessionSSLServerCached( void );
829 int testSessionTLS( void );
830 int testSessionTLSServer( void );
832 int testSessionTLS11( void );
833 int testSessionTLS11Server( void );
834 int testSessionTLS12( void );
835 int testSessionTLS12ClientCert( void );
836 
837 /* Functions to test local client/server sessions. These require threading
838  support since they run the client and server in different threads */
839 
840 #ifdef TEST_SESSION_LOOPBACK
841  int testSessionSSHv1ClientServer( void );
842  int testSessionSSHClientServer( void );
846  int testSessionSSHClientServerSFTP( void );
848  int testSessionSSHClientServerExec( void );
852  int testSessionSSLClientServer( void );
854  int testSessionTLSClientServer( void );
859  int testSessionTLS11ClientServer( void );
860  int testSessionTLS12ClientServer( void );
867  int testSessionRTCSClientServer( void );
868  int testSessionOCSPClientServer( void );
869  int testSessionTSPClientServer( void );
871  int testSessionSCEPClientServer( void );
874  int testSessionCMPClientServer( void );
875  int testSessionCMPSHA2ClientServer( void );
877  int testSessionCMPFailClientServer( void );
878  int testSessionPNPPKIClientServer( void );
882  int testSessionSuiteBClientServer( void );
883 #endif /* TEST_SESSION_LOOPBACK */
884 
885 /* Umbrella tests for the above functions */
886 
887 BOOLEAN testSelfTest( void );
888 BOOLEAN testLowLevel( void );
889 BOOLEAN testRandom( void );
890 BOOLEAN testConfig( void );
891 BOOLEAN testDevice( void );
892 BOOLEAN testMidLevel( void );
893 BOOLEAN testHighLevel( void );
894 BOOLEAN testCert( void );
895 BOOLEAN testCertMgmt( void );
896 BOOLEAN testKeysetFile( void );
898 BOOLEAN testEnveloping( void );
899 BOOLEAN testSessions( void );
901 BOOLEAN testUsers( void );
902 
903 #if defined( __MVS__ ) || defined( __VMCMS__ )
904  #pragma convlit( resume )
905 #endif /* IBM big iron */
906 #if defined( __ILEC400__ )
907  #pragma convert( 819 )
908 #endif /* IBM medium iron */