@syncfusion/ej2-office-common 35.1.37
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/.eslintrc.json +263 -0
- package/.prettierrc.json +5 -0
- package/README.md +167 -0
- package/api-extractor.json +35 -0
- package/core.js +4 -0
- package/dist/ej2-office-common.umd.min.js +11 -0
- package/dist/ej2-office-common.umd.min.js.map +1 -0
- package/dist/es6/ej2-office-common.es2015.js +6585 -0
- package/dist/es6/ej2-office-common.es2015.js.map +1 -0
- package/dist/es6/ej2-office-common.es5.js +7955 -0
- package/dist/es6/ej2-office-common.es5.js.map +1 -0
- package/dist/global/ej2-office-common.min.js +11 -0
- package/dist/global/ej2-office-common.min.js.map +1 -0
- package/dist/global/index.d.ts +14 -0
- package/encryption.js +4 -0
- package/features.js +4 -0
- package/global.json +6 -0
- package/index.js +4 -0
- package/license +10 -0
- package/nuget.config +7 -0
- package/package.json +23 -0
- package/src/all.d.ts +41 -0
- package/src/all.js +38 -0
- package/src/core/index.d.ts +6 -0
- package/src/core/index.js +6 -0
- package/src/core/xml/index.d.ts +7 -0
- package/src/core/xml/index.js +6 -0
- package/src/core/xml/model.d.ts +71 -0
- package/src/core/xml/model.js +20 -0
- package/src/encryption/agile-constants.d.ts +61 -0
- package/src/encryption/agile-constants.js +71 -0
- package/src/encryption/agile-encryption-info.d.ts +46 -0
- package/src/encryption/agile-encryption-info.js +333 -0
- package/src/encryption/agile-password.d.ts +8 -0
- package/src/encryption/agile-password.js +58 -0
- package/src/encryption/cfb-reader.d.ts +11 -0
- package/src/encryption/cfb-reader.js +345 -0
- package/src/encryption/crypto-primitives.d.ts +74 -0
- package/src/encryption/crypto-primitives.js +302 -0
- package/src/encryption/decrypt-encrypted-package.d.ts +16 -0
- package/src/encryption/decrypt-encrypted-package.js +138 -0
- package/src/encryption/encryption-info-xml.d.ts +21 -0
- package/src/encryption/encryption-info-xml.js +282 -0
- package/src/encryption/errors.d.ts +66 -0
- package/src/encryption/errors.js +124 -0
- package/src/encryption/index.d.ts +35 -0
- package/src/encryption/index.js +100 -0
- package/src/features/diagrams/constants.d.ts +83 -0
- package/src/features/diagrams/constants.js +101 -0
- package/src/features/diagrams/diagram-data-model.d.ts +148 -0
- package/src/features/diagrams/diagram-data-model.js +446 -0
- package/src/features/diagrams/diagram-parsers.d.ts +28 -0
- package/src/features/diagrams/diagram-parsers.js +182 -0
- package/src/features/diagrams/diagram-serializers.d.ts +20 -0
- package/src/features/diagrams/diagram-serializers.js +110 -0
- package/src/features/diagrams/diagram-views.d.ts +60 -0
- package/src/features/diagrams/diagram-views.js +213 -0
- package/src/features/diagrams/element-tree.d.ts +55 -0
- package/src/features/diagrams/element-tree.js +197 -0
- package/src/features/diagrams/errors.d.ts +17 -0
- package/src/features/diagrams/errors.js +59 -0
- package/src/features/diagrams/index.d.ts +17 -0
- package/src/features/diagrams/index.js +17 -0
- package/src/features/diagrams/smart-art-catalog.d.ts +107 -0
- package/src/features/diagrams/smart-art-catalog.js +422 -0
- package/src/features/diagrams/smart-art-diagram.d.ts +96 -0
- package/src/features/diagrams/smart-art-diagram.js +258 -0
- package/src/features/index.d.ts +11 -0
- package/src/features/index.js +11 -0
- package/src/features/ink/constants.d.ts +54 -0
- package/src/features/ink/constants.js +54 -0
- package/src/features/ink/index.d.ts +18 -0
- package/src/features/ink/index.js +15 -0
- package/src/features/ink/ink-effects.d.ts +35 -0
- package/src/features/ink/ink-effects.js +45 -0
- package/src/features/ink/ink-model.d.ts +237 -0
- package/src/features/ink/ink-model.js +406 -0
- package/src/features/ink/ink-parser.d.ts +59 -0
- package/src/features/ink/ink-parser.js +671 -0
- package/src/features/ink/ink-serializer.d.ts +16 -0
- package/src/features/ink/ink-serializer.js +281 -0
- package/src/features/ink/ink-units.d.ts +33 -0
- package/src/features/ink/ink-units.js +92 -0
- package/src/features/ink/ink-xml.d.ts +26 -0
- package/src/features/ink/ink-xml.js +165 -0
- package/src/features/ink/trace-codec.d.ts +127 -0
- package/src/features/ink/trace-codec.js +266 -0
- package/src/features/mathml/constants.d.ts +47 -0
- package/src/features/mathml/constants.js +47 -0
- package/src/features/mathml/errors.d.ts +50 -0
- package/src/features/mathml/errors.js +69 -0
- package/src/features/mathml/index.d.ts +30 -0
- package/src/features/mathml/index.js +22 -0
- package/src/features/mathml/math-factory.d.ts +26 -0
- package/src/features/mathml/math-factory.js +568 -0
- package/src/features/mathml/model/controls.d.ts +896 -0
- package/src/features/mathml/model/controls.js +1541 -0
- package/src/features/mathml/model/enums.d.ts +153 -0
- package/src/features/mathml/model/enums.js +133 -0
- package/src/features/mathml/model/math-element.d.ts +173 -0
- package/src/features/mathml/model/math-element.js +315 -0
- package/src/features/mathml/model/roots.d.ts +82 -0
- package/src/features/mathml/model/roots.js +177 -0
- package/src/features/mathml/openxml.d.ts +56 -0
- package/src/features/mathml/openxml.js +87 -0
- package/src/features/mathml/parse/math-parser.d.ts +43 -0
- package/src/features/mathml/parse/math-parser.js +636 -0
- package/src/features/mathml/serialize/math-serializer.d.ts +34 -0
- package/src/features/mathml/serialize/math-serializer.js +749 -0
- package/src/features/smart-art/diagram-xml.d.ts +63 -0
- package/src/features/smart-art/diagram-xml.js +459 -0
- package/src/features/smart-art/errors.d.ts +24 -0
- package/src/features/smart-art/errors.js +47 -0
- package/src/features/smart-art/index.d.ts +26 -0
- package/src/features/smart-art/index.js +26 -0
- package/src/features/smart-art/minimal-samples.d.ts +18 -0
- package/src/features/smart-art/minimal-samples.js +40 -0
- package/src/features/smart-art/mutators.d.ts +60 -0
- package/src/features/smart-art/mutators.js +566 -0
- package/src/features/smart-art/namespaces.d.ts +153 -0
- package/src/features/smart-art/namespaces.js +163 -0
- package/src/features/smart-art/package-graph.d.ts +61 -0
- package/src/features/smart-art/package-graph.js +413 -0
- package/src/features/smart-art/parse-colors.d.ts +19 -0
- package/src/features/smart-art/parse-colors.js +39 -0
- package/src/features/smart-art/parse-data.d.ts +21 -0
- package/src/features/smart-art/parse-data.js +121 -0
- package/src/features/smart-art/parse-layout.d.ts +20 -0
- package/src/features/smart-art/parse-layout.js +40 -0
- package/src/features/smart-art/parse-rel-ids.d.ts +71 -0
- package/src/features/smart-art/parse-rel-ids.js +233 -0
- package/src/features/smart-art/parse-style.d.ts +19 -0
- package/src/features/smart-art/parse-style.js +39 -0
- package/src/features/smart-art/point-text.d.ts +80 -0
- package/src/features/smart-art/point-text.js +424 -0
- package/src/features/smart-art/register.d.ts +33 -0
- package/src/features/smart-art/register.js +95 -0
- package/src/features/smart-art/serialize.d.ts +40 -0
- package/src/features/smart-art/serialize.js +48 -0
- package/src/features/smart-art/types.d.ts +403 -0
- package/src/features/smart-art/types.js +28 -0
- package/src/global.js +1 -0
- package/src/index.d.ts +21 -0
- package/src/index.js +22 -0
- package/tsconfig.build.json +13 -0
- package/tsconfig.harness.json +32 -0
- package/tslint.json +111 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Parse EncryptionInfo stream for Agile encryption ([MS-OFFCRYPTO] §2.3.4.10).
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Binary header: VersionMajor, VersionMinor (2 bytes each LE), Reserved (4 bytes LE),
|
|
6
|
+
* then UTF-8 XML. Agile is **4.4** with Reserved **0x00000040**.
|
|
7
|
+
* Standard Encryption (minor version 2) is explicitly unsupported.
|
|
8
|
+
*
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
var __values = (this && this.__values) || function (o) {
|
|
12
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
|
13
|
+
if (m) return m.call(o);
|
|
14
|
+
return {
|
|
15
|
+
next: function () {
|
|
16
|
+
if (o && i >= o.length) o = void 0;
|
|
17
|
+
return { value: o && o[i++], done: !o };
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
import { AGILE_ENCRYPTION_NS, AGILE_RESERVED, AGILE_VERSION_MAJOR, AGILE_VERSION_MINOR, MAX_SPIN_COUNT, PASSWORD_KEY_ENCRYPTOR_URI, STANDARD_ENCRYPTION_VERSION_MINOR, } from './agile-constants';
|
|
22
|
+
import { assertAesKeyBits, assertSupportedCipher, resolveHashAlgorithm, } from './crypto-primitives';
|
|
23
|
+
import { EncryptedPackageError, UnsupportedEncryptionError, } from './errors';
|
|
24
|
+
import { parseEncryptionInfoXml } from './encryption-info-xml';
|
|
25
|
+
function __gt() {
|
|
26
|
+
// Prefer Node global; fall back to browser window. Avoid @types/node.
|
|
27
|
+
var g = (function () {
|
|
28
|
+
try {
|
|
29
|
+
// eslint-disable-next-line no-new-func
|
|
30
|
+
return Function('return this')();
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
})();
|
|
36
|
+
return g || {};
|
|
37
|
+
}
|
|
38
|
+
var HEADER_BYTES = 8;
|
|
39
|
+
/**
|
|
40
|
+
* Parses EncryptionInfo stream bytes into an Agile model.
|
|
41
|
+
*
|
|
42
|
+
* @throws {UnsupportedEncryptionError} Standard Encryption or unknown version/alg.
|
|
43
|
+
* @throws {EncryptedPackageError} Truncated or missing required Agile fields.
|
|
44
|
+
*/
|
|
45
|
+
export function parseAgileEncryptionInfo(encryptionInfo, limits) {
|
|
46
|
+
if (encryptionInfo.byteLength < HEADER_BYTES + 1) {
|
|
47
|
+
throw new EncryptedPackageError('EncryptionInfo stream is truncated');
|
|
48
|
+
}
|
|
49
|
+
var view = new DataView(encryptionInfo.buffer, encryptionInfo.byteOffset, encryptionInfo.byteLength);
|
|
50
|
+
var versionMajor = view.getUint16(0, true);
|
|
51
|
+
var versionMinor = view.getUint16(2, true);
|
|
52
|
+
var reserved = view.getUint32(4, true);
|
|
53
|
+
// Standard Encryption: major 2|3|4, minor 2 ([MS-OFFCRYPTO] §2.3.4.5).
|
|
54
|
+
if (versionMinor === STANDARD_ENCRYPTION_VERSION_MINOR &&
|
|
55
|
+
(versionMajor === 2 || versionMajor === 3 || versionMajor === 4)) {
|
|
56
|
+
throw new UnsupportedEncryptionError('OFFCRYPTO Standard Encryption (EncryptionInfo minor version 2) is not supported; Agile (4.4) only');
|
|
57
|
+
}
|
|
58
|
+
if (versionMajor !== AGILE_VERSION_MAJOR || versionMinor !== AGILE_VERSION_MINOR) {
|
|
59
|
+
throw new UnsupportedEncryptionError("Unsupported EncryptionInfo version " + String(versionMajor) + "." + String(versionMinor));
|
|
60
|
+
}
|
|
61
|
+
if (reserved !== AGILE_RESERVED) {
|
|
62
|
+
throw new UnsupportedEncryptionError("Unsupported EncryptionInfo reserved field 0x" + reserved.toString(16));
|
|
63
|
+
}
|
|
64
|
+
var xmlBytes = encryptionInfo.subarray(HEADER_BYTES);
|
|
65
|
+
var xmlText = utf8Decode(xmlBytes);
|
|
66
|
+
var root;
|
|
67
|
+
try {
|
|
68
|
+
root = parseEncryptionInfoXml(xmlText, limits, 'EncryptionInfo');
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
if (err instanceof EncryptedPackageError || err instanceof UnsupportedEncryptionError) {
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
74
|
+
if (err instanceof Error && err.name === 'PackageLimitError') {
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
var msg = err instanceof Error ? err.message : 'XML parse failed';
|
|
78
|
+
throw new EncryptedPackageError("EncryptionInfo XML is invalid: " + msg);
|
|
79
|
+
}
|
|
80
|
+
if (root.localName !== 'encryption' || root.namespaceUri !== AGILE_ENCRYPTION_NS) {
|
|
81
|
+
// Accept default-ns resolution failures only when localName matches and NS empty
|
|
82
|
+
// after serializers omit xmlns on root (rare); still require encryption localName.
|
|
83
|
+
if (root.localName !== 'encryption') {
|
|
84
|
+
throw new EncryptedPackageError('EncryptionInfo root element is not encryption');
|
|
85
|
+
}
|
|
86
|
+
if (root.namespaceUri !== '' && root.namespaceUri !== AGILE_ENCRYPTION_NS) {
|
|
87
|
+
throw new EncryptedPackageError('EncryptionInfo root element is not encryption');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
var keyDataEl = findChild(root, AGILE_ENCRYPTION_NS, 'keyData');
|
|
91
|
+
var dataIntegrityEl = findChildOptional(root, AGILE_ENCRYPTION_NS, 'dataIntegrity');
|
|
92
|
+
var keyEncryptorsEl = findChild(root, AGILE_ENCRYPTION_NS, 'keyEncryptors');
|
|
93
|
+
var keyData = parseKeyData(keyDataEl);
|
|
94
|
+
var dataIntegrity = dataIntegrityEl === undefined ? undefined : parseDataIntegrity(dataIntegrityEl);
|
|
95
|
+
var passwordKeyEncryptor = parsePasswordKeyEncryptor(keyEncryptorsEl);
|
|
96
|
+
return { keyData: keyData, dataIntegrity: dataIntegrity, passwordKeyEncryptor: passwordKeyEncryptor };
|
|
97
|
+
}
|
|
98
|
+
function parseKeyData(el) {
|
|
99
|
+
var saltSize = requirePositiveIntAttr(el, 'saltSize');
|
|
100
|
+
var blockSize = requirePositiveIntAttr(el, 'blockSize');
|
|
101
|
+
var keyBits = requirePositiveIntAttr(el, 'keyBits');
|
|
102
|
+
var hashSize = requirePositiveIntAttr(el, 'hashSize');
|
|
103
|
+
var cipherAlgorithm = requireAttr(el, 'cipherAlgorithm');
|
|
104
|
+
var cipherChaining = requireAttr(el, 'cipherChaining');
|
|
105
|
+
var hashAlgorithmRaw = requireAttr(el, 'hashAlgorithm');
|
|
106
|
+
var saltValue = requireBase64Attr(el, 'saltValue');
|
|
107
|
+
assertSupportedCipher(cipherAlgorithm, cipherChaining);
|
|
108
|
+
assertAesKeyBits(keyBits);
|
|
109
|
+
var hashAlgorithm = resolveHashAlgorithm(hashAlgorithmRaw);
|
|
110
|
+
if (blockSize !== 16) {
|
|
111
|
+
throw new UnsupportedEncryptionError("Unsupported OFFCRYPTO blockSize: " + String(blockSize) + " (AES requires 16)");
|
|
112
|
+
}
|
|
113
|
+
if (saltValue.byteLength !== saltSize) {
|
|
114
|
+
throw new EncryptedPackageError('keyData saltValue length does not match saltSize');
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
saltSize: saltSize,
|
|
118
|
+
blockSize: blockSize,
|
|
119
|
+
keyBits: keyBits,
|
|
120
|
+
hashSize: hashSize,
|
|
121
|
+
cipherAlgorithm: cipherAlgorithm,
|
|
122
|
+
cipherChaining: cipherChaining,
|
|
123
|
+
hashAlgorithm: hashAlgorithm,
|
|
124
|
+
saltValue: saltValue,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function parseDataIntegrity(el) {
|
|
128
|
+
return {
|
|
129
|
+
encryptedHmacKey: requireBase64Attr(el, 'encryptedHmacKey'),
|
|
130
|
+
encryptedHmacValue: requireBase64Attr(el, 'encryptedHmacValue'),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function parsePasswordKeyEncryptor(keyEncryptorsEl) {
|
|
134
|
+
var e_1, _a;
|
|
135
|
+
var encryptorEls = keyEncryptorsEl.children.filter(function (c) { return c.kind === 'element' && c.localName === 'keyEncryptor'; });
|
|
136
|
+
if (encryptorEls.length === 0) {
|
|
137
|
+
throw new EncryptedPackageError('EncryptionInfo has no keyEncryptor');
|
|
138
|
+
}
|
|
139
|
+
var passwordEl;
|
|
140
|
+
try {
|
|
141
|
+
for (var encryptorEls_1 = __values(encryptorEls), encryptorEls_1_1 = encryptorEls_1.next(); !encryptorEls_1_1.done; encryptorEls_1_1 = encryptorEls_1.next()) {
|
|
142
|
+
var ke = encryptorEls_1_1.value;
|
|
143
|
+
var uri = getAttr(ke, 'uri');
|
|
144
|
+
if (uri === PASSWORD_KEY_ENCRYPTOR_URI) {
|
|
145
|
+
passwordEl = findEncryptedKey(ke);
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
if (uri !== undefined && uri.length > 0) {
|
|
149
|
+
throw new UnsupportedEncryptionError('OFFCRYPTO certificate (or non-password) keyEncryptor is not supported');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
154
|
+
finally {
|
|
155
|
+
try {
|
|
156
|
+
if (encryptorEls_1_1 && !encryptorEls_1_1.done && (_a = encryptorEls_1.return)) _a.call(encryptorEls_1);
|
|
157
|
+
}
|
|
158
|
+
finally { if (e_1) throw e_1.error; }
|
|
159
|
+
}
|
|
160
|
+
if (passwordEl === undefined) {
|
|
161
|
+
throw new UnsupportedEncryptionError('OFFCRYPTO EncryptionInfo has no password keyEncryptor');
|
|
162
|
+
}
|
|
163
|
+
var spinCount = requireNonNegativeIntAttr(passwordEl, 'spinCount');
|
|
164
|
+
if (spinCount > MAX_SPIN_COUNT) {
|
|
165
|
+
throw new EncryptedPackageError("OFFCRYPTO spinCount exceeds maximum allowed (" + String(MAX_SPIN_COUNT) + ")");
|
|
166
|
+
}
|
|
167
|
+
var saltSize = requirePositiveIntAttr(passwordEl, 'saltSize');
|
|
168
|
+
var blockSize = requirePositiveIntAttr(passwordEl, 'blockSize');
|
|
169
|
+
var keyBits = requirePositiveIntAttr(passwordEl, 'keyBits');
|
|
170
|
+
var hashSize = requirePositiveIntAttr(passwordEl, 'hashSize');
|
|
171
|
+
var cipherAlgorithm = requireAttr(passwordEl, 'cipherAlgorithm');
|
|
172
|
+
var cipherChaining = requireAttr(passwordEl, 'cipherChaining');
|
|
173
|
+
var hashAlgorithmRaw = requireAttr(passwordEl, 'hashAlgorithm');
|
|
174
|
+
var saltValue = requireBase64Attr(passwordEl, 'saltValue');
|
|
175
|
+
var encryptedVerifierHashInput = requireBase64Attr(passwordEl, 'encryptedVerifierHashInput');
|
|
176
|
+
var encryptedVerifierHashValue = requireBase64Attr(passwordEl, 'encryptedVerifierHashValue');
|
|
177
|
+
var encryptedKeyValue = requireBase64Attr(passwordEl, 'encryptedKeyValue');
|
|
178
|
+
assertSupportedCipher(cipherAlgorithm, cipherChaining);
|
|
179
|
+
assertAesKeyBits(keyBits);
|
|
180
|
+
var hashAlgorithm = resolveHashAlgorithm(hashAlgorithmRaw);
|
|
181
|
+
if (blockSize !== 16) {
|
|
182
|
+
throw new UnsupportedEncryptionError("Unsupported password keyEncryptor blockSize: " + String(blockSize));
|
|
183
|
+
}
|
|
184
|
+
if (saltValue.byteLength !== saltSize) {
|
|
185
|
+
throw new EncryptedPackageError('encryptedKey saltValue length does not match saltSize');
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
spinCount: spinCount,
|
|
189
|
+
saltSize: saltSize,
|
|
190
|
+
blockSize: blockSize,
|
|
191
|
+
keyBits: keyBits,
|
|
192
|
+
hashSize: hashSize,
|
|
193
|
+
cipherAlgorithm: cipherAlgorithm,
|
|
194
|
+
cipherChaining: cipherChaining,
|
|
195
|
+
hashAlgorithm: hashAlgorithm,
|
|
196
|
+
saltValue: saltValue,
|
|
197
|
+
encryptedVerifierHashInput: encryptedVerifierHashInput,
|
|
198
|
+
encryptedVerifierHashValue: encryptedVerifierHashValue,
|
|
199
|
+
encryptedKeyValue: encryptedKeyValue,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function findEncryptedKey(keyEncryptor) {
|
|
203
|
+
var e_2, _a;
|
|
204
|
+
try {
|
|
205
|
+
for (var _b = __values(keyEncryptor.children), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
206
|
+
var child = _c.value;
|
|
207
|
+
if (child.kind !== 'element') {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
if (child.localName === 'encryptedKey') {
|
|
211
|
+
return child;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
216
|
+
finally {
|
|
217
|
+
try {
|
|
218
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
219
|
+
}
|
|
220
|
+
finally { if (e_2) throw e_2.error; }
|
|
221
|
+
}
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
function findChild(parent, ns, localName) {
|
|
225
|
+
var el = findChildOptional(parent, ns, localName);
|
|
226
|
+
if (el === undefined) {
|
|
227
|
+
throw new EncryptedPackageError("EncryptionInfo missing element " + localName);
|
|
228
|
+
}
|
|
229
|
+
return el;
|
|
230
|
+
}
|
|
231
|
+
function findChildOptional(parent, ns, localName) {
|
|
232
|
+
var e_3, _a, e_4, _b;
|
|
233
|
+
try {
|
|
234
|
+
for (var _c = __values(parent.children), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
235
|
+
var child = _d.value;
|
|
236
|
+
if (child.kind !== 'element') {
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (child.localName === localName && (child.namespaceUri === ns || child.namespaceUri === '')) {
|
|
240
|
+
return child;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
245
|
+
finally {
|
|
246
|
+
try {
|
|
247
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
248
|
+
}
|
|
249
|
+
finally { if (e_3) throw e_3.error; }
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
for (var _e = __values(parent.children), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
253
|
+
var child = _f.value;
|
|
254
|
+
if (child.kind === 'element' && child.localName === localName) {
|
|
255
|
+
return child;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
260
|
+
finally {
|
|
261
|
+
try {
|
|
262
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
263
|
+
}
|
|
264
|
+
finally { if (e_4) throw e_4.error; }
|
|
265
|
+
}
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
268
|
+
function getAttr(el, localName) {
|
|
269
|
+
var e_5, _a;
|
|
270
|
+
try {
|
|
271
|
+
for (var _b = __values(el.attributes), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
272
|
+
var a = _c.value;
|
|
273
|
+
if (a.localName === localName) {
|
|
274
|
+
return a.value;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
279
|
+
finally {
|
|
280
|
+
try {
|
|
281
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
282
|
+
}
|
|
283
|
+
finally { if (e_5) throw e_5.error; }
|
|
284
|
+
}
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
function requireAttr(el, localName) {
|
|
288
|
+
var v = getAttr(el, localName);
|
|
289
|
+
if (v === undefined || v.length === 0) {
|
|
290
|
+
throw new EncryptedPackageError("EncryptionInfo missing attribute " + localName);
|
|
291
|
+
}
|
|
292
|
+
return v;
|
|
293
|
+
}
|
|
294
|
+
function requirePositiveIntAttr(el, localName) {
|
|
295
|
+
var raw = requireAttr(el, localName);
|
|
296
|
+
var n = Number.parseInt(raw, 10);
|
|
297
|
+
if (!Number.isFinite(n) || n <= 0) {
|
|
298
|
+
throw new EncryptedPackageError("EncryptionInfo attribute " + localName + " is invalid");
|
|
299
|
+
}
|
|
300
|
+
return n;
|
|
301
|
+
}
|
|
302
|
+
function requireNonNegativeIntAttr(el, localName) {
|
|
303
|
+
var raw = requireAttr(el, localName);
|
|
304
|
+
var n = Number.parseInt(raw, 10);
|
|
305
|
+
if (!Number.isFinite(n) || n < 0) {
|
|
306
|
+
throw new EncryptedPackageError("EncryptionInfo attribute " + localName + " is invalid");
|
|
307
|
+
}
|
|
308
|
+
return n;
|
|
309
|
+
}
|
|
310
|
+
function requireBase64Attr(el, localName) {
|
|
311
|
+
var raw = requireAttr(el, localName);
|
|
312
|
+
try {
|
|
313
|
+
return base64Decode(raw);
|
|
314
|
+
}
|
|
315
|
+
catch (_a) {
|
|
316
|
+
throw new EncryptedPackageError("EncryptionInfo attribute " + localName + " is not valid base64");
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function base64Decode(value) {
|
|
320
|
+
var normalized = value.replace(/\s+/g, '');
|
|
321
|
+
if (typeof __gt().atob === 'function') {
|
|
322
|
+
var bin = __gt().atob(normalized);
|
|
323
|
+
var out = new Uint8Array(bin.length);
|
|
324
|
+
for (var i = 0; i < bin.length; i++) {
|
|
325
|
+
out[i] = bin.charCodeAt(i);
|
|
326
|
+
}
|
|
327
|
+
return out;
|
|
328
|
+
}
|
|
329
|
+
return new Uint8Array(Buffer.from(normalized, 'base64'));
|
|
330
|
+
}
|
|
331
|
+
function utf8Decode(bytes) {
|
|
332
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
333
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AgilePasswordKeyEncryptor } from './agile-encryption-info';
|
|
2
|
+
/**
|
|
3
|
+
* Verifies the password and returns the secret key used to decrypt EncryptedPackage
|
|
4
|
+
* (decrypted encryptedKeyValue, truncated to keyBits/8).
|
|
5
|
+
*
|
|
6
|
+
* @throws {InvalidPasswordError} When verifier hash does not match.
|
|
7
|
+
*/
|
|
8
|
+
export declare function unlockIntermediateKey(password: string, encryptor: AgilePasswordKeyEncryptor): Uint8Array;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Password key encryptor verifier and intermediate key ([MS-OFFCRYPTO] §2.3.4.13).
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* 1. Derive key with blockKey `BLOCK_KEY_VERIFIER_INPUT`; decrypt encryptedVerifierHashInput.
|
|
6
|
+
* 2. Hash the decrypted verifier input; derive key with `BLOCK_KEY_VERIFIER_HASH`;
|
|
7
|
+
* decrypt encryptedVerifierHashValue; compare first hashSize bytes → else InvalidPasswordError.
|
|
8
|
+
* 3. Derive key with `BLOCK_KEY_ENCRYPTED_KEY`; decrypt encryptedKeyValue → intermediate key
|
|
9
|
+
* (truncated to keyBits/8).
|
|
10
|
+
*
|
|
11
|
+
* Integrity HMAC failure uses the same InvalidPasswordError (fail-closed; do not
|
|
12
|
+
* distinguish wrong password vs tampered package in the public message).
|
|
13
|
+
*
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
import { InvalidPasswordError } from './errors';
|
|
17
|
+
import { BLOCK_KEY_ENCRYPTOR_KEY, BLOCK_KEY_VERIFIER_HASH, BLOCK_KEY_VERIFIER_INPUT, } from './agile-constants';
|
|
18
|
+
import { aesCbcDecrypt, deriveAgileIv, deriveAgileKey, encodePasswordUtf16Le, hashBytes, timingSafeEqual, } from './crypto-primitives';
|
|
19
|
+
/**
|
|
20
|
+
* Verifies the password and returns the secret key used to decrypt EncryptedPackage
|
|
21
|
+
* (decrypted encryptedKeyValue, truncated to keyBits/8).
|
|
22
|
+
*
|
|
23
|
+
* @throws {InvalidPasswordError} When verifier hash does not match.
|
|
24
|
+
*/
|
|
25
|
+
export function unlockIntermediateKey(password, encryptor) {
|
|
26
|
+
var passwordBytes = encodePasswordUtf16Le(password);
|
|
27
|
+
var hashAlgorithm = encryptor.hashAlgorithm, saltValue = encryptor.saltValue, spinCount = encryptor.spinCount, keyBits = encryptor.keyBits, blockSize = encryptor.blockSize, hashSize = encryptor.hashSize;
|
|
28
|
+
// --- verifier hash input ---
|
|
29
|
+
var keyVerifierInput = deriveAgileKey(hashAlgorithm, saltValue, passwordBytes, spinCount, BLOCK_KEY_VERIFIER_INPUT, keyBits);
|
|
30
|
+
var ivVerifierInput = deriveAgileIv(hashAlgorithm, saltValue, undefined, blockSize);
|
|
31
|
+
var verifierInputPadded = aesCbcDecrypt(keyVerifierInput, ivVerifierInput, encryptor.encryptedVerifierHashInput);
|
|
32
|
+
// §2.3.4.13: verifier input is saltSize random bytes (zero-padded to blockSize on encrypt).
|
|
33
|
+
if (verifierInputPadded.byteLength < encryptor.saltSize) {
|
|
34
|
+
throw new InvalidPasswordError();
|
|
35
|
+
}
|
|
36
|
+
var verifierInput = verifierInputPadded.subarray(0, encryptor.saltSize);
|
|
37
|
+
var verifierHashComputed = hashBytes(hashAlgorithm, verifierInput);
|
|
38
|
+
// --- verifier hash value ---
|
|
39
|
+
var keyVerifierHash = deriveAgileKey(hashAlgorithm, saltValue, passwordBytes, spinCount, BLOCK_KEY_VERIFIER_HASH, keyBits);
|
|
40
|
+
var ivVerifierHash = deriveAgileIv(hashAlgorithm, saltValue, undefined, blockSize);
|
|
41
|
+
var verifierHashDecrypted = aesCbcDecrypt(keyVerifierHash, ivVerifierHash, encryptor.encryptedVerifierHashValue);
|
|
42
|
+
var expectedLen = Math.min(hashSize, verifierHashComputed.byteLength, verifierHashDecrypted.byteLength);
|
|
43
|
+
if (expectedLen <= 0) {
|
|
44
|
+
throw new InvalidPasswordError();
|
|
45
|
+
}
|
|
46
|
+
if (!timingSafeEqual(verifierHashComputed.subarray(0, expectedLen), verifierHashDecrypted.subarray(0, expectedLen))) {
|
|
47
|
+
throw new InvalidPasswordError();
|
|
48
|
+
}
|
|
49
|
+
// --- encrypted key value → intermediate / secret key ---
|
|
50
|
+
var keyEncryptedKey = deriveAgileKey(hashAlgorithm, saltValue, passwordBytes, spinCount, BLOCK_KEY_ENCRYPTOR_KEY, keyBits);
|
|
51
|
+
var ivEncryptedKey = deriveAgileIv(hashAlgorithm, saltValue, undefined, blockSize);
|
|
52
|
+
var decryptedKey = aesCbcDecrypt(keyEncryptedKey, ivEncryptedKey, encryptor.encryptedKeyValue);
|
|
53
|
+
var keyLen = keyBits / 8;
|
|
54
|
+
if (decryptedKey.byteLength < keyLen) {
|
|
55
|
+
throw new InvalidPasswordError();
|
|
56
|
+
}
|
|
57
|
+
return decryptedKey.subarray(0, keyLen);
|
|
58
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface OffCryptoStreams {
|
|
2
|
+
readonly encryptionInfo: Uint8Array;
|
|
3
|
+
readonly encryptedPackage: Uint8Array;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Extracts `\EncryptionInfo` and `\EncryptedPackage` from an OFFCRYPTO CFB.
|
|
7
|
+
*
|
|
8
|
+
* @param input - Entire OLE compound-file bytes.
|
|
9
|
+
* @throws {EncryptedPackageError} When structure is incomplete or streams missing.
|
|
10
|
+
*/
|
|
11
|
+
export declare function readOffCryptoStreams(input: Uint8Array): OffCryptoStreams;
|