How to use the fabric-client.newCryptoKeyStore function in fabric-client

To help you get started, we’ve selected a few fabric-client 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-test / tools / PTE / pte-main.js View on Github external
logger.error('[queryBlockchainInfo] no connection profile is found for org(%s)', org);
            process.exit(1);
        }

        var username = testUtil.getOrgEnrollIdSubmitter(cpf, org);
        var secret = testUtil.getOrgEnrollSecretSubmitter(cpf, org);

        sBlock = txCfgPtr.queryBlockOpt.startBlock;
        eBlock = txCfgPtr.queryBlockOpt.endBlock;
        qOrg = txCfgPtr.queryBlockOpt.org;
        qPeer = txCfgPtr.queryBlockOpt.peer;
        logger.info('[queryBlockchainInfo] query block info org:peer:start:end=%s:%s:%d:%d', qOrg, qPeer, sBlock, eBlock);

        hfc.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');
        var cryptoSuite = hfc.newCryptoSuite();
        cryptoSuite.setCryptoKeyStore(hfc.newCryptoKeyStore({ path: testUtil.storePathForOrg(Nid, orgName) }));
        client.setCryptoSuite(cryptoSuite);

        // get client key
        if (TLS == testUtil.TLSCLIENTAUTH) {
            await testUtil.tlsEnroll(client, org, cpf);
            logger.debug('[queryBlockchainInfo] got user private key: org= %s', org);
        }

        chainAddOrderer(channel, client, org);

        channelAddQIPeer(channel, client, qOrg, qPeer);

        return hfc.newDefaultKeyValueStore({
            path: testUtil.storePathForOrg(orgName)
        }).then(function (store) {
            client.setStateStore(store);
github hyperledger / fabric-sdk-node / test / integration / grpc.js View on Github external
test('\n\n*** GRPC message size tests ***\n\n', async (t) => {
	testUtil.resetDefaults();
	testUtil.setupChaincodeDeploy();

	try {
		// setup client , including user and tls mutual certs
		const client = new Client();
		const channel_name = testUtil.END2END.channel;
		const channel = client.newChannel(channel_name);
		const ORGS = Client.getConfigSetting('test-network');
		const userOrg = 'org1';
		const orgName = ORGS[userOrg].name;
		const url = ORGS[userOrg].peer1.requests;
		const data = fs.readFileSync(path.join(__dirname, 'e2e', ORGS[userOrg].peer1.tls_cacerts));
		const cryptoSuite = Client.newCryptoSuite();
		cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: testUtil.storePathForOrg(orgName)}));
		client.setCryptoSuite(cryptoSuite);
		const tlsInfo = await e2eUtils.tlsEnroll(userOrg);
		client.setTlsClientCertAndKey(tlsInfo.certificate, tlsInfo.key);
		const store = await Client.newDefaultKeyValueStore({path: testUtil.storePathForOrg(orgName)});
		client.setStateStore(store);
		await testUtil.getSubmitter(client, t, userOrg, true);

		// make sure chaincode is installed that has the echo function
		const go_cc = testUtil.END2END.chaincodeId;
		const node_cc = testUtil.NODE_END2END.chaincodeId;
		const version = 'v' + (new Date()).getTime();
		await e2eUtils.installChaincode(userOrg, testUtil.CHAINCODE_UPGRADE_PATH, testUtil.METADATA_PATH, version, 'golang', t, true);
		await e2eUtils.installChaincode('org2', testUtil.CHAINCODE_UPGRADE_PATH, testUtil.METADATA_PATH, version, 'golang', t, true);
		await e2eUtils.instantiateChaincode(userOrg, testUtil.CHAINCODE_UPGRADE_PATH, version, 'golang', true, false, t);
		await e2eUtils.installChaincode(userOrg, testUtil.NODE_CHAINCODE_UPGRADE_PATH, testUtil.METADATA_PATH, version, 'node', t, true);
		await e2eUtils.installChaincode('org2', testUtil.NODE_CHAINCODE_UPGRADE_PATH, testUtil.METADATA_PATH, version, 'node', t, true);
github hyperledger / fabric-sdk-node / test / integration / network-e2e / idmanager.js View on Github external
async initialize() {
		this.defaultClient = await Client.loadFromConfig(this.ccp);
		this.defaultClient.setCryptoSuite(Client.newCryptoSuite());

		this.hsmClient = await Client.loadFromConfig(this.ccp);
		const hsmCryptoSuite = Client.newCryptoSuite(this.hsmOptions);
		// Setting a key store triggers enrollment using this crypto suite to store the generated private key in the HSM
		hsmCryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: '/tmp'}));
		this.hsmClient.setCryptoSuite(hsmCryptoSuite);
	}
