Subversion Repositories DevTools

Rev

Rev 2218 | Rev 2228 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2218 Rev 2222
Line 28... Line 28...
28
#pragma warn -com
28
#pragma warn -com
29
#include <LoggingMacros.h>
29
#include <LoggingMacros.h>
30
#pragma warn +com
30
#pragma warn +com
31
//## end module%41F607FA0261.includes
31
//## end module%41F607FA0261.includes
32
 
32
 
-
 
33
// Iteration
-
 
34
#include "Iteration.h"
33
// IXmlSchemaWrapperFactory
35
// TestScenario
34
#include "IXmlSchemaWrapperFactory.h"
36
#include "TestScenario.h"
-
 
37
// TimeEstimate
-
 
38
#include "TimeEstimate.h"
-
 
39
// ProgressBar
-
 
40
#include "ProgressBar.h"
35
// IXmlSchemaWrapperSchema
41
// IXmlSchemaWrapperSchema
36
#include "IXmlSchemaWrapperSchema.h"
42
#include "IXmlSchemaWrapperSchema.h"
37
// IXmlSchemaWrapperString
43
// IXmlSchemaWrapperString
38
#include "IXmlSchemaWrapperString.h"
44
#include "IXmlSchemaWrapperString.h"
39
// TransactionSpecification
-
 
40
#include "TransactionSpecification.h"
-
 
41
// IXmlSchemaWrapperByteArray
45
// IXmlSchemaWrapperByteArray
42
#include "IXmlSchemaWrapperByteArray.h"
46
#include "IXmlSchemaWrapperByteArray.h"
43
// IXmlSchemaWrapperElement
47
// IXmlSchemaWrapperElement
44
#include "IXmlSchemaWrapperElement.h"
48
#include "IXmlSchemaWrapperElement.h"
-
 
49
// IXmlSchemaWrapperFactory
-
 
50
#include "IXmlSchemaWrapperFactory.h"
45
// IMessageDigest
51
// IXmlSchemaWrapperStream
46
#include "IMessageDigest.h"
52
#include "IXmlSchemaWrapperStream.h"
47
// MacCallback
53
// MacQualification
48
#include "MacCallback.h"
54
#include "MacQualification.h"
49
// EvaluationCallback
55
// EvaluationCallback
50
#include "EvaluationCallback.h"
56
#include "EvaluationCallback.h"
51
// EvaluationContext
57
// EvaluationContext
52
#include "EvaluationContext.h"
58
#include "EvaluationContext.h"
53
// TransactionStream
59
// TransactionStream
54
#include "TransactionStream.h"
60
#include "TransactionStream.h"
55
// TransactionStructure
61
// TransactionStructure
56
#include "TransactionStructure.h"
62
#include "TransactionStructure.h"
57
// Iteration
-
 
58
#include "Iteration.h"
-
 
59
// TestScenario
-
 
60
#include "TestScenario.h"
-
 
61
// TimeEstimate
-
 
62
#include "TimeEstimate.h"
-
 
63
// ProgressBar
-
 
64
#include "ProgressBar.h"
-
 
65
// TransactionSpecificationValue
63
// TransactionSpecificationValue
66
#include "TransactionSpecificationValue.h"
64
#include "TransactionSpecificationValue.h"
-
 
65
// TransactionSpecification
-
 
66
#include "TransactionSpecification.h"
-
 
67
// IMessageDigest
-
 
68
#include "IMessageDigest.h"
67
//## begin module%41F607FA0261.additionalDeclarations preserve=yes
69
//## begin module%41F607FA0261.additionalDeclarations preserve=yes
68
#include <sstream>
70
#include <sstream>
69
#include "Utilities.h"
71
#include "Utilities.h"
-
 
72
 
-
 
73
#define COMPENSATE_FOR_PARSER_BUG 1
-
 
74
#if COMPENSATE_FOR_PARSER_BUG
-
 
75
static void rotateBuffer( unsigned char * buffer, const unsigned int & length )
-
 
76
{
-
 
77
	unsigned char b;
-
 
78
 
-
 
79
	for ( unsigned int i=0, j=length-1; i<length/2; ++i,--j )
-
 
80
	{
-
 
81
		b = buffer[ i ];
-
 
82
		buffer[ i ] = buffer[ j ];
-
 
83
		buffer[ j ] = b;
-
 
84
	}
-
 
85
}
-
 
