1 package org.apache.maven.wagon.shared.http;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.http.conn.ssl.TrustStrategy;
23
24 import java.security.cert.CertificateException;
25 import java.security.cert.CertificateExpiredException;
26 import java.security.cert.CertificateNotYetValidException;
27 import java.security.cert.X509Certificate;
28
29
30
31
32
33
34
35 public class RelaxedTrustStrategy
36 implements TrustStrategy
37 {
38 private final boolean ignoreSSLValidityDates;
39
40 public RelaxedTrustStrategy( boolean ignoreSSLValidityDates )
41 {
42 this.ignoreSSLValidityDates = ignoreSSLValidityDates;
43 }
44
45 public boolean isTrusted( X509Certificate[] certificates, String authType )
46 throws CertificateException
47 {
48 if ( ( certificates != null ) && ( certificates.length > 0 ) )
49 {
50 for ( X509Certificate currentCertificate : certificates )
51 {
52 try
53 {
54 currentCertificate.checkValidity();
55 }
56 catch ( CertificateExpiredException e )
57 {
58 if ( !ignoreSSLValidityDates )
59 {
60 throw e;
61 }
62 }
63 catch ( CertificateNotYetValidException e )
64 {
65 if ( !ignoreSSLValidityDates )
66 {
67 throw e;
68 }
69 }
70 }
71 return true;
72 }
73 else
74 {
75 return false;
76 }
77 }
78
79 }