public static Set<X509Certificate> filterValid( X509Certificate... certificates )
    {
        final Set<X509Certificate> results = new HashSet<>();

        if (certificates != null)
        {
            for ( X509Certificate certificate : certificates )
            {
                if ( certificate == null )
                {
                    continue;
                }

                try
                {
                    certificate.checkValidity();
                }
                catch ( CertificateExpiredException | CertificateNotYetValidException e )
                {
                    // Not yet or no longer valid. Don't include in result.
                    continue;
                }

                results.add( certificate );
            }
        }

        return results;
    }
Returns all valid certificates from the provided input, where validity references the notBefore and notAfter
dates of each certificate.

This method returns all certificates from the input for which {@link X509Certificate#checkValidity()} returns
true.

The return value of this method is a Set, which means that duplicate certificates in the input are implicitly
being removed from the result.

@param certificates An array of certificates (possibly empty, possibly null).
@return A Set of valid certificates (possibly empty, but never null).
xmppserver/src/main/java/org/jivesoftware/openfire/keystore/CertificateUtils.java