1 import { serverTime } from '@proton/crypto';
2 import { KT_DATA_VALIDITY_PERIOD, KT_DOMAINS, ctLogs, getBaseDomain } from '@proton/key-transparency';
3 import { HOUR } from '@proton/shared/lib/constants';
5 export enum KtFeatureEnum {
10 export type KT_FF = KtFeatureEnum | undefined;
12 export const isKTActive = (feature: KT_FF) => {
13 // Do not activate KT if
14 // - feature flag is off;
15 // - the api is not prod's or proton.black's
16 // - the hardcoded KT certificate data is older than 6 months.
17 // - the server time compared to the client time is off by more than 24 hours -- (UI warning is shown to prevent attacks)
18 // - Web Crypto isn't fully supported (it is needed for certificate verification in pki.js)
19 if (feature === undefined || feature === KtFeatureEnum.DISABLE) {
23 const domain = getBaseDomain(false);
24 if (domain === KT_DOMAINS.UNKNOWN) {
28 const ctLogTimestamp = new Date(ctLogs.log_list_timestamp);
29 const keyTransparencyDataAge = serverTime().getTime() - ctLogTimestamp.getTime();
30 if (keyTransparencyDataAge > KT_DATA_VALIDITY_PERIOD) {
34 const timeOffset = serverTime().getTime() - Date.now();
35 if (Math.abs(timeOffset) > 24 * HOUR) {
39 // Test for full Web Crypto support, required by pki.js
40 if (typeof crypto === 'undefined' || !('subtle' in crypto)) {