Search in sources :

Example 1 with IdaKeyStore

use of uk.gov.ida.saml.security.IdaKeyStore in project verify-hub by alphagov.

the class HubTransformersFactoryTest method getKeyStore.

private static IdaKeyStore getKeyStore(X509Certificate hubSigningCert) throws Base64DecodingException {
    List<KeyPair> encryptionKeyPairs = new ArrayList<>();
    PublicKeyFactory publicKeyFactory = new PublicKeyFactory(new X509CertificateFactory());
    PrivateKeyFactory privateKeyFactory = new PrivateKeyFactory();
    PublicKey encryptionPublicKey = publicKeyFactory.createPublicKey(TestCertificateStrings.HUB_TEST_PUBLIC_ENCRYPTION_CERT);
    PrivateKey encryptionPrivateKey = privateKeyFactory.createPrivateKey(Base64.decode(TestCertificateStrings.HUB_TEST_PRIVATE_ENCRYPTION_KEY.getBytes()));
    encryptionKeyPairs.add(new KeyPair(encryptionPublicKey, encryptionPrivateKey));
    PublicKey publicSigningKey = publicKeyFactory.createPublicKey(TestCertificateStrings.HUB_TEST_PUBLIC_SIGNING_CERT);
    PrivateKey privateSigningKey = privateKeyFactory.createPrivateKey(Base64.decode(TestCertificateStrings.HUB_TEST_PRIVATE_SIGNING_KEY.getBytes()));
    KeyPair signingKeyPair = new KeyPair(publicSigningKey, privateSigningKey);
    return new IdaKeyStore(hubSigningCert, 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 IdaKeyStore

use of uk.gov.ida.saml.security.IdaKeyStore in project verify-hub by alphagov.

the class MatchingServiceHealthCheckIntegrationTests method getKeyStore.

private IdaKeyStore getKeyStore() {
    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 IdaKeyStore

use of uk.gov.ida.saml.security.IdaKeyStore in project verify-hub by alphagov.

the class PrometheusMetricsIntegrationTest method getKeyStore.

private static IdaKeyStore getKeyStore() {
    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 4 with IdaKeyStore

use of uk.gov.ida.saml.security.IdaKeyStore in project verify-hub by alphagov.

the class SamlEngineModule method getKeyStore.

@Provides
@Singleton
private IdaKeyStore getKeyStore(X509CertificateFactory certificateFactory, SamlEngineConfiguration configuration) {
    Map<KeyPosition, PrivateKey> privateKeyStore = privateEncryptionKeys(configuration);
    DeserializablePublicKeyConfiguration publicSigningKeyConfiguration = configuration.getPublicSigningCert();
    String encodedSigningCertificate = publicSigningKeyConfiguration.getCert();
    X509Certificate signingCertificate = encodedSigningCertificate != null ? certificateFactory.createCertificate(encodedSigningCertificate) : null;
    KeyPair primaryEncryptionKeyPair = Crypto.keyPairFromPrivateKey(privateKeyStore.get(KeyPosition.PRIMARY));
    KeyPair secondaryEncryptionKeyPair = Crypto.keyPairFromPrivateKey(privateKeyStore.get(KeyPosition.SECONDARY));
    KeyPair signingKeyPair = Crypto.keyPairFromPrivateKey(privateSigningKey(configuration));
    return new IdaKeyStore(signingCertificate, signingKeyPair, asList(primaryEncryptionKeyPair, secondaryEncryptionKeyPair));
}
Also used : KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) DeserializablePublicKeyConfiguration(uk.gov.ida.common.shared.configuration.DeserializablePublicKeyConfiguration) IdaKeyStore(uk.gov.ida.saml.security.IdaKeyStore) X509Certificate(java.security.cert.X509Certificate) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 5 with IdaKeyStore

use of uk.gov.ida.saml.security.IdaKeyStore in project verify-hub by alphagov.

the class SamlMessageSenderApiResourceTest method getKeyStore.

private static IdaKeyStore getKeyStore() {
    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)

Aggregations

KeyPair (java.security.KeyPair)7 IdaKeyStore (uk.gov.ida.saml.security.IdaKeyStore)7 PrivateKey (java.security.PrivateKey)6 PublicKey (java.security.PublicKey)5 ArrayList (java.util.ArrayList)4 PrivateKeyFactory (uk.gov.ida.common.shared.security.PrivateKeyFactory)4 PublicKeyFactory (uk.gov.ida.common.shared.security.PublicKeyFactory)4 X509CertificateFactory (uk.gov.ida.common.shared.security.X509CertificateFactory)4 Provides (com.google.inject.Provides)2 X509Certificate (java.security.cert.X509Certificate)2 Singleton (javax.inject.Singleton)2 KeyException (java.security.KeyException)1 Decrypter (org.opensaml.saml.saml2.encryption.Decrypter)1 DeserializablePublicKeyConfiguration (uk.gov.ida.common.shared.configuration.DeserializablePublicKeyConfiguration)1 KeyLoadingException (uk.gov.ida.hub.samlengine.exceptions.KeyLoadingException)1 DecrypterFactory (uk.gov.ida.saml.security.DecrypterFactory)1 IdaKeyStoreCredentialRetriever (uk.gov.ida.saml.security.IdaKeyStoreCredentialRetriever)1 ValidatedResponse (uk.gov.ida.saml.security.validators.ValidatedResponse)1 EncryptionAlgorithmValidator (uk.gov.ida.saml.security.validators.encryptedelementtype.EncryptionAlgorithmValidator)1