@open-charging-cloud/chargy-core 0.9.0 → 0.9.1
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/README.md +14 -1
- package/dist/ACrypt.d.ts +2 -1
- package/dist/ACrypt.d.ts.map +1 -1
- package/dist/Alfen.d.ts.map +1 -1
- package/dist/BSMCrypt01.d.ts.map +1 -1
- package/dist/EMHCrypt01.d.ts.map +1 -1
- package/dist/GDFCrypt01.d.ts.map +1 -1
- package/dist/Mennekes.d.ts.map +1 -1
- package/dist/OCMF.d.ts +2 -0
- package/dist/OCMF.d.ts.map +1 -1
- package/dist/browser/index.js +204 -101
- package/dist/browser/index.js.map +1 -1
- package/dist/chargy.d.ts +6 -1
- package/dist/chargy.d.ts.map +1 -1
- package/dist/interfaces/chargyInterfaces.d.ts +3 -1
- package/dist/interfaces/chargyInterfaces.d.ts.map +1 -1
- package/dist/node/index.js +204 -101
- package/dist/node/index.js.map +1 -1
- package/i18n.json +35 -0
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -9841,11 +9841,16 @@ function CreateWarning(message, level = "low" /* low */) {
|
|
|
9841
9841
|
message
|
|
9842
9842
|
};
|
|
9843
9843
|
}
|
|
9844
|
-
function CreateError(message, level = "high" /* high
|
|
9845
|
-
|
|
9844
|
+
function CreateError(message, level = "high" /* high */, code, details) {
|
|
9845
|
+
const error = {
|
|
9846
9846
|
level,
|
|
9847
9847
|
message
|
|
9848
9848
|
};
|
|
9849
|
+
if (code !== void 0)
|
|
9850
|
+
error.code = code;
|
|
9851
|
+
if (details !== void 0)
|
|
9852
|
+
error.details = details;
|
|
9853
|
+
return error;
|
|
9849
9854
|
}
|
|
9850
9855
|
function isISessionCryptoResult1(obj) {
|
|
9851
9856
|
return isObject(obj) && obj["status"] !== void 0;
|
|
@@ -10831,6 +10836,20 @@ var ACrypt = class {
|
|
|
10831
10836
|
newText.classList.remove("overEntry");
|
|
10832
10837
|
};
|
|
10833
10838
|
}
|
|
10839
|
+
// Records why a verification step failed as structured data: a stable reason
|
|
10840
|
+
// key (localized via i18n.json and machine-switchable by the GUI) plus an
|
|
10841
|
+
// optional, language-neutral technical detail. Presentation is left to the GUI.
|
|
10842
|
+
AddVerificationError(cryptoResult, reasonKey, detail) {
|
|
10843
|
+
const details = detail instanceof Error ? detail.message : typeof detail === "string" ? detail : void 0;
|
|
10844
|
+
(cryptoResult.errors ??= []).push(
|
|
10845
|
+
CreateError(
|
|
10846
|
+
this.chargy.GetMultilanguageText(reasonKey),
|
|
10847
|
+
"high" /* high */,
|
|
10848
|
+
reasonKey,
|
|
10849
|
+
details
|
|
10850
|
+
)
|
|
10851
|
+
);
|
|
10852
|
+
}
|
|
10834
10853
|
};
|
|
10835
10854
|
var Alfen = class {
|
|
10836
10855
|
chargy;
|
|
@@ -11245,9 +11264,15 @@ var AlfenCrypt01 = class extends ACrypt {
|
|
|
11245
11264
|
cryptoResult.publicKey = meter.publicKeys[0]?.value;
|
|
11246
11265
|
cryptoResult.publicKeyFormat = meter.publicKeys[0]?.format;
|
|
11247
11266
|
cryptoResult.publicKeySignatures = meter.publicKeys[0]?.signatures;
|
|
11267
|
+
let publicKey;
|
|
11268
|
+
try {
|
|
11269
|
+
publicKey = buf2hex(this.chargy.base32Decode(cryptoResult.publicKey ?? "", "RFC4648"));
|
|
11270
|
+
} catch (exception) {
|
|
11271
|
+
this.AddVerificationError(cryptoResult, "Verification_PublicKeyDecodingFailed", exception);
|
|
11272
|
+
return setResult("InvalidPublicKey" /* InvalidPublicKey */);
|
|
11273
|
+
}
|
|
11274
|
+
let result = false;
|
|
11248
11275
|
try {
|
|
11249
|
-
const publicKey = buf2hex(this.chargy.base32Decode(cryptoResult.publicKey ?? "", "RFC4648"));
|
|
11250
|
-
let result = false;
|
|
11251
11276
|
switch (meter.publicKeys[0]?.algorithm ?? "") {
|
|
11252
11277
|
case "secp192r1":
|
|
11253
11278
|
cryptoResult.hashValue = await sha256(cryptoBuffer);
|
|
@@ -11292,25 +11317,29 @@ var AlfenCrypt01 = class extends ACrypt {
|
|
|
11292
11317
|
);
|
|
11293
11318
|
break;
|
|
11294
11319
|
}
|
|
11295
|
-
|
|
11296
|
-
|
|
11297
|
-
}
|
|
11298
|
-
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
11299
|
-
} catch {
|
|
11320
|
+
} catch (exception) {
|
|
11321
|
+
this.AddVerificationError(cryptoResult, "Verification_SignatureMalformed", exception);
|
|
11300
11322
|
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
11301
11323
|
}
|
|
11302
|
-
|
|
11324
|
+
if (result)
|
|
11325
|
+
return setResult("ValidSignature" /* ValidSignature */);
|
|
11326
|
+
this.AddVerificationError(cryptoResult, "Verification_SignatureMismatch");
|
|
11327
|
+
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
11328
|
+
} catch (exception) {
|
|
11329
|
+
this.AddVerificationError(cryptoResult, "Verification_PublicKeyDecodingFailed", exception);
|
|
11303
11330
|
return setResult("InvalidPublicKey" /* InvalidPublicKey */);
|
|
11304
11331
|
}
|
|
11305
11332
|
} else
|
|
11306
11333
|
return setResult("PublicKeyNotFound" /* PublicKeyNotFound */);
|
|
11307
11334
|
} else
|
|
11308
11335
|
return setResult("EnergyMeterNotFound" /* EnergyMeterNotFound */);
|
|
11309
|
-
} catch {
|
|
11336
|
+
} catch (exception) {
|
|
11337
|
+
this.AddVerificationError(cryptoResult, "Verification_UnexpectedError", exception);
|
|
11310
11338
|
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
11311
11339
|
}
|
|
11312
11340
|
}
|
|
11313
|
-
|
|
11341
|
+
this.AddVerificationError(cryptoResult, "Verification_SignatureMissing");
|
|
11342
|
+
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
11314
11343
|
}
|
|
11315
11344
|
async ViewMeasurement(measurementValue, _errorDiv, introDiv, infoDiv, PlainTextDiv, HashedPlainTextDiv, PublicKeyDiv, SignatureExpectedDiv, SignatureCheckDiv) {
|
|
11316
11345
|
const result = measurementValue.result;
|
|
@@ -12149,33 +12178,46 @@ var BSMCrypt01 = class extends ACrypt {
|
|
|
12149
12178
|
const publicKeyDER = ASN1_PublicKey.decode(Buffer.from(meter.publicKeys[0]?.value ?? "", "hex"), "der");
|
|
12150
12179
|
publicKey = buf2hex(publicKeyDER.publicKey.data).toLowerCase();
|
|
12151
12180
|
}
|
|
12181
|
+
let keyPair;
|
|
12152
12182
|
try {
|
|
12153
|
-
|
|
12154
|
-
|
|
12155
|
-
|
|
12156
|
-
)
|
|
12157
|
-
|
|
12158
|
-
|
|
12159
|
-
|
|
12160
|
-
|
|
12161
|
-
|
|
12162
|
-
|
|
12163
|
-
|
|
12164
|
-
|
|
12183
|
+
keyPair = this.curve.keyFromPublic(publicKey, "hex");
|
|
12184
|
+
} catch (exception) {
|
|
12185
|
+
this.AddVerificationError(cryptoResult, "Verification_PublicKeyDecodingFailed", exception);
|
|
12186
|
+
return setResult("InvalidPublicKey" /* InvalidPublicKey */);
|
|
12187
|
+
}
|
|
12188
|
+
const keyValidation = keyPair.validate();
|
|
12189
|
+
if (!keyValidation.result) {
|
|
12190
|
+
this.AddVerificationError(cryptoResult, "Verification_PublicKeyNotOnCurve", keyValidation.reason ?? void 0);
|
|
12191
|
+
return setResult("InvalidPublicKey" /* InvalidPublicKey */);
|
|
12192
|
+
}
|
|
12193
|
+
let signatureValid;
|
|
12194
|
+
try {
|
|
12195
|
+
signatureValid = keyPair.verify(cryptoResult.sha256value, cryptoResult.signature);
|
|
12196
|
+
} catch (exception) {
|
|
12197
|
+
this.AddVerificationError(cryptoResult, "Verification_SignatureMalformed", exception);
|
|
12165
12198
|
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
12166
12199
|
}
|
|
12167
|
-
|
|
12200
|
+
if (measurementValue.errors && measurementValue.errors.length > 0)
|
|
12201
|
+
return setResult("ValidationError" /* ValidationError */);
|
|
12202
|
+
if (signatureValid)
|
|
12203
|
+
return setResult("ValidSignature" /* ValidSignature */);
|
|
12204
|
+
this.AddVerificationError(cryptoResult, "Verification_SignatureMismatch");
|
|
12205
|
+
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
12206
|
+
} catch (exception) {
|
|
12207
|
+
this.AddVerificationError(cryptoResult, "Verification_PublicKeyDecodingFailed", exception);
|
|
12168
12208
|
return setResult("InvalidPublicKey" /* InvalidPublicKey */);
|
|
12169
12209
|
}
|
|
12170
12210
|
} else
|
|
12171
12211
|
return setResult("PublicKeyNotFound" /* PublicKeyNotFound */);
|
|
12172
12212
|
} else
|
|
12173
12213
|
return setResult("EnergyMeterNotFound" /* EnergyMeterNotFound */);
|
|
12174
|
-
} catch {
|
|
12214
|
+
} catch (exception) {
|
|
12215
|
+
this.AddVerificationError(cryptoResult, "Verification_UnexpectedError", exception);
|
|
12175
12216
|
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
12176
12217
|
}
|
|
12177
12218
|
}
|
|
12178
|
-
|
|
12219
|
+
this.AddVerificationError(cryptoResult, "Verification_SignatureMissing");
|
|
12220
|
+
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
12179
12221
|
}
|
|
12180
12222
|
async ViewMeasurement(measurementValue, _errorDiv, introDiv, infoDiv, PlainTextDiv, HashedPlainTextDiv, PublicKeyDiv, SignatureExpectedDiv, SignatureCheckDiv) {
|
|
12181
12223
|
if (measurementValue.measurement === void 0)
|
|
@@ -12354,35 +12396,7 @@ var BSMCrypt01 = class extends ACrypt {
|
|
|
12354
12396
|
if ((value & 1 << 29) != 0) events.push("OEM 15");
|
|
12355
12397
|
return events;
|
|
12356
12398
|
}
|
|
12357
|
-
|
|
12358
|
-
// {
|
|
12359
|
-
// const statusArray:string[] = [];
|
|
12360
|
-
// try
|
|
12361
|
-
// {
|
|
12362
|
-
// const status = parseInt(statusValue);
|
|
12363
|
-
// if ((status & 1) == 1)
|
|
12364
|
-
// statusArray.push("Fehler erkannt");
|
|
12365
|
-
// if ((status & 2) == 2)
|
|
12366
|
-
// statusArray.push("Synchrone Messwertübermittlung");
|
|
12367
|
-
// // Bit 3 is reserved!
|
|
12368
|
-
// if ((status & 8) == 8)
|
|
12369
|
-
// statusArray.push("System-Uhr ist synchron");
|
|
12370
|
-
// else
|
|
12371
|
-
// statusArray.push("System-Uhr ist nicht synchron");
|
|
12372
|
-
// if ((status & 16) == 16)
|
|
12373
|
-
// statusArray.push("Rücklaufsperre aktiv");
|
|
12374
|
-
// if ((status & 32) == 32)
|
|
12375
|
-
// statusArray.push("Energierichtung -A");
|
|
12376
|
-
// if ((status & 64) == 64)
|
|
12377
|
-
// statusArray.push("Magnetfeld erkannt");
|
|
12378
|
-
// }
|
|
12379
|
-
// catch
|
|
12380
|
-
// {
|
|
12381
|
-
// statusArray.push("Invalid status!");
|
|
12382
|
-
// }
|
|
12383
|
-
// return statusArray;
|
|
12384
|
-
// }
|
|
12385
|
-
// //#endregion
|
|
12399
|
+
//#endregion
|
|
12386
12400
|
};
|
|
12387
12401
|
|
|
12388
12402
|
// src/interfaces/IPublicKeyInfo.ts
|
|
@@ -13841,29 +13855,44 @@ var EMHCrypt01 = class extends ACrypt {
|
|
|
13841
13855
|
cryptoResult.publicKey = publicKey?.value.toLowerCase();
|
|
13842
13856
|
cryptoResult.publicKeyFormat = publicKey?.format;
|
|
13843
13857
|
cryptoResult.publicKeySignatures = publicKey?.signatures;
|
|
13858
|
+
let keyPair;
|
|
13844
13859
|
try {
|
|
13845
|
-
|
|
13846
|
-
|
|
13847
|
-
|
|
13848
|
-
)
|
|
13849
|
-
|
|
13850
|
-
|
|
13851
|
-
|
|
13852
|
-
|
|
13860
|
+
keyPair = this.curve.keyFromPublic(cryptoResult.publicKey ?? "", "hex");
|
|
13861
|
+
} catch (exception) {
|
|
13862
|
+
this.AddVerificationError(cryptoResult, "Verification_PublicKeyDecodingFailed", exception);
|
|
13863
|
+
return setResult("InvalidPublicKey" /* InvalidPublicKey */);
|
|
13864
|
+
}
|
|
13865
|
+
const keyValidation = keyPair.validate();
|
|
13866
|
+
if (!keyValidation.result) {
|
|
13867
|
+
this.AddVerificationError(cryptoResult, "Verification_PublicKeyNotOnCurve", keyValidation.reason ?? void 0);
|
|
13868
|
+
return setResult("InvalidPublicKey" /* InvalidPublicKey */);
|
|
13869
|
+
}
|
|
13870
|
+
let signatureValid;
|
|
13871
|
+
try {
|
|
13872
|
+
signatureValid = keyPair.verify(cryptoResult.sha256value, cryptoResult.signature);
|
|
13873
|
+
} catch (exception) {
|
|
13874
|
+
this.AddVerificationError(cryptoResult, "Verification_SignatureMalformed", exception);
|
|
13853
13875
|
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
13854
13876
|
}
|
|
13855
|
-
|
|
13877
|
+
if (signatureValid)
|
|
13878
|
+
return setResult("ValidSignature" /* ValidSignature */);
|
|
13879
|
+
this.AddVerificationError(cryptoResult, "Verification_SignatureMismatch");
|
|
13880
|
+
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
13881
|
+
} catch (exception) {
|
|
13882
|
+
this.AddVerificationError(cryptoResult, "Verification_PublicKeyDecodingFailed", exception);
|
|
13856
13883
|
return setResult("InvalidPublicKey" /* InvalidPublicKey */);
|
|
13857
13884
|
}
|
|
13858
13885
|
} else
|
|
13859
13886
|
return setResult("PublicKeyNotFound" /* PublicKeyNotFound */);
|
|
13860
13887
|
} else
|
|
13861
13888
|
return setResult("EnergyMeterNotFound" /* EnergyMeterNotFound */);
|
|
13862
|
-
} catch {
|
|
13889
|
+
} catch (exception) {
|
|
13890
|
+
this.AddVerificationError(cryptoResult, "Verification_UnexpectedError", exception);
|
|
13863
13891
|
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
13864
13892
|
}
|
|
13865
13893
|
}
|
|
13866
|
-
|
|
13894
|
+
this.AddVerificationError(cryptoResult, "Verification_SignatureMissing");
|
|
13895
|
+
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
13867
13896
|
}
|
|
13868
13897
|
async ViewMeasurement(measurementValue, _errorDiv, introDiv, infoDiv, PlainTextDiv, HashedPlainTextDiv, PublicKeyDiv, SignatureExpectedDiv, SignatureCheckDiv) {
|
|
13869
13898
|
if (measurementValue.measurement?.chargingSession?.authorizationStart?.timestamp === void 0) {
|
|
@@ -13971,7 +14000,7 @@ var EMHCrypt01 = class extends ACrypt {
|
|
|
13971
14000
|
DecodeStatus(statusValue) {
|
|
13972
14001
|
const statusArray = [];
|
|
13973
14002
|
try {
|
|
13974
|
-
const status = parseInt(statusValue);
|
|
14003
|
+
const status = parseInt(statusValue, 16);
|
|
13975
14004
|
if ((status & 1) == 1)
|
|
13976
14005
|
statusArray.push("Fehler erkannt");
|
|
13977
14006
|
if ((status & 2) == 2)
|
|
@@ -14073,29 +14102,44 @@ var GDFCrypt01 = class extends ACrypt {
|
|
|
14073
14102
|
cryptoResult.publicKey = publicKey?.value.toLowerCase();
|
|
14074
14103
|
cryptoResult.publicKeyFormat = publicKey?.format;
|
|
14075
14104
|
cryptoResult.publicKeySignatures = publicKey?.signatures;
|
|
14105
|
+
let keyPair;
|
|
14076
14106
|
try {
|
|
14077
|
-
|
|
14078
|
-
|
|
14079
|
-
|
|
14080
|
-
)
|
|
14081
|
-
|
|
14082
|
-
|
|
14083
|
-
|
|
14084
|
-
|
|
14107
|
+
keyPair = this.curve.keyFromPublic(cryptoResult.publicKey ?? "", "hex");
|
|
14108
|
+
} catch (exception) {
|
|
14109
|
+
this.AddVerificationError(cryptoResult, "Verification_PublicKeyDecodingFailed", exception);
|
|
14110
|
+
return setResult("InvalidPublicKey" /* InvalidPublicKey */);
|
|
14111
|
+
}
|
|
14112
|
+
const keyValidation = keyPair.validate();
|
|
14113
|
+
if (!keyValidation.result) {
|
|
14114
|
+
this.AddVerificationError(cryptoResult, "Verification_PublicKeyNotOnCurve", keyValidation.reason ?? void 0);
|
|
14115
|
+
return setResult("InvalidPublicKey" /* InvalidPublicKey */);
|
|
14116
|
+
}
|
|
14117
|
+
let signatureValid;
|
|
14118
|
+
try {
|
|
14119
|
+
signatureValid = keyPair.verify(cryptoResult.sha256value, cryptoResult.signature);
|
|
14120
|
+
} catch (exception) {
|
|
14121
|
+
this.AddVerificationError(cryptoResult, "Verification_SignatureMalformed", exception);
|
|
14085
14122
|
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
14086
14123
|
}
|
|
14087
|
-
|
|
14124
|
+
if (signatureValid)
|
|
14125
|
+
return setResult("ValidSignature" /* ValidSignature */);
|
|
14126
|
+
this.AddVerificationError(cryptoResult, "Verification_SignatureMismatch");
|
|
14127
|
+
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
14128
|
+
} catch (exception) {
|
|
14129
|
+
this.AddVerificationError(cryptoResult, "Verification_PublicKeyDecodingFailed", exception);
|
|
14088
14130
|
return setResult("InvalidPublicKey" /* InvalidPublicKey */);
|
|
14089
14131
|
}
|
|
14090
14132
|
} else
|
|
14091
14133
|
return setResult("PublicKeyNotFound" /* PublicKeyNotFound */);
|
|
14092
14134
|
} else
|
|
14093
14135
|
return setResult("EnergyMeterNotFound" /* EnergyMeterNotFound */);
|
|
14094
|
-
} catch {
|
|
14136
|
+
} catch (exception) {
|
|
14137
|
+
this.AddVerificationError(cryptoResult, "Verification_UnexpectedError", exception);
|
|
14095
14138
|
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
14096
14139
|
}
|
|
14097
14140
|
}
|
|
14098
|
-
|
|
14141
|
+
this.AddVerificationError(cryptoResult, "Verification_SignatureMissing");
|
|
14142
|
+
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
14099
14143
|
}
|
|
14100
14144
|
async ViewMeasurement(measurementValue, _errorDiv, introDiv, infoDiv, PlainTextDiv, HashedPlainTextDiv, PublicKeyDiv, SignatureExpectedDiv, SignatureCheckDiv) {
|
|
14101
14145
|
if (measurementValue.measurement?.chargingSession?.authorizationStart?.timestamp === void 0) {
|
|
@@ -14434,19 +14478,38 @@ var MennekesCrypt01 = class extends ACrypt {
|
|
|
14434
14478
|
);
|
|
14435
14479
|
cryptoResult.hashValue = (await sha256(new DataView(signedDataBuffer))).substring(0, 48);
|
|
14436
14480
|
const publicKey = cleanHex(meter.publicKeys.at(0)?.value ?? measurement.publicKey);
|
|
14437
|
-
if (publicKey.length !== 96)
|
|
14481
|
+
if (publicKey.length !== 96) {
|
|
14482
|
+
this.AddVerificationError(cryptoResult, "Verification_PublicKeyDecodingFailed");
|
|
14438
14483
|
return setResult("InvalidPublicKey" /* InvalidPublicKey */);
|
|
14439
|
-
|
|
14440
|
-
|
|
14441
|
-
|
|
14484
|
+
}
|
|
14485
|
+
let keyPair;
|
|
14486
|
+
try {
|
|
14487
|
+
keyPair = this.curve192r1.keyFromPublic("04" + publicKey, "hex");
|
|
14488
|
+
} catch (exception) {
|
|
14489
|
+
this.AddVerificationError(cryptoResult, "Verification_PublicKeyDecodingFailed", exception);
|
|
14490
|
+
return setResult("InvalidPublicKey" /* InvalidPublicKey */);
|
|
14491
|
+
}
|
|
14492
|
+
const keyValidation = keyPair.validate();
|
|
14493
|
+
if (!keyValidation.result) {
|
|
14494
|
+
this.AddVerificationError(cryptoResult, "Verification_PublicKeyNotOnCurve", keyValidation.reason ?? void 0);
|
|
14495
|
+
return setResult("InvalidPublicKey" /* InvalidPublicKey */);
|
|
14496
|
+
}
|
|
14497
|
+
let signatureValid;
|
|
14498
|
+
try {
|
|
14499
|
+
signatureValid = keyPair.verify(cryptoResult.hashValue.toUpperCase(), {
|
|
14442
14500
|
r: signatureExpected.r,
|
|
14443
14501
|
s: signatureExpected.s
|
|
14444
|
-
}
|
|
14445
|
-
)
|
|
14446
|
-
|
|
14447
|
-
|
|
14448
|
-
|
|
14449
|
-
|
|
14502
|
+
});
|
|
14503
|
+
} catch (exception) {
|
|
14504
|
+
this.AddVerificationError(cryptoResult, "Verification_SignatureMalformed", exception);
|
|
14505
|
+
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
14506
|
+
}
|
|
14507
|
+
if (signatureValid)
|
|
14508
|
+
return setResult("ValidSignature" /* ValidSignature */);
|
|
14509
|
+
this.AddVerificationError(cryptoResult, "Verification_SignatureMismatch");
|
|
14510
|
+
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
14511
|
+
} catch (exception) {
|
|
14512
|
+
this.AddVerificationError(cryptoResult, "Verification_UnexpectedError", exception);
|
|
14450
14513
|
return setResult("InvalidSignature" /* InvalidSignature */);
|
|
14451
14514
|
}
|
|
14452
14515
|
}
|
|
@@ -15424,7 +15487,9 @@ var OCMF = class {
|
|
|
15424
15487
|
// "value": ocmfJSONDocument.signature["SD"]
|
|
15425
15488
|
// }],
|
|
15426
15489
|
"result": {
|
|
15427
|
-
"status": ocmfJSONDocument.validationStatus ?? "Unvalidated" /* Unvalidated
|
|
15490
|
+
"status": ocmfJSONDocument.validationStatus ?? "Unvalidated" /* Unvalidated */,
|
|
15491
|
+
// Surface the per-document verification diagnostics on the measurement value.
|
|
15492
|
+
...ocmfJSONDocument.validationErrors && ocmfJSONDocument.validationErrors.length > 0 ? { errors: ocmfJSONDocument.validationErrors } : {}
|
|
15428
15493
|
},
|
|
15429
15494
|
"ocmfDocument": ocmfJSONDocument
|
|
15430
15495
|
});
|
|
@@ -15569,6 +15634,20 @@ var OCMF = class {
|
|
|
15569
15634
|
// return mergedCTR;
|
|
15570
15635
|
// }
|
|
15571
15636
|
// //#endregion
|
|
15637
|
+
// Records why a verification step failed as structured data: a stable reason
|
|
15638
|
+
// key (localized via i18n.json and machine-switchable by the GUI) plus an
|
|
15639
|
+
// optional, language-neutral technical detail. Presentation is left to the GUI.
|
|
15640
|
+
AddValidationError(OCMFJSONDocument, reasonKey, detail) {
|
|
15641
|
+
const details = detail instanceof Error ? detail.message : typeof detail === "string" ? detail : void 0;
|
|
15642
|
+
(OCMFJSONDocument.validationErrors ??= []).push(
|
|
15643
|
+
CreateError(
|
|
15644
|
+
this.chargy.GetMultilanguageText(reasonKey),
|
|
15645
|
+
"high" /* high */,
|
|
15646
|
+
reasonKey,
|
|
15647
|
+
details
|
|
15648
|
+
)
|
|
15649
|
+
);
|
|
15650
|
+
}
|
|
15572
15651
|
//#region (private) validateOCMFSignature(OCMFJSONDocument, PublicKey, PublicKeyEncoding?)
|
|
15573
15652
|
async validateOCMFSignature(OCMFJSONDocument, PublicKey, PublicKeyEncoding) {
|
|
15574
15653
|
try {
|
|
@@ -15608,7 +15687,8 @@ var OCMF = class {
|
|
|
15608
15687
|
curve = new this.chargy.elliptic.ec("p256");
|
|
15609
15688
|
break;
|
|
15610
15689
|
}
|
|
15611
|
-
} catch {
|
|
15690
|
+
} catch (exception) {
|
|
15691
|
+
this.AddValidationError(OCMFJSONDocument, "Verification_UnknownSignatureFormat", exception);
|
|
15612
15692
|
OCMFJSONDocument.validationStatus = "UnknownSignatureFormat" /* UnknownSignatureFormat */;
|
|
15613
15693
|
return OCMFJSONDocument.validationStatus;
|
|
15614
15694
|
}
|
|
@@ -15685,20 +15765,26 @@ var OCMF = class {
|
|
|
15685
15765
|
y: OCMFJSONDocument.publicKey.y
|
|
15686
15766
|
}, "hex");
|
|
15687
15767
|
}
|
|
15688
|
-
} catch {
|
|
15768
|
+
} catch (exception) {
|
|
15769
|
+
this.AddValidationError(OCMFJSONDocument, "Verification_PublicKeyDecodingFailed", exception);
|
|
15689
15770
|
OCMFJSONDocument.validationStatus = "InvalidPublicKey" /* InvalidPublicKey */;
|
|
15690
15771
|
return OCMFJSONDocument.validationStatus;
|
|
15691
15772
|
}
|
|
15692
15773
|
try {
|
|
15693
15774
|
if (publicKey === null)
|
|
15694
15775
|
throw new Error("Missing public key!");
|
|
15695
|
-
|
|
15776
|
+
const signatureValid = publicKey.verify(OCMFJSONDocument.hashValue, OCMFJSONDocument.signatureRS);
|
|
15777
|
+
if (!signatureValid)
|
|
15778
|
+
this.AddValidationError(OCMFJSONDocument, "Verification_SignatureMismatch");
|
|
15779
|
+
OCMFJSONDocument.validationStatus = signatureValid ? "ValidSignature" /* ValidSignature */ : "InvalidSignature" /* InvalidSignature */;
|
|
15696
15780
|
return await Promise.resolve(OCMFJSONDocument.validationStatus);
|
|
15697
|
-
} catch {
|
|
15781
|
+
} catch (exception) {
|
|
15782
|
+
this.AddValidationError(OCMFJSONDocument, "Verification_SignatureMalformed", exception);
|
|
15698
15783
|
OCMFJSONDocument.validationStatus = "InvalidSignature" /* InvalidSignature */;
|
|
15699
15784
|
return OCMFJSONDocument.validationStatus;
|
|
15700
15785
|
}
|
|
15701
|
-
} catch {
|
|
15786
|
+
} catch (exception) {
|
|
15787
|
+
this.AddValidationError(OCMFJSONDocument, "Verification_UnexpectedError", exception);
|
|
15702
15788
|
OCMFJSONDocument.validationStatus = "InvalidSignature" /* InvalidSignature */;
|
|
15703
15789
|
return OCMFJSONDocument.validationStatus;
|
|
15704
15790
|
}
|
|
@@ -19647,6 +19733,26 @@ var Chargy = class {
|
|
|
19647
19733
|
return textContent.replace(/\s+/g, "");
|
|
19648
19734
|
return void 0;
|
|
19649
19735
|
}
|
|
19736
|
+
TryToCreatePublicKeyLookup(processedFiles) {
|
|
19737
|
+
if (processedFiles.length === 0)
|
|
19738
|
+
return void 0;
|
|
19739
|
+
const publicKeys = new Array();
|
|
19740
|
+
for (const processedFile of processedFiles) {
|
|
19741
|
+
if (IsAChargeTransparencyRecord(processedFile.result) || IsAChargeTransparencyLiveLink(processedFile.result)) {
|
|
19742
|
+
return void 0;
|
|
19743
|
+
}
|
|
19744
|
+
if (IsAPublicKey(processedFile.result))
|
|
19745
|
+
publicKeys.push(processedFile.result);
|
|
19746
|
+
else if (IsAPublicKeyLookup(processedFile.result))
|
|
19747
|
+
publicKeys.push(...processedFile.result.publicKeys);
|
|
19748
|
+
else
|
|
19749
|
+
return void 0;
|
|
19750
|
+
}
|
|
19751
|
+
if (processedFiles.length === 1 && IsAPublicKeyLookup(processedFiles[0]?.result)) {
|
|
19752
|
+
return processedFiles[0].result;
|
|
19753
|
+
}
|
|
19754
|
+
return { publicKeys };
|
|
19755
|
+
}
|
|
19650
19756
|
//#endregion
|
|
19651
19757
|
//#region QR code image files...
|
|
19652
19758
|
normalizeMIMEType(mimeType) {
|
|
@@ -20405,18 +20511,15 @@ var Chargy = class {
|
|
|
20405
20511
|
}
|
|
20406
20512
|
processedFiles.push(processedFile);
|
|
20407
20513
|
}
|
|
20514
|
+
const publicKeyLookup = this.TryToCreatePublicKeyLookup(processedFiles);
|
|
20515
|
+
if (publicKeyLookup != null)
|
|
20516
|
+
return publicKeyLookup;
|
|
20408
20517
|
if (processedFiles.length == 1) {
|
|
20409
20518
|
const processedFile = getFirstArrayElement(processedFiles, "Missing processed file");
|
|
20410
20519
|
if (IsAChargeTransparencyRecord(processedFile.result))
|
|
20411
20520
|
return this.processChargeTransparencyRecord(processedFile.result);
|
|
20412
20521
|
if (IsAChargeTransparencyLiveLink(processedFile.result))
|
|
20413
20522
|
return processedFile.result;
|
|
20414
|
-
if (IsAPublicKeyLookup(processedFile.result))
|
|
20415
|
-
return {
|
|
20416
|
-
status: "InvalidSessionFormat" /* InvalidSessionFormat */,
|
|
20417
|
-
message: this.GetMultilanguageText("UnknownOrInvalidChargeTransparencyRecord"),
|
|
20418
|
-
certainty: 0
|
|
20419
|
-
};
|
|
20420
20523
|
return processedFile.result;
|
|
20421
20524
|
} else if (processedFiles.length > 1) {
|
|
20422
20525
|
const mergedCTR = {
|