2
0

Abort CLI if master password doesn't match.

This commit is contained in:
Maarten Billemont 2017-08-03 01:13:15 -04:00
parent 434d70ebff
commit 096919637f
2 changed files with 20 additions and 15 deletions

View File

@ -410,7 +410,7 @@ static MPMarshalledUser *mpw_marshall_read_flat(
return NULL; return NULL;
} }
if (keyID && !mpw_id_buf_equals( keyID, mpw_id_buf( masterKey, MPMasterKeySize ) )) { if (keyID && !mpw_id_buf_equals( keyID, mpw_id_buf( masterKey, MPMasterKeySize ) )) {
*error = (MPMarshallError){ MPMarshallErrorMasterPassword, "Incorrect master password for import file." }; *error = (MPMarshallError){ MPMarshallErrorMasterPassword, "Master password doesn't match key ID." };
return NULL; return NULL;
} }
if (!(user = mpw_marshall_user( fullName, masterPassword, algorithm ))) { if (!(user = mpw_marshall_user( fullName, masterPassword, algorithm ))) {
@ -586,7 +586,7 @@ static MPMarshalledUser *mpw_marshall_read_json(
return NULL; return NULL;
} }
if (keyID && !mpw_id_buf_equals( keyID, mpw_id_buf( masterKey, MPMasterKeySize ) )) { if (keyID && !mpw_id_buf_equals( keyID, mpw_id_buf( masterKey, MPMasterKeySize ) )) {
*error = (MPMarshallError){ MPMarshallErrorMasterPassword, "Incorrect master password for import file." }; *error = (MPMarshallError){ MPMarshallErrorMasterPassword, "Master password doesn't match key ID." };
return NULL; return NULL;
} }
if (!(user = mpw_marshall_user( fullName, masterPassword, algorithm ))) { if (!(user = mpw_marshall_user( fullName, masterPassword, algorithm ))) {

View File

@ -155,20 +155,20 @@ int main(int argc, char *const argv[]) {
switch (optopt) { switch (optopt) {
case 'u': case 'u':
ftl( "Missing full name to option: -%c\n", optopt ); ftl( "Missing full name to option: -%c\n", optopt );
abort(); return 1;
case 't': case 't':
ftl( "Missing type name to option: -%c\n", optopt ); ftl( "Missing type name to option: -%c\n", optopt );
abort(); return 1;
case 'c': case 'c':
ftl( "Missing counter value to option: -%c\n", optopt ); ftl( "Missing counter value to option: -%c\n", optopt );
abort(); return 1;
default: default:
ftl( "Unknown option: -%c\n", optopt ); ftl( "Unknown option: -%c\n", optopt );
abort(); return 1;
} }
default: default:
ftl( "Unexpected option: %c", opt ); ftl( "Unexpected option: %c", opt );
abort(); return 1;
} }
if (optind < argc) if (optind < argc)
siteNameArg = argv[optind]; siteNameArg = argv[optind];
@ -187,12 +187,12 @@ int main(int argc, char *const argv[]) {
if (!(fullNameArg && (fullName = strdup( fullNameArg ))) && if (!(fullNameArg && (fullName = strdup( fullNameArg ))) &&
!(fullName = getline_prompt( "Your full name:" ))) { !(fullName = getline_prompt( "Your full name:" ))) {
ftl( "Missing full name.\n" ); ftl( "Missing full name.\n" );
abort(); return 1;
} }
if (!(siteNameArg && (siteName = strdup( siteNameArg ))) && if (!(siteNameArg && (siteName = strdup( siteNameArg ))) &&
!(siteName = getline_prompt( "Site name:" ))) { !(siteName = getline_prompt( "Site name:" ))) {
ftl( "Missing site name.\n" ); ftl( "Missing site name.\n" );
abort(); return 1;
} }
if (!(masterPasswordArg && (masterPassword = strdup( masterPasswordArg )))) if (!(masterPasswordArg && (masterPassword = strdup( masterPasswordArg ))))
while (!masterPassword || !strlen( masterPassword )) while (!masterPassword || !strlen( masterPassword ))
@ -226,8 +226,13 @@ int main(int argc, char *const argv[]) {
MPMarshallError marshallError = { MPMarshallSuccess }; MPMarshallError marshallError = { MPMarshallSuccess };
MPMarshalledUser *user = mpw_marshall_read( buf, mpwSitesFormat, masterPassword, &marshallError ); MPMarshalledUser *user = mpw_marshall_read( buf, mpwSitesFormat, masterPassword, &marshallError );
mpw_free_string( buf ); mpw_free_string( buf );
if (!user || marshallError.type != MPMarshallSuccess) if (!user || marshallError.type != MPMarshallSuccess) {
wrn( "Couldn't parse configuration file:\n %s: %s\n", mpwSitesPath, marshallError.description ); if (marshallError.type == MPMarshallErrorMasterPassword) {
ftl( "Incorrect master password according to configuration:\n %s: %s\n", mpwSitesPath, marshallError.description );
return 1;
} else
err( "Couldn't parse configuration file:\n %s: %s\n", mpwSitesPath, marshallError.description );
}
else { else {
// Load defaults. // Load defaults.
@ -275,7 +280,7 @@ int main(int argc, char *const argv[]) {
int algorithmVersionInt = atoi( algorithmVersionArg ); int algorithmVersionInt = atoi( algorithmVersionArg );
if (algorithmVersionInt < MPAlgorithmVersionFirst || algorithmVersionInt > MPAlgorithmVersionLast) { if (algorithmVersionInt < MPAlgorithmVersionFirst || algorithmVersionInt > MPAlgorithmVersionLast) {
ftl( "Invalid algorithm version: %s\n", algorithmVersionArg ); ftl( "Invalid algorithm version: %s\n", algorithmVersionArg );
abort(); return 1;
} }
algorithmVersion = (MPAlgorithmVersion)algorithmVersionInt; algorithmVersion = (MPAlgorithmVersion)algorithmVersionInt;
} }
@ -283,7 +288,7 @@ int main(int argc, char *const argv[]) {
long long int siteCounterInt = atoll( siteCounterArg ); long long int siteCounterInt = atoll( siteCounterArg );
if (siteCounterInt < 0 || siteCounterInt > UINT32_MAX) { if (siteCounterInt < 0 || siteCounterInt > UINT32_MAX) {
ftl( "Invalid site counter: %s\n", siteCounterArg ); ftl( "Invalid site counter: %s\n", siteCounterArg );
abort(); return 1;
} }
siteCounter = (uint32_t)siteCounterInt; siteCounter = (uint32_t)siteCounterInt;
} }
@ -323,7 +328,7 @@ int main(int argc, char *const argv[]) {
mpw_free_string( fullName ); mpw_free_string( fullName );
if (!masterKey) { if (!masterKey) {
ftl( "Couldn't derive master key." ); ftl( "Couldn't derive master key." );
abort(); return 1;
} }
MPSiteKey siteKey = mpw_siteKey( masterKey, siteName, siteCounter, keyPurpose, keyContext, algorithmVersion ); MPSiteKey siteKey = mpw_siteKey( masterKey, siteName, siteCounter, keyPurpose, keyContext, algorithmVersion );
@ -334,7 +339,7 @@ int main(int argc, char *const argv[]) {
mpw_free_string( keyContext ); mpw_free_string( keyContext );
if (!sitePassword) { if (!sitePassword) {
ftl( "Couldn't derive site password." ); ftl( "Couldn't derive site password." );
abort(); return 1;
} }
fprintf( stdout, "%s\n", sitePassword ); fprintf( stdout, "%s\n", sitePassword );