From dc7089c38c83902943958aacfc592dc47b0eb62c Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Fri, 22 Sep 2017 18:23:08 -0400 Subject: [PATCH] mpw-tests was not checking mpw_tests.xml's keyID. --- platform-independent/cli-c/cli/mpw-tests.c | 67 +++++++++++++--------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/platform-independent/cli-c/cli/mpw-tests.c b/platform-independent/cli-c/cli/mpw-tests.c index 00223093..4124fc96 100644 --- a/platform-independent/cli-c/cli/mpw-tests.c +++ b/platform-independent/cli-c/cli/mpw-tests.c @@ -57,40 +57,51 @@ int main(int argc, char *const argv[]) { MPKeyPurpose keyPurpose = mpw_purposeWithName( (char *)keyPurposeString ); // Run the test case. - fprintf( stdout, "test case %s... ", id ); - if (!xmlStrlen( result )) { - fprintf( stdout, "abstract.\n" ); - continue; - } + do { + fprintf( stdout, "test case %s... ", id ); + if (!xmlStrlen( result )) { + fprintf( stdout, "abstract.\n" ); + continue; + } - // 1. calculate the master key. - MPMasterKey masterKey = mpw_masterKey( - (char *)fullName, (char *)masterPassword, algorithm ); - if (!masterKey) { - ftl( "Couldn't derive master key.\n" ); - continue; - } + // 1. calculate the master key. + MPMasterKey masterKey = mpw_masterKey( + (char *)fullName, (char *)masterPassword, algorithm ); + if (!masterKey) { + ftl( "Couldn't derive master key.\n" ); + abort(); + } - // 2. calculate the site password. - const char *sitePassword = mpw_siteResult( - masterKey, (char *)siteName, siteCounter, keyPurpose, (char *)keyContext, resultType, NULL, algorithm ); - mpw_free( &masterKey, MPMasterKeySize ); - if (!sitePassword) { - ftl( "Couldn't derive site password.\n" ); - continue; - } + // Check the master key. + MPKeyID testKeyID = mpw_id_buf( masterKey, MPMasterKeySize ); + if (xmlStrcmp( keyID, BAD_CAST testKeyID ) != 0) { + ++failedTests; + fprintf( stdout, "FAILED! (keyID: got %s != expected %s)\n", testKeyID, keyID ); + continue; + } + + // 2. calculate the site password. + const char *testResult = mpw_siteResult( + masterKey, (char *)siteName, siteCounter, keyPurpose, (char *)keyContext, resultType, NULL, algorithm ); + mpw_free( &masterKey, MPMasterKeySize ); + if (!testResult) { + ftl( "Couldn't derive site password.\n" ); + continue; + } + + // Check the site result. + if (xmlStrcmp( result, BAD_CAST testResult ) != 0) { + ++failedTests; + fprintf( stdout, "FAILED! (result: got %s != expected %s)\n", testResult, result ); + mpw_free_string( &testResult ); + continue; + } + mpw_free_string( &testResult ); - // Check the result. - if (xmlStrcmp( result, BAD_CAST sitePassword ) == 0) fprintf( stdout, "pass.\n" ); - - else { - ++failedTests; - fprintf( stdout, "FAILED! (got %s != expected %s)\n", sitePassword, result ); - } + } while(false); // Free test case. - mpw_free_string( &sitePassword ); xmlFree( id ); xmlFree( fullName ); xmlFree( masterPassword );