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