1 package eu
.alefzero
.owncloud
.authenticator
; 
   4  * Licensed to the Apache Software Foundation (ASF) under one 
   5  * or more contributor license agreements.  See the NOTICE file 
   6  * distributed with this work for additional information 
   7  * regarding copyright ownership.  The ASF licenses this file 
   8  * to you under the Apache License, Version 2.0 (the 
   9  * "License"); you may not use this file except in compliance 
  10  * with the License.  You may obtain a copy of the License at 
  12  *   http://www.apache.org/licenses/LICENSE-2.0 
  14  * Unless required by applicable law or agreed to in writing, 
  15  * software distributed under the License is distributed on an 
  16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
  17  * KIND, either express or implied.  See the License for the 
  18  * specific language governing permissions and limitations 
  22 import java
.security
.KeyStore
; 
  23 import java
.security
.KeyStoreException
; 
  24 import java
.security
.NoSuchAlgorithmException
; 
  25 import java
.security
.cert
.CertificateException
; 
  26 import java
.security
.cert
.X509Certificate
; 
  28 import javax
.net
.ssl
.TrustManager
; 
  29 import javax
.net
.ssl
.TrustManagerFactory
; 
  30 import javax
.net
.ssl
.X509TrustManager
; 
  34  * @version $Id: EasyX509TrustManager.java 765355 2009-04-15 20:59:07Z evenisse 
  38 public class EasyX509TrustManager 
implements X509TrustManager 
{ 
  40     private X509TrustManager standardTrustManager 
= null
; 
  43      * Constructor for EasyX509TrustManager. 
  45     public EasyX509TrustManager(KeyStore keystore
) 
  46             throws NoSuchAlgorithmException
, KeyStoreException 
{ 
  48         TrustManagerFactory factory 
= TrustManagerFactory
 
  49                 .getInstance(TrustManagerFactory
.getDefaultAlgorithm()); 
  50         factory
.init(keystore
); 
  51         TrustManager
[] trustmanagers 
= factory
.getTrustManagers(); 
  52         if (trustmanagers
.length 
== 0) { 
  53             throw new NoSuchAlgorithmException("no trust manager found"); 
  55         this.standardTrustManager 
= (X509TrustManager
) trustmanagers
[0]; 
  59      * @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[], 
  62     public void checkClientTrusted(X509Certificate
[] certificates
, 
  63             String authType
) throws CertificateException 
{ 
  64         standardTrustManager
.checkClientTrusted(certificates
, authType
); 
  68      * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[], 
  71     public void checkServerTrusted(X509Certificate
[] certificates
, 
  72             String authType
) throws CertificateException 
{ 
  73         if ((certificates 
!= null
) && (certificates
.length 
== 1)) { 
  74             certificates
[0].checkValidity(); 
  76             // standardTrustManager.checkServerTrusted( certificates, authType 
  82      * @see javax.net.ssl.X509TrustManager#getAcceptedIssuers() 
  84     public X509Certificate
[] getAcceptedIssuers() { 
  85         return this.standardTrustManager
.getAcceptedIssuers();