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 public class OpenSSLExtendedSessionImpl extends ExtendedSSLSession { 34 private final OpenSSLSessionImpl delegate; 35 36 public OpenSSLExtendedSessionImpl(OpenSSLSessionImpl delegate) { 37 this.delegate = delegate; 38 } 39 40 public OpenSSLSessionImpl getDelegate() { 41 return delegate; 42 } 43 44 public String[] getLocalSupportedSignatureAlgorithms() { 45 // From src/ssl/t1_lib.c tls12_sigalgs 46 // TODO: use BoringSSL API to actually fetch the real data 47 return new String[] { 48 "SHA512withRSA", 49 "SHA512withECDSA", 50 "SHA384withRSA", 51 "SHA384withECDSA", 52 "SHA256withRSA", 53 "SHA256withECDSA", 54 "SHA224withRSA", 55 "SHA224withECDSA", 56 "SHA1withRSA", 57 "SHA1withECDSA", 58 }; 59 } 60 61 public String[] getPeerSupportedSignatureAlgorithms() { 62 // TODO: use BoringSSL API to actually fetch the real data 63 return new String[] { 64 "SHA1withRSA", 65 "SHA1withECDSA", 66 }; 67 } 68 69 public List<SNIServerName> getRequestedServerNames() { 70 String requestedServerName = delegate.getRequestedServerName(); 71 if (requestedServerName == null) { 72 return null; 73 } 74 75 return Collections.<SNIServerName> singletonList(new SNIHostName(requestedServerName)); 76 } 77 78 @Override 79 public byte[] getId() { 80 return delegate.getId(); 81 } 82 83 @Override 84 public SSLSessionContext getSessionContext() { 85 return delegate.getSessionContext(); 86 } 87 88 @Override 89 public long getCreationTime() { 90 return delegate.getCreationTime(); 91 } 92 93 @Override 94 public long getLastAccessedTime() { 95 return delegate.getLastAccessedTime(); 96 } 97 98 @Override 99 public void invalidate() { 100 delegate.invalidate(); 101 } 102 103 @Override 104 public boolean isValid() { 105 return delegate.isValid(); 106 } 107 108 @Override 109 public void putValue(String name, Object value) { 110 delegate.putValue(name, value); 111 } 112 113 @Override 114 public Object getValue(String name) { 115 return delegate.getValue(name); 116 } 117 118 @Override 119 public void removeValue(String name) { 120 delegate.removeValue(name); 121 } 122 123 @Override 124 public String[] getValueNames() { 125 return delegate.getValueNames(); 126 } 127 128 @Override 129 public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException { 130 return delegate.getPeerCertificates(); 131 } 132 133 @Override 134 public Certificate[] getLocalCertificates() { 135 return delegate.getLocalCertificates(); 136 } 137 138 @Override 139 public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException { 140 return delegate.getPeerCertificateChain(); 141 } 142 143 @Override 144 public Principal getPeerPrincipal() throws SSLPeerUnverifiedException { 145 return delegate.getPeerPrincipal(); 146 } 147 148 @Override 149 public Principal getLocalPrincipal() { 150 return delegate.getLocalPrincipal(); 151 } 152 153 @Override 154 public String getCipherSuite() { 155 return delegate.getCipherSuite(); 156 } 157 158 @Override 159 public String getProtocol() { 160 return delegate.getProtocol(); 161 } 162 163 @Override 164 public String getPeerHost() { 165 return delegate.getPeerHost(); 166 } 167 168 @Override 169 public int getPeerPort() { 170 return delegate.getPeerPort(); 171 } 172 173 @Override 174 public int getPacketBufferSize() { 175 return delegate.getPacketBufferSize(); 176 } 177 178 @Override 179 public int getApplicationBufferSize() { 180 return delegate.getApplicationBufferSize(); 181 } 182 } 183