From 17d38235a198eb006f073024dfef680467524e91 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Fri, 21 Nov 2014 01:30:47 -0500 Subject: [PATCH] Initial test of identicon support. --- MasterPassword/C/build | 4 ++-- MasterPassword/C/mpw.c | 3 +++ MasterPassword/C/types.c | 48 ++++++++++++++++++++++++++++++++++++++++ MasterPassword/C/types.h | 1 + 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/MasterPassword/C/build b/MasterPassword/C/build index 90525aa4..135452da 100755 --- a/MasterPassword/C/build +++ b/MasterPassword/C/build @@ -191,7 +191,7 @@ mpw() { # library paths -L"." -L"lib/scrypt" # link libraries - -l"crypto" + -l"crypto" -l"curses" # scrypt "lib/scrypt/scrypt-crypto_aesctr.o" "lib/scrypt/scrypt-sha256.o" @@ -248,7 +248,7 @@ mpw-bench() { ### TARGETS haslib() { - LC_ALL=C cc -l"$1" 2>&1 | ! grep -q 'library not found' + ! LC_ALL=C cc -l"$1" 2>&1 | grep -q 'library not found' } cc() { if hash llvm-gcc 2>/dev/null; then diff --git a/MasterPassword/C/mpw.c b/MasterPassword/C/mpw.c index ea286d12..73ce75f4 100644 --- a/MasterPassword/C/mpw.c +++ b/MasterPassword/C/mpw.c @@ -221,6 +221,9 @@ int main(int argc, char *const argv[]) { masterPassword = getpass( "Your master password: " ); trc("masterPassword: %s\n", masterPassword); + // Summarize operation. + fprintf(stderr, "%s's password for %s:\n[ %s ]: ", userName, siteName, Identicon( userName, masterPassword )); + // Calculate the master key salt. const char *mpKeyScope = ScopeForVariant(MPElementVariantPassword); trc("key scope: %s\n", mpKeyScope); diff --git a/MasterPassword/C/types.c b/MasterPassword/C/types.c index 5eaf7104..fc342a9f 100644 --- a/MasterPassword/C/types.c +++ b/MasterPassword/C/types.c @@ -10,9 +10,13 @@ #include #include #include +#include #include +#include +#include + #include "types.h" const MPElementType TypeWithName(const char *typeName) { @@ -171,6 +175,7 @@ const char CharacterFromClass(char characterClass, uint8_t seedByte) { return classCharacters[seedByte % strlen(classCharacters)]; } + const char *IDForBuf(const void *buf, size_t length) { uint8_t hash[32]; SHA256_Buf(buf, length, hash); @@ -186,5 +191,48 @@ const char *Hex(const void *buf, size_t length) { char *id = (char *)calloc(length*2+1, sizeof(char)); for (int kH = 0; kH < length; kH++) sprintf(&(id[kH * 2]), "%02X", ((const uint8_t*)buf)[kH]); + return id; } + +int putvari; +char *putvarc = NULL; +static void initputvar() { + if (putvarc) + free(putvarc); + putvari=0; + putvarc=(char *)calloc(256, sizeof(char)); +} +static int putvar(int c) { + putvarc[putvari++]=c; + return 0; +} + +const char *Identicon(const char *userName, const char *masterPassword) { + const char *left[] = { "╔", "╚", "╰", "═" }; + const char *right[] = { "╗", "╝", "╯", "═" }; + const char *body[] = { "█", "░", "▒", "▓", "☺", "☻" }; + const char *accessory[] = { "◈", "◎", "◐", "◑", "◒", "◓", "☀", "☁", "☂", "☃", "☄", "★", "☆", "☎", "☏", "⎈", "⌂", "☘", "☢", "☣", "☕", "⌚", "⌛", "⏰", "⚡", "⛄", "⛅", "☔", "♔", "♕", "♖", "♗", "♘", "♙", "♚", "♛", "♜", "♝", "♞", "♟", "♨", "♩", "♪", "♫", "⚐", "⚑", "⚔", "⚖", "⚙", "⚠", "⌘", "⏎", "✄", "✆", "✈", "✉", "✌" }; + + uint8_t identiconSeed[32]; + HMAC_SHA256_Buf(masterPassword, strlen(masterPassword), userName, strlen(userName), identiconSeed); + + char *identicon = (char *)calloc(20, sizeof(char)); + setupterm(NULL, 2, NULL); + initputvar(); + tputs(tparm(tgetstr("AF", NULL), identiconSeed[4] % 7 + 1), 1, putvar); + char red[strlen(putvarc)]; + strcpy(red, putvarc); + tputs(tgetstr("me", NULL), 1, putvar); + char reset[strlen(putvarc)]; + strcpy(reset, putvarc); + sprintf(identicon, "%s%s%s%s%s%s", + red, + left[identiconSeed[0] % (sizeof(left) / sizeof(left[0]))], + body[identiconSeed[1] % (sizeof(body) / sizeof(body[0]))], + right[identiconSeed[2] % (sizeof(right) / sizeof(right[0]))], + accessory[identiconSeed[3] % (sizeof(accessory) / sizeof(accessory[0]))], + reset); + + return identicon; +} diff --git a/MasterPassword/C/types.h b/MasterPassword/C/types.h index 4cde84c9..c3ef0b61 100644 --- a/MasterPassword/C/types.h +++ b/MasterPassword/C/types.h @@ -56,4 +56,5 @@ const char *CipherForType(MPElementType type, uint8_t seedByte); const char CharacterFromClass(char characterClass, uint8_t seedByte); const char *IDForBuf(const void *buf, size_t length); const char *Hex(const void *buf, size_t length); +const char *Identicon(const char *userName, const char *masterPassword);