java.security.Timestamp Java Examples

The following examples show how to use java.security.Timestamp. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Serialize.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        // Create a certpath consisting of one certificate
        File f = new File(System.getProperty("test.src", "."), "cert_file");
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Certificate c = cf.generateCertificate(fis);
        fis.close();
        CertPath cp = cf.generateCertPath(Collections.singletonList(c));

        // Create a code signer
        CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp));

        // Serialize the code signer
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(cs);
        out.close();

        // Deserialize the code signer
        byte[] data = byteOut.toByteArray();
        CodeSigner cs2 = (CodeSigner) new ObjectInputStream(
            new ByteArrayInputStream(data)).readObject();

        // Test for equality
        if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) {
            throw new Exception("CodeSigner serialization test FAILED");
        }
    }
 
Example #2
Source File: PKIXExtendedParameters.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public PKIXExtendedParameters(PKIXBuilderParameters params,
        Timestamp timestamp, String variant)
        throws InvalidAlgorithmParameterException {
    super(params.getTrustAnchors(), null);
    p = params;
    jarTimestamp = timestamp;
    this.variant = variant;
}
 
Example #3
Source File: ConstraintsParameters.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public ConstraintsParameters(X509Certificate c, boolean match,
        Date pkixdate, Timestamp jarTime, String variant) {
    cert = c;
    trustedMatch = match;
    pkixDate = pkixdate;
    jarTimestamp = jarTime;
    this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
    algorithm = null;
    algParams = null;
    publicKey = null;
}
 
Example #4
Source File: AlgorithmChecker.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new {@code AlgorithmChecker} with the
 * given {@code TrustAnchor}, {@code AlgorithmConstraints},
 * {@code Timestamp}, and {@code String} variant.
 *
 * @param anchor the trust anchor selected to validate the target
 *     certificate
 * @param constraints the algorithm constraints (or null)
 * @param pkixdate The date specified by the PKIXParameters date.  If the
 *                 PKIXParameters is null, the current date is used.  This
 *                 should be null when jar files are being checked.
 * @param jarTimestamp Timestamp passed for JAR timestamp constraint
 *                     checking. Set to null if not applicable.
 * @param variant is the Validator variants of the operation. A null value
 *                passed will set it to Validator.GENERIC.
 */
public AlgorithmChecker(TrustAnchor anchor,
        AlgorithmConstraints constraints, Date pkixdate,
        Timestamp jarTimestamp, String variant) {

    if (anchor != null) {
        if (anchor.getTrustedCert() != null) {
            this.trustedPubKey = anchor.getTrustedCert().getPublicKey();
            // Check for anchor certificate restrictions
            trustedMatch = checkFingerprint(anchor.getTrustedCert());
            if (trustedMatch && debug != null) {
                debug.println("trustedMatch = true");
            }
        } else {
            this.trustedPubKey = anchor.getCAPublicKey();
        }
    } else {
        this.trustedPubKey = null;
        if (debug != null) {
            debug.println("TrustAnchor is null, trustedMatch is false.");
        }
    }

    this.prevPubKey = this.trustedPubKey;
    this.constraints = (constraints == null ? certPathDefaultConstraints :
            constraints);
    // If we are checking jar files, set pkixdate the same as the timestamp
    // for certificate checking
    this.pkixdate = (jarTimestamp != null ? jarTimestamp.getTimestamp() :
            pkixdate);
    this.jarTimestamp = jarTimestamp;
    this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
}
 
Example #5
Source File: Serialize.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        // Create a certpath consisting of one certificate
        File f = new File(System.getProperty("test.src", "."), "cert_file");
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Certificate c = cf.generateCertificate(fis);
        fis.close();
        CertPath cp = cf.generateCertPath(Collections.singletonList(c));

        // Create a code signer
        CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp));

        // Serialize the code signer
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(cs);
        out.close();

        // Deserialize the code signer
        byte[] data = byteOut.toByteArray();
        CodeSigner cs2 = (CodeSigner) new ObjectInputStream(
            new ByteArrayInputStream(data)).readObject();

        // Test for equality
        if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) {
            throw new Exception("CodeSigner serialization test FAILED");
        }
    }
 
Example #6
Source File: PKIXExtendedParameters.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public PKIXExtendedParameters(PKIXBuilderParameters params,
        Timestamp timestamp, String variant)
        throws InvalidAlgorithmParameterException {
    super(params.getTrustAnchors(), null);
    p = params;
    jarTimestamp = timestamp;
    this.variant = variant;
}
 
