2
0

Copy TOTP counter support to v2 override.

This commit is contained in:
Maarten Billemont 2017-08-30 09:54:16 -04:00
parent 6fa8ee53cd
commit 6f4f6b8d1e
4 changed files with 19 additions and 10 deletions

View File

@ -73,7 +73,7 @@ static MPMasterKey mpw_masterKey_v0(
MPMasterKey masterKey = mpw_kdf_scrypt( MPMasterKeySize, masterPassword, masterKeySalt, masterKeySaltSize, MP_N, MP_r, MP_p );
mpw_free( &masterKeySalt, masterKeySaltSize );
if (!masterKey) {
err( "Could not allocate master key: %s\n", strerror( errno ) );
err( "Could not derive master key: %s\n", strerror( errno ) );
return NULL;
}
trc( " => masterKey.id: %s\n", mpw_id_buf( masterKey, MPMasterKeySize ) );
@ -128,8 +128,9 @@ static MPSiteKey mpw_siteKey_v0(
static const char *mpw_sitePasswordFromTemplate_v0(
MPMasterKey __unused masterKey, MPSiteKey siteKey, MPResultType resultType, const char __unused *resultParam) {
// Determine the template.
const char *_siteKey = (const char *)siteKey;
// Determine the template.
uint16_t seedByte;
mpw_uint16( (uint16_t)_siteKey[0], (uint8_t *)&seedByte );
const char *template = mpw_templateForType_v0( resultType, seedByte );

View File

@ -23,6 +23,7 @@
#define MP_N 32768LU
#define MP_r 8U
#define MP_p 2U
#define MP_otp_window 5 * 60 /* s */
// Inherited functions.
MPMasterKey mpw_masterKey_v0(
@ -55,8 +56,9 @@ static const char *mpw_sitePasswordFromTemplate_v1(
MPMasterKey __unused masterKey, MPSiteKey siteKey, MPResultType resultType, const char __unused *resultParam) {
// Determine the template.
const char *template = mpw_templateForType( resultType, siteKey[0] );
trc( "template: %u => %s\n", siteKey[0], template );
uint8_t seedByte = siteKey[0];
const char *template = mpw_templateForType( resultType, seedByte );
trc( "template: %u => %s\n", seedByte, template );
if (!template)
return NULL;
if (strlen( template ) > MPSiteKeySize) {
@ -67,9 +69,10 @@ static const char *mpw_sitePasswordFromTemplate_v1(
// Encode the password from the seed using the template.
char *const sitePassword = calloc( strlen( template ) + 1, sizeof( char ) );
for (size_t c = 0; c < strlen( template ); ++c) {
sitePassword[c] = mpw_characterFromClass( template[c], siteKey[c + 1] );
seedByte = siteKey[c + 1];
sitePassword[c] = mpw_characterFromClass( template[c], seedByte );
trc( " - class: %c, index: %3u (0x%02hhX) => character: %c\n",
template[c], siteKey[c + 1], siteKey[c + 1], sitePassword[c] );
template[c], seedByte, seedByte, sitePassword[c] );
}
trc( " => password: %s\n", sitePassword );

View File

@ -18,12 +18,14 @@
#include <string.h>
#include <errno.h>
#include <time.h>
#include "mpw-util.h"
#define MP_N 32768LU
#define MP_r 8U
#define MP_p 2U
#define MP_otp_window 5 * 60 /* s */
// Inherited functions.
MPMasterKey mpw_masterKey_v1(
@ -51,7 +53,9 @@ static MPSiteKey mpw_siteKey_v2(
const char *keyScope = mpw_scopeForPurpose( keyPurpose );
trc( "keyScope: %s\n", keyScope );
// TODO: Implement MPCounterValueTOTP
// OTP counter value.
if (siteCounter == MPCounterValueTOTP)
siteCounter = ((uint32_t)time( NULL ) / MP_otp_window) * MP_otp_window;
// Calculate the site seed.
trc( "siteSalt: keyScope=%s | #siteName=%s | siteName=%s | siteCounter=%s | #keyContext=%s | keyContext=%s\n",
@ -78,7 +82,7 @@ static MPSiteKey mpw_siteKey_v2(
MPSiteKey siteKey = mpw_hash_hmac_sha256( masterKey, MPMasterKeySize, siteSalt, siteSaltSize );
mpw_free( &siteSalt, siteSaltSize );
if (!siteKey) {
err( "Could not allocate site key: %s\n", strerror( errno ) );
err( "Could not derive site key: %s\n", strerror( errno ) );
return NULL;
}
trc( " => siteKey.id: %s\n", mpw_id_buf( siteKey, MPSiteKeySize ) );

View File

@ -24,6 +24,7 @@
#define MP_N 32768LU
#define MP_r 8U
#define MP_p 2U
#define MP_otp_window 5 * 60 /* s */
// Inherited functions.
MPSiteKey mpw_siteKey_v2(
@ -64,7 +65,7 @@ static MPMasterKey mpw_masterKey_v3(
MPMasterKey masterKey = mpw_kdf_scrypt( MPMasterKeySize, masterPassword, masterKeySalt, masterKeySaltSize, MP_N, MP_r, MP_p );
mpw_free( &masterKeySalt, masterKeySaltSize );
if (!masterKey) {
err( "Could not allocate master key: %s\n", strerror( errno ) );
err( "Could not derive master key: %s\n", strerror( errno ) );
return NULL;
}
trc( " => masterKey.id: %s\n", mpw_id_buf( masterKey, MPMasterKeySize ) );