1 /* 2 * Copyright 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * 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, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.conscrypt; 17 18 import java.security.Principal; 19 import java.security.cert.Certificate; 20 import java.util.Collections; 21 import java.util.List; 22 import javax.net.ssl.ExtendedSSLSession; 23 import javax.net.ssl.SNIHostName; 24 import javax.net.ssl.SNIServerName; 25 import javax.net.ssl.SSLPeerUnverifiedException; 26 import javax.net.ssl.SSLSessionContext; 27 import javax.security.cert.X509Certificate; 28 29 /** 30 * Implementation of the ExtendedSSLSession class for OpenSSL. Uses a delegate to maintain backward 31 * compatibility with previous versions of Android which don't have ExtendedSSLSession. 32 * 33 * @hide 34 */ 35 @Internal 36 public class OpenSSLExtendedSessionImpl extends ExtendedSSLSession { 37 private final AbstractOpenSSLSession delegate; 38 OpenSSLExtendedSessionImpl(AbstractOpenSSLSession delegate)39 public OpenSSLExtendedSessionImpl(AbstractOpenSSLSession delegate) { 40 this.delegate = delegate; 41 } 42 getDelegate()43 public AbstractOpenSSLSession getDelegate() { 44 return delegate; 45 } 46 47 /* @Override */ 48 @SuppressWarnings("MissingOverride") // For Android backward-compatibility. getLocalSupportedSignatureAlgorithms()49 public String[] getLocalSupportedSignatureAlgorithms() { 50 // From src/ssl/t1_lib.c tls12_sigalgs 51 // TODO: use BoringSSL API to actually fetch the real data 52 return new String[] { 53 "SHA512withRSA", 54 "SHA512withECDSA", 55 "SHA384withRSA", 56 "SHA384withECDSA", 57 "SHA256withRSA", 58 "SHA256withECDSA", 59 "SHA224withRSA", 60 "SHA224withECDSA", 61 "SHA1withRSA", 62 "SHA1withECDSA", 63 }; 64 } 65 66 /* @Override */ 67 @SuppressWarnings("MissingOverride") // For Android backward-compatibility. getPeerSupportedSignatureAlgorithms()68 public String[] getPeerSupportedSignatureAlgorithms() { 69 // TODO: use BoringSSL API to actually fetch the real data 70 return new String[] { 71 "SHA1withRSA", 72 "SHA1withECDSA", 73 }; 74 } 75 76 /* @Override */ 77 @SuppressWarnings("MissingOverride") // For Android backward-compatibility. getRequestedServerNames()78 public List<SNIServerName> getRequestedServerNames() { 79 String requestedServerName = delegate.getRequestedServerName(); 80 if (requestedServerName == null) { 81 return null; 82 } 83 84 return Collections.<SNIServerName> singletonList(new SNIHostName(requestedServerName)); 85 } 86 87 @Override getId()88 public byte[] getId() { 89 return delegate.getId(); 90 } 91 92 @Override getSessionContext()93 public SSLSessionContext getSessionContext() { 94 return delegate.getSessionContext(); 95 } 96 97 @Override getCreationTime()98 public long getCreationTime() { 99 return delegate.getCreationTime(); 100 } 101 102 @Override getLastAccessedTime()103 public long getLastAccessedTime() { 104 return delegate.getLastAccessedTime(); 105 } 106 107 @Override invalidate()108 public void invalidate() { 109 delegate.invalidate(); 110 } 111 112 @Override isValid()113 public boolean isValid() { 114 return delegate.isValid(); 115 } 116 117 @Override putValue(String name, Object value)118 public void putValue(String name, Object value) { 119 delegate.putValue(name, value); 120 } 121 122 @Override getValue(String name)123 public Object getValue(String name) { 124 return delegate.getValue(name); 125 } 126 127 @Override removeValue(String name)128 public void removeValue(String name) { 129 delegate.removeValue(name); 130 } 131 132 @Override getValueNames()133 public String[] getValueNames() { 134 return delegate.getValueNames(); 135 } 136 137 @Override getPeerCertificates()138 public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException { 139 return delegate.getPeerCertificates(); 140 } 141 142 @Override getLocalCertificates()143 public Certificate[] getLocalCertificates() { 144 return delegate.getLocalCertificates(); 145 } 146 147 @Override getPeerCertificateChain()148 public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException { 149 return delegate.getPeerCertificateChain(); 150 } 151 152 @Override getPeerPrincipal()153 public Principal getPeerPrincipal() throws SSLPeerUnverifiedException { 154 return delegate.getPeerPrincipal(); 155 } 156 157 @Override getLocalPrincipal()158 public Principal getLocalPrincipal() { 159 return delegate.getLocalPrincipal(); 160 } 161 162 @Override getCipherSuite()163 public String getCipherSuite() { 164 return delegate.getCipherSuite(); 165 } 166 167 @Override getProtocol()168 public String getProtocol() { 169 return delegate.getProtocol(); 170 } 171 172 @Override getPeerHost()173 public String getPeerHost() { 174 return delegate.getPeerHost(); 175 } 176 177 @Override getPeerPort()178 public int getPeerPort() { 179 return delegate.getPeerPort(); 180 } 181 182 @Override getPacketBufferSize()183 public int getPacketBufferSize() { 184 return delegate.getPacketBufferSize(); 185 } 186 187 @Override getApplicationBufferSize()188 public int getApplicationBufferSize() { 189 return delegate.getApplicationBufferSize(); 190 } 191 } 192