Skip to content

Commit 5a66faf

Browse files
committed
Return X500Principal from getPeerPrincipal() and getLocalPrincipal()
1 parent 276eff7 commit 5a66faf

6 files changed

Lines changed: 26 additions & 48 deletions

File tree

src/java/com/wolfssl/provider/jsse/WolfSSLEngine.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,7 @@ protected synchronized void cacheRequestedServerNamesFromNetData() {
321321
List<SNIServerName> names;
322322
WolfSSLImplementSSLSession session;
323323

324-
if (this.engineHelper == null ||
325-
this.engineHelper.getUseClientMode()) {
324+
if (this.engineHelper == null || this.engineHelper.getUseClientMode()) {
326325
return;
327326
}
328327

@@ -1199,8 +1198,7 @@ private synchronized int RecvAppData(ByteBuffer[] out, int ofst, int length)
11991198
default:
12001199
/* Throw SSLHandshakeException if handshake not finished */
12011200
if (!this.handshakeFinished) {
1202-
SSLHandshakeException hse =
1203-
new SSLHandshakeException(
1201+
SSLHandshakeException hse = new SSLHandshakeException(
12041202
"SSL/TLS handshake error in read: " + ret +
12051203
" , err = " + err);
12061204
if (this.engineHelper != null) {
@@ -1482,8 +1480,7 @@ else if (hs == SSLEngineResult.HandshakeStatus.NEED_WRAP &&
14821480
for (int pos = 0;
14831481
pos < this.pendingAppDataLen;) {
14841482
if (idx2 + ofst >= length) break;
1485-
int space =
1486-
out[idx2 + ofst].remaining();
1483+
int space = out[idx2 + ofst].remaining();
14871484
if (space == 0) { idx2++; continue; }
14881485
int sz2 = Math.min(space,
14891486
this.pendingAppDataLen - pos);

src/java/com/wolfssl/provider/jsse/WolfSSLEngineHelper.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,7 @@ private boolean isTls13CipherSuite(String suite) {
866866
}
867867

868868
return suite.startsWith("TLS_AES_") ||
869-
suite.startsWith("TLS_CHACHA20_") ||
870-
suite.startsWith("TLS_SM4_");
869+
suite.startsWith("TLS_CHACHA20_") || suite.startsWith("TLS_SM4_");
871870
}
872871

873872
private String[] getEffectiveProtocolsForCiphers(String[] protocols,
@@ -948,8 +947,7 @@ else if ("TLSv1.2".equals(proto) || "DTLSv1.2".equals(proto) ||
948947
return protocols;
949948
}
950949

951-
private void applyConfiguredCipherProtocolSettings()
952-
throws SSLException {
950+
private void applyConfiguredCipherProtocolSettings() throws SSLException {
953951

954952
String[] suites;
955953
String[] protocols;
@@ -1081,8 +1079,7 @@ private void setLocalServerNames(SSLEngine engine) {
10811079
/* SSLEngine(host, port) should send SNI by default if no explicit
10821080
* server names were configured and SNI extension is enabled. */
10831081
boolean isEngineConnectionWithHost = this.clientMode &&
1084-
engine != null &&
1085-
this.hostname != null &&
1082+
engine != null && this.hostname != null &&
10861083
this.params.getServerNames() == null;
10871084

10881085
/* Enable SNI if explicitly requested via property, if

src/java/com/wolfssl/provider/jsse/WolfSSLImplementSSLSession.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -673,12 +673,11 @@ public Certificate[] getLocalCertificates() {
673673
public synchronized Principal getPeerPrincipal()
674674
throws SSLPeerUnverifiedException {
675675

676-
/* Use standard Java X509Certificate.getSubjectDN()
677-
* for X500Name equals() compatibility */
676+
/* Return X500Principal for proper equals() symmetry */
678677
Certificate[] certs = getPeerCertificates();
679678
if (certs != null && certs.length > 0 &&
680679
certs[0] instanceof X509Certificate) {
681-
return ((X509Certificate) certs[0]).getSubjectDN();
680+
return ((X509Certificate) certs[0]).getSubjectX500Principal();
682681
}
683682
throw new SSLPeerUnverifiedException("No peer certificate");
684683
}
@@ -699,7 +698,7 @@ public Principal getLocalPrincipal() {
699698
if (certs.length > 0){
700699
/* When chain of certificates exceeds one,
701700
* the user certifcate is the first */
702-
localPrincipal = certs[0].getSubjectDN();
701+
localPrincipal = certs[0].getSubjectX500Principal();
703702
}
704703

705704
/* free native resources earlier than garbage collection if
@@ -1137,8 +1136,7 @@ public synchronized List<SNIServerName> getRequestedServerNames()
11371136
byte[] sniRequestArr = null;
11381137

11391138
if (this.ssl == null) {
1140-
if (this.sniServerNames != null &&
1141-
!this.sniServerNames.isEmpty()) {
1139+
if (this.sniServerNames != null && !this.sniServerNames.isEmpty()) {
11421140
return Collections.unmodifiableList(
11431141
new ArrayList<SNIServerName>(this.sniServerNames));
11441142
}

src/java/com/wolfssl/provider/jsse/WolfSSLInternalVerifyCb.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,7 @@ else if (sock != null) {
310310
}
311311
} catch (Exception e) {
312312
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
313-
() -> "Hostname verification error: " +
314-
e.getMessage());
313+
() -> "Hostname verification error: " + e.getMessage());
315314
this.verifyException = e;
316315
return 0;
317316
} finally {

src/test/com/wolfssl/provider/jsse/test/WolfSSLEngineTest.java

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,10 +2629,9 @@ public X509Certificate[] getAcceptedIssuers() {
26292629

26302630
cliToSer.flip();
26312631
if (cliToSer.hasRemaining() &&
2632-
(server.getHandshakeStatus() ==
2633-
HandshakeStatus.NEED_UNWRAP ||
2632+
(server.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP ||
26342633
server.getHandshakeStatus() ==
2635-
HandshakeStatus.NOT_HANDSHAKING)) {
2634+
HandshakeStatus.NOT_HANDSHAKING)) {
26362635
try {
26372636
server.unwrap(cliToSer, sink);
26382637
} catch (SSLException e) {
@@ -2651,10 +2650,9 @@ public X509Certificate[] getAcceptedIssuers() {
26512650

26522651
serToCli.flip();
26532652
if (serToCli.hasRemaining() &&
2654-
(client.getHandshakeStatus() ==
2655-
HandshakeStatus.NEED_UNWRAP ||
2653+
(client.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP ||
26562654
client.getHandshakeStatus() ==
2657-
HandshakeStatus.NOT_HANDSHAKING)) {
2655+
HandshakeStatus.NOT_HANDSHAKING)) {
26582656
try {
26592657
client.unwrap(serToCli, sink);
26602658
} catch (SSLHandshakeException e) {
@@ -2701,8 +2699,7 @@ public void testCloseNotifyTLS13HandshakeStatus()
27012699
}
27022700

27032701
SSLEngine server = this.ctx.createSSLEngine();
2704-
SSLEngine client =
2705-
this.ctx.createSSLEngine("wolfSSL test", 11111);
2702+
SSLEngine client = this.ctx.createSSLEngine("wolfSSL test", 11111);
27062703

27072704
server.setUseClientMode(false);
27082705
server.setNeedClientAuth(false);
@@ -2794,8 +2791,7 @@ public void testBufferUnderflowPartialRecord()
27942791

27952792
this.ctx = tf.createSSLContext("TLS", engineProvider);
27962793
SSLEngine server = this.ctx.createSSLEngine();
2797-
SSLEngine client =
2798-
this.ctx.createSSLEngine("wolfSSL test", 11111);
2794+
SSLEngine client = this.ctx.createSSLEngine("wolfSSL test", 11111);
27992795

28002796
server.setUseClientMode(false);
28012797
server.setNeedClientAuth(false);
@@ -2812,16 +2808,13 @@ public void testBufferUnderflowPartialRecord()
28122808
}
28132809

28142810
/* Client wraps some application data */
2815-
String testData =
2816-
"Hello from client for underflow test";
2817-
ByteBuffer appBuf =
2818-
ByteBuffer.wrap(testData.getBytes());
2811+
String testData = "Hello from client for underflow test";
2812+
ByteBuffer appBuf = ByteBuffer.wrap(testData.getBytes());
28192813
ByteBuffer netBuf = ByteBuffer.allocateDirect(
28202814
client.getSession().getPacketBufferSize());
28212815

28222816
SSLEngineResult result = client.wrap(appBuf, netBuf);
2823-
if (result.getStatus() !=
2824-
SSLEngineResult.Status.OK) {
2817+
if (result.getStatus() != SSLEngineResult.Status.OK) {
28252818
error("\t... failed");
28262819
fail("wrap failed: " + result.getStatus());
28272820
}
@@ -2835,22 +2828,19 @@ public void testBufferUnderflowPartialRecord()
28352828

28362829
/* Create a partial record (only first 3 bytes of the
28372830
* TLS record header, less than the 5-byte header) */
2838-
ByteBuffer partialBuf =
2839-
ByteBuffer.allocateDirect(3);
2831+
ByteBuffer partialBuf = ByteBuffer.allocateDirect(3);
28402832
byte[] partial = new byte[3];
28412833
netBuf.get(partial);
28422834
partialBuf.put(partial);
28432835
partialBuf.flip();
28442836

28452837
ByteBuffer outBuf = ByteBuffer.allocate(
2846-
server.getSession()
2847-
.getApplicationBufferSize());
2838+
server.getSession().getApplicationBufferSize());
28482839

28492840
/* Unwrap partial record: BUFFER_UNDERFLOW expected */
28502841
result = server.unwrap(partialBuf, outBuf);
28512842

2852-
if (result.getStatus() !=
2853-
SSLEngineResult.Status.BUFFER_UNDERFLOW) {
2843+
if (result.getStatus() != SSLEngineResult.Status.BUFFER_UNDERFLOW) {
28542844
error("\t... failed");
28552845
fail("expected BUFFER_UNDERFLOW for partial " +
28562846
"TLS record, got " + result.getStatus());
@@ -2878,8 +2868,7 @@ public void testBufferOverflowSmallOutput()
28782868

28792869
this.ctx = tf.createSSLContext("TLS", engineProvider);
28802870
SSLEngine server = this.ctx.createSSLEngine();
2881-
SSLEngine client =
2882-
this.ctx.createSSLEngine("wolfSSL test", 11111);
2871+
SSLEngine client = this.ctx.createSSLEngine("wolfSSL test", 11111);
28832872

28842873
server.setUseClientMode(false);
28852874
server.setNeedClientAuth(false);
@@ -2917,8 +2906,7 @@ public void testBufferOverflowSmallOutput()
29172906

29182907
result = server.unwrap(netCopy, tinyOut);
29192908

2920-
if (result.getStatus() !=
2921-
SSLEngineResult.Status.BUFFER_OVERFLOW) {
2909+
if (result.getStatus() != SSLEngineResult.Status.BUFFER_OVERFLOW) {
29222910
error("\t... failed");
29232911
fail("expected BUFFER_OVERFLOW for small output buffer, " +
29242912
"got " + result.getStatus());

src/test/com/wolfssl/provider/jsse/test/WolfSSLTestFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,7 @@ public int CloseConnection(SSLEngine server, SSLEngine client,
870870
if (!s.toString().equals("NEED_WRAP") ||
871871
!result.getStatus().name().equals("CLOSED") ) {
872872
throw new SSLException(
873-
"Bad status: HS=" + s +
874-
" status=" + result.getStatus());
873+
"Bad status: HS=" + s + " status=" + result.getStatus());
875874
}
876875

877876
/* server wraps its own close_notify */

0 commit comments

Comments
 (0)