Skip to content

Commit

Permalink
Read IPs from SSLEngine session
Browse files Browse the repository at this point in the history
When SSLEngine is used IPs cannot be retrieved from the socket or stream
proxies so they are stored into the SSLEngine session.

This is an extension to the standard because the SSLEngine should be
unaware of the underlying communication but it is needed for the audit.
  • Loading branch information
fmarco76 committed Jun 23, 2023
1 parent 9bafa9e commit 4b50c69
Showing 1 changed file with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void alertReceived(SSLAlertEvent event) {

try {
SSLSocket socket = event.getSocket();
JSSEngine engine = event.getEngine();
JSSEngine sslEngine = event.getEngine();

InetAddress clientAddress = null;
InetAddress serverAddress = null;
Expand All @@ -107,8 +107,8 @@ public void alertReceived(SSLAlertEvent event) {
Principal subjectDN = peerCertificate == null ? null : peerCertificate.getSubjectDN();
subjectID = subjectDN == null ? "" : subjectDN.toString();
} else {
if(engine != null) {
JSSSession session = engine.getSession();
if(sslEngine != null) {
JSSSession session = sslEngine.getSession();
if(session != null) {
Certificate[] certs = session.getPeerCertificates();
if(certs != null) {
Expand All @@ -117,6 +117,8 @@ public void alertReceived(SSLAlertEvent event) {
subjectID = cert.getSubjectDN().toString();
}
}
clientIP = session.getRemoteAddr();
serverIP = session.getLocalAddr();
}
}
}
Expand Down Expand Up @@ -151,7 +153,7 @@ public void alertSent(SSLAlertEvent event) {

try {
SSLSocket socket = event.getSocket();
JSSEngine engine = event.getEngine();
JSSEngine sslEngine = event.getEngine();

int description = event.getDescription();
String reason = "serverAlertSent: " + SSLAlertDescription.valueOf(description).toString();
Expand All @@ -173,14 +175,16 @@ public void alertSent(SSLAlertEvent event) {
serverIP = (String)info.get("serverIP");
subjectID = (String)info.get("subjectID");
} else {
if(engine != null) {
JSSSession session = engine.getSession();
if(sslEngine != null) {
JSSSession session = sslEngine.getSession();
if(session != null) {
Certificate[] certs = session.getPeerCertificates();
if(certs != null) {
X509Certificate cert = (X509Certificate) certs[0];
subjectID = cert.getSubjectDN().toString();
}
clientIP = session.getRemoteAddr();
serverIP = session.getLocalAddr();
}
}
}
Expand All @@ -205,8 +209,8 @@ public void alertSent(SSLAlertEvent event) {
subjectID = subjectDN == null ? "" : subjectDN.toString();

} else {
if(engine != null) {
JSSSession session = engine.getSession();
if(sslEngine != null) {
JSSSession session = sslEngine.getSession();
if(session != null) {
Certificate[] certs = session.getPeerCertificates();
if(certs != null) {
Expand All @@ -215,6 +219,8 @@ public void alertSent(SSLAlertEvent event) {
subjectID = cert.getSubjectDN().toString();
}
}
clientIP = session.getRemoteAddr();
serverIP = session.getLocalAddr();
}
}
}
Expand Down Expand Up @@ -250,7 +256,7 @@ public void handshakeCompleted(SSLHandshakeCompletedEvent event) {

try {
SSLSocket socket = event.getSocket();
JSSEngine engine = event.getEngine();
JSSEngine sslEngine = event.getEngine();

InetAddress clientAddress = null;
InetAddress serverAddress = null;
Expand Down Expand Up @@ -278,8 +284,8 @@ public void handshakeCompleted(SSLHandshakeCompletedEvent event) {
info.put("subjectID", subjectID);
socketInfos.put(socket, info);
} else {
if(engine != null) {
JSSSession session = engine.getSession();
if(sslEngine != null) {
JSSSession session = sslEngine.getSession();
if(session != null) {
Certificate[] certs = session.getPeerCertificates();
if(certs != null) {
Expand All @@ -289,6 +295,8 @@ public void handshakeCompleted(SSLHandshakeCompletedEvent event) {
}
}
}
clientIP = session.getRemoteAddr();
serverIP = session.getLocalAddr();
}
}
logger.debug("PKIServerSocketListener: Handshake completed:");
Expand Down

0 comments on commit 4b50c69

Please sign in to comment.