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 */ 16package org.conscrypt; 17 18import java.security.Principal; 19import java.security.cert.Certificate; 20import java.util.Collections; 21import java.util.List; 22import javax.net.ssl.ExtendedSSLSession; 23import javax.net.ssl.SNIHostName; 24import javax.net.ssl.SNIServerName; 25import javax.net.ssl.SSLPeerUnverifiedException; 26import javax.net.ssl.SSLSessionContext; 27import 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 36public class OpenSSLExtendedSessionImpl extends ExtendedSSLSession { 37 private final AbstractOpenSSLSession delegate; 38 39 public OpenSSLExtendedSessionImpl(AbstractOpenSSLSession delegate) { 40 this.delegate = delegate; 41 } 42 43 public AbstractOpenSSLSession getDelegate() { 44 return delegate; 45 } 46 47 /* @Override */ 48 @SuppressWarnings("MissingOverride") // For Android backward-compatibility. 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. 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. 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 88 public byte[] getId() { 89 return delegate.getId(); 90 } 91 92 @Override 93 public SSLSessionContext getSessionContext() { 94 return delegate.getSessionContext(); 95 } 96 97 @Override 98 public long getCreationTime() { 99 return delegate.getCreationTime(); 100 } 101 102 @Override 103 public long getLastAccessedTime() { 104 return delegate.getLastAccessedTime(); 105 } 106 107 @Override 108 public void invalidate() { 109 delegate.invalidate(); 110 } 111 112 @Override 113 public boolean isValid() { 114 return delegate.isValid(); 115 } 116 117 @Override 118 public void putValue(String name, Object value) { 119 delegate.putValue(name, value); 120 } 121 122 @Override 123 public Object getValue(String name) { 124 return delegate.getValue(name); 125 } 126 127 @Override 128 public void removeValue(String name) { 129 delegate.removeValue(name); 130 } 131 132 @Override 133 public String[] getValueNames() { 134 return delegate.getValueNames(); 135 } 136 137 @Override 138 public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException { 139 return delegate.getPeerCertificates(); 140 } 141 142 @Override 143 public Certificate[] getLocalCertificates() { 144 return delegate.getLocalCertificates(); 145 } 146 147 @Override 148 public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException { 149 return delegate.getPeerCertificateChain(); 150 } 151 152 @Override 153 public Principal getPeerPrincipal() throws SSLPeerUnverifiedException { 154 return delegate.getPeerPrincipal(); 155 } 156 157 @Override 158 public Principal getLocalPrincipal() { 159 return delegate.getLocalPrincipal(); 160 } 161 162 @Override 163 public String getCipherSuite() { 164 return delegate.getCipherSuite(); 165 } 166 167 @Override 168 public String getProtocol() { 169 return delegate.getProtocol(); 170 } 171 172 @Override 173 public String getPeerHost() { 174 return delegate.getPeerHost(); 175 } 176 177 @Override 178 public int getPeerPort() { 179 return delegate.getPeerPort(); 180 } 181 182 @Override 183 public int getPacketBufferSize() { 184 return delegate.getPacketBufferSize(); 185 } 186 187 @Override 188 public int getApplicationBufferSize() { 189 return delegate.getApplicationBufferSize(); 190 } 191} 192