86
#endif
-
 
87
 
70
//## end module%41F607FA0261.additionalDeclarations
88
//## end module%41F607FA0261.additionalDeclarations
71
 
89
 
72
 
90
 
73
// Class TransactionSpecification 
91
// Class TransactionSpecification
74
 
92
 
75
//## begin TransactionSpecification::headerStructureName%4206D764033E.attr preserve=no  private: static char {RAC} "SysHdr_t"
93
//## begin TransactionSpecification::headerStructureName%4206D764033E.attr preserve=no  private: static char {RAC} "SysHdr_t"
76
const char *TransactionSpecification::g_headerStructureName = "SysHdr_t";
94
const char *TransactionSpecification::g_headerStructureName = "SysHdr_t";
77
//## end TransactionSpecification::headerStructureName%4206D764033E.attr
95
//## end TransactionSpecification::headerStructureName%4206D764033E.attr
78
 
96
 
79
//## Operation: TransactionSpecification%41F7060D0204
97
//## Operation: TransactionSpecification%41F7060D0204
80
TransactionSpecification::TransactionSpecification (const int &transactionSpecificationNumber)
98
TransactionSpecification::TransactionSpecification (const int &transactionSpecificationNumber)
81
  //## begin TransactionSpecification::TransactionSpecification%41F7060D0204.hasinit preserve=no
99
  //## begin TransactionSpecification::TransactionSpecification%41F7060D0204.hasinit preserve=no
82
      : m_structureIndex(0),
100
	  : m_structureIndex(0),
83
        m_transactionSpecificationNumber(0),
101
		m_transactionSpecificationNumber(0),
84
        m_udSubtype(0),
102
		m_udSubtype(0),
85
        m_udType(0),
103
		m_udType(0),
86
        m_formatVersion(0),
104
		m_formatVersion(0),
87
        m_scenario(0),
105
		m_scenario(0),
88
        m_string(0),
106
        m_string(0),
89
        m_structure(0),
107
        m_structure(0),
90
        m_macFields(0)
108
        m_macFields(0)
91
  //## end TransactionSpecification::TransactionSpecification%41F7060D0204.hasinit
109
  //## end TransactionSpecification::TransactionSpecification%41F7060D0204.hasinit
92
  //## begin TransactionSpecification::TransactionSpecification%41F7060D0204.initialization preserve=yes
110
  //## begin TransactionSpecification::TransactionSpecification%41F7060D0204.initialization preserve=yes
