に完成されたことを確認する方法:SSL handshake failures when no data was sent over Twisted TLSConnectionTLSハンドシェイクが。これは、この質問のフォローアップされたツイスト
私はすぐに、クライアントが接続されているように、接続を閉じ、単純なSSLサーバーを実装しています。
私は、OpenSSLでそれをテストしていると私は、このハンドシェイクに失敗しました:
$ openssl s_client -connect localhost:12345
CONNECTED(00000003) 2329:error:140790E5:SSL routines:SSL23_WRITE
:ssl handshake failure:s23_lib.c:188:
問題はTLS.Connection.loseConnection
が行われるための継続的なハンドシェイクを待たずに、ただ、クライアントが切断されていることです。
コールバックはOpenSSL.SSL.Connection.do_handshake
に添付されていましたが、残念ながら私はこれができるかどうか、またはそれをどうやって行うのか分かりません。
TLSハンドシェイクが行われたことをどのようにテストできるかについてのヒントは非常に高く評価されています。どうもありがとう!ここで
は、私は、有効なこれは本当に汚いとない100%を解決するために、今のコード
class ApplicationProtocol(Protocol):
'''Protocol that closes the connection when connection is made.'''
def connectionMade(self):
self.transport.loseConnection()
# Here is a barebone TLS Server
serverFactory = ServerFactory()
serverFactory.protocol = ApplicationProtocol
server_cert_path = 'server.pem'
serverContextFactory = DefaultOpenSSLContextFactory(
privateKeyFileName = server_cert_path,
certificateFileName = server_cert_path,
sslmethod=SSL.SSLv23_METHOD)
tlsFactory = TLSMemoryBIOFactory(serverContextFactory, False, serverFactory)
reactor.listenTCP(12345, tlsFactory)
#reactor.listenSSL(12345, serverFactory, serverContextFactory)
です。
def tls_lose_connection(self):
"""
Monkey patching for TLSMemoryBIOProtocol to wait for handshake to end,
before closing the connection.
Send a TLS close alert and close the underlying connection.
"""
def close_connection():
self.disconnecting = True
if not self._writeBlockedOnRead:
self._tlsConnection.shutdown()
self._flushSendBIO()
self.transport.loseConnection()
# If we don't know if the handshake was done, we wait for a bit
# and the close the connection.
# This is done to avoid closing the connection in the middle of a
# handshake.
if not self._handshakeDone:
reactor.callLater(0.5, close_connection)
else:
close_connection()
TLSMemoryBIOProtocol.loseConnection = tls_lose_connection
ありがとう、非常に:)。 pyOpenSSLのドキュメントから、Context.set_info_callbackはConnectionオブジェクトをコールバックに渡しているようです...このコールバックをフックして、接続上でhandshake_in_progressとhandshake_doneフラグを設定できると思います。 –
@Adi - これを行う方法を見つけましたか? info_callbackがOpenSSL.SSLを取得したことを確認しました。Connectionインスタンスを作成し、ハンドシェイクが完了したことを確認するフラグをテストすることができますが、ConnectionインスタンスからTwisted Protocolインスタンスを取得する準備ができていません。 – Von
@ Von私の現在の汚れたソリューションを追加しました。私はset_info_callbackの値を調べようとしましたが、正しい値が見つからず、ハンドシェークが行われたかどうかを確認できませんでした。 –