在 SSL_read() 之前我需要 SSL_accept() 吗?

Do I need SSL_accept() before SSL_read()?

OpenSSL doc中表示:

If necessary, a write function will negotiate a TLS/SSL session, if not already explicitly performed by SSL_connect(3) or SSL_accept(3). If the peer requests a re-negotiation, it will be performed transparently during the write function operation. The behaviour of the write functions depends on the underlying BIO.

我已经打电话给 SSL_set_accept_state()

For the transparent negotiation to succeed, the ssl must have been initialized to client or server mode. This is being done by calling SSL_set_connect_state(3) or SSL_set_accept_state() before the first call to a write function.

那我能少写点代码吗?

So can I write less code?

是的。在某些情况下,如果未显式调用 SSL_accept ,它可能会简化代码。在其他情况下,人们可能希望将初始 TLS 握手与其余代码明确分开,以便更好地控制,例如在通信的哪个阶段会出现哪些错误以及如何处理这些错误。