Example usage for org.bouncycastle.bcpg.sig KeyExpirationTime getTime

List of usage examples for org.bouncycastle.bcpg.sig KeyExpirationTime getTime

Introduction

In this page you can find the example usage for org.bouncycastle.bcpg.sig KeyExpirationTime getTime.

Prototype

public long getTime() 

Source Link

Document

Return the number of seconds after creation time a key is valid for.

Usage

From source file:com.google.e2e.bcdriver.KeyChecker.java

License:Apache License

private static final boolean isSignatureCurrent(PGPSignature sig, StringBuilder errors) {

    long ts = getSignatureTimestamp(sig, errors);
    if (ts < 0) {
        return false;
    }//  w  ww.  j  ava  2 s  .co m
    // Timestamp should not be in the future.
    if (ts > (System.currentTimeMillis() + ACCEPTABLE_DELTA_MSEC)) {
        errors.append(niceSig(sig) + " in the future? (" + new Date(ts) + ")\n");
        return false;
    }
    if (ts < 0) {
        errors.append(niceSig(sig) + " is negative? (" + ts + ")\n");
        return false;
    }

    // Check if the signature or key has expired.
    PGPSignatureSubpacketVector svec = sig.getHashedSubPackets();
    if (svec != null) {
        SignatureExpirationTime tspack = (SignatureExpirationTime) svec
                .getSubpacket(SignatureSubpacketTags.EXPIRE_TIME);
        if (tspack != null) {
            long expDelta = tspack.getTime() * 1000L;
            if (!acceptableInterval(sig, ts, expDelta, errors)) {
                return false;
            }
        }
        // If there's a key-expiration subpacket, also check that.
        KeyExpirationTime ket = (KeyExpirationTime) svec.getSubpacket(SignatureSubpacketTags.KEY_EXPIRE_TIME);
        if (ket != null) {
            long expDelta = ket.getTime() * 1000L;
            if (!acceptableInterval(sig, ts, expDelta, errors)) {
                return false;
            }
        }
    }

    return true;
}