Skip to content

Commit

Permalink
[FABN-830] Client calls toBytes of PKCS11 keys
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jonathan Patchell authored and Jonathan Patchell committed Aug 15, 2018
1 parent f45d87b commit a0a7fb0
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions fabric-client/lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1246,14 +1246,23 @@ const Client = class extends BaseClient {
});
logger.debug(`Successfully enrolled user "${opts.username}"`);

const cryptoContent = { signedCertPEM: enrollment.certificate };
let keyBytes = null;
try {
keyBytes = enrollment.key.toBytes();
} catch(err) {
logger.debug('Cannot access enrollment private key bytes');
}
if (keyBytes != null && keyBytes.startsWith('-----BEGIN')) {
cryptoContent.privateKeyPEM = keyBytes;
} else {
cryptoContent.privateKeyObj = enrollment.key;
}
return this.createUser(
{
username: opts.username,
mspid: mspid,
cryptoContent: {
privateKeyPEM: enrollment.key.toBytes(),
signedCertPEM: enrollment.certificate
}
cryptoContent: cryptoContent
});
}

Expand Down

0 comments on commit a0a7fb0

Please sign in to comment.