diff options
Diffstat (limited to 'source/storage')
| -rw-r--r-- | source/storage/KeyManager.mc | 24 | ||||
| -rw-r--r-- | source/storage/Vault.mc | 19 |
2 files changed, 43 insertions, 0 deletions
diff --git a/source/storage/KeyManager.mc b/source/storage/KeyManager.mc index 567288f..47dbd59 100644 --- a/source/storage/KeyManager.mc +++ b/source/storage/KeyManager.mc @@ -84,6 +84,30 @@ class KeyManager { return out; } + // A keyed hash (16 hex characters) of a settings form's content, for + // the applied-forms log (README 10.3). Keyed like the fingerprints, with + // its own label, because the content includes secrets. The parts are + // fed to the native HMAC one by one, each preceded by `separator`, so a + // large import form costs no byte loop here (the watchdog). + function formHash(parts as Array<ByteArray>, separator as Number) as String { + deviceKeys(); + var mac = new Cryptography.HashBasedMessageAuthenticationCode({ + :algorithm => Cryptography.HASH_SHA256, + :key => _fingerprintKey as ByteArray + }); + mac.update(Bytes.fromUtf8("OTPW-FH-1")); + for (var i = 0; i < parts.size(); i++) { + mac.update([separator]b); + if (parts[i].size() > 0) { + mac.update(parts[i]); + } + } + var digest = mac.digest(); + var out = Bytes.toHex(digest.slice(0, FINGERPRINT_BYTES)); + Bytes.wipe(digest); + return out; + } + // True when a PIN has been set. function hasPin() as Boolean { return _store.getValue(WRAP_KEY) != null; diff --git a/source/storage/Vault.mc b/source/storage/Vault.mc index 46c8de2..88054e0 100644 --- a/source/storage/Vault.mc +++ b/source/storage/Vault.mc @@ -31,6 +31,9 @@ class Vault { var lockout as Lockout; // The "Erase locked entries after 10 wrong PINs" setting (off by default). var eraseAfterFailures as Boolean = false; + // The "Encrypt names" setting: new entries keep their names in the + // encrypted part (existing ones are converted by AboutScan). + var encryptNames as Boolean = false; private var _store as Persist.Backend; private var _meta as Dictionary<Application.Storage.KeyType, Application.Storage.ValueType>; @@ -126,6 +129,7 @@ class Vault { throw new VaultError(VaultError.LIMIT, "at most " + MAX_ENTRIES + " entries"); } entry.id = newId(); + entry.namesEncrypted = encryptNames; entry.fingerprint = keyManager.fingerprint(entry); if (entry.created == 0) { entry.created = Clock.nowUnix(0); @@ -156,6 +160,21 @@ class Vault { _store.deleteValue("x." + entry.id); // the cached matrix may be stale } + // Re-seal an entry with or without encrypted names ("Encrypt names"). + // Nothing else changes, so the barcode cache stays. Throws NOT_FOUND, + // LOCKED, DAMAGED or FULL. + function setNamesEncrypted(id as String, encrypted as Boolean) as Void { + var entry = open(id); + entry.namesEncrypted = encrypted; + try { + write("e." + id, seal(entry)); + } catch (e instanceof VaultError) { + entry.wipeSecrets(); + throw e; + } + entry.wipeSecrets(); + } + // ---- Encoded barcode cache (README 12.2) ----------------------------- // Store an encoded matrix for a code entry, sealed with the entry's own |
