Skip to content

Commit

Permalink
Merge pull request #217 from cconlon/SSLSocketEndOfStreamRead
Browse files Browse the repository at this point in the history
JSSE: return end of stream in WolfSSLInputStream.read() on SOCKET_ERROR_E
  • Loading branch information
JacobBarthelmeh authored Sep 12, 2024
2 parents 7ee9c7d + 1b3c748 commit a9c28d7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions native/com_wolfssl_WolfSSL.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/java/com/wolfssl/WolfSSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ public enum TLS_VERSION {
public static final int SSL_ERROR_WANT_X509_LOOKUP = 83;
/** I/O error, zero return, no more data */
public static final int SSL_ERROR_ZERO_RETURN = 6;
/** Generatl SSL error */
/** General SSL error */
public static final int SSL_ERROR_SSL = 85;
/** Error state on socket */
public static final int SOCKET_ERROR_E = -308;
/** Received fatal alert error */
public static final int FATAL_ERROR = -313;
/** Peer closed socket */
Expand Down
22 changes: 16 additions & 6 deletions src/java/com/wolfssl/provider/jsse/WolfSSLSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -2514,12 +2514,22 @@ public synchronized int read(byte[] b, int off, int len)
/* other errors besides end of stream or WANT_READ
* are treated as I/O errors and throw an exception */
String errStr = WolfSSL.getErrorString(err);
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
"Native wolfSSL_read() error: " + errStr +
" (error code: " + err + ")");
throw new IOException("Native wolfSSL_read() " +
"error: " + errStr +
" (error code: " + err + ")");
if (err == WolfSSL.SOCKET_ERROR_E) {
/* Socket error, indicate to caller by returning
* end of stream */
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
"Native wolfSSL_read() error: " + errStr +
" (error code: " + err + "), end of stream");
return -1;

} else {
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
"Native wolfSSL_read() error: " + errStr +
" (error code: " + err + ")");
throw new IOException("Native wolfSSL_read() " +
"error: " + errStr +
" (error code: " + err + ")");
}
}

} catch (SocketException e) {
Expand Down

0 comments on commit a9c28d7

Please sign in to comment.