| 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 |
|
| 16 |
package org.globus.gsi.trustmanager; |
| 17 |
|
| 18 |
import org.globus.gsi.util.ProxyCertificateUtil; |
| 19 |
|
| 20 |
import org.globus.gsi.proxy.ext.ProxyCertInfo; |
| 21 |
|
| 22 |
import java.security.cert.CertPathValidatorException; |
| 23 |
import java.security.cert.X509Certificate; |
| 24 |
import java.util.Set; |
| 25 |
|
| 26 |
import org.globus.gsi.GSIConstants; |
| 27 |
|
| 28 |
/** |
| 29 |
* Checks if the certificate includes unsupported critical extensions. |
| 30 |
* |
| 31 |
* @version ${version} |
| 32 |
* @since 1.0 |
| 33 |
*/ |
| 34 |
public class UnsupportedCriticalExtensionChecker implements CertificateChecker { |
| 35 |
/** |
| 36 |
* Method that checks if there are unsupported critical extension. Supported |
| 37 |
* ones are only BasicConstrains, KeyUsage, Proxy Certificate (old and new) |
| 38 |
* |
| 39 |
* @param cert The certificate to validate. |
| 40 |
* @param certType The type of certificate to validate. |
| 41 |
* @throws CertPathValidatorException If any critical extension that is not supported is in the certificate. |
| 42 |
* Anything other than those listed above will trigger the exception. |
| 43 |
*/ |
| 44 |
public void invoke(X509Certificate cert, GSIConstants.CertificateType certType) throws CertPathValidatorException { |
| 45 |
Set<String> criticalExtensionOids = |
| 46 |
cert.getCriticalExtensionOIDs(); |
| 47 |
if (criticalExtensionOids == null) { |
| 48 |
return; |
| 49 |
} |
| 50 |
for (String criticalExtensionOid : criticalExtensionOids) { |
| 51 |
isUnsupported(certType, criticalExtensionOid); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
private void isUnsupported(GSIConstants.CertificateType certType, String criticalExtensionOid) |
| 56 |
throws CertPathValidatorException { |
| 57 |
boolean unsupportedCritExtention = criticalExtensionOid.equals(X509ProxyCertPathValidator.BASIC_CONSTRAINT_OID); |
| 58 |
unsupportedCritExtention = unsupportedCritExtention || criticalExtensionOid.equals(X509ProxyCertPathValidator.KEY_USAGE_OID); |
| 59 |
unsupportedCritExtention = unsupportedCritExtention |
| 60 |
|| (criticalExtensionOid.equals(ProxyCertInfo.OID.toString()) |
| 61 |
&& ProxyCertificateUtil.isGsi4Proxy(certType)); |
| 62 |
unsupportedCritExtention = unsupportedCritExtention |
| 63 |
|| (criticalExtensionOid.equals(ProxyCertInfo.OLD_OID.toString()) |
| 64 |
&& ProxyCertificateUtil.isGsi3Proxy(certType)); |
| 65 |
|
| 66 |
if (unsupportedCritExtention) { |
| 67 |
return; |
| 68 |
} |
| 69 |
// if (criticalExtensionOid.equals(X509ProxyCertPathValidator.BASIC_CONSTRAINT_OID) |
| 70 |
// || criticalExtensionOid.equals(X509ProxyCertPathValidator.KEY_USAGE_OID) |
| 71 |
// || (criticalExtensionOid.equals(Constants.PROXY_OID.toString()) |
| 72 |
// && ProxyCertificateUtil.isGsi4Proxy(certType)) |
| 73 |
// || (criticalExtensionOid.equals(Constants.PROXY_OLD_OID.toString()) |
| 74 |
// && ProxyCertificateUtil.isGsi3Proxy(certType))) { |
| 75 |
// return; |
| 76 |
// } |
| 77 |
throw new CertPathValidatorException("Critical extension with unsupported OID " + criticalExtensionOid); |
| 78 |
} |
| 79 |
} |