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.netty.handler.ssl;
17  
18  import io.netty.util.internal.SuppressJava6Requirement;
19  
20  import java.nio.ByteBuffer;
21  
22  import javax.net.ssl.SSLEngine;
23  import javax.net.ssl.SSLEngineResult;
24  import javax.net.ssl.SSLEngineResult.HandshakeStatus;
25  import javax.net.ssl.SSLException;
26  import javax.net.ssl.SSLParameters;
27  import javax.net.ssl.SSLSession;
28  
29  class JdkSslEngine extends SSLEngine implements ApplicationProtocolAccessor {
30      private final SSLEngine engine;
31      private volatile String applicationProtocol;
32  
33      JdkSslEngine(SSLEngine engine) {
34          this.engine = engine;
35      }
36  
37      @Override
38      public String getNegotiatedApplicationProtocol() {
39          return applicationProtocol;
40      }
41  
42      void setNegotiatedApplicationProtocol(String applicationProtocol) {
43          this.applicationProtocol = applicationProtocol;
44      }
45  
46      @Override
47      public SSLSession getSession() {
48          return engine.getSession();
49      }
50  
51      public SSLEngine getWrappedEngine() {
52          return engine;
53      }
54  
55      @Override
56      public void closeInbound() throws SSLException {
57          engine.closeInbound();
58      }
59  
60      @Override
61      public void closeOutbound() {
62          engine.closeOutbound();
63      }
64  
65      @Override
66      public String getPeerHost() {
67          return engine.getPeerHost();
68      }
69  
70      @Override
71      public int getPeerPort() {
72          return engine.getPeerPort();
73      }
74  
75      @Override
76      public SSLEngineResult wrap(ByteBuffer byteBuffer, ByteBuffer byteBuffer2) throws SSLException {
77          return engine.wrap(byteBuffer, byteBuffer2);
78      }
79  
80      @Override
81      public SSLEngineResult wrap(ByteBuffer[] byteBuffers, ByteBuffer byteBuffer) throws SSLException {
82          return engine.wrap(byteBuffers, byteBuffer);
83      }
84  
85      @Override
86      public SSLEngineResult wrap(ByteBuffer[] byteBuffers, int i, int i2, ByteBuffer byteBuffer) throws SSLException {
87          return engine.wrap(byteBuffers, i, i2, byteBuffer);
88      }
89  
90      @Override
91      public SSLEngineResult unwrap(ByteBuffer byteBuffer, ByteBuffer byteBuffer2) throws SSLException {
92          return engine.unwrap(byteBuffer, byteBuffer2);
93      }
94  
95      @Override
96      public SSLEngineResult unwrap(ByteBuffer byteBuffer, ByteBuffer[] byteBuffers) throws SSLException {
97          return engine.unwrap(byteBuffer, byteBuffers);
98      }
99  
100     @Override
101     public SSLEngineResult unwrap(ByteBuffer byteBuffer, ByteBuffer[] byteBuffers, int i, int i2) throws SSLException {
102         return engine.unwrap(byteBuffer, byteBuffers, i, i2);
103     }
104 
105     @Override
106     public Runnable getDelegatedTask() {
107         return engine.getDelegatedTask();
108     }
109 
110     @Override
111     public boolean isInboundDone() {
112         return engine.isInboundDone();
113     }
114 
115     @Override
116     public boolean isOutboundDone() {
117         return engine.isOutboundDone();
118     }
119 
120     @Override
121     public String[] getSupportedCipherSuites() {
122         return engine.getSupportedCipherSuites();
123     }
124 
125     @Override
126     public String[] getEnabledCipherSuites() {
127         return engine.getEnabledCipherSuites();
128     }
129 
130     @Override
131     public void setEnabledCipherSuites(String[] strings) {
132         engine.setEnabledCipherSuites(strings);
133     }
134 
135     @Override
136     public String[] getSupportedProtocols() {
137         return engine.getSupportedProtocols();
138     }
139 
140     @Override
141     public String[] getEnabledProtocols() {
142         return engine.getEnabledProtocols();
143     }
144 
145     @Override
146     public void setEnabledProtocols(String[] strings) {
147         engine.setEnabledProtocols(strings);
148     }
149 
150     @SuppressJava6Requirement(reason = "Can only be called when running on JDK7+")
151     @Override
152     public SSLSession getHandshakeSession() {
153         return engine.getHandshakeSession();
154     }
155 
156     @Override
157     public void beginHandshake() throws SSLException {
158         engine.beginHandshake();
159     }
160 
161     @Override
162     public HandshakeStatus getHandshakeStatus() {
163         return engine.getHandshakeStatus();
164     }
165 
166     @Override
167     public void setUseClientMode(boolean b) {
168         engine.setUseClientMode(b);
169     }
170 
171     @Override
172     public boolean getUseClientMode() {
173         return engine.getUseClientMode();
174     }
175 
176     @Override
177     public void setNeedClientAuth(boolean b) {
178         engine.setNeedClientAuth(b);
179     }
180 
181     @Override
182     public boolean getNeedClientAuth() {
183         return engine.getNeedClientAuth();
184     }
185 
186     @Override
187     public void setWantClientAuth(boolean b) {
188         engine.setWantClientAuth(b);
189     }
190 
191     @Override
192     public boolean getWantClientAuth() {
193         return engine.getWantClientAuth();
194     }
195 
196     @Override
197     public void setEnableSessionCreation(boolean b) {
198         engine.setEnableSessionCreation(b);
199     }
200 
201     @Override
202     public boolean getEnableSessionCreation() {
203         return engine.getEnableSessionCreation();
204     }
205 
206     @Override
207     public SSLParameters getSSLParameters() {
208         return engine.getSSLParameters();
209     }
210 
211     @Override
212     public void setSSLParameters(SSLParameters sslParameters) {
213         engine.setSSLParameters(sslParameters);
214     }
215 }