1 /* 2 * Copyright 2014 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 17 package android.net.http; 18 19 import java.security.Principal; 20 import java.security.cert.Certificate; 21 import java.security.cert.X509Certificate; 22 23 import javax.net.ssl.SSLPeerUnverifiedException; 24 import javax.net.ssl.SSLSession; 25 import javax.net.ssl.SSLSessionContext; 26 import javax.net.ssl.SSLSocket; 27 import javax.net.ssl.X509TrustManager; 28 29 /** 30 * This is only used when a {@code certificate} is available but usage 31 * requires a {@link SSLSession}. 32 */ 33 public class DelegatingSSLSession implements SSLSession { DelegatingSSLSession()34 protected DelegatingSSLSession() { 35 } 36 37 public static class CertificateWrap extends DelegatingSSLSession { 38 private final Certificate mCertificate; 39 CertificateWrap(Certificate certificate)40 public CertificateWrap(Certificate certificate) { 41 mCertificate = certificate; 42 } 43 44 @Override getPeerCertificates()45 public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException { 46 return new Certificate[] { mCertificate }; 47 } 48 } 49 50 51 @Override getApplicationBufferSize()52 public int getApplicationBufferSize() { 53 throw new UnsupportedOperationException(); 54 } 55 56 @Override getCipherSuite()57 public String getCipherSuite() { 58 throw new UnsupportedOperationException(); 59 } 60 61 @Override getCreationTime()62 public long getCreationTime() { 63 throw new UnsupportedOperationException(); 64 } 65 66 @Override getId()67 public byte[] getId() { 68 throw new UnsupportedOperationException(); 69 } 70 71 @Override getLastAccessedTime()72 public long getLastAccessedTime() { 73 throw new UnsupportedOperationException(); 74 } 75 76 @Override getLocalCertificates()77 public Certificate[] getLocalCertificates() { 78 throw new UnsupportedOperationException(); 79 } 80 81 @Override getLocalPrincipal()82 public Principal getLocalPrincipal() { 83 throw new UnsupportedOperationException(); 84 } 85 86 @Override getPacketBufferSize()87 public int getPacketBufferSize() { 88 throw new UnsupportedOperationException(); 89 } 90 91 @Override getPeerCertificateChain()92 public javax.security.cert.X509Certificate[] getPeerCertificateChain() 93 throws SSLPeerUnverifiedException { 94 throw new UnsupportedOperationException(); 95 } 96 97 @Override getPeerCertificates()98 public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException { 99 throw new UnsupportedOperationException(); 100 } 101 102 @Override getPeerHost()103 public String getPeerHost() { 104 throw new UnsupportedOperationException(); 105 } 106 107 @Override getPeerPort()108 public int getPeerPort() { 109 throw new UnsupportedOperationException(); 110 } 111 112 @Override getPeerPrincipal()113 public Principal getPeerPrincipal() throws SSLPeerUnverifiedException { 114 throw new UnsupportedOperationException(); 115 } 116 117 @Override getProtocol()118 public String getProtocol() { 119 throw new UnsupportedOperationException(); 120 } 121 122 @Override getSessionContext()123 public SSLSessionContext getSessionContext() { 124 throw new UnsupportedOperationException(); 125 } 126 127 @Override getValue(String name)128 public Object getValue(String name) { 129 throw new UnsupportedOperationException(); 130 } 131 132 @Override getValueNames()133 public String[] getValueNames() { 134 throw new UnsupportedOperationException(); 135 } 136 137 @Override invalidate()138 public void invalidate() { 139 throw new UnsupportedOperationException(); 140 } 141 142 @Override isValid()143 public boolean isValid() { 144 throw new UnsupportedOperationException(); 145 } 146 147 @Override putValue(String name, Object value)148 public void putValue(String name, Object value) { 149 throw new UnsupportedOperationException(); 150 } 151 152 @Override removeValue(String name)153 public void removeValue(String name) { 154 throw new UnsupportedOperationException(); 155 } 156 } 157