Skip to content

Commit

Permalink
FABN-599 - Add msp unit test
Browse files Browse the repository at this point in the history
- Add msp.js Mocha test
- Remove obsolete Identity tape test
- Remove obsolete MSP test
- Remove obsolete Remote tape test
- remove obsolete user tape test
- Remove obsolete tape perf tests
- Move constants to constants file, and use them from there

Change-Id: I28e6fe2d3947d3cdd896caab70a92e8b61314eac
Signed-off-by: [email protected] <[email protected]>
  • Loading branch information
nklincoln committed Feb 8, 2019
1 parent ff63a50 commit bcedac0
Show file tree
Hide file tree
Showing 15 changed files with 546 additions and 1,371 deletions.
3 changes: 1 addition & 2 deletions fabric-client/lib/msp/msp.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ const MSP = class {
logger.debug('Encoded cert from deserialized identity: %s', cert);
if (!store_key) {
const publicKey = this.cryptoSuite.importKey(cert, {algorithm: CryptoAlgorithms.X509Certificate, ephemeral: true});
const sdk_identity = new Identity(cert, publicKey, this.getId(), this.cryptoSuite);
return sdk_identity;
return new Identity(cert, publicKey, this.getId(), this.cryptoSuite);
} else {
return this.cryptoSuite.importKey(cert, {algorithm: CryptoAlgorithms.X509Certificate})
.then((publicKey) => {
Expand Down
45 changes: 17 additions & 28 deletions fabric-client/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
/**
* Copyright 2019 IBM All Rights Reserved.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-License-Identifier: Apache-2.0
*/


Expand All @@ -29,17 +21,20 @@ const sjcl = require('sjcl');
// The following methods are for loading the proper implementation of an extensible APIs.
//

// returns a new instance of the CryptoSuite API implementation
//
// @param {Object} setting This optional parameter is an object with the following optional properties:
// - software {boolean}: Whether to load a software-based implementation (true) or HSM implementation (false)
// default is true (for software based implementation), specific implementation module is specified
// in the setting 'crypto-suite-software'
// - keysize {number}: The key size to use for the crypto suite instance. default is value of the setting 'crypto-keysize'
// - algorithm {string}: Digital signature algorithm, currently supporting ECDSA only with value "EC"
// - hash {string}: 'SHA2' or 'SHA3'
//
//
/**
* Returns a new instance of the CryptoSuite API implementation. Supports the following:
* - newCryptoSuite({software: true, keysize: 256, algorithm: EC})
* - newCryptoSuite({software: false, lib: '/usr/local/bin/pkcs11.so', slot: 0, pin: '1234'})
* - newCryptoSuite({keysize: 384})
* - newCryptoSuite()
* @param {Object} setting This optional parameter is an object with the following optional properties:
* - software {boolean}: Whether to load a software-based implementation (true) or HSM implementation (false)
* default is true (for software based implementation), specific implementation module is specified
* in the setting 'crypto-suite-software'
* - keysize {number}: The key size to use for the crypto suite instance. default is value of the setting 'crypto-keysize'
* - algorithm {string}: Digital signature algorithm, currently supporting ECDSA only with value "EC"
* - hash {string}: 'SHA2' or 'SHA3'
*/
module.exports.newCryptoSuite = (setting) => {
let csImpl, keysize, algorithm, hashAlgo, opts = null;

Expand All @@ -52,12 +47,6 @@ module.exports.newCryptoSuite = (setting) => {

csImpl = useHSM ? exports.getConfigSetting('crypto-suite-hsm') : exports.getConfigSetting('crypto-suite-software');

// this function supports the following:
// - newCryptoSuite({software: true, keysize: 256, algorithm: EC})
// - newCryptoSuite({software: false, lib: '/usr/local/bin/pkcs11.so', slot: 0, pin: '1234'})
// - newCryptoSuite({keysize: 384})
// - newCryptoSuite()

// step 1: what's the cryptosuite impl to use, key size and algo
if (setting && setting.keysize && typeof setting === 'object' && typeof setting.keysize === 'number') {
keysize = setting.keysize;
Expand Down
15 changes: 15 additions & 0 deletions fabric-client/test/data/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-----BEGIN CERTIFICATE-----
MIICVDCCAfqgAwIBAgIUfU2mX13EKc1LRR5Fet2iwFPn+IMwCgYIKoZIzj0EAwIw
XTELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQK
EwtIeXBlcmxlZGdlcjEPMA0GA1UECxMGRmFicmljMQ4wDAYDVQQDEwV0bHNjYTAe
Fw0xOTAyMDQxMTUxMDBaFw0yMDAyMDQxMTU2MDBaMF0xCzAJBgNVBAYTAlVTMRcw
FQYDVQQIEw5Ob3J0aCBDYXJvbGluYTEUMBIGA1UEChMLSHlwZXJsZWRnZXIxDzAN
BgNVBAsTBmNsaWVudDEOMAwGA1UEAxMFYWRtaW4wWTATBgcqhkjOPQIBBggqhkjO
PQMBBwNCAAR+08XWiZZWFkrhX4nC2s0W0QwfIZpMgdgYnLkYcSSEiw+KAuuZBgAc
zgmP/o35XPLXeGQ2UlMCpZnVmDSQ5QvFo4GXMIGUMA4GA1UdDwEB/wQEAwIDqDAd
BgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADAdBgNV
HQ4EFgQUcnSSvNcFSuKRNlLqmqct0Kea7aMwHwYDVR0jBBgwFoAUV1uJWaYdWC+h
t4RtFzxQe/F9jswwFQYDVR0RBA4wDIcEqS7fWocEfwAAATAKBggqhkjOPQQDAgNI
ADBFAiEAt1tv0n42KtkmpUNNuD1ji6hJTBVc6hQL1GcQbVgWW0ACIH6F6vA26TwI
N7FqJHSDzyVAcz5B9VuO6PMB1v/cGs1M
-----END CERTIFICATE-----
Loading

0 comments on commit bcedac0

Please sign in to comment.