Beryl::TLS::Socket
Inherits IO::Buffered < IO < Reference < Object
A TLS 1.3 connection over another IO, shaped like
OpenSSL::SSL::Socket: an IO with IO::Buffered, and the same
accessors (alpn_protocol, cipher, tls_version, hostname,
peer_certificate).
tcp = TCPSocket.new("example.com", 443)
tls = Beryl::TLS::Socket::Client.new(tcp, hostname: "example.com", sync_close: true)
tls << "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n"
tls.flush
tls.gets_to_end
Reads and writes may run in two fibers at once (one each). A failure sends the alert the error names before it is raised.
The socket keeps no IO::Buffered buffers of its own. Reads (read,
peek, gets) are served from the plaintext of the record last
opened, so read_buffering? has no effect. Writes gather, up to one
record's worth, in a buffer that starts at the size of the first write
and grows with what is written, and are sealed into a record at
flush, when that record is full, or at close.
Instance methods
Whether close has been called. Reads and writes after it raise
IO::Error ("Closed stream"), as on any closed IO, and a pool or a
driver that checks closed? (as OpenSSL::SSL::Socket answers it)
sees the connection is gone.
Returns keying material exported from the connection (RFC 9846 §7.5), e.g. for channel binding.
Whether reads and writes raise a TLS failure as ConnectionFailed
(an IO::Error) instead of the TLS::Error itself. A server that
treats IO::Error as the end of a connection, as HTTP::Server
does, then ends a failed handshake quietly; Server turns it on for
the sockets it accepts.
Whether reads and writes raise a TLS failure as ConnectionFailed
(an IO::Error) instead of the TLS::Error itself. A server that
treats IO::Error as the end of a connection, as HTTP::Server
does, then ends a failed handshake quietly; Server turns it on for
the sockets it accepts.
Returns the plaintext waiting to be read, reading the next record when none is waiting; empty at the end of the stream.
Sends close_notify (once the handshake is done), wipes the
connection's secrets, then closes the IO below when sync_close?.
Closing again does nothing.
Reads at most slice.size bytes from the wrapped IO into slice.
Returns the number of bytes read.
TODO: Add return type restriction Int32
Writes slice entirely into the wrapped IO.
TODO: Add return type restriction Nil
Sends a KeyUpdate and moves to the next sending key (§4.6.3). With request_peer_update the peer is asked to update its key too.
Gathers slice with what was written before it, sealing the gathered plaintext into a record first when slice would not fit in the same record.