001/*
002 *   Licensed to the Apache Software Foundation (ASF) under one
003 *   or more contributor license agreements.  See the NOTICE file
004 *   distributed with this work for additional information
005 *   regarding copyright ownership.  The ASF licenses this file
006 *   to you under the Apache License, Version 2.0 (the
007 *   "License"); you may not use this file except in compliance
008 *   with the License.  You may obtain a copy of the License at
009 *
010 *     https://www.apache.org/licenses/LICENSE-2.0
011 *
012 *   Unless required by applicable law or agreed to in writing,
013 *   software distributed under the License is distributed on an
014 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *   KIND, either express or implied.  See the License for the
016 *   specific language governing permissions and limitations
017 *   under the License.
018 *
019 */
020
021package org.apache.directory.ldap.client.api;
022
023
024import java.net.Socket;
025import java.security.cert.CertificateException;
026import java.security.cert.X509Certificate;
027
028import javax.net.ssl.SSLEngine;
029import javax.net.ssl.X509ExtendedTrustManager;
030import javax.net.ssl.X509TrustManager;
031
032import org.apache.directory.api.i18n.I18n;
033import org.slf4j.Logger;
034import org.slf4j.LoggerFactory;
035
036
037/**
038 * An implementation of {@link X509TrustManager} which trusts the given certificates without verifying them.
039 *
040 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
041 */
042public class NoVerificationTrustManager extends X509ExtendedTrustManager
043{
044    /** The logger. */
045    private static final Logger LOG = LoggerFactory.getLogger( NoVerificationTrustManager.class );
046    
047    
048    /**
049     * {@inheritDoc}
050     */
051    @Override
052    public void checkClientTrusted( X509Certificate[] x509Certificates, String authType, Socket socket )
053        throws CertificateException 
054    {
055        if ( LOG.isDebugEnabled() )
056        {
057            LOG.debug( I18n.msg( I18n.MSG_04168_CHECK_CLIENT_TRUSTED, x509Certificates[0] ) );
058        }
059    }
060
061    
062    /**
063     * {@inheritDoc}
064     */
065    @Override
066    public void checkClientTrusted( X509Certificate[] x509Certificates, String authType, SSLEngine engine )
067        throws CertificateException 
068    {
069        if ( LOG.isDebugEnabled() )
070        {
071            LOG.debug( I18n.msg( I18n.MSG_04168_CHECK_CLIENT_TRUSTED, x509Certificates[0] ) );
072        }
073    }
074    
075    
076    public void checkServerTrusted( X509Certificate[] x509Certificates, String authType, Socket socket )
077        throws CertificateException 
078    {
079        if ( LOG.isDebugEnabled() )
080        {
081            LOG.debug( I18n.msg( I18n.MSG_04169_CHECK_SERVER_TRUSTED, x509Certificates[0] ) );
082        }
083    }
084
085    /**
086     * {@inheritDoc}
087     */
088    @Override
089    public void checkServerTrusted( X509Certificate[] x509Certificates, String authType, SSLEngine engine )
090        throws CertificateException 
091    {
092        if ( LOG.isDebugEnabled() )
093        {
094            LOG.debug( I18n.msg( I18n.MSG_04169_CHECK_SERVER_TRUSTED, x509Certificates[0] ) );
095        }
096    }
097
098
099    /**
100     * {@inheritDoc}
101     */
102    @Override
103    public void checkClientTrusted( X509Certificate[] x509Certificates, String s ) throws CertificateException
104    {
105        if ( LOG.isDebugEnabled() )
106        {
107            LOG.debug( I18n.msg( I18n.MSG_04168_CHECK_CLIENT_TRUSTED, x509Certificates[0] ) );
108        }
109    }
110
111
112    /**
113     * {@inheritDoc}
114     */
115    @Override
116    public void checkServerTrusted( X509Certificate[] x509Certificates, String s ) throws CertificateException
117    {
118        if ( LOG.isDebugEnabled() )
119        {
120            LOG.debug( I18n.msg( I18n.MSG_04169_CHECK_SERVER_TRUSTED, x509Certificates[0] ) );
121        }
122    }
123
124
125    /**
126     * {@inheritDoc}
127     */
128    @Override
129    public X509Certificate[] getAcceptedIssuers()
130    {
131        return new X509Certificate[0];
132    }
133}