You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by od...@apache.org on 2010/09/14 17:07:28 UTC
svn commit: r996937 - in
/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main:
java/org/apache/harmony/xnet/provider/jsse/ native/jsse/shared/
native/jsse/unix/
Author: odeakin
Date: Tue Sep 14 15:07:27 2010
New Revision: 996937
URL: http://svn.apache.org/viewvc?rev=996937&view=rev
Log:
Implement closeOutbound() and closeInbound() methods, and remove unused code and fields on SSLEngineImpl.
Modified:
harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java
harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.c
harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.h
harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/unix/exports.txt
harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/unix/libhyjsse.exp
Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java?rev=996937&r1=996936&r2=996937&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java (original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java Tue Sep 14 15:07:27 2010
@@ -17,10 +17,6 @@
package org.apache.harmony.xnet.provider.jsse;
-import org.apache.harmony.xnet.provider.jsse.AlertException;
-import org.apache.harmony.xnet.provider.jsse.SSLSessionImpl;
-import org.apache.harmony.xnet.provider.jsse.SSLEngineDataStream;
-
import java.io.FileDescriptor;
import java.io.IOException;
import java.lang.reflect.Field;
@@ -61,30 +57,12 @@ public class SSLEngineImpl extends SSLEn
// all cleaning work had been done and the engine is not operable)
private boolean engine_was_shutteddown = false;
- // record protocol to be used
- protected SSLRecordProtocol recordProtocol;
- // input stream for record protocol
- private SSLBufferedInput recProtIS;
- // handshake protocol to be used
- private HandshakeProtocol handshakeProtocol;
- // alert protocol to be used
- private AlertProtocol alertProtocol;
- // place where application data will be stored
- private SSLEngineAppData appData;
- // outcoming application data stream
- private SSLEngineDataStream dataStream = new SSLEngineDataStream();
// active session object
private SSLSessionImpl session;
// peer configuration parameters
protected SSLParameters sslParameters;
- // in case of emergency situations when data could not be
- // placed in destination buffers it will be stored in this
- // fields
- private byte[] remaining_wrapped_data = null;
- private byte[] remaining_hsh_data = null;
-
// logger
private Logger.Stream logger = Logger.getStream("engine");
@@ -163,15 +141,11 @@ public class SSLEngineImpl extends SSLEn
}
handshakeStatus = acceptImpl(SSLEngineAddress);
}
-// appData = new SSLEngineAppData();
-// alertProtocol = new AlertProtocol();
-// recProtIS = new SSLBufferedInput();
-// recordProtocol = new SSLRecordProtocol(handshakeProtocol,
-// alertProtocol, recProtIS, appData);
}
-// handshakeProtocol.start();
}
+ private static native void closeInboundImpl(long SSLEngineAddress);
+
/**
* Closes inbound operations of this engine
* @throws SSLException
@@ -187,23 +161,18 @@ public class SSLEngineImpl extends SSLEn
return;
}
isInboundDone = true;
+
+ closeInboundImpl(SSLEngineAddress);
+
engine_was_closed = true;
- if (handshake_started) {
- if (!close_notify_was_received) {
- if (session != null) {
- session.invalidate();
- }
- alertProtocol.alert(AlertProtocol.FATAL,
- AlertProtocol.INTERNAL_ERROR);
- throw new SSLException("Inbound is closed before close_notify "
- + "alert has been received.");
- }
- } else {
+ if (!handshake_started) {
// engine is closing before initial handshake has been made
shutdown();
}
}
+ private static native void closeOutboundImpl(long SSLEngineAddress);
+
/**
* Closes outbound operations of this engine
* @see javax.net.ssl.SSLEngine#closeOutbound() method documentation
@@ -218,12 +187,10 @@ public class SSLEngineImpl extends SSLEn
return;
}
isOutboundDone = true;
- if (handshake_started) {
- // initial handshake had been started
- alertProtocol.alert(AlertProtocol.WARNING,
- AlertProtocol.CLOSE_NOTIFY);
- close_notify_was_sent = true;
- } else {
+
+ closeOutboundImpl(SSLEngineAddress);
+
+ if (!handshake_started) {
// engine is closing before initial handshake has been made
shutdown();
}
@@ -404,15 +371,6 @@ public class SSLEngineImpl extends SSLEn
return SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING;
}
return handshakeStatus;
-// if (alertProtocol.hasAlert()) {
-// // need to send an alert
-// return SSLEngineResult.HandshakeStatus.NEED_WRAP;
-// }
-// if (close_notify_was_sent && !close_notify_was_received) {
-// // waiting for "close_notify" response
-// return SSLEngineResult.HandshakeStatus.NEED_UNWRAP;
-// }
-// return handshakeProtocol.getStatus();
}
/**
@@ -479,138 +437,6 @@ public class SSLEngineImpl extends SSLEn
byte[] dst = dsts[0].array();
int dst_len = dst.length;
return unwrapImpl(SSLEngineAddress, src.array(), src.array().length, dst, dst_len);
-// SSLEngineResult.HandshakeStatus handshakeStatus = getHandshakeStatus();
-// // If is is initial handshake or connection closure stage,
-// // check if this call was made in spite of handshake status
-// if ((session == null || engine_was_closed) && (
-// handshakeStatus.equals(
-// SSLEngineResult.HandshakeStatus.NEED_WRAP) ||
-// handshakeStatus.equals(
-// SSLEngineResult.HandshakeStatus.NEED_TASK))) {
-// return new SSLEngineResult(
-// getEngineStatus(), handshakeStatus, 0, 0);
-// }
-//
-// if (src.remaining() < recordProtocol.getMinRecordSize()) {
-// return new SSLEngineResult(
-// SSLEngineResult.Status.BUFFER_UNDERFLOW,
-// getHandshakeStatus(), 0, 0);
-// }
-//
-// try {
-// src.mark();
-// // check the destination buffers and count their capacity
-// int capacity = 0;
-// for (int i=offset; i<offset+length; i++) {
-// if (dsts[i] == null) {
-// throw new IllegalStateException(
-// "Some of the input parameters are null");
-// }
-// if (dsts[i].isReadOnly()) {
-// throw new ReadOnlyBufferException();
-// }
-// capacity += dsts[i].remaining();
-// }
-// if (capacity < recordProtocol.getDataSize(src.remaining())) {
-// return new SSLEngineResult(
-// SSLEngineResult.Status.BUFFER_OVERFLOW,
-// getHandshakeStatus(), 0, 0);
-// }
-// recProtIS.setSourceBuffer(src);
-// // unwrap the record contained in source buffer, pass it
-// // to appropriate client protocol (alert, handshake, or app)
-// // and retrieve the type of unwrapped data
-// int type = recordProtocol.unwrap();
-// // process the data and return the result
-// switch (type) {
-// case ContentType.HANDSHAKE:
-// case ContentType.CHANGE_CIPHER_SPEC:
-// if (handshakeProtocol.getStatus().equals(
-// SSLEngineResult.HandshakeStatus.FINISHED)) {
-// session = recordProtocol.getSession();
-// }
-// break;
-// case ContentType.APPLICATION_DATA:
-// break;
-// case ContentType.ALERT:
-// if (alertProtocol.isFatalAlert()) {
-// alertProtocol.setProcessed();
-// if (session != null) {
-// session.invalidate();
-// }
-// String description = "Fatal alert received "
-// + alertProtocol.getAlertDescription();
-// shutdown();
-// throw new SSLException(description);
-// } else {
-// if (logger != null) {
-// logger.println("Warning allert has been received: "
-// + alertProtocol.getAlertDescription());
-// }
-// switch(alertProtocol.getDescriptionCode()) {
-// case AlertProtocol.CLOSE_NOTIFY:
-// alertProtocol.setProcessed();
-// close_notify_was_received = true;
-// if (!close_notify_was_sent) {
-// closeOutbound();
-// closeInbound();
-// } else {
-// closeInbound();
-// shutdown();
-// }
-// break;
-// case AlertProtocol.NO_RENEGOTIATION:
-// alertProtocol.setProcessed();
-// if (session == null) {
-// // message received during the initial
-// // handshake
-// throw new AlertException(
-// AlertProtocol.HANDSHAKE_FAILURE,
-// new SSLHandshakeException(
-// "Received no_renegotiation "
-// + "during the initial handshake"));
-// } else {
-// // just stop the handshake
-// handshakeProtocol.stop();
-// }
-// break;
-// default:
-// alertProtocol.setProcessed();
-// }
-// }
-// break;
-// }
-// return new SSLEngineResult(getEngineStatus(), getHandshakeStatus(),
-// recProtIS.consumed(),
-// // place the app. data (if any) into the dest. buffers
-// // and get the number of produced bytes:
-// appData.placeTo(dsts, offset, length));
-// } catch (BufferUnderflowException e) {
-// // there was not enought data ource buffer to make complete packet
-// src.reset();
-// return new SSLEngineResult(SSLEngineResult.Status.BUFFER_UNDERFLOW,
-// getHandshakeStatus(), 0, 0);
-// } catch (AlertException e) {
-// // fatal alert occured
-// alertProtocol.alert(AlertProtocol.FATAL, e.getDescriptionCode());
-// engine_was_closed = true;
-// src.reset();
-// if (session != null) {
-// session.invalidate();
-// }
-// // shutdown work will be made after the alert will be sent
-// // to another peer (by wrap method)
-// throw e.getReason();
-// } catch (SSLException e) {
-// throw e;
-// } catch (IOException e) {
-// alertProtocol.alert(AlertProtocol.FATAL,
-// AlertProtocol.INTERNAL_ERROR);
-// engine_was_closed = true;
-// // shutdown work will be made after the alert will be sent
-// // to another peer (by wrap method)
-// throw new SSLException(e.getMessage());
-// }
}
/**
@@ -652,147 +478,6 @@ public class SSLEngineImpl extends SSLEn
int src_len = src.length;
return wrapImpl(SSLEngineAddress, src, src_len, dst.array(), dst.array().length);
-
-
-// SSLEngineResult.HandshakeStatus handshakeStatus = getHandshakeStatus();
-// // If it is an initial handshake or connection closure stage,
-// // check if this call was made in spite of handshake status
-// if ((session == null || engine_was_closed) && (
-// handshakeStatus.equals(
-// SSLEngineResult.HandshakeStatus.NEED_UNWRAP) ||
-// handshakeStatus.equals(
-// SSLEngineResult.HandshakeStatus.NEED_TASK))) {
-// return new SSLEngineResult(
-// getEngineStatus(), handshakeStatus, 0, 0);
-// }
-//
-// int capacity = dst.remaining();
-// int produced = 0;
-//
-// if (alertProtocol.hasAlert()) {
-// // we have an alert to be sent
-// if (capacity < recordProtocol.getRecordSize(2)) {
-// return new SSLEngineResult(
-// SSLEngineResult.Status.BUFFER_OVERFLOW,
-// handshakeStatus, 0, 0);
-// }
-// byte[] alert_data = alertProtocol.wrap();
-// // place the alert record into destination
-// dst.put(alert_data);
-// if (alertProtocol.isFatalAlert()) {
-// alertProtocol.setProcessed();
-// if (session != null) {
-// session.invalidate();
-// }
-// // fatal alert has been sent, so shut down the engine
-// shutdown();
-// return new SSLEngineResult(
-// SSLEngineResult.Status.CLOSED,
-// SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING,
-// 0, alert_data.length);
-// } else {
-// alertProtocol.setProcessed();
-// // check if the works on this engine have been done
-// if (close_notify_was_sent && close_notify_was_received) {
-// shutdown();
-// return new SSLEngineResult(SSLEngineResult.Status.CLOSED,
-// SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING,
-// 0, alert_data.length);
-// }
-// return new SSLEngineResult(
-// getEngineStatus(),
-// getHandshakeStatus(),
-// 0, alert_data.length);
-// }
-// }
-//
-// if (capacity < recordProtocol.getMinRecordSize()) {
-// if (logger != null) {
-// logger.println("Capacity of the destination("
-// +capacity+") < MIN_PACKET_SIZE("
-// +recordProtocol.getMinRecordSize()+")");
-// }
-// return new SSLEngineResult(SSLEngineResult.Status.BUFFER_OVERFLOW,
-// handshakeStatus, 0, 0);
-// }
-//
-// try {
-// if (!handshakeStatus.equals(
-// SSLEngineResult.HandshakeStatus.NEED_WRAP)) {
-// // so we wraps application data
-// dataStream.setSourceBuffers(srcs, offset, len);
-// if ((capacity < SSLRecordProtocol.MAX_SSL_PACKET_SIZE) &&
-// (capacity < recordProtocol.getRecordSize(
-// dataStream.available()))) {
-// if (logger != null) {
-// logger.println("The destination buffer("
-// +capacity+") can not take the resulting packet("
-// + recordProtocol.getRecordSize(
-// dataStream.available())+")");
-// }
-// return new SSLEngineResult(
-// SSLEngineResult.Status.BUFFER_OVERFLOW,
-// handshakeStatus, 0, 0);
-// }
-// if (remaining_wrapped_data == null) {
-// remaining_wrapped_data =
-// recordProtocol.wrap(ContentType.APPLICATION_DATA,
-// dataStream);
-// }
-// if (capacity < remaining_wrapped_data.length) {
-// // It should newer happen because we checked the destination
-// // buffer size, but there is a possibility
-// // (if dest buffer was filled outside)
-// // so we just remember the data into remaining_wrapped_data
-// // and will enclose it during the the next call
-// return new SSLEngineResult(
-// SSLEngineResult.Status.BUFFER_OVERFLOW,
-// handshakeStatus, dataStream.consumed(), 0);
-// } else {
-// dst.put(remaining_wrapped_data);
-// produced = remaining_wrapped_data.length;
-// remaining_wrapped_data = null;
-// return new SSLEngineResult(getEngineStatus(),
-// handshakeStatus, dataStream.consumed(), produced);
-// }
-// } else {
-// if (remaining_hsh_data == null) {
-// remaining_hsh_data = handshakeProtocol.wrap();
-// }
-// if (capacity < remaining_hsh_data.length) {
-// // It should newer happen because we checked the destination
-// // buffer size, but there is a possibility
-// // (if dest buffer was filled outside)
-// // so we just remember the data into remaining_hsh_data
-// // and will enclose it during the the next call
-// return new SSLEngineResult(
-// SSLEngineResult.Status.BUFFER_OVERFLOW,
-// handshakeStatus, 0, 0);
-// } else {
-// dst.put(remaining_hsh_data);
-// produced = remaining_hsh_data.length;
-// remaining_hsh_data = null;
-//
-// handshakeStatus = handshakeProtocol.getStatus();
-// if (handshakeStatus.equals(
-// SSLEngineResult.HandshakeStatus.FINISHED)) {
-// session = recordProtocol.getSession();
-// }
-// }
-// return new SSLEngineResult(
-// getEngineStatus(), getHandshakeStatus(), 0, produced);
-// }
-// } catch (AlertException e) {
-// // fatal alert occured
-// alertProtocol.alert(AlertProtocol.FATAL, e.getDescriptionCode());
-// engine_was_closed = true;
-// if (session != null) {
-// session.invalidate();
-// }
-// // shutdown work will be made after the alert will be sent
-// // to another peer (by wrap method)
-// throw e.getReason();
-// }
}
// Shutdownes the engine and makes all cleanup work.
@@ -801,14 +486,6 @@ public class SSLEngineImpl extends SSLEn
engine_was_shutteddown = true;
isOutboundDone = true;
isInboundDone = true;
- if (handshake_started) {
- alertProtocol.shutdown();
- alertProtocol = null;
- handshakeProtocol.shutdown();
- handshakeProtocol = null;
- recordProtocol.shutdown();
- recordProtocol = null;
- }
}
Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.c?rev=996937&r1=996936&r2=996937&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.c (original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.c Tue Sep 14 15:07:27 2010
@@ -228,7 +228,7 @@ JNIEXPORT jobject JNICALL Java_org_apach
JNIEXPORT jobject JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_unwrapImpl
(JNIEnv *env, jclass clazz, jlong jsslengine, jbyteArray src, int src_len,
jbyteArray dst, int dst_len) {
- _sslengine *sslengine = jlong2addr(_sslengine, jsslengine);
+ _sslengine *sslengine = jlong2addr(_sslengine, jsslengine);
BIO *bio = sslengine->bio;
BIO *bio_io = sslengine->bio_io;
SSL *ssl = NULL;
@@ -296,3 +296,15 @@ JNIEXPORT jobject JNICALL Java_org_apach
engine_state, handshake_state, write_result, read_result);
return result;
}
+
+JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_closeInboundImpl
+ (JNIEnv *env, jclass clazz, jlong jsslengine) {
+ _sslengine *sslengine = jlong2addr(_sslengine, jsslengine);
+ BIO_shutdown_wr(sslengine->bio_io);
+}
+
+JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_closeOutboundImpl
+ (JNIEnv *env, jclass clazz, jlong jsslengine) {
+ _sslengine *sslengine = jlong2addr(_sslengine, jsslengine);
+ BIO_shutdown_wr(sslengine->bio);
+}
Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.h?rev=996937&r1=996936&r2=996937&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.h (original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.h Tue Sep 14 15:07:27 2010
@@ -35,6 +35,11 @@ JNIEXPORT jobject JNICALL Java_org_apach
(JNIEnv *, jclass, jlong, jbyteArray, int, jbyteArray, int);
JNIEXPORT jobject JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_unwrapImpl
(JNIEnv *, jclass, jlong, jbyteArray, int, jbyteArray, int);
+JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_closeInboundImpl
+ (JNIEnv *, jclass, jlong);
+JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_closeOutboundImpl
+ (JNIEnv *, jclass, jlong);
+
#ifdef __cplusplus
}
#endif
Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/unix/exports.txt
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/unix/exports.txt?rev=996937&r1=996936&r2=996937&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/unix/exports.txt (original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/unix/exports.txt Tue Sep 14 15:07:27 2010
@@ -20,3 +20,5 @@ Java_org_apache_harmony_xnet_provider_js
Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_connectImpl
Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_wrapImpl
Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_unwrapImpl
+Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_closeInboundImpl
+Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_closeOutboundImpl
Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/unix/libhyjsse.exp
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/unix/libhyjsse.exp?rev=996937&r1=996936&r2=996937&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/unix/libhyjsse.exp (original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/unix/libhyjsse.exp Tue Sep 14 15:07:27 2010
@@ -22,5 +22,7 @@ HYJSSE_0.1 {
Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_connectImpl;
Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_wrapImpl;
Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_unwrapImpl;
+ Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_closeInboundImpl;
+ Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_closeOutboundImpl;
local : *;
};