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