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

The following examples show how to use sun.security.pkcs.PKCS9Attribute#isKnown() . 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: UnknownAttribute.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 2
Source File: UnknownAttribute.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 3
Source File: UnknownAttribute.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 4
Source File: UnknownAttribute.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 5
Source File: UnknownAttribute.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 6
Source File: UnknownAttribute.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 7
Source File: UnknownAttribute.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 8
Source File: UnknownAttribute.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 9
Source File: UnknownAttribute.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 10
Source File: UnknownAttribute.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 11
Source File: UnknownAttribute.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 12
Source File: UnknownAttribute.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
 
Example 13
Source File: UnknownAttribute.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(
            PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = {
            0x30, 0x08,                 // SEQUENCE OF
            0x06, 0x02, 0x2A, 0x03,     // OID 1.2.3 and
            0x31, 0x02, 0x05, 0x00      // an empty SET
    };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
        // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(
            new ObjectIdentifier("1.2.3"), new byte[]{0x31,0x02,0x05,0x00});
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}