@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,282 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Minimal attribute-oriented XML element parser for OFFCRYPTO EncryptionInfo.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* EncryptionInfo XML is a small attribute-heavy tree (encryption / keyData /
|
|
6
|
+
* dataIntegrity / keyEncryptors). This parser intentionally does **not** pull a
|
|
7
|
+
* full OOXML DOM. It supports nested elements, attributes, default namespaces,
|
|
8
|
+
* and rejects DOCTYPE / entity expansion.
|
|
9
|
+
*
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
13
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
+
if (!m) return o;
|
|
15
|
+
var i = m.call(o), r, ar = [], e;
|
|
16
|
+
try {
|
|
17
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
+
}
|
|
19
|
+
catch (error) { e = { error: error }; }
|
|
20
|
+
finally {
|
|
21
|
+
try {
|
|
22
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
+
}
|
|
24
|
+
finally { if (e) throw e.error; }
|
|
25
|
+
}
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
var __spread = (this && this.__spread) || function () {
|
|
29
|
+
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
import { EncryptedPackageError, PackageLimitError, } from './errors';
|
|
33
|
+
var DEFAULT_XML_NESTING = 256;
|
|
34
|
+
var DEFAULT_XML_ATTRS = 4096;
|
|
35
|
+
var DEFAULT_TEXT_NODE = 32 * 1024 * 1024;
|
|
36
|
+
/**
|
|
37
|
+
* Parses EncryptionInfo UTF-8 XML into a single root element tree.
|
|
38
|
+
*
|
|
39
|
+
* @throws {EncryptedPackageError} Malformed XML.
|
|
40
|
+
* @throws {PackageLimitError} Nesting / attribute / text limits.
|
|
41
|
+
*/
|
|
42
|
+
export function parseEncryptionInfoXml(xmlText, limits, partName) {
|
|
43
|
+
if (partName === void 0) { partName = 'EncryptionInfo'; }
|
|
44
|
+
if (/<!DOCTYPE/i.test(xmlText) || /<!ENTITY/i.test(xmlText)) {
|
|
45
|
+
throw new EncryptedPackageError('EncryptionInfo XML must not contain DTD or entities');
|
|
46
|
+
}
|
|
47
|
+
var maxDepth = (limits.xmlNestingDepth != null ? limits.xmlNestingDepth : DEFAULT_XML_NESTING);
|
|
48
|
+
var maxAttrs = (limits.xmlAttributesPerElement != null ? limits.xmlAttributesPerElement : DEFAULT_XML_ATTRS);
|
|
49
|
+
var maxText = (limits.textNodeLengthBytes != null ? limits.textNodeLengthBytes : DEFAULT_TEXT_NODE);
|
|
50
|
+
var i = 0;
|
|
51
|
+
var length = xmlText.length;
|
|
52
|
+
var skipWs = function () {
|
|
53
|
+
while (i < length) {
|
|
54
|
+
var c = xmlText.charCodeAt(i);
|
|
55
|
+
if (c === 0x20 || c === 0x09 || c === 0x0a || c === 0x0d) {
|
|
56
|
+
i += 1;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var peek = function () { return (i < length ? xmlText[i] : ''); };
|
|
64
|
+
var startsWith = function (s) { return xmlText.startsWith(s, i); };
|
|
65
|
+
var readName = function () {
|
|
66
|
+
var start = i;
|
|
67
|
+
while (i < length) {
|
|
68
|
+
var c = xmlText[i];
|
|
69
|
+
if (/[A-Za-z0-9:_.-]/.test(c)) {
|
|
70
|
+
i += 1;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (i === start) {
|
|
77
|
+
throw new EncryptedPackageError('EncryptionInfo XML is invalid: expected name');
|
|
78
|
+
}
|
|
79
|
+
return xmlText.slice(start, i);
|
|
80
|
+
};
|
|
81
|
+
var decodeEntities = function (raw) {
|
|
82
|
+
return raw
|
|
83
|
+
.replace(/</g, '<')
|
|
84
|
+
.replace(/>/g, '>')
|
|
85
|
+
.replace(/"/g, '"')
|
|
86
|
+
.replace(/'/g, "'")
|
|
87
|
+
.replace(/&/g, '&');
|
|
88
|
+
};
|
|
89
|
+
var readAttrValue = function () {
|
|
90
|
+
var quote = peek();
|
|
91
|
+
if (quote !== '"' && quote !== "'") {
|
|
92
|
+
throw new EncryptedPackageError('EncryptionInfo XML is invalid: attribute value');
|
|
93
|
+
}
|
|
94
|
+
i += 1;
|
|
95
|
+
var start = i;
|
|
96
|
+
while (i < length && xmlText[i] !== quote) {
|
|
97
|
+
i += 1;
|
|
98
|
+
if (i - start > maxText) {
|
|
99
|
+
throw new PackageLimitError('textNodeLengthBytes', { partName: partName, actual: i - start });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (i >= length) {
|
|
103
|
+
throw new EncryptedPackageError('EncryptionInfo XML is invalid: unclosed attribute');
|
|
104
|
+
}
|
|
105
|
+
var value = xmlText.slice(start, i);
|
|
106
|
+
i += 1; // closing quote
|
|
107
|
+
return decodeEntities(value);
|
|
108
|
+
};
|
|
109
|
+
var resolveQName = function (qName, nsStack, isAttr) {
|
|
110
|
+
var colon = qName.indexOf(':');
|
|
111
|
+
var prefix = colon === -1 ? '' : qName.slice(0, colon);
|
|
112
|
+
var localName = colon === -1 ? qName : qName.slice(colon + 1);
|
|
113
|
+
if (isAttr && prefix === '') {
|
|
114
|
+
return { localName: localName, namespaceUri: '' };
|
|
115
|
+
}
|
|
116
|
+
if (prefix === 'xmlns') {
|
|
117
|
+
return { localName: localName, namespaceUri: 'http://www.w3.org/2000/xmlns/' };
|
|
118
|
+
}
|
|
119
|
+
for (var s = nsStack.length - 1; s >= 0; s--) {
|
|
120
|
+
var uri = nsStack[s].get(prefix);
|
|
121
|
+
if (uri !== undefined) {
|
|
122
|
+
return { localName: localName, namespaceUri: uri };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return { localName: localName, namespaceUri: '' };
|
|
126
|
+
};
|
|
127
|
+
var parseElement = function (nsStack, depth) {
|
|
128
|
+
if (depth > maxDepth) {
|
|
129
|
+
throw new PackageLimitError('xmlNestingDepth', { partName: partName, actual: depth });
|
|
130
|
+
}
|
|
131
|
+
if (peek() !== '<') {
|
|
132
|
+
throw new EncryptedPackageError('EncryptionInfo XML is invalid: expected element');
|
|
133
|
+
}
|
|
134
|
+
i += 1; // <
|
|
135
|
+
if (peek() === '/') {
|
|
136
|
+
throw new EncryptedPackageError('EncryptionInfo XML is invalid: unexpected end tag');
|
|
137
|
+
}
|
|
138
|
+
// Skip processing instructions / comments / XML declaration at this level via caller.
|
|
139
|
+
var rawName = readName();
|
|
140
|
+
skipWs();
|
|
141
|
+
var pendingAttrs = [];
|
|
142
|
+
var selfClosing = false;
|
|
143
|
+
var localNs = new Map();
|
|
144
|
+
while (i < length && peek() !== '>' && peek() !== '/') {
|
|
145
|
+
var attrName = readName();
|
|
146
|
+
skipWs();
|
|
147
|
+
if (peek() !== '=') {
|
|
148
|
+
throw new EncryptedPackageError('EncryptionInfo XML is invalid: expected =');
|
|
149
|
+
}
|
|
150
|
+
i += 1;
|
|
151
|
+
skipWs();
|
|
152
|
+
var attrValue = readAttrValue();
|
|
153
|
+
skipWs();
|
|
154
|
+
if (attrName === 'xmlns') {
|
|
155
|
+
localNs.set('', attrValue);
|
|
156
|
+
}
|
|
157
|
+
else if (attrName.startsWith('xmlns:')) {
|
|
158
|
+
localNs.set(attrName.slice(6), attrValue);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
pendingAttrs.push({ qName: attrName, value: attrValue });
|
|
162
|
+
}
|
|
163
|
+
if (pendingAttrs.length > maxAttrs) {
|
|
164
|
+
throw new PackageLimitError('xmlAttributesPerElement', {
|
|
165
|
+
partName: partName,
|
|
166
|
+
actual: pendingAttrs.length,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (startsWith('/>')) {
|
|
171
|
+
selfClosing = true;
|
|
172
|
+
i += 2;
|
|
173
|
+
}
|
|
174
|
+
else if (peek() === '>') {
|
|
175
|
+
i += 1;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
throw new EncryptedPackageError('EncryptionInfo XML is invalid: element tag');
|
|
179
|
+
}
|
|
180
|
+
var childNsStack = __spread(nsStack, [localNs]);
|
|
181
|
+
var nameResolved = resolveQName(rawName, childNsStack, false);
|
|
182
|
+
var attributes = pendingAttrs.map(function (a) {
|
|
183
|
+
var r = resolveQName(a.qName, childNsStack, true);
|
|
184
|
+
return { localName: r.localName, namespaceUri: r.namespaceUri, value: a.value };
|
|
185
|
+
});
|
|
186
|
+
if (selfClosing) {
|
|
187
|
+
return { kind: 'element',
|
|
188
|
+
localName: nameResolved.localName,
|
|
189
|
+
namespaceUri: nameResolved.namespaceUri,
|
|
190
|
+
attributes: attributes,
|
|
191
|
+
children: [],
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
var children = [];
|
|
195
|
+
for (;;) {
|
|
196
|
+
skipWs();
|
|
197
|
+
if (i >= length) {
|
|
198
|
+
throw new EncryptedPackageError('EncryptionInfo XML is invalid: unclosed element');
|
|
199
|
+
}
|
|
200
|
+
if (startsWith('</')) {
|
|
201
|
+
i += 2;
|
|
202
|
+
var endName = readName();
|
|
203
|
+
skipWs();
|
|
204
|
+
if (peek() !== '>') {
|
|
205
|
+
throw new EncryptedPackageError('EncryptionInfo XML is invalid: end tag');
|
|
206
|
+
}
|
|
207
|
+
i += 1;
|
|
208
|
+
if (endName !== rawName) {
|
|
209
|
+
throw new EncryptedPackageError("EncryptionInfo XML is invalid: mismatched end tag " + endName);
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
if (startsWith('<!--')) {
|
|
214
|
+
var end = xmlText.indexOf('-->', i + 4);
|
|
215
|
+
if (end < 0) {
|
|
216
|
+
throw new EncryptedPackageError('EncryptionInfo XML is invalid: unclosed comment');
|
|
217
|
+
}
|
|
218
|
+
i = end + 3;
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (startsWith('<?')) {
|
|
222
|
+
var end = xmlText.indexOf('?>', i + 2);
|
|
223
|
+
if (end < 0) {
|
|
224
|
+
throw new EncryptedPackageError('EncryptionInfo XML is invalid: unclosed PI');
|
|
225
|
+
}
|
|
226
|
+
i = end + 2;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (peek() === '<') {
|
|
230
|
+
children.push(parseElement(childNsStack, depth + 1));
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
// Text node — EncryptionInfo does not need text content; skip with limit.
|
|
234
|
+
var textStart = i;
|
|
235
|
+
while (i < length && peek() !== '<') {
|
|
236
|
+
i += 1;
|
|
237
|
+
if (i - textStart > maxText) {
|
|
238
|
+
throw new PackageLimitError('textNodeLengthBytes', {
|
|
239
|
+
partName: partName,
|
|
240
|
+
actual: i - textStart,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return { kind: 'element',
|
|
246
|
+
localName: nameResolved.localName,
|
|
247
|
+
namespaceUri: nameResolved.namespaceUri,
|
|
248
|
+
attributes: attributes,
|
|
249
|
+
children: children,
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
// Skip BOM / XML declaration / leading comments.
|
|
253
|
+
skipWs();
|
|
254
|
+
if (startsWith('\uFEFF')) {
|
|
255
|
+
i += 1;
|
|
256
|
+
skipWs();
|
|
257
|
+
}
|
|
258
|
+
while (startsWith('<?') || startsWith('<!--')) {
|
|
259
|
+
if (startsWith('<?')) {
|
|
260
|
+
var end = xmlText.indexOf('?>', i + 2);
|
|
261
|
+
if (end < 0) {
|
|
262
|
+
throw new EncryptedPackageError('EncryptionInfo XML is invalid: unclosed declaration');
|
|
263
|
+
}
|
|
264
|
+
i = end + 2;
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
var end = xmlText.indexOf('-->', i + 4);
|
|
268
|
+
if (end < 0) {
|
|
269
|
+
throw new EncryptedPackageError('EncryptionInfo XML is invalid: unclosed comment');
|
|
270
|
+
}
|
|
271
|
+
i = end + 3;
|
|
272
|
+
}
|
|
273
|
+
skipWs();
|
|
274
|
+
}
|
|
275
|
+
var root = parseElement([new Map()], 1);
|
|
276
|
+
skipWs();
|
|
277
|
+
if (i < length) {
|
|
278
|
+
// Allow trailing whitespace only (already skipped); anything else is junk.
|
|
279
|
+
throw new EncryptedPackageError('EncryptionInfo XML is invalid: trailing content');
|
|
280
|
+
}
|
|
281
|
+
return root;
|
|
282
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encryption-related error types shared across Office libraries.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Messages must never include the consumer password or key material.
|
|
6
|
+
* Citation: [MS-OFFCRYPTO] §1.3.3.4, §2.3.4.4–§2.3.4.15.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Shared fields for limit-breach errors.
|
|
10
|
+
*/
|
|
11
|
+
export interface SecurityErrorOptions {
|
|
12
|
+
/** Package part that triggered the failure, when known. */
|
|
13
|
+
readonly partName?: string;
|
|
14
|
+
/** Observed value that exceeded the configured limit, when known. */
|
|
15
|
+
readonly actual?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Decrypt-relevant numeric guards (subset of broader package security limits).
|
|
19
|
+
*/
|
|
20
|
+
export interface DecryptSecurityLimits {
|
|
21
|
+
/** Maximum sum of uncompressed part bytes across the package. */
|
|
22
|
+
readonly totalUncompressedBytes: number;
|
|
23
|
+
/** Maximum uncompressed size of any single part / decrypted stream. */
|
|
24
|
+
readonly singlePartUncompressedBytes: number;
|
|
25
|
+
/** Maximum element nesting depth during EncryptionInfo XML parse. */
|
|
26
|
+
readonly xmlNestingDepth?: number;
|
|
27
|
+
/** Maximum attribute count on a single EncryptionInfo XML element. */
|
|
28
|
+
readonly xmlAttributesPerElement?: number;
|
|
29
|
+
/** Maximum length in bytes of a single EncryptionInfo XML text node. */
|
|
30
|
+
readonly textNodeLengthBytes?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Default decrypt limits aligned with typical Office package security defaults.
|
|
34
|
+
*/
|
|
35
|
+
export declare const DEFAULT_DECRYPT_SECURITY_LIMITS: DecryptSecurityLimits;
|
|
36
|
+
/**
|
|
37
|
+
* Builds effective decrypt limits from optional caller overrides.
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveDecryptLimits(overrides?: Partial<DecryptSecurityLimits>): DecryptSecurityLimits;
|
|
40
|
+
export declare class PackageLimitError extends Error {
|
|
41
|
+
/** Name of the limit field that was exceeded. */
|
|
42
|
+
readonly limit: keyof DecryptSecurityLimits | string;
|
|
43
|
+
/** Offending part name when applicable. */
|
|
44
|
+
readonly partName: string | undefined;
|
|
45
|
+
/** Observed value when known. */
|
|
46
|
+
readonly actual: number | undefined;
|
|
47
|
+
constructor(limit: keyof DecryptSecurityLimits | string, options?: SecurityErrorOptions);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Raised when the package is encrypted and cannot be opened as supplied.
|
|
51
|
+
*/
|
|
52
|
+
export declare class EncryptedPackageError extends Error {
|
|
53
|
+
constructor(message: string);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Raised when a consumer-supplied password fails OFFCRYPTO verification.
|
|
57
|
+
*/
|
|
58
|
+
export declare class InvalidPasswordError extends Error {
|
|
59
|
+
constructor(message?: string);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Raised when the package uses a recognized encryption method this build does not decrypt.
|
|
63
|
+
*/
|
|
64
|
+
export declare class UnsupportedEncryptionError extends Error {
|
|
65
|
+
constructor(message?: string);
|
|
66
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encryption-related error types shared across Office libraries.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Messages must never include the consumer password or key material.
|
|
6
|
+
* Citation: [MS-OFFCRYPTO] §1.3.3.4, §2.3.4.4–§2.3.4.15.
|
|
7
|
+
*/
|
|
8
|
+
var __extends = (this && this.__extends) || (function () {
|
|
9
|
+
var extendStatics = function (d, b) {
|
|
10
|
+
extendStatics = Object.setPrototypeOf ||
|
|
11
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
12
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
13
|
+
return extendStatics(d, b);
|
|
14
|
+
};
|
|
15
|
+
return function (d, b) {
|
|
16
|
+
extendStatics(d, b);
|
|
17
|
+
function __() { this.constructor = d; }
|
|
18
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
19
|
+
};
|
|
20
|
+
})();
|
|
21
|
+
var __assign = (this && this.__assign) || function () {
|
|
22
|
+
__assign = Object.assign || function(t) {
|
|
23
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
24
|
+
s = arguments[i];
|
|
25
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
26
|
+
t[p] = s[p];
|
|
27
|
+
}
|
|
28
|
+
return t;
|
|
29
|
+
};
|
|
30
|
+
return __assign.apply(this, arguments);
|
|
31
|
+
};
|
|
32
|
+
var ONE_KIB = 1024;
|
|
33
|
+
var ONE_MIB = ONE_KIB * 1024;
|
|
34
|
+
var ONE_GIB = ONE_MIB * 1024;
|
|
35
|
+
/**
|
|
36
|
+
* Default decrypt limits aligned with typical Office package security defaults.
|
|
37
|
+
*/
|
|
38
|
+
export var DEFAULT_DECRYPT_SECURITY_LIMITS = Object.freeze({
|
|
39
|
+
totalUncompressedBytes: 1 * ONE_GIB,
|
|
40
|
+
singlePartUncompressedBytes: 256 * ONE_MIB,
|
|
41
|
+
xmlNestingDepth: 256,
|
|
42
|
+
xmlAttributesPerElement: 4096,
|
|
43
|
+
textNodeLengthBytes: 32 * ONE_MIB,
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* Builds effective decrypt limits from optional caller overrides.
|
|
47
|
+
*/
|
|
48
|
+
export function resolveDecryptLimits(overrides) {
|
|
49
|
+
if (overrides === undefined) {
|
|
50
|
+
return DEFAULT_DECRYPT_SECURITY_LIMITS;
|
|
51
|
+
}
|
|
52
|
+
var xmlNestingDepth = (overrides.xmlNestingDepth != null ? overrides.xmlNestingDepth : DEFAULT_DECRYPT_SECURITY_LIMITS.xmlNestingDepth);
|
|
53
|
+
var xmlAttributesPerElement = (overrides.xmlAttributesPerElement != null ? overrides.xmlAttributesPerElement : DEFAULT_DECRYPT_SECURITY_LIMITS.xmlAttributesPerElement);
|
|
54
|
+
var textNodeLengthBytes = (overrides.textNodeLengthBytes != null ? overrides.textNodeLengthBytes : DEFAULT_DECRYPT_SECURITY_LIMITS.textNodeLengthBytes);
|
|
55
|
+
var resolved = __assign({ totalUncompressedBytes: (overrides.totalUncompressedBytes != null ? overrides.totalUncompressedBytes : DEFAULT_DECRYPT_SECURITY_LIMITS.totalUncompressedBytes), singlePartUncompressedBytes: (overrides.singlePartUncompressedBytes != null ? overrides.singlePartUncompressedBytes : DEFAULT_DECRYPT_SECURITY_LIMITS.singlePartUncompressedBytes) }, (xmlNestingDepth === undefined ? {} : { xmlNestingDepth: xmlNestingDepth }), (xmlAttributesPerElement === undefined ? {} : { xmlAttributesPerElement: xmlAttributesPerElement }), (textNodeLengthBytes === undefined ? {} : { textNodeLengthBytes: textNodeLengthBytes }));
|
|
56
|
+
return Object.freeze(resolved);
|
|
57
|
+
}
|
|
58
|
+
var PackageLimitError = /** @class */ (function (_super) {
|
|
59
|
+
__extends(PackageLimitError, _super);
|
|
60
|
+
function PackageLimitError(limit, options) {
|
|
61
|
+
var _newTarget = this.constructor;
|
|
62
|
+
if (options === void 0) { options = {}; }
|
|
63
|
+
var _this = this;
|
|
64
|
+
var partSuffix = options.partName === undefined ? '' : " (part: " + options.partName + ")";
|
|
65
|
+
var actualSuffix = options.actual === undefined ? '' : "; actual value: " + String(options.actual);
|
|
66
|
+
_this = _super.call(this, "Package security limit exceeded: " + limit + partSuffix + actualSuffix) || this;
|
|
67
|
+
_this.name = 'PackageLimitError';
|
|
68
|
+
_this.limit = limit;
|
|
69
|
+
_this.partName = options.partName;
|
|
70
|
+
_this.actual = options.actual;
|
|
71
|
+
// ES5 / AMD emit: restore prototype so `instanceof` works in browsers.
|
|
72
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
73
|
+
return _this;
|
|
74
|
+
}
|
|
75
|
+
return PackageLimitError;
|
|
76
|
+
}(Error));
|
|
77
|
+
export { PackageLimitError };
|
|
78
|
+
/**
|
|
79
|
+
* Raised when the package is encrypted and cannot be opened as supplied.
|
|
80
|
+
*/
|
|
81
|
+
var EncryptedPackageError = /** @class */ (function (_super) {
|
|
82
|
+
__extends(EncryptedPackageError, _super);
|
|
83
|
+
function EncryptedPackageError(message) {
|
|
84
|
+
var _newTarget = this.constructor;
|
|
85
|
+
var _this = _super.call(this, message) || this;
|
|
86
|
+
_this.name = 'EncryptedPackageError';
|
|
87
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
88
|
+
return _this;
|
|
89
|
+
}
|
|
90
|
+
return EncryptedPackageError;
|
|
91
|
+
}(Error));
|
|
92
|
+
export { EncryptedPackageError };
|
|
93
|
+
/**
|
|
94
|
+
* Raised when a consumer-supplied password fails OFFCRYPTO verification.
|
|
95
|
+
*/
|
|
96
|
+
var InvalidPasswordError = /** @class */ (function (_super) {
|
|
97
|
+
__extends(InvalidPasswordError, _super);
|
|
98
|
+
function InvalidPasswordError(message) {
|
|
99
|
+
var _newTarget = this.constructor;
|
|
100
|
+
if (message === void 0) { message = 'Invalid password'; }
|
|
101
|
+
var _this = _super.call(this, message) || this;
|
|
102
|
+
_this.name = 'InvalidPasswordError';
|
|
103
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
104
|
+
return _this;
|
|
105
|
+
}
|
|
106
|
+
return InvalidPasswordError;
|
|
107
|
+
}(Error));
|
|
108
|
+
export { InvalidPasswordError };
|
|
109
|
+
/**
|
|
110
|
+
* Raised when the package uses a recognized encryption method this build does not decrypt.
|
|
111
|
+
*/
|
|
112
|
+
var UnsupportedEncryptionError = /** @class */ (function (_super) {
|
|
113
|
+
__extends(UnsupportedEncryptionError, _super);
|
|
114
|
+
function UnsupportedEncryptionError(message) {
|
|
115
|
+
var _newTarget = this.constructor;
|
|
116
|
+
if (message === void 0) { message = 'Unsupported encryption method'; }
|
|
117
|
+
var _this = _super.call(this, message) || this;
|
|
118
|
+
_this.name = 'UnsupportedEncryptionError';
|
|
119
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
120
|
+
return _this;
|
|
121
|
+
}
|
|
122
|
+
return UnsupportedEncryptionError;
|
|
123
|
+
}(Error));
|
|
124
|
+
export { UnsupportedEncryptionError };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared OFFCRYPTO Agile password decrypt for Office Open XML packages.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Implements [MS-OFFCRYPTO] Agile EncryptionInfo (4.4) + password keyEncryptor
|
|
6
|
+
* + AES-CBC EncryptedPackage segment decrypt. Consumed by PowerPoint and other
|
|
7
|
+
* Office libraries via `@syncfusion/ej2-office-common`.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
import { DecryptSecurityLimits } from './errors';
|
|
12
|
+
/**
|
|
13
|
+
* Returns whether `input` begins with the OLE compound-file signature used by
|
|
14
|
+
* ECMA-376 OFFCRYPTO packages.
|
|
15
|
+
*
|
|
16
|
+
* @param input - Entire package bytes.
|
|
17
|
+
* @returns `true` when the CFB signature matches.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export declare function isOffCryptoPackage(input: Uint8Array | ArrayBuffer): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Decrypts an OFFCRYPTO OLE CFB package to OPC ZIP bytes.
|
|
24
|
+
*
|
|
25
|
+
* @param input - Entire encrypted package bytes (CFB).
|
|
26
|
+
* @param password - Consumer password (never logged; not retained).
|
|
27
|
+
* @param limits - Decrypt size / XML guards (duck-types broader SecurityLimits).
|
|
28
|
+
* @returns Decrypted OPC package bytes.
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export declare function decryptOffCryptoPackage(input: Uint8Array, password: string, limits?: DecryptSecurityLimits): Promise<Uint8Array>;
|
|
33
|
+
export { DEFAULT_DECRYPT_SECURITY_LIMITS, EncryptedPackageError, InvalidPasswordError, PackageLimitError, resolveDecryptLimits, UnsupportedEncryptionError, DecryptSecurityLimits, SecurityErrorOptions, } from './errors';
|
|
34
|
+
export { AGILE_ENCRYPTION_NS, AGILE_RESERVED, AGILE_VERSION_MAJOR, AGILE_VERSION_MINOR, BLOCK_KEY_ENCRYPTOR_KEY, BLOCK_KEY_HMAC_KEY, BLOCK_KEY_HMAC_VALUE, BLOCK_KEY_VERIFIER_HASH, BLOCK_KEY_VERIFIER_INPUT, ENCRYPTED_PACKAGE_SEGMENT_SIZE, PASSWORD_KEY_ENCRYPTOR_NS, PASSWORD_KEY_ENCRYPTOR_URI, STREAM_ENCRYPTED_PACKAGE, STREAM_ENCRYPTION_INFO, } from './agile-constants';
|
|
35
|
+
export { aesCbcDecrypt, aesCbcEncrypt, concatBytes, deriveAgileIv, deriveAgileKey, encodePasswordUtf16Le, hashBytes, hashDigestLength, hmacBytes, timingSafeEqual, AgileHashName, } from './crypto-primitives';
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared OFFCRYPTO Agile password decrypt for Office Open XML packages.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Implements [MS-OFFCRYPTO] Agile EncryptionInfo (4.4) + password keyEncryptor
|
|
6
|
+
* + AES-CBC EncryptedPackage segment decrypt. Consumed by PowerPoint and other
|
|
7
|
+
* Office libraries via `@syncfusion/ej2-office-common`.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
14
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
15
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
16
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
20
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
21
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
22
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
23
|
+
function step(op) {
|
|
24
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
25
|
+
while (_) try {
|
|
26
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
27
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
28
|
+
switch (op[0]) {
|
|
29
|
+
case 0: case 1: t = op; break;
|
|
30
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
31
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
32
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
33
|
+
default:
|
|
34
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
35
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
36
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
37
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
38
|
+
if (t[2]) _.ops.pop();
|
|
39
|
+
_.trys.pop(); continue;
|
|
40
|
+
}
|
|
41
|
+
op = body.call(thisArg, _);
|
|
42
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
43
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
import { parseAgileEncryptionInfo } from './agile-encryption-info';
|
|
47
|
+
import { unlockIntermediateKey } from './agile-password';
|
|
48
|
+
import { readOffCryptoStreams } from './cfb-reader';
|
|
49
|
+
import { decryptEncryptedPackageStream } from './decrypt-encrypted-package';
|
|
50
|
+
import { DEFAULT_DECRYPT_SECURITY_LIMITS, resolveDecryptLimits, } from './errors';
|
|
51
|
+
/** OLE CFB header signature used by ECMA-376 OFFCRYPTO packages ([MS-CFB]). */
|
|
52
|
+
var OLE_CFB_SIGNATURE = Object.freeze([0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1]);
|
|
53
|
+
/**
|
|
54
|
+
* Returns whether `input` begins with the OLE compound-file signature used by
|
|
55
|
+
* ECMA-376 OFFCRYPTO packages.
|
|
56
|
+
*
|
|
57
|
+
* @param input - Entire package bytes.
|
|
58
|
+
* @returns `true` when the CFB signature matches.
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
export function isOffCryptoPackage(input) {
|
|
63
|
+
var bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
|
|
64
|
+
if (bytes.byteLength < OLE_CFB_SIGNATURE.length) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
for (var i = 0; i < OLE_CFB_SIGNATURE.length; i++) {
|
|
68
|
+
if (bytes[i] !== OLE_CFB_SIGNATURE[i]) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Decrypts an OFFCRYPTO OLE CFB package to OPC ZIP bytes.
|
|
76
|
+
*
|
|
77
|
+
* @param input - Entire encrypted package bytes (CFB).
|
|
78
|
+
* @param password - Consumer password (never logged; not retained).
|
|
79
|
+
* @param limits - Decrypt size / XML guards (duck-types broader SecurityLimits).
|
|
80
|
+
* @returns Decrypted OPC package bytes.
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export function decryptOffCryptoPackage(input, password, limits) {
|
|
85
|
+
if (limits === void 0) { limits = DEFAULT_DECRYPT_SECURITY_LIMITS; }
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
+
var resolved, streams, info, secretKey;
|
|
88
|
+
return __generator(this, function (_a) {
|
|
89
|
+
resolved = resolveDecryptLimits(limits);
|
|
90
|
+
streams = readOffCryptoStreams(input);
|
|
91
|
+
info = parseAgileEncryptionInfo(streams.encryptionInfo, resolved);
|
|
92
|
+
secretKey = unlockIntermediateKey(password, info.passwordKeyEncryptor);
|
|
93
|
+
return [2 /*return*/, decryptEncryptedPackageStream(streams.encryptedPackage, secretKey, info.keyData, info.dataIntegrity, resolved)];
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
export { DEFAULT_DECRYPT_SECURITY_LIMITS, EncryptedPackageError, InvalidPasswordError, PackageLimitError, resolveDecryptLimits, UnsupportedEncryptionError, } from './errors';
|
|
98
|
+
// Re-export internals needed by test fixtures / host encrypt harnesses.
|
|
99
|
+
export { AGILE_ENCRYPTION_NS, AGILE_RESERVED, AGILE_VERSION_MAJOR, AGILE_VERSION_MINOR, BLOCK_KEY_ENCRYPTOR_KEY, BLOCK_KEY_HMAC_KEY, BLOCK_KEY_HMAC_VALUE, BLOCK_KEY_VERIFIER_HASH, BLOCK_KEY_VERIFIER_INPUT, ENCRYPTED_PACKAGE_SEGMENT_SIZE, PASSWORD_KEY_ENCRYPTOR_NS, PASSWORD_KEY_ENCRYPTOR_URI, STREAM_ENCRYPTED_PACKAGE, STREAM_ENCRYPTION_INFO, } from './agile-constants';
|
|
100
|
+
export { aesCbcDecrypt, aesCbcEncrypt, concatBytes, deriveAgileIv, deriveAgileKey, encodePasswordUtf16Le, hashBytes, hashDigestLength, hmacBytes, timingSafeEqual, } from './crypto-primitives';
|