Connect to the network now

pull/139/head
Baohua Yang 2021-07-22 16:37:37 -07:00
parent 7f649dfd3b
commit 01826b5e26
5 changed files with 80 additions and 10 deletions

View File

@ -16,6 +16,9 @@ jq -r ".certs.admincert" $file > admin.cert
echo "Output ca cert"
jq -r ".certs.cacert" $file > ca.cert
echo "Output tlsca cert"
jq -r ".certs.tlscacert" $file > tlsca.cert
echo "Output intermediate certs"
jq -r ".certs.intermediatecerts" $file > intermediate.cert

View File

@ -8,7 +8,9 @@
],
"peers": [
"peer0.org1.example.com",
"peer0.org2.example.com"
"peer1.org1.example.com",
"peer0.org2.example.com",
"peer1.org2.example.com"
]
}
},
@ -16,13 +18,15 @@
"Org1": {
"mspid": "Org1MSP",
"peers": [
"peer0.org1.example.com"
"peer0.org1.example.com",
"peer1.org1.example.com"
]
},
"Org2": {
"mspid": "Org2MSP",
"peers": [
"peer0.org2.example.com"
"peer0.org2.example.com",
"peer1.org2.example.com"
]
}
},
@ -47,6 +51,15 @@
"path": "/opt/crypto-config/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem"
}
},
"peer1.org1.example.com": {
"url": "grpcs://peer1.org1.example.com:7051",
"grpcOptions": {
"ssl-target-name-override": "peer1.org1.example.com"
},
"tlsCACerts": {
"path": "/opt/crypto-config/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem"
}
},
"peer0.org2.example.com": {
"url": "grpcs://peer0.org2.example.com:7051",
"grpcOptions": {
@ -55,6 +68,15 @@
"tlsCACerts": {
"path": "/opt/crypto-config/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem"
}
},
"peer1.org2.example.com": {
"url": "grpcs://peer1.org2.example.com:7051",
"grpcOptions": {
"ssl-target-name-override": "peer1.org2.example.com"
},
"tlsCACerts": {
"path": "/opt/crypto-config/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem"
}
}
}
}

View File

@ -10,7 +10,7 @@
"author": "Hyperledger",
"license": "Apache-2.0",
"dependencies": {
"fabric-network": "^2.2.4",
"fabric-common": "^2.2.4"
"fabric-network": "^2.2.8",
"fabric-common": "^2.2.8"
}
}
}

View File

