@sphereon/ssi-sdk-ext.kms-musap-rn 0.26.1-next.9 → 0.27.1-feature.MWALL.718.6
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.
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { IKey, ManagedKeyInfo, MinimalImportableKey, TKeyType } from '@veramo/core';
|
|
2
|
-
import { SscdType } from '@sphereon/musap-react-native';
|
|
2
|
+
import { ExternalSscdSettings, SscdType } from '@sphereon/musap-react-native';
|
|
3
3
|
import { AbstractKeyManagementSystem } from '@veramo/key-manager';
|
|
4
4
|
import { KeyMetadata } from './index';
|
|
5
5
|
export declare const logger: import("@sphereon/ssi-types").ISimpleLogger<unknown>;
|
|
6
6
|
export declare class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
7
|
-
private
|
|
8
|
-
private sscdType;
|
|
9
|
-
|
|
7
|
+
private musapClient;
|
|
8
|
+
private readonly sscdType;
|
|
9
|
+
private readonly sscdId;
|
|
10
|
+
private readonly defaultKeyAttributes;
|
|
11
|
+
private readonly defaultSignAttributes;
|
|
12
|
+
constructor(sscdType?: SscdType, sscdId?: string, opts?: {
|
|
13
|
+
externalSscdSettings?: ExternalSscdSettings;
|
|
14
|
+
defaultKeyAttributes?: Record<string, string>;
|
|
15
|
+
defaultSignAttributes?: Record<string, string>;
|
|
16
|
+
});
|
|
10
17
|
listKeys(): Promise<ManagedKeyInfo[]>;
|
|
11
18
|
createKey(args: {
|
|
12
19
|
type: TKeyType;
|
|
@@ -32,5 +39,7 @@ export declare class MusapKeyManagementSystem extends AbstractKeyManagementSyste
|
|
|
32
39
|
myKeyRef: Pick<IKey, 'kid'>;
|
|
33
40
|
theirKey: Pick<IKey, 'publicKeyHex' | 'type'>;
|
|
34
41
|
}): Promise<string>;
|
|
42
|
+
private recordToKeyAttributes;
|
|
43
|
+
private recordToSignatureAttributes;
|
|
35
44
|
}
|
|
36
45
|
//# sourceMappingURL=MusapKeyManagerSystem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MusapKeyManagerSystem.d.ts","sourceRoot":"","sources":["../src/MusapKeyManagerSystem.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"MusapKeyManagerSystem.d.ts","sourceRoot":"","sources":["../src/MusapKeyManagerSystem.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACnF,OAAO,EACL,oBAAoB,EAepB,QAAQ,EACT,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AAGjE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAUrC,eAAO,MAAM,MAAM,sDAA+C,CAAA;AAElE,qBAAa,wBAAyB,SAAQ,2BAA2B;IACvE,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAoC;IACzE,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAoC;gBAE9D,QAAQ,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QACvD,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;QAC5C,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9C,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAC/C;IAmBK,QAAQ,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAKrC,SAAS,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,QAAQ,CAAC;QAAC,IAAI,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAuCtF,OAAO,CAAC,yBAAyB,CAahC;IAED,OAAO,CAAC,yBAAyB,CAchC;IAEK,SAAS,CAAC,EAAE,GAAG,EAAE,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAc3D,OAAO,CAAC,kBAAkB;IAapB,IAAI,CAAC,IAAI,EAAE;QACf,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,UAAU,CAAC;QACjB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;KACjB,GAAG,OAAO,CAAC,MAAM,CAAC;IAuBb,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,oBAAoB,EAAE,KAAK,CAAC,GAAG;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAI9G,OAAO,CAAC,cAAc;IAqBtB,YAAY,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAInH,OAAO,CAAC,qBAAqB;IAU7B,OAAO,CAAC,2BAA2B;CASpC"}
|
|
@@ -29,7 +29,7 @@ const ssi_types_1 = require("@sphereon/ssi-types");
|
|
|
29
29
|
const ssi_sdk_ext_key_utils_1 = require("@sphereon/ssi-sdk-ext.key-utils");
|
|
30
30
|
exports.logger = ssi_types_1.Loggers.DEFAULT.get('sphereon:musap-rn-kms');
|
|
31
31
|
class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem {
|
|
32
|
-
constructor(sscdType) {
|
|
32
|
+
constructor(sscdType, sscdId, opts) {
|
|
33
33
|
super();
|
|
34
34
|
this.mapKeyTypeToAlgorithmType = (type) => {
|
|
35
35
|
switch (type) {
|
|
@@ -39,6 +39,8 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
39
39
|
return 'ECCP256R1';
|
|
40
40
|
case 'RSA':
|
|
41
41
|
return 'RSA2K';
|
|
42
|
+
case 'Ed25519':
|
|
43
|
+
return 'ECC_ED25519';
|
|
42
44
|
default:
|
|
43
45
|
throw new Error(`Key type ${type} is not supported by MUSAP`);
|
|
44
46
|
}
|
|
@@ -49,6 +51,9 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
49
51
|
return 'Secp256k1';
|
|
50
52
|
case 'eccp256r1':
|
|
51
53
|
return 'Secp256r1';
|
|
54
|
+
case 'ecc_ed25519':
|
|
55
|
+
return 'Ed25519';
|
|
56
|
+
case 'rsa2k':
|
|
52
57
|
case 'rsa4k':
|
|
53
58
|
return 'RSA';
|
|
54
59
|
default:
|
|
@@ -56,9 +61,15 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
56
61
|
}
|
|
57
62
|
};
|
|
58
63
|
try {
|
|
59
|
-
this.
|
|
64
|
+
this.musapClient = musap_react_native_1.MusapClient;
|
|
60
65
|
this.sscdType = sscdType ? sscdType : 'TEE';
|
|
61
|
-
this.
|
|
66
|
+
this.sscdId = sscdId !== null && sscdId !== void 0 ? sscdId : this.sscdType;
|
|
67
|
+
this.defaultKeyAttributes = opts === null || opts === void 0 ? void 0 : opts.defaultKeyAttributes;
|
|
68
|
+
this.defaultSignAttributes = opts === null || opts === void 0 ? void 0 : opts.defaultSignAttributes;
|
|
69
|
+
const enabledSscds = this.musapClient.listEnabledSscds();
|
|
70
|
+
if (!enabledSscds.some(value => value.sscdId == sscdId)) {
|
|
71
|
+
this.musapClient.enableSscd(this.sscdType, this.sscdId, opts === null || opts === void 0 ? void 0 : opts.externalSscdSettings);
|
|
72
|
+
}
|
|
62
73
|
}
|
|
63
74
|
catch (e) {
|
|
64
75
|
console.error('enableSscd', e);
|
|
@@ -67,7 +78,7 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
67
78
|
}
|
|
68
79
|
listKeys() {
|
|
69
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
const keysJson = (
|
|
81
|
+
const keysJson = (this.musapClient.listKeys());
|
|
71
82
|
return keysJson.map((key) => this.asMusapKeyInfo(key));
|
|
72
83
|
});
|
|
73
84
|
}
|
|
@@ -77,18 +88,27 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
77
88
|
if (meta === undefined || !('keyAlias' in meta)) {
|
|
78
89
|
return Promise.reject(Error('a unique keyAlias field is required for MUSAP'));
|
|
79
90
|
}
|
|
91
|
+
if (this.sscdType == 'EXTERNAL') {
|
|
92
|
+
const existingKeys = (this.musapClient.listKeys());
|
|
93
|
+
const extKey = existingKeys.find(musapKey => musapKey.sscdType === 'External Signature'); // FIXME returning does not match SscdType enum
|
|
94
|
+
if (extKey) {
|
|
95
|
+
extKey.algorithm = 'eccp256r1'; // FIXME MUSAP announces key as rsa2k, but it's actually EC
|
|
96
|
+
return this.asMusapKeyInfo(extKey);
|
|
97
|
+
}
|
|
98
|
+
return Promise.reject(Error(`No external key was bound yet for sscd ${this.sscdId}`));
|
|
99
|
+
}
|
|
80
100
|
const keyGenReq = {
|
|
81
101
|
keyAlgorithm: this.mapKeyTypeToAlgorithmType(type),
|
|
82
102
|
keyUsage: 'keyUsage' in meta ? meta.keyUsage : 'sign',
|
|
83
103
|
keyAlias: meta.keyAlias,
|
|
84
|
-
attributes: 'attributes' in meta ? meta.attributes :
|
|
104
|
+
attributes: this.recordToKeyAttributes(Object.assign(Object.assign({}, this.defaultKeyAttributes), ('attributes' in meta ? meta.attributes : {}))),
|
|
85
105
|
role: 'role' in meta ? meta.role : 'administrator',
|
|
86
106
|
};
|
|
87
107
|
try {
|
|
88
|
-
const generatedKeyUri = yield this.
|
|
108
|
+
const generatedKeyUri = yield this.musapClient.generateKey(this.sscdType, keyGenReq);
|
|
89
109
|
if (generatedKeyUri) {
|
|
90
110
|
exports.logger.debug('Generated key:', generatedKeyUri);
|
|
91
|
-
const key =
|
|
111
|
+
const key = this.musapClient.getKeyByUri(generatedKeyUri);
|
|
92
112
|
return this.asMusapKeyInfo(key);
|
|
93
113
|
}
|
|
94
114
|
else {
|
|
@@ -104,7 +124,11 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
104
124
|
deleteKey(_a) {
|
|
105
125
|
return __awaiter(this, arguments, void 0, function* ({ kid }) {
|
|
106
126
|
try {
|
|
107
|
-
this.
|
|
127
|
+
const key = this.musapClient.getKeyById(kid);
|
|
128
|
+
if (key.sscdType === 'External Signature') {
|
|
129
|
+
return true; // FIXME we can't remove a eSim key for now because this would mean onboarding again
|
|
130
|
+
}
|
|
131
|
+
void this.musapClient.removeKey(kid);
|
|
108
132
|
return true;
|
|
109
133
|
}
|
|
110
134
|
catch (error) {
|
|
@@ -130,7 +154,10 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
130
154
|
throw new Error('key_not_found: No key ref provided');
|
|
131
155
|
}
|
|
132
156
|
const data = new text_encoding_1.TextDecoder().decode(args.data);
|
|
133
|
-
const key = this.
|
|
157
|
+
const key = this.musapClient.getKeyById(args.keyRef.kid);
|
|
158
|
+
if (key.sscdType === 'External Signature') {
|
|
159
|
+
key.algorithm = 'eccp256r1'; // FIXME MUSAP announces key as rsa2k, but it's actually EC
|
|
160
|
+
}
|
|
134
161
|
const signatureReq = {
|
|
135
162
|
keyUri: key.keyUri,
|
|
136
163
|
data,
|
|
@@ -138,9 +165,9 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
138
165
|
displayText: args.displayText,
|
|
139
166
|
transId: args.transId,
|
|
140
167
|
format: (_a = args.format) !== null && _a !== void 0 ? _a : 'RAW',
|
|
141
|
-
attributes: args.attributes,
|
|
168
|
+
attributes: this.recordToSignatureAttributes(Object.assign(Object.assign({}, this.defaultSignAttributes), args.attributes)),
|
|
142
169
|
};
|
|
143
|
-
return this.
|
|
170
|
+
return this.musapClient.sign(signatureReq);
|
|
144
171
|
});
|
|
145
172
|
}
|
|
146
173
|
importKey(args) {
|
|
@@ -169,6 +196,24 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
169
196
|
sharedSecret(args) {
|
|
170
197
|
throw new Error('Not supported.');
|
|
171
198
|
}
|
|
199
|
+
recordToKeyAttributes(record) {
|
|
200
|
+
if (!record) {
|
|
201
|
+
return [];
|
|
202
|
+
}
|
|
203
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
204
|
+
name: key,
|
|
205
|
+
value,
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
recordToSignatureAttributes(record) {
|
|
209
|
+
if (!record) {
|
|
210
|
+
return [];
|
|
211
|
+
}
|
|
212
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
213
|
+
name: key,
|
|
214
|
+
value,
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
172
217
|
}
|
|
173
218
|
exports.MusapKeyManagementSystem = MusapKeyManagementSystem;
|
|
174
219
|
//# sourceMappingURL=MusapKeyManagerSystem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MusapKeyManagerSystem.js","sourceRoot":"","sources":["../src/MusapKeyManagerSystem.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,6EAA8D;AAE9D,
|
|
1
|
+
{"version":3,"file":"MusapKeyManagerSystem.js","sourceRoot":"","sources":["../src/MusapKeyManagerSystem.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,6EAA8D;AAE9D,qEAiBqC;AACrC,q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AA;QACX,CAAC;QACD,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YACnD,IAAI,EAAE,GAAG;YACT,KAAK;SACN,CAAC,CAAC,CAAA;IACL,CAAC;CACF;AAhND,4DAgNC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk-ext.kms-musap-rn",
|
|
3
3
|
"description": "Sphereon SSI-SDK react-native plugin for management of keys with musap.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.27.1-feature.MWALL.718.6+91385c2",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"build:clean": "tsc --build --clean && tsc --build"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@sphereon/musap-react-native": "0.
|
|
14
|
-
"@sphereon/ssi-sdk-ext.key-utils": "0.
|
|
15
|
-
"@sphereon/ssi-sdk-ext.x509-utils": "0.
|
|
13
|
+
"@sphereon/musap-react-native": "0.2.1-next.184",
|
|
14
|
+
"@sphereon/ssi-sdk-ext.key-utils": "0.27.1-feature.MWALL.718.6+91385c2",
|
|
15
|
+
"@sphereon/ssi-sdk-ext.x509-utils": "0.27.1-feature.MWALL.718.6+91385c2",
|
|
16
16
|
"@sphereon/ssi-types": "0.30.2-feature.SDK.41.oidf.support.286",
|
|
17
17
|
"@veramo/core": "4.2.0",
|
|
18
18
|
"@veramo/key-manager": "4.2.0",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"react-native",
|
|
42
42
|
"Veramo"
|
|
43
43
|
],
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "91385c2f4118d2915f8f6e4839e4fe0e409583d5"
|
|
45
45
|
}
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { PEMToBinary } from '@sphereon/ssi-sdk-ext.x509-utils'
|
|
2
2
|
import { IKey, ManagedKeyInfo, MinimalImportableKey, TKeyType } from '@veramo/core'
|
|
3
3
|
import {
|
|
4
|
+
ExternalSscdSettings,
|
|
5
|
+
IMusapClient,
|
|
4
6
|
isSignatureAlgorithmType,
|
|
5
7
|
JWSAlgorithm,
|
|
6
8
|
KeyAlgorithm,
|
|
7
9
|
KeyAlgorithmType,
|
|
10
|
+
KeyAttribute,
|
|
8
11
|
KeyGenReq,
|
|
12
|
+
MusapClient,
|
|
9
13
|
MusapKey,
|
|
10
|
-
MusapModule,
|
|
11
|
-
MusapModuleType,
|
|
12
14
|
signatureAlgorithmFromKeyAlgorithm,
|
|
13
15
|
SignatureAlgorithmType,
|
|
16
|
+
SignatureAttribute,
|
|
14
17
|
SignatureFormat,
|
|
15
18
|
SignatureReq,
|
|
19
|
+
SscdType,
|
|
16
20
|
} from '@sphereon/musap-react-native'
|
|
17
|
-
import { KeyAttribute, SscdType } from '@sphereon/musap-react-native'
|
|
18
21
|
import { AbstractKeyManagementSystem } from '@veramo/key-manager'
|
|
19
22
|
import { TextDecoder } from 'text-encoding'
|
|
20
23
|
import { Loggers } from '@sphereon/ssi-types'
|
|
@@ -31,15 +34,29 @@ import {
|
|
|
31
34
|
export const logger = Loggers.DEFAULT.get('sphereon:musap-rn-kms')
|
|
32
35
|
|
|
33
36
|
export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
34
|
-
private
|
|
35
|
-
private sscdType: SscdType
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
private musapClient: IMusapClient
|
|
38
|
+
private readonly sscdType: SscdType
|
|
39
|
+
private readonly sscdId: string
|
|
40
|
+
private readonly defaultKeyAttributes: Record<string, string> | undefined
|
|
41
|
+
private readonly defaultSignAttributes: Record<string, string> | undefined
|
|
42
|
+
|
|
43
|
+
constructor(sscdType?: SscdType, sscdId?: string, opts?: {
|
|
44
|
+
externalSscdSettings?: ExternalSscdSettings,
|
|
45
|
+
defaultKeyAttributes?: Record<string, string>,
|
|
46
|
+
defaultSignAttributes?: Record<string, string>
|
|
47
|
+
}) {
|
|
38
48
|
super()
|
|
39
49
|
try {
|
|
40
|
-
this.
|
|
50
|
+
this.musapClient = MusapClient
|
|
41
51
|
this.sscdType = sscdType ? sscdType : 'TEE'
|
|
42
|
-
this.
|
|
52
|
+
this.sscdId = sscdId ?? this.sscdType
|
|
53
|
+
this.defaultKeyAttributes = opts?.defaultKeyAttributes
|
|
54
|
+
this.defaultSignAttributes = opts?.defaultSignAttributes
|
|
55
|
+
|
|
56
|
+
const enabledSscds = this.musapClient.listEnabledSscds()
|
|
57
|
+
if (!enabledSscds.some(value => value.sscdId == sscdId)) {
|
|
58
|
+
this.musapClient.enableSscd(this.sscdType, this.sscdId, opts?.externalSscdSettings)
|
|
59
|
+
}
|
|
43
60
|
} catch (e) {
|
|
44
61
|
console.error('enableSscd', e)
|
|
45
62
|
throw Error('enableSscd failed')
|
|
@@ -47,7 +64,7 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
47
64
|
}
|
|
48
65
|
|
|
49
66
|
async listKeys(): Promise<ManagedKeyInfo[]> {
|
|
50
|
-
const keysJson: MusapKey[] = (
|
|
67
|
+
const keysJson: MusapKey[] = (this.musapClient.listKeys()) as MusapKey[]
|
|
51
68
|
return keysJson.map((key) => this.asMusapKeyInfo(key))
|
|
52
69
|
}
|
|
53
70
|
|
|
@@ -57,19 +74,29 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
57
74
|
return Promise.reject(Error('a unique keyAlias field is required for MUSAP'))
|
|
58
75
|
}
|
|
59
76
|
|
|
77
|
+
if (this.sscdType == 'EXTERNAL') {
|
|
78
|
+
const existingKeys: MusapKey[] = (this.musapClient.listKeys()) as MusapKey[]
|
|
79
|
+
const extKey = existingKeys.find(musapKey => musapKey.sscdType as string === 'External Signature') // FIXME returning does not match SscdType enum
|
|
80
|
+
if (extKey) {
|
|
81
|
+
extKey.algorithm = 'eccp256r1' // FIXME MUSAP announces key as rsa2k, but it's actually EC
|
|
82
|
+
return this.asMusapKeyInfo(extKey)
|
|
83
|
+
}
|
|
84
|
+
return Promise.reject(Error(`No external key was bound yet for sscd ${this.sscdId}`))
|
|
85
|
+
}
|
|
86
|
+
|
|
60
87
|
const keyGenReq = {
|
|
61
88
|
keyAlgorithm: this.mapKeyTypeToAlgorithmType(type),
|
|
62
89
|
keyUsage: 'keyUsage' in meta ? (meta.keyUsage as string) : 'sign',
|
|
63
90
|
keyAlias: meta.keyAlias as string,
|
|
64
|
-
attributes: 'attributes' in meta ?
|
|
91
|
+
attributes: this.recordToKeyAttributes({ ...this.defaultKeyAttributes, ...('attributes' in meta ? meta.attributes : {}) }),
|
|
65
92
|
role: 'role' in meta ? (meta.role as string) : 'administrator',
|
|
66
93
|
} satisfies KeyGenReq
|
|
67
94
|
|
|
68
95
|
try {
|
|
69
|
-
const generatedKeyUri = await this.
|
|
96
|
+
const generatedKeyUri = await this.musapClient.generateKey(this.sscdType, keyGenReq)
|
|
70
97
|
if (generatedKeyUri) {
|
|
71
98
|
logger.debug('Generated key:', generatedKeyUri)
|
|
72
|
-
const key =
|
|
99
|
+
const key = this.musapClient.getKeyByUri(generatedKeyUri)
|
|
73
100
|
return this.asMusapKeyInfo(key)
|
|
74
101
|
} else {
|
|
75
102
|
return Promise.reject(new Error('Failed to generate key. No key URI'))
|
|
@@ -88,6 +115,8 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
88
115
|
return 'ECCP256R1'
|
|
89
116
|
case 'RSA':
|
|
90
117
|
return 'RSA2K'
|
|
118
|
+
case 'Ed25519':
|
|
119
|
+
return 'ECC_ED25519'
|
|
91
120
|
default:
|
|
92
121
|
throw new Error(`Key type ${type} is not supported by MUSAP`)
|
|
93
122
|
}
|
|
@@ -99,6 +128,9 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
99
128
|
return 'Secp256k1'
|
|
100
129
|
case 'eccp256r1':
|
|
101
130
|
return 'Secp256r1'
|
|
131
|
+
case 'ecc_ed25519':
|
|
132
|
+
return 'Ed25519'
|
|
133
|
+
case 'rsa2k':
|
|
102
134
|
case 'rsa4k':
|
|
103
135
|
return 'RSA'
|
|
104
136
|
default:
|
|
@@ -107,8 +139,12 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
107
139
|
}
|
|
108
140
|
|
|
109
141
|
async deleteKey({ kid }: { kid: string }): Promise<boolean> {
|
|
110
|
-
|
|
111
|
-
|
|
142
|
+
try {
|
|
143
|
+
const key: MusapKey = this.musapClient.getKeyById(kid) as MusapKey
|
|
144
|
+
if (key.sscdType as string === 'External Signature') {
|
|
145
|
+
return true // FIXME we can't remove a eSim key for now because this would mean onboarding again
|
|
146
|
+
}
|
|
147
|
+
void this.musapClient.removeKey(kid)
|
|
112
148
|
return true
|
|
113
149
|
} catch (error) {
|
|
114
150
|
console.warn('Failed to delete key:', error)
|
|
@@ -129,14 +165,22 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
129
165
|
return signatureAlgorithmFromKeyAlgorithm(providedAlgorithm as JWSAlgorithm)
|
|
130
166
|
}
|
|
131
167
|
|
|
132
|
-
async sign(args: {
|
|
168
|
+
async sign(args: {
|
|
169
|
+
keyRef: Pick<IKey, 'kid'>;
|
|
170
|
+
algorithm?: string;
|
|
171
|
+
data: Uint8Array;
|
|
172
|
+
[x: string]: any
|
|
173
|
+
}): Promise<string> {
|
|
133
174
|
if (!args.keyRef) {
|
|
134
175
|
throw new Error('key_not_found: No key ref provided')
|
|
135
176
|
}
|
|
136
177
|
|
|
137
178
|
const data = new TextDecoder().decode(args.data as Uint8Array)
|
|
138
179
|
|
|
139
|
-
const key: MusapKey = this.
|
|
180
|
+
const key: MusapKey = this.musapClient.getKeyById(args.keyRef.kid) as MusapKey
|
|
181
|
+
if (key.sscdType as string === 'External Signature') {
|
|
182
|
+
key.algorithm = 'eccp256r1' // FIXME MUSAP announces key as rsa2k, but it's actually EC
|
|
183
|
+
}
|
|
140
184
|
const signatureReq: SignatureReq = {
|
|
141
185
|
keyUri: key.keyUri,
|
|
142
186
|
data,
|
|
@@ -144,9 +188,9 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
144
188
|
displayText: args.displayText,
|
|
145
189
|
transId: args.transId,
|
|
146
190
|
format: (args.format as SignatureFormat) ?? 'RAW',
|
|
147
|
-
attributes: args.attributes,
|
|
191
|
+
attributes: this.recordToSignatureAttributes({ ...this.defaultSignAttributes, ...args.attributes }),
|
|
148
192
|
}
|
|
149
|
-
return this.
|
|
193
|
+
return this.musapClient.sign(signatureReq)
|
|
150
194
|
}
|
|
151
195
|
|
|
152
196
|
async importKey(args: Omit<MinimalImportableKey, 'kms'> & { privateKeyPEM?: string }): Promise<ManagedKeyInfo> {
|
|
@@ -156,6 +200,7 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
156
200
|
private asMusapKeyInfo(args: MusapKey): ManagedKeyInfo {
|
|
157
201
|
const { keyId, publicKey, ...metadata }: KeyMetadata = { ...args }
|
|
158
202
|
const keyType = this.mapAlgorithmTypeToKeyType(args.algorithm)
|
|
203
|
+
|
|
159
204
|
const pemBinary = PEMToBinary(args.publicKey.pem) // The der is flawed, it's not binary but a string [123, 4567]
|
|
160
205
|
const publicKeyBinary = isAsn1Der(pemBinary) ? asn1DerToRawPublicKey(pemBinary, keyType) : pemBinary
|
|
161
206
|
const publicKeyHex = isRawCompressedPublicKey(publicKeyBinary) // TODO In the future I think it's better to have an option in KeyGenReq to specify which public key format we want back. Now it's different in iOS vs Android and we need to handle that inconsistency afterwards
|
|
@@ -176,4 +221,24 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
176
221
|
sharedSecret(args: { myKeyRef: Pick<IKey, 'kid'>; theirKey: Pick<IKey, 'publicKeyHex' | 'type'> }): Promise<string> {
|
|
177
222
|
throw new Error('Not supported.')
|
|
178
223
|
}
|
|
224
|
+
|
|
225
|
+
private recordToKeyAttributes(record?: Record<string, string>): KeyAttribute[] {
|
|
226
|
+
if (!record) {
|
|
227
|
+
return []
|
|
228
|
+
}
|
|
229
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
230
|
+
name: key,
|
|
231
|
+
value,
|
|
232
|
+
}))
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
private recordToSignatureAttributes(record?: Record<string, string>): SignatureAttribute[] {
|
|
236
|
+
if (!record) {
|
|
237
|
+
return []
|
|
238
|
+
}
|
|
239
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
240
|
+
name: key,
|
|
241
|
+
value,
|
|
242
|
+
}))
|
|
243
|
+
}
|
|
179
244
|
}
|