2
0

mpw-tests was not checking mpw_tests.xml's keyID.

This commit is contained in:
Maarten Billemont 2017-09-22 18:23:08 -04:00
parent 34540f0844
commit dc7089c38c

View File

@ -57,40 +57,51 @@ int main(int argc, char *const argv[]) {
MPKeyPurpose keyPurpose = mpw_purposeWithName( (char *)keyPurposeString ); MPKeyPurpose keyPurpose = mpw_purposeWithName( (char *)keyPurposeString );
// Run the test case. // Run the test case.
fprintf( stdout, "test case %s... ", id ); do {
if (!xmlStrlen( result )) { fprintf( stdout, "test case %s... ", id );
fprintf( stdout, "abstract.\n" ); if (!xmlStrlen( result )) {
continue; fprintf( stdout, "abstract.\n" );
} continue;
}
// 1. calculate the master key. // 1. calculate the master key.
MPMasterKey masterKey = mpw_masterKey( MPMasterKey masterKey = mpw_masterKey(
(char *)fullName, (char *)masterPassword, algorithm ); (char *)fullName, (char *)masterPassword, algorithm );
if (!masterKey) { if (!masterKey) {
ftl( "Couldn't derive master key.\n" ); ftl( "Couldn't derive master key.\n" );
continue; abort();
} }
// 2. calculate the site password. // Check the master key.
const char *sitePassword = mpw_siteResult( MPKeyID testKeyID = mpw_id_buf( masterKey, MPMasterKeySize );
masterKey, (char *)siteName, siteCounter, keyPurpose, (char *)keyContext, resultType, NULL, algorithm ); if (xmlStrcmp( keyID, BAD_CAST testKeyID ) != 0) {
mpw_free( &masterKey, MPMasterKeySize ); ++failedTests;
if (!sitePassword) { fprintf( stdout, "FAILED! (keyID: got %s != expected %s)\n", testKeyID, keyID );
ftl( "Couldn't derive site password.\n" ); continue;
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" ); fprintf( stdout, "pass.\n" );
} while(false);
else {
++failedTests;
fprintf( stdout, "FAILED! (got %s != expected %s)\n", sitePassword, result );
}
// Free test case. // Free test case.
mpw_free_string( &sitePassword );
xmlFree( id ); xmlFree( id );
xmlFree( fullName ); xmlFree( fullName );
xmlFree( masterPassword ); xmlFree( masterPassword );