Example usage for java.security.cert X509CertSelector setCertificateValid

List of usage examples for java.security.cert X509CertSelector setCertificateValid

Introduction

In this page you can find the example usage for java.security.cert X509CertSelector setCertificateValid.

Prototype

public void setCertificateValid(Date certValid) 

Source Link

Document

Sets the certificateValid criterion.

Usage

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    X509CertSelector selec = new X509CertSelector();
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    FileInputStream in = new FileInputStream(args[0]);
    Certificate c = cf.generateCertificate(in);
    System.out.println(selec.match(c));
    selec.setIssuer("CN=Peter,OU=Network Center," + "O=University,L=ZB,ST=Vancouver,C=CN");

    System.out.println(selec.match(c));

    Calendar cld = Calendar.getInstance();
    int year = Integer.parseInt(args[1]);
    int month = Integer.parseInt(args[2]) - 1;
    int day = Integer.parseInt(args[3]);
    cld.set(year, month, day);//from   w w w  .j a va  2  s .com
    Date d = cld.getTime();
    selec.setCertificateValid(d);

    System.out.println(selec.match(c));
    BigInteger sn = new BigInteger("1039056963");
    selec.setSerialNumber(sn);

    System.out.println(selec.match(c));
}

From source file:mitm.application.djigzo.ws.impl.X509CertStoreWSImpl.java

private List<X509CertificateDTO> getCertificatesAction(Expired expired, MissingKeyAlias missingKeyAlias,
        Integer firstResult, Integer maxResults) throws WebServiceCheckedException {
    List<X509CertificateDTO> certificates = new LinkedList<X509CertificateDTO>();

    try {/*from w ww .j a  va2 s  .  co  m*/
        X509CertSelector certSelector = new X509CertSelector();

        if (expired == Expired.NOT_ALLOWED) {
            certSelector.setCertificateValid(new Date());
        }

        CloseableIterator<? extends X509CertStoreEntry> iterator = certStore.getCertStoreIterator(certSelector,
                missingKeyAlias, firstResult, maxResults);

        try {
            while (iterator.hasNext()) {
                X509CertStoreEntry certStoreEntry = iterator.next();

                certificates.add(certificateDTOBuilder.buildCertificateDTO(certStoreEntry.getCertificate(),
                        certStoreEntry.getKeyAlias()));
            }
        } finally {
            iterator.close();
        }

        return certificates;
    } catch (CertStoreException e) {
        throw new WebServiceCheckedException(e);
    } catch (CloseableIteratorException e) {
        throw new WebServiceCheckedException(e);
    }
}