Line 291... Line 309...
291
//## Operation: generate%4204564D02F3
309
//## Operation: generate%4204564D02F3
292
const bool TransactionSpecification::generate (TransactionStream& stream, const bool &generateHeaders, EvaluationContext& evaluationContext)
310
const bool TransactionSpecification::generate (TransactionStream& stream, const bool &generateHeaders, EvaluationContext& evaluationContext)
293
{
311
{
294
  //## begin TransactionSpecification::generate%4204564D02F3.body preserve=yes
312
  //## begin TransactionSpecification::generate%4204564D02F3.body preserve=yes
295
 
313
 
-
 
314
	XMLSchema::IXmlSchemaWrapperFactory & xmlSchemaWrapperFactory
-
 
315
		= m_scenario->getIteration().getSchemaWrapperFactory();
-
 
316
		
296
	/**
317
	/**
297
	 *	Traverse the structures associated with this transaction  in order,
318
	 *	Traverse the structures associated with this transaction  in order,
298
	 *	querying our collection of defined fields for every schema element
319
	 *	querying our collection of defined fields for every schema element
299
	 *	that we encounter.  When we have a match, then we evaluate the
320
	 *	that we encounter.  When we have a match, then we evaluate the
300
	 *	expression found, and assign the result to the schema element currently
321
	 *	expression found, and assign the result to the schema element currently
Line 331... Line 352...
331
		 */
352
		 */
332
		if ( m_macFields.size() )
353
		if ( m_macFields.size() )
333
		{
354
		{
334
			if ( evaluationContext.haveMessageDigest() )
355
			if ( evaluationContext.haveMessageDigest() )
335
			{
356
			{
-
 
357
				/**
-
 
358
				 *	Create a serialsation stream, and serialise all attributes
-
 
359
				 *	into it that are to be included in the MAC.  Then MAC the
-
 
360
				 *	stream.  We need to do this because we need to MAC the
-
 
361
				 *	serialised form, not the internal binary form.
-
 
362
				 */
-
 
363
				MacQualification macQualification( evaluationContext );
-
 
364
 
-
 
365
				XMLSchema::IXmlSchemaWrapperStream *	stream	= 0;
336
				XMLSchema::IXmlSchemaWrapperByteArray * value = 0;
366
				XMLSchema::IXmlSchemaWrapperByteArray *	digest	= 0;
-
 
367
 
337
				try
368
				try
338
				{
369
				{
339
					value = &m_scenario->getIteration().
370
					stream = &xmlSchemaWrapperFactory.createXdrStream();
340
						getSchemaWrapperFactory().createByteArray();
371
					digest = &xmlSchemaWrapperFactory.createByteArray();
341
					MacCallback macCallback(
-
 
342
						evaluationContext,
-
 
343
						*value );
-
 
344
 
372
 
345
					m_structureIndex = 0;
-
 
346
					for ( structure = m_structure.begin();
373
					for ( structure = m_structure.begin();
347
						  structure != m_structure.end();
374
						  structure != m_structure.end();
348
						  ++structure )
375
						  ++structure )
349
					{
376
					{
-
 
377
						// We only include the structure in the MAC computation,
-
 
378
						// never the header.
350
						if ( !(*structure)->isHeader() )
379
						if ( !(*structure)->isHeader() )
351
						{
380
						{
352
							generated = (*structure)->getSchemaElement().
381
							if ( !(*structure)->write(
353
								traverse( macCallback );
382
									*stream,
354
							if ( !generated )
383
									macQualification ) )
355
							{
384
							{
-
 
385
								generated = false;
356
								break;
386
								break;
357
							}
387
							}
358
						}
388
						}
359
						++m_structureIndex;
-
 
360
					}
389
					}
361
 
390
 
362
					if ( evaluationContext.getMessageDigest().getLength() )
391
					if ( generated )
363
					{
392
					{
364
						value->assign(
393
						void *			buffer = 0;
365
							evaluationContext.getMessageDigest().getValue(),
-
 
366
							evaluationContext.getMessageDigest().getLength() );
394
						unsigned int	length = 0;
367
						for ( std::vector< XMLSchema::IXmlSchemaWrapperElement * >
-
 
-
 
395
 
368
								::iterator macField = m_macFields.begin();
396
						// When we get a zero-length MAC, we don't assign it.
369
							  macField != m_macFields.end();
397
						if ( stream->getData( buffer, length ) )
370
							  ++macField )
-
 
371
						{
398
						{
-
 
399
							generated = evaluationContext.getMessageDigest().
372
							if ( !(*macField)->setByteArray( *value ) )
400
								updateByteArray( buffer, length );
-
 
401
							if ( generated )
373
							{
402
							{
-
 
403
								if ( evaluationContext.getMessageDigest().digest() )
-
 
404
								{
-
 
405
									if ( evaluationContext.getMessageDigest().getLength() )
-
 
406
									{
-
 
407
#if COMPENSATE_FOR_PARSER_BUG
-
 
408
										/**
-
 
409
										 *	Compensate for the parser treating
-
 
410
										 *	an array of 8 U8 as a U64 (Why does
-
 
411
										 *	it do that?  Its wrong.).
-
 
412
										 */
-
 
413
										unsigned char * b = const_cast< unsigned char * >( evaluationContext.getMessageDigest().getValue() );
-
 
414
										length = evaluationContext.getMessageDigest().getLength();
-
 
415
										rotateBuffer( b, length );
-
 
416
										digest->assign( b, length );
-
 
417
#else
-
 
418
										digest->assign(
-
 
419
											evaluationContext.getMessageDigest().getValue(),
-
 
420
											evaluationContext.getMessageDigest().getLength() );
-
 
421
#endif // #ifdef COMPENSATE_FOR_PARSER_BUG
-
 
422
 
-
 
423
										for ( std::vector< XMLSchema::IXmlSchemaWrapperElement * >
-
 
424
												::iterator macField = m_macFields.begin();
-
 
425
											  macField != m_macFields.end();
-
 
426
											  ++macField )
-
 
427
										{
-
 
428
											if ( !(*macField)->setByteArray( *digest ) )
-
 
429
											{
374
								generated = false;
430
												generated = false;
375
								break;
431
												break;
-
 
432
											}
-
 
433
										}
-
 
434
									}
-
 
435
									else
-
 
436
									{
-
 
437
										generated = false;
-
 
438
									}
-
 
439
								}
-
 
440
								else
-
 
441
								{
-
 
442
									generated = false;
-
 
443
								}
376
							}
444
							}
377
						}
445
						}
378
					}
446
					}
-
 
447
 
379
				}
448
				}
380
				__finally
449
				__finally
381
				{
450
				{
382
					if ( value )
451
					if ( digest )
383
					{
452
					{
384
						m_scenario->getIteration().getSchemaWrapperFactory().
453
						xmlSchemaWrapperFactory.destroyByteArray( *digest );
-
 
454
						digest = 0;
-
 
455
					}
-
 
456
 
-
 
457
					if ( stream )
-
 
458
					{
385
							destroyByteArray( *value );
459
						xmlSchemaWrapperFactory.destroyStream( *stream );
386
						value = 0;
460
						stream = 0;
387
					}
461
					}
388
				}
462
				}
389
			}
463
			}
390
			else
464
			else
391
			{
465
			{
-
 
466
				generated = false;
-
 
467
			}
-
 
468
 
-
 
469
			if ( !generated )
-
 
470
			{
392
				std::stringstream message;
471
				std::stringstream message;
393
				message
472
				message
394
					<< "Cannot compute MAC.  Is the security subsystem operational?";
473
					<< "Cannot compute MAC.  Is the security subsystem operational?";
395
				MERROR( message.str() );
474
				MERROR( message.str() );
396
				message << "  Ignore the error and continue?";
475
				message << "  Ignore the error and continue?";
397
 
476
 
398
				if ( MessageDlg(
477
				generated = ( MessageDlg(
399
						message.str().c_str(),
478
									message.str().c_str(),
400
						mtConfirmation,
479
									mtConfirmation,
401
						TMsgDlgButtons() << mbYes << mbNo,
480
									TMsgDlgButtons() << mbYes << mbNo,
402
						0 ) != mrYes )
481
									0 ) != mrYes );
403
				{
-
 
404
					generated = false;
-
 
405
				}
-
 
406
			}
482
			}
407
			clearMacFields();
483
			clearMacFields();
408
		}
484
		}
409
	}
485
	}
