Send support for Sender Key

This commit is contained in:
Scott Nonnenberg 2021-05-25 15:40:04 -07:00 committed by GitHub
parent d8417e562b
commit e6f1ec2b6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 2290 additions and 911 deletions

View file

@ -20,6 +20,10 @@ type Storage = {
remove(key: string): Promise<void>;
};
function isWellFormed(data: unknown): data is SerializedCertificateType {
return serializedCertificateSchema.safeParse(data).success;
}
// In case your clock is different from the server's, we "fake" expire certificates early.
const CLOCK_SKEW_THRESHOLD = 15 * 60 * 1000;
@ -88,10 +92,14 @@ export class SenderCertificateService {
);
const valueInStorage = storage.get(modeToStorageKey(mode));
return serializedCertificateSchema.check(valueInStorage) &&
if (
isWellFormed(valueInStorage) &&
isExpirationValid(valueInStorage.expires)
? valueInStorage
: undefined;
) {
return valueInStorage;
}
return undefined;
}
private fetchCertificate(