@serve.zone/interfaces 32.87.0 → 32.89.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +17 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/cloudaccess.d.ts +402 -0
- package/dist_ts/data/cloudaccess.js +685 -0
- package/dist_ts/data/cloudlyconfig.d.ts +20 -0
- package/dist_ts/data/cloudlyconfig.js +21 -1
- package/dist_ts/data/gatewayareas.d.ts +116 -21
- package/dist_ts/data/gatewayareas.js +36 -1
- package/dist_ts/data/gatewayareas.validation.d.ts +30 -1
- package/dist_ts/data/gatewayareas.validation.js +242 -38
- package/dist_ts/data/gatewayconnector.d.ts +2 -2
- package/dist_ts/data/gatewayconnector.js +20 -1
- package/dist_ts/data/gatewayintent.d.ts +154 -0
- package/dist_ts/data/gatewayintent.js +61 -0
- package/dist_ts/data/index.d.ts +2 -0
- package/dist_ts/data/index.js +3 -1
- package/dist_ts/data/witness.js +4 -9
- package/dist_ts/private/bearerencoding.d.ts +9 -0
- package/dist_ts/private/bearerencoding.js +17 -0
- package/dist_ts/private/storagecontract.js +3 -3
- package/dist_ts/requests/cloudaccess.d.ts +125 -0
- package/dist_ts/requests/cloudaccess.js +2 -0
- package/dist_ts/requests/gatewayconnector.d.ts +33 -1
- package/dist_ts/requests/index.d.ts +2 -1
- package/dist_ts/requests/index.js +3 -2
- package/package.json +1 -1
- package/readme.md +156 -10
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/cloudaccess.ts +1133 -0
- package/ts/data/cloudlyconfig.ts +27 -0
- package/ts/data/gatewayareas.ts +84 -21
- package/ts/data/gatewayareas.validation.ts +268 -36
- package/ts/data/gatewayconnector.ts +19 -0
- package/ts/data/gatewayintent.ts +209 -0
- package/ts/data/index.ts +2 -0
- package/ts/data/witness.ts +3 -10
- package/ts/private/bearerencoding.ts +24 -0
- package/ts/private/storagecontract.ts +2 -2
- package/ts/requests/cloudaccess.ts +201 -0
- package/ts/requests/gatewayconnector.ts +41 -1
- package/ts/requests/index.ts +2 -0
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
import { isPlainRecord, readDataElements, readDataProperty, readExactDataRecord } from '../private/dataproperties.js';
|
|
23
23
|
import { matchesEngineKeyEntry, readEngineKeyEntries } from '../private/enginekeyentries.js';
|
|
24
24
|
import { isGatewayClientIdText } from '../private/gatewayclientid.js';
|
|
25
|
+
import { parseCanonicalIpAddress } from '../private/ipaddress.js';
|
|
25
26
|
import { normalizeCoreMailCredentialVerifier } from './coremail.runtime.js';
|
|
26
27
|
import {
|
|
27
28
|
isGatewayClientHostname,
|
|
@@ -35,10 +36,12 @@ import {
|
|
|
35
36
|
gatewayBlockRuleTypes,
|
|
36
37
|
gatewayDnsRecordTypes,
|
|
37
38
|
gatewayDnsStaticRecordTypes,
|
|
39
|
+
gatewayEdgeSettingBounds,
|
|
38
40
|
gatewayMailIdentityScramIterations,
|
|
39
41
|
gatewayRoutePathClasses,
|
|
40
42
|
isGatewayApiTokenScope,
|
|
41
43
|
type IGatewayDnsStaticRecordRow,
|
|
44
|
+
type IGatewayScramVerifier,
|
|
42
45
|
type TGatewayAreaContent,
|
|
43
46
|
type TGatewayRoutePortEntry,
|
|
44
47
|
type TGatewayRoutePortsInput,
|
|
@@ -476,17 +479,90 @@ const isCanonicalBase64 = (valueArg: unknown, minimumBytesArg: number, maximumBy
|
|
|
476
479
|
}
|
|
477
480
|
};
|
|
478
481
|
|
|
482
|
+
/** The salt of an `IGatewayScramVerifier`: canonical padded base64 of 16 to 64 bytes. */
|
|
483
|
+
const isScramSalt = (valueArg: unknown): valueArg is string => isCanonicalBase64(valueArg, 16, 64);
|
|
484
|
+
|
|
485
|
+
/** The iterations of an `IGatewayScramVerifier`: 4096 to 1000000. */
|
|
486
|
+
const isScramIterations = (valueArg: unknown): valueArg is number => isInteger(valueArg, 4096) && valueArg <= 1_000_000;
|
|
487
|
+
|
|
479
488
|
const checkScramVerifier = (scopeArg: IScope, valueArg: unknown, pathArg: string, iterationsArg: number | null): void => {
|
|
480
489
|
const verifier = readExactDataRecord(valueArg, ['algorithm', 'salt', 'iterations', 'storedKey', 'serverKey']);
|
|
481
490
|
check(scopeArg, verifier !== null
|
|
482
491
|
&& verifier.algorithm === 'SCRAM-SHA-256'
|
|
483
|
-
&&
|
|
484
|
-
&&
|
|
492
|
+
&& isScramSalt(verifier.salt)
|
|
493
|
+
&& isScramIterations(verifier.iterations)
|
|
485
494
|
&& (iterationsArg === null || verifier.iterations === iterationsArg)
|
|
486
495
|
&& isCanonicalBase64(verifier.storedKey, 32, 32)
|
|
487
496
|
&& isCanonicalBase64(verifier.serverKey, 32, 32), pathArg, 'invalid-verifier');
|
|
488
497
|
};
|
|
489
498
|
|
|
499
|
+
/** An input `deriveGatewayScramVerifier` refuses; the message names the member, never its value. */
|
|
500
|
+
export class GatewayScramVerifierError extends Error {
|
|
501
|
+
public constructor(reasonArg: string) {
|
|
502
|
+
super(`Gateway SCRAM verifier rejected: ${reasonArg}.`);
|
|
503
|
+
this.name = 'GatewayScramVerifierError';
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
const toBase64 = (bytesArg: ArrayBuffer): string => (
|
|
508
|
+
globalThis.btoa(String.fromCharCode(...new Uint8Array(bytesArg)))
|
|
509
|
+
);
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* The SCRAM-SHA-256 verifier (RFC 5802/7677 stored form) of a password under a given salt and
|
|
513
|
+
* iteration count: `SaltedPassword = PBKDF2-HMAC-SHA256(password, salt, iterations, 32 bytes)`,
|
|
514
|
+
* `StoredKey = SHA-256(HMAC-SHA256(SaltedPassword, 'Client Key'))`,
|
|
515
|
+
* `ServerKey = HMAC-SHA256(SaltedPassword, 'Server Key')`. For one salt it answers exactly what
|
|
516
|
+
* SmartMTA 13.1.0's `deriveScramVerifier` stores, so a gateway's SMTP AUTH accepts the password.
|
|
517
|
+
*
|
|
518
|
+
* - `password`: a non-empty string, taken as its UTF-8 bytes as written. No SASLprep and no Unicode
|
|
519
|
+
* normalisation is applied (SmartMTA applies none either), so two spellings of one non-ASCII
|
|
520
|
+
* password are two passwords: a caller passes the password it minted (24 random bytes as base64url,
|
|
521
|
+
* which is ASCII) and never a human-typed one it has not normalised itself.
|
|
522
|
+
* - `salt`: the verifier's `salt`, canonical padded base64 of 16 to 64 bytes. The caller draws it
|
|
523
|
+
* (once, at mint) and the answer carries it back unchanged; this function draws nothing.
|
|
524
|
+
* - `iterations`: 4096 to 1000000; a WorkApp mail identity uses `gatewayMailIdentityScramIterations`.
|
|
525
|
+
*
|
|
526
|
+
* To check a password against a stored verifier, derive with that verifier's `salt` and `iterations`
|
|
527
|
+
* and compare `storedKey` and `serverKey`: there is no second function. Throws
|
|
528
|
+
* `GatewayScramVerifierError` for an input outside these rules, which are the ones
|
|
529
|
+
* `validateGatewayAreaTables` holds a verifier to, so every answer passes it.
|
|
530
|
+
*/
|
|
531
|
+
export const deriveGatewayScramVerifier = async (inputArg: {
|
|
532
|
+
password: string;
|
|
533
|
+
salt: string;
|
|
534
|
+
iterations: number;
|
|
535
|
+
}): Promise<IGatewayScramVerifier> => {
|
|
536
|
+
const { password, salt, iterations } = inputArg;
|
|
537
|
+
if (typeof password !== 'string' || password.length === 0) {
|
|
538
|
+
throw new GatewayScramVerifierError('the password is no non-empty string');
|
|
539
|
+
}
|
|
540
|
+
if (!isScramSalt(salt)) {
|
|
541
|
+
throw new GatewayScramVerifierError('the salt is no canonical padded base64 of 16 to 64 bytes');
|
|
542
|
+
}
|
|
543
|
+
if (!isScramIterations(iterations)) {
|
|
544
|
+
throw new GatewayScramVerifierError('the iterations are no integer from 4096 to 1000000');
|
|
545
|
+
}
|
|
546
|
+
const subtle = globalThis.crypto.subtle;
|
|
547
|
+
const encoder = new TextEncoder();
|
|
548
|
+
const passwordKey = await subtle.importKey('raw', encoder.encode(password), 'PBKDF2', false, ['deriveBits']);
|
|
549
|
+
const saltedPassword = await subtle.deriveBits({
|
|
550
|
+
name: 'PBKDF2',
|
|
551
|
+
hash: 'SHA-256',
|
|
552
|
+
salt: Uint8Array.from(globalThis.atob(salt), (characterArg) => characterArg.charCodeAt(0)),
|
|
553
|
+
iterations,
|
|
554
|
+
}, passwordKey, 256);
|
|
555
|
+
const macKey = await subtle.importKey('raw', saltedPassword, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
|
|
556
|
+
const clientKey = await subtle.sign('HMAC', macKey, encoder.encode('Client Key'));
|
|
557
|
+
return {
|
|
558
|
+
algorithm: 'SCRAM-SHA-256',
|
|
559
|
+
salt,
|
|
560
|
+
iterations,
|
|
561
|
+
storedKey: toBase64(await subtle.digest('SHA-256', clientKey)),
|
|
562
|
+
serverKey: toBase64(await subtle.sign('HMAC', macKey, encoder.encode('Server Key'))),
|
|
563
|
+
};
|
|
564
|
+
};
|
|
565
|
+
|
|
490
566
|
const checkAttribution = (
|
|
491
567
|
scopeArg: IScope,
|
|
492
568
|
valueArg: unknown,
|
|
@@ -852,36 +928,114 @@ const validateSecurity = (scopeArg: IScope, contentArg: Record<string, unknown>)
|
|
|
852
928
|
// ---------------------------------------------------------------------------------------------
|
|
853
929
|
|
|
854
930
|
/**
|
|
855
|
-
* The
|
|
856
|
-
* `
|
|
931
|
+
* The form of a record's `name` (Linus ruling 129, Q1): at most 253 characters, every label a
|
|
932
|
+
* `zoneLabel`, except that the leftmost label may be exactly `*` with at least one label after it.
|
|
933
|
+
* Lowercase, no trailing dot, nothing around it.
|
|
857
934
|
*/
|
|
858
|
-
const
|
|
859
|
-
|
|
860
|
-
|
|
935
|
+
const isDnsRecordName = (valueArg: unknown): valueArg is string => {
|
|
936
|
+
if (typeof valueArg !== 'string' || valueArg.length === 0 || valueArg.length > 253) {
|
|
937
|
+
return false;
|
|
938
|
+
}
|
|
939
|
+
const [first, ...rest] = valueArg.split('.');
|
|
940
|
+
return (first === '*' ? rest.length > 0 : zoneLabel.test(first)) && rest.every((labelArg) => zoneLabel.test(labelArg));
|
|
941
|
+
};
|
|
942
|
+
|
|
943
|
+
/** A record's `name`: beyond 253 characters `bound-exceeded`, outside the form `invalid-value`. */
|
|
944
|
+
const checkDnsRecordName = (scopeArg: IScope, valueArg: unknown): boolean => {
|
|
945
|
+
if (typeof valueArg === 'string' && valueArg.length > 253) {
|
|
946
|
+
refuse(scopeArg, 'name', 'bound-exceeded');
|
|
947
|
+
return false;
|
|
948
|
+
}
|
|
949
|
+
check(scopeArg, isDnsRecordName(valueArg), 'name');
|
|
950
|
+
return isDnsRecordName(valueArg);
|
|
861
951
|
};
|
|
862
952
|
|
|
953
|
+
const utf8Encoder = new TextEncoder();
|
|
954
|
+
const utf8Length = (textArg: string): number => utf8Encoder.encode(textArg).length;
|
|
955
|
+
const whitespace = /\s/;
|
|
956
|
+
|
|
863
957
|
/**
|
|
864
|
-
*
|
|
865
|
-
*
|
|
866
|
-
* most
|
|
867
|
-
*
|
|
958
|
+
* A domain name inside a record value, in the one spelling the gateway's record value owner emits
|
|
959
|
+
* (dcrouter's `canonicalDnsRecordValue`): lowercase as written, no trailing dot, no whitespace, no
|
|
960
|
+
* empty label, every label at most 63 octets and the name at most 253. The characters of a label are
|
|
961
|
+
* not restricted further, as the gateway's encoder does not restrict them; the root is no name here.
|
|
868
962
|
*/
|
|
869
|
-
const
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
963
|
+
const isDnsValueName = (valueArg: string): boolean => (
|
|
964
|
+
valueArg !== '' && !whitespace.test(valueArg) && valueArg === valueArg.toLowerCase() && !valueArg.endsWith('.')
|
|
965
|
+
&& utf8Length(valueArg) <= 253
|
|
966
|
+
&& valueArg.split('.').every((labelArg) => labelArg !== '' && utf8Length(labelArg) <= 63)
|
|
967
|
+
);
|
|
968
|
+
|
|
969
|
+
/** A decimal number from 0 to `maximumArg` without a leading zero, as the value owner writes one. */
|
|
970
|
+
const isDnsValueNumber = (valueArg: string, maximumArg: number): boolean => (
|
|
971
|
+
/^(?:0|[1-9][0-9]{0,9})$/.test(valueArg) && Number(valueArg) <= maximumArg
|
|
972
|
+
);
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* The one spelling of a record value per type (Linus ruling 129, Q3), which is what dcrouter's
|
|
976
|
+
* record value owner emits (`canonicalDnsRecordValue`): the validator judges that spelling and
|
|
977
|
+
* accepts no other, so one record has one digest.
|
|
978
|
+
*
|
|
979
|
+
* - `A`, `AAAA`: one address of the type's family in the contract's canonical address text
|
|
980
|
+
* (`parseCanonicalIpAddress`, Linus ruling 143 B): a dotted quad without leading zeros, or the
|
|
981
|
+
* RFC 5952 text (lowercase, no leading zeros, the longest run of zero groups compressed). Every
|
|
982
|
+
* other spelling of the same address, which the gateway's DNS encoder would serve alike, is
|
|
983
|
+
* refused: the gateway's exporter respells a stored value. Spelling only: any address of the
|
|
984
|
+
* family is a value (the unspecified and multicast addresses too).
|
|
985
|
+
* - `CNAME`, `NS`: one name (`isDnsValueName`).
|
|
986
|
+
* - `MX`: `<preference> <exchange>` with one space between: the preference 0 to 65535, the exchange
|
|
987
|
+
* a name, or `.` exactly with preference 0 (the null MX of RFC 7505).
|
|
988
|
+
* - `SOA`: `<mname> <rname> <serial> <refresh> <retry> <expire> <minimum>` with one space between
|
|
989
|
+
* each: two names and five numbers from 0 to 4294967295.
|
|
990
|
+
* - `CAA`: any text without whitespace around it (the gateway keeps it as it is).
|
|
991
|
+
* - `TXT`: the text itself.
|
|
992
|
+
*/
|
|
993
|
+
const isDnsRecordValue = (typeArg: unknown, valueArg: string): boolean => {
|
|
994
|
+
switch (typeArg) {
|
|
995
|
+
case 'A':
|
|
996
|
+
return parseCanonicalIpAddress(valueArg)?.family === 4;
|
|
997
|
+
case 'AAAA':
|
|
998
|
+
return parseCanonicalIpAddress(valueArg)?.family === 6;
|
|
999
|
+
case 'CNAME':
|
|
1000
|
+
case 'NS':
|
|
1001
|
+
return isDnsValueName(valueArg);
|
|
1002
|
+
case 'MX': {
|
|
1003
|
+
const fields = valueArg.split(' ');
|
|
1004
|
+
return fields.length === 2 && isDnsValueNumber(fields[0], 65_535)
|
|
1005
|
+
&& (fields[1] === '.' ? fields[0] === '0' : isDnsValueName(fields[1]));
|
|
1006
|
+
}
|
|
1007
|
+
case 'SOA': {
|
|
1008
|
+
const fields = valueArg.split(' ');
|
|
1009
|
+
return fields.length === 7 && isDnsValueName(fields[0]) && isDnsValueName(fields[1])
|
|
1010
|
+
&& fields.slice(2).every((fieldArg) => isDnsValueNumber(fieldArg, 4_294_967_295));
|
|
1011
|
+
}
|
|
1012
|
+
case 'CAA':
|
|
1013
|
+
return valueArg === valueArg.trim();
|
|
1014
|
+
default:
|
|
1015
|
+
// `TXT` is the text itself; a type outside the vocabulary is refused at `type`.
|
|
1016
|
+
return true;
|
|
873
1017
|
}
|
|
874
|
-
const groups = halves.flatMap((halfArg) => (halfArg === '' ? [] : halfArg.split(':')));
|
|
875
|
-
return groups.every((groupArg) => /^[0-9A-Fa-f]{1,4}$/.test(groupArg))
|
|
876
|
-
&& (halves.length === 2 ? groups.length <= 8 : groups.length === 8);
|
|
877
1018
|
};
|
|
878
1019
|
|
|
879
|
-
/** A record value: a bounded text
|
|
1020
|
+
/** A record value: a bounded text in the one spelling of its type (`isDnsRecordValue`). */
|
|
880
1021
|
const checkRecordValue = (scopeArg: IScope, typeArg: unknown, valueArg: unknown): void => {
|
|
881
1022
|
checkText(scopeArg, valueArg, 'value', contract.maximumRecordValueLength);
|
|
882
|
-
if (isText(valueArg, contract.maximumRecordValueLength)
|
|
883
|
-
check(scopeArg, typeArg
|
|
1023
|
+
if (isText(valueArg, contract.maximumRecordValueLength)) {
|
|
1024
|
+
check(scopeArg, isDnsRecordValue(typeArg, valueArg), 'value');
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* A zone the gateway may answer for: a zone name of at least two labels whose labels are letters,
|
|
1030
|
+
* digits and inner hyphens (no underscore), the form a delegation can name.
|
|
1031
|
+
*/
|
|
1032
|
+
const authorityZoneLabel = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
|
|
1033
|
+
const isAuthorityZoneName = (valueArg: unknown): boolean => {
|
|
1034
|
+
if (!isZoneName(valueArg)) {
|
|
1035
|
+
return false;
|
|
884
1036
|
}
|
|
1037
|
+
const labels = valueArg.split('.');
|
|
1038
|
+
return labels.length >= 2 && labels.every((labelArg) => authorityZoneLabel.test(labelArg));
|
|
885
1039
|
};
|
|
886
1040
|
|
|
887
1041
|
const validateDns = (scopeArg: IScope, contentArg: Record<string, unknown>): void => {
|
|
@@ -965,13 +1119,14 @@ const validateDns = (scopeArg: IScope, contentArg: Record<string, unknown>): voi
|
|
|
965
1119
|
} else if (domainSources.get(row.domainId) !== 'dcrouter') {
|
|
966
1120
|
refuse(rowScopeArg, 'domainId', 'reference-not-dcrouter-zone');
|
|
967
1121
|
} else {
|
|
968
|
-
// A record lies inside its zone: the zone's name itself or a name below it, as written.
|
|
1122
|
+
// A record lies inside its zone: the zone's name itself or a name below it, as written. A name
|
|
1123
|
+
// outside the name form is refused for that alone, below.
|
|
969
1124
|
const zone = domainNames.get(row.domainId);
|
|
970
|
-
if (
|
|
1125
|
+
if (isDnsRecordName(row.name) && isZoneName(zone)) {
|
|
971
1126
|
check(rowScopeArg, row.name === zone || row.name.endsWith(`.${zone}`), 'name');
|
|
972
1127
|
}
|
|
973
1128
|
}
|
|
974
|
-
|
|
1129
|
+
checkDnsRecordName(rowScopeArg, row.name);
|
|
975
1130
|
checkOneOf(rowScopeArg, row.type, 'type', gatewayDnsRecordTypes);
|
|
976
1131
|
checkRecordValue(rowScopeArg, row.type, row.value);
|
|
977
1132
|
checkInteger(rowScopeArg, row.ttl, 'ttl', 1);
|
|
@@ -984,7 +1139,7 @@ const validateDns = (scopeArg: IScope, contentArg: Record<string, unknown>): voi
|
|
|
984
1139
|
if (rowScopeArg.rowId !== null) {
|
|
985
1140
|
check(rowScopeArg, /^static-[a-f0-9]{64}$/.test(rowScopeArg.rowId), 'id', 'invalid-row-id');
|
|
986
1141
|
}
|
|
987
|
-
|
|
1142
|
+
checkDnsRecordName(rowScopeArg, row.name);
|
|
988
1143
|
checkOneOf(rowScopeArg, row.type, 'type', gatewayDnsStaticRecordTypes);
|
|
989
1144
|
checkRecordValue(rowScopeArg, row.type, row.value);
|
|
990
1145
|
checkInteger(rowScopeArg, row.ttl, 'ttl', 1, true);
|
|
@@ -1005,10 +1160,14 @@ const validateDns = (scopeArg: IScope, contentArg: Record<string, unknown>): voi
|
|
|
1005
1160
|
check(rowScopeArg, isGatewayClientHostname(rowScopeArg.rowId), 'id', 'invalid-row-id');
|
|
1006
1161
|
}
|
|
1007
1162
|
checkText(rowScopeArg, row.reason, 'reason', contract.maximumTextLength);
|
|
1163
|
+
// The gateway stores a reason trimmed, so one with whitespace around it would not read back.
|
|
1164
|
+
if (isText(row.reason, contract.maximumTextLength)) {
|
|
1165
|
+
check(rowScopeArg, row.reason === row.reason.trim(), 'reason');
|
|
1166
|
+
}
|
|
1008
1167
|
});
|
|
1009
1168
|
rowList(scopeArg, 'authorityZones', contentArg.authorityZones, bounds.authorityZones, (rowScopeArg, rowArg) => {
|
|
1010
1169
|
if (exact(rowScopeArg, rowArg, ['id'], null) !== null && rowScopeArg.rowId !== null) {
|
|
1011
|
-
check(rowScopeArg,
|
|
1170
|
+
check(rowScopeArg, isAuthorityZoneName(rowScopeArg.rowId), 'id', 'invalid-row-id');
|
|
1012
1171
|
}
|
|
1013
1172
|
});
|
|
1014
1173
|
rowList(scopeArg, 'clientHostnames', contentArg.clientHostnames, bounds.clientHostnames, (rowScopeArg, rowArg) => {
|
|
@@ -1572,6 +1731,20 @@ const validateMail = (scopeArg: IScope, contentArg: Record<string, unknown>, dns
|
|
|
1572
1731
|
});
|
|
1573
1732
|
}
|
|
1574
1733
|
checkOneOf(memberScopeArg, server.tlsSource, 'tlsSource', ['managedCertificate', 'configuredMaterial']);
|
|
1734
|
+
// Enabled mail with server options names its hostname and at least one port: the gateway cannot
|
|
1735
|
+
// start a mail server without them.
|
|
1736
|
+
if (server.enabled === true && isPlainRecord(server.emailConfig)) {
|
|
1737
|
+
const hostname = engineValueAt(server.emailConfig, 'hostname');
|
|
1738
|
+
check(memberScopeArg, typeof hostname === 'string' && hostname.trim() !== '', 'emailConfig.hostname');
|
|
1739
|
+
const ports = readDataElements(engineValueAt(server.emailConfig, 'ports'), Number.MAX_SAFE_INTEGER);
|
|
1740
|
+
check(memberScopeArg, ports !== null && ports.length > 0 && ports.every(isPort), 'emailConfig.ports');
|
|
1741
|
+
}
|
|
1742
|
+
// `configuredMaterial` serves the table's own TLS material: the lifted key, or a certificate in
|
|
1743
|
+
// `emailConfig.tls` (every other material member is a refused engine key).
|
|
1744
|
+
if (server.tlsSource === 'configuredMaterial') {
|
|
1745
|
+
check(memberScopeArg, isPlainRecord(server.emailConfig)
|
|
1746
|
+
&& (server.tlsKey !== null || Boolean(engineValueAt(server.emailConfig, 'tls.certPem'))), 'tlsSource');
|
|
1747
|
+
}
|
|
1575
1748
|
});
|
|
1576
1749
|
rowList(scopeArg, 'domains', contentArg.domains, bounds.domains, (rowScopeArg, rowArg) => {
|
|
1577
1750
|
const row = exact(rowScopeArg, rowArg, [
|
|
@@ -1722,6 +1895,40 @@ const checkNullableNonEmptyList = (
|
|
|
1722
1895
|
checkListArg(scopeArg, valueArg, pathArg);
|
|
1723
1896
|
};
|
|
1724
1897
|
|
|
1898
|
+
const edgeBounds = gatewayEdgeSettingBounds;
|
|
1899
|
+
|
|
1900
|
+
/** A bounded set of ports that never names the client-first TLS port. */
|
|
1901
|
+
const checkServerFirstPorts = (scopeArg: IScope, valueArg: unknown, pathArg: string): void => {
|
|
1902
|
+
if (Array.isArray(valueArg) && valueArg.length > edgeBounds.maximumServerFirstPorts) {
|
|
1903
|
+
refuse(scopeArg, pathArg, 'bound-exceeded');
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1906
|
+
checkPortSet(scopeArg, valueArg, pathArg);
|
|
1907
|
+
const ports = readDataElements(valueArg, edgeBounds.maximumServerFirstPorts);
|
|
1908
|
+
check(scopeArg, ports === null || !ports.includes(edgeBounds.clientFirstPort), pathArg);
|
|
1909
|
+
};
|
|
1910
|
+
|
|
1911
|
+
/** A bounded set of texts without whitespace around them (the gateway stores each trimmed). */
|
|
1912
|
+
const checkEgressTextSet = (scopeArg: IScope, valueArg: unknown, pathArg: string): void => {
|
|
1913
|
+
if (Array.isArray(valueArg) && valueArg.length > edgeBounds.maximumEgressListEntries) {
|
|
1914
|
+
refuse(scopeArg, pathArg, 'bound-exceeded');
|
|
1915
|
+
return;
|
|
1916
|
+
}
|
|
1917
|
+
checkTextSet(scopeArg, valueArg, pathArg,
|
|
1918
|
+
(entryArg) => isText(entryArg, contract.maximumNameLength) && entryArg === entryArg.trim());
|
|
1919
|
+
};
|
|
1920
|
+
|
|
1921
|
+
/** An edge's mail hostname: lowercase letters, digits and inner hyphens in two or more labels, at most 253 characters. */
|
|
1922
|
+
const mailHostnamePattern = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)+$/;
|
|
1923
|
+
|
|
1924
|
+
/** `null`, or the contract's canonical address text of one family (dotted quad, RFC 5952). */
|
|
1925
|
+
const checkNullableAddress = (scopeArg: IScope, valueArg: unknown, pathArg: string, familyArg: 4 | 6): void => {
|
|
1926
|
+
checkNullableText(scopeArg, valueArg, pathArg, 64);
|
|
1927
|
+
if (isText(valueArg, 64)) {
|
|
1928
|
+
check(scopeArg, parseCanonicalIpAddress(valueArg)?.family === familyArg, pathArg);
|
|
1929
|
+
}
|
|
1930
|
+
};
|
|
1931
|
+
|
|
1725
1932
|
const checkPerformance = (scopeArg: IScope, valueArg: unknown, pathArg: string): void => {
|
|
1726
1933
|
if (valueArg === null) {
|
|
1727
1934
|
return;
|
|
@@ -1740,9 +1947,21 @@ const checkPerformance = (scopeArg: IScope, valueArg: unknown, pathArg: string):
|
|
|
1740
1947
|
if (key === 'profile') {
|
|
1741
1948
|
checkOneOf(inner, performance.profile, 'profile', ['balanced', 'throughput', 'highConcurrency'], true);
|
|
1742
1949
|
} else if (key === 'serverFirstPorts') {
|
|
1743
|
-
checkNullableNonEmptyList(inner, performance.serverFirstPorts, 'serverFirstPorts',
|
|
1950
|
+
checkNullableNonEmptyList(inner, performance.serverFirstPorts, 'serverFirstPorts', checkServerFirstPorts);
|
|
1744
1951
|
} else {
|
|
1745
|
-
|
|
1952
|
+
const range = edgeBounds.performance[key];
|
|
1953
|
+
const value = performance[key];
|
|
1954
|
+
check(inner, value === null || (isInteger(value, range.minimum) && value <= range.maximum), key);
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
// A stream window never starts or settles above its maximum.
|
|
1958
|
+
const maximumWindow = performance.maxStreamWindowBytes;
|
|
1959
|
+
if (isInteger(maximumWindow, 1)) {
|
|
1960
|
+
for (const key of ['minStreamWindowBytes', 'sustainedStreamWindowBytes'] as const) {
|
|
1961
|
+
const value = performance[key];
|
|
1962
|
+
if (isInteger(value, 1)) {
|
|
1963
|
+
check(inner, value <= maximumWindow, key);
|
|
1964
|
+
}
|
|
1746
1965
|
}
|
|
1747
1966
|
}
|
|
1748
1967
|
};
|
|
@@ -1754,7 +1973,8 @@ const egressSettingKeys = [
|
|
|
1754
1973
|
/**
|
|
1755
1974
|
* An edge's egress policy in its one spelling (ruling 125, Q-b7): always the object, so `null` fails
|
|
1756
1975
|
* the shape check (the gateway reads no policy and a disabled one alike; ruling 128, B2's pattern);
|
|
1757
|
-
* enabled, it states its ports
|
|
1976
|
+
* enabled, it states its ports, which are exactly `gatewayEdgeSettingBounds.egressAllowedPorts`
|
|
1977
|
+
* (`[25]`, Linus ruling 129 Q3: the only ports a gateway opens for egress); disabled, every setting is
|
|
1758
1978
|
* `null`, because the gateway keeps only `enabled` of a disabled policy; a list is `null` or non-empty.
|
|
1759
1979
|
*/
|
|
1760
1980
|
const checkEgress = (scopeArg: IScope, valueArg: unknown): void => {
|
|
@@ -1771,13 +1991,19 @@ const checkEgress = (scopeArg: IScope, valueArg: unknown): void => {
|
|
|
1771
1991
|
return;
|
|
1772
1992
|
}
|
|
1773
1993
|
if (egress.enabled === true) {
|
|
1774
|
-
|
|
1994
|
+
const ports = readDataElements(egress.allowedPorts, contract.maximumListEntries);
|
|
1995
|
+
const allowed = edgeBounds.egressAllowedPorts;
|
|
1996
|
+
check(inner, ports !== null && ports.length === allowed.length
|
|
1997
|
+
&& ports.every((portArg, indexArg) => portArg === allowed[indexArg]), 'allowedPorts');
|
|
1998
|
+
} else {
|
|
1999
|
+
checkNullableNonEmptyList(inner, egress.allowedPorts, 'allowedPorts', checkPortSet);
|
|
1775
2000
|
}
|
|
1776
|
-
checkNullableNonEmptyList(inner, egress.allowedPorts, 'allowedPorts', checkPortSet);
|
|
1777
2001
|
checkNullableBoolean(inner, egress.allowPrivateRanges, 'allowPrivateRanges');
|
|
1778
|
-
checkNullableNonEmptyList(inner, egress.deniedCidrs, 'deniedCidrs',
|
|
1779
|
-
checkNullableNonEmptyList(inner, egress.allowedHostPatterns, 'allowedHostPatterns',
|
|
1780
|
-
|
|
2002
|
+
checkNullableNonEmptyList(inner, egress.deniedCidrs, 'deniedCidrs', checkEgressTextSet);
|
|
2003
|
+
checkNullableNonEmptyList(inner, egress.allowedHostPatterns, 'allowedHostPatterns', checkEgressTextSet);
|
|
2004
|
+
const streams = egress.maxConcurrentStreams;
|
|
2005
|
+
check(inner, streams === null || (isInteger(streams, 1) && streams <= edgeBounds.maximumEgressConcurrentStreams),
|
|
2006
|
+
'maxConcurrentStreams');
|
|
1781
2007
|
};
|
|
1782
2008
|
|
|
1783
2009
|
const validateEdges = (scopeArg: IScope, contentArg: Record<string, unknown>): void => {
|
|
@@ -1787,6 +2013,9 @@ const validateEdges = (scopeArg: IScope, contentArg: Record<string, unknown>): v
|
|
|
1787
2013
|
if (hub !== null) {
|
|
1788
2014
|
checkBoolean(memberScopeArg, hub.enabled, 'enabled');
|
|
1789
2015
|
checkNullableText(memberScopeArg, hub.hubDomain, 'hubDomain', 253);
|
|
2016
|
+
if (isText(hub.hubDomain, 253)) {
|
|
2017
|
+
check(memberScopeArg, hub.hubDomain === hub.hubDomain.trim(), 'hubDomain');
|
|
2018
|
+
}
|
|
1790
2019
|
checkPerformance(memberScopeArg, hub.performance, 'performance');
|
|
1791
2020
|
}
|
|
1792
2021
|
});
|
|
@@ -1807,9 +2036,12 @@ const validateEdges = (scopeArg: IScope, contentArg: Record<string, unknown>): v
|
|
|
1807
2036
|
checkPerformance(rowScopeArg, row.performance, 'performance');
|
|
1808
2037
|
checkEgress(rowScopeArg, row.egress);
|
|
1809
2038
|
checkTextSet(rowScopeArg, row.tags, 'tags');
|
|
1810
|
-
|
|
1811
|
-
|
|
2039
|
+
checkNullableAddress(rowScopeArg, row.publicIp, 'publicIp', 4);
|
|
2040
|
+
checkNullableAddress(rowScopeArg, row.publicIpv6, 'publicIpv6', 6);
|
|
1812
2041
|
checkNullableText(rowScopeArg, row.mailHostname, 'mailHostname', 253);
|
|
2042
|
+
if (isText(row.mailHostname, 253)) {
|
|
2043
|
+
check(rowScopeArg, mailHostnamePattern.test(row.mailHostname), 'mailHostname');
|
|
2044
|
+
}
|
|
1813
2045
|
});
|
|
1814
2046
|
};
|
|
1815
2047
|
|
|
@@ -360,6 +360,24 @@ export const gatewayConnectorRefusals = Object.freeze([
|
|
|
360
360
|
* export.
|
|
361
361
|
*/
|
|
362
362
|
'local-changing-during-export',
|
|
363
|
+
/**
|
|
364
|
+
* A local write to a configuration area the gateway's controller owns: an operator's or a gateway
|
|
365
|
+
* client's change on the gateway itself, whichever call carried it (the gateway's own API, a
|
|
366
|
+
* gateway-client token or a gateway-client call on the connector socket). Nothing was written; the
|
|
367
|
+
* error text names the area (the error data stays `{ code, retryable }` and carries none), and the
|
|
368
|
+
* change is made at the controller. A reader built on an earlier release of this package reads it
|
|
369
|
+
* as a failure without a named refusal.
|
|
370
|
+
*/
|
|
371
|
+
'area-controller-owned',
|
|
372
|
+
/**
|
|
373
|
+
* Momentary (`gatewayConnectorMomentaryRefusals`): a `getGatewayRouteDnsResults` while the gateway
|
|
374
|
+
* runs no route DNS reconciler (it has not started yet, or it failed), so no outcome can be read.
|
|
375
|
+
* It refuses the whole read only and is never one hostname's condition: those stay in the result
|
|
376
|
+
* rows (`IGatewayRouteDnsResult`). Nothing changed, and the controller asks again later. A reader
|
|
377
|
+
* built on an earlier release of this package reads it as a failure without a named refusal, never
|
|
378
|
+
* as an answer.
|
|
379
|
+
*/
|
|
380
|
+
'route-dns-unavailable',
|
|
363
381
|
] as const);
|
|
364
382
|
|
|
365
383
|
/** One of the reasons one side of the gateway connector answers instead of a request. */
|
|
@@ -386,6 +404,7 @@ export const isGatewayConnectorRefusal = (valueArg: unknown): valueArg is TGatew
|
|
|
386
404
|
*/
|
|
387
405
|
export const gatewayConnectorMomentaryRefusals = Object.freeze([
|
|
388
406
|
'local-changing-during-export',
|
|
407
|
+
'route-dns-unavailable',
|
|
389
408
|
] as const satisfies readonly TGatewayConnectorRefusal[]);
|
|
390
409
|
|
|
391
410
|
/** One of the momentary connector refusals. */
|