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 * http://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 */ 020package org.apache.mina.filter.ssl; 021 022import java.security.InvalidAlgorithmParameterException; 023import java.security.KeyStore; 024import java.security.KeyStoreException; 025import java.security.Provider; 026import java.security.cert.CertificateException; 027import java.security.cert.X509Certificate; 028 029import javax.net.ssl.ManagerFactoryParameters; 030import javax.net.ssl.TrustManager; 031import javax.net.ssl.TrustManagerFactory; 032import javax.net.ssl.TrustManagerFactorySpi; 033import javax.net.ssl.X509TrustManager; 034 035/** 036 * Bogus {@link javax.net.ssl.TrustManagerFactory} which creates 037 * {@link javax.net.ssl.X509TrustManager} trusting everything. 038 * 039 * @author <a href="http://mina.apache.org">Apache MINA Project</a> 040 */ 041public class BogusTrustManagerFactory extends TrustManagerFactory { 042 043 public BogusTrustManagerFactory() { 044 super(new BogusTrustManagerFactorySpi(), new Provider("MinaBogus", 1.0, "") { 045 private static final long serialVersionUID = -4024169055312053827L; 046 }, "MinaBogus"); 047 } 048 049 private static final X509TrustManager X509 = new X509TrustManager() { 050 public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { 051 // Do nothing 052 } 053 054 public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { 055 // Do nothing 056 } 057 058 public X509Certificate[] getAcceptedIssuers() { 059 return new X509Certificate[0]; 060 } 061 }; 062 063 private static final TrustManager[] X509_MANAGERS = new TrustManager[] { X509 }; 064 065 private static class BogusTrustManagerFactorySpi extends TrustManagerFactorySpi { 066 067 @Override 068 protected TrustManager[] engineGetTrustManagers() { 069 return X509_MANAGERS; 070 } 071 072 @Override 073 protected void engineInit(KeyStore keystore) throws KeyStoreException { 074 // noop 075 } 076 077 @Override 078 protected void engineInit(ManagerFactoryParameters managerFactoryParameters) 079 throws InvalidAlgorithmParameterException { 080 // noop 081 } 082 083 } 084}