public void validate()

in cassandra-analytics-sidecar-client/src/main/java/org/apache/cassandra/spark/validation/KeyStoreValidation.java [70:120]


    public void validate()
    {
        String latestAlias = null;
        try
        {
            if (!configured)
            {
                throw new RuntimeException("KeyStore is not configured");
            }

            if (password == null)
            {
                throw new RuntimeException("Keystore password was not provided.");
            }

            KeyStore keyStore = KeyStore.getInstance(type);
            keyStore.load(stream.get(), password);
            if (keyStore.size() == 0)
            {
                throw new RuntimeException("KeyStore is empty");
            }

            for (Enumeration<String> aliases = keyStore.aliases(); aliases.hasMoreElements();)
            {
                latestAlias = aliases.nextElement();
                Certificate cert = keyStore.getCertificate(latestAlias);
                if (cert instanceof X509Certificate)
                {
                    ((X509Certificate) cert).checkValidity();
                }
            }

            for (Enumeration<String> aliases = keyStore.aliases(); aliases.hasMoreElements();)
            {
                Key key = keyStore.getKey(aliases.nextElement(), password);
                if (key != null && key instanceof PrivateKey)
                {
                    return;  // KeyStore contains a private key
                }
            }
            throw new RuntimeException("KeyStore contains no private keys");
        }
        catch (CertificateExpiredException exception)
        {
            throw new RuntimeException(String.format("Certificate with alias '%s' is expired.", latestAlias), exception);
        }
        catch (IOException | GeneralSecurityException exception)
        {
            throw new RuntimeException("KeyStore is misconfigured", exception);
        }
    }