2
0

Present site details.

This commit is contained in:
Maarten Billemont 2018-10-29 19:00:07 +01:00
parent 14387a2310
commit 98d0d7a497
5 changed files with 57 additions and 21 deletions

View File

@ -238,7 +238,7 @@ int main(const int argc, char *const argv[]) {
if (operation.site) { if (operation.site) {
dbg( "siteName : %s", operation.site->name ); dbg( "siteName : %s", operation.site->name );
dbg( "siteCounter : %u", operation.siteCounter ); dbg( "siteCounter : %u", operation.siteCounter );
dbg( "resultType : %s (%u)", mpw_nameForType( operation.resultType ), operation.resultType ); dbg( "resultType : %s (%u)", mpw_shortNameForType( operation.resultType ), operation.resultType );
dbg( "resultParam : %s", operation.resultParam ); dbg( "resultParam : %s", operation.resultParam );
dbg( "keyPurpose : %s (%u)", mpw_nameForPurpose( operation.keyPurpose ), operation.keyPurpose ); dbg( "keyPurpose : %s (%u)", mpw_nameForPurpose( operation.keyPurpose ), operation.keyPurpose );
dbg( "keyContext : %s", operation.keyContext ); dbg( "keyContext : %s", operation.keyContext );

View File

@ -96,7 +96,7 @@ const char *mpw_siteResult(
return NULL; return NULL;
trc( "-- mpw_siteResult (algorithm: %u)", algorithmVersion ); trc( "-- mpw_siteResult (algorithm: %u)", algorithmVersion );
trc( "resultType: %d (%s)", resultType, mpw_nameForType( resultType ) ); trc( "resultType: %d (%s)", resultType, mpw_shortNameForType( resultType ) );
trc( "resultParam: %s", resultParam ); trc( "resultParam: %s", resultParam );
char *sitePassword = NULL; char *sitePassword = NULL;
@ -168,7 +168,7 @@ const char *mpw_siteState(
return NULL; return NULL;
trc( "-- mpw_siteState (algorithm: %u)", algorithmVersion ); trc( "-- mpw_siteState (algorithm: %u)", algorithmVersion );
trc( "resultType: %d (%s)", resultType, mpw_nameForType( resultType ) ); trc( "resultType: %d (%s)", resultType, mpw_shortNameForType( resultType ) );
trc( "resultParam: %zu bytes = %s", sizeof( resultParam ), resultParam ); trc( "resultParam: %zu bytes = %s", sizeof( resultParam ), resultParam );
if (!masterKey || !resultParam) if (!masterKey || !resultParam)
return NULL; return NULL;

View File

@ -482,7 +482,7 @@ static MPMarshalledUser *mpw_marshal_read_flat(
} }
if (strcmp( headerName, "Default Type" ) == 0) { if (strcmp( headerName, "Default Type" ) == 0) {
int value = atoi( headerValue ); int value = atoi( headerValue );
if (!mpw_nameForType( (MPResultType)value )) { if (!mpw_shortNameForType( (MPResultType)value )) {
*error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid user default type: %s", headerValue ) }; *error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid user default type: %s", headerValue ) };
return NULL; return NULL;
} }
@ -564,7 +564,7 @@ static MPMarshalledUser *mpw_marshal_read_flat(
if (siteName && str_type && str_counter && str_algorithm && str_uses && str_lastUsed) { if (siteName && str_type && str_counter && str_algorithm && str_uses && str_lastUsed) {
MPResultType siteType = (MPResultType)atoi( str_type ); MPResultType siteType = (MPResultType)atoi( str_type );
if (!mpw_nameForType( siteType )) { if (!mpw_shortNameForType( siteType )) {
*error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid site type: %s: %s", siteName, str_type ) }; *error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid site type: %s: %s", siteName, str_type ) };
return NULL; return NULL;
} }
@ -703,7 +703,7 @@ static MPMarshalledUser *mpw_marshal_read_json(
} }
MPAlgorithmVersion algorithm = (MPAlgorithmVersion)value; MPAlgorithmVersion algorithm = (MPAlgorithmVersion)value;
MPResultType defaultType = (MPResultType)mpw_get_json_int( json_file, "user.default_type", MPResultTypeDefault ); MPResultType defaultType = (MPResultType)mpw_get_json_int( json_file, "user.default_type", MPResultTypeDefault );
if (!mpw_nameForType( defaultType )) { if (!mpw_shortNameForType( defaultType )) {
*error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid user default type: %u", defaultType ) }; *error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid user default type: %u", defaultType ) };
return NULL; return NULL;
} }
@ -745,7 +745,7 @@ static MPMarshalledUser *mpw_marshal_read_json(
} }
MPAlgorithmVersion siteAlgorithm = (MPAlgorithmVersion)value; MPAlgorithmVersion siteAlgorithm = (MPAlgorithmVersion)value;
MPResultType siteType = (MPResultType)mpw_get_json_int( json_site.val, "type", (int32_t)user->defaultType ); MPResultType siteType = (MPResultType)mpw_get_json_int( json_site.val, "type", (int32_t)user->defaultType );
if (!mpw_nameForType( siteType )) { if (!mpw_shortNameForType( siteType )) {
*error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid site type: %s: %u", siteName, siteType ) }; *error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid site type: %s: %u", siteName, siteType ) };
return NULL; return NULL;
} }

