Java Code Examples for sun.security.pkcs.PKCS9Attribute#getValue()

The following examples show how to use sun.security.pkcs.PKCS9Attribute#getValue() . 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: TimestampCheck.java    From dragonwell8_jdk with GNU General Public License v2.0 7 votes vote down vote up
static void checkTimestamp(String file, String policyId, String digestAlg)
        throws Exception {
    try (JarFile jf = new JarFile(file)) {
        JarEntry je = jf.getJarEntry("META-INF/SIGNER.RSA");
        try (InputStream is = jf.getInputStream(je)) {
            byte[] content = IOUtils.readAllBytes(is);
            PKCS7 p7 = new PKCS7(content);
            SignerInfo[] si = p7.getSignerInfos();
            if (si == null || si.length == 0) {
                throw new Exception("Not signed");
            }
            PKCS9Attribute p9 = si[0].getUnauthenticatedAttributes()
                    .getAttribute(PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_OID);
            PKCS7 tsToken = new PKCS7((byte[]) p9.getValue());
            TimestampToken tt =
                    new TimestampToken(tsToken.getContentInfo().getData());
            if (!tt.getHashAlgorithm().toString().equals(digestAlg)) {
                throw new Exception("Digest alg different");
            }
            if (!tt.getPolicyID().equals(policyId)) {
                throw new Exception("policyId different");
            }
        }
    }
}
 
Example 2
Source File: TimestampCheck.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static void checkTimestamp(String file, String policyId, String digestAlg)
        throws Exception {
    try (JarFile jf = new JarFile(file)) {
        JarEntry je = jf.getJarEntry("META-INF/OLD.RSA");
        try (InputStream is = jf.getInputStream(je)) {
            byte[] content = IOUtils.readFully(is, -1, true);
            PKCS7 p7 = new PKCS7(content);
            SignerInfo[] si = p7.getSignerInfos();
            if (si == null || si.length == 0) {
                throw new Exception("Not signed");
            }
            PKCS9Attribute p9 = si[0].getUnauthenticatedAttributes()
                    .getAttribute(PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_OID);
            PKCS7 tsToken = new PKCS7((byte[]) p9.getValue());
            TimestampToken tt =
                    new TimestampToken(tsToken.getContentInfo().getData());
            if (!tt.getHashAlgorithm().toString().equals(digestAlg)) {
                throw new Exception("Digest alg different");
            }
            if (!tt.getPolicyID().equals(policyId)) {
                throw new Exception("policyId different");
            }
        }
    }
}
 
Example 3
Source File: TimestampCheck.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static void checkTimestamp(String file, String policyId, String digestAlg)
        throws Exception {
    try (JarFile jf = new JarFile(file)) {
        JarEntry je = jf.getJarEntry("META-INF/SIGNER.RSA");
        try (InputStream is = jf.getInputStream(je)) {
            byte[] content = IOUtils.readAllBytes(is);
            PKCS7 p7 = new PKCS7(content);
            SignerInfo[] si = p7.getSignerInfos();
            if (si == null || si.length == 0) {
                throw new Exception("Not signed");
            }
            PKCS9Attribute p9 = si[0].getUnauthenticatedAttributes()
                    .getAttribute(PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_OID);
            PKCS7 tsToken = new PKCS7((byte[]) p9.getValue());
            TimestampToken tt =
                    new TimestampToken(tsToken.getContentInfo().getData());
            if (!tt.getHashAlgorithm().toString().equals(digestAlg)) {
                throw new Exception("Digest alg different");
            }
            if (!tt.getPolicyID().equals(policyId)) {
                throw new Exception("policyId different");
            }
        }
    }
}
 