Example #7
Source File: Serialize.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        // Create a certpath consisting of one certificate
        File f = new File(System.getProperty("test.src", "."), "cert_file");
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Certificate c = cf.generateCertificate(fis);
        fis.close();
        CertPath cp = cf.generateCertPath(Collections.singletonList(c));

        // Create a code signer
        CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp));

        // Serialize the code signer
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(cs);
        out.close();

        // Deserialize the code signer
        byte[] data = byteOut.toByteArray();
        CodeSigner cs2 = (CodeSigner) new ObjectInputStream(
            new ByteArrayInputStream(data)).readObject();

        // Test for equality
        if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) {
            throw new Exception("CodeSigner serialization test FAILED");
        }
    }
 
Example #8
Source File: AlgorithmChecker.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new {@code AlgorithmChecker} with the
 * given {@code TrustAnchor}, {@code AlgorithmConstraints},
 * {@code Timestamp}, and {@code String} variant.
 *
 * @param anchor the trust anchor selected to validate the target
 *     certificate
 * @param constraints the algorithm constraints (or null)
 * @param pkixdate The date specified by the PKIXParameters date.  If the
 *                 PKIXParameters is null, the current date is used.  This
 *                 should be null when jar files are being checked.
 * @param jarTimestamp Timestamp passed for JAR timestamp constraint
 *                     checking. Set to null if not applicable.
 * @param variant is the Validator variants of the operation. A null value
 *                passed will set it to Validator.GENERIC.
 */
public AlgorithmChecker(TrustAnchor anchor,
        AlgorithmConstraints constraints, Date pkixdate,
        Timestamp jarTimestamp, String variant) {

    if (anchor != null) {
        if (anchor.getTrustedCert() != null) {
            this.trustedPubKey = anchor.getTrustedCert().getPublicKey();
            // Check for anchor certificate restrictions
            trustedMatch = checkFingerprint(anchor.getTrustedCert());
            if (trustedMatch && debug != null) {
                debug.println("trustedMatch = true");
            }
        } else {
            this.trustedPubKey = anchor.getCAPublicKey();
        }
    } else {
        this.trustedPubKey = null;
        if (debug != null) {
            debug.println("TrustAnchor is null, trustedMatch is false.");
        }
    }

    this.prevPubKey = this.trustedPubKey;
    this.constraints = (constraints == null ? certPathDefaultConstraints :
            constraints);
    // If we are checking jar files, set pkixdate the same as the timestamp
    // for certificate checking
    this.pkixdate = (jarTimestamp != null ? jarTimestamp.getTimestamp() :
            pkixdate);
    this.jarTimestamp = jarTimestamp;
    this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
}
 
Example #9
Source File: ConstraintsParameters.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public ConstraintsParameters(X509Certificate c, boolean match,
        Date pkixdate, Timestamp jarTime, String variant) {
    cert = c;
    trustedMatch = match;
    pkixDate = pkixdate;
    jarTimestamp = jarTime;
    this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
    algorithm = null;
    algParams = null;
    publicKey = null;
}
 
Example #10
Source File: Serialize.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        // Create a certpath consisting of one certificate
        File f = new File(System.getProperty("test.src", "."), "cert_file");
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Certificate c = cf.generateCertificate(fis);
        fis.close();
        CertPath cp = cf.generateCertPath(Collections.singletonList(c));

        // Create a code signer
        CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp));

        // Serialize the code signer
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(cs);
        out.close();

        // Deserialize the code signer
        byte[] data = byteOut.toByteArray();
        CodeSigner cs2 = (CodeSigner) new ObjectInputStream(
            new ByteArrayInputStream(data)).readObject();

        // Test for equality
        if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) {
            throw new Exception("CodeSigner serialization test FAILED");
        }
    }
 
Example #11
Source File: Serialize.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        // Create a certpath consisting of one certificate
        File f = new File(System.getProperty("test.src", "."), "cert_file");
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Certificate c = cf.generateCertificate(fis);
        fis.close();
        CertPath cp = cf.generateCertPath(Collections.singletonList(c));

        // Create a code signer
        CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp));

        // Serialize the code signer
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(cs);
        out.close();

        // Deserialize the code signer
        byte[] data = byteOut.toByteArray();
        CodeSigner cs2 = (CodeSigner) new ObjectInputStream(
            new ByteArrayInputStream(data)).readObject();

        // Test for equality
        if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) {
            throw new Exception("CodeSigner serialization test FAILED");
        }
    }
 
Example #12
Source File: Criteria.java    From OpenCue with Apache License 2.0 5 votes vote down vote up
void addLessThanTimestamp(String col, Timestamp timestamp) {
    if (timestamp == null) { return; }
    StringBuilder sb = new StringBuilder(128);
    sb.append("(");
    sb.append(col);
    sb.append(" < ?");
    sb.append(") ");
    values.add(timestamp);
    chunks.add(sb);
}
 
