View Javadoc
1   /*
2    * Copyright 2014 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty5.handler.ssl;
17  
18  import javax.net.ssl.SSLEngine;
19  import javax.net.ssl.SSLEngineResult;
20  import javax.net.ssl.SSLEngineResult.HandshakeStatus;
21  import javax.net.ssl.SSLException;
22  import javax.net.ssl.SSLParameters;
23  import javax.net.ssl.SSLSession;
24  import java.nio.ByteBuffer;
25  
26  class JdkSslEngine extends SSLEngine implements ApplicationProtocolAccessor {
27      private final SSLEngine engine;
28      private volatile String applicationProtocol;
29  
30      JdkSslEngine(SSLEngine engine) {
31          this.engine = engine;
32      }
33  
34      @Override
35      public String getNegotiatedApplicationProtocol() {
36          return applicationProtocol;
37      }
38  
39      void setNegotiatedApplicationProtocol(String applicationProtocol) {
40          this.applicationProtocol = applicationProtocol;
41      }
42  
43      @Override
44      public SSLSession getSession() {
45          return engine.getSession();
46      }
47  
48      public SSLEngine getWrappedEngine() {
49          return engine;
50      }
51  
52      @Override
53      public void closeInbound() throws SSLException {
54          engine.closeInbound();
55      }
56  
57      @Override
58      public void closeOutbound() {
59          engine.closeOutbound();
60      }
61  
62      @Override
63      public String getPeerHost() {
64          return engine.getPeerHost();
65      }
66  
67      @Override
68      public int getPeerPort() {
69          return engine.getPeerPort();
70      }
71  
72      @Override
73      public SSLEngineResult wrap(ByteBuffer byteBuffer, ByteBuffer byteBuffer2) throws SSLException {
74          return engine.wrap(byteBuffer, byteBuffer2);
75      }
76  
77      @Override
78      public SSLEngineResult wrap(ByteBuffer[] byteBuffers, ByteBuffer byteBuffer) throws SSLException {
79          return engine.wrap(byteBuffers, byteBuffer);
80      }
81  
82      @Override
83      public SSLEngineResult wrap(ByteBuffer[] byteBuffers, int i, int i2, ByteBuffer byteBuffer) throws SSLException {
84          return engine.wrap(byteBuffers, i, i2, byteBuffer);
85      }
86  
87      @Override
88      public SSLEngineResult unwrap(ByteBuffer byteBuffer, ByteBuffer byteBuffer2) throws SSLException {
89          return engine.unwrap(byteBuffer, byteBuffer2);
90      }
91  
92      @Override
93      public SSLEngineResult unwrap(ByteBuffer byteBuffer, ByteBuffer[] byteBuffers) throws SSLException {
94          return engine.unwrap(byteBuffer, byteBuffers);
95      }
96  
97      @Override
98      public SSLEngineResult unwrap(ByteBuffer byteBuffer, ByteBuffer[] byteBuffers, int i, int i2) throws SSLException {
99          return engine.unwrap(byteBuffer, byteBuffers, i, i2);
100     }
101 
102     @Override
103     public Runnable getDelegatedTask() {
104         return engine.getDelegatedTask();
105     }
106 
107     @Override
108     public boolean isInboundDone() {
109         return engine.isInboundDone();
110     }
111 
112     @Override
113     public boolean isOutboundDone() {
114         return engine.isOutboundDone();
115     }
116 
117     @Override
118     public String[] getSupportedCipherSuites() {
119         return engine.getSupportedCipherSuites();
120     }
121 
122     @Override
123     public String[] getEnabledCipherSuites() {
124         return engine.getEnabledCipherSuites();
125     }
126 
127     @Override
128     public void setEnabledCipherSuites(String[] strings) {
129         engine.setEnabledCipherSuites(strings);
130     }
131 
132     @Override
133     public String[] getSupportedProtocols() {
134         return engine.getSupportedProtocols();
135     }
136 
137     @Override
138     public String[] getEnabledProtocols() {
139         return engine.getEnabledProtocols();
140     }
141 
142     @Override
143     public void setEnabledProtocols(String[] strings) {
144         engine.setEnabledProtocols(strings);
145     }
146 
147     @Override
148     public SSLSession getHandshakeSession() {
149         return engine.getHandshakeSession();
150     }
151 
152     @Override
153     public void beginHandshake() throws SSLException {
154         engine.beginHandshake();
155     }
156 
157     @Override
158     public HandshakeStatus getHandshakeStatus() {
159         return engine.getHandshakeStatus();
160     }
161 
162     @Override
163     public void setUseClientMode(boolean b) {
164         engine.setUseClientMode(b);
165     }
166 
167     @Override
168     public boolean getUseClientMode() {
169         return engine.getUseClientMode();
170     }
171 
172     @Override
173     public void setNeedClientAuth(boolean b) {
174         engine.setNeedClientAuth(b);
175     }
176 
177     @Override
178     public boolean getNeedClientAuth() {
179         return engine.getNeedClientAuth();
180     }
181 
182     @Override
183     public void setWantClientAuth(boolean b) {
184         engine.setWantClientAuth(b);
185     }
186 
187     @Override
188     public boolean getWantClientAuth() {
189         return engine.getWantClientAuth();
190     }
191 
192     @Override
193     public void setEnableSessionCreation(boolean b) {
194         engine.setEnableSessionCreation(b);
195     }
196 
197     @Override
198     public boolean getEnableSessionCreation() {
199         return engine.getEnableSessionCreation();
200     }
201 
202     @Override
203     public SSLParameters getSSLParameters() {
204         return engine.getSSLParameters();
205     }
206 
207     @Override
208     public void setSSLParameters(SSLParameters sslParameters) {
209         engine.setSSLParameters(sslParameters);
210     }
211 }