Example 4
Source File: TimestampCheck.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static void checkTimestamp(String file, String policyId, String digestAlg)
        throws Exception {
    try (JarFile jf = new JarFile(file)) {
        JarEntry je = jf.getJarEntry("META-INF/OLD.RSA");
        try (InputStream is = jf.getInputStream(je)) {
            byte[] content = IOUtils.readFully(is, -1, true);
            PKCS7 p7 = new PKCS7(content);
            SignerInfo[] si = p7.getSignerInfos();
            if (si == null || si.length == 0) {
                throw new Exception("Not signed");
            }
            PKCS9Attribute p9 = si[0].getUnauthenticatedAttributes()
                    .getAttribute(PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_OID);
            PKCS7 tsToken = new PKCS7((byte[]) p9.getValue());
            TimestampToken tt =
                    new TimestampToken(tsToken.getContentInfo().getData());
            if (!tt.getHashAlgorithm().toString().equals(digestAlg)) {
                throw new Exception("Digest alg different");
            }
            if (!tt.getPolicyID().equals(policyId)) {
                throw new Exception("policyId different");
            }
        }
    }
}
 
Example 5
Source File: TimestampCheck.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static void checkTimestamp(String file, String policyId, String digestAlg)
        throws Exception {
    try (JarFile jf = new JarFile(file)) {
        JarEntry je = jf.getJarEntry("META-INF/SIGNER.RSA");
        try (InputStream is = jf.getInputStream(je)) {
            byte[] content = IOUtils.readAllBytes(is);
            PKCS7 p7 = new PKCS7(content);
            SignerInfo[] si = p7.getSignerInfos();
            if (si == null || si.length == 0) {
                throw new Exception("Not signed");
            }
            PKCS9Attribute p9 = si[0].getUnauthenticatedAttributes()
                    .getAttribute(PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_OID);
            PKCS7 tsToken = new PKCS7((byte[]) p9.getValue());
            TimestampToken tt =
                    new TimestampToken(tsToken.getContentInfo().getData());
            if (!tt.getHashAlgorithm().toString().equals(digestAlg)) {
                throw new Exception("Digest alg different");
            }
            if (!tt.getPolicyID().equals(policyId)) {
                throw new Exception("policyId different");
            }
        }
    }
}
 
Example 6
Source File: PKCS10Attribute.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs an attribute from a DER encoding.
 * This constructor expects the value to be encoded as defined above,
 * i.e. a SEQUENCE of OID and SET OF value(s), not a literal
 * X.509 v3 extension. Only PKCS9 defined attributes are supported
 * currently.
 *
 * @param derVal the der encoded attribute.
 * @exception IOException on parsing errors.
 */
public PKCS10Attribute(DerValue derVal) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(derVal);
    this.attributeId = attr.getOID();
    this.attributeValue = attr.getValue();
}
 
Example 7
Source File: PKCS10Attribute.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs an attribute from PKCS9 attribute.
 *
 * @param attr the PKCS9Attribute to create from.
 */
public PKCS10Attribute(PKCS9Attribute attr) {
    this.attributeId = attr.getOID();
    this.attributeValue = attr.getValue();
}
 
Example 8
Source File: PKCS10Attribute.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs an attribute from a DER encoding.
 * This constructor expects the value to be encoded as defined above,
 * i.e. a SEQUENCE of OID and SET OF value(s), not a literal
 * X.509 v3 extension. Only PKCS9 defined attributes are supported
 * currently.
 *
 * @param derVal the der encoded attribute.
 * @exception IOException on parsing errors.
 */
public PKCS10Attribute(DerValue derVal) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(derVal);
    this.attributeId = attr.getOID();
    this.attributeValue = attr.getValue();
}
 
Example 9
Source File: PKCS10Attribute.java    From Bytecoder with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an attribute from PKCS9 attribute.
 *
 * @param attr the PKCS9Attribute to create from.
 */
public PKCS10Attribute(PKCS9Attribute attr) {
    this.attributeId = attr.getOID();
    this.attributeValue = attr.getValue();
}
 
Example 10
Source File: PKCS10Attribute.java    From Bytecoder with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an attribute from a DER encoding.
 * This constructor expects the value to be encoded as defined above,
 * i.e. a SEQUENCE of OID and SET OF value(s), not a literal
 * X.509 v3 extension. Only PKCS9 defined attributes are supported
 * currently.
 *
 * @param derVal the der encoded attribute.
 * @exception IOException on parsing errors.
 */
public PKCS10Attribute(DerValue derVal) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(derVal);
    this.attributeId = attr.getOID();
    this.attributeValue = attr.getValue();
}
 
