Standardize on a naming scheme: cipher -> template, userName -> fullName, element -> site.
This commit is contained in:
parent
b976e79b0f
commit
3f4558da2b
@ -33,7 +33,7 @@ else
|
|||||||
# Modify here or override using targets='mpw mpw-bench' ./build
|
# Modify here or override using targets='mpw mpw-bench' ./build
|
||||||
targets=(
|
targets=(
|
||||||
mpw # C CLI version of Master Password.
|
mpw # C CLI version of Master Password.
|
||||||
#mpw-bench # C CLI Master Password benchmark utility.
|
mpw-bench # C CLI Master Password benchmark utility.
|
||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -25,11 +25,11 @@
|
|||||||
|
|
||||||
int main(int argc, char *const argv[]) {
|
int main(int argc, char *const argv[]) {
|
||||||
|
|
||||||
char *userName = "Robert Lee Mitchel";
|
char *fullName = "Robert Lee Mitchel";
|
||||||
char *masterPassword = "banana colored duckling";
|
char *masterPassword = "banana colored duckling";
|
||||||
char *siteName = "masterpasswordapp.com";
|
char *siteName = "masterpasswordapp.com";
|
||||||
uint32_t siteCounter = 1;
|
uint32_t siteCounter = 1;
|
||||||
MPElementType siteType = MPElementTypeGeneratedLong;
|
MPSiteType siteType = MPSiteTypeGeneratedLong;
|
||||||
|
|
||||||
// Start MP
|
// Start MP
|
||||||
struct timeval startTime;
|
struct timeval startTime;
|
||||||
@ -42,8 +42,8 @@ int main(int argc, char *const argv[]) {
|
|||||||
for (int i = 0; i < iterations; ++i) {
|
for (int i = 0; i < iterations; ++i) {
|
||||||
// Calculate the master key salt.
|
// Calculate the master key salt.
|
||||||
char *mpNameSpace = "com.lyndir.masterpassword";
|
char *mpNameSpace = "com.lyndir.masterpassword";
|
||||||
const uint32_t n_userNameLength = htonl(strlen(userName));
|
const uint32_t n_fullNameLength = htonl(strlen(fullName));
|
||||||
const size_t masterKeySaltLength = strlen(mpNameSpace) + sizeof(n_userNameLength) + strlen(userName);
|
const size_t masterKeySaltLength = strlen(mpNameSpace) + sizeof(n_fullNameLength) + strlen(fullName);
|
||||||
char *masterKeySalt = malloc( masterKeySaltLength );
|
char *masterKeySalt = malloc( masterKeySaltLength );
|
||||||
if (!masterKeySalt) {
|
if (!masterKeySalt) {
|
||||||
fprintf(stderr, "Could not allocate master key salt: %d\n", errno);
|
fprintf(stderr, "Could not allocate master key salt: %d\n", errno);
|
||||||
@ -52,8 +52,8 @@ int main(int argc, char *const argv[]) {
|
|||||||
|
|
||||||
char *mKS = masterKeySalt;
|
char *mKS = masterKeySalt;
|
||||||
memcpy(mKS, mpNameSpace, strlen(mpNameSpace)); mKS += strlen(mpNameSpace);
|
memcpy(mKS, mpNameSpace, strlen(mpNameSpace)); mKS += strlen(mpNameSpace);
|
||||||
memcpy(mKS, &n_userNameLength, sizeof(n_userNameLength)); mKS += sizeof(n_userNameLength);
|
memcpy(mKS, &n_fullNameLength, sizeof(n_fullNameLength)); mKS += sizeof(n_fullNameLength);
|
||||||
memcpy(mKS, userName, strlen(userName)); mKS += strlen(userName);
|
memcpy(mKS, fullName, strlen(fullName)); mKS += strlen(fullName);
|
||||||
if (mKS - masterKeySalt != masterKeySaltLength)
|
if (mKS - masterKeySalt != masterKeySaltLength)
|
||||||
abort();
|
abort();
|
||||||
trc("masterKeySalt ID: %s\n", IDForBuf(masterKeySalt, masterKeySaltLength));
|
trc("masterKeySalt ID: %s\n", IDForBuf(masterKeySalt, masterKeySaltLength));
|
||||||
@ -96,17 +96,17 @@ int main(int argc, char *const argv[]) {
|
|||||||
free(masterKey);
|
free(masterKey);
|
||||||
free(sitePasswordInfo);
|
free(sitePasswordInfo);
|
||||||
|
|
||||||
// Determine the cipher.
|
// Determine the template.
|
||||||
const char *cipher = CipherForType(siteType, sitePasswordSeed[0]);
|
const char *template = TemplateForType(siteType, sitePasswordSeed[0]);
|
||||||
trc("type %d, cipher: %s\n", siteType, cipher);
|
trc("type %d, template: %s\n", siteType, template);
|
||||||
if (strlen(cipher) > 32)
|
if (strlen(template) > 32)
|
||||||
abort();
|
abort();
|
||||||
|
|
||||||
// Encode the password from the seed using the cipher.
|
// Encode the password from the seed using the template.
|
||||||
char *sitePassword = calloc(strlen(cipher) + 1, sizeof(char));
|
char *sitePassword = calloc(strlen(template) + 1, sizeof(char));
|
||||||
for (int c = 0; c < strlen(cipher); ++c) {
|
for (int c = 0; c < strlen(template); ++c) {
|
||||||
sitePassword[c] = CharacterFromClass(cipher[c], sitePasswordSeed[c + 1]);
|
sitePassword[c] = CharacterFromClass(template[c], sitePasswordSeed[c + 1]);
|
||||||
trc("class %c, character: %c\n", cipher[c], sitePassword[c]);
|
trc("class %c, character: %c\n", template[c], sitePassword[c]);
|
||||||
}
|
}
|
||||||
memset(sitePasswordSeed, 0, sizeof(sitePasswordSeed));
|
memset(sitePasswordSeed, 0, sizeof(sitePasswordSeed));
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ int main(int argc, char *const argv[]) {
|
|||||||
int bcrypt_cost = 9;
|
int bcrypt_cost = 9;
|
||||||
iterations = 600;
|
iterations = 600;
|
||||||
for (int i = 0; i < iterations; ++i) {
|
for (int i = 0; i < iterations; ++i) {
|
||||||
crypt(masterPassword, crypt_gensalt("$2b$", bcrypt_cost, userName, strlen(userName)));
|
crypt(masterPassword, crypt_gensalt("$2b$", bcrypt_cost, fullName, strlen(fullName)));
|
||||||
|
|
||||||
if (i % 10 == 0)
|
if (i % 10 == 0)
|
||||||
fprintf( stderr, "\rbcrypt (cost %d): iteration %d / %d..", bcrypt_cost, i, iterations );
|
fprintf( stderr, "\rbcrypt (cost %d): iteration %d / %d..", bcrypt_cost, i, iterations );
|
||||||
|
@ -35,14 +35,14 @@
|
|||||||
#define MP_dkLen 64
|
#define MP_dkLen 64
|
||||||
#define MP_hash PearlHashSHA256
|
#define MP_hash PearlHashSHA256
|
||||||
|
|
||||||
#define MP_env_username "MP_USERNAME"
|
#define MP_env_fullname "MP_FULLNAME"
|
||||||
#define MP_env_sitetype "MP_SITETYPE"
|
#define MP_env_sitetype "MP_SITETYPE"
|
||||||
#define MP_env_sitecounter "MP_SITECOUNTER"
|
#define MP_env_sitecounter "MP_SITECOUNTER"
|
||||||
|
|
||||||
void usage() {
|
void usage() {
|
||||||
fprintf(stderr, "Usage: mpw [-u name] [-t type] [-c counter] site\n\n");
|
fprintf(stderr, "Usage: mpw [-u name] [-t type] [-c counter] site\n\n");
|
||||||
fprintf(stderr, " -u name Specify the full name of the user.\n"
|
fprintf(stderr, " -u name Specify the full name of the user.\n"
|
||||||
" Defaults to %s in env.\n\n", MP_env_username);
|
" Defaults to %s in env.\n\n", MP_env_fullname);
|
||||||
fprintf(stderr, " -t type Specify the password's template.\n"
|
fprintf(stderr, " -t type Specify the password's template.\n"
|
||||||
" Defaults to %s in env or 'long' for password, 'name' for login.\n"
|
" Defaults to %s in env or 'long' for password, 'name' for login.\n"
|
||||||
" x, max, maximum | 20 characters, contains symbols.\n"
|
" x, max, maximum | 20 characters, contains symbols.\n"
|
||||||
@ -67,7 +67,7 @@ void usage() {
|
|||||||
" -v a, answer | Empty for a universal site answer or\n"
|
" -v a, answer | Empty for a universal site answer or\n"
|
||||||
" | the most significant word(s) of the question.\n\n");
|
" | the most significant word(s) of the question.\n\n");
|
||||||
fprintf(stderr, " ENVIRONMENT\n\n"
|
fprintf(stderr, " ENVIRONMENT\n\n"
|
||||||
" MP_USERNAME | The full name of the user.\n"
|
" MP_FULLNAME | The full name of the user.\n"
|
||||||
" MP_SITETYPE | The default password template.\n"
|
" MP_SITETYPE | The default password template.\n"
|
||||||
" MP_SITECOUNTER | The default counter value.\n\n");
|
" MP_SITECOUNTER | The default counter value.\n\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -105,12 +105,12 @@ char *getlinep(const char *prompt) {
|
|||||||
int main(int argc, char *const argv[]) {
|
int main(int argc, char *const argv[]) {
|
||||||
|
|
||||||
// Read the environment.
|
// Read the environment.
|
||||||
char *userName = getenv( MP_env_username );
|
char *fullName = getenv( MP_env_fullname );
|
||||||
const char *masterPassword = NULL;
|
const char *masterPassword = NULL;
|
||||||
const char *siteName = NULL;
|
const char *siteName = NULL;
|
||||||
MPElementType siteType = MPElementTypeGeneratedLong;
|
MPSiteType siteType = MPSiteTypeGeneratedLong;
|
||||||
const char *siteTypeString = getenv( MP_env_sitetype );
|
const char *siteTypeString = getenv( MP_env_sitetype );
|
||||||
MPElementVariant siteVariant = MPElementVariantPassword;
|
MPSiteVariant siteVariant = MPSiteVariantPassword;
|
||||||
const char *siteVariantString = NULL;
|
const char *siteVariantString = NULL;
|
||||||
const char *siteContextString = NULL;
|
const char *siteContextString = NULL;
|
||||||
uint32_t siteCounter = 1;
|
uint32_t siteCounter = 1;
|
||||||
@ -120,7 +120,7 @@ int main(int argc, char *const argv[]) {
|
|||||||
for (int opt; (opt = getopt(argc, argv, "u:t:c:v:C:h")) != -1;)
|
for (int opt; (opt = getopt(argc, argv, "u:t:c:v:C:h")) != -1;)
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'u':
|
case 'u':
|
||||||
userName = optarg;
|
fullName = optarg;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
siteTypeString = optarg;
|
siteTypeString = optarg;
|
||||||
@ -140,7 +140,7 @@ int main(int argc, char *const argv[]) {
|
|||||||
case '?':
|
case '?':
|
||||||
switch (optopt) {
|
switch (optopt) {
|
||||||
case 'u':
|
case 'u':
|
||||||
fprintf(stderr, "Missing user name to option: -%c\n", optopt);
|
fprintf(stderr, "Missing full name to option: -%c\n", optopt);
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
fprintf(stderr, "Missing type name to option: -%c\n", optopt);
|
fprintf(stderr, "Missing type name to option: -%c\n", optopt);
|
||||||
@ -159,13 +159,13 @@ int main(int argc, char *const argv[]) {
|
|||||||
siteName = argv[optind];
|
siteName = argv[optind];
|
||||||
|
|
||||||
// Convert and validate input.
|
// Convert and validate input.
|
||||||
if (!userName) {
|
if (!fullName) {
|
||||||
if (!(userName = getlinep("Your user name:"))) {
|
if (!(fullName = getlinep("Your full name:"))) {
|
||||||
fprintf(stderr, "Missing user name.\n");
|
fprintf(stderr, "Missing full name.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
trc("userName: %s\n", userName);
|
trc("fullName: %s\n", fullName);
|
||||||
if (!siteName) {
|
if (!siteName) {
|
||||||
if (!(siteName = getlinep("Site name:"))) {
|
if (!(siteName = getlinep("Site name:"))) {
|
||||||
fprintf(stderr, "Missing site name.\n");
|
fprintf(stderr, "Missing site name.\n");
|
||||||
@ -180,10 +180,10 @@ int main(int argc, char *const argv[]) {
|
|||||||
}
|
}
|
||||||
if (siteVariantString)
|
if (siteVariantString)
|
||||||
siteVariant = VariantWithName( siteVariantString );
|
siteVariant = VariantWithName( siteVariantString );
|
||||||
if (siteVariant == MPElementVariantLogin)
|
if (siteVariant == MPSiteVariantLogin)
|
||||||
siteType = MPElementTypeGeneratedName;
|
siteType = MPSiteTypeGeneratedName;
|
||||||
if (siteVariant == MPElementVariantAnswer)
|
if (siteVariant == MPSiteVariantAnswer)
|
||||||
siteType = MPElementTypeGeneratedPhrase;
|
siteType = MPSiteTypeGeneratedPhrase;
|
||||||
if (siteTypeString)
|
if (siteTypeString)
|
||||||
siteType = TypeWithName( siteTypeString );
|
siteType = TypeWithName( siteTypeString );
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ int main(int argc, char *const argv[]) {
|
|||||||
ssize_t linelen;
|
ssize_t linelen;
|
||||||
while ((linelen = getline(&line, &linecap, mpwConfig)) > 0) {
|
while ((linelen = getline(&line, &linecap, mpwConfig)) > 0) {
|
||||||
char *lineData = line;
|
char *lineData = line;
|
||||||
if (strcmp(strsep(&lineData, ":"), userName) == 0) {
|
if (strcmp(strsep(&lineData, ":"), fullName) == 0) {
|
||||||
masterPassword = strcpy(malloc(strlen(lineData)), strsep(&lineData, "\n"));
|
masterPassword = strcpy(malloc(strlen(lineData)), strsep(&lineData, "\n"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ int main(int argc, char *const argv[]) {
|
|||||||
trc("masterPassword: %s\n", masterPassword);
|
trc("masterPassword: %s\n", masterPassword);
|
||||||
|
|
||||||
// Summarize operation.
|
// Summarize operation.
|
||||||
fprintf(stderr, "%s's password for %s:\n[ %s ]: ", userName, siteName, Identicon( userName, masterPassword ));
|
fprintf(stderr, "%s's password for %s:\n[ %s ]: ", fullName, siteName, Identicon( fullName, masterPassword ));
|
||||||
struct timeval startTime;
|
struct timeval startTime;
|
||||||
if (gettimeofday(&startTime, NULL) != 0) {
|
if (gettimeofday(&startTime, NULL) != 0) {
|
||||||
fprintf(stderr, "Could not get time: %d\n", errno);
|
fprintf(stderr, "Could not get time: %d\n", errno);
|
||||||
@ -222,10 +222,10 @@ int main(int argc, char *const argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the master key salt.
|
// Calculate the master key salt.
|
||||||
const char *mpKeyScope = ScopeForVariant(MPElementVariantPassword);
|
const char *mpKeyScope = ScopeForVariant(MPSiteVariantPassword);
|
||||||
trc("key scope: %s\n", mpKeyScope);
|
trc("key scope: %s\n", mpKeyScope);
|
||||||
const uint32_t n_userNameLength = htonl(strlen(userName));
|
const uint32_t n_fullNameLength = htonl(strlen(fullName));
|
||||||
const size_t masterKeySaltLength = strlen(mpKeyScope) + sizeof(n_userNameLength) + strlen(userName);
|
const size_t masterKeySaltLength = strlen(mpKeyScope) + sizeof(n_fullNameLength) + strlen(fullName);
|
||||||
char *masterKeySalt = (char *)malloc( masterKeySaltLength );
|
char *masterKeySalt = (char *)malloc( masterKeySaltLength );
|
||||||
if (!masterKeySalt) {
|
if (!masterKeySalt) {
|
||||||
fprintf(stderr, "Could not allocate master key salt: %d\n", errno);
|
fprintf(stderr, "Could not allocate master key salt: %d\n", errno);
|
||||||
@ -234,8 +234,8 @@ int main(int argc, char *const argv[]) {
|
|||||||
|
|
||||||
char *mKS = masterKeySalt;
|
char *mKS = masterKeySalt;
|
||||||
memcpy(mKS, mpKeyScope, strlen(mpKeyScope)); mKS += strlen(mpKeyScope);
|
memcpy(mKS, mpKeyScope, strlen(mpKeyScope)); mKS += strlen(mpKeyScope);
|
||||||
memcpy(mKS, &n_userNameLength, sizeof(n_userNameLength)); mKS += sizeof(n_userNameLength);
|
memcpy(mKS, &n_fullNameLength, sizeof(n_fullNameLength)); mKS += sizeof(n_fullNameLength);
|
||||||
memcpy(mKS, userName, strlen(userName)); mKS += strlen(userName);
|
memcpy(mKS, fullName, strlen(fullName)); mKS += strlen(fullName);
|
||||||
if (mKS - masterKeySalt != masterKeySaltLength)
|
if (mKS - masterKeySalt != masterKeySaltLength)
|
||||||
abort();
|
abort();
|
||||||
trc("masterKeySalt ID: %s\n", IDForBuf(masterKeySalt, masterKeySaltLength));
|
trc("masterKeySalt ID: %s\n", IDForBuf(masterKeySalt, masterKeySaltLength));
|
||||||
|
@ -23,66 +23,66 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
const MPElementType TypeWithName(const char *typeName) {
|
const MPSiteType TypeWithName(const char *typeName) {
|
||||||
char lowerTypeName[strlen(typeName)];
|
char lowerTypeName[strlen(typeName)];
|
||||||
strcpy(lowerTypeName, typeName);
|
strcpy(lowerTypeName, typeName);
|
||||||
for (char *tN = lowerTypeName; *tN; ++tN)
|
for (char *tN = lowerTypeName; *tN; ++tN)
|
||||||
*tN = tolower(*tN);
|
*tN = tolower(*tN);
|
||||||
|
|
||||||
if (0 == strcmp(lowerTypeName, "x") || 0 == strcmp(lowerTypeName, "max") || 0 == strcmp(lowerTypeName, "maximum"))
|
if (0 == strcmp(lowerTypeName, "x") || 0 == strcmp(lowerTypeName, "max") || 0 == strcmp(lowerTypeName, "maximum"))
|
||||||
return MPElementTypeGeneratedMaximum;
|
return MPSiteTypeGeneratedMaximum;
|
||||||
if (0 == strcmp(lowerTypeName, "l") || 0 == strcmp(lowerTypeName, "long"))
|
if (0 == strcmp(lowerTypeName, "l") || 0 == strcmp(lowerTypeName, "long"))
|
||||||
return MPElementTypeGeneratedLong;
|
return MPSiteTypeGeneratedLong;
|
||||||
if (0 == strcmp(lowerTypeName, "m") || 0 == strcmp(lowerTypeName, "med") || 0 == strcmp(lowerTypeName, "medium"))
|
if (0 == strcmp(lowerTypeName, "m") || 0 == strcmp(lowerTypeName, "med") || 0 == strcmp(lowerTypeName, "medium"))
|
||||||
return MPElementTypeGeneratedMedium;
|
return MPSiteTypeGeneratedMedium;
|
||||||
if (0 == strcmp(lowerTypeName, "b") || 0 == strcmp(lowerTypeName, "basic"))
|
if (0 == strcmp(lowerTypeName, "b") || 0 == strcmp(lowerTypeName, "basic"))
|
||||||
return MPElementTypeGeneratedBasic;
|
return MPSiteTypeGeneratedBasic;
|
||||||
if (0 == strcmp(lowerTypeName, "s") || 0 == strcmp(lowerTypeName, "short"))
|
if (0 == strcmp(lowerTypeName, "s") || 0 == strcmp(lowerTypeName, "short"))
|
||||||
return MPElementTypeGeneratedShort;
|
return MPSiteTypeGeneratedShort;
|
||||||
if (0 == strcmp(lowerTypeName, "i") || 0 == strcmp(lowerTypeName, "pin"))
|
if (0 == strcmp(lowerTypeName, "i") || 0 == strcmp(lowerTypeName, "pin"))
|
||||||
return MPElementTypeGeneratedPIN;
|
return MPSiteTypeGeneratedPIN;
|
||||||
if (0 == strcmp(lowerTypeName, "n") || 0 == strcmp(lowerTypeName, "name"))
|
if (0 == strcmp(lowerTypeName, "n") || 0 == strcmp(lowerTypeName, "name"))
|
||||||
return MPElementTypeGeneratedName;
|
return MPSiteTypeGeneratedName;
|
||||||
if (0 == strcmp(lowerTypeName, "p") || 0 == strcmp(lowerTypeName, "phrase"))
|
if (0 == strcmp(lowerTypeName, "p") || 0 == strcmp(lowerTypeName, "phrase"))
|
||||||
return MPElementTypeGeneratedPhrase;
|
return MPSiteTypeGeneratedPhrase;
|
||||||
|
|
||||||
fprintf(stderr, "Not a generated type name: %s", lowerTypeName);
|
fprintf(stderr, "Not a generated type name: %s", lowerTypeName);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *TemplateForType(MPElementType type, uint8_t seedByte) {
|
const char *TemplateForType(MPSiteType type, uint8_t seedByte) {
|
||||||
if (!(type & MPElementTypeClassGenerated)) {
|
if (!(type & MPSiteTypeClassGenerated)) {
|
||||||
fprintf(stderr, "Not a generated type: %d", type);
|
fprintf(stderr, "Not a generated type: %d", type);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MPElementTypeGeneratedMaximum: {
|
case MPSiteTypeGeneratedMaximum: {
|
||||||
const char *templates[] = { "anoxxxxxxxxxxxxxxxxx", "axxxxxxxxxxxxxxxxxno" };
|
const char *templates[] = { "anoxxxxxxxxxxxxxxxxx", "axxxxxxxxxxxxxxxxxno" };
|
||||||
return templates[seedByte % 2];
|
return templates[seedByte % 2];
|
||||||
}
|
}
|
||||||
case MPElementTypeGeneratedLong: {
|
case MPSiteTypeGeneratedLong: {
|
||||||
const char *templates[] = { "CvcvnoCvcvCvcv", "CvcvCvcvnoCvcv", "CvcvCvcvCvcvno", "CvccnoCvcvCvcv", "CvccCvcvnoCvcv", "CvccCvcvCvcvno", "CvcvnoCvccCvcv", "CvcvCvccnoCvcv", "CvcvCvccCvcvno", "CvcvnoCvcvCvcc", "CvcvCvcvnoCvcc", "CvcvCvcvCvccno", "CvccnoCvccCvcv", "CvccCvccnoCvcv", "CvccCvccCvcvno", "CvcvnoCvccCvcc", "CvcvCvccnoCvcc", "CvcvCvccCvccno", "CvccnoCvcvCvcc", "CvccCvcvnoCvcc", "CvccCvcvCvccno" };
|
const char *templates[] = { "CvcvnoCvcvCvcv", "CvcvCvcvnoCvcv", "CvcvCvcvCvcvno", "CvccnoCvcvCvcv", "CvccCvcvnoCvcv", "CvccCvcvCvcvno", "CvcvnoCvccCvcv", "CvcvCvccnoCvcv", "CvcvCvccCvcvno", "CvcvnoCvcvCvcc", "CvcvCvcvnoCvcc", "CvcvCvcvCvccno", "CvccnoCvccCvcv", "CvccCvccnoCvcv", "CvccCvccCvcvno", "CvcvnoCvccCvcc", "CvcvCvccnoCvcc", "CvcvCvccCvccno", "CvccnoCvcvCvcc", "CvccCvcvnoCvcc", "CvccCvcvCvccno" };
|
||||||
return templates[seedByte % 21];
|
return templates[seedByte % 21];
|
||||||
}
|
}
|
||||||
case MPElementTypeGeneratedMedium: {
|
case MPSiteTypeGeneratedMedium: {
|
||||||
const char *templates[] = { "CvcnoCvc", "CvcCvcno" };
|
const char *templates[] = { "CvcnoCvc", "CvcCvcno" };
|
||||||
return templates[seedByte % 2];
|
return templates[seedByte % 2];
|
||||||
}
|
}
|
||||||
case MPElementTypeGeneratedBasic: {
|
case MPSiteTypeGeneratedBasic: {
|
||||||
const char *templates[] = { "aaanaaan", "aannaaan", "aaannaaa" };
|
const char *templates[] = { "aaanaaan", "aannaaan", "aaannaaa" };
|
||||||
return templates[seedByte % 3];
|
return templates[seedByte % 3];
|
||||||
}
|
}
|
||||||
case MPElementTypeGeneratedShort: {
|
case MPSiteTypeGeneratedShort: {
|
||||||
return "Cvcn";
|
return "Cvcn";
|
||||||
}
|
}
|
||||||
case MPElementTypeGeneratedPIN: {
|
case MPSiteTypeGeneratedPIN: {
|
||||||
return "nnnn";
|
return "nnnn";
|
||||||
}
|
}
|
||||||
case MPElementTypeGeneratedName: {
|
case MPSiteTypeGeneratedName: {
|
||||||
return "cvccvcvcv";
|
return "cvccvcvcv";
|
||||||
}
|
}
|
||||||
case MPElementTypeGeneratedPhrase: {
|
case MPSiteTypeGeneratedPhrase: {
|
||||||
const char *templates[] = { "cvcc cvc cvccvcv cvc", "cvc cvccvcvcv cvcv", "cv cvccv cvc cvcvccv" };
|
const char *templates[] = { "cvcc cvc cvccvcv cvc", "cvc cvccvcvcv cvcv", "cv cvccv cvc cvcvccv" };
|
||||||
return templates[seedByte % 3];
|
return templates[seedByte % 3];
|
||||||
}
|
}
|
||||||
@ -93,32 +93,32 @@ const char *TemplateForType(MPElementType type, uint8_t seedByte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const MPElementVariant VariantWithName(const char *variantName) {
|
const MPSiteVariant VariantWithName(const char *variantName) {
|
||||||
char lowerVariantName[strlen(variantName)];
|
char lowerVariantName[strlen(variantName)];
|
||||||
strcpy(lowerVariantName, variantName);
|
strcpy(lowerVariantName, variantName);
|
||||||
for (char *vN = lowerVariantName; *vN; ++vN)
|
for (char *vN = lowerVariantName; *vN; ++vN)
|
||||||
*vN = tolower(*vN);
|
*vN = tolower(*vN);
|
||||||
|
|
||||||
if (0 == strcmp(lowerVariantName, "p") || 0 == strcmp(lowerVariantName, "password"))
|
if (0 == strcmp(lowerVariantName, "p") || 0 == strcmp(lowerVariantName, "password"))
|
||||||
return MPElementVariantPassword;
|
return MPSiteVariantPassword;
|
||||||
if (0 == strcmp(lowerVariantName, "l") || 0 == strcmp(lowerVariantName, "login"))
|
if (0 == strcmp(lowerVariantName, "l") || 0 == strcmp(lowerVariantName, "login"))
|
||||||
return MPElementVariantLogin;
|
return MPSiteVariantLogin;
|
||||||
if (0 == strcmp(lowerVariantName, "a") || 0 == strcmp(lowerVariantName, "answer"))
|
if (0 == strcmp(lowerVariantName, "a") || 0 == strcmp(lowerVariantName, "answer"))
|
||||||
return MPElementVariantAnswer;
|
return MPSiteVariantAnswer;
|
||||||
|
|
||||||
fprintf(stderr, "Not a variant name: %s", lowerVariantName);
|
fprintf(stderr, "Not a variant name: %s", lowerVariantName);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *ScopeForVariant(MPElementVariant variant) {
|
const char *ScopeForVariant(MPSiteVariant variant) {
|
||||||
switch (variant) {
|
switch (variant) {
|
||||||
case MPElementVariantPassword: {
|
case MPSiteVariantPassword: {
|
||||||
return "com.lyndir.masterpassword";
|
return "com.lyndir.masterpassword";
|
||||||
}
|
}
|
||||||
case MPElementVariantLogin: {
|
case MPSiteVariantLogin: {
|
||||||
return "com.lyndir.masterpassword.login";
|
return "com.lyndir.masterpassword.login";
|
||||||
}
|
}
|
||||||
case MPElementVariantAnswer: {
|
case MPSiteVariantAnswer: {
|
||||||
return "com.lyndir.masterpassword.answer";
|
return "com.lyndir.masterpassword.answer";
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@ -218,14 +218,14 @@ static int putvar(int c) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char *Identicon(const char *userName, const char *masterPassword) {
|
const char *Identicon(const char *fullName, const char *masterPassword) {
|
||||||
const char *leftArm[] = { "╔", "╚", "╰", "═" };
|
const char *leftArm[] = { "╔", "╚", "╰", "═" };
|
||||||
const char *rightArm[] = { "╗", "╝", "╯", "═" };
|
const char *rightArm[] = { "╗", "╝", "╯", "═" };
|
||||||
const char *body[] = { "█", "░", "▒", "▓", "☺", "☻" };
|
const char *body[] = { "█", "░", "▒", "▓", "☺", "☻" };
|
||||||
const char *accessory[] = { "◈", "◎", "◐", "◑", "◒", "◓", "☀", "☁", "☂", "☃", "☄", "★", "☆", "☎", "☏", "⎈", "⌂", "☘", "☢", "☣", "☕", "⌚", "⌛", "⏰", "⚡", "⛄", "⛅", "☔", "♔", "♕", "♖", "♗", "♘", "♙", "♚", "♛", "♜", "♝", "♞", "♟", "♨", "♩", "♪", "♫", "⚐", "⚑", "⚔", "⚖", "⚙", "⚠", "⌘", "⏎", "✄", "✆", "✈", "✉", "✌" };
|
const char *accessory[] = { "◈", "◎", "◐", "◑", "◒", "◓", "☀", "☁", "☂", "☃", "☄", "★", "☆", "☎", "☏", "⎈", "⌂", "☘", "☢", "☣", "☕", "⌚", "⌛", "⏰", "⚡", "⛄", "⛅", "☔", "♔", "♕", "♖", "♗", "♘", "♙", "♚", "♛", "♜", "♝", "♞", "♟", "♨", "♩", "♪", "♫", "⚐", "⚑", "⚔", "⚖", "⚙", "⚠", "⌘", "⏎", "✄", "✆", "✈", "✉", "✌" };
|
||||||
|
|
||||||
uint8_t identiconSeed[32];
|
uint8_t identiconSeed[32];
|
||||||
HMAC_SHA256_Buf(masterPassword, strlen(masterPassword), userName, strlen(userName), identiconSeed);
|
HMAC_SHA256_Buf(masterPassword, strlen(masterPassword), fullName, strlen(fullName), identiconSeed);
|
||||||
|
|
||||||
uint8_t colorIdentifier = identiconSeed[4] % 7 + 1;
|
uint8_t colorIdentifier = identiconSeed[4] % 7 + 1;
|
||||||
char *colorString, *resetString;
|
char *colorString, *resetString;
|
||||||
|
@ -8,40 +8,40 @@
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
/** Generate the password to log in with. */
|
/** Generate the password to log in with. */
|
||||||
MPElementVariantPassword,
|
MPSiteVariantPassword,
|
||||||
/** Generate the login name to log in as. */
|
/** Generate the login name to log in as. */
|
||||||
MPElementVariantLogin,
|
MPSiteVariantLogin,
|
||||||
/** Generate the answer to a security question. */
|
/** Generate the answer to a security question. */
|
||||||
MPElementVariantAnswer,
|
MPSiteVariantAnswer,
|
||||||
} MPElementVariant;
|
} MPSiteVariant;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
/** Generate the password. */
|
/** Generate the password. */
|
||||||
MPElementTypeClassGenerated = 1 << 4,
|
MPSiteTypeClassGenerated = 1 << 4,
|
||||||
/** Store the password. */
|
/** Store the password. */
|
||||||
MPElementTypeClassStored = 1 << 5,
|
MPSiteTypeClassStored = 1 << 5,
|
||||||
} MPElementTypeClass;
|
} MPSiteTypeClass;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
/** Export the key-protected content data. */
|
/** Export the key-protected content data. */
|
||||||
MPElementFeatureExportContent = 1 << 10,
|
MPSiteFeatureExportContent = 1 << 10,
|
||||||
/** Never export content. */
|
/** Never export content. */
|
||||||
MPElementFeatureDevicePrivate = 1 << 11,
|
MPSiteFeatureDevicePrivate = 1 << 11,
|
||||||
} MPElementFeature;
|
} MPSiteFeature;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MPElementTypeGeneratedMaximum = 0x0 | MPElementTypeClassGenerated | 0x0,
|
MPSiteTypeGeneratedMaximum = 0x0 | MPSiteTypeClassGenerated | 0x0,
|
||||||
MPElementTypeGeneratedLong = 0x1 | MPElementTypeClassGenerated | 0x0,
|
MPSiteTypeGeneratedLong = 0x1 | MPSiteTypeClassGenerated | 0x0,
|
||||||
MPElementTypeGeneratedMedium = 0x2 | MPElementTypeClassGenerated | 0x0,
|
MPSiteTypeGeneratedMedium = 0x2 | MPSiteTypeClassGenerated | 0x0,
|
||||||
MPElementTypeGeneratedBasic = 0x4 | MPElementTypeClassGenerated | 0x0,
|
MPSiteTypeGeneratedBasic = 0x4 | MPSiteTypeClassGenerated | 0x0,
|
||||||
MPElementTypeGeneratedShort = 0x3 | MPElementTypeClassGenerated | 0x0,
|
MPSiteTypeGeneratedShort = 0x3 | MPSiteTypeClassGenerated | 0x0,
|
||||||
MPElementTypeGeneratedPIN = 0x5 | MPElementTypeClassGenerated | 0x0,
|
MPSiteTypeGeneratedPIN = 0x5 | MPSiteTypeClassGenerated | 0x0,
|
||||||
MPElementTypeGeneratedName = 0xE | MPElementTypeClassGenerated | 0x0,
|
MPSiteTypeGeneratedName = 0xE | MPSiteTypeClassGenerated | 0x0,
|
||||||
MPElementTypeGeneratedPhrase = 0xF | MPElementTypeClassGenerated | 0x0,
|
MPSiteTypeGeneratedPhrase = 0xF | MPSiteTypeClassGenerated | 0x0,
|
||||||
|
|
||||||
MPElementTypeStoredPersonal = 0x0 | MPElementTypeClassStored | MPElementFeatureExportContent,
|
MPSiteTypeStoredPersonal = 0x0 | MPSiteTypeClassStored | MPSiteFeatureExportContent,
|
||||||
MPElementTypeStoredDevicePrivate = 0x1 | MPElementTypeClassStored | MPElementFeatureDevicePrivate,
|
MPSiteTypeStoredDevicePrivate = 0x1 | MPSiteTypeClassStored | MPSiteFeatureDevicePrivate,
|
||||||
} MPElementType;
|
} MPSiteType;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define trc(...) fprintf(stderr, __VA_ARGS__)
|
#define trc(...) fprintf(stderr, __VA_ARGS__)
|
||||||
@ -49,12 +49,12 @@ typedef enum {
|
|||||||
#define trc(...) do {} while (0)
|
#define trc(...) do {} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const MPElementVariant VariantWithName(const char *variantName);
|
const MPSiteVariant VariantWithName(const char *variantName);
|
||||||
const char *ScopeForVariant(MPElementVariant variant);
|
const char *ScopeForVariant(MPSiteVariant variant);
|
||||||
const MPElementType TypeWithName(const char *typeName);
|
const MPSiteType TypeWithName(const char *typeName);
|
||||||
const char *TemplateForType(MPElementType type, uint8_t seedByte);
|
const char *TemplateForType(MPSiteType type, uint8_t seedByte);
|
||||||
const char CharacterFromClass(char characterClass, uint8_t seedByte);
|
const char CharacterFromClass(char characterClass, uint8_t seedByte);
|
||||||
const char *IDForBuf(const void *buf, size_t length);
|
const char *IDForBuf(const void *buf, size_t length);
|
||||||
const char *Hex(const void *buf, size_t length);
|
const char *Hex(const void *buf, size_t length);
|
||||||
const char *Identicon(const char *userName, const char *masterPassword);
|
const char *Identicon(const char *fullName, const char *masterPassword);
|
||||||
|
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
package com.lyndir.masterpassword;
|
|
||||||
|
|
||||||
import com.lyndir.masterpassword.entity.*;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <i>07 04, 2012</i>
|
|
||||||
*
|
|
||||||
* @author lhunath
|
|
||||||
*/
|
|
||||||
public enum MPElementTypeClass {
|
|
||||||
|
|
||||||
Generated(MPElementGeneratedEntity.class),
|
|
||||||
Stored(MPElementStoredEntity.class);
|
|
||||||
|
|
||||||
private final Class<? extends MPElementEntity> entityClass;
|
|
||||||
|
|
||||||
MPElementTypeClass(final Class<? extends MPElementEntity> entityClass) {
|
|
||||||
|
|
||||||
this.entityClass = entityClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<? extends MPElementEntity> getEntityClass() {
|
|
||||||
|
|
||||||
return entityClass;
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,7 +5,7 @@ package com.lyndir.masterpassword;
|
|||||||
*
|
*
|
||||||
* @author lhunath
|
* @author lhunath
|
||||||
*/
|
*/
|
||||||
public enum MPElementFeature {
|
public enum MPSiteFeature {
|
||||||
|
|
||||||
/** Export the key-protected content data. */
|
/** Export the key-protected content data. */
|
||||||
ExportContent,
|
ExportContent,
|
@ -5,7 +5,6 @@ import com.google.common.collect.ImmutableSet;
|
|||||||
import com.lyndir.lhunath.opal.system.logging.Logger;
|
import com.lyndir.lhunath.opal.system.logging.Logger;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.annotation.Generated;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -13,14 +12,14 @@ import javax.annotation.Generated;
|
|||||||
*
|
*
|
||||||
* @author lhunath
|
* @author lhunath
|
||||||
*/
|
*/
|
||||||
public enum MPElementType {
|
public enum MPSiteType {
|
||||||
|
|
||||||
GeneratedMaximum( "20 characters, contains symbols.", //
|
GeneratedMaximum( "20 characters, contains symbols.", //
|
||||||
ImmutableList.of( "x", "max", "maximum" ), MPElementTypeClass.Generated, //
|
ImmutableList.of( "x", "max", "maximum" ), MPSiteTypeClass.Generated, //
|
||||||
ImmutableList.of( new MPTemplate( "anoxxxxxxxxxxxxxxxxx" ), new MPTemplate( "axxxxxxxxxxxxxxxxxno" ) ) ),
|
ImmutableList.of( new MPTemplate( "anoxxxxxxxxxxxxxxxxx" ), new MPTemplate( "axxxxxxxxxxxxxxxxxno" ) ) ),
|
||||||
|
|
||||||
GeneratedLong( "Copy-friendly, 14 characters, contains symbols.", //
|
GeneratedLong( "Copy-friendly, 14 characters, contains symbols.", //
|
||||||
ImmutableList.of( "l", "long" ), MPElementTypeClass.Generated, //
|
ImmutableList.of( "l", "long" ), MPSiteTypeClass.Generated, //
|
||||||
ImmutableList.of( new MPTemplate( "CvcvnoCvcvCvcv" ), new MPTemplate( "CvcvCvcvnoCvcv" ),
|
ImmutableList.of( new MPTemplate( "CvcvnoCvcvCvcv" ), new MPTemplate( "CvcvCvcvnoCvcv" ),
|
||||||
new MPTemplate( "CvcvCvcvCvcvno" ), new MPTemplate( "CvccnoCvcvCvcv" ),
|
new MPTemplate( "CvcvCvcvCvcvno" ), new MPTemplate( "CvccnoCvcvCvcv" ),
|
||||||
new MPTemplate( "CvccCvcvnoCvcv" ), new MPTemplate( "CvccCvcvCvcvno" ),
|
new MPTemplate( "CvccCvcvnoCvcv" ), new MPTemplate( "CvccCvcvCvcvno" ),
|
||||||
@ -34,56 +33,56 @@ public enum MPElementType {
|
|||||||
new MPTemplate( "CvccCvcvCvccno" ) ) ),
|
new MPTemplate( "CvccCvcvCvccno" ) ) ),
|
||||||
|
|
||||||
GeneratedMedium( "Copy-friendly, 8 characters, contains symbols.", //
|
GeneratedMedium( "Copy-friendly, 8 characters, contains symbols.", //
|
||||||
ImmutableList.of( "m", "med", "medium" ), MPElementTypeClass.Generated, //
|
ImmutableList.of( "m", "med", "medium" ), MPSiteTypeClass.Generated, //
|
||||||
ImmutableList.of( new MPTemplate( "CvcnoCvc" ), new MPTemplate( "CvcCvcno" ) ) ),
|
ImmutableList.of( new MPTemplate( "CvcnoCvc" ), new MPTemplate( "CvcCvcno" ) ) ),
|
||||||
|
|
||||||
GeneratedBasic( "8 characters, no symbols.", //
|
GeneratedBasic( "8 characters, no symbols.", //
|
||||||
ImmutableList.of( "b", "basic" ), MPElementTypeClass.Generated, //
|
ImmutableList.of( "b", "basic" ), MPSiteTypeClass.Generated, //
|
||||||
ImmutableList.of( new MPTemplate( "aaanaaan" ), new MPTemplate( "aannaaan" ), new MPTemplate( "aaannaaa" ) ) ),
|
ImmutableList.of( new MPTemplate( "aaanaaan" ), new MPTemplate( "aannaaan" ), new MPTemplate( "aaannaaa" ) ) ),
|
||||||
|
|
||||||
GeneratedShort( "Copy-friendly, 4 characters, no symbols.", //
|
GeneratedShort( "Copy-friendly, 4 characters, no symbols.", //
|
||||||
ImmutableList.of( "s", "short" ), MPElementTypeClass.Generated, //
|
ImmutableList.of( "s", "short" ), MPSiteTypeClass.Generated, //
|
||||||
ImmutableList.of( new MPTemplate( "Cvcn" ) ) ),
|
ImmutableList.of( new MPTemplate( "Cvcn" ) ) ),
|
||||||
|
|
||||||
GeneratedPIN( "4 numbers.", //
|
GeneratedPIN( "4 numbers.", //
|
||||||
ImmutableList.of( "i", "pin" ), MPElementTypeClass.Generated, //
|
ImmutableList.of( "i", "pin" ), MPSiteTypeClass.Generated, //
|
||||||
ImmutableList.of( new MPTemplate( "nnnn" ) ) ),
|
ImmutableList.of( new MPTemplate( "nnnn" ) ) ),
|
||||||
|
|
||||||
GeneratedName( "9 letter name.", //
|
GeneratedName( "9 letter name.", //
|
||||||
ImmutableList.of( "n", "name" ), MPElementTypeClass.Generated, //
|
ImmutableList.of( "n", "name" ), MPSiteTypeClass.Generated, //
|
||||||
ImmutableList.of( new MPTemplate( "cvccvcvcv" ) ) ),
|
ImmutableList.of( new MPTemplate( "cvccvcvcv" ) ) ),
|
||||||
|
|
||||||
GeneratedPhrase( "20 character sentence.", //
|
GeneratedPhrase( "20 character sentence.", //
|
||||||
ImmutableList.of( "p", "phrase" ), MPElementTypeClass.Generated, //
|
ImmutableList.of( "p", "phrase" ), MPSiteTypeClass.Generated, //
|
||||||
ImmutableList.of( new MPTemplate( "cvcc cvc cvccvcv cvc" ), new MPTemplate( "cvc cvccvcvcv cvcv" ),
|
ImmutableList.of( new MPTemplate( "cvcc cvc cvccvcv cvc" ), new MPTemplate( "cvc cvccvcvcv cvcv" ),
|
||||||
new MPTemplate( "cv cvccv cvc cvcvccv" ) ) ),
|
new MPTemplate( "cv cvccv cvc cvcvccv" ) ) ),
|
||||||
|
|
||||||
StoredPersonal( "AES-encrypted, exportable.", //
|
StoredPersonal( "AES-encrypted, exportable.", //
|
||||||
ImmutableList.of( "personal" ), MPElementTypeClass.Stored, //
|
ImmutableList.of( "personal" ), MPSiteTypeClass.Stored, //
|
||||||
ImmutableList.<MPTemplate>of(), MPElementFeature.ExportContent ),
|
ImmutableList.<MPTemplate>of(), MPSiteFeature.ExportContent ),
|
||||||
|
|
||||||
StoredDevicePrivate( "AES-encrypted, not exported.", //
|
StoredDevicePrivate( "AES-encrypted, not exported.", //
|
||||||
ImmutableList.of( "device" ), MPElementTypeClass.Stored, //
|
ImmutableList.of( "device" ), MPSiteTypeClass.Stored, //
|
||||||
ImmutableList.<MPTemplate>of(), MPElementFeature.DevicePrivate );
|
ImmutableList.<MPTemplate>of(), MPSiteFeature.DevicePrivate );
|
||||||
|
|
||||||
static final Logger logger = Logger.get( MPElementType.class );
|
static final Logger logger = Logger.get( MPSiteType.class );
|
||||||
|
|
||||||
private final String description;
|
private final String description;
|
||||||
private final List<String> options;
|
private final List<String> options;
|
||||||
private final MPElementTypeClass typeClass;
|
private final MPSiteTypeClass typeClass;
|
||||||
private final List<MPTemplate> templates;
|
private final List<MPTemplate> templates;
|
||||||
private final Set<MPElementFeature> typeFeatures;
|
private final Set<MPSiteFeature> typeFeatures;
|
||||||
|
|
||||||
MPElementType(final String description, final List<String> options, final MPElementTypeClass typeClass,
|
MPSiteType(final String description, final List<String> options, final MPSiteTypeClass typeClass, final List<MPTemplate> templates,
|
||||||
final List<MPTemplate> templates, final MPElementFeature... typeFeatures) {
|
final MPSiteFeature... typeFeatures) {
|
||||||
|
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.typeClass = typeClass;
|
this.typeClass = typeClass;
|
||||||
this.templates = templates;
|
this.templates = templates;
|
||||||
|
|
||||||
ImmutableSet.Builder<MPElementFeature> typeFeaturesBuilder = ImmutableSet.builder();
|
ImmutableSet.Builder<MPSiteFeature> typeFeaturesBuilder = ImmutableSet.builder();
|
||||||
for (final MPElementFeature typeFeature : typeFeatures) {
|
for (final MPSiteFeature typeFeature : typeFeatures) {
|
||||||
typeFeaturesBuilder.add( typeFeature );
|
typeFeaturesBuilder.add( typeFeature );
|
||||||
}
|
}
|
||||||
this.typeFeatures = typeFeaturesBuilder.build();
|
this.typeFeatures = typeFeaturesBuilder.build();
|
||||||
@ -98,12 +97,12 @@ public enum MPElementType {
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MPElementTypeClass getTypeClass() {
|
public MPSiteTypeClass getTypeClass() {
|
||||||
|
|
||||||
return typeClass;
|
return typeClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<MPElementFeature> getTypeFeatures() {
|
public Set<MPSiteFeature> getTypeFeatures() {
|
||||||
|
|
||||||
return typeFeatures;
|
return typeFeatures;
|
||||||
}
|
}
|
||||||
@ -113,9 +112,9 @@ public enum MPElementType {
|
|||||||
*
|
*
|
||||||
* @return The type registered for the given option.
|
* @return The type registered for the given option.
|
||||||
*/
|
*/
|
||||||
public static MPElementType forOption(final String option) {
|
public static MPSiteType forOption(final String option) {
|
||||||
|
|
||||||
for (final MPElementType type : values())
|
for (final MPSiteType type : values())
|
||||||
if (type.getOptions().contains( option.toLowerCase() ))
|
if (type.getOptions().contains( option.toLowerCase() ))
|
||||||
return type;
|
return type;
|
||||||
|
|
||||||
@ -127,12 +126,12 @@ public enum MPElementType {
|
|||||||
*
|
*
|
||||||
* @return The type registered with the given name.
|
* @return The type registered with the given name.
|
||||||
*/
|
*/
|
||||||
public static MPElementType forName(final String name) {
|
public static MPSiteType forName(final String name) {
|
||||||
|
|
||||||
if (name == null)
|
if (name == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
for (final MPElementType type : values())
|
for (final MPSiteType type : values())
|
||||||
if (type.name().equalsIgnoreCase( name ))
|
if (type.name().equalsIgnoreCase( name ))
|
||||||
return type;
|
return type;
|
||||||
|
|
||||||
@ -144,10 +143,10 @@ public enum MPElementType {
|
|||||||
*
|
*
|
||||||
* @return All types that support the given class.
|
* @return All types that support the given class.
|
||||||
*/
|
*/
|
||||||
public static ImmutableList<MPElementType> forClass(final MPElementTypeClass typeClass) {
|
public static ImmutableList<MPSiteType> forClass(final MPSiteTypeClass typeClass) {
|
||||||
|
|
||||||
ImmutableList.Builder<MPElementType> types = ImmutableList.builder();
|
ImmutableList.Builder<MPSiteType> types = ImmutableList.builder();
|
||||||
for (final MPElementType type : values())
|
for (final MPSiteType type : values())
|
||||||
if (type.getTypeClass() == typeClass)
|
if (type.getTypeClass() == typeClass)
|
||||||
types.add( type );
|
types.add( type );
|
||||||
|
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.lyndir.masterpassword;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <i>07 04, 2012</i>
|
||||||
|
*
|
||||||
|
* @author lhunath
|
||||||
|
*/
|
||||||
|
public enum MPSiteTypeClass {
|
||||||
|
Generated,
|
||||||
|
Stored
|
||||||
|
}
|
@ -8,7 +8,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author lhunath, 14-12-02
|
* @author lhunath, 14-12-02
|
||||||
*/
|
*/
|
||||||
public enum MPElementVariant {
|
public enum MPSiteVariant {
|
||||||
Password( "The password to log in with.", "Doesn't currently use a context.", //
|
Password( "The password to log in with.", "Doesn't currently use a context.", //
|
||||||
ImmutableList.of( "p", "password" ), "com.lyndir.masterpassword" ),
|
ImmutableList.of( "p", "password" ), "com.lyndir.masterpassword" ),
|
||||||
Login( "The username to log in as.", "Doesn't currently use a context.", //
|
Login( "The username to log in as.", "Doesn't currently use a context.", //
|
||||||
@ -16,14 +16,14 @@ public enum MPElementVariant {
|
|||||||
Answer( "The answer to a security question.", "Empty for a universal site answer or\nthe most significant word(s) of the question.", //
|
Answer( "The answer to a security question.", "Empty for a universal site answer or\nthe most significant word(s) of the question.", //
|
||||||
ImmutableList.of( "a", "answer" ), "com.lyndir.masterpassword.answer" );
|
ImmutableList.of( "a", "answer" ), "com.lyndir.masterpassword.answer" );
|
||||||
|
|
||||||
static final Logger logger = Logger.get( MPElementType.class );
|
static final Logger logger = Logger.get( MPSiteType.class );
|
||||||
|
|
||||||
private final String description;
|
private final String description;
|
||||||
private final String contextDescription;
|
private final String contextDescription;
|
||||||
private final List<String> options;
|
private final List<String> options;
|
||||||
private final String scope;
|
private final String scope;
|
||||||
|
|
||||||
MPElementVariant(final String description, final String contextDescription, final List<String> options, final String scope) {
|
MPSiteVariant(final String description, final String contextDescription, final List<String> options, final String scope) {
|
||||||
this.contextDescription = contextDescription;
|
this.contextDescription = contextDescription;
|
||||||
|
|
||||||
this.options = options;
|
this.options = options;
|
||||||
@ -52,9 +52,9 @@ public enum MPElementVariant {
|
|||||||
*
|
*
|
||||||
* @return The variant registered for the given option.
|
* @return The variant registered for the given option.
|
||||||
*/
|
*/
|
||||||
public static MPElementVariant forOption(final String option) {
|
public static MPSiteVariant forOption(final String option) {
|
||||||
|
|
||||||
for (final MPElementVariant variant : values())
|
for (final MPSiteVariant variant : values())
|
||||||
if (variant.getOptions().contains( option.toLowerCase() ))
|
if (variant.getOptions().contains( option.toLowerCase() ))
|
||||||
return variant;
|
return variant;
|
||||||
|
|
||||||
@ -65,12 +65,12 @@ public enum MPElementVariant {
|
|||||||
*
|
*
|
||||||
* @return The variant registered with the given name.
|
* @return The variant registered with the given name.
|
||||||
*/
|
*/
|
||||||
public static MPElementVariant forName(final String name) {
|
public static MPSiteVariant forName(final String name) {
|
||||||
|
|
||||||
if (name == null)
|
if (name == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
for (final MPElementVariant type : values())
|
for (final MPSiteVariant type : values())
|
||||||
if (type.name().equalsIgnoreCase( name ))
|
if (type.name().equalsIgnoreCase( name ))
|
||||||
return type;
|
return type;
|
||||||
|
|
@ -4,7 +4,6 @@ import com.google.common.base.Charsets;
|
|||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.primitives.Bytes;
|
import com.google.common.primitives.Bytes;
|
||||||
import com.lambdaworks.crypto.SCrypt;
|
import com.lambdaworks.crypto.SCrypt;
|
||||||
import com.lyndir.lhunath.opal.crypto.CryptUtils;
|
|
||||||
import com.lyndir.lhunath.opal.system.*;
|
import com.lyndir.lhunath.opal.system.*;
|
||||||
import com.lyndir.lhunath.opal.system.logging.Logger;
|
import com.lyndir.lhunath.opal.system.logging.Logger;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -32,22 +31,22 @@ public class MasterKey {
|
|||||||
private static final MessageDigests MP_hash = MessageDigests.SHA256;
|
private static final MessageDigests MP_hash = MessageDigests.SHA256;
|
||||||
private static final MessageAuthenticationDigests MP_mac = MessageAuthenticationDigests.HmacSHA256;
|
private static final MessageAuthenticationDigests MP_mac = MessageAuthenticationDigests.HmacSHA256;
|
||||||
|
|
||||||
private final String userName;
|
private final String fullName;
|
||||||
private final byte[] masterKey;
|
private final byte[] masterKey;
|
||||||
|
|
||||||
private boolean valid;
|
private boolean valid;
|
||||||
|
|
||||||
public MasterKey(final String userName, final String masterPassword) {
|
public MasterKey(final String fullName, final String masterPassword) {
|
||||||
|
|
||||||
this.userName = userName;
|
this.fullName = fullName;
|
||||||
logger.trc( "userName: %s", userName );
|
logger.trc( "fullName: %s", fullName );
|
||||||
logger.trc( "masterPassword: %s", masterPassword );
|
logger.trc( "masterPassword: %s", masterPassword );
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
byte[] userNameBytes = userName.getBytes( MP_charset );
|
byte[] userNameBytes = fullName.getBytes( MP_charset );
|
||||||
byte[] userNameLengthBytes = bytesForInt( userNameBytes.length );
|
byte[] userNameLengthBytes = bytesForInt( userNameBytes.length );
|
||||||
|
|
||||||
String mpKeyScope = MPElementVariant.Password.getScope();
|
String mpKeyScope = MPSiteVariant.Password.getScope();
|
||||||
byte[] masterKeySalt = Bytes.concat( mpKeyScope.getBytes( MP_charset ), userNameLengthBytes, userNameBytes );
|
byte[] masterKeySalt = Bytes.concat( mpKeyScope.getBytes( MP_charset ), userNameLengthBytes, userNameBytes );
|
||||||
logger.trc( "key scope: %s", mpKeyScope );
|
logger.trc( "key scope: %s", mpKeyScope );
|
||||||
logger.trc( "masterKeySalt ID: %s", idForBytes( masterKeySalt ) );
|
logger.trc( "masterKeySalt ID: %s", idForBytes( masterKeySalt ) );
|
||||||
@ -63,9 +62,9 @@ public class MasterKey {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUserName() {
|
public String getFullName() {
|
||||||
|
|
||||||
return userName;
|
return fullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKeyID() {
|
public String getKeyID() {
|
||||||
@ -74,7 +73,7 @@ public class MasterKey {
|
|||||||
return idForBytes( masterKey );
|
return idForBytes( masterKey );
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] getSubkey(final int subkeyLength) {
|
private byte[] getSubKey(final int subkeyLength) {
|
||||||
|
|
||||||
Preconditions.checkState( valid );
|
Preconditions.checkState( valid );
|
||||||
byte[] subkey = new byte[Math.min( subkeyLength, masterKey.length )];
|
byte[] subkey = new byte[Math.min( subkeyLength, masterKey.length )];
|
||||||
@ -83,10 +82,10 @@ public class MasterKey {
|
|||||||
return subkey;
|
return subkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String encode(final String siteName, final MPElementType siteType, int siteCounter, final MPElementVariant siteVariant,
|
public String encode(final String siteName, final MPSiteType siteType, int siteCounter, final MPSiteVariant siteVariant,
|
||||||
@Nullable final String siteContext) {
|
@Nullable final String siteContext) {
|
||||||
Preconditions.checkState( valid );
|
Preconditions.checkState( valid );
|
||||||
Preconditions.checkArgument( siteType.getTypeClass() == MPElementTypeClass.Generated );
|
Preconditions.checkArgument( siteType.getTypeClass() == MPSiteTypeClass.Generated );
|
||||||
Preconditions.checkArgument( !siteName.isEmpty() );
|
Preconditions.checkArgument( !siteName.isEmpty() );
|
||||||
|
|
||||||
logger.trc( "siteName: %s", siteName );
|
logger.trc( "siteName: %s", siteName );
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
package com.lyndir.masterpassword.entity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <i>07 04, 2012</i>
|
|
||||||
*
|
|
||||||
* @author lhunath
|
|
||||||
*/
|
|
||||||
public class MPElementEntity {
|
|
||||||
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package com.lyndir.masterpassword.entity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <i>07 04, 2012</i>
|
|
||||||
*
|
|
||||||
* @author lhunath
|
|
||||||
*/
|
|
||||||
public class MPElementGeneratedEntity extends MPElementEntity {
|
|
||||||
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package com.lyndir.masterpassword.entity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <i>07 04, 2012</i>
|
|
||||||
*
|
|
||||||
* @author lhunath
|
|
||||||
*/
|
|
||||||
public class MPElementStoredEntity extends MPElementEntity {
|
|
||||||
|
|
||||||
}
|
|
@ -2,9 +2,7 @@ package com.lyndir.masterpassword;
|
|||||||
|
|
||||||
import static com.lyndir.lhunath.opal.system.util.ObjectUtils.*;
|
import static com.lyndir.lhunath.opal.system.util.ObjectUtils.*;
|
||||||
|
|
||||||
import com.google.common.base.Verify;
|
|
||||||
import com.lyndir.lhunath.opal.system.logging.Logger;
|
import com.lyndir.lhunath.opal.system.logging.Logger;
|
||||||
import com.lyndir.lhunath.opal.system.util.NFunctionNN;
|
|
||||||
import com.lyndir.lhunath.opal.system.util.NNSupplier;
|
import com.lyndir.lhunath.opal.system.util.NNSupplier;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -165,12 +163,12 @@ public class MPWTests {
|
|||||||
return siteCounter;
|
return siteCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MPElementType getSiteType() {
|
public MPSiteType getSiteType() {
|
||||||
return MPElementType.forName( siteType );
|
return MPSiteType.forName( siteType );
|
||||||
}
|
}
|
||||||
|
|
||||||
public MPElementVariant getSiteVariant() {
|
public MPSiteVariant getSiteVariant() {
|
||||||
return MPElementVariant.forName( siteVariant );
|
return MPSiteVariant.forName( siteVariant );
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSiteContext() {
|
public String getSiteContext() {
|
||||||
|
@ -6,7 +6,6 @@ import com.google.common.io.Resources;
|
|||||||
import com.lyndir.lhunath.opal.system.logging.Logger;
|
import com.lyndir.lhunath.opal.system.logging.Logger;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.Unmarshaller;
|
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
@ -46,7 +45,7 @@ public class MasterKeyTest {
|
|||||||
public void testGetUserName()
|
public void testGetUserName()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
assertEquals( new MasterKey( defaultCase.getFullName(), defaultCase.getMasterPassword() ).getUserName(),
|
assertEquals( new MasterKey( defaultCase.getFullName(), defaultCase.getMasterPassword() ).getFullName(),
|
||||||
defaultCase.getFullName() );
|
defaultCase.getFullName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,8 +87,8 @@ public class EmergencyActivity extends Activity {
|
|||||||
sitePasswordField.setPaintFlags( userNameField.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG );
|
sitePasswordField.setPaintFlags( userNameField.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG );
|
||||||
|
|
||||||
typeField.setAdapter(
|
typeField.setAdapter(
|
||||||
new ArrayAdapter<MPElementType>( this, R.layout.type_item, MPElementType.forClass( MPElementTypeClass.Generated ) ) );
|
new ArrayAdapter<MPSiteType>( this, R.layout.type_item, MPSiteType.forClass( MPSiteTypeClass.Generated ) ) );
|
||||||
typeField.setSelection( MPElementType.GeneratedLong.ordinal() );
|
typeField.setSelection( MPSiteType.GeneratedLong.ordinal() );
|
||||||
|
|
||||||
counterField.setMinValue( 1 );
|
counterField.setMinValue( 1 );
|
||||||
counterField.setMaxValue( Integer.MAX_VALUE );
|
counterField.setMaxValue( Integer.MAX_VALUE );
|
||||||
@ -170,7 +170,7 @@ public class EmergencyActivity extends Activity {
|
|||||||
|
|
||||||
private void updateSitePassword() {
|
private void updateSitePassword() {
|
||||||
final String siteName = siteNameField.getText().toString();
|
final String siteName = siteNameField.getText().toString();
|
||||||
final MPElementType type = (MPElementType) typeField.getSelectedItem();
|
final MPSiteType type = (MPSiteType) typeField.getSelectedItem();
|
||||||
final int counter = counterField.getValue();
|
final int counter = counterField.getValue();
|
||||||
|
|
||||||
if (masterKeyFuture == null || siteName.isEmpty() || type == null) {
|
if (masterKeyFuture == null || siteName.isEmpty() || type == null) {
|
||||||
|
@ -48,8 +48,8 @@ public class CLI {
|
|||||||
String siteName = null, masterPassword, context = null;
|
String siteName = null, masterPassword, context = null;
|
||||||
String userName = System.getenv( ENV_USERNAME );
|
String userName = System.getenv( ENV_USERNAME );
|
||||||
String siteTypeName = ifNotNullElse( System.getenv( ENV_SITETYPE ), "" );
|
String siteTypeName = ifNotNullElse( System.getenv( ENV_SITETYPE ), "" );
|
||||||
MPElementType siteType = siteTypeName.isEmpty()? MPElementType.GeneratedLong: MPElementType.forOption( siteTypeName );
|
MPSiteType siteType = siteTypeName.isEmpty()? MPSiteType.GeneratedLong: MPSiteType.forOption( siteTypeName );
|
||||||
MPElementVariant variant = MPElementVariant.Password;
|
MPSiteVariant variant = MPSiteVariant.Password;
|
||||||
String siteCounterName = ifNotNullElse( System.getenv( ENV_SITECOUNTER ), "" );
|
String siteCounterName = ifNotNullElse( System.getenv( ENV_SITECOUNTER ), "" );
|
||||||
int siteCounter = siteCounterName.isEmpty()? 1: Integer.parseInt( siteCounterName );
|
int siteCounter = siteCounterName.isEmpty()? 1: Integer.parseInt( siteCounterName );
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ public class CLI {
|
|||||||
else if ("-t".equals( arg ) || "--type".equals( arg ))
|
else if ("-t".equals( arg ) || "--type".equals( arg ))
|
||||||
typeArg = true;
|
typeArg = true;
|
||||||
else if (typeArg) {
|
else if (typeArg) {
|
||||||
siteType = MPElementType.forOption( arg );
|
siteType = MPSiteType.forOption( arg );
|
||||||
typeArg = false;
|
typeArg = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ public class CLI {
|
|||||||
else if ("-v".equals( arg ) || "--variant".equals( arg ))
|
else if ("-v".equals( arg ) || "--variant".equals( arg ))
|
||||||
variantArg = true;
|
variantArg = true;
|
||||||
else if (variantArg) {
|
else if (variantArg) {
|
||||||
variant = MPElementVariant.forOption( arg );
|
variant = MPSiteVariant.forOption( arg );
|
||||||
variantArg = false;
|
variantArg = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,13 +106,13 @@ public class CLI {
|
|||||||
System.out.format( " Defaults to %s in env or 'long' for password, 'name' for login.\n", ENV_SITETYPE );
|
System.out.format( " Defaults to %s in env or 'long' for password, 'name' for login.\n", ENV_SITETYPE );
|
||||||
|
|
||||||
int optionsLength = 0;
|
int optionsLength = 0;
|
||||||
Map<String, MPElementType> typeMap = Maps.newLinkedHashMap();
|
Map<String, MPSiteType> typeMap = Maps.newLinkedHashMap();
|
||||||
for (MPElementType elementType : MPElementType.values()) {
|
for (MPSiteType elementType : MPSiteType.values()) {
|
||||||
String options = Joiner.on( ", " ).join( elementType.getOptions() );
|
String options = Joiner.on( ", " ).join( elementType.getOptions() );
|
||||||
typeMap.put( options, elementType );
|
typeMap.put( options, elementType );
|
||||||
optionsLength = Math.max( optionsLength, options.length() );
|
optionsLength = Math.max( optionsLength, options.length() );
|
||||||
}
|
}
|
||||||
for (Map.Entry<String, MPElementType> entry : typeMap.entrySet()) {
|
for (Map.Entry<String, MPSiteType> entry : typeMap.entrySet()) {
|
||||||
String infoString = strf( " -v %" + optionsLength + "s | ", entry.getKey() );
|
String infoString = strf( " -v %" + optionsLength + "s | ", entry.getKey() );
|
||||||
String infoNewline = "\n" + StringUtils.repeat( " ", infoString.length() - 3 ) + " | ";
|
String infoNewline = "\n" + StringUtils.repeat( " ", infoString.length() - 3 ) + " | ";
|
||||||
infoString += entry.getValue().getDescription().replaceAll( "\n", infoNewline );
|
infoString += entry.getValue().getDescription().replaceAll( "\n", infoNewline );
|
||||||
@ -126,13 +126,13 @@ public class CLI {
|
|||||||
System.out.format( " Defaults to 'password'.\n" );
|
System.out.format( " Defaults to 'password'.\n" );
|
||||||
|
|
||||||
optionsLength = 0;
|
optionsLength = 0;
|
||||||
Map<String, MPElementVariant> variantMap = Maps.newLinkedHashMap();
|
Map<String, MPSiteVariant> variantMap = Maps.newLinkedHashMap();
|
||||||
for (MPElementVariant elementVariant : MPElementVariant.values()) {
|
for (MPSiteVariant elementVariant : MPSiteVariant.values()) {
|
||||||
String options = Joiner.on( ", " ).join( elementVariant.getOptions() );
|
String options = Joiner.on( ", " ).join( elementVariant.getOptions() );
|
||||||
variantMap.put( options, elementVariant );
|
variantMap.put( options, elementVariant );
|
||||||
optionsLength = Math.max( optionsLength, options.length() );
|
optionsLength = Math.max( optionsLength, options.length() );
|
||||||
}
|
}
|
||||||
for (Map.Entry<String, MPElementVariant> entry : variantMap.entrySet()) {
|
for (Map.Entry<String, MPSiteVariant> entry : variantMap.entrySet()) {
|
||||||
String infoString = strf( " -v %" + optionsLength + "s | ", entry.getKey() );
|
String infoString = strf( " -v %" + optionsLength + "s | ", entry.getKey() );
|
||||||
String infoNewline = "\n" + StringUtils.repeat( " ", infoString.length() - 3 ) + " | ";
|
String infoNewline = "\n" + StringUtils.repeat( " ", infoString.length() - 3 ) + " | ";
|
||||||
infoString += entry.getValue().getDescription().replaceAll( "\n", infoNewline );
|
infoString += entry.getValue().getDescription().replaceAll( "\n", infoNewline );
|
||||||
@ -142,7 +142,7 @@ public class CLI {
|
|||||||
|
|
||||||
System.out.format( " -C context A variant-specific context.\n" );
|
System.out.format( " -C context A variant-specific context.\n" );
|
||||||
System.out.format( " Defaults to empty.\n" );
|
System.out.format( " Defaults to empty.\n" );
|
||||||
for (Map.Entry<String, MPElementVariant> entry : variantMap.entrySet()) {
|
for (Map.Entry<String, MPSiteVariant> entry : variantMap.entrySet()) {
|
||||||
String infoString = strf( " -v %" + optionsLength + "s | ", entry.getKey() );
|
String infoString = strf( " -v %" + optionsLength + "s | ", entry.getKey() );
|
||||||
String infoNewline = "\n" + StringUtils.repeat( " ", infoString.length() - 3 ) + " | ";
|
String infoNewline = "\n" + StringUtils.repeat( " ", infoString.length() - 3 ) + " | ";
|
||||||
infoString += entry.getValue().getContextDescription().replaceAll( "\n", infoNewline );
|
infoString += entry.getValue().getContextDescription().replaceAll( "\n", infoNewline );
|
||||||
|
@ -17,12 +17,12 @@ import javax.swing.event.*;
|
|||||||
*/
|
*/
|
||||||
public class PasswordFrame extends JFrame implements DocumentListener {
|
public class PasswordFrame extends JFrame implements DocumentListener {
|
||||||
|
|
||||||
private final User user;
|
private final User user;
|
||||||
private final JTextField siteNameField;
|
private final JTextField siteNameField;
|
||||||
private final JComboBox<MPElementType> siteTypeField;
|
private final JComboBox<MPSiteType> siteTypeField;
|
||||||
private final JSpinner siteCounterField;
|
private final JSpinner siteCounterField;
|
||||||
private final JTextField passwordField;
|
private final JTextField passwordField;
|
||||||
private final JLabel tipLabel;
|
private final JLabel tipLabel;
|
||||||
|
|
||||||
public PasswordFrame(User user)
|
public PasswordFrame(User user)
|
||||||
throws HeadlessException {
|
throws HeadlessException {
|
||||||
@ -89,7 +89,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
// Site Type & Counter
|
// Site Type & Counter
|
||||||
MPElementType[] types = Iterables.toArray( MPElementType.forClass( MPElementTypeClass.Generated ), MPElementType.class );
|
MPSiteType[] types = Iterables.toArray( MPSiteType.forClass( MPSiteTypeClass.Generated ), MPSiteType.class );
|
||||||
JComponent siteSettings = Components.boxLayout( BoxLayout.LINE_AXIS, //
|
JComponent siteSettings = Components.boxLayout( BoxLayout.LINE_AXIS, //
|
||||||
siteTypeField = new JComboBox<>( types ), //
|
siteTypeField = new JComboBox<>( types ), //
|
||||||
siteCounterField = new JSpinner(
|
siteCounterField = new JSpinner(
|
||||||
@ -104,7 +104,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
|||||||
siteTypeField.setFont( Res.exoRegular().deriveFont( 12f ) );
|
siteTypeField.setFont( Res.exoRegular().deriveFont( 12f ) );
|
||||||
siteTypeField.setAlignmentX( LEFT_ALIGNMENT );
|
siteTypeField.setAlignmentX( LEFT_ALIGNMENT );
|
||||||
siteTypeField.setAlignmentY( CENTER_ALIGNMENT );
|
siteTypeField.setAlignmentY( CENTER_ALIGNMENT );
|
||||||
siteTypeField.setSelectedItem( MPElementType.GeneratedLong );
|
siteTypeField.setSelectedItem( MPSiteType.GeneratedLong );
|
||||||
siteTypeField.addItemListener( new ItemListener() {
|
siteTypeField.addItemListener( new ItemListener() {
|
||||||
@Override
|
@Override
|
||||||
public void itemStateChanged(final ItemEvent e) {
|
public void itemStateChanged(final ItemEvent e) {
|
||||||
@ -146,11 +146,11 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updatePassword(final PasswordCallback callback) {
|
private void updatePassword(final PasswordCallback callback) {
|
||||||
final MPElementType siteType = (MPElementType) siteTypeField.getSelectedItem();
|
final MPSiteType siteType = (MPSiteType) siteTypeField.getSelectedItem();
|
||||||
final String siteName = siteNameField.getText();
|
final String siteName = siteNameField.getText();
|
||||||
final int siteCounter = (Integer) siteCounterField.getValue();
|
final int siteCounter = (Integer) siteCounterField.getValue();
|
||||||
|
|
||||||
if (siteType.getTypeClass() != MPElementTypeClass.Generated || siteName == null || siteName.isEmpty() || !user.hasKey()) {
|
if (siteType.getTypeClass() != MPSiteTypeClass.Generated || siteName == null || siteName.isEmpty() || !user.hasKey()) {
|
||||||
passwordField.setText( null );
|
passwordField.setText( null );
|
||||||
tipLabel.setText( null );
|
tipLabel.setText( null );
|
||||||
return;
|
return;
|
||||||
@ -159,7 +159,7 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
|||||||
Res.execute( new Runnable() {
|
Res.execute( new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final String sitePassword = user.getKey().encode( siteName, siteType, siteCounter, MPElementVariant.Password, null );
|
final String sitePassword = user.getKey().encode( siteName, siteType, siteCounter, MPSiteVariant.Password, null );
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.passwordGenerated( siteName, sitePassword );
|
callback.passwordGenerated( siteName, sitePassword );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user