in xsec/tools/xtest/xtest.cpp [2585:2835]
int main(int argc, char **argv) {
/* We output a version number to overcome a "feature" in Microsoft's memory
leak detection */
cerr << "DSIG Info - Using Apache XML-Security-C Library v" <<
XSEC_VERSION_MAJOR <<
"." << XSEC_VERSION_MEDIUM << "." << XSEC_VERSION_MINOR <<
" (" << _XSEC_VERSION_FULL << ")\n";
// Check parameters
bool doEncryptionTest = true;
bool doEncryptionUnitTests = true;
bool doSignatureTest = true;
bool doSignatureUnitTests = true;
// Testing for which Crypto API to use by default - only really useful on windows
#if !defined(XSEC_HAVE_OPENSSL)
#if defined(XSEC_HAVE_WINCAPI)
g_useWinCAPI = true;
#endif
#endif
int paramCount = 1;
while (paramCount < argc) {
if (_stricmp(argv[paramCount], "--help") == 0 || _stricmp(argv[paramCount], "-h") == 0) {
printUsage();
exit(0);
}
else if (_stricmp(argv[paramCount], "--print-docs") == 0 || _stricmp(argv[paramCount], "-p") == 0) {
g_printDocs = true;
paramCount++;
}
#if defined(XSEC_HAVE_WINCAPI) && defined(XSEC_HAVE_OPENSSL)
else if (_stricmp(argv[paramCount], "--wincapi") == 0 || _stricmp(argv[paramCount], "-w") == 0) {
g_useWinCAPI = true;
paramCount++;
}
#endif
#if defined(XSEC_HAVE_NSS)
else if (_stricmp(argv[paramCount], "--nss") == 0 || _stricmp(argv[paramCount], "-n") == 0) {
g_useNSS = true;
paramCount++;
}
#endif
else if (_stricmp(argv[paramCount], "--signature-only") == 0 || _stricmp(argv[paramCount], "-s") == 0) {
doEncryptionTest = false;
doEncryptionUnitTests = false;
doSignatureUnitTests = false;
paramCount++;
}
else if (_stricmp(argv[paramCount], "--encryption-only") == 0 || _stricmp(argv[paramCount], "-e") == 0) {
doSignatureTest = false;
doEncryptionUnitTests = false;
doSignatureUnitTests = false;
paramCount++;
}
else if (_stricmp(argv[paramCount], "--encryption-unit-only") == 0 || _stricmp(argv[paramCount], "-u") == 0) {
doEncryptionTest = false;
doSignatureTest = false;
doSignatureUnitTests = false;
paramCount++;
}
else if (_stricmp(argv[paramCount], "--signature-unit-only") == 0 || _stricmp(argv[paramCount], "-t") == 0) {
doEncryptionTest = false;
doSignatureTest = false;
doEncryptionUnitTests = false;
paramCount++;
}
else if (_stricmp(argv[paramCount], "--no-gcm") == 0) {
g_testGCM = false;
paramCount++;
}
/* else if (stricmp(argv[paramCount], "--xkms-only") == 0 || stricmp(argv[paramCount], "-x") == 0) {
doEncryptionTest = false;
doSignatureTest = false;
doEncryptionUnitTests = false;
doSignatureUnitTests = false;
paramCount++;
}*/
else {
printUsage();
return 2;
}
}
#if defined (_DEBUG) && defined (_MSC_VER) && defined (_XSEC_DO_MEMDEBUG)
// Do some memory debugging under Visual C++
_CrtMemState s1, s2, s3;
// At this point we are about to start really using XSEC, so
// Take a "before" checkpoing
_CrtMemCheckpoint( &s1 );
#endif
// First initialise the XML system
try {
XMLPlatformUtils::Initialize();
#ifdef XSEC_HAVE_XALAN
XPathEvaluator::initialize();
XalanTransformer::initialize();
#endif
XSECPlatformUtils::Initialise();
#if defined (XSEC_HAVE_OPENSSL) && defined (XSEC_HAVE_WINCAPI)
if (g_useWinCAPI) {
// Setup for Windows Crypt API
WinCAPICryptoProvider * cp;
// First set windows as the crypto provider
cp = new WinCAPICryptoProvider();
XSECPlatformUtils::SetCryptoProvider(cp);
}
#endif
#if defined (XSEC_HAVE_NSS)
if (g_useNSS) {
// Setup for NSS Crypt API
NSSCryptoProvider * cp;
// First set windows as the crypto provider
cp = new NSSCryptoProvider();
XSECPlatformUtils::SetCryptoProvider(cp);
}
#endif
}
catch (const XMLException &e) {
cerr << "Error during initialisation of Xerces" << endl;
cerr << "Error Message = : "
<< e.getMessage() << endl;
}
{
// Set up for tests
g_haveAES = XSECPlatformUtils::g_cryptoProvider->algorithmSupported(XSECCryptoSymmetricKey::KEY_AES_128);
// Setup for building documents
XMLCh tempStr[100];
XMLString::transcode("Core", tempStr, 99);
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
// Output some info
char * provName = XMLString::transcode(XSECPlatformUtils::g_cryptoProvider->getProviderName());
cerr << "Crypto Provider string : " << provName << endl;
XSEC_RELEASE_XMLCH(provName);
// Test signature functions
if (doSignatureTest) {
cerr << endl << "====================================";
cerr << endl << "Testing Signature Function";
cerr << endl << "====================================";
cerr << endl << endl;
testSignature(impl);
}
// Test signature functions
if (doSignatureUnitTests) {
cerr << endl << "====================================";
cerr << endl << "Performing Signature Unit Tests";
cerr << endl << "====================================";
cerr << endl << endl;
unitTestSignature(impl);
}
// Test encrypt function
if (doEncryptionTest) {
cerr << endl << "====================================";
cerr << endl << "Testing Encryption Function";
cerr << endl << "====================================";
cerr << endl << endl;
testEncrypt(impl);
}
// Running Encryption Unit test
if (doEncryptionUnitTests) {
cerr << endl << "====================================";
cerr << endl << "Performing Encryption Unit Tests";
cerr << endl << "====================================";
cerr << endl << endl;
unitTestEncrypt(impl);
}
cerr << endl << "All tests passed" << endl;
}
XSECPlatformUtils::Terminate();
#ifdef XSEC_HAVE_XALAN
XalanTransformer::terminate();
XPathEvaluator::terminate();
#endif
XMLPlatformUtils::Terminate();
#if defined (_DEBUG) && defined (_MSC_VER) && defined (_XSEC_DO_MEMDEBUG)
_CrtMemCheckpoint( &s2 );
if ( _CrtMemDifference( &s3, &s1, &s2 ) && (
s3.lCounts[0] > 0 ||
s3.lCounts[1] > 1 ||
// s3.lCounts[2] > 2 || We don't worry about C Runtime
s3.lCounts[3] > 0 ||
s3.lCounts[4] > 0)) {
// Note that there is generally 1 Normal and 1 CRT block
// still taken. 1 is from Xalan and 1 from stdio
// Send all reports to STDOUT
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
// Dumpy memory stats
_CrtMemDumpAllObjectsSince( &s3 );
_CrtMemDumpStatistics( &s3 );
}
// Now turn off memory leak checking and end as there are some
// Globals that are allocated that get seen as leaks (Xalan?)
int dbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
dbgFlag &= ~(_CRTDBG_LEAK_CHECK_DF);
_CrtSetDbgFlag( dbgFlag );
#endif
return 0;
}