Example 11
Source File: PKCS10Attribute.java    From jdk8u_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs an attribute from PKCS9 attribute.
 *
 * @param attr the PKCS9Attribute to create from.
 */
public PKCS10Attribute(PKCS9Attribute attr) {
    this.attributeId = attr.getOID();
    this.attributeValue = attr.getValue();
}
 
Example 12
Source File: PKCS10Attribute.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs an attribute from a DER encoding.
 * This constructor expects the value to be encoded as defined above,
 * i.e. a SEQUENCE of OID and SET OF value(s), not a literal
 * X.509 v3 extension. Only PKCS9 defined attributes are supported
 * currently.
 *
 * @param derVal the der encoded attribute.
 * @exception IOException on parsing errors.
 */
public PKCS10Attribute(DerValue derVal) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(derVal);
    this.attributeId = attr.getOID();
    this.attributeValue = attr.getValue();
}
 
Example 13
Source File: PKCS10Attribute.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs an attribute from PKCS9 attribute.
 *
 * @param attr the PKCS9Attribute to create from.
 */
public PKCS10Attribute(PKCS9Attribute attr) {
    this.attributeId = attr.getOID();
    this.attributeValue = attr.getValue();
}
 
Example 14
Source File: PKCS10Attribute.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs an attribute from a DER encoding.
 * This constructor expects the value to be encoded as defined above,
 * i.e. a SEQUENCE of OID and SET OF value(s), not a literal
 * X.509 v3 extension. Only PKCS9 defined attributes are supported
 * currently.
 *
 * @param derVal the der encoded attribute.
 * @exception IOException on parsing errors.
 */
public PKCS10Attribute(DerValue derVal) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(derVal);
    this.attributeId = attr.getOID();
    this.attributeValue = attr.getValue();
}
 
Example 15
Source File: PKCS10Attribute.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs an attribute from PKCS9 attribute.
 *
 * @param attr the PKCS9Attribute to create from.
 */
public PKCS10Attribute(PKCS9Attribute attr) {
    this.attributeId = attr.getOID();
    this.attributeValue = attr.getValue();
}
 
Example 16
Source File: PKCS10Attribute.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs an attribute from a DER encoding.
 * This constructor expects the value to be encoded as defined above,
 * i.e. a SEQUENCE of OID and SET OF value(s), not a literal
 * X.509 v3 extension. Only PKCS9 defined attributes are supported
 * currently.
 *
 * @param derVal the der encoded attribute.
 * @exception IOException on parsing errors.
 */
public PKCS10Attribute(DerValue derVal) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(derVal);
    this.attributeId = attr.getOID();
    this.attributeValue = attr.getValue();
}
 
Example 17
Source File: PKCS10Attribute.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs an attribute from PKCS9 attribute.
 *
 * @param attr the PKCS9Attribute to create from.
 */
public PKCS10Attribute(PKCS9Attribute attr) {
    this.attributeId = attr.getOID();
    this.attributeValue = attr.getValue();
}
 
Example 18
Source File: PKCS10Attribute.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs an attribute from PKCS9 attribute.
 *
 * @param attr the PKCS9Attribute to create from.
 */
public PKCS10Attribute(PKCS9Attribute attr) {
    this.attributeId = attr.getOID();
    this.attributeValue = attr.getValue();
}
 
Example 19
Source File: PKCS10Attribute.java    From jdk8u-dev-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs an attribute from a DER encoding.
 * This constructor expects the value to be encoded as defined above,
 * i.e. a SEQUENCE of OID and SET OF value(s), not a literal
 * X.509 v3 extension. Only PKCS9 defined attributes are supported
 * currently.
 *
 * @param derVal the der encoded attribute.
 * @exception IOException on parsing errors.
 */
public PKCS10Attribute(DerValue derVal) throws IOException {
    PKCS9Attribute attr = new PKCS9Attribute(derVal);
    this.attributeId = attr.getOID();
    this.attributeValue = attr.getValue();
}
 
Example 20
Source File: PKCS10Attribute.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs an attribute from PKCS9 attribute.
 *
 * @param attr the PKCS9Attribute to create from.
 */
public PKCS10Attribute(PKCS9Attribute attr) {
    this.attributeId = attr.getOID();
    this.attributeValue = attr.getValue();
}