Search in sources :

Example 1 with KeyLoadingException

use of uk.gov.ida.hub.samlengine.exceptions.KeyLoadingException in project verify-hub by alphagov.

the class SamlEngineModule method getKeyStore.

@Provides
@Singleton
private IdaKeyStore getKeyStore(SamlEngineConfiguration configuration, SigningCertFromMetadataExtractor signingCertExtractor) {
    try {
        PrivateKey primaryEncryptionKey = configuration.getPrimaryPrivateEncryptionKeyConfiguration().getPrivateKey();
        PrivateKey secondaryEncryptionKey = configuration.getSecondaryPrivateEncryptionKeyConfiguration().getPrivateKey();
        PrivateKey signingKey = configuration.getPrivateSigningKeyConfiguration().getPrivateKey();
        PublicKey publicSigningKey = KeySupport.derivePublicKey(signingKey);
        KeyPair primaryEncryptionKeyPair = new KeyPair(KeySupport.derivePublicKey(primaryEncryptionKey), primaryEncryptionKey);
        KeyPair secondaryEncryptionKeyPair = new KeyPair(KeySupport.derivePublicKey(secondaryEncryptionKey), secondaryEncryptionKey);
        KeyPair signingKeyPair = new KeyPair(publicSigningKey, signingKey);
        X509Certificate signingCertificate = signingCertExtractor.getSigningCertForCurrentSigningKey(publicSigningKey);
        return new IdaKeyStore(signingCertificate, signingKeyPair, asList(primaryEncryptionKeyPair, secondaryEncryptionKeyPair));
    } catch (KeyException e) {
        throw new KeyLoadingException(e);
    }
}
Also used : KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) PublicKey(java.security.PublicKey) KeyLoadingException(uk.gov.ida.hub.samlengine.exceptions.KeyLoadingException) IdaKeyStore(uk.gov.ida.saml.security.IdaKeyStore) X509Certificate(java.security.cert.X509Certificate) KeyException(java.security.KeyException) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

Provides (com.google.inject.Provides)1 KeyException (java.security.KeyException)1 KeyPair (java.security.KeyPair)1 PrivateKey (java.security.PrivateKey)1 PublicKey (java.security.PublicKey)1 X509Certificate (java.security.cert.X509Certificate)1 Singleton (javax.inject.Singleton)1 KeyLoadingException (uk.gov.ida.hub.samlengine.exceptions.KeyLoadingException)1 IdaKeyStore (uk.gov.ida.saml.security.IdaKeyStore)1