001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2006-2008 Sun Microsystems, Inc. 015 * Portions Copyright 2014-2015 ForgeRock AS. 016 */ 017package org.opends.server.extensions; 018 019 020 021import java.security.cert.X509Certificate; 022import javax.net.ssl.TrustManager; 023import javax.net.ssl.X509TrustManager; 024 025import org.opends.server.admin.std.server.BlindTrustManagerProviderCfg; 026import org.opends.server.api.TrustManagerProvider; 027import org.forgerock.opendj.config.server.ConfigException; 028import org.opends.server.types.DirectoryException; 029import org.opends.server.types.InitializationException; 030 031 032 033/** 034 * This class provides an implementation of a trust manager provider that will 035 * indicate that any certificate presented should be blindly trusted by the 036 * Directory Server. This can provide convenience and ease of use, but that 037 * added convenience will be at the expense of security and therefore it should 038 * not be used in environments in which the clients may not be considered 039 * trustworthy. 040 */ 041public class BlindTrustManagerProvider 042 extends TrustManagerProvider<BlindTrustManagerProviderCfg> 043 implements X509TrustManager 044{ 045 /** 046 * Creates a new instance of this blind trust manager provider. The 047 * <CODE>initializeTrustManagerProvider</CODE> method must be called on the 048 * resulting object before it may be used. 049 */ 050 public BlindTrustManagerProvider() 051 { 052 // No implementation is required. 053 } 054 055 056 057 /** {@inheritDoc} */ 058 @Override 059 public void initializeTrustManagerProvider( 060 BlindTrustManagerProviderCfg configuration) 061 throws ConfigException, InitializationException 062 { 063 // No implementation is required. 064 } 065 066 067 068 /** 069 * Performs any finalization that may be necessary for this trust manager 070 * provider. 071 */ 072 @Override 073 public void finalizeTrustManagerProvider() 074 { 075 // No implementation is required. 076 } 077 078 079 080 /** {@inheritDoc} */ 081 @Override 082 public TrustManager[] getTrustManagers() 083 throws DirectoryException 084 { 085 return new TrustManager[] { this }; 086 } 087 088 089 090 /** 091 * Determines whether an SSL client with the provided certificate chain should 092 * be trusted. In this case, all client certificates will be trusted. 093 * 094 * @param chain The certificate chain for the SSL client. 095 * @param authType The authentication type based on the client certificate. 096 */ 097 public void checkClientTrusted(X509Certificate[] chain, String authType) 098 { 099 // As long as we don't throw an exception, then the client certificate will 100 // be considered trusted. 101 } 102 103 104 105 /** 106 * Determines whether an SSL server with the provided certificate chain should 107 * be trusted. In this case, all server certificates will be trusted. 108 * 109 * @param chain The certificate chain for the SSL server. 110 * @param authType The key exchange algorithm used. 111 */ 112 public void checkServerTrusted(X509Certificate[] chain, String authType) 113 { 114 // As long as we don't throw an exception, then the server certificate will 115 // be considered trusted. 116 } 117 118 119 120 /** 121 * Retrieves the set of certificate authority certificates which are trusted 122 * for authenticating peers. 123 * 124 * @return An empty array, since we don't care what certificates are 125 * presented because we will trust them all. 126 */ 127 public X509Certificate[] getAcceptedIssuers() 128 { 129 return new X509Certificate[0]; 130 } 131} 132