Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit a0a7fb0

Browse files
Jonathan PatchellJonathan Patchell
authored andcommitted
[FABN-830] Client calls toBytes of PKCS11 keys
When using an HSM, the _setUserFromConfig() method of fabric-client/lib/Client.js calls the toBytes() method of the private key. In the case of an HSM this operation isn't allowed and it throws an error. This change will handle the error and constructs the cryptoContent accordingly. Change-Id: Iaae0ce0fca0316c252a851393770636a4c7cf42a Signed-off-by: Jonathan Patchell <Jonathan.Patchell@gemalto.com>
1 parent f45d87b commit a0a7fb0

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

fabric-client/lib/Client.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,14 +1246,23 @@ const Client = class extends BaseClient {
12461246
});
12471247
logger.debug(`Successfully enrolled user "${opts.username}"`);
12481248

1249+
const cryptoContent = { signedCertPEM: enrollment.certificate };
1250+
let keyBytes = null;
1251+
try {
1252+
keyBytes = enrollment.key.toBytes();
1253+
} catch(err) {
1254+
logger.debug('Cannot access enrollment private key bytes');
1255+
}
1256+
if (keyBytes != null && keyBytes.startsWith('-----BEGIN')) {
1257+
cryptoContent.privateKeyPEM = keyBytes;
1258+
} else {
1259+
cryptoContent.privateKeyObj = enrollment.key;
1260+
}
12491261
return this.createUser(
12501262
{
12511263
username: opts.username,
12521264
mspid: mspid,
1253-
cryptoContent: {
1254-
privateKeyPEM: enrollment.key.toBytes(),
1255-
signedCertPEM: enrollment.certificate
1256-
}
1265+
cryptoContent: cryptoContent
12571266
});
12581267
}
12591268

0 commit comments

Comments
 (0)