我正在尝试转换一些python代码:
def create_socket(self):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if self.ssl:
self.socket = ssl.wrap_socket(self.__socket, ssl_version=ssl.PROTOCOL_SSLv23, cert_reqs=ssl.CERT_NONE)
快速编写代码,并使其无法正常工作。问题似乎是我找不到说cert_reqs = ssl.CERT_NONE
的等效方法这是我到目前为止所拥有的:
let q = DispatchQueue.main
let socket = NWConnection(host: "localhost", port: 2222, using: .tls)
socket.start(queue: q)
socket.stateUpdateHandler = {(newState) in
switch(newState) {
case .ready:
print("ready")
case .waiting(let error):
print("waiting")
print(error)
case .failed(let error):
print("fail")
print(error)
case .setup:
print("setting up")
case .preparing:
print("prep")
case .cancelled:
print("cancelled")
}
}
但是它会产生以下输出:
prep
[BoringSSL] boringssl_context_alert_callback_handler(3747) [C1.1:1[0x7fe5385070e0] Alert level: fatal, description: certificate unknown
[BoringSSL] boringssl_context_error_print(3699) boringssl ctx 0x600000ba0120: 140622469049032:error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl_Sim/boringssl-109.202.1/ssl/handshake.cc:372:
[BoringSSL] boringssl_context_get_error_code(3519) [C1.1:1][0x7fe5385070e0] SSL_AD_CERTIFICATE_UNKNOWN
fail
-9808: Optional(bad certificate format)