1 /* ownCloud Android client application 
   2  *   Copyright (C) 2012 Bartek Przybylski 
   4  *   This program is free software: you can redistribute it and/or modify 
   5  *   it under the terms of the GNU General Public License as published by 
   6  *   the Free Software Foundation, either version 3 of the License, or 
   7  *   (at your option) any later version. 
   9  *   This program is distributed in the hope that it will be useful, 
  10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of 
  11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  12  *   GNU General Public License for more details. 
  14  *   You should have received a copy of the GNU General Public License 
  15  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. 
  19 package com
.owncloud
.android
.network
; 
  21 import java
.security
.cert
.CertPathValidatorException
; 
  22 import java
.security
.cert
.CertificateException
; 
  23 import java
.security
.cert
.CertificateExpiredException
; 
  24 import java
.security
.cert
.CertificateNotYetValidException
; 
  25 import java
.security
.cert
.X509Certificate
; 
  27 import javax
.net
.ssl
.SSLPeerUnverifiedException
; 
  30  * Exception joining all the problems that {@link AdvancedX509TrustManager} can find in 
  31  * a certificate chain for a server. 
  33  * This was initially created as an extension of CertificateException, but some 
  34  * implementations of the SSL socket layer in existing devices are REPLACING the CertificateException 
  35  * instances thrown by {@link javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[], String)} 
  36  * with SSLPeerUnverifiedException FORGETTING THE CAUSING EXCEPTION instead of wrapping it.  
  38  * Due to this, extending RuntimeException is necessary to get that the CertificateCombinedException  
  39  * instance reaches {@link AdvancedSslSocketFactory#verifyPeerIdentity}. 
  41  * BE CAREFUL. As a RuntimeException extensions, Java compilers do not require to handle it 
  42  * in client methods. Be sure to use it only when you know exactly where it will go. 
  44  * @author David A. Velasco 
  46 public class CertificateCombinedException 
extends RuntimeException 
{ 
  49     private static final long serialVersionUID 
= -8875782030758554999L; 
  51     private X509Certificate mServerCert 
= null
; 
  52     private String mHostInUrl
; 
  54     private CertificateExpiredException mCertificateExpiredException 
= null
; 
  55     private CertificateNotYetValidException mCertificateNotYetValidException 
= null
; 
  56     private CertPathValidatorException mCertPathValidatorException 
= null
; 
  57     private CertificateException mOtherCertificateException 
= null
; 
  58     private SSLPeerUnverifiedException mSslPeerUnverifiedException 
= null
; 
  60     public CertificateCombinedException(X509Certificate x509Certificate
) { 
  61         mServerCert 
= x509Certificate
; 
  64     public X509Certificate 
getServerCertificate() { 
  68     public String 
getHostInUrl() { 
  72     public void setHostInUrl(String host
) { 
  76     public CertificateExpiredException 
getCertificateExpiredException() { 
  77         return mCertificateExpiredException
; 
  80     public void setCertificateExpiredException(CertificateExpiredException c
) { 
  81         mCertificateExpiredException  
= c
; 
  84     public CertificateNotYetValidException 
getCertificateNotYetValidException() { 
  85         return mCertificateNotYetValidException
; 
  88     public void setCertificateNotYetException(CertificateNotYetValidException c
) { 
  89         mCertificateNotYetValidException 
= c
; 
  92     public CertPathValidatorException 
getCertPathValidatorException() { 
  93         return mCertPathValidatorException
; 
  96     public void setCertPathValidatorException(CertPathValidatorException c
) { 
  97         mCertPathValidatorException 
= c
; 
 100     public CertificateException 
getOtherCertificateException() { 
 101         return mOtherCertificateException
; 
 104     public void setOtherCertificateException(CertificateException c
) { 
 105         mOtherCertificateException 
= c
; 
 108     public SSLPeerUnverifiedException 
getSslPeerUnverifiedException() { 
 109         return mSslPeerUnverifiedException 
;  
 112     public void setSslPeerUnverifiedException(SSLPeerUnverifiedException s
) { 
 113         mSslPeerUnverifiedException 
= s
; 
 116     public boolean isException() { 
 117         return (mCertificateExpiredException 
!= null 
|| 
 118                 mCertificateNotYetValidException 
!= null 
|| 
 119                 mCertPathValidatorException 
!= null 
|| 
 120                 mOtherCertificateException 
!= null 
|| 
 121                 mSslPeerUnverifiedException 
!= null
); 
 124     public boolean isRecoverable() { 
 125         return (mCertificateExpiredException 
!= null 
|| 
 126                 mCertificateNotYetValidException 
!= null 
|| 
 127                 mCertPathValidatorException 
!= null 
|| 
 128                 mSslPeerUnverifiedException 
!= null
);