Forbid the separator in the sub-addr name

This commit is contained in:
Rodolphe Bréard 2023-09-25 11:30:08 +02:00
parent f45c77ba64
commit 1c8d6db391
2 changed files with 15 additions and 9 deletions

View file

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- The style has been entirely reworked using Bootstrap instead of Bulma
- It is now impossible to include the separator in the dedicated name
## [0.3.0] - 2023-08-25

View file

@ -29,15 +29,20 @@ const generatedAddr = computed(() => {
const raw_account = accounts.value.find((e) => e.id == selectedAccountId.value);
if (raw_account) {
const account = fromRawAccount(raw_account);
var hasher = hmac.create(sha256, account.key);
hasher.update(account.localPart);
hasher.update(account.separator);
hasher.update(subAddrName.value);
const mac = hasher.digest();
const offset = mac[mac.length - 1] & 0xf;
const reduced_mac = mac.slice(offset, offset + 5);
const code = base32Encode(reduced_mac, 'RFC4648', { padding: false }).toLowerCase();
return `${account.localPart}${account.separator}${subAddrName.value}${account.separator}${code}@${account.domain}`;
if (subAddrName.value.indexOf(account.separator) != -1) {
subAddrName.value = subAddrName.value.replaceAll(account.separator, '');
}
if (subAddrName.value) {
var hasher = hmac.create(sha256, account.key);
hasher.update(account.localPart);
hasher.update(account.separator);
hasher.update(subAddrName.value);
const mac = hasher.digest();
const offset = mac[mac.length - 1] & 0xf;
const reduced_mac = mac.slice(offset, offset + 5);
const code = base32Encode(reduced_mac, 'RFC4648', { padding: false }).toLowerCase();
return `${account.localPart}${account.separator}${subAddrName.value}${account.separator}${code}@${account.domain}`;
}
}
}
return '';