View File

@ -54,34 +54,34 @@ const MPResultType mpw_typeWithName(const char *typeName) {
} }
// Find what password type is represented by the type name. // Find what password type is represented by the type name.
if (mpw_strncasecmp( mpw_nameForType( MPResultTypeTemplateMaximum ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateMaximum ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplateMaximum; return MPResultTypeTemplateMaximum;
if (mpw_strncasecmp( mpw_nameForType( MPResultTypeTemplateLong ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateLong ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplateLong; return MPResultTypeTemplateLong;
if (mpw_strncasecmp( mpw_nameForType( MPResultTypeTemplateMedium ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateMedium ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplateMedium; return MPResultTypeTemplateMedium;
if (mpw_strncasecmp( mpw_nameForType( MPResultTypeTemplateBasic ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateBasic ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplateBasic; return MPResultTypeTemplateBasic;
if (mpw_strncasecmp( mpw_nameForType( MPResultTypeTemplateShort ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateShort ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplateShort; return MPResultTypeTemplateShort;
if (mpw_strncasecmp( mpw_nameForType( MPResultTypeTemplatePIN ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplatePIN ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplatePIN; return MPResultTypeTemplatePIN;
if (mpw_strncasecmp( mpw_nameForType( MPResultTypeTemplateName ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplateName ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplateName; return MPResultTypeTemplateName;
if (mpw_strncasecmp( mpw_nameForType( MPResultTypeTemplatePhrase ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeTemplatePhrase ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeTemplatePhrase; return MPResultTypeTemplatePhrase;
if (mpw_strncasecmp( mpw_nameForType( MPResultTypeStatefulPersonal ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeStatefulPersonal ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeStatefulPersonal; return MPResultTypeStatefulPersonal;
if (mpw_strncasecmp( mpw_nameForType( MPResultTypeStatefulDevice ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeStatefulDevice ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeStatefulDevice; return MPResultTypeStatefulDevice;
if (mpw_strncasecmp( mpw_nameForType( MPResultTypeDeriveKey ), typeName, strlen( typeName ) ) == 0) if (mpw_strncasecmp( mpw_shortNameForType( MPResultTypeDeriveKey ), typeName, strlen( typeName ) ) == 0)
return MPResultTypeDeriveKey; return MPResultTypeDeriveKey;
dbg( "Not a generated type name: %s", typeName ); dbg( "Not a generated type name: %s", typeName );
return (MPResultType)ERR; return (MPResultType)ERR;
} }
const char *mpw_nameForType(MPResultType resultType) { const char *mpw_shortNameForType(MPResultType resultType) {
switch (resultType) { switch (resultType) {
case MPResultTypeTemplateMaximum: case MPResultTypeTemplateMaximum:
@ -113,6 +113,38 @@ const char *mpw_nameForType(MPResultType resultType) {
} }
} }
const char *mpw_longNameForType(MPResultType resultType) {
switch (resultType) {
case MPResultTypeTemplateMaximum:
return "Maximum Security Password";
case MPResultTypeTemplateLong:
return "Long Password";
case MPResultTypeTemplateMedium:
return "Medium Password";
case MPResultTypeTemplateBasic:
return "Basic Password";
case MPResultTypeTemplateShort:
return "Short Password";
case MPResultTypeTemplatePIN:
return "PIN";
case MPResultTypeTemplateName:
return "Name";
case MPResultTypeTemplatePhrase:
return "Phrase";
case MPResultTypeStatefulPersonal:
return "Personal Password";
case MPResultTypeStatefulDevice:
return "Device Private Password";
case MPResultTypeDeriveKey:
return "Crypto Key";
default: {
dbg( "Unknown password type: %d", resultType );
return NULL;
}
}
}
const char **mpw_templatesForType(MPResultType type, size_t *count) { const char **mpw_templatesForType(MPResultType type, size_t *count) {
if (!(type & MPResultTypeClassTemplate)) { if (!(type & MPResultTypeClassTemplate)) {

View File

@ -147,9 +147,13 @@ const char *mpw_scopeForPurpose(MPKeyPurpose purpose);
*/ */
const MPResultType mpw_typeWithName(const char *typeName); const MPResultType mpw_typeWithName(const char *typeName);
/** /**
* @return The standard name for the given password type. * @return The standard identifying name for the given password type.
*/ */
const char *mpw_nameForType(MPResultType resultType); const char *mpw_shortNameForType(MPResultType resultType);
/**
* @return The descriptive name for the given password type.
*/
const char *mpw_longNameForType(MPResultType resultType);
/** /**
* @return A newly allocated array of internal strings that express the templates to use for the given type. * @return A newly allocated array of internal strings that express the templates to use for the given type.