Search in sources :

Example 6 with CertificateReader

use of org.cloudfoundry.credhub.util.CertificateReader in project credhub by cloudfoundry-incubator.

the class CertificateSignedByCAValidator method isValid.

@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
    try {
        Field certificateField = value.getClass().getDeclaredField("certificate");
        Field caField = value.getClass().getDeclaredField("ca");
        certificateField.setAccessible(true);
        caField.setAccessible(true);
        final String certificateValue = (String) certificateField.get(value);
        final String caValue = (String) caField.get(value);
        if (StringUtils.isEmpty(certificateValue) || StringUtils.isEmpty(caValue)) {
            return true;
        }
        final CertificateReader certificateReader = new CertificateReader(certificateValue);
        return certificateReader.isSignedByCa(caValue);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Field(java.lang.reflect.Field) CertificateReader(org.cloudfoundry.credhub.util.CertificateReader)

Example 7 with CertificateReader

use of org.cloudfoundry.credhub.util.CertificateReader in project credhub by cloudfoundry-incubator.

the class CertificateValidator method isValid.

@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
    for (String fieldName : fields) {
        try {
            Field field = value.getClass().getDeclaredField(fieldName);
            field.setAccessible(true);
            if (StringUtils.isEmpty((String) field.get(value))) {
                return true;
            }
            CertificateReader reader = new CertificateReader((String) field.get(value));
            return reader.isValid();
        } catch (NoSuchFieldException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
    return true;
}
Also used : Field(java.lang.reflect.Field) CertificateReader(org.cloudfoundry.credhub.util.CertificateReader)

Aggregations

CertificateReader (org.cloudfoundry.credhub.util.CertificateReader)7 Field (java.lang.reflect.Field)4 ParameterizedValidationException (org.cloudfoundry.credhub.exceptions.ParameterizedValidationException)3 PublicKey (java.security.PublicKey)1 X509Certificate (java.security.cert.X509Certificate)1 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)1 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)1 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)1 CertificateGenerationParameters (org.cloudfoundry.credhub.domain.CertificateGenerationParameters)1 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)1 CertificateGenerateRequest (org.cloudfoundry.credhub.request.CertificateGenerateRequest)1 CertificateSetRequest (org.cloudfoundry.credhub.request.CertificateSetRequest)1 UnsupportedFormatException (org.cloudfoundry.credhub.util.PrivateKeyReader.UnsupportedFormatException)1 Test (org.junit.Test)1