src/org/gege/caldavsyncadapter/caldav/EasyX509TrustManager.java

Tue, 10 Feb 2015 18:12:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 10 Feb 2015 18:12:00 +0100
changeset 0
fb9019fb1bf7
permissions
-rw-r--r--

Import initial revisions of existing project AndroidCaldavSyncAdapater,
forked from upstream repository at 27e8a0f8495c92e0780d450bdf0c7cec77a03a55.

michael@0 1 /**
michael@0 2 * Copyright (c) 2012-2013, Gerald Garcia
michael@0 3 *
michael@0 4 * This file is part of Andoid Caldav Sync Adapter Free.
michael@0 5 *
michael@0 6 * Andoid Caldav Sync Adapter Free is free software: you can redistribute
michael@0 7 * it and/or modify it under the terms of the GNU General Public License
michael@0 8 * as published by the Free Software Foundation, either version 3 of the
michael@0 9 * License, or at your option any later version.
michael@0 10 *
michael@0 11 * Andoid Caldav Sync Adapter Free is distributed in the hope that
michael@0 12 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
michael@0 13 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
michael@0 14 * GNU General Public License for more details.
michael@0 15 *
michael@0 16 * You should have received a copy of the GNU General Public License
michael@0 17 * along with Andoid Caldav Sync Adapter Free.
michael@0 18 * If not, see <http://www.gnu.org/licenses/>.
michael@0 19 *
michael@0 20 */
michael@0 21
michael@0 22 package org.gege.caldavsyncadapter.caldav;
michael@0 23
michael@0 24 /*
michael@0 25 * Licensed to the Apache Software Foundation (ASF) under one
michael@0 26 * or more contributor license agreements. See the NOTICE file
michael@0 27 * distributed with this work for additional information
michael@0 28 * regarding copyright ownership. The ASF licenses this file
michael@0 29 * to you under the Apache License, Version 2.0 (the
michael@0 30 * "License"); you may not use this file except in compliance
michael@0 31 * with the License. You may obtain a copy of the License at
michael@0 32 *
michael@0 33 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 34 *
michael@0 35 * Unless required by applicable law or agreed to in writing,
michael@0 36 * software distributed under the License is distributed on an
michael@0 37 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
michael@0 38 * KIND, either express or implied. See the License for the
michael@0 39 * specific language governing permissions and limitations
michael@0 40 * under the License.
michael@0 41 */
michael@0 42
michael@0 43 import java.security.KeyStore;
michael@0 44 import java.security.KeyStoreException;
michael@0 45 import java.security.NoSuchAlgorithmException;
michael@0 46 import java.security.cert.CertificateException;
michael@0 47 import java.security.cert.X509Certificate;
michael@0 48
michael@0 49 import javax.net.ssl.TrustManager;
michael@0 50 import javax.net.ssl.TrustManagerFactory;
michael@0 51 import javax.net.ssl.X509TrustManager;
michael@0 52
michael@0 53 /**
michael@0 54 * @author olamy
michael@0 55 * @version $Id: EasyX509TrustManager.java 765355 2009-04-15 20:59:07Z evenisse $
michael@0 56 * @since 1.2.3
michael@0 57 */
michael@0 58 public class EasyX509TrustManager
michael@0 59 implements X509TrustManager
michael@0 60 {
michael@0 61
michael@0 62 private X509TrustManager standardTrustManager = null;
michael@0 63
michael@0 64 /**
michael@0 65 * Constructor for EasyX509TrustManager.
michael@0 66 */
michael@0 67 public EasyX509TrustManager( KeyStore keystore )
michael@0 68 throws NoSuchAlgorithmException, KeyStoreException
michael@0 69 {
michael@0 70 super();
michael@0 71 TrustManagerFactory factory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() );
michael@0 72 factory.init( keystore );
michael@0 73 TrustManager[] trustmanagers = factory.getTrustManagers();
michael@0 74 if ( trustmanagers.length == 0 )
michael@0 75 {
michael@0 76 throw new NoSuchAlgorithmException( "no trust manager found" );
michael@0 77 }
michael@0 78 this.standardTrustManager = (X509TrustManager) trustmanagers[0];
michael@0 79 }
michael@0 80
michael@0 81 /**
michael@0 82 * @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[],String authType)
michael@0 83 */
michael@0 84 public void checkClientTrusted( X509Certificate[] certificates, String authType )
michael@0 85 throws CertificateException
michael@0 86 {
michael@0 87 standardTrustManager.checkClientTrusted( certificates, authType );
michael@0 88 }
michael@0 89
michael@0 90 /**
michael@0 91 * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[],String authType)
michael@0 92 */
michael@0 93 public void checkServerTrusted( X509Certificate[] certificates, String authType )
michael@0 94 throws CertificateException
michael@0 95 {
michael@0 96 if ( ( certificates != null ) && ( certificates.length == 1 ) )
michael@0 97 {
michael@0 98 certificates[0].checkValidity();
michael@0 99 }
michael@0 100 else
michael@0 101 {
michael@0 102 standardTrustManager.checkServerTrusted( certificates, authType );
michael@0 103 }
michael@0 104 }
michael@0 105
michael@0 106 /**
michael@0 107 * @see javax.net.ssl.X509TrustManager#getAcceptedIssuers()
michael@0 108 */
michael@0 109 public X509Certificate[] getAcceptedIssuers()
michael@0 110 {
michael@0 111 return this.standardTrustManager.getAcceptedIssuers();
michael@0 112 }
michael@0 113
michael@0 114 }

mercurial