| 67 | } |
| 68 | |
| 69 | async checkBoot(bootInfo: BootInfo, isKms: boolean): Promise<BootResponse> { |
| 70 | const policy = getPolicy(); |
| 71 | const deny = (reason: string): BootResponse => ({ |
| 72 | isAllowed: false, |
| 73 | reason, |
| 74 | gatewayAppId: '', |
| 75 | }); |
| 76 | const allow = (reason: string): BootResponse => ({ |
| 77 | isAllowed: true, |
| 78 | reason, |
| 79 | gatewayAppId: this.mockGatewayAppId, |
| 80 | }); |
| 81 | |
| 82 | switch (policy) { |
| 83 | case 'deny-all': |
| 84 | return deny(`mock policy: deny-all`); |
| 85 | case 'deny-kms': |
| 86 | if (isKms) return deny(`mock policy: deny-kms`); |
| 87 | return allow('mock app allowed (deny-kms policy)'); |
| 88 | case 'deny-app': |
| 89 | if (!isKms) return deny(`mock policy: deny-app`); |
| 90 | return allow('mock KMS allowed (deny-app policy)'); |
| 91 | case 'allowlist-device': { |
| 92 | const allowed = parseList('MOCK_ALLOWED_DEVICE_IDS'); |
| 93 | const deviceId = bootInfo.deviceId.toLowerCase().replace(/^0x/, ''); |
| 94 | if (allowed.size === 0) return deny('mock policy: allowlist-device with empty list'); |
| 95 | if (!allowed.has(deviceId)) return deny(`mock policy: device ${bootInfo.deviceId} not in allowlist`); |
| 96 | return allow(`mock policy: device ${bootInfo.deviceId} allowed`); |
| 97 | } |
| 98 | case 'allowlist-mr': { |
| 99 | const allowed = parseList('MOCK_ALLOWED_MR_AGGREGATED'); |
| 100 | const mr = bootInfo.mrAggregated.toLowerCase().replace(/^0x/, ''); |
| 101 | if (allowed.size === 0) return deny('mock policy: allowlist-mr with empty list'); |
| 102 | if (!allowed.has(mr)) return deny(`mock policy: mrAggregated ${bootInfo.mrAggregated} not in allowlist`); |
| 103 | return allow(`mock policy: mrAggregated ${bootInfo.mrAggregated} allowed`); |
| 104 | } |
| 105 | case 'allow-all': |
| 106 | default: |
| 107 | return allow(isKms ? 'mock KMS always allowed' : 'mock app always allowed'); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | async getGatewayAppId(): Promise<string> { |
| 112 | return this.mockGatewayAppId; |