001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Boris V. Kuznetsov
020: * @version $Revision$
021: */package javax.net.ssl;
022:
023: import java.net.HttpURLConnection;
024: import java.net.URL;
025: import java.security.Principal;
026: import java.security.cert.Certificate;
027: import java.security.cert.X509Certificate;
028:
029: /**
030: * @com.intel.drl.spec_ref
031: *
032: */
033: public abstract class HttpsURLConnection extends HttpURLConnection {
034:
035: private static HostnameVerifier defaultHostnameVerifier = new DefaultHostnameVerifier();
036:
037: private static SSLSocketFactory defaultSSLSocketFactory = (SSLSocketFactory) SSLSocketFactory
038: .getDefault();
039:
040: protected HostnameVerifier hostnameVerifier;
041:
042: private static SSLSocketFactory socketFactory;
043:
044: protected HttpsURLConnection(URL url) {
045: super (url);
046: hostnameVerifier = defaultHostnameVerifier;
047: socketFactory = defaultSSLSocketFactory;
048: }
049:
050: public abstract String getCipherSuite();
051:
052: public abstract Certificate[] getLocalCertificates();
053:
054: public abstract Certificate[] getServerCertificates()
055: throws SSLPeerUnverifiedException;
056:
057: public Principal getPeerPrincipal()
058: throws SSLPeerUnverifiedException {
059: Certificate[] certs = getServerCertificates();
060: if (certs == null || certs.length == 0
061: || (!(certs[0] instanceof X509Certificate))) {
062: throw new SSLPeerUnverifiedException(
063: "No server's end-entity certificate");
064: }
065: return ((X509Certificate) certs[0]).getSubjectX500Principal();
066: }
067:
068: public Principal getLocalPrincipal() {
069: Certificate[] certs = getLocalCertificates();
070: if (certs == null || certs.length == 0
071: || (!(certs[0] instanceof X509Certificate))) {
072: return null;
073: }
074: return ((X509Certificate) certs[0]).getSubjectX500Principal();
075: }
076:
077: public static void setDefaultHostnameVerifier(HostnameVerifier v) {
078: if (v == null) {
079: throw new IllegalArgumentException(
080: "HostnameVerifier is null");
081: }
082: defaultHostnameVerifier = v;
083: }
084:
085: public static HostnameVerifier getDefaultHostnameVerifier() {
086: return defaultHostnameVerifier;
087: }
088:
089: public void setHostnameVerifier(HostnameVerifier v) {
090: if (v == null) {
091: throw new IllegalArgumentException(
092: "HostnameVerifier is null");
093: }
094: hostnameVerifier = v;
095: }
096:
097: public HostnameVerifier getHostnameVerifier() {
098: return hostnameVerifier;
099: }
100:
101: public static void setDefaultSSLSocketFactory(SSLSocketFactory sf) {
102: if (sf == null) {
103: throw new IllegalArgumentException(
104: "SSLSocketFactory is null");
105: }
106: defaultSSLSocketFactory = sf;
107: }
108:
109: public static SSLSocketFactory getDefaultSSLSocketFactory() {
110: return defaultSSLSocketFactory;
111: }
112:
113: public void setSSLSocketFactory(SSLSocketFactory sf) {
114: if (sf == null) {
115: throw new IllegalArgumentException(
116: "SSLSocketFactory is null");
117: }
118: socketFactory = sf;
119: }
120:
121: public SSLSocketFactory getSSLSocketFactory() {
122: return socketFactory;
123: }
124:
125: }
|