michael@0: /** michael@0: * Copyright (c) 2012-2013, Gerald Garcia michael@0: * michael@0: * This file is part of Andoid Caldav Sync Adapter Free. michael@0: * michael@0: * Andoid Caldav Sync Adapter Free is free software: you can redistribute michael@0: * it and/or modify it under the terms of the GNU General Public License michael@0: * as published by the Free Software Foundation, either version 3 of the michael@0: * License, or at your option any later version. michael@0: * michael@0: * Andoid Caldav Sync Adapter Free is distributed in the hope that michael@0: * it will be useful, but WITHOUT ANY WARRANTY; without even the implied michael@0: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the michael@0: * GNU General Public License for more details. michael@0: * michael@0: * You should have received a copy of the GNU General Public License michael@0: * along with Andoid Caldav Sync Adapter Free. michael@0: * If not, see . michael@0: * michael@0: */ michael@0: michael@0: package org.gege.caldavsyncadapter.caldav; michael@0: michael@0: /* michael@0: * Licensed to the Apache Software Foundation (ASF) under one michael@0: * or more contributor license agreements. See the NOTICE file michael@0: * distributed with this work for additional information michael@0: * regarding copyright ownership. The ASF licenses this file michael@0: * to you under the Apache License, Version 2.0 (the michael@0: * "License"); you may not use this file except in compliance michael@0: * with the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, michael@0: * software distributed under the License is distributed on an michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY michael@0: * KIND, either express or implied. See the License for the michael@0: * specific language governing permissions and limitations michael@0: * under the License. michael@0: */ michael@0: michael@0: import java.security.KeyStore; michael@0: import java.security.KeyStoreException; michael@0: import java.security.NoSuchAlgorithmException; michael@0: import java.security.cert.CertificateException; michael@0: import java.security.cert.X509Certificate; michael@0: michael@0: import javax.net.ssl.TrustManager; michael@0: import javax.net.ssl.TrustManagerFactory; michael@0: import javax.net.ssl.X509TrustManager; michael@0: michael@0: /** michael@0: * @author olamy michael@0: * @version $Id: EasyX509TrustManager.java 765355 2009-04-15 20:59:07Z evenisse $ michael@0: * @since 1.2.3 michael@0: */ michael@0: public class EasyX509TrustManager michael@0: implements X509TrustManager michael@0: { michael@0: michael@0: private X509TrustManager standardTrustManager = null; michael@0: michael@0: /** michael@0: * Constructor for EasyX509TrustManager. michael@0: */ michael@0: public EasyX509TrustManager( KeyStore keystore ) michael@0: throws NoSuchAlgorithmException, KeyStoreException michael@0: { michael@0: super(); michael@0: TrustManagerFactory factory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() ); michael@0: factory.init( keystore ); michael@0: TrustManager[] trustmanagers = factory.getTrustManagers(); michael@0: if ( trustmanagers.length == 0 ) michael@0: { michael@0: throw new NoSuchAlgorithmException( "no trust manager found" ); michael@0: } michael@0: this.standardTrustManager = (X509TrustManager) trustmanagers[0]; michael@0: } michael@0: michael@0: /** michael@0: * @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[],String authType) michael@0: */ michael@0: public void checkClientTrusted( X509Certificate[] certificates, String authType ) michael@0: throws CertificateException michael@0: { michael@0: standardTrustManager.checkClientTrusted( certificates, authType ); michael@0: } michael@0: michael@0: /** michael@0: * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[],String authType) michael@0: */ michael@0: public void checkServerTrusted( X509Certificate[] certificates, String authType ) michael@0: throws CertificateException michael@0: { michael@0: if ( ( certificates != null ) && ( certificates.length == 1 ) ) michael@0: { michael@0: certificates[0].checkValidity(); michael@0: } michael@0: else michael@0: { michael@0: standardTrustManager.checkServerTrusted( certificates, authType ); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * @see javax.net.ssl.X509TrustManager#getAcceptedIssuers() michael@0: */ michael@0: public X509Certificate[] getAcceptedIssuers() michael@0: { michael@0: return this.standardTrustManager.getAcceptedIssuers(); michael@0: } michael@0: michael@0: }