@sphereon/ssi-sdk-ext.kms-musap-rn 0.26.1-next.5 → 0.26.1-next.86
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,CAWhC;IAED,OAAO,CAAC,yBAAyB,CAchC;IAEK,SAAS,CAAC,EAAE,GAAG,EAAE,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAU3D,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) {
|
|
@@ -49,6 +49,9 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
49
49
|
return 'Secp256k1';
|
|
50
50
|
case 'eccp256r1':
|
|
51
51
|
return 'Secp256r1';
|
|
52
|
+
case 'ecc_ed25519':
|
|
53
|
+
return 'Ed25519';
|
|
54
|
+
case 'rsa2k':
|
|
52
55
|
case 'rsa4k':
|
|
53
56
|
return 'RSA';
|
|
54
57
|
default:
|
|
@@ -56,9 +59,15 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
56
59
|
}
|
|
57
60
|
};
|
|
58
61
|
try {
|
|
59
|
-
this.
|
|
62
|
+
this.musapClient = musap_react_native_1.MusapClient;
|
|
60
63
|
this.sscdType = sscdType ? sscdType : 'TEE';
|
|
61
|
-
this.
|
|
64
|
+
this.sscdId = sscdId !== null && sscdId !== void 0 ? sscdId : this.sscdType;
|
|
65
|
+
this.defaultKeyAttributes = opts === null || opts === void 0 ? void 0 : opts.defaultKeyAttributes;
|
|
66
|
+
this.defaultSignAttributes = opts === null || opts === void 0 ? void 0 : opts.defaultSignAttributes;
|
|
67
|
+
const enabledSscds = this.musapClient.listEnabledSscds();
|
|
68
|
+
if (!enabledSscds.some(value => value.sscdId == sscdId)) {
|
|
69
|
+
this.musapClient.enableSscd(this.sscdType, this.sscdId, opts === null || opts === void 0 ? void 0 : opts.externalSscdSettings);
|
|
70
|
+
}
|
|
62
71
|
}
|
|
63
72
|
catch (e) {
|
|
64
73
|
console.error('enableSscd', e);
|
|
@@ -67,7 +76,7 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
67
76
|
}
|
|
68
77
|
listKeys() {
|
|
69
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
const keysJson = (
|
|
79
|
+
const keysJson = (this.musapClient.listKeys());
|
|
71
80
|
return keysJson.map((key) => this.asMusapKeyInfo(key));
|
|
72
81
|
});
|
|
73
82
|
}
|
|
@@ -77,18 +86,27 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
77
86
|
if (meta === undefined || !('keyAlias' in meta)) {
|
|
78
87
|
return Promise.reject(Error('a unique keyAlias field is required for MUSAP'));
|
|
79
88
|
}
|
|
89
|
+
if (this.sscdType == 'EXTERNAL') {
|
|
90
|
+
const existingKeys = (this.musapClient.listKeys());
|
|
91
|
+
const extKey = existingKeys.find(musapKey => musapKey.sscdType === 'External Signature'); // FIXME returning does not match SscdType enum
|
|
92
|
+
if (extKey) {
|
|
93
|
+
extKey.algorithm = 'eccp256r1'; // FIXME MUSAP announces key as rsa2k, but it's actually EC
|
|
94
|
+
return this.asMusapKeyInfo(extKey);
|
|
95
|
+
}
|
|
96
|
+
return Promise.reject(Error(`No external key was bound yet for sscd ${this.sscdId}`));
|
|
97
|
+
}
|
|
80
98
|
const keyGenReq = {
|
|
81
99
|
keyAlgorithm: this.mapKeyTypeToAlgorithmType(type),
|
|
82
100
|
keyUsage: 'keyUsage' in meta ? meta.keyUsage : 'sign',
|
|
83
101
|
keyAlias: meta.keyAlias,
|
|
84
|
-
attributes: 'attributes' in meta ? meta.attributes :
|
|
102
|
+
attributes: this.recordToKeyAttributes(Object.assign(Object.assign({}, this.defaultKeyAttributes), ('attributes' in meta ? meta.attributes : {}))),
|
|
85
103
|
role: 'role' in meta ? meta.role : 'administrator',
|
|
86
104
|
};
|
|
87
105
|
try {
|
|
88
|
-
const generatedKeyUri = yield this.
|
|
106
|
+
const generatedKeyUri = yield this.musapClient.generateKey(this.sscdType, keyGenReq);
|
|
89
107
|
if (generatedKeyUri) {
|
|
90
108
|
exports.logger.debug('Generated key:', generatedKeyUri);
|
|
91
|
-
const key =
|
|
109
|
+
const key = this.musapClient.getKeyByUri(generatedKeyUri);
|
|
92
110
|
return this.asMusapKeyInfo(key);
|
|
93
111
|
}
|
|
94
112
|
else {
|
|
@@ -104,7 +122,7 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
104
122
|
deleteKey(_a) {
|
|
105
123
|
return __awaiter(this, arguments, void 0, function* ({ kid }) {
|
|
106
124
|
try {
|
|
107
|
-
this.
|
|
125
|
+
void this.musapClient.removeKey(kid);
|
|
108
126
|
return true;
|
|
109
127
|
}
|
|
110
128
|
catch (error) {
|
|
@@ -130,7 +148,10 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
130
148
|
throw new Error('key_not_found: No key ref provided');
|
|
131
149
|
}
|
|
132
150
|
const data = new text_encoding_1.TextDecoder().decode(args.data);
|
|
133
|
-
const key = this.
|
|
151
|
+
const key = this.musapClient.getKeyById(args.keyRef.kid);
|
|
152
|
+
if (key.sscdType === 'External Signature') {
|
|
153
|
+
key.algorithm = 'eccp256r1'; // FIXME MUSAP announces key as rsa2k, but it's actually EC
|
|
154
|
+
}
|
|
134
155
|
const signatureReq = {
|
|
135
156
|
keyUri: key.keyUri,
|
|
136
157
|
data,
|
|
@@ -138,9 +159,9 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
138
159
|
displayText: args.displayText,
|
|
139
160
|
transId: args.transId,
|
|
140
161
|
format: (_a = args.format) !== null && _a !== void 0 ? _a : 'RAW',
|
|
141
|
-
attributes: args.attributes,
|
|
162
|
+
attributes: this.recordToSignatureAttributes(Object.assign(Object.assign({}, this.defaultSignAttributes), args.attributes)),
|
|
142
163
|
};
|
|
143
|
-
return this.
|
|
164
|
+
return this.musapClient.sign(signatureReq);
|
|
144
165
|
});
|
|
145
166
|
}
|
|
146
167
|
importKey(args) {
|
|
@@ -169,6 +190,24 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
169
190
|
sharedSecret(args) {
|
|
170
191
|
throw new Error('Not supported.');
|
|
171
192
|
}
|
|
193
|
+
recordToKeyAttributes(record) {
|
|
194
|
+
if (!record) {
|
|
195
|
+
return [];
|
|
196
|
+
}
|
|
197
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
198
|
+
name: key,
|
|
199
|
+
value,
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
recordToSignatureAttributes(record) {
|
|
203
|
+
if (!record) {
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
207
|
+
name: key,
|
|
208
|
+
value,
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
172
211
|
}
|
|
173
212
|
exports.MusapKeyManagementSystem = MusapKeyManagementSystem;
|
|
174
213
|
//# 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,qDAAiE;AACjE,iDAA2C;AAC3C,mDAA6C;AAE7C,2EAOwC;AAE3B,QAAA,MAAM,GAAG,mBAAO,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;AAElE,MAAa,wBAAyB,SAAQ,yCAA2B;IAOvE,YAAY,QAAmB,EAAE,MAAe,EAAE,IAIjD;QACC,KAAK,EAAE,CAAA;QA8DD,8BAAyB,GAAG,CAAC,IAAc,EAAoB,EAAE;YACvE,QAAQ,IAAI,EAAE,CAAC;gBACb,KAAK,WAAW;oBACd,OAAO,WAAW,CAAA;gBACpB,KAAK,WAAW;oBACd,OAAO,WAAW,CAAA;gBACpB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AC,CAAA;QACtF,OAAO,CAAC,IAAI,mCAAQ,OAAO,CAAC,IAAI,KAAE,aAAa,GAAE,CAAA;QACjD,OAAO,OAAyB,CAAA;IAClC,CAAC;IAED,YAAY,CAAC,IAAoF;QAC/F,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IACnC,CAAC;IAEO,qBAAqB,CAAC,MAA+B;QAC3D,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,EAAE,CAAA;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;IAEO,2BAA2B,CAAC,MAA+B;QACjE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,EAAE,CAAA;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;AA1MD,4DA0MC"}
|
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.26.1-next.
|
|
4
|
+
"version": "0.26.1-next.86+650ee51",
|
|
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.26.1-next.
|
|
15
|
-
"@sphereon/ssi-sdk-ext.x509-utils": "0.26.1-next.
|
|
13
|
+
"@sphereon/musap-react-native": "0.2.1-unstable.161",
|
|
14
|
+
"@sphereon/ssi-sdk-ext.key-utils": "0.26.1-next.86+650ee51",
|
|
15
|
+
"@sphereon/ssi-sdk-ext.x509-utils": "0.26.1-next.86+650ee51",
|
|
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": "650ee51e31a6dfa4abaf1227a5dbfdc0905f4670"
|
|
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'))
|
|
@@ -99,6 +126,9 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
99
126
|
return 'Secp256k1'
|
|
100
127
|
case 'eccp256r1':
|
|
101
128
|
return 'Secp256r1'
|
|
129
|
+
case 'ecc_ed25519':
|
|
130
|
+
return 'Ed25519'
|
|
131
|
+
case 'rsa2k':
|
|
102
132
|
case 'rsa4k':
|
|
103
133
|
return 'RSA'
|
|
104
134
|
default:
|
|
@@ -108,7 +138,7 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
108
138
|
|
|
109
139
|
async deleteKey({ kid }: { kid: string }): Promise<boolean> {
|
|
110
140
|
try {
|
|
111
|
-
this.
|
|
141
|
+
void this.musapClient.removeKey(kid)
|
|
112
142
|
return true
|
|
113
143
|
} catch (error) {
|
|
114
144
|
console.warn('Failed to delete key:', error)
|
|
@@ -129,14 +159,22 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
129
159
|
return signatureAlgorithmFromKeyAlgorithm(providedAlgorithm as JWSAlgorithm)
|
|
130
160
|
}
|
|
131
161
|
|
|
132
|
-
async sign(args: {
|
|
162
|
+
async sign(args: {
|
|
163
|
+
keyRef: Pick<IKey, 'kid'>;
|
|
164
|
+
algorithm?: string;
|
|
165
|
+
data: Uint8Array;
|
|
166
|
+
[x: string]: any
|
|
167
|
+
}): Promise<string> {
|
|
133
168
|
if (!args.keyRef) {
|
|
134
169
|
throw new Error('key_not_found: No key ref provided')
|
|
135
170
|
}
|
|
136
171
|
|
|
137
172
|
const data = new TextDecoder().decode(args.data as Uint8Array)
|
|
138
173
|
|
|
139
|
-
const key: MusapKey = this.
|
|
174
|
+
const key: MusapKey = this.musapClient.getKeyById(args.keyRef.kid) as MusapKey
|
|
175
|
+
if (key.sscdType as string === 'External Signature') {
|
|
176
|
+
key.algorithm = 'eccp256r1' // FIXME MUSAP announces key as rsa2k, but it's actually EC
|
|
177
|
+
}
|
|
140
178
|
const signatureReq: SignatureReq = {
|
|
141
179
|
keyUri: key.keyUri,
|
|
142
180
|
data,
|
|
@@ -144,9 +182,9 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
144
182
|
displayText: args.displayText,
|
|
145
183
|
transId: args.transId,
|
|
146
184
|
format: (args.format as SignatureFormat) ?? 'RAW',
|
|
147
|
-
attributes: args.attributes,
|
|
185
|
+
attributes: this.recordToSignatureAttributes({ ...this.defaultSignAttributes, ...args.attributes }),
|
|
148
186
|
}
|
|
149
|
-
return this.
|
|
187
|
+
return this.musapClient.sign(signatureReq)
|
|
150
188
|
}
|
|
151
189
|
|
|
152
190
|
async importKey(args: Omit<MinimalImportableKey, 'kms'> & { privateKeyPEM?: string }): Promise<ManagedKeyInfo> {
|
|
@@ -156,6 +194,7 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
156
194
|
private asMusapKeyInfo(args: MusapKey): ManagedKeyInfo {
|
|
157
195
|
const { keyId, publicKey, ...metadata }: KeyMetadata = { ...args }
|
|
158
196
|
const keyType = this.mapAlgorithmTypeToKeyType(args.algorithm)
|
|
197
|
+
|
|
159
198
|
const pemBinary = PEMToBinary(args.publicKey.pem) // The der is flawed, it's not binary but a string [123, 4567]
|
|
160
199
|
const publicKeyBinary = isAsn1Der(pemBinary) ? asn1DerToRawPublicKey(pemBinary, keyType) : pemBinary
|
|
161
200
|
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 +215,24 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
176
215
|
sharedSecret(args: { myKeyRef: Pick<IKey, 'kid'>; theirKey: Pick<IKey, 'publicKeyHex' | 'type'> }): Promise<string> {
|
|
177
216
|
throw new Error('Not supported.')
|
|
178
217
|
}
|
|
218
|
+
|
|
219
|
+
private recordToKeyAttributes(record?: Record<string, string>): KeyAttribute[] {
|
|
220
|
+
if (!record) {
|
|
221
|
+
return []
|
|
222
|
+
}
|
|
223
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
224
|
+
name: key,
|
|
225
|
+
value,
|
|
226
|
+
}))
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
private recordToSignatureAttributes(record?: Record<string, string>): SignatureAttribute[] {
|
|
230
|
+
if (!record) {
|
|
231
|
+
return []
|
|
232
|
+
}
|
|
233
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
234
|
+
name: key,
|
|
235
|
+
value,
|
|
236
|
+
}))
|
|
237
|
+
}
|
|
179
238
|
}
|