| 1 |
/* |
| 2 |
* Copyright 1999-2010 University of Chicago |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 11 |
* express or implied. |
| 12 |
* |
| 13 |
* See the License for the specific language governing permissions and limitations under the License. |
| 14 |
*/ |
| 15 |
package org.globus.gsi.proxy; |
| 16 |
|
| 17 |
import org.globus.common.CoGProperties; |
| 18 |
|
| 19 |
import org.globus.gsi.util.CertificateLoadUtil; |
| 20 |
|
| 21 |
import org.globus.gsi.trustmanager.CRLChecker; |
| 22 |
import org.globus.gsi.trustmanager.CertificateChecker; |
| 23 |
import org.globus.gsi.trustmanager.DateValidityChecker; |
| 24 |
import org.globus.gsi.trustmanager.IdentityChecker; |
| 25 |
import org.globus.gsi.trustmanager.SigningPolicyChecker; |
| 26 |
import org.globus.gsi.trustmanager.UnsupportedCriticalExtensionChecker; |
| 27 |
import org.globus.gsi.trustmanager.X509ProxyCertPathValidator; |
| 28 |
|
| 29 |
import org.globus.gsi.X509Credential; |
| 30 |
|
| 31 |
import java.util.ArrayList; |
| 32 |
import java.util.List; |
| 33 |
import org.apache.commons.logging.Log; |
| 34 |
import org.apache.commons.logging.LogFactory; |
| 35 |
import java.util.Map; |
| 36 |
import javax.security.auth.x500.X500Principal; |
| 37 |
import java.security.cert.CertPathValidatorException; |
| 38 |
import java.security.cert.CertPath; |
| 39 |
import java.io.ByteArrayInputStream; |
| 40 |
import java.io.InputStream; |
| 41 |
import java.io.StringReader; |
| 42 |
import java.security.cert.X509Certificate; |
| 43 |
import java.security.cert.X509CRL; |
| 44 |
import org.globus.gsi.GSIConstants; |
| 45 |
import org.globus.gsi.TrustedCertificates; |
| 46 |
import org.globus.gsi.SigningPolicy; |
| 47 |
import org.globus.gsi.SigningPolicyParser; |
| 48 |
import org.globus.gsi.CertificateRevocationLists; |
| 49 |
import org.globus.gsi.proxy.ProxyPolicyHandler; |
| 50 |
import org.globus.gsi.proxy.ProxyPathValidator; |
| 51 |
import org.globus.gsi.proxy.ProxyPathValidatorException; |
| 52 |
import org.globus.gsi.proxy.ext.ProxyCertInfo; |
| 53 |
import org.globus.gsi.proxy.ext.ProxyPolicy; |
| 54 |
|
| 55 |
import junit.framework.TestCase; |
| 56 |
|
| 57 |
public class ProxyPathValidatorTest extends TestCase { |
| 58 |
|
| 59 |
private static Log log = LogFactory.getLog(ProxyPathValidatorTest.class); |
| 60 |
public static final String BASE = "validatorTest/"; |
| 61 |
|
| 62 |
public static String[] crlNames = { "ca2crl.r0", "testca3.r0" }; |
| 63 |
|
| 64 |
public static String[][] certs = { |
| 65 |
{GSIConstants.CertificateType.CA.name(), "TestCA1.pem"}, |
| 66 |
{GSIConstants.CertificateType.EEC.name(), "eecFromTestCA1.pem"}, |
| 67 |
{GSIConstants.CertificateType.GSI_2_PROXY.name(), "gsi2fullproxy.pem"}, |
| 68 |
{GSIConstants.CertificateType.GSI_2_LIMITED_PROXY.name(), "gsi2limitedproxy.pem"}, |
| 69 |
// 4, double GSIConstants.CertificateType.GSI_2_LIMITED_PROXY), gsi2limited2xproxy.pem (issued by |
| 70 |
// 3) |
| 71 |
{GSIConstants.CertificateType.GSI_2_LIMITED_PROXY.name(), "gsi2limited2xproxy.pem"}, |
| 72 |
// 5, GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY), gsi3impersonationproxy.pem |
| 73 |
{GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY.name(), "gsi3impersonationproxy.pem"}, |
| 74 |
// 6, GSIConstants.CertificateType.GSI_3_INDEPENDENT_PROXY), gsi3independentproxy.pem |
| 75 |
{GSIConstants.CertificateType.GSI_3_INDEPENDENT_PROXY.name(), "gsi3independentproxy.pem"}, |
| 76 |
// 7, GSIConstants.CertificateType.GSI_3_LIMITED_PROXY), gsi3limitedproxy.pem |
| 77 |
{GSIConstants.CertificateType.GSI_3_LIMITED_PROXY.name(), "gsi3limitedproxy.pem"}, |
| 78 |
// 8, GSIConstants.CertificateType.GSI_3_RESTRICTED_PROXY), gsi3restrictedproxy.pem |
| 79 |
{GSIConstants.CertificateType.GSI_3_RESTRICTED_PROXY.name(), "gsi3restrictedproxy.pem"}, |
| 80 |
// double |
| 81 |
// 9, GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY), gsi3impersonation2xproxy.pem |
| 82 |
{GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY.name(), "gsi3impersonation2xproxy.pem"}, |
| 83 |
// 10, GSIConstants.CertificateType.GSI_3_INDEPENDENT_PROXY), gsi3independent2xproxy.pem |
| 84 |
{GSIConstants.CertificateType.GSI_3_INDEPENDENT_PROXY.name(), "gsi3independent2xproxy.pem"}, |
| 85 |
// pathLen = 0 |
| 86 |
// 11, GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY), gsi3impersonationp0proxy.pem |
| 87 |
{GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY.name(), "gsi3impersonationp0proxy.pem"}, |
| 88 |
// pathLen = 1 |
| 89 |
// 12, GSIConstants.CertificateType.GSI_3_INDEPENDENT_PROXY), gsi2independentp1proxy.pem |
| 90 |
{GSIConstants.CertificateType.GSI_3_INDEPENDENT_PROXY.name(), "gsi3independentp1proxy.pem"}, |
| 91 |
// pathLen = 2 |
| 92 |
// 13, GSIConstants.CertificateType.CA), |
| 93 |
{GSIConstants.CertificateType.CA.name(), "testca.pem"}, |
| 94 |
// 14, GSIConstants.CertificateType.EEC) |
| 95 |
{GSIConstants.CertificateType.EEC.name(), "testeec1.pem"}, |
| 96 |
// 15, GSIConstants.CertificateType.EEC) |
| 97 |
{GSIConstants.CertificateType.EEC.name(), "testeec2.pem"}, |
| 98 |
// pathLen = 1 |
| 99 |
// 16, GSIConstants.CertificateType.CA) |
| 100 |
{GSIConstants.CertificateType.CA.name(), "testca2.pem"}, // crl for this, 16 |
| 101 |
// 17, GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY), |
| 102 |
{GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY.name(), "testgsi3proxy.pem"}, |
| 103 |
// for CRL test |
| 104 |
// 18, GSIConstants.CertificateType.CA), |
| 105 |
{GSIConstants.CertificateType.CA.name(), "testca3.pem"}, |
| 106 |
// 19, GSIConstants.CertificateType.EEC), |
| 107 |
{GSIConstants.CertificateType.EEC.name(), "crl_usercert.pem"}, |
| 108 |
// 20, GSIConstants.CertificateType.GSI_2_PROXY), |
| 109 |
{GSIConstants.CertificateType.GSI_2_PROXY.name(), "crl_proxy.pem"}, |
| 110 |
// 21 (all good) |
| 111 |
// GSIConstants.CertificateType.CA) |
| 112 |
{GSIConstants.CertificateType.CA.name(), "ca1cert.pem"}, |
| 113 |
// 22, GSIConstants.CertificateType.EEC |
| 114 |
{GSIConstants.CertificateType.EEC.name(), "user1ca1.pem"}, |
| 115 |
// 23, GSIConstants.CertificateType.EEC) |
| 116 |
{GSIConstants.CertificateType.EEC.name(), "user2ca1.pem"}, |
| 117 |
// 24, GSIConstants.CertificateType.EEC) |
| 118 |
{GSIConstants.CertificateType.EEC.name(), "user3ca1.pem"}, |
| 119 |
// 25 |
| 120 |
// GSIConstants.CertificateType.CA) |
| 121 |
{GSIConstants.CertificateType.CA.name(), "ca2cert.pem"}, // crl 25 |
| 122 |
// must be revoked (in ca2crl.r0) |
| 123 |
// 26, GSIConstants.CertificateType.EEC) |
| 124 |
{GSIConstants.CertificateType.EEC.name(), "user1ca2.pem"}, |
| 125 |
// must be revoked (in ca2crl.r0) |
| 126 |
// 27, GSIConstants.CertificateType.EEC), |
| 127 |
{GSIConstants.CertificateType.EEC.name(), "user2ca2.pem"}, |
| 128 |
// 28, GSIConstants.CertificateType.EEC) |
| 129 |
{GSIConstants.CertificateType.EEC.name(), "user3ca2.pem"}, |
| 130 |
// 29 |
| 131 |
// gsi3 limited impersonation signs a gsi3 independent |
| 132 |
{GSIConstants.CertificateType.GSI_3_INDEPENDENT_PROXY.name(), "gsi3independentFromLimitedProxy.pem"}, |
| 133 |
// 30 |
| 134 |
// gsi3 limited impersonation signs a gsi3 impersonation |
| 135 |
{GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY.name(), "gsi3limitedimpersonation2xproxy.pem"}, |
| 136 |
// 31 |
| 137 |
// gsi3 independent signs a gsi3 impersonation |
| 138 |
{GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY.name(), "gsi3impersonationFromIndependentProxy.pem"}, |
| 139 |
// 32 |
| 140 |
// gsi3 pathlength 0 impersonatipon proxy signs proxy |
| 141 |
{GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY.name(), "gsi3FromPathZeroProxy.pem"}, |
| 142 |
// 33 |
| 143 |
// gsi3 path length 1 independent proxy signs proxy |
| 144 |
{GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY.name(), "gsi3FromPathOneProxy.pem"}, |
| 145 |
// 34 |
| 146 |
// gsi3FrompathOneProxy signs proxy |
| 147 |
{GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY.name(), "gsi3FromPathOneIssuedProxy.pem"}, |
| 148 |
// 35 |
| 149 |
// gsi2 proxy generated from gsi3impersonationProxy |
| 150 |
{GSIConstants.CertificateType.GSI_2_PROXY.name(), "gsi2proxyFromgsi3.pem"}, |
| 151 |
// 36 |
| 152 |
// gsi3 proxy generated from gsi2fullproxy |
| 153 |
{GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY.name(), "gsi3proxyFromgsi2.pem" }}; |
| 154 |
|
| 155 |
public static String[] badCerts = { |
| 156 |
"-----BEGIN CERTIFICATE-----\n" + "MIICFTCCAX6gAwIBAgIDClb3MA0GCSqGSIb3DQEBBAUAMGIxCzAJBgNVBAYTAlVT\n" |
| 157 |
+ "M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AeFw0wMjEyMTgw\n" |
| 171 |
+ "NzIxMThaFw0wMjEyMTgxOTI2MThaMHIxCzAJBgNVBAYTAlVTMQ8wDQYDVQQKEwZH\n" |
| 172 |
+ "bG9idXMxJDAiBgNVBAoTG0FyZ29ubmUgTmF0aW9uYWwgTGFib3JhdG9yeTEMMAoG\n" |
| 173 |
+ "A1UECxMDTUNTMQ4wDAYDVQQDEwVnYXdvcjEOMAwGA1UEAxMFcHJveHkwWjANBgkq\n" |
| 174 |
+ "hkiG9w0BAQEFAANJADBGAkEAx2fp80b+Yo0zCwjYJdIjzn0N3ezzcD2h2bAr/Nop\n" |
| 175 |
+ "w/H6JB4heiVGMeydMlSJHyI7J/s5l8k39G/KVrBGT9tRJwIBETANBgkqhkiG9w0B\n" |
| 176 |
+ "AQQFAAOBgQCRRvTdW6Ddn1curWm515l/GoAoJ76XBFJWfusIZ9TdwE8hlkRpK9Bd\n" |
| 177 |
+ "Rrao4Z2YO+e3UItn45Hs+8gzx+jBB1AduTUor603Z8AXaNbF/c+gz62lBWlcmZ2Y\n" |
| 178 |
+ "LzuUWgwZLd9HdA2YBgCcT3B9VFmBxcnPjGOwWT29ZUtyy2GXFtzcDw==\n" |
| 179 |
+ "-----END CERTIFICATE-----" }; |
| 180 |
|
| 181 |
public static String[] testCerts = { |
| 182 |
"-----BEGIN CERTIFICATE-----\n" |
| 183 |
+ "MIIB7zCCAVigAwIBAgICAbowDQYJKoZIhvcNAQEEBQAwVzEbMBkGA1UEChMSZG9l\n" |
| 184 |
+ "c2NpZW5jZWdyaWQub3JnMQ8wDQYDVQQLEwZQZW9wbGUxJzAlBgNVBAMTHlZpamF5\n" |
| 185 |
+ "YSBMYWtzaG1pIE5hdGFyYWphbiAxNzkwODAeFw0wMzAxMTcyMjExMjJaFw0wMzAx\n" |
| 186 |
+ "MTgxMDE2MjJaMGcxGzAZBgNVBAoTEmRvZXNjaWVuY2VncmlkLm9yZzEPMA0GA1UE\n" |
| 187 |
+ "CxMGUGVvcGxlMScwJQYDVQQDEx5WaWpheWEgTGFrc2htaSBOYXRhcmFqYW4gMTc5\n" |
| 188 |
+ "MDgxDjAMBgNVBAMTBXByb3h5MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANGP+xct\n" |
| 189 |
+ "lDYMPm11QKnACvqs95fbPRehvUi6/dizZ+VrDOU1OTUoXA0t6HRgtmJ8XthEUKxU\n" |
| 190 |
+ "MVsxjXtoZOzfuFECAwEAATANBgkqhkiG9w0BAQQFAAOBgQBqFTcN/qqvTnyI4z26\n" |
| 191 |
+ "lv1lMTuRIjL9l6Ug/Kwxuzjpl088INky1myFPjKsWMYzh9nXIQg9gg2dJTno5JHB\n" |
| 192 |
+ "++u0Fw2iNrTjswu4hvqYZn+LoSGchH2XyCUssuOWCbW4IkN8/Xzfre2oC2EieECC\n" |
| 193 |
+ "w+jjGhcqPrxvkHh8xXYroqA0Sg==\n" |
| 194 |
+ "-----END CERTIFICATE-----", |
| 195 |
"-----BEGIN CERTIFICATE-----\n" |
| 196 |
+ "MIIDLDCCAhSgAwIBAgICAbowDQYJKoZIhvcNAQEFBQAwdTETMBEGCgmSJomT8ixk\n" |
| 197 |
+ "ARkWA25ldDESMBAGCgmSJomT8ixkARkWAmVzMSAwHgYDVQQLExdDZXJ0aWZpY2F0\n" |
| 198 |
+ "ZSBBdXRob3JpdGllczEZMBcGA1UECxMQRE9FIFNjaWVuY2UgR3JpZDENMAsGA1UE\n" |
| 199 |
+ "AxMEcGtpMTAeFw0wMjA5MjMyMzQ2NDRaFw0wMzA5MjMyMzQ2NDRaMFcxGzAZBgNV\n" |
| 200 |
+ "BAoTEmRvZXNjaWVuY2VncmlkLm9yZzEPMA0GA1UECxMGUGVvcGxlMScwJQYDVQQD\n" |
| 201 |
+ "Ex5WaWpheWEgTGFrc2htaSBOYXRhcmFqYW4gMTc5MDgwgZ8wDQYJKoZIhvcNAQEB\n" |
| 202 |
+ "BQADgY0AMIGJAoGBAORYHsPQU3yVlTsC/29CDoEYF82PV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 231 |
+ "ZXJ0aWZpY2F0ZSBBdXRob3JpdGllczEcMBoGA1UEAxMTQ2VydGlmaWNhdGUgTWFu\n" |
| 232 |
+ "YWdlcjCB5AYDVR0gBIHcMIHZMIHWBgoqhkiG90wDBgQBMIHHMF8GCCsGAQUFBwIC\n" |
| 233 |
+ "MFMwJhYfRVNuZXQgKEVuZXJneSBTY2llbmNlcyBOZXR3b3JrKTADAgEBGilFU25l\n" |
| 234 |
+ "dC1ET0UgU2NpZW5jZSBHcmlkIENlcnRpZmljYXRlIFBvbGljeTBkBggrBgEFBQcC\n" |
| 235 |
+ "ARZYaHR0cDovL2VudmlzYWdlLmVzLm5ldC9FbnZpc2FnZSUyMERvY3MvRE9FU0cl\n" |
| 236 |
+ "MjBDQSUyMENlcnRpZmljYXRlJTIwUG9saWN5JTIwYW5kJTIwQ1BTLnBkZjANBgkq\n" |
| 237 |
+ "hkiG9w0BAQUFAAOBgQCaAdUregqwmCJG6j/h6uK2bTpcfa/SfpaYwsTy+zlf5r4P\n" |
| 238 |
+ "iY/wIRN0ZjJ4RrJQ/WUH16onNwb87JnYe0V4JYhATAOnp/5y9kl+iC4XvHBioVxm\n" |
| 239 |
+ "3sEADL40WAVREWBGZnyFqysXAEGfk+Wg7um5FzCwi6380GASKY0VujQG03f6Pg==\n" |
| 240 |
+ "-----END CERTIFICATE-----" |
| 241 |
}; |
| 242 |
|
| 243 |
// Globus CA signing policy. Using globusca.pem and usercert.pem |
| 244 |
public static String signingPolicy = "access_id_CA X509 '/C=TestCA1/CN=CA'\npos_rights globus CA:sign\ncond_subjects globus '\"/*\"'"; |
| 245 |
|
| 246 |
// Globus CA signing policy that causes usercert.pem to violate |
| 247 |
// the policy |
| 248 |
public static String signingPolicyViolation = "access_id_CA X509 '/C=TestCA1/CN=CA'\npos_rights globus CA:sign\ncond_subjects globus '\"/12*\"'"; |
| 249 |
|
| 250 |
// Globus CA signing policy without relevant signing policy |
| 251 |
public static String signingPolicySansPolicy = "# Globus CA rights\naccess_id_CA nonX509 '/C=US/O=Globus/CN=Globus Certification Authority'\npos_rights globus CA:sign\ncond_subjects globus '\"/C=usa/O=Globus/*\" \"/C=USA/O=Globus/*\"'\n# End of ca-signing-policy.conf"; |
| 252 |
|
| 253 |
public static X509Certificate[] goodCertsArr; |
| 254 |
|
| 255 |
static { |
| 256 |
try { |
| 257 |
goodCertsArr = initCerts(); |
| 258 |
} catch (Exception e) { |
| 259 |
throw new RuntimeException("Failed to load certs: " + e.getMessage()); |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
public ProxyPathValidatorTest(String name) { |
| 264 |
super(name); |
| 265 |
} |
| 266 |
|
| 267 |
public static X509Certificate[] initCerts() throws Exception { |
| 268 |
CoGProperties.getDefault().setProperty(CoGProperties.getDefault().CRL_CACHE_LIFETIME, "1"); |
| 269 |
|
| 270 |
X509Certificate[] goodCertsArr = new X509Certificate[certs.length]; |
| 271 |
ClassLoader loader = ProxyPathValidatorTest.class.getClassLoader(); |
| 272 |
for (int i = 0; i < certs.length; i++) { |
| 273 |
String name = BASE + certs[i][1]; |
| 274 |
InputStream in = loader.getResourceAsStream(name); |
| 275 |
if (in == null) { |
| 276 |
throw new Exception("Unable to load: " + name); |
| 277 |
} |
| 278 |
log.debug("goodCertsArr[" + i + "]" + name); |
| 279 |
goodCertsArr[i] = CertificateLoadUtil.loadCertificate(in); |
| 280 |
} |
| 281 |
return goodCertsArr; |
| 282 |
} |
| 283 |
|
| 284 |
public void testValidateGsi2PathGood() throws Exception { |
| 285 |
|
| 286 |
X509Certificate[] chain = null; |
| 287 |
X509Certificate[] trustedCerts = new X509Certificate[] { goodCertsArr[0] }; |
| 288 |
|
| 289 |
// EEC, CA |
| 290 |
chain = new X509Certificate[] { goodCertsArr[1], goodCertsArr[0] }; |
| 291 |
validateChain(chain, trustedCerts, goodCertsArr[1], false); |
| 292 |
|
| 293 |
// proxy, EEC, CA |
| 294 |
chain = new X509Certificate[] { goodCertsArr[2], goodCertsArr[1], goodCertsArr[0] }; |
| 295 |
validateChain(chain, trustedCerts, goodCertsArr[1], false); |
| 296 |
|
| 297 |
// limited proxy, EEC, CA |
| 298 |
chain = new X509Certificate[] { goodCertsArr[3], goodCertsArr[1], goodCertsArr[0] }; |
| 299 |
validateChain(chain, trustedCerts, goodCertsArr[1], true); |
| 300 |
|
| 301 |
// double limited proxy, limited proxy, EEC, CA |
| 302 |
chain = new X509Certificate[] { goodCertsArr[4], goodCertsArr[3], goodCertsArr[1], goodCertsArr[0] }; |
| 303 |
|
| 304 |
validateChain(chain, trustedCerts, goodCertsArr[1], true); |
| 305 |
} |
| 306 |
|
| 307 |
public void testValidateGsi3PathGood() throws Exception { |
| 308 |
|
| 309 |
X509Certificate[] chain = null; |
| 310 |
X509Certificate[] trustedCerts = new X509Certificate[] { goodCertsArr[0] }; |
| 311 |
|
| 312 |
// GSI 3 PC impersonation, EEC, CA |
| 313 |
chain = new X509Certificate[] { goodCertsArr[5], goodCertsArr[1], goodCertsArr[0] }; |
| 314 |
validateChain(chain, trustedCerts, goodCertsArr[1], false); |
| 315 |
|
| 316 |
// GSI 3 PC independent, EEC, CA |
| 317 |
chain = new X509Certificate[] { goodCertsArr[6], goodCertsArr[1], goodCertsArr[0] }; |
| 318 |
validateChain(chain, trustedCerts, goodCertsArr[6], false); |
| 319 |
|
| 320 |
// GSI 3 PC imperson limited, EEC, CA |
| 321 |
chain = new X509Certificate[] { goodCertsArr[7], goodCertsArr[1], goodCertsArr[0] }; |
| 322 |
validateChain(chain, trustedCerts, goodCertsArr[1], true); |
| 323 |
|
| 324 |
// GSI 3 PC impersonation, GSI 3 PC limited impersonation, EEC, CA |
| 325 |
chain = new X509Certificate[] { goodCertsArr[30], goodCertsArr[7], goodCertsArr[1], goodCertsArr[0] }; |
| 326 |
validateChain(chain, trustedCerts, goodCertsArr[1], true); |
| 327 |
|
| 328 |
// GSI 3 PC impersonation, GSI 3 PC impersonation, EEC, CA |
| 329 |
chain = new X509Certificate[] { goodCertsArr[9], goodCertsArr[5], goodCertsArr[1], goodCertsArr[0] }; |
| 330 |
validateChain(chain, trustedCerts, goodCertsArr[1], false); |
| 331 |
|
| 332 |
// GSI 3 PC indepedent, GSI 3 PC independent, EEC, CA |
| 333 |
chain = new X509Certificate[] { goodCertsArr[10], goodCertsArr[6], goodCertsArr[1], goodCertsArr[0] }; |
| 334 |
validateChain(chain, trustedCerts, goodCertsArr[10], false); |
| 335 |
|
| 336 |
// GSI 3 PC impersonation, GSI 3 PC independent, EEC, CA |
| 337 |
chain = new X509Certificate[] { goodCertsArr[31], goodCertsArr[6], goodCertsArr[1], goodCertsArr[0] }; |
| 338 |
validateChain(chain, trustedCerts, goodCertsArr[6], false); |
| 339 |
|
| 340 |
// GSI 3 PC indepedent, GSI 3 PC limited impersonation, EEC, CA |
| 341 |
chain = new X509Certificate[] { goodCertsArr[29], goodCertsArr[7], goodCertsArr[1], goodCertsArr[0] }; |
| 342 |
validateChain(chain, trustedCerts, goodCertsArr[29], false); |
| 343 |
} |
| 344 |
|
| 345 |
public void testValidatePathWithRestrictedProxy() throws Exception { |
| 346 |
|
| 347 |
X509Certificate[] chain = null; |
| 348 |
X509Certificate[] trustedCerts = new X509Certificate[] { goodCertsArr[0] }; |
| 349 |
|
| 350 |
// GSI 3 PC restricted, EEC, CA |
| 351 |
chain = new X509Certificate[] { goodCertsArr[8], goodCertsArr[1], goodCertsArr[0] }; |
| 352 |
validateError(chain, trustedCerts, ProxyPathValidatorException.UNKNOWN_POLICY); |
| 353 |
|
| 354 |
// // GSI 3 PC impersonation, GSI 3 PC restricted, EEC, CA |
| 355 |
chain = new X509Certificate[] { goodCertsArr[9], goodCertsArr[8], goodCertsArr[1], goodCertsArr[0] }; |
| 356 |
validateError(chain, trustedCerts, ProxyPathValidatorException.UNKNOWN_POLICY); |
| 357 |
|
| 358 |
TestProxyPathValidator v = new TestProxyPathValidator(); |
| 359 |
v.setProxyPolicyHandler("1.3.6.1.4.1.3536.1.1.1.8", new ProxyPolicyHandler() { |
| 360 |
public void validate(ProxyCertInfo info, CertPath path, int index) throws CertPathValidatorException { |
| 361 |
ProxyPolicy policy = info.getProxyPolicy(); |
| 362 |
String pol = policy.getPolicyAsString(); |
| 363 |
assertEquals("<AllPermissions...>\r\n".trim(), pol.trim()); |
| 364 |
// COMMENT fails without trimming |
| 365 |
} |
| 366 |
}); |
| 367 |
chain = new X509Certificate[] { goodCertsArr[8], goodCertsArr[1], goodCertsArr[0] }; |
| 368 |
v.validate(chain, trustedCerts); |
| 369 |
} |
| 370 |
|
| 371 |
public void testValidatePathBad() throws Exception { |
| 372 |
X509Certificate[] chain = null; |
| 373 |
X509Certificate[] trustedCerts = new X509Certificate[] { goodCertsArr[0] }; |
| 374 |
|
| 375 |
// proxy, CA |
| 376 |
chain = new X509Certificate[] { goodCertsArr[5], goodCertsArr[0] }; |
| 377 |
validateChain(chain, trustedCerts); |
| 378 |
|
| 379 |
// user, proxy, CA |
| 380 |
chain = new X509Certificate[] { goodCertsArr[1], goodCertsArr[2], goodCertsArr[0] }; |
| 381 |
validateChain(chain, trustedCerts); |
| 382 |
|
| 383 |
// user, user, CA |
| 384 |
chain = new X509Certificate[] { goodCertsArr[1], goodCertsArr[1], goodCertsArr[0] }; |
| 385 |
validateChain(chain, trustedCerts); |
| 386 |
|
| 387 |
// user, CA, user |
| 388 |
chain = new X509Certificate[] { goodCertsArr[1], goodCertsArr[0], goodCertsArr[1] }; |
| 389 |
validateChain(chain, trustedCerts); |
| 390 |
} |
| 391 |
|
| 392 |
public void testValidatePathMixedProxy() throws Exception { |
| 393 |
X509Certificate[] chain = null; |
| 394 |
X509Certificate[] trustedCerts = new X509Certificate[] { goodCertsArr[0] }; |
| 395 |
|
| 396 |
// GSI 3 PC, GSI 2 PC, EEC, CA |
| 397 |
chain = new X509Certificate[] { goodCertsArr[6], goodCertsArr[2], goodCertsArr[1], goodCertsArr[0] }; |
| 398 |
validateChain(chain, trustedCerts); |
| 399 |
|
| 400 |
// GSI 2 PC, GSI 3 PC, EEC, CA |
| 401 |
chain = new X509Certificate[] { goodCertsArr[2], goodCertsArr[6], goodCertsArr[1], goodCertsArr[0] }; |
| 402 |
validateChain(chain, trustedCerts); |
| 403 |
} |
| 404 |
|
| 405 |
public void testValidatePathProxyPathConstraint() throws Exception { |
| 406 |
X509Certificate[] chain = null; |
| 407 |
X509Certificate[] trustedCerts = new X509Certificate[] { goodCertsArr[0] }; |
| 408 |
|
| 409 |
// GSI 3 PC pathlen=0, GSI 3 PC, EEC, CA |
| 410 |
chain = new X509Certificate[] { goodCertsArr[11], goodCertsArr[1], goodCertsArr[0] }; |
| 411 |
validateChain(chain, trustedCerts, goodCertsArr[1], false); |
| 412 |
|
| 413 |
// GSI 3 PC, GSI 3 PC pathlen=0, EEC, CA |
| 414 |
chain = new X509Certificate[] { goodCertsArr[32], goodCertsArr[11], goodCertsArr[1], goodCertsArr[0] }; |
| 415 |
validateChain(chain, trustedCerts); |
| 416 |
|
| 417 |
// GSI 3 PC, GSI 3 PC pathlen=1, EEC, CA |
| 418 |
chain = new X509Certificate[] { goodCertsArr[33], goodCertsArr[12], goodCertsArr[1], goodCertsArr[0] }; |
| 419 |
validateChain(chain, trustedCerts, goodCertsArr[12], false); |
| 420 |
|
| 421 |
// GSI 3 PC, GSI 3 PC, GSI 3 PC pathlen=1, EEC, CA |
| 422 |
chain = new X509Certificate[] { goodCertsArr[34], goodCertsArr[33], goodCertsArr[12], goodCertsArr[1], |
| 423 |
goodCertsArr[0] }; |
| 424 |
validateError(chain, trustedCerts, ProxyPathValidatorException.PATH_LENGTH_EXCEEDED); |
| 425 |
} |
| 426 |
|
| 427 |
public void testValidatePathCAPathConstraint() throws Exception { |
| 428 |
X509Certificate[] chain = null; |
| 429 |
X509Certificate[] trustedCerts = new X509Certificate[] { goodCertsArr[16] }; |
| 430 |
|
| 431 |
// should all be OK |
| 432 |
|
| 433 |
// EEC, CA (pathlen=0) |
| 434 |
chain = new X509Certificate[] { goodCertsArr[15], goodCertsArr[16] }; |
| 435 |
validateChain(chain, trustedCerts, goodCertsArr[15], false); |
| 436 |
|
| 437 |
// GSI 2 limited PC, EEC, CA (pathlen=0) |
| 438 |
chain = new X509Certificate[] { goodCertsArr[3], goodCertsArr[15], goodCertsArr[16] }; |
| 439 |
//validateChain(chain, trustedCerts, goodCertsArr[15], true); |
| 440 |
validateError(chain, trustedCerts, ProxyPathValidatorException.PATH_LENGTH_EXCEEDED); |
| 441 |
|
| 442 |
// GSI 3 PC, EEC, CA (pathlen=0) |
| 443 |
chain = new X509Certificate[] { goodCertsArr[17], goodCertsArr[15], goodCertsArr[16] }; |
| 444 |
validateChain(chain, trustedCerts, goodCertsArr[15], false); |
| 445 |
|
| 446 |
// GSI 3 PC, EEC, CA (pathlen=0), CA (pathlen=2), CA (pathlen=2) |
| 447 |
chain = new X509Certificate[] { goodCertsArr[17], goodCertsArr[15], goodCertsArr[16], goodCertsArr[13], |
| 448 |
goodCertsArr[13] }; |
| 449 |
validateChain(chain, trustedCerts, goodCertsArr[15], false); |
| 450 |
|
| 451 |
// these should fail |
| 452 |
|
| 453 |
// EEC, CA (pathlen=0), CA (pathlen=0) |
| 454 |
chain = new X509Certificate[] { goodCertsArr[15], goodCertsArr[16], goodCertsArr[16] }; |
| 455 |
validateError(chain, trustedCerts, ProxyPathValidatorException.PATH_LENGTH_EXCEEDED); |
| 456 |
|
| 457 |
// GSI 2 limited PC, EEC, CA (pathlen=0), CA (pathlen=2), CA (pathlen=2), CA (pathlen=2) |
| 458 |
chain = new X509Certificate[] { goodCertsArr[3], goodCertsArr[15], goodCertsArr[16], goodCertsArr[13], |
| 459 |
goodCertsArr[13], goodCertsArr[13] }; |
| 460 |
validateError(chain, trustedCerts, ProxyPathValidatorException.PATH_LENGTH_EXCEEDED); |
| 461 |
|
| 462 |
// GSI 3 PC, GSI 3 PC pathlen=1, EEC, CA |
| 463 |
chain = new X509Certificate[] { goodCertsArr[10/*10*/], goodCertsArr[12], goodCertsArr[1], goodCertsArr[13] }; |
| 464 |
//validateChain(chain, trustedCerts, goodCertsArr[10/*10*/], false); |
| 465 |
validateError(chain, trustedCerts, ProxyPathValidatorException.PATH_LENGTH_EXCEEDED); |
| 466 |
|
| 467 |
// GSI 3 PC, GSI 3 PC, GSI 3 PC pathlen=1, EEC, CA |
| 468 |
chain = new X509Certificate[] { goodCertsArr[10], goodCertsArr[10], goodCertsArr[12], goodCertsArr[1], |
| 469 |
goodCertsArr[13] }; |
| 470 |
validateError(chain, trustedCerts, ProxyPathValidatorException.PATH_LENGTH_EXCEEDED); |
| 471 |
|
| 472 |
// GSI 3 PC, GSI 3 PC pathlen=0, EEC, CA |
| 473 |
chain = new X509Certificate[] { goodCertsArr[10], goodCertsArr[11], goodCertsArr[1], goodCertsArr[13] }; |
| 474 |
validateError(chain, trustedCerts, ProxyPathValidatorException.FAILURE); |
| 475 |
} |
| 476 |
|
| 477 |
public void testKeyUsage() throws Exception { |
| 478 |
X509Certificate[] certsArr = new X509Certificate[testCerts.length]; |
| 479 |
|
| 480 |
for (int i = 0; i < certsArr.length; i++) { |
| 481 |
certsArr[i] = CertificateLoadUtil.loadCertificate( |
| 482 |
new ByteArrayInputStream(testCerts[i].getBytes())); |
| 483 |
} |
| 484 |
X509Certificate[] trustedCAs = new X509Certificate[]{certsArr[2]}; |
| 485 |
X509Certificate[] chain = null; |
| 486 |
|
| 487 |
// certArr[1] - has key usage but certSign is off - but it signs proxy |
| 488 |
// certArr[2] - has key usage and certSign is on |
| 489 |
chain = new X509Certificate[] { certsArr[0], certsArr[1], certsArr[2] }; |
| 490 |
validateChain(chain, trustedCAs, certsArr[1], false); |
| 491 |
|
| 492 |
TestProxyPathValidator v = new TestProxyPathValidator(); |
| 493 |
v.validate(chain, new TrustedCertificates(trustedCAs)); |
| 494 |
assertEquals(false, v.isLimited()); |
| 495 |
assertEquals(certsArr[1], v.getIdentityCertificate()); |
| 496 |
|
| 497 |
} |
| 498 |
|
| 499 |
public void testNoBasicConstraintsExtension() throws Exception { |
| 500 |
X509Certificate[] chain = null; |
| 501 |
X509Certificate[] trustedCAs = new X509Certificate[] { goodCertsArr[16] }; |
| 502 |
X509Certificate[] trustedCerts = new X509Certificate[] { goodCertsArr[16] }; |
| 503 |
// EEC, EEC, CA - that should fail |
| 504 |
//chain = new X509Certificate[] { goodCertsArr[1], goodCertsArr[1], goodCertsArr[0] }; |
| 505 |
chain = new X509Certificate[] { goodCertsArr[15], goodCertsArr[15], goodCertsArr[16] }; |
| 506 |
//validateChain(chain, trustedCerts, goodCertsArr[15], false); |
| 507 |
|
| 508 |
validateChain(chain, trustedCAs); |
| 509 |
|
| 510 |
|
| 511 |
TestProxyPathValidator v = new TestProxyPathValidator(); |
| 512 |
TrustedCertificates trustedCert = new TrustedCertificates(new X509Certificate[] { goodCertsArr[16] }, |
| 513 |
new SigningPolicy[] { new SigningPolicy(new X500Principal("CN=foo"), new String[] { "CN=foo" }) }); |
| 514 |
|
| 515 |
//X509Certificate[] trustedCerts = new X509Certificate[] { goodCertsArr[1] }; |
| 516 |
chain = new X509Certificate[] { goodCertsArr[16], goodCertsArr[16], goodCertsArr[0] }; |
| 517 |
// this makes the PathValidator think the chain is: |
| 518 |
// CA, CA, CA - which is ok. irrelevant to signing policy. |
| 519 |
try { |
| 520 |
|
| 521 |
v.validate(chain, trustedCert); |
| 522 |
|
| 523 |
} catch (ProxyPathValidatorException e) { |
| 524 |
e.printStackTrace(); |
| 525 |
fail("Unexpected exception: " + e.getMessage()); |
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
//JGLOBUS-103 |
| 530 |
public void testCrlsChecks() throws Exception { |
| 531 |
|
| 532 |
TestProxyPathValidator tvalidator = new TestProxyPathValidator(); |
| 533 |
|
| 534 |
// chain of good certs |
| 535 |
X509Certificate[] chain = new X509Certificate[]{goodCertsArr[22], goodCertsArr[21]}; |
| 536 |
X509Certificate[] tCerts = new X509Certificate[]{goodCertsArr[1], |
| 537 |
goodCertsArr[16], goodCertsArr[25], goodCertsArr[21]}; |
| 538 |
ClassLoader loader = ProxyPathValidatorTest.class.getClassLoader(); |
| 539 |
String location1 = loader.getResource(BASE).getPath(); |
| 540 |
CertificateRevocationLists certRevLists = CertificateRevocationLists.getCertificateRevocationLists(location1); |
| 541 |
assertNotNull(certRevLists); |
| 542 |
assertEquals(2,certRevLists.getCrls().length); |
| 543 |
|
| 544 |
TrustedCertificates trustedCerts = new TrustedCertificates(tCerts); |
| 545 |
X509CRL[] crls = certRevLists.getCrls(); |
| 546 |
assertNotNull(crls); |
| 547 |
assertEquals(2, crls.length); |
| 548 |
try { |
| 549 |
tvalidator.validate(chain, trustedCerts.getCertificates(), certRevLists, trustedCerts.getSigningPolicies()); |
| 550 |
} catch (ProxyPathValidatorException e) { |
| 551 |
e.printStackTrace(); |
| 552 |
fail("Unexpected exception: " + e.getMessage()); |
| 553 |
} |
| 554 |
|
| 555 |
tvalidator.reset(); |
| 556 |
|
| 557 |
// remove signing policy checks and validity checks |
| 558 |
|
| 559 |
// ca1 ca1user1 good chain |
| 560 |
chain = new X509Certificate[] { goodCertsArr[22], goodCertsArr[21] }; |
| 561 |
certRevLists = CertificateRevocationLists.getCertificateRevocationLists(location1); |
| 562 |
assertNotNull(certRevLists.getCrls()); |
| 563 |
assertEquals(2,certRevLists.getCrls().length); |
| 564 |
|
| 565 |
try { |
| 566 |
tvalidator.validate(chain, new X509Certificate[] { goodCertsArr[21] }, certRevLists, trustedCerts |
| 567 |
.getSigningPolicies()); |
| 568 |
} catch (ProxyPathValidatorException e) { |
| 569 |
e.printStackTrace(); |
| 570 |
fail("Unexpected exception: " + e.getMessage()); |
| 571 |
} |
| 572 |
|
| 573 |
tvalidator.reset(); |
| 574 |
|
| 575 |
// ca1 ca1user2 good chain |
| 576 |
chain = new X509Certificate[] { goodCertsArr[23], goodCertsArr[21] }; |
| 577 |
try { |
| 578 |
tvalidator.validate(chain, new X509Certificate[] { goodCertsArr[21] }, certRevLists, trustedCerts |
| 579 |
.getSigningPolicies()); |
| 580 |
} catch (ProxyPathValidatorException e) { |
| 581 |
e.printStackTrace(); |
| 582 |
fail("Unexpected exception: " + e.getMessage()); |
| 583 |
} |
| 584 |
|
| 585 |
tvalidator.reset(); |
| 586 |
|
| 587 |
// ca2 user1 bad chain |
| 588 |
chain = new X509Certificate[] { goodCertsArr[26], goodCertsArr[25] }; |
| 589 |
try { |
| 590 |
tvalidator.validate(chain, new X509Certificate[] { goodCertsArr[25] }, certRevLists, trustedCerts |
| 591 |
.getSigningPolicies()); |
| 592 |
fail("Validation did not throw exception"); |
| 593 |
} catch (ProxyPathValidatorException crlExp) { |
| 594 |
// COMMENT no check on exception error code |
| 595 |
//assertEquals(ProxyPathValidatorException.REVOKED, crlExp.getErrorCode()); |
| 596 |
} |
| 597 |
|
| 598 |
tvalidator.reset(); |
| 599 |
|
| 600 |
// ca2 user2 bad chain |
| 601 |
chain = new X509Certificate[] { goodCertsArr[27], goodCertsArr[25] }; |
| 602 |
try { |
| 603 |
tvalidator.validate(chain, new X509Certificate[] { goodCertsArr[25] }, certRevLists, trustedCerts |
| 604 |
.getSigningPolicies()); |
| 605 |
fail("Validation did not throw exception"); |
| 606 |
} catch (ProxyPathValidatorException crlExp) { |
| 607 |
// COMMENT no check on exceptino error code |
| 608 |
//assertEquals(ProxyPathValidatorException.REVOKED, crlExp.getErrorCode()); |
| 609 |
} |
| 610 |
|
| 611 |
tvalidator.reset(); |
| 612 |
|
| 613 |
// ca2 user3 good chain |
| 614 |
chain = new X509Certificate[] { goodCertsArr[28], goodCertsArr[25] }; |
| 615 |
try { |
| 616 |
tvalidator.validate(chain, new X509Certificate[] { goodCertsArr[25] }, certRevLists, trustedCerts.getSigningPolicies()); |
| 617 |
} catch (ProxyPathValidatorException e) { |
| 618 |
e.printStackTrace(); |
| 619 |
fail("Unexpected exception: " + e.getMessage()); |
| 620 |
} |
| 621 |
} |
| 622 |
|
| 623 |
public void testSigningPolicy() throws Exception { |
| 624 |
|
| 625 |
X509Certificate[] chain = null; |
| 626 |
|
| 627 |
Map<X500Principal, SigningPolicy> map = new SigningPolicyParser().parse(new StringReader(signingPolicy)); |
| 628 |
SigningPolicy policy = map.values().iterator().next(); |
| 629 |
assertNotNull(policy); |
| 630 |
|
| 631 |
TestProxyPathValidator tvalidator = new TestProxyPathValidator(true); |
| 632 |
chain = new X509Certificate[] { goodCertsArr[1], goodCertsArr[0] }; |
| 633 |
TrustedCertificates tc = new TrustedCertificates(new X509Certificate[] { goodCertsArr[0] }, |
| 634 |
new SigningPolicy[] { policy }); |
| 635 |
tvalidator.validate(chain, tc); |
| 636 |
|
| 637 |
map = new SigningPolicyParser().parse(new StringReader(signingPolicyViolation)); |
| 638 |
policy = map.values().iterator().next(); |
| 639 |
assertNotNull(policy); |
| 640 |
tc = new TrustedCertificates(new X509Certificate[] { goodCertsArr[0] }, new SigningPolicy[] { policy }); |
| 641 |
|
| 642 |
try { |
| 643 |
tvalidator.validate(chain, tc); |
| 644 |
fail("Exception expected"); |
| 645 |
} catch (ProxyPathValidatorException exp) { |
| 646 |
// COMMENT ignore error code |
| 647 |
//assertEquals(ProxyPathValidatorException.SIGNING_POLICY_VIOLATION, exp.getErrorCode()); |
| 648 |
} |
| 649 |
|
| 650 |
try { |
| 651 |
map = new SigningPolicyParser().parse(new StringReader(signingPolicySansPolicy)); |
| 652 |
fail("Exception expected"); |
| 653 |
} catch (IllegalArgumentException exp) { |
| 654 |
} |
| 655 |
} |
| 656 |
|
| 657 |
private void validateChain(X509Certificate[] chain, X509Certificate[] trustedCerts) throws Exception { |
| 658 |
validateError(chain, trustedCerts, ProxyPathValidatorException.FAILURE); |
| 659 |
} |
| 660 |
|
| 661 |
private void validateChain(X509Certificate[] chain, X509Certificate[] trustedCerts, |
| 662 |
X509Certificate expectedIdentity, boolean expectedLimited) throws Exception { |
| 663 |
TestProxyPathValidator v = new TestProxyPathValidator(); |
| 664 |
v.validate(chain, new TrustedCertificates(trustedCerts)); |
| 665 |
assertEquals(expectedLimited, v.isLimited()); |
| 666 |
assertEquals(expectedIdentity, v.getIdentityCertificate()); |
| 667 |
} |
| 668 |
|
| 669 |
private void validateError(X509Certificate[] chain, X509Certificate[] trustedCerts, int expectedErrorCode) throws Exception { |
| 670 |
TestProxyPathValidator v = new TestProxyPathValidator(); |
| 671 |
try { |
| 672 |
v.validate(chain); |
| 673 |
fail("Did not throw exception as expected"); |
| 674 |
} catch (ProxyPathValidatorException e) { |
| 675 |
// COMMENT ignore error codes, because new code works with strings |
| 676 |
//assertEquals(expectedErrorCode, e.getErrorCode()); |
| 677 |
} |
| 678 |
} |
| 679 |
|
| 680 |
// for testing only to disable validity checking |
| 681 |
class TestProxyPathValidator extends ProxyPathValidator { |
| 682 |
|
| 683 |
boolean policyChk = false; |
| 684 |
MockProxyCertPathValidator validator; |
| 685 |
|
| 686 |
TestProxyPathValidator() { |
| 687 |
super(); |
| 688 |
policyChk = false; |
| 689 |
validator = new MockProxyCertPathValidator(false, false, false); |
| 690 |
} |
| 691 |
|
| 692 |
TestProxyPathValidator(boolean checkSigningPolicy) { |
| 693 |
policyChk = checkSigningPolicy; |
| 694 |
validator = new MockProxyCertPathValidator(false, false, true); |
| 695 |
} |
| 696 |
|
| 697 |
public void validate(X509Certificate[] certPath) throws ProxyPathValidatorException { |
| 698 |
super.setValidator(validator); |
| 699 |
super.validate(certPath); |
| 700 |
} |
| 701 |
|
| 702 |
public void validate(X509Certificate[] certPath, TrustedCertificates trustedCerts) |
| 703 |
throws ProxyPathValidatorException { |
| 704 |
super.setValidator(validator); |
| 705 |
super.validate(certPath, trustedCerts); |
| 706 |
} |
| 707 |
|
| 708 |
public void validate(X509Certificate[] certPath, TrustedCertificates trustedCerts, |
| 709 |
CertificateRevocationLists crlsList, Boolean enforceSigningPolicy) throws ProxyPathValidatorException { |
| 710 |
super.setValidator(validator); |
| 711 |
super.validate(certPath, trustedCerts, crlsList, enforceSigningPolicy); |
| 712 |
} |
| 713 |
} |
| 714 |
|
| 715 |
// for testing only to disable validity checking |
| 716 |
|
| 717 |
public class MockProxyCertPathValidator extends X509ProxyCertPathValidator { |
| 718 |
|
| 719 |
boolean checkCertificateDateValidity; |
| 720 |
boolean checkCRLDateValidity; |
| 721 |
boolean checkSigningPolicy; |
| 722 |
private CertificateChecker dateChecker = new DateValidityChecker(); |
| 723 |
|
| 724 |
public MockProxyCertPathValidator(boolean checkCertificateDateValidity_, |
| 725 |
boolean checkCRLDateValidity_, |
| 726 |
boolean checkSigningPolicy_) { |
| 727 |
|
| 728 |
this.checkCertificateDateValidity = checkCertificateDateValidity_; |
| 729 |
this.checkCRLDateValidity = checkCRLDateValidity_; |
| 730 |
this.checkSigningPolicy = checkSigningPolicy_; |
| 731 |
} |
| 732 |
|
| 733 |
@Override |
| 734 |
protected List<CertificateChecker> getCertificateCheckers() { |
| 735 |
List<CertificateChecker> checkers = new ArrayList<CertificateChecker>(); |
| 736 |
if (checkCertificateDateValidity) { |
| 737 |
checkers.add(dateChecker); |
| 738 |
} |
| 739 |
checkers.add(new UnsupportedCriticalExtensionChecker()); |
| 740 |
checkers.add(new IdentityChecker(this)); |
| 741 |
checkers.add(new CRLChecker(this.certStore, this.keyStore, this.checkCertificateDateValidity)); |
| 742 |
if (this.checkSigningPolicy) { |
| 743 |
checkers.add(new SigningPolicyChecker(this.policyStore)); |
| 744 |
} |
| 745 |
return checkers; |
| 746 |
} |
| 747 |
} |
| 748 |
|
| 749 |
|
| 750 |
} |