1 /* ownCloud webDAV Library for Android is available under MIT license
2 * Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 package com
.owncloud
.android
.oc_framework
.network
;
27 import java
.security
.cert
.CertPathValidatorException
;
28 import java
.security
.cert
.CertificateException
;
29 import java
.security
.cert
.CertificateExpiredException
;
30 import java
.security
.cert
.CertificateNotYetValidException
;
31 import java
.security
.cert
.X509Certificate
;
33 import javax
.net
.ssl
.SSLPeerUnverifiedException
;
36 * Exception joining all the problems that {@link AdvancedX509TrustManager} can find in
37 * a certificate chain for a server.
39 * This was initially created as an extension of CertificateException, but some
40 * implementations of the SSL socket layer in existing devices are REPLACING the CertificateException
41 * instances thrown by {@link javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[], String)}
42 * with SSLPeerUnverifiedException FORGETTING THE CAUSING EXCEPTION instead of wrapping it.
44 * Due to this, extending RuntimeException is necessary to get that the CertificateCombinedException
45 * instance reaches {@link AdvancedSslSocketFactory#verifyPeerIdentity}.
47 * BE CAREFUL. As a RuntimeException extensions, Java compilers do not require to handle it
48 * in client methods. Be sure to use it only when you know exactly where it will go.
50 * @author David A. Velasco
52 public class CertificateCombinedException
extends RuntimeException
{
54 /** Generated - to refresh every time the class changes */
55 private static final long serialVersionUID
= -8875782030758554999L;
57 private X509Certificate mServerCert
= null
;
58 private String mHostInUrl
;
60 private CertificateExpiredException mCertificateExpiredException
= null
;
61 private CertificateNotYetValidException mCertificateNotYetValidException
= null
;
62 private CertPathValidatorException mCertPathValidatorException
= null
;
63 private CertificateException mOtherCertificateException
= null
;
64 private SSLPeerUnverifiedException mSslPeerUnverifiedException
= null
;
66 public CertificateCombinedException(X509Certificate x509Certificate
) {
67 mServerCert
= x509Certificate
;
70 public X509Certificate
getServerCertificate() {
74 public String
getHostInUrl() {
78 public void setHostInUrl(String host
) {
82 public CertificateExpiredException
getCertificateExpiredException() {
83 return mCertificateExpiredException
;
86 public void setCertificateExpiredException(CertificateExpiredException c
) {
87 mCertificateExpiredException
= c
;
90 public CertificateNotYetValidException
getCertificateNotYetValidException() {
91 return mCertificateNotYetValidException
;
94 public void setCertificateNotYetException(CertificateNotYetValidException c
) {
95 mCertificateNotYetValidException
= c
;
98 public CertPathValidatorException
getCertPathValidatorException() {
99 return mCertPathValidatorException
;
102 public void setCertPathValidatorException(CertPathValidatorException c
) {
103 mCertPathValidatorException
= c
;
106 public CertificateException
getOtherCertificateException() {
107 return mOtherCertificateException
;
110 public void setOtherCertificateException(CertificateException c
) {
111 mOtherCertificateException
= c
;
114 public SSLPeerUnverifiedException
getSslPeerUnverifiedException() {
115 return mSslPeerUnverifiedException
;
118 public void setSslPeerUnverifiedException(SSLPeerUnverifiedException s
) {
119 mSslPeerUnverifiedException
= s
;
122 public boolean isException() {
123 return (mCertificateExpiredException
!= null
||
124 mCertificateNotYetValidException
!= null
||
125 mCertPathValidatorException
!= null
||
126 mOtherCertificateException
!= null
||
127 mSslPeerUnverifiedException
!= null
);
130 public boolean isRecoverable() {
131 return (mCertificateExpiredException
!= null
||
132 mCertificateNotYetValidException
!= null
||
133 mCertPathValidatorException
!= null
||
134 mSslPeerUnverifiedException
!= null
);