Search in sources :

Example 1 with PrivateKeyFactory

use of uk.gov.ida.common.shared.security.PrivateKeyFactory in project verify-hub by alphagov.

the class MatchingServiceHealthCheckIntegrationTests method getKeyStore.

private IdaKeyStore getKeyStore() throws Base64DecodingException {
    List<KeyPair> encryptionKeyPairs = new ArrayList<>();
    PublicKeyFactory publicKeyFactory = new PublicKeyFactory(new X509CertificateFactory());
    PrivateKeyFactory privateKeyFactory = new PrivateKeyFactory();
    PublicKey encryptionPublicKey = publicKeyFactory.createPublicKey(HUB_TEST_PUBLIC_ENCRYPTION_CERT);
    PrivateKey encryptionPrivateKey = privateKeyFactory.createPrivateKey(Base64.getDecoder().decode(HUB_TEST_PRIVATE_ENCRYPTION_KEY.getBytes()));
    encryptionKeyPairs.add(new KeyPair(encryptionPublicKey, encryptionPrivateKey));
    PublicKey publicSigningKey = publicKeyFactory.createPublicKey(HUB_TEST_PUBLIC_SIGNING_CERT);
    PrivateKey privateSigningKey = privateKeyFactory.createPrivateKey(Base64.getDecoder().decode(HUB_TEST_PRIVATE_SIGNING_KEY.getBytes()));
    KeyPair signingKeyPair = new KeyPair(publicSigningKey, privateSigningKey);
    return new IdaKeyStore(signingKeyPair, encryptionKeyPairs);
}
Also used : X509CertificateFactory(uk.gov.ida.common.shared.security.X509CertificateFactory) KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) PrivateKeyFactory(uk.gov.ida.common.shared.security.PrivateKeyFactory) PublicKey(java.security.PublicKey) ArrayList(java.util.ArrayList) PublicKeyFactory(uk.gov.ida.common.shared.security.PublicKeyFactory) IdaKeyStore(uk.gov.ida.saml.security.IdaKeyStore)

Example 2 with PrivateKeyFactory

use of uk.gov.ida.common.shared.security.PrivateKeyFactory in project verify-hub by alphagov.

the class SamlMessageSenderApiResourceTest method getKeyStore.

private static IdaKeyStore getKeyStore() throws Base64DecodingException {
    List<KeyPair> encryptionKeyPairs = new ArrayList<>();
    PublicKeyFactory publicKeyFactory = new PublicKeyFactory(new X509CertificateFactory());
    PrivateKeyFactory privateKeyFactory = new PrivateKeyFactory();
    PublicKey encryptionPublicKey = publicKeyFactory.createPublicKey(HUB_TEST_PUBLIC_ENCRYPTION_CERT);
    PrivateKey encryptionPrivateKey = privateKeyFactory.createPrivateKey(Base64.getDecoder().decode(HUB_TEST_PRIVATE_ENCRYPTION_KEY.getBytes()));
    encryptionKeyPairs.add(new KeyPair(encryptionPublicKey, encryptionPrivateKey));
    PublicKey publicSigningKey = publicKeyFactory.createPublicKey(HUB_TEST_PUBLIC_SIGNING_CERT);
    PrivateKey privateSigningKey = privateKeyFactory.createPrivateKey(Base64.getDecoder().decode(HUB_TEST_PRIVATE_SIGNING_KEY.getBytes()));
    KeyPair signingKeyPair = new KeyPair(publicSigningKey, privateSigningKey);
    return new IdaKeyStore(signingKeyPair, encryptionKeyPairs);
}
Also used : X509CertificateFactory(uk.gov.ida.common.shared.security.X509CertificateFactory) KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) PrivateKeyFactory(uk.gov.ida.common.shared.security.PrivateKeyFactory) PublicKey(java.security.PublicKey) ArrayList(java.util.ArrayList) PublicKeyFactory(uk.gov.ida.common.shared.security.PublicKeyFactory) IdaKeyStore(uk.gov.ida.saml.security.IdaKeyStore)

Example 3 with PrivateKeyFactory

use of uk.gov.ida.common.shared.security.PrivateKeyFactory in project verify-hub by alphagov.

the class ExecuteAttributeQueryRequestTest method run_shouldThrowCertChainValidationExceptionOnResponse.

@Test
public void run_shouldThrowCertChainValidationExceptionOnResponse() throws Exception {
    when(attributeQueryRequestClient.sendQuery(any(Element.class), anyString(), any(SessionId.class), any(URI.class))).thenReturn(matchingServiceResponse);
    final BasicX509Credential x509Credential = new BasicX509Credential(new X509CertificateFactory().createCertificate(UNCHAINED_PUBLIC_CERT), new PrivateKeyFactory().createPrivateKey(Base64.decode(UNCHAINED_PRIVATE_KEY.getBytes())));
    Response response = aResponse().withSigningCredential(x509Credential).withIssuer(anIssuer().withIssuerId("issuer-id").build()).build();
    when(elementToResponseTransformer.apply(matchingServiceResponse)).thenReturn(response);
    executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto);
    verify(matchingResponseSignatureValidator).validate(response, AttributeAuthorityDescriptor.DEFAULT_ELEMENT_NAME);
}
Also used : X509CertificateFactory(uk.gov.ida.common.shared.security.X509CertificateFactory) Response(org.opensaml.saml.saml2.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlValidationResponse(uk.gov.ida.saml.core.validation.SamlValidationResponse) BasicX509Credential(org.opensaml.security.x509.BasicX509Credential) PrivateKeyFactory(uk.gov.ida.common.shared.security.PrivateKeyFactory) Element(org.w3c.dom.Element) SessionId(uk.gov.ida.common.SessionId) URI(java.net.URI) Test(org.junit.Test)

Aggregations

PrivateKeyFactory (uk.gov.ida.common.shared.security.PrivateKeyFactory)3 X509CertificateFactory (uk.gov.ida.common.shared.security.X509CertificateFactory)3 KeyPair (java.security.KeyPair)2 PrivateKey (java.security.PrivateKey)2 PublicKey (java.security.PublicKey)2 ArrayList (java.util.ArrayList)2 PublicKeyFactory (uk.gov.ida.common.shared.security.PublicKeyFactory)2 IdaKeyStore (uk.gov.ida.saml.security.IdaKeyStore)2 URI (java.net.URI)1 Test (org.junit.Test)1 Response (org.opensaml.saml.saml2.core.Response)1 BasicX509Credential (org.opensaml.security.x509.BasicX509Credential)1 Element (org.w3c.dom.Element)1 SessionId (uk.gov.ida.common.SessionId)1 ResponseBuilder.aResponse (uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse)1 SamlValidationResponse (uk.gov.ida.saml.core.validation.SamlValidationResponse)1