使用fabric-ca-client进行Hyperledger V1.0用户注册,JWT令牌已过期

时间:2017-09-26 07:15:58

标签: node.js express postman access-token hyperledger-fabric

我在与Hyperledger fabric V1.0交互时遇到了一些问题。我正在测试Ubuntu机器上的余额转移示例。我停靠了Node.js API,以便与来自远程应用程序的结构进行交互。然后我在Docker上为node.js应用程序公开了端口4000,并与容器的外部端口建立了桥接以访问服务器。昨天我可以从命令行本地执行sample REST API requests。例如,我可以在网络中注册/注册用户,创建频道等。但是使用Postman工具,我收到的错误如下:

  • 错误:注册失败;
  • ECONNREFUSED localhost:8054,ECONNREFUSED localhost:7054,端口号 取决于我用于请求的用户令牌。
  • 错误:必须为此客户端实例分配用户上下文。

这是我的第一个问题。

今天出现了第二个问题。 Node.js使用JWS令牌进行安全身份验证,这些令牌在10小时后过期,这是正常的,因为它在config.json文件中以这种方式配置。但我无法理解的是,我甚至无法使用命令行从localhost验证新用户。例如,此登录请求不会返回任何内容,它不会执行:

curl -s -X POST http://localhost:4000/users -H "content-type: application/x-www-form-urlencoded" -d 'username=Jim&orgName=org1'
来自POSTMAN的POST请求给出了以下错误:

[2017-09-26 06:46:57.514] [DEBUG] SampleWebApp - End point : /users
[2017-09-26 06:46:57.514] [DEBUG] SampleWebApp - User name : Toko
[2017-09-26 06:46:57.514] [DEBUG] SampleWebApp - Org name  : org1
[2017-09-26 06:46:57.519] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore.js - constructor
[2017-09-26 06:46:57.523] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore -- getValue
[2017-09-26 06:46:57.525] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore.js - constructor
[2017-09-26 06:46:57.526] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore -- getValue
[2017-09-26 06:46:57.602] [DEBUG] Helper - [utils.CryptoKeyStore]: This class requires a CryptoKeyStore to save keys, using the store: {"opts":{"path":"/tmp/fabric-client-kvs_peerOrg1"}}
[2017-09-26 06:46:57.603] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore.js - constructor
[2017-09-26 06:46:57.604] [DEBUG] Helper - [utils.CryptoKeyStore]: _getKeyStore returning ks
[2017-09-26 06:46:57.604] [DEBUG] Helper - [crypto_ecdsa_aes]: generateKey, store.setValue
[2017-09-26 06:46:57.605] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param X: ea4b0229247d282daf293fc11728b4a4a4bddcabecffca02f7bcde725f0738c7
[2017-09-26 06:46:57.606] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param Y: f6a41282f86bcd853fddca402f1d47868a864b46adc8abd4e8a5864778f18de5
[2017-09-26 06:46:57.613] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore -- setValue
[2017-09-26 06:46:57.675] [ERROR] Helper - Error: Calling enrollment endpoint failed with error [Error: connect ECONNREFUSED 127.0.0.1:7054]
    at ClientRequest.<anonymous> (/usr/src/app/node_modules/fabric-ca-client/lib/FabricCAClientImpl.js:711:12)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:188:7)
    at TLSSocket.socketErrorListener (_http_client.js:310:9)
    at emitOne (events.js:96:13)
    at TLSSocket.emit (events.js:188:7)
    at emitErrorNT (net.js:1277:8)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
[2017-09-26 06:46:57.676] [DEBUG] Helper - Toko failed to register
[2017-09-26 06:46:57.677] [ERROR] Helper - Toko enrollment failed
(node:17) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Cannot save null userContext.
(node:17) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property '_enrollmentSecret' of null

如果您有任何人已经遇到同样的问题,请指导我。提前谢谢!

更新 Docker容器:

&#13;
&#13;
40b9eb090695        dev-peer1.org1.example.com-mycc-v0-f76f22af4a360dd2172e04459b1687f933a29d4b8d6c97ea0a4a21144a108361   "chaincode -peer.a..."   2 hours ago         Up 2 hours                                                           dev-peer1.org1.example.com-mycc-v0
2a7d3271c32a        dev-peer0.org1.example.com-mycc-v0-f021beca29998638e0bb7caa7af8fda7f1e709518214a3181d259abcb2347093   "chaincode -peer.a..."   2 hours ago         Up 2 hours                                                           dev-peer0.org1.example.com-mycc-v0
b5c6f5d3a036        myapp/node-app                                                                                         "npm start"              2 hours ago         Up 2 hours          0.0.0.0:9999->4000/tcp                           myapp_node
33b7c1355832        hyperledger/fabric-peer                                                                               "peer node start"        2 hours ago         Up 2 hours          0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp   peer0.org1.example.com
cf9b72d928ef        hyperledger/fabric-peer                                                                               "peer node start"        2 hours ago         Up 2 hours          0.0.0.0:7056->7051/tcp, 0.0.0.0:7058->7053/tcp   peer1.org1.example.com
4de554d07d7b        hyperledger/fabric-peer                                                                               "peer node start"        2 hours ago         Up 2 hours          0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp   peer0.org2.example.com
c627b28ebd4a        hyperledger/fabric-peer                                                                               "peer node start"        2 hours ago         Up 2 hours          0.0.0.0:8056->7051/tcp, 0.0.0.0:8058->7053/tcp   peer1.org2.example.com
e02b4ffe531b        hyperledger/fabric-ca                                                                                 "sh -c 'fabric-ca-..."   2 hours ago         Up 2 hours          0.0.0.0:8054->7054/tcp                           ca_peerOrg2
91dc8167caed        hyperledger/fabric-orderer                                                                            "orderer"                2 hours ago         Up 2 hours          0.0.0.0:7050->7050/tcp                           orderer.example.com
d150835f7826        hyperledger/fabric-ca                                                                                 "sh -c 'fabric-ca-..."   2 hours ago         Up 2 hours          0.0.0.0:7054->7054/tcp                           ca_peerOrg1
&#13;
&#13;
&#13;

由于我在连接到ca_peerOrg1时在localhost:7054上收到错误 - Error: Calling enrollment endpoint failed with error [Error: connect ECONNREFUSED 127.0.0.1:7054] 我通过运行此命令检查了ca_peerOrg1容器:docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' d150835f7826 我得到以下IP地址:172.20.0.2。是否意味着Fabric-client配置不正确? /users方法请求localhost:7054,但实际上ca_peerOrg1有不同的ip - 172.20.0.2。如果它是这样我怎么能配置sdk的IP地址?

解决 我通过在app/network-config.json文件中使用我的Ubuntu 服务器IP地址更改 localhost 来解决了我的问题。现在,我可以使用以下网址http://serverIP:PublicPort/users访问API的用户功能,并从Postman注册用户。

0 个答案:

没有答案