Home | History | Annotate | Download | only in conscrypt
      1 /*
      2  * Copyright 2017 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.List;
     21 import javax.net.ssl.ExtendedSSLSession;
     22 import javax.net.ssl.SSLPeerUnverifiedException;
     23 import javax.net.ssl.SSLSessionContext;
     24 import javax.security.cert.X509Certificate;
     25 
     26 /**
     27  * This is an adapter that wraps the active session with {@link ExtendedSSLSession}, if running
     28  * on Java 7+.
     29  */
     30 class Java7ExtendedSSLSession extends ExtendedSSLSession implements SessionDecorator {
     31     // TODO: use BoringSSL API to actually fetch the real data
     32     private static final String[] LOCAL_SUPPORTED_SIGNATURE_ALGORITHMS = new String[] {
     33             "SHA512withRSA", "SHA512withECDSA", "SHA384withRSA", "SHA384withECDSA", "SHA256withRSA",
     34             "SHA256withECDSA", "SHA224withRSA", "SHA224withECDSA", "SHA1withRSA", "SHA1withECDSA",
     35     };
     36     // TODO: use BoringSSL API to actually fetch the real data
     37     private static final String[] PEER_SUPPORTED_SIGNATURE_ALGORITHMS =
     38             new String[] {"SHA1withRSA", "SHA1withECDSA"};
     39     private final ConscryptSession delegate;
     40 
     41     Java7ExtendedSSLSession(ConscryptSession delegate) {
     42         this.delegate = delegate;
     43     }
     44 
     45     @Override
     46     public final ConscryptSession getDelegate() {
     47         return delegate;
     48     }
     49 
     50     /* @Override */
     51     @SuppressWarnings("MissingOverride") // For Android backward-compatibility.
     52     public final String[] getLocalSupportedSignatureAlgorithms() {
     53         return LOCAL_SUPPORTED_SIGNATURE_ALGORITHMS.clone();
     54     }
     55 
     56     /* @Override */
     57     @SuppressWarnings("MissingOverride") // For Android backward-compatibility.
     58     public final String[] getPeerSupportedSignatureAlgorithms() {
     59         return PEER_SUPPORTED_SIGNATURE_ALGORITHMS.clone();
     60     }
     61 
     62     @Override
     63     public final String getRequestedServerName() {
     64         return getDelegate().getRequestedServerName();
     65     }
     66 
     67     /**
     68      * Provides forward-compatibility with Java 9.
     69      */
     70     @Override
     71     public final List<byte[]> getStatusResponses() {
     72         return getDelegate().getStatusResponses();
     73     }
     74 
     75     @Override
     76     public final byte[] getPeerSignedCertificateTimestamp() {
     77         return getDelegate().getPeerSignedCertificateTimestamp();
     78     }
     79 
     80     @Override
     81     public final byte[] getId() {
     82         return getDelegate().getId();
     83     }
     84 
     85     @Override
     86     public final SSLSessionContext getSessionContext() {
     87         return getDelegate().getSessionContext();
     88     }
     89 
     90     @Override
     91     public final long getCreationTime() {
     92         return getDelegate().getCreationTime();
     93     }
     94 
     95     @Override
     96     public final long getLastAccessedTime() {
     97         return getDelegate().getLastAccessedTime();
     98     }
     99 
    100     @Override
    101     public final void invalidate() {
    102         getDelegate().invalidate();
    103     }
    104 
    105     @Override
    106     public final boolean isValid() {
    107         return getDelegate().isValid();
    108     }
    109 
    110     @Override
    111     public final void putValue(String s, Object o) {
    112         getDelegate().putValue(s, o);
    113     }
    114 
    115     @Override
    116     public final Object getValue(String s) {
    117         return getDelegate().getValue(s);
    118     }
    119 
    120     @Override
    121     public final void removeValue(String s) {
    122         getDelegate().removeValue(s);
    123     }
    124 
    125     @Override
    126     public final String[] getValueNames() {
    127         return getDelegate().getValueNames();
    128     }
    129 
    130     @Override
    131     public java.security.cert.X509Certificate[] getPeerCertificates()
    132         throws SSLPeerUnverifiedException {
    133         return getDelegate().getPeerCertificates();
    134     }
    135 
    136     @Override
    137     public final Certificate[] getLocalCertificates() {
    138         return getDelegate().getLocalCertificates();
    139     }
    140 
    141     @Override
    142     public final X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException {
    143         return getDelegate().getPeerCertificateChain();
    144     }
    145 
    146     @Override
    147     public final Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
    148         return getDelegate().getPeerPrincipal();
    149     }
    150 
    151     @Override
    152     public final Principal getLocalPrincipal() {
    153         return getDelegate().getLocalPrincipal();
    154     }
    155 
    156     @Override
    157     public final String getCipherSuite() {
    158         return getDelegate().getCipherSuite();
    159     }
    160 
    161     @Override
    162     public final String getProtocol() {
    163         return getDelegate().getProtocol();
    164     }
    165 
    166     @Override
    167     public final String getPeerHost() {
    168         return getDelegate().getPeerHost();
    169     }
    170 
    171     @Override
    172     public final int getPeerPort() {
    173         return getDelegate().getPeerPort();
    174     }
    175 
    176     @Override
    177     public final int getPacketBufferSize() {
    178         return getDelegate().getPacketBufferSize();
    179     }
    180 
    181     @Override
    182     public final int getApplicationBufferSize() {
    183         return getDelegate().getApplicationBufferSize();
    184     }
    185 }
    186