读取接口返回什么?

huangapple go评论44阅读模式
英文:

What does the read interface return?

问题

SSL_read()如果接收到的记录不是一个应用程序消息,会返回什么(对于阻塞套接字)?如果它返回非零值,调用者应该如何处理?

我看不出调用者/客户端可以如何处理这三种非应用程序消息,它们似乎更像是 SSL 的内部状态。

如果返回 0 字节,对于阻塞套接字来说,这将会让人困惑。

如果返回大于 0 字节,那么调用者会认为接收到了一个应用程序消息?(调用者不会收到指示记录类型的标志)。

我正在查看源代码,但情况并不清楚。

英文:

The SSL/TLS protocol has four sub-protocols and message types:

  • Application
  • Handshake
  • Change cipher spec
  • Alerts

What does SSL_read() return (for a blocking socket) if the record received was NOT an Application message? And if it does return non-zero, how is the caller supposed to know what to do with it?

I don't see what the caller/client can do with the 3 non-Application messages, they seem more like internal state for SSL.

If it returns 0 bytes, this will be confusing for a blocking socket.

If it returns > 0 bytes, the caller would this an Application message has been received? (there is no flag returned to the caller to indicate the record type).

I am looking at the source code but it's not clear.

答案1

得分: 1

SSL_read只会返回从应用程序记录中检索到的数据。接收到的任何其他消息只会改变SSL会话的内部状态,比如继续SSL握手(如果之前没有完成),保存会话票据以供将来使用或在关闭连接时(在关闭警报时)关闭连接。

如果SSL会话的这种内部更改导致会话被关闭或无效(比如在收到警报时),那么SSL_read将返回错误,并且可以使用SSL_get_error检索到错误的原因。

英文:

SSL_read will only return data retrieved from application records. Any other messages received will only change the internal state of the SSL session, like proceeding with the SSL handshake (if not previously finished), saving session tickets for later use or closing the connection (on shutdown alert).

If this internal change of the SSL session results in the session getting closed or invalid (like when getting an alert), then SSL_read will return with an error and the reason can be retrieved using SSL_get_error.

huangapple
  • 本文由 发表于 2023年2月8日 08:52:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75380421.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定