Example #13
Source File: Serialize.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        // Create a certpath consisting of one certificate
        File f = new File(System.getProperty("test.src", "."), "cert_file");
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Certificate c = cf.generateCertificate(fis);
        fis.close();
        CertPath cp = cf.generateCertPath(Collections.singletonList(c));

        // Create a code signer
        CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp));

        // Serialize the code signer
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(cs);
        out.close();

        // Deserialize the code signer
        byte[] data = byteOut.toByteArray();
        CodeSigner cs2 = (CodeSigner) new ObjectInputStream(
            new ByteArrayInputStream(data)).readObject();

        // Test for equality
        if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) {
            throw new Exception("CodeSigner serialization test FAILED");
        }
    }
 
Example #14
Source File: Criteria.java    From OpenCue with Apache License 2.0 5 votes vote down vote up
void addLessThanTimestamp(String col, Timestamp timestamp) {
    if (timestamp == null) { return; }
    StringBuilder sb = new StringBuilder(128);
    sb.append("(");
    sb.append(col);
    sb.append(" < ?");
    sb.append(") ");
    values.add(timestamp);
    chunks.add(sb);
}
 
Example #15
Source File: Serialize.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        // Create a certpath consisting of one certificate
        File f = new File(System.getProperty("test.src", "."), "cert_file");
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Certificate c = cf.generateCertificate(fis);
        fis.close();
        CertPath cp = cf.generateCertPath(Collections.singletonList(c));

        // Create a code signer
        CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp));

        // Serialize the code signer
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(cs);
        out.close();

        // Deserialize the code signer
        byte[] data = byteOut.toByteArray();
        CodeSigner cs2 = (CodeSigner) new ObjectInputStream(
            new ByteArrayInputStream(data)).readObject();

        // Test for equality
        if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) {
            throw new Exception("CodeSigner serialization test FAILED");
        }
    }
 
Example #16
Source File: PKIXExtendedParameters.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public PKIXExtendedParameters(PKIXBuilderParameters params,
        Timestamp timestamp, String variant)
        throws InvalidAlgorithmParameterException {
    super(params.getTrustAnchors(), null);
    p = params;
    jarTimestamp = timestamp;
    this.variant = variant;
}
 
Example #17
Source File: PKIXExtendedParameters.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public PKIXExtendedParameters(PKIXBuilderParameters params,
        Timestamp timestamp, String variant)
        throws InvalidAlgorithmParameterException {
    super(params.getTrustAnchors(), null);
    p = params;
    jarTimestamp = timestamp;
    this.variant = variant;
}
 
Example #18
Source File: AlgorithmChecker.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new {@code AlgorithmChecker} with the
 * given {@code TrustAnchor}, {@code AlgorithmConstraints},
 * {@code Timestamp}, and {@code String} variant.
 *
 * @param anchor the trust anchor selected to validate the target
 *     certificate
 * @param constraints the algorithm constraints (or null)
 * @param pkixdate The date specified by the PKIXParameters date.  If the
 *                 PKIXParameters is null, the current date is used.  This
 *                 should be null when jar files are being checked.
 * @param jarTimestamp Timestamp passed for JAR timestamp constraint
 *                     checking. Set to null if not applicable.
 * @param variant is the Validator variants of the operation. A null value
 *                passed will set it to Validator.GENERIC.
 */
public AlgorithmChecker(TrustAnchor anchor,
        AlgorithmConstraints constraints, Date pkixdate,
        Timestamp jarTimestamp, String variant) {

    if (anchor != null) {
        if (anchor.getTrustedCert() != null) {
            this.trustedPubKey = anchor.getTrustedCert().getPublicKey();
            // Check for anchor certificate restrictions
            trustedMatch = checkFingerprint(anchor.getTrustedCert());
            if (trustedMatch && debug != null) {
                debug.println("trustedMatch = true");
            }
        } else {
            this.trustedPubKey = anchor.getCAPublicKey();
        }
    } else {
        this.trustedPubKey = null;
        if (debug != null) {
            debug.println("TrustAnchor is null, trustedMatch is false.");
        }
    }

    this.prevPubKey = this.trustedPubKey;
    this.constraints = (constraints == null ? certPathDefaultConstraints :
            constraints);
    // If we are checking jar files, set pkixdate the same as the timestamp
    // for certificate checking
    this.pkixdate = (jarTimestamp != null ? jarTimestamp.getTimestamp() :
            pkixdate);
    this.jarTimestamp = jarTimestamp;
    this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
}
 
