How to use the fabric-common.Utils.newCryptoKeyStore function in fabric-common

To help you get started, we’ve selected a few fabric-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperledger / fabric-sdk-node / test / unit / crypto-key-store.js View on Github external
test('\n\n** CryptoKeyStore tests - newCryptoKeyStore tests **\n\n', (t) => {
	utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');// force for 'gulp test'
	const keyValStorePath = 'tmp/keyValStore1';
	const config = {path: keyValStorePath};
	let cs = utils.newCryptoKeyStore(config);
	t.equal(cs._storeConfig.opts, config, util.format('Returned instance should have store config opts of %j', config));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	const defaultKVSPath = path.join(os.homedir(), '.hfc-key-store');
	cs = utils.newCryptoKeyStore();
	t.equal(cs._storeConfig.opts.path, defaultKVSPath, util.format('Returned instance should have store config opts.path of %s', defaultKVSPath));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	let kvsImplClass = require(utils.getConfigSetting('key-value-store'));
	cs = utils.newCryptoKeyStore(kvsImplClass);
	t.equal(cs._storeConfig.opts.path, defaultKVSPath, util.format('Returned instance should have store config opts.path of %s', defaultKVSPath));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	kvsImplClass = require(utils.getConfigSetting('key-value-store'));
	cs = utils.newCryptoKeyStore(kvsImplClass, config);
	t.equal(cs._storeConfig.opts, config, util.format('Returned instance should have store config opts of %j', config));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	t.end();
});
github hyperledger / fabric-sdk-node / test / unit / crypto-key-store.js View on Github external
test('\n\n** CryptoKeyStore tests - newCryptoKeyStore tests **\n\n', (t) => {
	utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');// force for 'gulp test'
	const keyValStorePath = 'tmp/keyValStore1';
	const config = {path: keyValStorePath};
	let cs = utils.newCryptoKeyStore(config);
	t.equal(cs._storeConfig.opts, config, util.format('Returned instance should have store config opts of %j', config));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	const defaultKVSPath = path.join(os.homedir(), '.hfc-key-store');
	cs = utils.newCryptoKeyStore();
	t.equal(cs._storeConfig.opts.path, defaultKVSPath, util.format('Returned instance should have store config opts.path of %s', defaultKVSPath));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	let kvsImplClass = require(utils.getConfigSetting('key-value-store'));
	cs = utils.newCryptoKeyStore(kvsImplClass);
	t.equal(cs._storeConfig.opts.path, defaultKVSPath, util.format('Returned instance should have store config opts.path of %s', defaultKVSPath));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	kvsImplClass = require(utils.getConfigSetting('key-value-store'));
	cs = utils.newCryptoKeyStore(kvsImplClass, config);
	t.equal(cs._storeConfig.opts, config, util.format('Returned instance should have store config opts of %j', config));
github hyperledger / fabric-sdk-node / test / unit / crypto-key-store.js View on Github external
test('\n\n** CryptoKeyStore tests - newCryptoKeyStore tests **\n\n', (t) => {
	utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');// force for 'gulp test'
	const keyValStorePath = 'tmp/keyValStore1';
	const config = {path: keyValStorePath};
	let cs = utils.newCryptoKeyStore(config);
	t.equal(cs._storeConfig.opts, config, util.format('Returned instance should have store config opts of %j', config));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	const defaultKVSPath = path.join(os.homedir(), '.hfc-key-store');
	cs = utils.newCryptoKeyStore();
	t.equal(cs._storeConfig.opts.path, defaultKVSPath, util.format('Returned instance should have store config opts.path of %s', defaultKVSPath));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	let kvsImplClass = require(utils.getConfigSetting('key-value-store'));
	cs = utils.newCryptoKeyStore(kvsImplClass);
	t.equal(cs._storeConfig.opts.path, defaultKVSPath, util.format('Returned instance should have store config opts.path of %s', defaultKVSPath));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	kvsImplClass = require(utils.getConfigSetting('key-value-store'));
	cs = utils.newCryptoKeyStore(kvsImplClass, config);
	t.equal(cs._storeConfig.opts, config, util.format('Returned instance should have store config opts of %j', config));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	t.end();
});
github hyperledger / fabric-sdk-node / test / unit / cryptosuite-ecdsa-aes.js View on Github external
}).then((key) => {
			t.equal('secp384r1', key.getPublicKey()._key.curveName,
				'CryptoSuite_ECDSA_AES function tests: ccryptoUtils generated public key curveName == secp384r1');

			if (key._key) {
				t.pass('CryptoSuite_ECDSA_AES function tests: verify generateKey return object');
			} else {
				t.fail('CryptoSuite_ECDSA_AES function tests: verify generateKey return object');
			}

			utils.setConfigSetting('crypto-hash-algo', 'sha3'); // lower or upper case is allowed
			cryptoUtils = utils.newCryptoSuite();
			cryptoUtils.setCryptoKeyStore(utils.newCryptoKeyStore());

			t.equal(cryptoUtils.hash(TEST_MSG), HASH_MSG_SHA3_384,
				'CryptoSuite_ECDSA_AES function tests: using "SHA3" hashing algorithm with key size 384');

			// test generation options
			return cryptoUtils.generateKey({ephemeral: true});
		}, (err) => {
			t.fail('Failed to generateKey. Can not progress any further. Exiting. ' + err.stack ? err.stack : err);
github hyperledger / fabric-sdk-node / fabric-client / lib / msp / msp-manager.js View on Github external
if (!fabricConfig.getName()) {
				throw new Error('MSP Configuration does not have a name');
			}

			// with this method we are only dealing with verifying MSPs, not local MSPs. Local MSPs are instantiated
			// from user enrollment materials (see User class). For verifying MSPs the root certificates are always
			// required
			if (!fabricConfig.getRootCerts()) {
				throw new Error('MSP Configuration does not have any root certificates required for validating signing certificates');
			}

			// TODO: for now using application-scope defaults but crypto parameters like key size, hash family
			// and digital signature algorithm should be from the config itself
			const cs = utils.newCryptoSuite();
			cs.setCryptoKeyStore(utils.newCryptoKeyStore());

			// get the application org names
			const orgs = [];
			const org_units = fabricConfig.getOrganizationalUnitIdentifiers();
			if (org_units) {
				for (let i = 0; i < org_units.length; i++) {
					const org_unit = org_units[i];
					const org_id = org_unit.organizational_unit_identifier;
					logger.debug('loadMSPs - found org of :: %s', org_id);
					orgs.push(org_id);
				}
			}

			const newMSP = new MSP({
				rootCerts: fabricConfig.getRootCerts(),
				intermediateCerts: fabricConfig.getIntermediateCerts(),
github hyperledger / fabric-sdk-node / test / unit / crypto-key-store.js View on Github external
let cs = utils.newCryptoKeyStore(config);
	t.equal(cs._storeConfig.opts, config, util.format('Returned instance should have store config opts of %j', config));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	const defaultKVSPath = path.join(os.homedir(), '.hfc-key-store');
	cs = utils.newCryptoKeyStore();
	t.equal(cs._storeConfig.opts.path, defaultKVSPath, util.format('Returned instance should have store config opts.path of %s', defaultKVSPath));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	let kvsImplClass = require(utils.getConfigSetting('key-value-store'));
	cs = utils.newCryptoKeyStore(kvsImplClass);
	t.equal(cs._storeConfig.opts.path, defaultKVSPath, util.format('Returned instance should have store config opts.path of %s', defaultKVSPath));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	kvsImplClass = require(utils.getConfigSetting('key-value-store'));
	cs = utils.newCryptoKeyStore(kvsImplClass, config);
	t.equal(cs._storeConfig.opts, config, util.format('Returned instance should have store config opts of %j', config));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	t.end();
});
github hyperledger / fabric-sdk-node / fabric-ca-client / lib / FabricCAServices.js View on Github external
} else {
			_url = url;
			_tlsOptions = tlsOptions;
			_caName = caName;
			_cryptoSuite = cryptoSuite;
		}

		this.caName = _caName;

		const endpoint = parseURL(_url);

		if (_cryptoSuite) {
			this.setCryptoSuite(_cryptoSuite);
		} else {
			this.setCryptoSuite(utils.newCryptoSuite());
			this.getCryptoSuite().setCryptoKeyStore(utils.newCryptoKeyStore());
		}

		this._fabricCAClient = new FabricCAClient({
			caname: _caName,
			protocol: endpoint.protocol,
			hostname: endpoint.hostname,
			port: endpoint.port,
			tlsOptions: _tlsOptions
		}, this.getCryptoSuite());

		logger.debug('Successfully constructed Fabric CA service client: endpoint - %j', endpoint);

	}