@ -23,16 +23,16 @@ async function main() {
const client = new Client("c1")
client.addTlsClientCertAndKey({
url: "grpcs://peer0.org1.example.com:7051",
pem: "-----BEGIN CERTIFICATE-----MIIChTCCAiygAwIBAgIQVV+CR63zERwI+FLYFwBgmjAKBggqhkjOPQQDAjB2MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEfMB0GA1UEAxMWdGxzY2Eub3JnMS5leGFtcGxlLmNvbTAeFw0yMDA3MTcxODE5MDBaFw0zMDA3MTUxODE5MDBaMFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNpc2NvMR8wHQYDVQQDExZwZWVyMC5vcmcxLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEF4+/4lAVh7w2djxoer+rsmD6ejYG9MI3XH2s+vCEPd7AXZJoDq9UuCXZ7lU1dqEZldQN8564YsKa4sZ9EDDFvKOBtjCBszAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgMOm16EK5pSMRsbTTBkNFZvjBrd1hQaET+ZAA29zvkxIwRwYDVR0RBEAwPoIWcGVlcjAub3JnMS5leGFtcGxlLmNvbYIFcGVlcjCCFnBlZXIwLm9yZzEuZXhhbXBsZS5jb22CBXBlZXIwMAoGCCqGSM49BAMCA0cAMEQCICxAltMHintLLtqgF97c4KNXwH5QZRF8uWtlEGDwSkACAiA9FpumEzjlkaOenA69IeQSPhPKvYtXSvHrvDmMyaBJAg==-----END CERTIFICATE-----",
url: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twzYzwwx-----END PRIVATE KEY-----",
clientCert: "-----BEGIN CERTIFICATE-----MIICOzCCAeKgAwIBAgIRAPUP28xYwbLj0OAzFk4wlvgwCgYIKoZIzj0EAwIwdjELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHzAdBgNVBAMTFnRsc2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMjAwNzE3MTgxOTAwWhcNMzAwNzE1MTgxOTAwWjBbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEfMB0GA1UEAwwWQWRtaW5Ab3JnMS5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABNkRcwTElvBSdFiboyFr+GuOdeBuEsosCSbCH2IVGtbXNYjEtsf4Ut6tBRZ39u966EhLyShhpv7f5re3DNjPDDGjbDBqMA4GA1UdDwEB/wQEAwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADArBgNVHSMEJDAigCAw6bXoQrmlIxGxtNMGQ0Vm+MGt3WFBoRP5kADb3O+TEjAKBggqhkjOPQQDAgNHADBEAiAYQu0XAzDyrnlcJophUUV2HxnudmUGOXSLFONm4fa+6QIgRxeA7O1JDy9Yy2uM3aX5kNe9+WjSySGnp07ceLuRak4=-----END CERTIFICATE-----"
})
client.setTlsClientCertAndKey("-----BEGIN CERTIFICATE-----MIICOzCCAeKgAwIBAgIRAPUP28xYwbLj0OAzFk4wlvgwCgYIKoZIzj0EAwIwdjELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHzAdBgNVBAMTFnRsc2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMjAwNzE3MTgxOTAwWhcNMzAwNzE1MTgxOTAwWjBbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEfMB0GA1UEAwwWQWRtaW5Ab3JnMS5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABNkRcwTElvBSdFiboyFr+GuOdeBuEsosCSbCH2IVGtbXNYjEtsf4Ut6tBRZ39u966EhLyShhpv7f5re3DNjPDDGjbDBqMA4GA1UdDwEB/wQEAwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADArBgNVHSMEJDAigCAw6bXoQrmlIxGxtNMGQ0Vm+MGt3WFBoRP5kADb3O+TEjAKBggqhkjOPQQDAgNHADBEAiAYQu0XAzDyrnlcJophUUV2HxnudmUGOXSLFONm4fa+6QIgRxeA7O1JDy9Yy2uM3aX5kNe9+WjSySGnp07ceLuRak4=-----END CERTIFICATE-----","-----BEGIN PRIVATE KEY-----MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgOQEb55wiTX74p7cAMi33at2kDn0hgN2Q9lWutWRjTm+hRANCAATZEXMExJbwUnRYm6Mha/hrjnXgbhLKLAkmwh9iFRrW1zWIxLbH+FLerQUWd/bveuhIS8koYab+3+a3twzYzwwx-----END PRIVATE KEY-----")
const endPoint = new Endpoint({url:"grpcs://peer0.org1.example.com", pem:"-----BEGIN CERTIFICATE-----MIIChTCCAiygAwIBAgIQVV+CR63zERwI+FLYFwBgmjAKBggqhkjOPQQDAjB2MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEfMB0GA1UEAxMWdGxzY2Eub3JnMS5leGFtcGxlLmNvbTAeFw0yMDA3MTcxODE5MDBaFw0zMDA3MTUxODE5MDBaMFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNpc2NvMR8wHQYDVQQDExZwZWVyMC5vcmcxLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEF4+/4lAVh7w2djxoer+rsmD6ejYG9MI3XH2s+vCEPd7AXZJoDq9UuCXZ7lU1dqEZldQN8564YsKa4sZ9EDDFvKOBtjCBszAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgMOm16EK5pSMRsbTTBkNFZvjBrd1hQaET+ZAA29zvkxIwRwYDVR0RBEAwPoIWcGVlcjAub3JnMS5leGFtcGxlLmNvbYIFcGVlcjCCFnBlZXIwLm9yZzEuZXhhbXBsZS5jb22CBXBlZXIwMAoGCCqGSM49BAMCA0cAMEQCICxAltMHintLLtqgF97c4KNXwH5QZRF8uWtlEGDwSkACAiA9FpumEzjlkaOenA69IeQSPhPKvYtXSvHrvDmMyaBJAg==-----END CERTIFICATE-----", requestTimeout:300})
const endPoint = new Endpoint({url:"grpcs://peer1.org1.example.com:7051", pem:"-----BEGIN CERTIFICATE----- MIICVzCCAf2gAwIBAgIQQaMCImEphSvSI+GHAJmxqjAKBggqhkjOPQQDAjB2MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy YW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEfMB0GA1UEAxMWdGxzY2Eub3JnMS5leGFtcGxlLmNvbTAeFw0yMDA3MTcxODE5MDBaFw0zMDA3MTUxODE5 MDBaMHYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNpc2NvMRkwFwYDVQQKExBvcmcxLmV4YW1wbGUuY29tMR8wHQYD VQQDExZ0bHNjYS5vcmcxLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEVmrLLrpumifDP5gJfjVK3+RPl2W67+7NS/CV0rRfCG8d4xx+QvCRlaW/ 3LyIpcBMfGe7G9UgiaIVhhYHh+eNXKNtMGswDgYDVR0PAQH/BAQDAgGmMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1Ud DgQiBCAw6bXoQrmlIxGxtNMGQ0Vm+MGt3WFBoRP5kADb3O+TEjAKBggqhkjOPQQDAgNIADBFAiBkhGF4Adl6z0QfQlcAM85D2yFPVzC3/9WMJo/Qtjil9QIhAOfrSbTl IlN1ytBONKWl30rCv0pFOd6nTN7BOwllhWZq -----END CERTIFICATE-----", requestTimeout:30000})
const endorser = new Endorser("peer0-org1", client,"org1MSP")
const endorser = new Endorser("peer1-org1", client,"org1MSP")
await endorser.connect(endPoint)
// use the loaded connection profile
//const gateway = new Gateway();

View File

@ -0,0 +1,45 @@
'use strict';
// work with native fabric
const fs = require('fs')
const {Client, Endorser, Endpoint, Discoverer} = require('fabric-common');
async function main() {
const peer1TLSCACert=fs.readFileSync("/opt/crypto-config/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem").toString()
const org1AdminTLSClientCert=fs.readFileSync("/opt/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/tls/client.crt").toString()
const org1AdminTLSClientKey=fs.readFileSync("/opt/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/tls/client.key").toString()
const peerURL="grpcs://peer1.org1.example.com:7051"
const mspId="Org1MSP"
const client = new Client('myclient');
const endpoint = new Endpoint({url:peerURL, pem:peer1TLSCACert, clientCert:org1AdminTLSClientCert, clientKey:org1AdminTLSClientKey, requestTimeout: 30000, 'grpc-wait-for-ready-timeout': 30000});
// test using endorser
const endorser = new Endorser("myEndorser", client, mspId);
endorser.setEndpoint(endpoint);
await endorser.resetConnection()
try {
await endorser.connect(endpoint)
} catch (err) {
console.log(err)
console.log("is connectable = "+endorser.isConnectable())
await endorser.checkConnection()
if (endorser.hasChaincode("exp03")===true) {
console.log("Peer has chaincode")
} else {
console.log("Peer does not have chaincode")
}
}
// test using discoverer
const discoverer = new Discoverer("myDiscoverer", client, mspId);
discoverer.setEndpoint(endpoint);
await discoverer.resetConnection()
await discoverer.connect(endpoint)
await discoverer.checkConnection()
}
main()