Example #19
Source File: AlgorithmChecker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new {@code AlgorithmChecker} with the
 * given {@code TrustAnchor}, {@code AlgorithmConstraints},
 * {@code Timestamp}, and {@code String} variant.
 *
 * @param anchor the trust anchor selected to validate the target
 *     certificate
 * @param constraints the algorithm constraints (or null)
 * @param pkixdate The date specified by the PKIXParameters date.  If the
 *                 PKIXParameters is null, the current date is used.  This
 *                 should be null when jar files are being checked.
 * @param jarTimestamp Timestamp passed for JAR timestamp constraint
 *                     checking. Set to null if not applicable.
 * @param variant is the Validator variants of the operation. A null value
 *                passed will set it to Validator.GENERIC.
 */
public AlgorithmChecker(TrustAnchor anchor,
        AlgorithmConstraints constraints, Date pkixdate,
        Timestamp jarTimestamp, String variant) {

    if (anchor != null) {
        if (anchor.getTrustedCert() != null) {
            this.trustedPubKey = anchor.getTrustedCert().getPublicKey();
            // Check for anchor certificate restrictions
            trustedMatch = checkFingerprint(anchor.getTrustedCert());
            if (trustedMatch && debug != null) {
                debug.println("trustedMatch = true");
            }
        } else {
            this.trustedPubKey = anchor.getCAPublicKey();
        }
    } else {
        this.trustedPubKey = null;
        if (debug != null) {
            debug.println("TrustAnchor is null, trustedMatch is false.");
        }
    }

    this.prevPubKey = this.trustedPubKey;
    this.constraints = (constraints == null ? certPathDefaultConstraints :
            constraints);
    // If we are checking jar files, set pkixdate the same as the timestamp
    // for certificate checking
    this.pkixdate = (jarTimestamp != null ? jarTimestamp.getTimestamp() :
            pkixdate);
    this.jarTimestamp = jarTimestamp;
    this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
}
 
Example #20
Source File: Serialize.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        // Create a certpath consisting of one certificate
        File f = new File(System.getProperty("test.src", "."), "cert_file");
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Certificate c = cf.generateCertificate(fis);
        fis.close();
        CertPath cp = cf.generateCertPath(Collections.singletonList(c));

        // Create a code signer
        CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp));

        // Serialize the code signer
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(cs);
        out.close();

        // Deserialize the code signer
        byte[] data = byteOut.toByteArray();
        CodeSigner cs2 = (CodeSigner) new ObjectInputStream(
            new ByteArrayInputStream(data)).readObject();

        // Test for equality
        if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) {
            throw new Exception("CodeSigner serialization test FAILED");
        }
    }
 
Example #21
Source File: Serialize.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        // Create a certpath consisting of one certificate
        File f = new File(System.getProperty("test.src", "."), "cert_file");
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Certificate c = cf.generateCertificate(fis);
        fis.close();
        CertPath cp = cf.generateCertPath(Collections.singletonList(c));

        // Create a code signer
        CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp));

        // Serialize the code signer
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(cs);
        out.close();

        // Deserialize the code signer
        byte[] data = byteOut.toByteArray();
        CodeSigner cs2 = (CodeSigner) new ObjectInputStream(
            new ByteArrayInputStream(data)).readObject();

        // Test for equality
        if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) {
            throw new Exception("CodeSigner serialization test FAILED");
        }
    }
 
Example #22
Source File: Serialize.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        // Create a certpath consisting of one certificate
        File f = new File(System.getProperty("test.src", "."), "cert_file");
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Certificate c = cf.generateCertificate(fis);
        fis.close();
        CertPath cp = cf.generateCertPath(Collections.singletonList(c));

        // Create a code signer
        CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp));

        // Serialize the code signer
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(cs);
        out.close();

        // Deserialize the code signer
        byte[] data = byteOut.toByteArray();
        CodeSigner cs2 = (CodeSigner) new ObjectInputStream(
            new ByteArrayInputStream(data)).readObject();

        // Test for equality
        if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) {
            throw new Exception("CodeSigner serialization test FAILED");
        }
    }
 
Example #23
Source File: AlgorithmChecker.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new {@code AlgorithmChecker} with the
 * given {@code TrustAnchor}, {@code AlgorithmConstraints},
 * {@code Timestamp}, and {@code String} variant.
 *
 * @param anchor the trust anchor selected to validate the target
 *     certificate
 * @param constraints the algorithm constraints (or null)
 * @param pkixdate The date specified by the PKIXParameters date.  If the
 *                 PKIXParameters is null, the current date is used.  This
 *                 should be null when jar files are being checked.
 * @param jarTimestamp Timestamp passed for JAR timestamp constraint
 *                     checking. Set to null if not applicable.
 * @param variant is the Validator variants of the operation. A null value
 *                passed will set it to Validator.GENERIC.
 */