github hyperledger / fabric-sdk-node / test / integration / e2e / updateAnchorPeers.js View on Github external
const client = new Client();

	const caRootsPath = ORGS.orderer.tls_cacerts;
	const data = fs.readFileSync(path.join(__dirname, caRootsPath));
	const caroots = Buffer.from(data).toString();

	utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');

	const tlsInfo = await e2eUtils.tlsEnroll(org);
	client.setTlsClientCertAndKey(tlsInfo.certificate, tlsInfo.key);

	const store = await Client.newDefaultKeyValueStore({path: testUtil.storePathForOrg(ORGS[org].name)});
	client.setStateStore(store);
	const cryptoSuite = Client.newCryptoSuite();
	cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: testUtil.storePathForOrg(ORGS[org].name)}));
	client.setCryptoSuite(cryptoSuite);


	await testUtil.getSubmitter(client, t, true /* get the org admin*/, org);
	t.pass(`Successfully enrolled user 'admin' for ${org}`);

	const orderer = client.newOrderer(
		ORGS.orderer.url,
		{
			name: 'new orderer',
			'pem': caroots,
			'ssl-target-name-override': ORGS.orderer['server-hostname']
		}
	);

	const channel = client.newChannel(channel_name);
github IBM / monitoring_ui / react-backend / routes / index.js View on Github external
//   })
    //   config = hfc.loadFromConfig(json)
    // });
    client = hfc.loadFromConfig('./connection_profile.json')
  } else {
    client = hfc.loadFromConfig(requestConnectionProfile(req))
  }

  org = Object.keys(client._network_config._network_config.organizations)[0]
  certificateAuthorities = client._network_config._network_config.certificateAuthorities
  certificateAuthorityName = Object.keys(certificateAuthorities)[0]
  certificateAuthObj = certificateAuthorities[certificateAuthorityName]
  mspId = client._network_config._network_config.organizations[org]['mspid']
  storePath = './'
  client_crypto_suite = hfc.newCryptoSuite()
  crypto_store = hfc.newCryptoKeyStore({path: storePath})
  crypto_suite = hfc.newCryptoSuite()
  crypto_suite.setCryptoKeyStore(crypto_store)
  username = "monitoring_admin"
  // var crypto_store = hfc.newCryptoKeyStore({path: storePath})
  // crypto_suite.setCryptoKeyStore(crypto_store)
  client.setCryptoSuite(crypto_suite)
  // config.setCryptoSuite(client_crypto_suite);

  hfc.newDefaultKeyValueStore({path: storePath}).then( (store) => {
    client.setStateStore(store)
  }).then( (result) => {
    client.getUserContext(username, true).then ( (user) => {
    // res.send("Client Initialized")
    // console.log("Client Initialized")
    if (user && user.isEnrolled()) {
      console.log("Client Loaded From Persistence")
github blockchainvn / hyperledger-fabric-k8s / admin / controller.js View on Github external
.then(store => {
          fabric_client.setStateStore(store);
          const crypto_suite = Fabric_Client.newCryptoSuite();
          // use the same location for the state store (where the users' certificate are kept)
          // and the crypto store (where the users' keys are kept)
          const crypto_store = Fabric_Client.newCryptoKeyStore(
            keyvalueStoreConfig
          );
          crypto_suite.setCryptoKeyStore(crypto_store);
          fabric_client.setCryptoSuite(crypto_suite);
          return this.getSubmitter(fabric_client, config);

          // return fabric_client
          //   .loadUserFromStateStore(config.user)
          //   .then(member => fabric_client.setUserContext(member, true));

          // return this.getSubmitter(fabric_client, config);
        })
        .then(submitter => {
github hyperledger / education / LFS171x / fabric-material / tuna-app / registerUser.js View on Github external
}).then((state_store) => {
    // assign the store to the fabric client
    fabric_client.setStateStore(state_store);
    var crypto_suite = Fabric_Client.newCryptoSuite();
    // use the same location for the state store (where the users' certificate are kept)
    // and the crypto store (where the users' keys are kept)
    var crypto_store = Fabric_Client.newCryptoKeyStore({path: store_path});
    crypto_suite.setCryptoKeyStore(crypto_store);
    fabric_client.setCryptoSuite(crypto_suite);
    var	tlsOptions = {
    	trustedRoots: [],
    	verify: false
    };
    // be sure to change the http to https when the CA is running TLS enabled
    fabric_ca_client = new Fabric_CA_Client('http://localhost:7054', null , '', crypto_suite);

    // first check to see if the admin is already enrolled
    return fabric_client.getUserContext('admin', true);
}).then((user_from_store) => {
    if (user_from_store && user_from_store.isEnrolled()) {
github asararatnakar / FabricNodeApp1.0 / app / helper.js View on Github external
var hfc = require('fabric-client');
hfc.addConfigFile(path.join(__dirname, 'network-config.json'));
hfc.setLogger(logger);
var ORGS = hfc.getConfigSetting('network-config');

var clients = {};
var channels = {};
var caClients = {};

// set up the client and channel objects for each org
for (let key in ORGS) {
    if (key.indexOf('org') === 0) {
        let client = new hfc();

        let cryptoSuite = hfc.newCryptoSuite();
        cryptoSuite.setCryptoKeyStore(hfc.newCryptoKeyStore({ path: getKeyStoreForOrg(ORGS[key].name) }));
        client.setCryptoSuite(cryptoSuite);
        channels[key] = {};
        for (let index in config.channelsList) {
            let channelName = config.channelsList[index];
            let channel = client.newChannel(channelName);
            //Add all the orderers
            newOrderer(client, channel)
            clients[key] = client;
            channels[key][channelName] = channel;

            setupPeers(channel, key, client);
        }
        let caUrl = ORGS[key].ca;
        caClients[key] = new FabricCAService(caUrl, null /*defautl TLS opts*/ , '' /* default CA */ , cryptoSuite);
    }
}
github hyperledger / caliper / packages / caliper-fabric / lib / e2eUtils.js View on Github external
const channel_name = chaincode.channel;

    const client = new Client();
    const channel = client.newChannel(channel_name);

    // Conditional action on TLS enablement
    if(ORGS.orderer.url.toString().startsWith('grpcs')){
        const fabricCAEndpoint = ORGS[org].ca.url;
        const caName = ORGS[org].ca.name;
        const tlsInfo = await tlsEnroll(fabricCAEndpoint, caName);
        client.setTlsClientCertAndKey(tlsInfo.certificate, tlsInfo.key);
    }

    const orgName = ORGS[org].name;
    const cryptoSuite = Client.newCryptoSuite();
    cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: testUtil.storePathForOrg(orgName)}));
    client.setCryptoSuite(cryptoSuite);

    const caRootsPath = ORGS.orderer.tls_cacerts;
    let data = fs.readFileSync(CaliperUtils.resolvePath(caRootsPath, networkRoot));
    let caroots = Buffer.from(data).toString();

    channel.addOrderer(
        client.newOrderer(
            ORGS.orderer.url,
            {
                'pem': caroots,
                'ssl-target-name-override': ORGS.orderer['server-hostname']
            }
        )
    );
github hyperledger / fabric-sdk-node / test / integration / util.js View on Github external
function getAdmin(client, t, userOrg) {
	const keyPath = path.join(__dirname, util.format('../fixtures/crypto-material/crypto-config/peerOrganizations/%s.example.com/users/Admin@%s.example.com/msp/keystore', userOrg, userOrg));
	const keyPEM = Buffer.from(readAllFiles(keyPath)[0]).toString();
	const certPath = path.join(__dirname, util.format('../fixtures/crypto-material/crypto-config/peerOrganizations/%s.example.com/users/Admin@%s.example.com/msp/signcerts', userOrg, userOrg));
	const certPEM = readAllFiles(certPath)[0];

	const cryptoSuite = Client.newCryptoSuite();
	if (userOrg) {
		cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: module.exports.storePathForOrg(ORGS[userOrg].name)}));
		client.setCryptoSuite(cryptoSuite);
	}

	return Promise.resolve(client.createUser({
		username: 'peer' + userOrg + 'Admin',
		mspid: ORGS[userOrg].mspid,
		cryptoContent: {
			privateKeyPEM: keyPEM.toString(),
			signedCertPEM: certPEM.toString()
		}
	}));
}