Expose standard names for password type and purpose, and log them in the cli.
This commit is contained in:
parent
9d5105a9e5
commit
46cdf56944
@ -42,27 +42,65 @@ const MPPasswordType mpw_typeWithName(const char *typeName) {
|
|||||||
stdTypeName[stdTypeNameSize] = '\0';
|
stdTypeName[stdTypeNameSize] = '\0';
|
||||||
|
|
||||||
// Find what password type is represented by the type name.
|
// Find what password type is represented by the type name.
|
||||||
if (0 == strncmp( "maximum", stdTypeName, strlen( stdTypeName ) ) || 0 == strncmp( "x", stdTypeName, 1 ))
|
if (0 == strncmp( "x", stdTypeName, 1 )
|
||||||
|
|| strncmp( mpw_nameForType( MPPasswordTypeGeneratedMaximum ), stdTypeName, strlen( stdTypeName ) ) == 0)
|
||||||
return MPPasswordTypeGeneratedMaximum;
|
return MPPasswordTypeGeneratedMaximum;
|
||||||
if (0 == strncmp( "long", stdTypeName, strlen( stdTypeName ) ) || 0 == strncmp( "l", stdTypeName, 1 ))
|
if (0 == strncmp( "l", stdTypeName, 1 )
|
||||||
|
|| strncmp( mpw_nameForType( MPPasswordTypeGeneratedLong ), stdTypeName, strlen( stdTypeName ) ) == 0)
|
||||||
return MPPasswordTypeGeneratedLong;
|
return MPPasswordTypeGeneratedLong;
|
||||||
if (0 == strncmp( "medium", stdTypeName, strlen( stdTypeName ) ) || 0 == strncmp( "m", stdTypeName, 1 ))
|
if (0 == strncmp( "m", stdTypeName, 1 )
|
||||||
|
|| strncmp( mpw_nameForType( MPPasswordTypeGeneratedMedium ), stdTypeName, strlen( stdTypeName ) ) == 0)
|
||||||
return MPPasswordTypeGeneratedMedium;
|
return MPPasswordTypeGeneratedMedium;
|
||||||
if (0 == strncmp( "basic", stdTypeName, strlen( stdTypeName ) ) || 0 == strncmp( "b", stdTypeName, 1 ))
|
if (0 == strncmp( "b", stdTypeName, 1 )
|
||||||
|
|| strncmp( mpw_nameForType( MPPasswordTypeGeneratedBasic ), stdTypeName, strlen( stdTypeName ) ) == 0)
|
||||||
return MPPasswordTypeGeneratedBasic;
|
return MPPasswordTypeGeneratedBasic;
|
||||||
if (0 == strncmp( "short", stdTypeName, strlen( stdTypeName ) ) || 0 == strncmp( "s", stdTypeName, 1 ))
|
if (0 == strncmp( "s", stdTypeName, 1 )
|
||||||
|
|| strncmp( mpw_nameForType( MPPasswordTypeGeneratedShort ), stdTypeName, strlen( stdTypeName ) ) == 0)
|
||||||
return MPPasswordTypeGeneratedShort;
|
return MPPasswordTypeGeneratedShort;
|
||||||
if (0 == strncmp( "pin", stdTypeName, strlen( stdTypeName ) ) || 0 == strncmp( "i", stdTypeName, 1 ))
|
if (0 == strncmp( "i", stdTypeName, 1 )
|
||||||
|
|| strncmp( mpw_nameForType( MPPasswordTypeGeneratedPIN ), stdTypeName, strlen( stdTypeName ) ) == 0)
|
||||||
return MPPasswordTypeGeneratedPIN;
|
return MPPasswordTypeGeneratedPIN;
|
||||||
if (0 == strncmp( "name", stdTypeName, strlen( stdTypeName ) ) || 0 == strncmp( "n", stdTypeName, 1 ))
|
if (0 == strncmp( "n", stdTypeName, 1 )
|
||||||
|
|| strncmp( mpw_nameForType( MPPasswordTypeGeneratedName ), stdTypeName, strlen( stdTypeName ) ) == 0)
|
||||||
return MPPasswordTypeGeneratedName;
|
return MPPasswordTypeGeneratedName;
|
||||||
if (0 == strncmp( "phrase", stdTypeName, strlen( stdTypeName ) ) || 0 == strncmp( "p", stdTypeName, 1 ))
|
if (0 == strncmp( "p", stdTypeName, 1 )
|
||||||
|
|| strncmp( mpw_nameForType( MPPasswordTypeGeneratedPhrase ), stdTypeName, strlen( stdTypeName ) ) == 0)
|
||||||
return MPPasswordTypeGeneratedPhrase;
|
return MPPasswordTypeGeneratedPhrase;
|
||||||
|
|
||||||
ftl( "Not a generated type name: %s", stdTypeName );
|
ftl( "Not a generated type name: %s", stdTypeName );
|
||||||
return MPPasswordTypeDefault;
|
return MPPasswordTypeDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *mpw_nameForType(MPPasswordType passwordType) {
|
||||||
|
|
||||||
|
switch (passwordType) {
|
||||||
|
case MPPasswordTypeGeneratedMaximum:
|
||||||
|
return "maximum";
|
||||||
|
case MPPasswordTypeGeneratedLong:
|
||||||
|
return "long";
|
||||||
|
case MPPasswordTypeGeneratedMedium:
|
||||||
|
return "medium";
|
||||||
|
case MPPasswordTypeGeneratedBasic:
|
||||||
|
return "basic";
|
||||||
|
case MPPasswordTypeGeneratedShort:
|
||||||
|
return "short";
|
||||||
|
case MPPasswordTypeGeneratedPIN:
|
||||||
|
return "pin";
|
||||||
|
case MPPasswordTypeGeneratedName:
|
||||||
|
return "name";
|
||||||
|
case MPPasswordTypeGeneratedPhrase:
|
||||||
|
return "phrase";
|
||||||
|
case MPPasswordTypeStoredPersonal:
|
||||||
|
return "personal";
|
||||||
|
case MPPasswordTypeStoredDevice:
|
||||||
|
return "device";
|
||||||
|
default: {
|
||||||
|
ftl( "Unknown password type: %d", passwordType );
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const char **mpw_templatesForType(MPPasswordType type, size_t *count) {
|
const char **mpw_templatesForType(MPPasswordType type, size_t *count) {
|
||||||
|
|
||||||
if (!(type & MPPasswordTypeClassGenerated)) {
|
if (!(type & MPPasswordTypeClassGenerated)) {
|
||||||
@ -128,16 +166,32 @@ const MPKeyPurpose mpw_purposeWithName(const char *purposeName) {
|
|||||||
stdPurposeName[c] = (char)tolower( purposeName[c] );
|
stdPurposeName[c] = (char)tolower( purposeName[c] );
|
||||||
stdPurposeName[stdPurposeNameSize] = '\0';
|
stdPurposeName[stdPurposeNameSize] = '\0';
|
||||||
|
|
||||||
if (strncmp( "authentication", stdPurposeName, strlen( stdPurposeName ) ) == 0)
|
if (strncmp( mpw_nameForPurpose( MPKeyPurposeAuthentication ), stdPurposeName, strlen( stdPurposeName ) ) == 0)
|
||||||
return MPKeyPurposeAuthentication;
|
return MPKeyPurposeAuthentication;
|
||||||
if (strncmp( "identification", stdPurposeName, strlen( stdPurposeName ) ) == 0)
|
if (strncmp( mpw_nameForPurpose( MPKeyPurposeIdentification ), stdPurposeName, strlen( stdPurposeName ) ) == 0)
|
||||||
return MPKeyPurposeIdentification;
|
return MPKeyPurposeIdentification;
|
||||||
if (strncmp( "recovery", stdPurposeName, strlen( stdPurposeName ) ) == 0)
|
if (strncmp( mpw_nameForPurpose( MPKeyPurposeRecovery ), stdPurposeName, strlen( stdPurposeName ) ) == 0)
|
||||||
return MPKeyPurposeRecovery;
|
return MPKeyPurposeRecovery;
|
||||||
|
|
||||||
ftl( "Not a purpose name: %s", stdPurposeName );
|
ftl( "Not a purpose name: %s", stdPurposeName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *mpw_nameForPurpose(MPKeyPurpose purpose) {
|
||||||
|
|
||||||
|
switch (purpose) {
|
||||||
|
case MPKeyPurposeAuthentication:
|
||||||
|
return "authentication";
|
||||||
|
case MPKeyPurposeIdentification:
|
||||||
|
return "identification";
|
||||||
|
case MPKeyPurposeRecovery:
|
||||||
|
return "recovery";
|
||||||
|
default: {
|
||||||
|
ftl( "Unknown purpose: %d", purpose );
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const char *mpw_scopeForPurpose(MPKeyPurpose purpose) {
|
const char *mpw_scopeForPurpose(MPKeyPurpose purpose) {
|
||||||
|
|
||||||
switch (purpose) {
|
switch (purpose) {
|
||||||
|
@ -81,7 +81,7 @@ typedef enum( unsigned int, MPPasswordType ) {
|
|||||||
/** Custom saved password. */
|
/** Custom saved password. */
|
||||||
MPPasswordTypeStoredPersonal = 0x0 | MPPasswordTypeClassStored | MPSiteFeatureExportContent,
|
MPPasswordTypeStoredPersonal = 0x0 | MPPasswordTypeClassStored | MPSiteFeatureExportContent,
|
||||||
/** Custom saved password that should not be exported from the device. */
|
/** Custom saved password that should not be exported from the device. */
|
||||||
MPPasswordTypeStoredDevicePrivate = 0x1 | MPPasswordTypeClassStored | MPSiteFeatureDevicePrivate,
|
MPPasswordTypeStoredDevice = 0x1 | MPPasswordTypeClassStored | MPSiteFeatureDevicePrivate,
|
||||||
|
|
||||||
MPPasswordTypeDefault = MPPasswordTypeGeneratedLong,
|
MPPasswordTypeDefault = MPPasswordTypeGeneratedLong,
|
||||||
};
|
};
|
||||||
@ -92,15 +92,23 @@ typedef enum( unsigned int, MPPasswordType ) {
|
|||||||
* @return The purpose represented by the given name.
|
* @return The purpose represented by the given name.
|
||||||
*/
|
*/
|
||||||
const MPKeyPurpose mpw_purposeWithName(const char *purposeName);
|
const MPKeyPurpose mpw_purposeWithName(const char *purposeName);
|
||||||
|
/**
|
||||||
|
* @return The standard name for the given purpose.
|
||||||
|
*/
|
||||||
|
const char *mpw_nameForPurpose(MPKeyPurpose purpose);
|
||||||
/**
|
/**
|
||||||
* @return An internal string containing the scope identifier to apply when encoding for the given purpose.
|
* @return An internal string containing the scope identifier to apply when encoding for the given purpose.
|
||||||
*/
|
*/
|
||||||
const char *mpw_scopeForPurpose(MPKeyPurpose purpose);
|
const char *mpw_scopeForPurpose(MPKeyPurpose purpose);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The type represented by the given name.
|
* @return The password type represented by the given name.
|
||||||
*/
|
*/
|
||||||
const MPPasswordType mpw_typeWithName(const char *typeName);
|
const MPPasswordType mpw_typeWithName(const char *typeName);
|
||||||
|
/**
|
||||||
|
* @return The standard name for the given password type.
|
||||||
|
*/
|
||||||
|
const char *mpw_nameForType(MPPasswordType passwordType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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.
|
||||||
|
@ -299,9 +299,11 @@ int main(int argc, char *const argv[]) {
|
|||||||
trc( "masterPassword : %s\n", masterPassword );
|
trc( "masterPassword : %s\n", masterPassword );
|
||||||
dbg( "identicon : %s\n", identicon );
|
dbg( "identicon : %s\n", identicon );
|
||||||
dbg( "siteName : %s\n", siteName );
|
dbg( "siteName : %s\n", siteName );
|
||||||
dbg( "passwordType : %u\n", passwordType );
|
|
||||||
dbg( "algorithmVersion : %u\n", algorithmVersion );
|
|
||||||
dbg( "siteCounter : %u\n", siteCounter );
|
dbg( "siteCounter : %u\n", siteCounter );
|
||||||
|
dbg( "keyPurpose : %s (%u)\n", mpw_nameForPurpose( keyPurpose ), keyPurpose );
|
||||||
|
dbg( "keyContext : %s\n", keyContext );
|
||||||
|
dbg( "passwordType : %s (%u)\n", mpw_nameForType( passwordType ), passwordType );
|
||||||
|
dbg( "algorithmVersion : %u\n", algorithmVersion );
|
||||||
dbg( "-----------------\n\n" );
|
dbg( "-----------------\n\n" );
|
||||||
inf( "%s's password for %s:\n[ %s ]: ", fullName, siteName, identicon );
|
inf( "%s's password for %s:\n[ %s ]: ", fullName, siteName, identicon );
|
||||||
mpw_free_string( identicon );
|
mpw_free_string( identicon );
|
||||||
|
Loading…
Reference in New Issue
Block a user