Added ExtendedSession Java8 features bacK
diff --git a/common/src/main/java/org/conscrypt/OpenSSLExtendedSessionImpl.java b/common/src/main/java/org/conscrypt/OpenSSLExtendedSessionImpl.java
index 474af3e..dead13d 100644
--- a/common/src/main/java/org/conscrypt/OpenSSLExtendedSessionImpl.java
+++ b/common/src/main/java/org/conscrypt/OpenSSLExtendedSessionImpl.java
@@ -15,8 +15,12 @@
*/
package org.conscrypt;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.security.Principal;
import java.security.cert.Certificate;
+import java.util.Collections;
+import java.util.List;
import javax.net.ssl.ExtendedSSLSession;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSessionContext;
@@ -66,6 +70,29 @@
};
}
+ /* @Override */
+ // For Android/Java7 backward-compatibility.
+ @SuppressWarnings({"MissingOverride", "unchecked", "rawtypes", "LiteralClassName"})
+ public List getRequestedServerNames() {
+ try {
+ String requestedServerName = delegate.getRequestedServerName();
+ if (requestedServerName == null) {
+ return null;
+ }
+
+ Constructor sniHostNameConstructor =
+ Class.forName("javax.net.ssl.SNIHostName").getConstructor(String.class);
+ return Collections.singletonList(sniHostNameConstructor.newInstance(requestedServerName));
+
+ } catch (NoSuchMethodException e) {
+ } catch (InvocationTargetException e) {
+ } catch (IllegalAccessException e) {
+ } catch (ClassNotFoundException e) {
+ } catch (InstantiationException e) {
+ }
+ return null;
+ }
+
@Override
public byte[] getId() {
return delegate.getId();
diff --git a/openjdk/src/test/java/org/conscrypt/OpenSSLExtendedSessionImplTest.java b/openjdk/src/test/java/org/conscrypt/OpenSSLExtendedSessionImplTest.java
new file mode 100644
index 0000000..eff04d4
--- /dev/null
+++ b/openjdk/src/test/java/org/conscrypt/OpenSSLExtendedSessionImplTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli$
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.conscrypt;
+
+import javax.net.ssl.SNIHostName;
+import javax.net.ssl.SNIServerName;
+import javax.net.ssl.ExtendedSSLSession;
+import junit.framework.TestCase;
+import java.util.List;
+
+/**
+ * Test for OpenSSLExtendedSessionImpl
+ */
+public class OpenSSLExtendedSessionImplTest extends TestCase {
+ static class MockSSLSession extends OpenSSLSessionImpl {
+ MockSSLSession() {
+ super(0, null, null, null, null, null, 0, null);
+ }
+
+ @Override
+ public String getRequestedServerName() {
+ return "server.name";
+ }
+ }
+
+ public void test_getRequestedServerNames() {
+ AbstractOpenSSLSession session = new MockSSLSession();
+ ExtendedSSLSession extendedSession = new OpenSSLExtendedSessionImpl(session);
+ List<SNIServerName> names = extendedSession.getRequestedServerNames();
+ assertEquals("server.name", ((SNIHostName) names.get(0)).getAsciiName());
+ }
+}