调试 TLS 握手失败
Debugging TLS handshake failure
我正在尝试通过 fabric-network
nodejs sdk 访问我的对等点。
但是,我在 sdk gateway.connect
期间遇到错误,我在对等容器中找到的日志没有帮助。
即使使用 grpc=debug
日志记录模式,我也只有:
peer0.catie-test | 2020-09-21 13:27:07.731 UTC [core.comm] ServerHandshake -> ERRO 087 TLS handshake failed with error remote error: tls: handshake failure server=PeerServer remoteaddress=172.17.0.1:49918
peer0.catie-test | 2020-09-21 13:27:07.731 UTC [grpc] handleRawConn -> DEBU 088 grpc: Server.Serve failed to complete security handshake from "172.17.0.1:49918": remote error: tls: handshake failure
有什么方法可以获得更多有用的日志吗?例如,我想知道哪个密钥用于 TLS 握手检查。
编辑更多信息: 配置文件和 TLS 验证
我的对等端配置了带有环境变量的 TLS:
CORE_PEER_TLS_ENABLED=true
CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/crypto/peer/tls-msp/keystore/key.pem
CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/crypto/peer/tls-msp/signcerts/cert.pem
CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/crypto/peer/tls-msp/tlscacerts/tlsca.catie-test-cert.pem
我在客户端拥有正确的同级 tlscacert,因为同级和客户端的输出是相同的:
cat /etc/hyperledger/crypto/peer/tls-msp/tlscacerts/tlsca.catie-test-cert.pem # From the peer, output ZTd/o8LLw== at the end
cat /tmp/fabric-start-catie-test/building/artifacts/peer0.catie-test-crypto/tls-msp/tlscacerts/tlsca.catie-test-cert.pem # From the client, output ZTd/o8LLw== at the end
对端tlscacert的路径填写在客户端连接-profile.json :
"peers": {
"peer0.catie-test": {
"tlsCACerts": {
"path": "/tmp/fabric-start-catie-test/building/artifacts/peer0.catie-test-crypto/tls-msp/tlscacerts/tlsca.catie-test-cert.pem"
},
"grpcOptions":{
"ssl-target-name-override": "172.17.0.7",
"grpc.keepalive_time_ms": 10000
},
"url": "grpcs://172.17.0.4:7051",
"eventUrl": "grpcs://172.17.0.4:7053"
}
}
而且我还检查了 tlsCAcert 是生成我的对等证书的那个:
openssl verify -CAfile $CORE_PEER_TLS_ROOTCERT_FILE $CORE_PEER_TLS_CERT_FILE # Output : /etc/hyperledger/crypto/peer/tls-msp/signcerts/cert.pem: OK
编辑 2: Grpc 选项,对端名称而不是 IP 和客户端日志
还尝试将 grpcOptions
添加到 connection-profile.json
的 peer
部分(请参阅上面更新的段落),但它没有任何改变。
还尝试将对等名称添加到我的 /etc/hosts
以通过其名称而不是其 IP 访问我的对等。它使警告消失,但没有解决我的问题,我更喜欢在我的脚本中使用 IP。
这是 nodejs sdk 客户端的日志,以防它有助于诊断问题,但它只说 Endorser must be connected
我认为是,因为它到达我的对等方,因为我有这个 TLS我对等方的日志中出现错误。
(node:59350) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permitted by RFC 6066. This will be ignored in a future version.
2020-09-23T06:42:20.704Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.catie-test, url:grpcs://172.17.0.7:7051, connected:false, connectAttempted:true
2020-09-23T06:42:20.705Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.catie-test url:grpcs://172.17.0.7:7051 timeout:3000
2020-09-23T06:42:20.708Z - error: [NetworkConfig]: buildPeer - Unable to connect to the endorser peer0.catie-test due to Error: Failed to connect before the deadline on Endorser- name: peer0.catie-test, url:grpcs://172.17.0.7:7051, connected:false, connectAttempted:true
at checkState (/home/rqueraud/CATIE/Myrmica/myrmica-start/node_modules/@grpc/grpc-js/build/src/client.js:69:26)
at Timeout._onTimeout (/home/rqueraud/CATIE/Myrmica/myrmica-start/node_modules/@grpc/grpc-js/build/src/channel.js:292:17)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) {
connectFailed: true
}
(node:59350) UnhandledPromiseRejectionWarning: Error: Endorser must be connected
at Channel.addEndorser (/home/rqueraud/CATIE/Myrmica/myrmica-start/node_modules/fabric-common/lib/Channel.js:259:10)
at buildChannel (/home/rqueraud/CATIE/Myrmica/myrmica-start/node_modules/fabric-network/lib/impl/ccp/networkconfig.js:50:21)
at Object.loadFromConfig (/home/rqueraud/CATIE/Myrmica/myrmica-start/node_modules/fabric-network/lib/impl/ccp/networkconfig.js:34:19)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Gateway.connect (/home/rqueraud/CATIE/Myrmica/myrmica-start/node_modules/fabric-network/lib/gateway.js:279:13)
at async queryChaincode (/home/rqueraud/CATIE/Myrmica/myrmica-start/test/chaincode-sdk/index.js:41:5)
at async /home/rqueraud/CATIE/Myrmica/myrmica-start/test/chaincode-sdk/index.js:57:5
编辑 3 : Docker IPs ?尝试使用 EC2 实例。
正如@Urko 提到的,我的节点实际上是 docker 容器 运行ning docker-in-docker (dind) 图像。在这些容器中还有一些其他容器 运行 连接超级账本节点、cli、...图像。
我从主机访问它们,这也是我 运行 fabric sdk nodejs 客户端所在的主机。我无法通过它们的容器名称访问它们,我认为这只能在 docker-compose 配置中进行,不是吗?我已经尝试(参见上面的编辑 2)将他们的名字添加到我的 /etc/hosts 以通过名称而不是 IP 联系他们,但它没有改变任何东西。
然而,由于我的网络启动是脚本化的,所以这次我在 AWS 中使用 docker-machine 而不是 dind docker 容器来部署它,因此这些是可在 Internet 上访问的真实实例。但我仍然遇到同样的错误,这是来自对等方的日志,您可以在其中看到这是来自 public IP :
2020-09-24 08:32:57.653 UTC [core.comm] ServerHandshake -> ERRO 0d7 TLS handshake failed with error remote error: tls: handshake failure server=PeerServer remoteaddress=31.36.26.4:35462
您尝试在对等服务器中调用 gRPC,其中对等服务器使用其 TLS 系统进行保护。因此,如果您未能提供有效的 TLS 证书,服务器 tls 握手将失败,您将无法成功建立连接。
请检查您的网络配置文件是否正确开发,同时检查您使用的 TLS 证书是否与用于 运行 对等服务器的 TLS 证书相同,并且您的 TLS 证书路径是否正确。
似乎已将与您的对等点的连接定义为受 TLS 协议保护。因此,您可以配置对等配置以了解您在 TLS 中使用的证书。
当您使用此协议连接到任何服务器时,各方之间的通信是使用服务器证书加密的(在这种情况下,对等点将是服务器)。因此,您需要将客户端配置为信任尚未用于颁发对等 TLS 证书的根 CA 的服务器。
客户端是您使用 SDK 的地方,因此,您应该将其配置为信任 Peer TLS 证书。当您配置与区块链节点(同级和订购者)的连接时,您将定义它们的方向以及它们的 TLS 证书。这是一个示例,您可以在以下 link 中找到。在那里,您必须定义 tlsCACerts 参数的值:
orderers:
orderer.example.com:
url: grpcs://localhost:7050
grpcOptions:
ssl-target-name-override: orderer.example.com
grpc-max-send-message-length: 4194304
tlsCACerts:
path: test/fixtures/channel/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tlscacerts/example.com-cert.pem
peers:
peer0.org1.example.com:
url: grpcs://localhost:7051
grpcOptions:
ssl-target-name-override: peer0.org1.example.com
grpc.keepalive_time_ms: 600000
tlsCACerts:
path: test/fixtures/channel/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tlscacerts/org1.example.com-cert.pem
----- 已编辑----
此外,您必须检查 ssl-target-name-override
参数的值。它应该与您的节点名称相同,正如您在示例文件中看到的那样
----- 已编辑----
你为什么要使用这些 IP?!我知道这些 IP 是 Docker 网络的内部 IP,因此您不应使用它们。您可以尝试使用您的容器名称而不是 docker 网络 IP 吗?
----- 已编辑----
您能否验证您的 ca-server
配置文件并检查 tls
是否设置为 true?
我正在尝试通过 fabric-network
nodejs sdk 访问我的对等点。
但是,我在 sdk gateway.connect
期间遇到错误,我在对等容器中找到的日志没有帮助。
即使使用 grpc=debug
日志记录模式,我也只有:
peer0.catie-test | 2020-09-21 13:27:07.731 UTC [core.comm] ServerHandshake -> ERRO 087 TLS handshake failed with error remote error: tls: handshake failure server=PeerServer remoteaddress=172.17.0.1:49918
peer0.catie-test | 2020-09-21 13:27:07.731 UTC [grpc] handleRawConn -> DEBU 088 grpc: Server.Serve failed to complete security handshake from "172.17.0.1:49918": remote error: tls: handshake failure
有什么方法可以获得更多有用的日志吗?例如,我想知道哪个密钥用于 TLS 握手检查。
编辑更多信息: 配置文件和 TLS 验证
我的对等端配置了带有环境变量的 TLS:
CORE_PEER_TLS_ENABLED=true
CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/crypto/peer/tls-msp/keystore/key.pem
CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/crypto/peer/tls-msp/signcerts/cert.pem
CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/crypto/peer/tls-msp/tlscacerts/tlsca.catie-test-cert.pem
我在客户端拥有正确的同级 tlscacert,因为同级和客户端的输出是相同的:
cat /etc/hyperledger/crypto/peer/tls-msp/tlscacerts/tlsca.catie-test-cert.pem # From the peer, output ZTd/o8LLw== at the end
cat /tmp/fabric-start-catie-test/building/artifacts/peer0.catie-test-crypto/tls-msp/tlscacerts/tlsca.catie-test-cert.pem # From the client, output ZTd/o8LLw== at the end
对端tlscacert的路径填写在客户端连接-profile.json :
"peers": {
"peer0.catie-test": {
"tlsCACerts": {
"path": "/tmp/fabric-start-catie-test/building/artifacts/peer0.catie-test-crypto/tls-msp/tlscacerts/tlsca.catie-test-cert.pem"
},
"grpcOptions":{
"ssl-target-name-override": "172.17.0.7",
"grpc.keepalive_time_ms": 10000
},
"url": "grpcs://172.17.0.4:7051",
"eventUrl": "grpcs://172.17.0.4:7053"
}
}
而且我还检查了 tlsCAcert 是生成我的对等证书的那个:
openssl verify -CAfile $CORE_PEER_TLS_ROOTCERT_FILE $CORE_PEER_TLS_CERT_FILE # Output : /etc/hyperledger/crypto/peer/tls-msp/signcerts/cert.pem: OK
编辑 2: Grpc 选项,对端名称而不是 IP 和客户端日志
还尝试将 grpcOptions
添加到 connection-profile.json
的 peer
部分(请参阅上面更新的段落),但它没有任何改变。
还尝试将对等名称添加到我的 /etc/hosts
以通过其名称而不是其 IP 访问我的对等。它使警告消失,但没有解决我的问题,我更喜欢在我的脚本中使用 IP。
这是 nodejs sdk 客户端的日志,以防它有助于诊断问题,但它只说 Endorser must be connected
我认为是,因为它到达我的对等方,因为我有这个 TLS我对等方的日志中出现错误。
(node:59350) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permitted by RFC 6066. This will be ignored in a future version.
2020-09-23T06:42:20.704Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.catie-test, url:grpcs://172.17.0.7:7051, connected:false, connectAttempted:true
2020-09-23T06:42:20.705Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.catie-test url:grpcs://172.17.0.7:7051 timeout:3000
2020-09-23T06:42:20.708Z - error: [NetworkConfig]: buildPeer - Unable to connect to the endorser peer0.catie-test due to Error: Failed to connect before the deadline on Endorser- name: peer0.catie-test, url:grpcs://172.17.0.7:7051, connected:false, connectAttempted:true
at checkState (/home/rqueraud/CATIE/Myrmica/myrmica-start/node_modules/@grpc/grpc-js/build/src/client.js:69:26)
at Timeout._onTimeout (/home/rqueraud/CATIE/Myrmica/myrmica-start/node_modules/@grpc/grpc-js/build/src/channel.js:292:17)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) {
connectFailed: true
}
(node:59350) UnhandledPromiseRejectionWarning: Error: Endorser must be connected
at Channel.addEndorser (/home/rqueraud/CATIE/Myrmica/myrmica-start/node_modules/fabric-common/lib/Channel.js:259:10)
at buildChannel (/home/rqueraud/CATIE/Myrmica/myrmica-start/node_modules/fabric-network/lib/impl/ccp/networkconfig.js:50:21)
at Object.loadFromConfig (/home/rqueraud/CATIE/Myrmica/myrmica-start/node_modules/fabric-network/lib/impl/ccp/networkconfig.js:34:19)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Gateway.connect (/home/rqueraud/CATIE/Myrmica/myrmica-start/node_modules/fabric-network/lib/gateway.js:279:13)
at async queryChaincode (/home/rqueraud/CATIE/Myrmica/myrmica-start/test/chaincode-sdk/index.js:41:5)
at async /home/rqueraud/CATIE/Myrmica/myrmica-start/test/chaincode-sdk/index.js:57:5
编辑 3 : Docker IPs ?尝试使用 EC2 实例。
正如@Urko 提到的,我的节点实际上是 docker 容器 运行ning docker-in-docker (dind) 图像。在这些容器中还有一些其他容器 运行 连接超级账本节点、cli、...图像。
我从主机访问它们,这也是我 运行 fabric sdk nodejs 客户端所在的主机。我无法通过它们的容器名称访问它们,我认为这只能在 docker-compose 配置中进行,不是吗?我已经尝试(参见上面的编辑 2)将他们的名字添加到我的 /etc/hosts 以通过名称而不是 IP 联系他们,但它没有改变任何东西。
然而,由于我的网络启动是脚本化的,所以这次我在 AWS 中使用 docker-machine 而不是 dind docker 容器来部署它,因此这些是可在 Internet 上访问的真实实例。但我仍然遇到同样的错误,这是来自对等方的日志,您可以在其中看到这是来自 public IP :
2020-09-24 08:32:57.653 UTC [core.comm] ServerHandshake -> ERRO 0d7 TLS handshake failed with error remote error: tls: handshake failure server=PeerServer remoteaddress=31.36.26.4:35462
您尝试在对等服务器中调用 gRPC,其中对等服务器使用其 TLS 系统进行保护。因此,如果您未能提供有效的 TLS 证书,服务器 tls 握手将失败,您将无法成功建立连接。
请检查您的网络配置文件是否正确开发,同时检查您使用的 TLS 证书是否与用于 运行 对等服务器的 TLS 证书相同,并且您的 TLS 证书路径是否正确。
似乎已将与您的对等点的连接定义为受 TLS 协议保护。因此,您可以配置对等配置以了解您在 TLS 中使用的证书。
当您使用此协议连接到任何服务器时,各方之间的通信是使用服务器证书加密的(在这种情况下,对等点将是服务器)。因此,您需要将客户端配置为信任尚未用于颁发对等 TLS 证书的根 CA 的服务器。
客户端是您使用 SDK 的地方,因此,您应该将其配置为信任 Peer TLS 证书。当您配置与区块链节点(同级和订购者)的连接时,您将定义它们的方向以及它们的 TLS 证书。这是一个示例,您可以在以下 link 中找到。在那里,您必须定义 tlsCACerts 参数的值:
orderers:
orderer.example.com:
url: grpcs://localhost:7050
grpcOptions:
ssl-target-name-override: orderer.example.com
grpc-max-send-message-length: 4194304
tlsCACerts:
path: test/fixtures/channel/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tlscacerts/example.com-cert.pem
peers:
peer0.org1.example.com:
url: grpcs://localhost:7051
grpcOptions:
ssl-target-name-override: peer0.org1.example.com
grpc.keepalive_time_ms: 600000
tlsCACerts:
path: test/fixtures/channel/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tlscacerts/org1.example.com-cert.pem
----- 已编辑----
此外,您必须检查 ssl-target-name-override
参数的值。它应该与您的节点名称相同,正如您在示例文件中看到的那样
----- 已编辑----
你为什么要使用这些 IP?!我知道这些 IP 是 Docker 网络的内部 IP,因此您不应使用它们。您可以尝试使用您的容器名称而不是 docker 网络 IP 吗?
----- 已编辑----
您能否验证您的 ca-server
配置文件并检查 tls
是否设置为 true?