public AlgorithmChecker(TrustAnchor anchor,
        AlgorithmConstraints constraints, Date pkixdate,
        Timestamp jarTimestamp, String variant) {

    if (anchor != null) {
        if (anchor.getTrustedCert() != null) {
            this.trustedPubKey = anchor.getTrustedCert().getPublicKey();
            // Check for anchor certificate restrictions
            trustedMatch = checkFingerprint(anchor.getTrustedCert());
            if (trustedMatch && debug != null) {
                debug.println("trustedMatch = true");
            }
        } else {
            this.trustedPubKey = anchor.getCAPublicKey();
        }
    } else {
        this.trustedPubKey = null;
        if (debug != null) {
            debug.println("TrustAnchor is null, trustedMatch is false.");
        }
    }

    this.prevPubKey = this.trustedPubKey;
    this.constraints = (constraints == null ? certPathDefaultConstraints :
            constraints);
    // If we are checking jar files, set pkixdate the same as the timestamp
    // for certificate checking
    this.pkixdate = (jarTimestamp != null ? jarTimestamp.getTimestamp() :
            pkixdate);
    this.jarTimestamp = jarTimestamp;
    this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
}
 
Example #24
Source File: PKIXExtendedParameters.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public PKIXExtendedParameters(PKIXBuilderParameters params,
        Timestamp timestamp, String variant)
        throws InvalidAlgorithmParameterException {
    super(params.getTrustAnchors(), null);
    p = params;
    jarTimestamp = timestamp;
    this.variant = variant;
}
 
Example #25
Source File: ConstraintsParameters.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public ConstraintsParameters(X509Certificate c, boolean match,
        Date pkixdate, Timestamp jarTime, String variant) {
    cert = c;
    trustedMatch = match;
    pkixDate = pkixdate;
    jarTimestamp = jarTime;
    this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
    algorithm = null;
    algParams = null;
    key = null;
    if (c != null) {
        curveStr = getNamedCurveFromKey(c.getPublicKey());
    } else {
        curveStr = EMPTYLIST;
    }
}
 
Example #26
Source File: PKIXExtendedParameters.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public PKIXExtendedParameters(PKIXBuilderParameters params,
        Timestamp timestamp, String variant)
        throws InvalidAlgorithmParameterException {
    super(params.getTrustAnchors(), null);
    p = params;
    jarTimestamp = timestamp;
    this.variant = variant;
}
 
Example #27
Source File: Serialize.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        // Create a certpath consisting of one certificate
        File f = new File(System.getProperty("test.src", "."), "cert_file");
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Certificate c = cf.generateCertificate(fis);
        fis.close();
        CertPath cp = cf.generateCertPath(Collections.singletonList(c));

        // Create a code signer
        CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp));

        // Serialize the code signer
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(cs);
        out.close();

        // Deserialize the code signer
        byte[] data = byteOut.toByteArray();
        CodeSigner cs2 = (CodeSigner) new ObjectInputStream(
            new ByteArrayInputStream(data)).readObject();

        // Test for equality
        if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) {
            throw new Exception("CodeSigner serialization test FAILED");
        }
    }
 
Example #28
Source File: Serialize.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        // Create a certpath consisting of one certificate
        File f = new File(System.getProperty("test.src", "."), "cert_file");
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Certificate c = cf.generateCertificate(fis);
        fis.close();
        CertPath cp = cf.generateCertPath(Collections.singletonList(c));

        // Create a code signer
        CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp));

        // Serialize the code signer
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(cs);
        out.close();

        // Deserialize the code signer
        byte[] data = byteOut.toByteArray();
        CodeSigner cs2 = (CodeSigner) new ObjectInputStream(
            new ByteArrayInputStream(data)).readObject();

        // Test for equality
        if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) {
            throw new Exception("CodeSigner serialization test FAILED");
        }
    }
 
Example #29
Source File: ConstraintsParameters.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public ConstraintsParameters(X509Certificate c, boolean match,
        Date pkixdate, Timestamp jarTime, String variant) {
    cert = c;
    trustedMatch = match;
    pkixDate = pkixdate;
    jarTimestamp = jarTime;
    this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
    algorithm = null;
    algParams = null;
    publicKey = null;
}
 
Example #30
Source File: PKIXTimestampParameters.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void setTimestamp(Timestamp t) {
    jarTimestamp = t;
}