Render error messages as strings instead of internal codes.
This commit is contained in:
@@ -58,7 +58,7 @@ static MPMasterKey mpw_masterKeyForUser_v0(const char *fullName, const char *mas
|
||||
mpw_push_int( &masterKeySalt, &masterKeySaltSize, htonl( mpw_utf8_strlen( fullName ) ) );
|
||||
mpw_push_string( &masterKeySalt, &masterKeySaltSize, fullName );
|
||||
if (!masterKeySalt) {
|
||||
ftl( "Could not allocate master key salt: %d\n", errno );
|
||||
ftl( "Could not allocate master key salt: %s\n", strerror( errno ) );
|
||||
return NULL;
|
||||
}
|
||||
trc( "masterKeySalt ID: %s\n", mpw_id_buf( masterKeySalt, masterKeySaltSize ) );
|
||||
@@ -68,7 +68,7 @@ static MPMasterKey mpw_masterKeyForUser_v0(const char *fullName, const char *mas
|
||||
const uint8_t *masterKey = mpw_scrypt( MPMasterKeySize, masterPassword, masterKeySalt, masterKeySaltSize, MP_N, MP_r, MP_p );
|
||||
mpw_free( masterKeySalt, masterKeySaltSize );
|
||||
if (!masterKey) {
|
||||
ftl( "Could not allocate master key: %d\n", errno );
|
||||
ftl( "Could not allocate master key: %s\n", strerror( errno ) );
|
||||
return NULL;
|
||||
}
|
||||
trc( "masterKey ID: %s\n", mpw_id_buf( masterKey, MPMasterKeySize ) );
|
||||
@@ -104,7 +104,7 @@ static MPSiteKey mpw_siteKey_v0(
|
||||
mpw_push_string( &siteSalt, &siteSaltSize, keyContext );
|
||||
}
|
||||
if (!siteSalt || !siteSaltSize) {
|
||||
ftl( "Could not allocate site salt: %d\n", errno );
|
||||
ftl( "Could not allocate site salt: %s\n", strerror( errno ) );
|
||||
mpw_free( siteSalt, siteSaltSize );
|
||||
return NULL;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ static MPSiteKey mpw_siteKey_v0(
|
||||
MPSiteKey siteKey = mpw_hmac_sha256( masterKey, MPMasterKeySize, siteSalt, siteSaltSize );
|
||||
mpw_free( siteSalt, siteSaltSize );
|
||||
if (!siteKey) {
|
||||
ftl( "Could not allocate site key: %d\n", errno );
|
||||
ftl( "Could not allocate site key: %s\n", strerror( errno ) );
|
||||
return NULL;
|
||||
}
|
||||
trc( "siteKey ID: %s\n", mpw_id_buf( siteKey, MPSiteKeySize ) );
|
||||
|
@@ -43,7 +43,7 @@ static MPMasterKey mpw_masterKeyForUser_v1(const char *fullName, const char *mas
|
||||
mpw_push_int( &masterKeySalt, &masterKeySaltSize, htonl( mpw_utf8_strlen( fullName ) ) );
|
||||
mpw_push_string( &masterKeySalt, &masterKeySaltSize, fullName );
|
||||
if (!masterKeySalt) {
|
||||
ftl( "Could not allocate master key salt: %d\n", errno );
|
||||
ftl( "Could not allocate master key salt: %s\n", strerror( errno ) );
|
||||
return NULL;
|
||||
}
|
||||
trc( "masterKeySalt ID: %s\n", mpw_id_buf( masterKeySalt, masterKeySaltSize ) );
|
||||
@@ -53,7 +53,7 @@ static MPMasterKey mpw_masterKeyForUser_v1(const char *fullName, const char *mas
|
||||
MPMasterKey masterKey = mpw_scrypt( MPMasterKeySize, masterPassword, masterKeySalt, masterKeySaltSize, MP_N, MP_r, MP_p );
|
||||
mpw_free( masterKeySalt, masterKeySaltSize );
|
||||
if (!masterKey) {
|
||||
ftl( "Could not allocate master key: %d\n", errno );
|
||||
ftl( "Could not allocate master key: %s\n", strerror( errno ) );
|
||||
return NULL;
|
||||
}
|
||||
trc( "masterKey ID: %s\n", mpw_id_buf( masterKey, MPMasterKeySize ) );
|
||||
@@ -89,7 +89,7 @@ static MPSiteKey mpw_siteKey_v1(
|
||||
mpw_push_string( &siteSalt, &siteSaltSize, keyContext );
|
||||
}
|
||||
if (!siteSalt || !siteSaltSize) {
|
||||
ftl( "Could not allocate site salt: %d\n", errno );
|
||||
ftl( "Could not allocate site salt: %s\n", strerror( errno ) );
|
||||
mpw_free( siteSalt, siteSaltSize );
|
||||
return NULL;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ static MPSiteKey mpw_siteKey_v1(
|
||||
MPSiteKey siteKey = mpw_hmac_sha256( masterKey, MPMasterKeySize, siteSalt, siteSaltSize );
|
||||
mpw_free( siteSalt, siteSaltSize );
|
||||
if (!siteKey) {
|
||||
ftl( "Could not allocate site key: %d\n", errno );
|
||||
ftl( "Could not allocate site key: %s\n", strerror( errno ) );
|
||||
return NULL;
|
||||
}
|
||||
trc( "siteKey ID: %s\n", mpw_id_buf( siteKey, MPSiteKeySize ) );
|
||||
|
@@ -43,7 +43,7 @@ static MPMasterKey mpw_masterKeyForUser_v2(const char *fullName, const char *mas
|
||||
mpw_push_int( &masterKeySalt, &masterKeySaltSize, htonl( mpw_utf8_strlen( fullName ) ) );
|
||||
mpw_push_string( &masterKeySalt, &masterKeySaltSize, fullName );
|
||||
if (!masterKeySalt) {
|
||||
ftl( "Could not allocate master key salt: %d\n", errno );
|
||||
ftl( "Could not allocate master key salt: %s\n", strerror( errno ) );
|
||||
return NULL;
|
||||
}
|
||||
trc( "masterKeySalt ID: %s\n", mpw_id_buf( masterKeySalt, masterKeySaltSize ) );
|
||||
@@ -53,7 +53,7 @@ static MPMasterKey mpw_masterKeyForUser_v2(const char *fullName, const char *mas
|
||||
const uint8_t *masterKey = mpw_scrypt( MPMasterKeySize, masterPassword, masterKeySalt, masterKeySaltSize, MP_N, MP_r, MP_p );
|
||||
mpw_free( masterKeySalt, masterKeySaltSize );
|
||||
if (!masterKey) {
|
||||
ftl( "Could not allocate master key: %d\n", errno );
|
||||
ftl( "Could not allocate master key: %s\n", strerror( errno ) );
|
||||
return NULL;
|
||||
}
|
||||
trc( "masterKey ID: %s\n", mpw_id_buf( masterKey, MPMasterKeySize ) );
|
||||
@@ -89,7 +89,7 @@ static MPSiteKey mpw_siteKey_v2(
|
||||
mpw_push_string( &siteSalt, &siteSaltSize, keyContext );
|
||||
}
|
||||
if (!siteSalt || !siteSaltSize) {
|
||||
ftl( "Could not allocate site salt: %d\n", errno );
|
||||
ftl( "Could not allocate site salt: %s\n", strerror( errno ) );
|
||||
mpw_free( siteSalt, siteSaltSize );
|
||||
return NULL;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ static MPSiteKey mpw_siteKey_v2(
|
||||
const uint8_t *siteKey = mpw_hmac_sha256( masterKey, MPMasterKeySize, siteSalt, siteSaltSize );
|
||||
mpw_free( siteSalt, siteSaltSize );
|
||||
if (!siteKey) {
|
||||
ftl( "Could not allocate site key: %d\n", errno );
|
||||
ftl( "Could not allocate site key: %s\n", strerror( errno ) );
|
||||
return NULL;
|
||||
}
|
||||
trc( "siteKey ID: %s\n", mpw_id_buf( siteKey, MPSiteKeySize ) );
|
||||
|
@@ -43,7 +43,7 @@ static MPMasterKey mpw_masterKeyForUser_v3(const char *fullName, const char *mas
|
||||
mpw_push_int( &masterKeySalt, &masterKeySaltSize, htonl( strlen( fullName ) ) );
|
||||
mpw_push_string( &masterKeySalt, &masterKeySaltSize, fullName );
|
||||
if (!masterKeySalt) {
|
||||
ftl( "Could not allocate master key salt: %d\n", errno );
|
||||
ftl( "Could not allocate master key salt: %s\n", strerror( errno ) );
|
||||
return NULL;
|
||||
}
|
||||
trc( "masterKeySalt ID: %s\n", mpw_id_buf( masterKeySalt, masterKeySaltSize ) );
|
||||
@@ -53,7 +53,7 @@ static MPMasterKey mpw_masterKeyForUser_v3(const char *fullName, const char *mas
|
||||
const uint8_t *masterKey = mpw_scrypt( MPMasterKeySize, masterPassword, masterKeySalt, masterKeySaltSize, MP_N, MP_r, MP_p );
|
||||
mpw_free( masterKeySalt, masterKeySaltSize );
|
||||
if (!masterKey) {
|
||||
ftl( "Could not allocate master key: %d\n", errno );
|
||||
ftl( "Could not allocate master key: %s\n", strerror( errno ) );
|
||||
return NULL;
|
||||
}
|
||||
trc( "masterKey ID: %s\n", mpw_id_buf( masterKey, MPMasterKeySize ) );
|
||||
@@ -89,7 +89,7 @@ static MPSiteKey mpw_siteKey_v3(
|
||||
mpw_push_string( &siteSalt, &siteSaltSize, keyContext );
|
||||
}
|
||||
if (!siteSalt) {
|
||||
ftl( "Could not allocate site salt: %d\n", errno );
|
||||
ftl( "Could not allocate site salt: %s\n", strerror( errno ) );
|
||||
return NULL;
|
||||
}
|
||||
trc( "siteSalt ID: %s\n", mpw_id_buf( siteSalt, siteSaltSize ) );
|
||||
@@ -97,7 +97,7 @@ static MPSiteKey mpw_siteKey_v3(
|
||||
MPSiteKey siteKey = mpw_hmac_sha256( masterKey, MPMasterKeySize, siteSalt, siteSaltSize );
|
||||
mpw_free( siteSalt, siteSaltSize );
|
||||
if (!siteKey || !siteSaltSize) {
|
||||
ftl( "Could not allocate site key: %d\n", errno );
|
||||
ftl( "Could not allocate site key: %s\n", strerror( errno ) );
|
||||
mpw_free( siteSalt, siteSaltSize );
|
||||
return NULL;
|
||||
}
|
||||
|
@@ -662,3 +662,24 @@ MPMarshalledUser *mpw_marshall_read(
|
||||
*error = MPMarshallErrorFormat;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *mpw_explainMarshallError(const MPMarshallError error) {
|
||||
switch (error) {
|
||||
case MPMarshallSuccess:
|
||||
return "The marshalling operation completed successfully.";
|
||||
case MPMarshallErrorStructure:
|
||||
return "An error in the structure of the marshall file interrupted marshalling.";
|
||||
case MPMarshallErrorFormat:
|
||||
return "The marshall file uses an unsupported format version.";
|
||||
case MPMarshallErrorMissing:
|
||||
return "A required value is missing or not specified.";
|
||||
case MPMarshallErrorMasterPassword:
|
||||
return "The given master password is not valid.";
|
||||
case MPMarshallErrorIllegal:
|
||||
return "An illegal value was specified.";
|
||||
case MPMarshallErrorInternal:
|
||||
return "An internal system error interrupted marshalling.";
|
||||
}
|
||||
|
||||
return "An unrecognized error occurred.";
|
||||
}
|
||||
|
@@ -48,6 +48,7 @@ typedef enum( unsigned int, MPMarshallError ) {
|
||||
/** An internal system error interrupted marshalling. */
|
||||
MPMarshallErrorInternal,
|
||||
};
|
||||
const char *mpw_explainMarshallError(const MPMarshallError error);
|
||||
|
||||
typedef struct MPMarshalledQuestion {
|
||||
const char *keyword;
|
||||
|
Reference in New Issue
Block a user