Skip to content

Commit 9158542

Browse files
committed
Add javadoc to SSLEngineHelper
1 parent 546eeca commit 9158542

File tree

1 file changed

+37
-0
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl

1 file changed

+37
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLEngineHelper.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,51 @@
6464
import com.oracle.truffle.api.CompilerDirectives;
6565
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6666

67+
/**
68+
* This class implements equivalents of OpenSSL transport functions ({@code SSL_read} etc) on top of
69+
* JDK's {@link SSLEngine}. It takes care of the handshake, packeting, network and application data
70+
* buffering and network or memory buffer IO. In addition to what the OpenSSL functions would do, it
71+
* also handles Python-specific error handling, non-blocking IO and socket timeouts.
72+
*/
6773
public class SSLEngineHelper {
6874

6975
private static final ByteBuffer EMPTY_BUFFER = ByteBuffer.allocate(0);
7076
private static final int TLS_HEADER_SIZE = 5;
7177

78+
/**
79+
* Equivalent of {@code SSL_write}. Attempts to transmit all the data in the supplied buffer
80+
* into given {@link PSSLSocket} (which can be backed by a memory buffer).
81+
*
82+
* Errors are wrapped into Python exceptions. Requests for IO in non-blocking modes are
83+
* indicated using Python exceptions ({@code SSLErrorWantRead}, {@code SSLErrorWantWrite}).
84+
*/
7285
@TruffleBoundary
7386
public static void write(PNodeWithRaise node, PSSLSocket socket, ByteBuffer input) {
7487
loop(node, socket, input, EMPTY_BUFFER, Operation.WRITE);
7588
}
7689

90+
/**
91+
* Equivalent of {@code SSL_read}. Attempts to read bytes from the {@link PSSLSocket} (which can
92+
* be backed by a memory buffer) into given buffer. Will read at most the data of one TLS
93+
* packet. Decrypted but not read data is buffered on the socket and returned by the next call.
94+
* Empty output buffer after the call signifies the peer closed the connection cleanly.
95+
*
96+
* Errors are wrapped into Python exceptions. Requests for IO in non-blocking modes are
97+
* indicated using Python exceptions ({@code SSLErrorWantRead}, {@code SSLErrorWantWrite}).
98+
*/
7799
@TruffleBoundary
78100
public static void read(PNodeWithRaise node, PSSLSocket socket, ByteBuffer target) {
79101
loop(node, socket, EMPTY_BUFFER, target, Operation.READ);
80102
}
81103

104+
/**
105+
* Equivalent of {@code SSL_do_handshake}. Initiate a handshake if one has not been initiated
106+
* already. Becomes a no-op after the initial handshake is done, i.e. cannot be used to perform
107+
* renegotiation.
108+
*
109+
* Errors are wrapped into Python exceptions. Requests for IO in non-blocking modes are
110+
* indicated using Python exceptions ({@code SSLErrorWantRead}, {@code SSLErrorWantWrite}).
111+
*/
82112
@TruffleBoundary
83113
public static void handshake(PNodeWithRaise node, PSSLSocket socket) {
84114
if (!socket.isHandshakeComplete()) {
@@ -92,6 +122,13 @@ public static void handshake(PNodeWithRaise node, PSSLSocket socket) {
92122
}
93123
}
94124

125+
/**
126+
* Equivalent of {@code SSL_do_shutdown}. Initiates a duplex close of the TLS connection - sends
127+
* a close_notify message and tries to receive a close_notify from the peer.
128+
*
129+
* Errors are wrapped into Python exceptions. Requests for IO in non-blocking modes are
130+
* indicated using Python exceptions ({@code SSLErrorWantRead}, {@code SSLErrorWantWrite}).
131+
*/
95132
@TruffleBoundary
96133
public static void shutdown(PNodeWithRaise node, PSSLSocket socket) {
97134
socket.getEngine().closeOutbound();

0 commit comments

Comments
 (0)