Home | History | Annotate | Download | only in ssl
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  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,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 package javax.net.ssl;
     19 
     20 import java.security.Principal;
     21 import java.security.cert.Certificate;
     22 import java.util.EventObject;
     23 import javax.security.cert.X509Certificate;
     24 
     25 /**
     26  * The event object encapsulating the information about a completed SSL
     27  * handshake on a SSL connection.
     28  */
     29 public class HandshakeCompletedEvent extends EventObject {
     30 
     31     private transient SSLSession session;
     32 
     33     /**
     34      * Creates a new {@code HandshakeCompletedEvent} with the specified SSL
     35      * socket and SSL session.
     36      *
     37      * @param sock
     38      *            the SSL socket.
     39      * @param s
     40      *            the SSL session.
     41      */
     42     public HandshakeCompletedEvent(SSLSocket sock, SSLSession s) {
     43         super(sock);
     44         session = s;
     45     }
     46 
     47     /**
     48      * Returns the SSL session associated with this event.
     49      *
     50      * @return the SSL session associated with this event.
     51      */
     52     public SSLSession getSession() {
     53         return session;
     54     }
     55 
     56     /**
     57      * Returns the name of the cipher suite negotiated during this handshake.
     58      *
     59      * @return the name of the cipher suite negotiated during this handshake.
     60      */
     61     public String getCipherSuite() {
     62         return session.getCipherSuite();
     63     }
     64 
     65     /**
     66      * Returns the list of local certificates used during the handshake. These
     67      * certificates were sent to the peer.
     68      *
     69      * @return Returns the list of certificates used during the handshake with
     70      *         the local identity certificate followed by CAs, or {@code null}
     71      *         if no certificates were used during the handshake.
     72      */
     73     public Certificate[] getLocalCertificates() {
     74         return session.getLocalCertificates();
     75     }
     76 
     77     /**
     78      * Return the list of certificates identifying the peer during the
     79      * handshake.
     80      *
     81      * @return the list of certificates identifying the peer with the peer's
     82      *         identity certificate followed by CAs.
     83      * @throws SSLPeerUnverifiedException
     84      *             if the identity of the peer has not been verified.
     85      */
     86     public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException {
     87         return session.getPeerCertificates();
     88     }
     89 
     90     /**
     91      * Returns the list of certificates identifying the peer. The peer's
     92      * identity certificate is followed by the validated certificate authority
     93      * certificates.
     94      * <p>
     95      * <b>Replaced by:</b> {@link #getPeerCertificates()}
     96      *
     97      * @return the list of certificates identifying the peer
     98      * @throws SSLPeerUnverifiedException
     99      *             if the identity of the peer has not been verified.
    100      */
    101     public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException {
    102         return session.getPeerCertificateChain();
    103     }
    104 
    105     /**
    106      * Returns the {@code Principal} identifying the peer.
    107      *
    108      * @return the {@code Principal} identifying the peer.
    109      * @throws SSLPeerUnverifiedException
    110      *             if the identity of the peer has not been verified.
    111      */
    112     public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
    113         return session.getPeerPrincipal();
    114     }
    115 
    116     /**
    117      * Returns the {@code Principal} used to identify during the handshake.
    118      *
    119      * @return the {@code Principal} used to identify during the handshake.
    120      */
    121     public Principal getLocalPrincipal() {
    122         return session.getLocalPrincipal();
    123     }
    124 
    125     /**
    126      * Returns the SSL socket that produced this event.
    127      *
    128      * @return the SSL socket that produced this event.
    129      */
    130     public SSLSocket getSocket() {
    131         return (SSLSocket) this.source;
    132     }
    133 
    134 }
    135