001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Vera Y. Petrashkova
020: * @version $Revision$
021: */package javax.net.ssl;
022:
023: import java.nio.ByteBuffer;
024: import java.nio.ReadOnlyBufferException;
025:
026: /**
027: *
028: * @com.intel.drl.spec_ref
029: *
030: *
031: */
032: public abstract class SSLEngine {
033: // Store host value
034: private final String host;
035:
036: // Store port value
037: private final int port;
038:
039: /**
040: * @com.intel.drl.spec_ref
041: *
042: */
043: protected SSLEngine() {
044: host = null;
045: port = -1;
046: }
047:
048: /**
049: * @com.intel.drl.spec_ref
050: *
051: */
052: protected SSLEngine(String host, int port) {
053: this .host = host;
054: this .port = port;
055: }
056:
057: /**
058: * @com.intel.drl.spec_ref
059: *
060: */
061: public abstract void beginHandshake() throws SSLException;
062:
063: /**
064: * @com.intel.drl.spec_ref
065: *
066: */
067: public abstract void closeInbound() throws SSLException;
068:
069: /**
070: * @com.intel.drl.spec_ref
071: *
072: */
073: public abstract void closeOutbound();
074:
075: /**
076: * @com.intel.drl.spec_ref
077: *
078: */
079: public abstract Runnable getDelegatedTask();
080:
081: /**
082: * @com.intel.drl.spec_ref
083: *
084: */
085: public abstract String[] getEnabledCipherSuites();
086:
087: /**
088: * @com.intel.drl.spec_ref
089: *
090: */
091: public abstract String[] getEnabledProtocols();
092:
093: /**
094: * @com.intel.drl.spec_ref
095: *
096: */
097: public abstract boolean getEnableSessionCreation();
098:
099: /**
100: * @com.intel.drl.spec_ref
101: *
102: */
103: public abstract SSLEngineResult.HandshakeStatus getHandshakeStatus();
104:
105: /**
106: * @com.intel.drl.spec_ref
107: *
108: */
109: public abstract boolean getNeedClientAuth();
110:
111: /**
112: * @com.intel.drl.spec_ref
113: *
114: */
115: public String getPeerHost() {
116: return host;
117: }
118:
119: /**
120: * @com.intel.drl.spec_ref
121: *
122: */
123: public int getPeerPort() {
124: return port;
125: }
126:
127: /**
128: * @com.intel.drl.spec_ref
129: *
130: */
131: public abstract SSLSession getSession();
132:
133: /**
134: * @com.intel.drl.spec_ref
135: *
136: */
137: public abstract String[] getSupportedCipherSuites();
138:
139: /**
140: * @com.intel.drl.spec_ref
141: *
142: */
143: public abstract String[] getSupportedProtocols();
144:
145: /**
146: * @com.intel.drl.spec_ref
147: *
148: */
149: public abstract boolean getUseClientMode();
150:
151: /**
152: * @com.intel.drl.spec_ref
153: *
154: */
155: public abstract boolean getWantClientAuth();
156:
157: /**
158: * @com.intel.drl.spec_ref
159: *
160: */
161: public abstract boolean isInboundDone();
162:
163: /**
164: * @com.intel.drl.spec_ref
165: *
166: */
167: public abstract boolean isOutboundDone();
168:
169: /**
170: * @com.intel.drl.spec_ref
171: *
172: */
173: public abstract void setEnabledCipherSuites(String[] suites);
174:
175: /**
176: * @com.intel.drl.spec_ref
177: *
178: */
179: public abstract void setEnabledProtocols(String[] protocols);
180:
181: /**
182: * @com.intel.drl.spec_ref
183: *
184: */
185: public abstract void setEnableSessionCreation(boolean flag);
186:
187: /**
188: * @com.intel.drl.spec_ref
189: *
190: */
191: public abstract void setNeedClientAuth(boolean need);
192:
193: /**
194: * @com.intel.drl.spec_ref
195: *
196: */
197: public abstract void setUseClientMode(boolean mode);
198:
199: /**
200: * @com.intel.drl.spec_ref
201: *
202: */
203: public abstract void setWantClientAuth(boolean want);
204:
205: /**
206: * @com.intel.drl.spec_ref
207: *
208: */
209: public abstract SSLEngineResult unwrap(ByteBuffer src,
210: ByteBuffer[] dsts, int offset, int length)
211: throws SSLException;
212:
213: /**
214: * @com.intel.drl.spec_ref
215: *
216: */
217: public abstract SSLEngineResult wrap(ByteBuffer[] srcs, int offset,
218: int length, ByteBuffer dst) throws SSLException;
219:
220: /**
221: * implementation behavior follows RI:
222: * jdk 1.5 does not throw IllegalArgumentException when parameters are null
223: * and does not throw ReadOnlyBufferException if dst is read only byte buffer
224: *
225: */
226: public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer dst)
227: throws SSLException {
228: // if (src == null) {
229: // throw new IllegalArgumentException("Byte buffer src is null");
230: // }
231: // if (dst == null) {
232: // throw new IllegalArgumentException("Byte buffer dst is null");
233: // }
234: // if (dst.isReadOnly()) {
235: // throw new ReadOnlyBufferException();
236: // }
237: return unwrap(src, new ByteBuffer[] { dst }, 0, 1);
238: }
239:
240: /**
241: * implementation behavior follows RI:
242: * jdk 1.5 does not throw IllegalArgumentException when src is null or if
243: * dsts contains null elements
244: * It does not throw ReadOnlyBufferException when dsts contains read only elements
245: */
246: public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts)
247: throws SSLException {
248: // if (src == null) {
249: // throw new IllegalArgumentException("Byte buffer src is null");
250: // }
251: if (dsts == null) {
252: throw new IllegalArgumentException(
253: "Byte buffer array dsts is null");
254: }
255: // for (int i = 0; i < dsts.length; i++) {
256: // if (dsts[i] == null) {
257: // throw new IllegalArgumentException("Byte buffer dsts[" + i
258: // + "] is null");
259: // }
260: // if (dsts[i].isReadOnly()) {
261: // throw new ReadOnlyBufferException();
262: // }
263: // }
264: return unwrap(src, dsts, 0, dsts.length);
265: }
266:
267: /**
268: * implementation behavior follows RI: jdk 1.5 does not throw
269: * IllegalArgumentException when dst is null or if srcs contains null
270: * elements It does not throw ReadOnlyBufferException for read only dst
271: *
272: */
273: public SSLEngineResult wrap(ByteBuffer[] srcs, ByteBuffer dst)
274: throws SSLException {
275: if (srcs == null) {
276: throw new IllegalArgumentException(
277: "Byte buffer array srcs is null");
278: }
279: // for (int i = 0; i < srcs.length; i++) {
280: // if (srcs[i] == null) {
281: // throw new IllegalArgumentException("Byte buffer srcs[" + i
282: // + "] is null");
283: // }
284: // }
285: // if (dst == null) {
286: // throw new IllegalArgumentException("Byte buffer array dst is null");
287: // }
288: // if (dst.isReadOnly()) {
289: // throw new ReadOnlyBufferException();
290: // }
291: return wrap(srcs, 0, srcs.length, dst);
292: }
293:
294: /**
295: * implementation behavior follows RI:
296: * jdk 1.5 does not throw IllegalArgumentException when parameters are null
297: * and does not throw ReadOnlyBufferException if dst is read only byte buffer
298: *
299: */
300: public SSLEngineResult wrap(ByteBuffer src, ByteBuffer dst)
301: throws SSLException {
302: // if (src == null) {
303: // throw new IllegalArgumentException("Byte buffer src is null");
304: // }
305: // if (dst == null) {
306: // throw new IllegalArgumentException("Byte buffer dst is null");
307: // }
308: // if (dst.isReadOnly()) {
309: // throw new ReadOnlyBufferException();
310: // }
311: return wrap(new ByteBuffer[] { src }, 0, 1, dst);
312: }
313: }
|