1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with this 4 * work for additional information regarding copyright ownership. The ASF 5 * licenses this file to You under the Apache License, Version 2.0 (the 6 * "License"); you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 * License for the specific language governing permissions and limitations under 15 * the License. 16 */ 17package com.squareup.okhttp.internal.tls; 18 19import java.security.Principal; 20import java.security.cert.Certificate; 21import javax.net.ssl.SSLPeerUnverifiedException; 22import javax.net.ssl.SSLSession; 23import javax.net.ssl.SSLSessionContext; 24import javax.security.cert.X509Certificate; 25 26final class FakeSSLSession implements SSLSession { 27 private final Certificate[] certificates; 28 29 public FakeSSLSession(Certificate... certificates) throws Exception { 30 this.certificates = certificates; 31 } 32 33 public int getApplicationBufferSize() { 34 throw new UnsupportedOperationException(); 35 } 36 37 public String getCipherSuite() { 38 throw new UnsupportedOperationException(); 39 } 40 41 public long getCreationTime() { 42 throw new UnsupportedOperationException(); 43 } 44 45 public byte[] getId() { 46 throw new UnsupportedOperationException(); 47 } 48 49 public long getLastAccessedTime() { 50 throw new UnsupportedOperationException(); 51 } 52 53 public Certificate[] getLocalCertificates() { 54 throw new UnsupportedOperationException(); 55 } 56 57 public Principal getLocalPrincipal() { 58 throw new UnsupportedOperationException(); 59 } 60 61 public int getPacketBufferSize() { 62 throw new UnsupportedOperationException(); 63 } 64 65 public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException { 66 if (certificates.length == 0) { 67 throw new SSLPeerUnverifiedException("peer not authenticated"); 68 } else { 69 return certificates; 70 } 71 } 72 73 public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException { 74 throw new UnsupportedOperationException(); 75 } 76 77 public String getPeerHost() { 78 throw new UnsupportedOperationException(); 79 } 80 81 public int getPeerPort() { 82 throw new UnsupportedOperationException(); 83 } 84 85 public Principal getPeerPrincipal() throws SSLPeerUnverifiedException { 86 throw new UnsupportedOperationException(); 87 } 88 89 public String getProtocol() { 90 throw new UnsupportedOperationException(); 91 } 92 93 public SSLSessionContext getSessionContext() { 94 throw new UnsupportedOperationException(); 95 } 96 97 public void putValue(String s, Object obj) { 98 throw new UnsupportedOperationException(); 99 } 100 101 public void removeValue(String s) { 102 throw new UnsupportedOperationException(); 103 } 104 105 public Object getValue(String s) { 106 throw new UnsupportedOperationException(); 107 } 108 109 public String[] getValueNames() { 110 throw new UnsupportedOperationException(); 111 } 112 113 public void invalidate() { 114 throw new UnsupportedOperationException(); 115 } 116 117 public boolean isValid() { 118 throw new UnsupportedOperationException(); 119 } 120} 121