410
 
486
 
411
	if ( generated )
487
	if ( generated )
412
	{
488
	{
413
		for ( std::vector< TransactionStructure * >::iterator
-
 
414
				structure = m_structure.begin();
489
		for ( structure = m_structure.begin();
415
			  structure != m_structure.end();
490
			  structure != m_structure.end();
416
			  ++structure )
491
			  ++structure )
417
		{
492
		{
418
			if ( generateHeaders || !(*structure)->isHeader() )
493
			if ( generateHeaders || !(*structure)->isHeader() )
419
			{
494
			{
Line 423... Line 498...
423
				generated = (*structure)->write( stream );
498
				generated = (*structure)->write( stream );
424
				if ( !generated )
499
				if ( !generated )
425
				{
500
				{
426
					break;
501
					break;
427
				}
502
				}
428
				stream.incrementCount();
-
 
429
				if ( evaluationContext.haveProgressBar() )
-
 
430
				{
-
 
431
					evaluationContext.getProgressBar().increment();
-
 
432
				}
-
 
433
			}
503
			}
434
		}
504
		}
-
 
505
 
-
 
506
		stream.incrementCount();
-
 
507
		if ( evaluationContext.haveProgressBar() )
435
		
508
		{
-
 
509
			evaluationContext.getProgressBar().increment();
-
 
510
		}
436
		evaluationContext.getTimeEstimate().increment();
511
		evaluationContext.getTimeEstimate().increment();
437
	}
512
	}
438
 
513
 
439
	return ( generated );
514
	return ( generated );
440
 
515