2828import com .wolfssl .WolfSSLJNIException ;
2929import com .wolfssl .WolfSSLSession ;
3030import com .wolfssl .WolfSSLALPNSelectCallback ;
31+ import java .io .IOException ;
3132import java .nio .ByteBuffer ;
3233import java .nio .ReadOnlyBufferException ;
3334import java .util .function .BiFunction ;
3637import java .util .ArrayList ;
3738import java .util .logging .Level ;
3839import java .util .logging .Logger ;
40+ import java .security .cert .CertificateEncodingException ;
3941import javax .net .ssl .SSLEngine ;
4042import javax .net .ssl .SSLEngineResult ;
4143import javax .net .ssl .SSLEngineResult .HandshakeStatus ;
@@ -164,6 +166,14 @@ protected WolfSSLEngine(com.wolfssl.WolfSSLContext ctx,
164166 }
165167 EngineHelper = new WolfSSLEngineHelper (this .ssl , this .authStore ,
166168 this .params );
169+
170+ try {
171+ EngineHelper .LoadKeyAndCertChain (null , this );
172+ } catch (CertificateEncodingException | IOException e ) {
173+ WolfSSLDebug .log (getClass (), WolfSSLDebug .INFO ,
174+ "failed to load private key and/or cert chain" );
175+ throw new WolfSSLException (e );
176+ }
167177 }
168178
169179 /**
@@ -192,6 +202,14 @@ protected WolfSSLEngine(com.wolfssl.WolfSSLContext ctx,
192202 }
193203 EngineHelper = new WolfSSLEngineHelper (this .ssl , this .authStore ,
194204 this .params , port , host );
205+
206+ try {
207+ EngineHelper .LoadKeyAndCertChain (null , this );
208+ } catch (CertificateEncodingException | IOException e ) {
209+ WolfSSLDebug .log (getClass (), WolfSSLDebug .INFO ,
210+ "failed to load private key and/or cert chain" );
211+ throw new WolfSSLException (e );
212+ }
195213 }
196214
197215 /**
@@ -350,6 +368,13 @@ private synchronized int ClosingConnection() throws SocketException {
350368 /* send/recv close_notify as needed */
351369 synchronized (ioLock ) {
352370 ret = ssl .shutdownSSL ();
371+ if (ssl .getError (ret ) == WolfSSL .SSL_ERROR_ZERO_RETURN ) {
372+ /* got close_notify alert, reset ret to 0 to continue
373+ * and let corresponding close_notify to be sent */
374+ WolfSSLDebug .log (getClass (), WolfSSLDebug .INFO ,
375+ "ClosingConnection(), ssl.getError() is ZERO_RETURN" );
376+ ret = 0 ;
377+ }
353378 }
354379 UpdateCloseNotifyStatus ();
355380
@@ -757,6 +782,8 @@ private synchronized int RecvAppData(ByteBuffer[] out, int ofst, int length)
757782 synchronized (ioLock ) {
758783 if (ssl .getShutdown () ==
759784 WolfSSL .SSL_RECEIVED_SHUTDOWN ) {
785+ WolfSSLDebug .log (getClass (), WolfSSLDebug .INFO ,
786+ "RecvAppData(), received shutdown message" );
760787 try {
761788 ret = ClosingConnection ();
762789 if (ret > 0 ) {
@@ -1381,7 +1408,7 @@ public synchronized SSLEngineResult.HandshakeStatus getHandshakeStatus() {
13811408 @ Override
13821409 public synchronized void setUseClientMode (boolean mode ) {
13831410 WolfSSLDebug .log (getClass (), WolfSSLDebug .INFO ,
1384- "entered setUseClientMode()" );
1411+ "entered setUseClientMode(" + mode + " )" );
13851412 EngineHelper .setUseClientMode (mode );
13861413 this .clientModeSet = true ;
13871414 }
@@ -1396,7 +1423,7 @@ public synchronized boolean getUseClientMode() {
13961423 @ Override
13971424 public synchronized void setNeedClientAuth (boolean need ) {
13981425 WolfSSLDebug .log (getClass (), WolfSSLDebug .INFO ,
1399- "entered setNeedClientAuth()" );
1426+ "entered setNeedClientAuth(" + need + " )" );
14001427 EngineHelper .setNeedClientAuth (need );
14011428 }
14021429
@@ -1410,7 +1437,7 @@ public synchronized boolean getNeedClientAuth() {
14101437 @ Override
14111438 public synchronized void setWantClientAuth (boolean want ) {
14121439 WolfSSLDebug .log (getClass (), WolfSSLDebug .INFO ,
1413- "entered setWantClientAuth()" );
1440+ "entered setWantClientAuth(" + want + " )" );
14141441 EngineHelper .setWantClientAuth (want );
14151442 }
14161443
@@ -1424,7 +1451,7 @@ public synchronized boolean getWantClientAuth() {
14241451 @ Override
14251452 public synchronized void setEnableSessionCreation (boolean flag ) {
14261453 WolfSSLDebug .log (getClass (), WolfSSLDebug .INFO ,
1427- "entered setEnableSessionCreation()" );
1454+ "entered setEnableSessionCreation(" + flag + " )" );
14281455 EngineHelper .setEnableSessionCreation (flag );
14291456 }
14301457
0 commit comments