Search in sources :

Example 6 with CertificateDto

use of uk.gov.ida.hub.samlsoapproxy.domain.CertificateDto in project verify-hub by alphagov.

the class ConfigServiceKeyStoreTest method getEncryptionKeyForEntity_shouldThrowExceptionIfCertificateIsInvalid.

@Test
public void getEncryptionKeyForEntity_shouldThrowExceptionIfCertificateIsInvalid() throws Exception {
    final CertificateDto certOneDto = buildCertificateDto(IDP_ENTITY_ID, idpSigningCertPrimary);
    when(certificatesConfigProxy.getEncryptionCertificate(issuerId)).thenReturn(certOneDto);
    when(x509CertificateFactory.createCertificate(certOneDto.getCertificate())).thenReturn(x509Certificate);
    when(trustStoreForCertificateProvider.getTrustStoreFor(any(FederationEntityType.class))).thenReturn(trustStore);
    CertPathValidatorException underlyingException = new CertPathValidatorException("Invalid Certificate");
    when(certificateChainValidator.validate(x509Certificate, trustStore)).thenReturn(invalid(underlyingException));
    try {
        configServiceKeyStore.getEncryptionKeyForEntity(issuerId);
        Assert.fail(String.format("Expected [%s]", CertificateChainValidationException.class.getSimpleName()));
    } catch (CertificateChainValidationException success) {
        assertThat(success.getMessage()).isEqualTo("Certificate is not valid: Unable to get DN");
        assertThat(success.getCause()).isEqualTo(underlyingException);
    }
}
Also used : CertificateDto(uk.gov.ida.hub.samlsoapproxy.domain.CertificateDto) CertPathValidatorException(java.security.cert.CertPathValidatorException) CertificateChainValidationException(uk.gov.ida.common.shared.security.verification.exceptions.CertificateChainValidationException) FederationEntityType(uk.gov.ida.hub.samlsoapproxy.domain.FederationEntityType) Test(org.junit.Test)

Example 7 with CertificateDto

use of uk.gov.ida.hub.samlsoapproxy.domain.CertificateDto in project verify-hub by alphagov.

the class ConfigServiceKeyStoreTest method getEncryptionKeyForEntity_shouldValidateTheKeyReturnedByConfig.

@Test
public void getEncryptionKeyForEntity_shouldValidateTheKeyReturnedByConfig() throws Exception {
    final CertificateDto certOneDto = buildCertificateDto(IDP_ENTITY_ID, idpSigningCertPrimary);
    when(certificatesConfigProxy.getEncryptionCertificate(issuerId)).thenReturn(certOneDto);
    when(x509CertificateFactory.createCertificate(certOneDto.getCertificate())).thenReturn(x509Certificate);
    when(trustStoreForCertificateProvider.getTrustStoreFor(any(FederationEntityType.class))).thenReturn(trustStore);
    when(certificateChainValidator.validate(x509Certificate, trustStore)).thenReturn(valid());
    configServiceKeyStore.getEncryptionKeyForEntity(issuerId);
    verify(certificateChainValidator).validate(x509Certificate, trustStore);
}
Also used : CertificateDto(uk.gov.ida.hub.samlsoapproxy.domain.CertificateDto) FederationEntityType(uk.gov.ida.hub.samlsoapproxy.domain.FederationEntityType) Test(org.junit.Test)

Example 8 with CertificateDto

use of uk.gov.ida.hub.samlsoapproxy.domain.CertificateDto in project verify-hub by alphagov.

the class ConfigStubRule method setupStubForCertificates.

public void setupStubForCertificates(String issuer, String signingCertString, String encryptionCertString) throws JsonProcessingException {
    CertificateDto signingCertificate = new CertificateDtoBuilder().withIssuerId(issuer).withCertificate(signingCertString).withKeyUse(CertificateDto.KeyUse.Signing).build();
    CertificateDto encryptionCertificate = new CertificateDtoBuilder().withIssuerId(issuer).withCertificate(encryptionCertString).withKeyUse(CertificateDto.KeyUse.Encryption).build();
    registerStubForCertificates(issuer, signingCertificate, encryptionCertificate);
}
Also used : CertificateDto(uk.gov.ida.hub.samlsoapproxy.domain.CertificateDto) CertificateDtoBuilder(uk.gov.ida.hub.samlsoapproxy.builders.CertificateDtoBuilder)

Aggregations

CertificateDto (uk.gov.ida.hub.samlsoapproxy.domain.CertificateDto)8 Test (org.junit.Test)5 FederationEntityType (uk.gov.ida.hub.samlsoapproxy.domain.FederationEntityType)5 KeyStore (java.security.KeyStore)2 PublicKey (java.security.PublicKey)2 CertPathValidatorException (java.security.cert.CertPathValidatorException)2 X509Certificate (java.security.cert.X509Certificate)2 CertificateChainValidationException (uk.gov.ida.common.shared.security.verification.exceptions.CertificateChainValidationException)2 ArrayList (java.util.ArrayList)1 CertificateDtoBuilder (uk.gov.ida.hub.samlsoapproxy.builders.CertificateDtoBuilder)1