java.security.PKCS12Attribute Java Examples

The following examples show how to use java.security.PKCS12Attribute. 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: MetadataStoreLoadTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void setUp() {
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    final String allCharsString = "`1234567890-=qwertyuiop[]asdfghjkl;'\\zx"
            + "cvbnm,./!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:|>ZXCVBNM<>?\"";
    StringBuilder sbPrintable = new StringBuilder();
    while (sbPrintable.length() < MAX_HUGE_SIZE) {
        sbPrintable.append(allCharsString);
    }
    final String hugePrintable = sbPrintable.toString();
    final String binaryString = "00:11:22:33:44:55:66:77:88:99:AA:BB:DD:"
            + "EE:FF:";
    StringBuilder sbBinary = new StringBuilder();
    sbBinary.append(binaryString);
    while (sbBinary.length() < MAX_HUGE_SIZE) {
        sbBinary.append(":").append(binaryString);
    }
    sbBinary.insert(0, "[").append("]");
    final String hugeBinary = sbBinary.toString();
    ATTR_SET = new PKCS12Attribute[5];
    ATTR_SET[0] = new PKCS12Attribute("1.2.840.113549.1.9.1",
            "Test email addres attr <[email protected]>");
    ATTR_SET[1] = new PKCS12Attribute("1.2.110.1", "not registered attr");
    ATTR_SET[2] = new PKCS12Attribute("1.2.110.2", hugePrintable);
    ATTR_SET[3] = new PKCS12Attribute("1.2.110.3", hugeBinary);
    ATTR_SET[4] = new PKCS12Attribute("1.2.110.2", " ");
}
 
Example #2
Source File: MetadataStoreLoadTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void setUp() {
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    final String allCharsString = "`1234567890-=qwertyuiop[]asdfghjkl;'\\zx"
            + "cvbnm,./!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:|>ZXCVBNM<>?\"";
    StringBuilder sbPrintable = new StringBuilder();
    while (sbPrintable.length() < MAX_HUGE_SIZE) {
        sbPrintable.append(allCharsString);
    }
    final String hugePrintable = sbPrintable.toString();
    final String binaryString = "00:11:22:33:44:55:66:77:88:99:AA:BB:DD:"
            + "EE:FF:";
    StringBuilder sbBinary = new StringBuilder();
    sbBinary.append(binaryString);
    while (sbBinary.length() < MAX_HUGE_SIZE) {
        sbBinary.append(":").append(binaryString);
    }
    sbBinary.insert(0, "[").append("]");
    final String hugeBinary = sbBinary.toString();
    ATTR_SET = new PKCS12Attribute[5];
    ATTR_SET[0] = new PKCS12Attribute("1.2.840.113549.1.9.1",
            "Test email addres attr <[email protected]>");
    ATTR_SET[1] = new PKCS12Attribute("1.2.110.1", "not registered attr");
    ATTR_SET[2] = new PKCS12Attribute("1.2.110.2", hugePrintable);
    ATTR_SET[3] = new PKCS12Attribute("1.2.110.3", hugeBinary);
    ATTR_SET[4] = new PKCS12Attribute("1.2.110.2", " ");
}
 
Example #3
Source File: MetadataStoreLoadTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void setUp() {
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    final String allCharsString = "`1234567890-=qwertyuiop[]asdfghjkl;'\\zx"
            + "cvbnm,./!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:|>ZXCVBNM<>?\"";
    StringBuilder sbPrintable = new StringBuilder();
    while (sbPrintable.length() < MAX_HUGE_SIZE) {
        sbPrintable.append(allCharsString);
    }
    final String hugePrintable = sbPrintable.toString();
    final String binaryString = "00:11:22:33:44:55:66:77:88:99:AA:BB:DD:"
            + "EE:FF:";
    StringBuilder sbBinary = new StringBuilder();
    sbBinary.append(binaryString);
    while (sbBinary.length() < MAX_HUGE_SIZE) {
        sbBinary.append(":").append(binaryString);
    }
    sbBinary.insert(0, "[").append("]");
    final String hugeBinary = sbBinary.toString();
    ATTR_SET = new PKCS12Attribute[5];
    ATTR_SET[0] = new PKCS12Attribute("1.2.840.113549.1.9.1",
            "Test email addres attr <[email protected]>");
    ATTR_SET[1] = new PKCS12Attribute("1.2.110.1", "not registered attr");
    ATTR_SET[2] = new PKCS12Attribute("1.2.110.2", hugePrintable);
    ATTR_SET[3] = new PKCS12Attribute("1.2.110.3", hugeBinary);
    ATTR_SET[4] = new PKCS12Attribute("1.2.110.2", " ");
}
 
Example #4
Source File: MetadataStoreLoadTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void setUp() {
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    final String allCharsString = "`1234567890-=qwertyuiop[]asdfghjkl;'\\zx"
            + "cvbnm,./!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:|>ZXCVBNM<>?\"";
    StringBuilder sbPrintable = new StringBuilder();
    while (sbPrintable.length() < MAX_HUGE_SIZE) {
        sbPrintable.append(allCharsString);
    }
    final String hugePrintable = sbPrintable.toString();
    final String binaryString = "00:11:22:33:44:55:66:77:88:99:AA:BB:DD:"
            + "EE:FF:";
    StringBuilder sbBinary = new StringBuilder();
    sbBinary.append(binaryString);
    while (sbBinary.length() < MAX_HUGE_SIZE) {
        sbBinary.append(":").append(binaryString);
    }
    sbBinary.insert(0, "[").append("]");
    final String hugeBinary = sbBinary.toString();
    ATTR_SET = new PKCS12Attribute[5];
    ATTR_SET[0] = new PKCS12Attribute("1.2.840.113549.1.9.1",
            "Test email addres attr <[email protected]>");
    ATTR_SET[1] = new PKCS12Attribute("1.2.110.1", "not registered attr");
    ATTR_SET[2] = new PKCS12Attribute("1.2.110.2", hugePrintable);
    ATTR_SET[3] = new PKCS12Attribute("1.2.110.3", hugeBinary);
    ATTR_SET[4] = new PKCS12Attribute("1.2.110.2", " ");
}
 
Example #5
Source File: MetadataStoreLoadTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void setUp() {
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    final String allCharsString = "`1234567890-=qwertyuiop[]asdfghjkl;'\\zx"
            + "cvbnm,./!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:|>ZXCVBNM<>?\"";
    StringBuilder sbPrintable = new StringBuilder();
    while (sbPrintable.length() < MAX_HUGE_SIZE) {
        sbPrintable.append(allCharsString);
    }
    final String hugePrintable = sbPrintable.toString();
    final String binaryString = "00:11:22:33:44:55:66:77:88:99:AA:BB:DD:"
            + "EE:FF:";
    StringBuilder sbBinary = new StringBuilder();
    sbBinary.append(binaryString);
    while (sbBinary.length() < MAX_HUGE_SIZE) {
        sbBinary.append(":").append(binaryString);
    }
    sbBinary.insert(0, "[").append("]");
    final String hugeBinary = sbBinary.toString();
    ATTR_SET = new PKCS12Attribute[5];
    ATTR_SET[0] = new PKCS12Attribute("1.2.840.113549.1.9.1",
            "Test email addres attr <[email protected]>");
    ATTR_SET[1] = new PKCS12Attribute("1.2.110.1", "not registered attr");
    ATTR_SET[2] = new PKCS12Attribute("1.2.110.2", hugePrintable);
    ATTR_SET[3] = new PKCS12Attribute("1.2.110.3", hugeBinary);
    ATTR_SET[4] = new PKCS12Attribute("1.2.110.2", " ");
}
 
Example #6
Source File: MetadataStoreLoadTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void setUp() {
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    final String allCharsString = "`1234567890-=qwertyuiop[]asdfghjkl;'\\zx"
            + "cvbnm,./!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:|>ZXCVBNM<>?\"";
    StringBuilder sbPrintable = new StringBuilder();
    while (sbPrintable.length() < MAX_HUGE_SIZE) {
        sbPrintable.append(allCharsString);
    }
    final String hugePrintable = sbPrintable.toString();
    final String binaryString = "00:11:22:33:44:55:66:77:88:99:AA:BB:DD:"
            + "EE:FF:";
    StringBuilder sbBinary = new StringBuilder();
    sbBinary.append(binaryString);
    while (sbBinary.length() < MAX_HUGE_SIZE) {
        sbBinary.append(":").append(binaryString);
    }
    sbBinary.insert(0, "[").append("]");
    final String hugeBinary = sbBinary.toString();
    ATTR_SET = new PKCS12Attribute[5];
    ATTR_SET[0] = new PKCS12Attribute("1.2.840.113549.1.9.1",
            "Test email addres attr <[email protected]>");
    ATTR_SET[1] = new PKCS12Attribute("1.2.110.1", "not registered attr");
    ATTR_SET[2] = new PKCS12Attribute("1.2.110.2", hugePrintable);
    ATTR_SET[3] = new PKCS12Attribute("1.2.110.3", hugeBinary);
    ATTR_SET[4] = new PKCS12Attribute("1.2.110.2", " ");
}
 
Example #7
Source File: MetadataStoreLoadTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void setUp() {
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    final String allCharsString = "`1234567890-=qwertyuiop[]asdfghjkl;'\\zx"
            + "cvbnm,./!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:|>ZXCVBNM<>?\"";
    StringBuilder sbPrintable = new StringBuilder();
    while (sbPrintable.length() < MAX_HUGE_SIZE) {
        sbPrintable.append(allCharsString);
    }
    final String hugePrintable = sbPrintable.toString();
    final String binaryString = "00:11:22:33:44:55:66:77:88:99:AA:BB:DD:"
            + "EE:FF:";
    StringBuilder sbBinary = new StringBuilder();
    sbBinary.append(binaryString);
    while (sbBinary.length() < MAX_HUGE_SIZE) {
        sbBinary.append(":").append(binaryString);
    }
    sbBinary.insert(0, "[").append("]");
    final String hugeBinary = sbBinary.toString();
    ATTR_SET = new PKCS12Attribute[5];
    ATTR_SET[0] = new PKCS12Attribute("1.2.840.113549.1.9.1",
            "Test email addres attr <[email protected]>");
    ATTR_SET[1] = new PKCS12Attribute("1.2.110.1", "not registered attr");
    ATTR_SET[2] = new PKCS12Attribute("1.2.110.2", hugePrintable);
    ATTR_SET[3] = new PKCS12Attribute("1.2.110.3", hugeBinary);
    ATTR_SET[4] = new PKCS12Attribute("1.2.110.2", " ");
}
 
Example #8
Source File: MetadataStoreLoadTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void setUp() {
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    final String allCharsString = "`1234567890-=qwertyuiop[]asdfghjkl;'\\zx"
            + "cvbnm,./!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:|>ZXCVBNM<>?\"";
    StringBuilder sbPrintable = new StringBuilder();
    while (sbPrintable.length() < MAX_HUGE_SIZE) {
        sbPrintable.append(allCharsString);
    }
    final String hugePrintable = sbPrintable.toString();
    final String binaryString = "00:11:22:33:44:55:66:77:88:99:AA:BB:DD:"
            + "EE:FF:";
    StringBuilder sbBinary = new StringBuilder();
    sbBinary.append(binaryString);
    while (sbBinary.length() < MAX_HUGE_SIZE) {
        sbBinary.append(":").append(binaryString);
    }
    sbBinary.insert(0, "[").append("]");
    final String hugeBinary = sbBinary.toString();
    ATTR_SET = new PKCS12Attribute[5];
    ATTR_SET[0] = new PKCS12Attribute("1.2.840.113549.1.9.1",
            "Test email addres attr <[email protected]>");
    ATTR_SET[1] = new PKCS12Attribute("1.2.110.1", "not registered attr");
    ATTR_SET[2] = new PKCS12Attribute("1.2.110.2", hugePrintable);
    ATTR_SET[3] = new PKCS12Attribute("1.2.110.3", hugeBinary);
    ATTR_SET[4] = new PKCS12Attribute("1.2.110.2", " ");
}
 
Example #9
Source File: PKCS12KeyStore.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private Set<KeyStore.Entry.Attribute> getAttributes(Entry entry) {

        if (entry.attributes == null) {
            entry.attributes = new HashSet<>();
        }

        // friendlyName
        entry.attributes.add(new PKCS12Attribute(
            PKCS9FriendlyName_OID.toString(), entry.alias));

        // localKeyID
        byte[] keyIdValue = entry.keyId;
        if (keyIdValue != null) {
            entry.attributes.add(new PKCS12Attribute(
                PKCS9LocalKeyId_OID.toString(), Debug.toString(keyIdValue)));
        }

        // trustedKeyUsage
        if (entry instanceof CertEntry) {
            ObjectIdentifier[] trustedKeyUsageValue =
                ((CertEntry) entry).trustedKeyUsage;
            if (trustedKeyUsageValue != null) {
                if (trustedKeyUsageValue.length == 1) { // omit brackets
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        trustedKeyUsageValue[0].toString()));
                } else { // multi-valued
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        Arrays.toString(trustedKeyUsageValue)));
                }
            }
        }

        return entry.attributes;
    }
 
Example #10
Source File: PKCS12KeyStore.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private Set<KeyStore.Entry.Attribute> getAttributes(Entry entry) {

        if (entry.attributes == null) {
            entry.attributes = new HashSet<>();
        }

        // friendlyName
        entry.attributes.add(new PKCS12Attribute(
            PKCS9FriendlyName_OID.toString(), entry.alias));

        // localKeyID
        byte[] keyIdValue = entry.keyId;
        if (keyIdValue != null) {
            entry.attributes.add(new PKCS12Attribute(
                PKCS9LocalKeyId_OID.toString(), Debug.toString(keyIdValue)));
        }

        // trustedKeyUsage
        if (entry instanceof CertEntry) {
            ObjectIdentifier[] trustedKeyUsageValue =
                ((CertEntry) entry).trustedKeyUsage;
            if (trustedKeyUsageValue != null) {
                if (trustedKeyUsageValue.length == 1) { // omit brackets
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        trustedKeyUsageValue[0].toString()));
                } else { // multi-valued
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        Arrays.toString(trustedKeyUsageValue)));
                }
            }
        }

        return entry.attributes;
    }
 
Example #11
Source File: PKCS12KeyStore.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private Set<KeyStore.Entry.Attribute> getAttributes(Entry entry) {

        if (entry.attributes == null) {
            entry.attributes = new HashSet<>();
        }

        // friendlyName
        entry.attributes.add(new PKCS12Attribute(
            PKCS9FriendlyName_OID.toString(), entry.alias));

        // localKeyID
        byte[] keyIdValue = entry.keyId;
        if (keyIdValue != null) {
            entry.attributes.add(new PKCS12Attribute(
                PKCS9LocalKeyId_OID.toString(), Debug.toString(keyIdValue)));
        }

        // trustedKeyUsage
        if (entry instanceof CertEntry) {
            ObjectIdentifier[] trustedKeyUsageValue =
                ((CertEntry) entry).trustedKeyUsage;
            if (trustedKeyUsageValue != null) {
                if (trustedKeyUsageValue.length == 1) { // omit brackets
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        trustedKeyUsageValue[0].toString()));
                } else { // multi-valued
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        Arrays.toString(trustedKeyUsageValue)));
                }
            }
        }

        return entry.attributes;
    }
 
Example #12
Source File: PKCS12KeyStore.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private Set<KeyStore.Entry.Attribute> getAttributes(Entry entry) {

        if (entry.attributes == null) {
            entry.attributes = new HashSet<>();
        }

        // friendlyName
        entry.attributes.add(new PKCS12Attribute(
            PKCS9FriendlyName_OID.toString(), entry.alias));

        // localKeyID
        byte[] keyIdValue = entry.keyId;
        if (keyIdValue != null) {
            entry.attributes.add(new PKCS12Attribute(
                PKCS9LocalKeyId_OID.toString(), Debug.toString(keyIdValue)));
        }

        // trustedKeyUsage
        if (entry instanceof CertEntry) {
            ObjectIdentifier[] trustedKeyUsageValue =
                ((CertEntry) entry).trustedKeyUsage;
            if (trustedKeyUsageValue != null) {
                if (trustedKeyUsageValue.length == 1) { // omit brackets
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        trustedKeyUsageValue[0].toString()));
                } else { // multi-valued
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        Arrays.toString(trustedKeyUsageValue)));
                }
            }
        }

        return entry.attributes;
    }
 
Example #13
Source File: PKCS12KeyStore.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private Set<KeyStore.Entry.Attribute> getAttributes(Entry entry) {

        if (entry.attributes == null) {
            entry.attributes = new HashSet<>();
        }

        // friendlyName
        entry.attributes.add(new PKCS12Attribute(
            PKCS9FriendlyName_OID.toString(), entry.alias));

        // localKeyID
        byte[] keyIdValue = entry.keyId;
        if (keyIdValue != null) {
            entry.attributes.add(new PKCS12Attribute(
                PKCS9LocalKeyId_OID.toString(), Debug.toString(keyIdValue)));
        }

        // trustedKeyUsage
        if (entry instanceof CertEntry) {
            ObjectIdentifier[] trustedKeyUsageValue =
                ((CertEntry) entry).trustedKeyUsage;
            if (trustedKeyUsageValue != null) {
                if (trustedKeyUsageValue.length == 1) { // omit brackets
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        trustedKeyUsageValue[0].toString()));
                } else { // multi-valued
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        Arrays.toString(trustedKeyUsageValue)));
                }
            }
        }

        return entry.attributes;
    }
 
Example #14
Source File: PKCS12KeyStore.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Set<KeyStore.Entry.Attribute> getAttributes(Entry entry) {

        if (entry.attributes == null) {
            entry.attributes = new HashSet<>();
        }

        // friendlyName
        entry.attributes.add(new PKCS12Attribute(
            PKCS9FriendlyName_OID.toString(), entry.alias));

        // localKeyID
        byte[] keyIdValue = entry.keyId;
        if (keyIdValue != null) {
            entry.attributes.add(new PKCS12Attribute(
                PKCS9LocalKeyId_OID.toString(), Debug.toString(keyIdValue)));
        }

        // trustedKeyUsage
        if (entry instanceof CertEntry) {
            ObjectIdentifier[] trustedKeyUsageValue =
                ((CertEntry) entry).trustedKeyUsage;
            if (trustedKeyUsageValue != null) {
                if (trustedKeyUsageValue.length == 1) { // omit brackets
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        trustedKeyUsageValue[0].toString()));
                } else { // multi-valued
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        Arrays.toString(trustedKeyUsageValue)));
                }
            }
        }

        return entry.attributes;
    }
 
Example #15
Source File: PKCS12KeyStore.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private Set<KeyStore.Entry.Attribute> getAttributes(Entry entry) {

        if (entry.attributes == null) {
            entry.attributes = new HashSet<>();
        }

        // friendlyName
        entry.attributes.add(new PKCS12Attribute(
            PKCS9FriendlyName_OID.toString(), entry.alias));

        // localKeyID
        byte[] keyIdValue = entry.keyId;
        if (keyIdValue != null) {
            entry.attributes.add(new PKCS12Attribute(
                PKCS9LocalKeyId_OID.toString(), Debug.toString(keyIdValue)));
        }

        // trustedKeyUsage
        if (entry instanceof CertEntry) {
            ObjectIdentifier[] trustedKeyUsageValue =
                ((CertEntry) entry).trustedKeyUsage;
            if (trustedKeyUsageValue != null) {
                if (trustedKeyUsageValue.length == 1) { // omit brackets
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        trustedKeyUsageValue[0].toString()));
                } else { // multi-valued
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        Arrays.toString(trustedKeyUsageValue)));
                }
            }
        }

        return entry.attributes;
    }
 
Example #16
Source File: PKCS12KeyStore.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private Set<KeyStore.Entry.Attribute> getAttributes(Entry entry) {

        if (entry.attributes == null) {
            entry.attributes = new HashSet<>();
        }

        // friendlyName
        entry.attributes.add(new PKCS12Attribute(
            PKCS9FriendlyName_OID.toString(), entry.alias));

        // localKeyID
        byte[] keyIdValue = entry.keyId;
        if (keyIdValue != null) {
            entry.attributes.add(new PKCS12Attribute(
                PKCS9LocalKeyId_OID.toString(), Debug.toString(keyIdValue)));
        }

        // trustedKeyUsage
        if (entry instanceof CertEntry) {
            ObjectIdentifier[] trustedKeyUsageValue =
                ((CertEntry) entry).trustedKeyUsage;
            if (trustedKeyUsageValue != null) {
                if (trustedKeyUsageValue.length == 1) { // omit brackets
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        trustedKeyUsageValue[0].toString()));
                } else { // multi-valued
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        Arrays.toString(trustedKeyUsageValue)));
                }
            }
        }

        return entry.attributes;
    }
 
Example #17
Source File: PKCS12KeyStore.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private Set<KeyStore.Entry.Attribute> getAttributes(Entry entry) {

        if (entry.attributes == null) {
            entry.attributes = new HashSet<>();
        }

        // friendlyName
        entry.attributes.add(new PKCS12Attribute(
            PKCS9FriendlyName_OID.toString(), entry.alias));

        // localKeyID
        byte[] keyIdValue = entry.keyId;
        if (keyIdValue != null) {
            entry.attributes.add(new PKCS12Attribute(
                PKCS9LocalKeyId_OID.toString(), Debug.toString(keyIdValue)));
        }

        // trustedKeyUsage
        if (entry instanceof CertEntry) {
            ObjectIdentifier[] trustedKeyUsageValue =
                ((CertEntry) entry).trustedKeyUsage;
            if (trustedKeyUsageValue != null) {
                if (trustedKeyUsageValue.length == 1) { // omit brackets
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        trustedKeyUsageValue[0].toString()));
                } else { // multi-valued
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        Arrays.toString(trustedKeyUsageValue)));
                }
            }
        }

        return entry.attributes;
    }
 
Example #18
Source File: PKCS12KeyStore.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private Set<KeyStore.Entry.Attribute> getAttributes(Entry entry) {

        if (entry.attributes == null) {
            entry.attributes = new HashSet<>();
        }

        // friendlyName
        entry.attributes.add(new PKCS12Attribute(
            PKCS9FriendlyName_OID.toString(), entry.alias));

        // localKeyID
        byte[] keyIdValue = entry.keyId;
        if (keyIdValue != null) {
            entry.attributes.add(new PKCS12Attribute(
                PKCS9LocalKeyId_OID.toString(), Debug.toString(keyIdValue)));
        }

        // trustedKeyUsage
        if (entry instanceof CertEntry) {
            ObjectIdentifier[] trustedKeyUsageValue =
                ((CertEntry) entry).trustedKeyUsage;
            if (trustedKeyUsageValue != null) {
                if (trustedKeyUsageValue.length == 1) { // omit brackets
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        trustedKeyUsageValue[0].toString()));
                } else { // multi-valued
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        Arrays.toString(trustedKeyUsageValue)));
                }
            }
        }

        return entry.attributes;
    }
 
Example #19
Source File: PKCS12KeyStore.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private Set<KeyStore.Entry.Attribute> getAttributes(Entry entry) {

        if (entry.attributes == null) {
            entry.attributes = new HashSet<>();
        }

        // friendlyName
        entry.attributes.add(new PKCS12Attribute(
            PKCS9FriendlyName_OID.toString(), entry.alias));

        // localKeyID
        byte[] keyIdValue = entry.keyId;
        if (keyIdValue != null) {
            entry.attributes.add(new PKCS12Attribute(
                PKCS9LocalKeyId_OID.toString(), Debug.toString(keyIdValue)));
        }

        // trustedKeyUsage
        if (entry instanceof CertEntry) {
            ObjectIdentifier[] trustedKeyUsageValue =
                ((CertEntry) entry).trustedKeyUsage;
            if (trustedKeyUsageValue != null) {
                if (trustedKeyUsageValue.length == 1) { // omit brackets
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        trustedKeyUsageValue[0].toString()));
                } else { // multi-valued
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        Arrays.toString(trustedKeyUsageValue)));
                }
            }
        }

        return entry.attributes;
    }
 
Example #20
Source File: PKCS12KeyStore.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private Set<KeyStore.Entry.Attribute> getAttributes(Entry entry) {

        if (entry.attributes == null) {
            entry.attributes = new HashSet<>();
        }

        // friendlyName
        entry.attributes.add(new PKCS12Attribute(
            PKCS9FriendlyName_OID.toString(), entry.alias));

        // localKeyID
        byte[] keyIdValue = entry.keyId;
        if (keyIdValue != null) {
            entry.attributes.add(new PKCS12Attribute(
                PKCS9LocalKeyId_OID.toString(), Debug.toString(keyIdValue)));
        }

        // trustedKeyUsage
        if (entry instanceof CertEntry) {
            ObjectIdentifier[] trustedKeyUsageValue =
                ((CertEntry) entry).trustedKeyUsage;
            if (trustedKeyUsageValue != null) {
                if (trustedKeyUsageValue.length == 1) { // omit brackets
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        trustedKeyUsageValue[0].toString()));
                } else { // multi-valued
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        Arrays.toString(trustedKeyUsageValue)));
                }
            }
        }

        return entry.attributes;
    }
 
Example #21
Source File: PKCS12KeyStore.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private Set<KeyStore.Entry.Attribute> getAttributes(Entry entry) {

        if (entry.attributes == null) {
            entry.attributes = new HashSet<>();
        }

        // friendlyName
        entry.attributes.add(new PKCS12Attribute(
            PKCS9FriendlyName_OID.toString(), entry.alias));

        // localKeyID
        byte[] keyIdValue = entry.keyId;
        if (keyIdValue != null) {
            entry.attributes.add(new PKCS12Attribute(
                PKCS9LocalKeyId_OID.toString(), Debug.toString(keyIdValue)));
        }

        // trustedKeyUsage
        if (entry instanceof CertEntry) {
            ObjectIdentifier[] trustedKeyUsageValue =
                ((CertEntry) entry).trustedKeyUsage;
            if (trustedKeyUsageValue != null) {
                if (trustedKeyUsageValue.length == 1) { // omit brackets
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        trustedKeyUsageValue[0].toString()));
                } else { // multi-valued
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        Arrays.toString(trustedKeyUsageValue)));
                }
            }
        }

        return entry.attributes;
    }
 
Example #22
Source File: PKCS12KeyStore.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private Set<KeyStore.Entry.Attribute> getAttributes(Entry entry) {

        if (entry.attributes == null) {
            entry.attributes = new HashSet<>();
        }

        // friendlyName
        entry.attributes.add(new PKCS12Attribute(
            PKCS9FriendlyName_OID.toString(), entry.alias));

        // localKeyID
        byte[] keyIdValue = entry.keyId;
        if (keyIdValue != null) {
            entry.attributes.add(new PKCS12Attribute(
                PKCS9LocalKeyId_OID.toString(), Debug.toString(keyIdValue)));
        }

        // trustedKeyUsage
        if (entry instanceof CertEntry) {
            ObjectIdentifier[] trustedKeyUsageValue =
                ((CertEntry) entry).trustedKeyUsage;
            if (trustedKeyUsageValue != null) {
                if (trustedKeyUsageValue.length == 1) { // omit brackets
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        trustedKeyUsageValue[0].toString()));
                } else { // multi-valued
                    entry.attributes.add(new PKCS12Attribute(
                        TrustedKeyUsage_OID.toString(),
                        Arrays.toString(trustedKeyUsageValue)));
                }
            }
        }

        return entry.attributes;
    }
 
Example #23
Source File: PKCS12KeyStore.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private byte[] getBagAttributes(String alias, byte[] keyId,
    ObjectIdentifier[] trustedUsage,
    Set<KeyStore.Entry.Attribute> attributes) throws IOException {

    byte[] localKeyID = null;
    byte[] friendlyName = null;
    byte[] trustedKeyUsage = null;

    // return null if all three attributes are null
    if ((alias == null) && (keyId == null) && (trustedKeyUsage == null)) {
        return null;
    }

    // SafeBag Attributes
    DerOutputStream bagAttrs = new DerOutputStream();

    // Encode the friendlyname oid.
    if (alias != null) {
        DerOutputStream bagAttr1 = new DerOutputStream();
        bagAttr1.putOID(PKCS9FriendlyName_OID);
        DerOutputStream bagAttrContent1 = new DerOutputStream();
        DerOutputStream bagAttrValue1 = new DerOutputStream();
        bagAttrContent1.putBMPString(alias);
        bagAttr1.write(DerValue.tag_Set, bagAttrContent1);
        bagAttrValue1.write(DerValue.tag_Sequence, bagAttr1);
        friendlyName = bagAttrValue1.toByteArray();
    }

    // Encode the localkeyId oid.
    if (keyId != null) {
        DerOutputStream bagAttr2 = new DerOutputStream();
        bagAttr2.putOID(PKCS9LocalKeyId_OID);
        DerOutputStream bagAttrContent2 = new DerOutputStream();
        DerOutputStream bagAttrValue2 = new DerOutputStream();
        bagAttrContent2.putOctetString(keyId);
        bagAttr2.write(DerValue.tag_Set, bagAttrContent2);
        bagAttrValue2.write(DerValue.tag_Sequence, bagAttr2);
        localKeyID = bagAttrValue2.toByteArray();
    }

    // Encode the trustedKeyUsage oid.
    if (trustedUsage != null) {
        DerOutputStream bagAttr3 = new DerOutputStream();
        bagAttr3.putOID(TrustedKeyUsage_OID);
        DerOutputStream bagAttrContent3 = new DerOutputStream();
        DerOutputStream bagAttrValue3 = new DerOutputStream();
        for (ObjectIdentifier usage : trustedUsage) {
            bagAttrContent3.putOID(usage);
        }
        bagAttr3.write(DerValue.tag_Set, bagAttrContent3);
        bagAttrValue3.write(DerValue.tag_Sequence, bagAttr3);
        trustedKeyUsage = bagAttrValue3.toByteArray();
    }

    DerOutputStream attrs = new DerOutputStream();
    if (friendlyName != null) {
        attrs.write(friendlyName);
    }
    if (localKeyID != null) {
        attrs.write(localKeyID);
    }
    if (trustedKeyUsage != null) {
        attrs.write(trustedKeyUsage);
    }

    if (attributes != null) {
        for (KeyStore.Entry.Attribute attribute : attributes) {
            String attributeName = attribute.getName();
            // skip friendlyName, localKeyId and trustedKeyUsage
            if (CORE_ATTRIBUTES[0].equals(attributeName) ||
                CORE_ATTRIBUTES[1].equals(attributeName) ||
                CORE_ATTRIBUTES[2].equals(attributeName)) {
                continue;
            }
            attrs.write(((PKCS12Attribute) attribute).getEncoded());
        }
    }

    bagAttrs.write(DerValue.tag_Set, attrs);
    return bagAttrs.toByteArray();
}
 
Example #24
Source File: PKCS12KeyStore.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private byte[] getBagAttributes(String alias, byte[] keyId,
    ObjectIdentifier[] trustedUsage,
    Set<KeyStore.Entry.Attribute> attributes) throws IOException {

    byte[] localKeyID = null;
    byte[] friendlyName = null;
    byte[] trustedKeyUsage = null;

    // return null if all three attributes are null
    if ((alias == null) && (keyId == null) && (trustedKeyUsage == null)) {
        return null;
    }

    // SafeBag Attributes
    DerOutputStream bagAttrs = new DerOutputStream();

    // Encode the friendlyname oid.
    if (alias != null) {
        DerOutputStream bagAttr1 = new DerOutputStream();
        bagAttr1.putOID(PKCS9FriendlyName_OID);
        DerOutputStream bagAttrContent1 = new DerOutputStream();
        DerOutputStream bagAttrValue1 = new DerOutputStream();
        bagAttrContent1.putBMPString(alias);
        bagAttr1.write(DerValue.tag_Set, bagAttrContent1);
        bagAttrValue1.write(DerValue.tag_Sequence, bagAttr1);
        friendlyName = bagAttrValue1.toByteArray();
    }

    // Encode the localkeyId oid.
    if (keyId != null) {
        DerOutputStream bagAttr2 = new DerOutputStream();
        bagAttr2.putOID(PKCS9LocalKeyId_OID);
        DerOutputStream bagAttrContent2 = new DerOutputStream();
        DerOutputStream bagAttrValue2 = new DerOutputStream();
        bagAttrContent2.putOctetString(keyId);
        bagAttr2.write(DerValue.tag_Set, bagAttrContent2);
        bagAttrValue2.write(DerValue.tag_Sequence, bagAttr2);
        localKeyID = bagAttrValue2.toByteArray();
    }

    // Encode the trustedKeyUsage oid.
    if (trustedUsage != null) {
        DerOutputStream bagAttr3 = new DerOutputStream();
        bagAttr3.putOID(TrustedKeyUsage_OID);
        DerOutputStream bagAttrContent3 = new DerOutputStream();
        DerOutputStream bagAttrValue3 = new DerOutputStream();
        for (ObjectIdentifier usage : trustedUsage) {
            bagAttrContent3.putOID(usage);
        }
        bagAttr3.write(DerValue.tag_Set, bagAttrContent3);
        bagAttrValue3.write(DerValue.tag_Sequence, bagAttr3);
        trustedKeyUsage = bagAttrValue3.toByteArray();
    }

    DerOutputStream attrs = new DerOutputStream();
    if (friendlyName != null) {
        attrs.write(friendlyName);
    }
    if (localKeyID != null) {
        attrs.write(localKeyID);
    }
    if (trustedKeyUsage != null) {
        attrs.write(trustedKeyUsage);
    }

    if (attributes != null) {
        for (KeyStore.Entry.Attribute attribute : attributes) {
            String attributeName = attribute.getName();
            // skip friendlyName, localKeyId and trustedKeyUsage
            if (CORE_ATTRIBUTES[0].equals(attributeName) ||
                CORE_ATTRIBUTES[1].equals(attributeName) ||
                CORE_ATTRIBUTES[2].equals(attributeName)) {
                continue;
            }
            attrs.write(((PKCS12Attribute) attribute).getEncoded());
        }
    }

    bagAttrs.write(DerValue.tag_Set, attrs);
    return bagAttrs.toByteArray();
}
 
Example #25
Source File: PKCS12KeyStore.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private byte[] getBagAttributes(String alias, byte[] keyId,
    ObjectIdentifier[] trustedUsage,
    Set<KeyStore.Entry.Attribute> attributes) throws IOException {

    byte[] localKeyID = null;
    byte[] friendlyName = null;
    byte[] trustedKeyUsage = null;

    // return null if all three attributes are null
    if ((alias == null) && (keyId == null) && (trustedKeyUsage == null)) {
        return null;
    }

    // SafeBag Attributes
    DerOutputStream bagAttrs = new DerOutputStream();

    // Encode the friendlyname oid.
    if (alias != null) {
        DerOutputStream bagAttr1 = new DerOutputStream();
        bagAttr1.putOID(PKCS9FriendlyName_OID);
        DerOutputStream bagAttrContent1 = new DerOutputStream();
        DerOutputStream bagAttrValue1 = new DerOutputStream();
        bagAttrContent1.putBMPString(alias);
        bagAttr1.write(DerValue.tag_Set, bagAttrContent1);
        bagAttrValue1.write(DerValue.tag_Sequence, bagAttr1);
        friendlyName = bagAttrValue1.toByteArray();
    }

    // Encode the localkeyId oid.
    if (keyId != null) {
        DerOutputStream bagAttr2 = new DerOutputStream();
        bagAttr2.putOID(PKCS9LocalKeyId_OID);
        DerOutputStream bagAttrContent2 = new DerOutputStream();
        DerOutputStream bagAttrValue2 = new DerOutputStream();
        bagAttrContent2.putOctetString(keyId);
        bagAttr2.write(DerValue.tag_Set, bagAttrContent2);
        bagAttrValue2.write(DerValue.tag_Sequence, bagAttr2);
        localKeyID = bagAttrValue2.toByteArray();
    }

    // Encode the trustedKeyUsage oid.
    if (trustedUsage != null) {
        DerOutputStream bagAttr3 = new DerOutputStream();
        bagAttr3.putOID(TrustedKeyUsage_OID);
        DerOutputStream bagAttrContent3 = new DerOutputStream();
        DerOutputStream bagAttrValue3 = new DerOutputStream();
        for (ObjectIdentifier usage : trustedUsage) {
            bagAttrContent3.putOID(usage);
        }
        bagAttr3.write(DerValue.tag_Set, bagAttrContent3);
        bagAttrValue3.write(DerValue.tag_Sequence, bagAttr3);
        trustedKeyUsage = bagAttrValue3.toByteArray();
    }

    DerOutputStream attrs = new DerOutputStream();
    if (friendlyName != null) {
        attrs.write(friendlyName);
    }
    if (localKeyID != null) {
        attrs.write(localKeyID);
    }
    if (trustedKeyUsage != null) {
        attrs.write(trustedKeyUsage);
    }

    if (attributes != null) {
        for (KeyStore.Entry.Attribute attribute : attributes) {
            String attributeName = attribute.getName();
            // skip friendlyName, localKeyId and trustedKeyUsage
            if (CORE_ATTRIBUTES[0].equals(attributeName) ||
                CORE_ATTRIBUTES[1].equals(attributeName) ||
                CORE_ATTRIBUTES[2].equals(attributeName)) {
                continue;
            }
            attrs.write(((PKCS12Attribute) attribute).getEncoded());
        }
    }

    bagAttrs.write(DerValue.tag_Set, attrs);
    return bagAttrs.toByteArray();
}
 
Example #26
Source File: PKCS12KeyStore.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private byte[] getBagAttributes(String alias, byte[] keyId,
    ObjectIdentifier[] trustedUsage,
    Set<KeyStore.Entry.Attribute> attributes) throws IOException {

    byte[] localKeyID = null;
    byte[] friendlyName = null;
    byte[] trustedKeyUsage = null;

    // return null if all three attributes are null
    if ((alias == null) && (keyId == null) && (trustedKeyUsage == null)) {
        return null;
    }

    // SafeBag Attributes
    DerOutputStream bagAttrs = new DerOutputStream();

    // Encode the friendlyname oid.
    if (alias != null) {
        DerOutputStream bagAttr1 = new DerOutputStream();
        bagAttr1.putOID(PKCS9FriendlyName_OID);
        DerOutputStream bagAttrContent1 = new DerOutputStream();
        DerOutputStream bagAttrValue1 = new DerOutputStream();
        bagAttrContent1.putBMPString(alias);
        bagAttr1.write(DerValue.tag_Set, bagAttrContent1);
        bagAttrValue1.write(DerValue.tag_Sequence, bagAttr1);
        friendlyName = bagAttrValue1.toByteArray();
    }

    // Encode the localkeyId oid.
    if (keyId != null) {
        DerOutputStream bagAttr2 = new DerOutputStream();
        bagAttr2.putOID(PKCS9LocalKeyId_OID);
        DerOutputStream bagAttrContent2 = new DerOutputStream();
        DerOutputStream bagAttrValue2 = new DerOutputStream();
        bagAttrContent2.putOctetString(keyId);
        bagAttr2.write(DerValue.tag_Set, bagAttrContent2);
        bagAttrValue2.write(DerValue.tag_Sequence, bagAttr2);
        localKeyID = bagAttrValue2.toByteArray();
    }

    // Encode the trustedKeyUsage oid.
    if (trustedUsage != null) {
        DerOutputStream bagAttr3 = new DerOutputStream();
        bagAttr3.putOID(TrustedKeyUsage_OID);
        DerOutputStream bagAttrContent3 = new DerOutputStream();
        DerOutputStream bagAttrValue3 = new DerOutputStream();
        for (ObjectIdentifier usage : trustedUsage) {
            bagAttrContent3.putOID(usage);
        }
        bagAttr3.write(DerValue.tag_Set, bagAttrContent3);
        bagAttrValue3.write(DerValue.tag_Sequence, bagAttr3);
        trustedKeyUsage = bagAttrValue3.toByteArray();
    }

    DerOutputStream attrs = new DerOutputStream();
    if (friendlyName != null) {
        attrs.write(friendlyName);
    }
    if (localKeyID != null) {
        attrs.write(localKeyID);
    }
    if (trustedKeyUsage != null) {
        attrs.write(trustedKeyUsage);
    }

    if (attributes != null) {
        for (KeyStore.Entry.Attribute attribute : attributes) {
            String attributeName = attribute.getName();
            // skip friendlyName, localKeyId and trustedKeyUsage
            if (CORE_ATTRIBUTES[0].equals(attributeName) ||
                CORE_ATTRIBUTES[1].equals(attributeName) ||
                CORE_ATTRIBUTES[2].equals(attributeName)) {
                continue;
            }
            attrs.write(((PKCS12Attribute) attribute).getEncoded());
        }
    }

    bagAttrs.write(DerValue.tag_Set, attrs);
    return bagAttrs.toByteArray();
}
 
Example #27
Source File: PKCS12KeyStore.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private byte[] getBagAttributes(String alias, byte[] keyId,
    ObjectIdentifier[] trustedUsage,
    Set<KeyStore.Entry.Attribute> attributes) throws IOException {

    byte[] localKeyID = null;
    byte[] friendlyName = null;
    byte[] trustedKeyUsage = null;

    // return null if all three attributes are null
    if ((alias == null) && (keyId == null) && (trustedKeyUsage == null)) {
        return null;
    }

    // SafeBag Attributes
    DerOutputStream bagAttrs = new DerOutputStream();

    // Encode the friendlyname oid.
    if (alias != null) {
        DerOutputStream bagAttr1 = new DerOutputStream();
        bagAttr1.putOID(PKCS9FriendlyName_OID);
        DerOutputStream bagAttrContent1 = new DerOutputStream();
        DerOutputStream bagAttrValue1 = new DerOutputStream();
        bagAttrContent1.putBMPString(alias);
        bagAttr1.write(DerValue.tag_Set, bagAttrContent1);
        bagAttrValue1.write(DerValue.tag_Sequence, bagAttr1);
        friendlyName = bagAttrValue1.toByteArray();
    }

    // Encode the localkeyId oid.
    if (keyId != null) {
        DerOutputStream bagAttr2 = new DerOutputStream();
        bagAttr2.putOID(PKCS9LocalKeyId_OID);
        DerOutputStream bagAttrContent2 = new DerOutputStream();
        DerOutputStream bagAttrValue2 = new DerOutputStream();
        bagAttrContent2.putOctetString(keyId);
        bagAttr2.write(DerValue.tag_Set, bagAttrContent2);
        bagAttrValue2.write(DerValue.tag_Sequence, bagAttr2);
        localKeyID = bagAttrValue2.toByteArray();
    }

    // Encode the trustedKeyUsage oid.
    if (trustedUsage != null) {
        DerOutputStream bagAttr3 = new DerOutputStream();
        bagAttr3.putOID(TrustedKeyUsage_OID);
        DerOutputStream bagAttrContent3 = new DerOutputStream();
        DerOutputStream bagAttrValue3 = new DerOutputStream();
        for (ObjectIdentifier usage : trustedUsage) {
            bagAttrContent3.putOID(usage);
        }
        bagAttr3.write(DerValue.tag_Set, bagAttrContent3);
        bagAttrValue3.write(DerValue.tag_Sequence, bagAttr3);
        trustedKeyUsage = bagAttrValue3.toByteArray();
    }

    DerOutputStream attrs = new DerOutputStream();
    if (friendlyName != null) {
        attrs.write(friendlyName);
    }
    if (localKeyID != null) {
        attrs.write(localKeyID);
    }
    if (trustedKeyUsage != null) {
        attrs.write(trustedKeyUsage);
    }

    if (attributes != null) {
        for (KeyStore.Entry.Attribute attribute : attributes) {
            String attributeName = attribute.getName();
            // skip friendlyName, localKeyId and trustedKeyUsage
            if (CORE_ATTRIBUTES[0].equals(attributeName) ||
                CORE_ATTRIBUTES[1].equals(attributeName) ||
                CORE_ATTRIBUTES[2].equals(attributeName)) {
                continue;
            }
            attrs.write(((PKCS12Attribute) attribute).getEncoded());
        }
    }

    bagAttrs.write(DerValue.tag_Set, attrs);
    return bagAttrs.toByteArray();
}
 
Example #28
Source File: PKCS12KeyStore.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private byte[] getBagAttributes(String alias, byte[] keyId,
    ObjectIdentifier[] trustedUsage,
    Set<KeyStore.Entry.Attribute> attributes) throws IOException {

    byte[] localKeyID = null;
    byte[] friendlyName = null;
    byte[] trustedKeyUsage = null;

    // return null if all three attributes are null
    if ((alias == null) && (keyId == null) && (trustedKeyUsage == null)) {
        return null;
    }

    // SafeBag Attributes
    DerOutputStream bagAttrs = new DerOutputStream();

    // Encode the friendlyname oid.
    if (alias != null) {
        DerOutputStream bagAttr1 = new DerOutputStream();
        bagAttr1.putOID(PKCS9FriendlyName_OID);
        DerOutputStream bagAttrContent1 = new DerOutputStream();
        DerOutputStream bagAttrValue1 = new DerOutputStream();
        bagAttrContent1.putBMPString(alias);
        bagAttr1.write(DerValue.tag_Set, bagAttrContent1);
        bagAttrValue1.write(DerValue.tag_Sequence, bagAttr1);
        friendlyName = bagAttrValue1.toByteArray();
    }

    // Encode the localkeyId oid.
    if (keyId != null) {
        DerOutputStream bagAttr2 = new DerOutputStream();
        bagAttr2.putOID(PKCS9LocalKeyId_OID);
        DerOutputStream bagAttrContent2 = new DerOutputStream();
        DerOutputStream bagAttrValue2 = new DerOutputStream();
        bagAttrContent2.putOctetString(keyId);
        bagAttr2.write(DerValue.tag_Set, bagAttrContent2);
        bagAttrValue2.write(DerValue.tag_Sequence, bagAttr2);
        localKeyID = bagAttrValue2.toByteArray();
    }

    // Encode the trustedKeyUsage oid.
    if (trustedUsage != null) {
        DerOutputStream bagAttr3 = new DerOutputStream();
        bagAttr3.putOID(TrustedKeyUsage_OID);
        DerOutputStream bagAttrContent3 = new DerOutputStream();
        DerOutputStream bagAttrValue3 = new DerOutputStream();
        for (ObjectIdentifier usage : trustedUsage) {
            bagAttrContent3.putOID(usage);
        }
        bagAttr3.write(DerValue.tag_Set, bagAttrContent3);
        bagAttrValue3.write(DerValue.tag_Sequence, bagAttr3);
        trustedKeyUsage = bagAttrValue3.toByteArray();
    }

    DerOutputStream attrs = new DerOutputStream();
    if (friendlyName != null) {
        attrs.write(friendlyName);
    }
    if (localKeyID != null) {
        attrs.write(localKeyID);
    }
    if (trustedKeyUsage != null) {
        attrs.write(trustedKeyUsage);
    }

    if (attributes != null) {
        for (KeyStore.Entry.Attribute attribute : attributes) {
            String attributeName = attribute.getName();
            // skip friendlyName, localKeyId and trustedKeyUsage
            if (CORE_ATTRIBUTES[0].equals(attributeName) ||
                CORE_ATTRIBUTES[1].equals(attributeName) ||
                CORE_ATTRIBUTES[2].equals(attributeName)) {
                continue;
            }
            attrs.write(((PKCS12Attribute) attribute).getEncoded());
        }
    }

    bagAttrs.write(DerValue.tag_Set, attrs);
    return bagAttrs.toByteArray();
}
 
Example #29
Source File: PKCS12KeyStore.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private byte[] getBagAttributes(String alias, byte[] keyId,
    ObjectIdentifier[] trustedUsage,
    Set<KeyStore.Entry.Attribute> attributes) throws IOException {

    byte[] localKeyID = null;
    byte[] friendlyName = null;
    byte[] trustedKeyUsage = null;

    // return null if all three attributes are null
    if ((alias == null) && (keyId == null) && (trustedKeyUsage == null)) {
        return null;
    }

    // SafeBag Attributes
    DerOutputStream bagAttrs = new DerOutputStream();

    // Encode the friendlyname oid.
    if (alias != null) {
        DerOutputStream bagAttr1 = new DerOutputStream();
        bagAttr1.putOID(PKCS9FriendlyName_OID);
        DerOutputStream bagAttrContent1 = new DerOutputStream();
        DerOutputStream bagAttrValue1 = new DerOutputStream();
        bagAttrContent1.putBMPString(alias);
        bagAttr1.write(DerValue.tag_Set, bagAttrContent1);
        bagAttrValue1.write(DerValue.tag_Sequence, bagAttr1);
        friendlyName = bagAttrValue1.toByteArray();
    }

    // Encode the localkeyId oid.
    if (keyId != null) {
        DerOutputStream bagAttr2 = new DerOutputStream();
        bagAttr2.putOID(PKCS9LocalKeyId_OID);
        DerOutputStream bagAttrContent2 = new DerOutputStream();
        DerOutputStream bagAttrValue2 = new DerOutputStream();
        bagAttrContent2.putOctetString(keyId);
        bagAttr2.write(DerValue.tag_Set, bagAttrContent2);
        bagAttrValue2.write(DerValue.tag_Sequence, bagAttr2);
        localKeyID = bagAttrValue2.toByteArray();
    }

    // Encode the trustedKeyUsage oid.
    if (trustedUsage != null) {
        DerOutputStream bagAttr3 = new DerOutputStream();
        bagAttr3.putOID(TrustedKeyUsage_OID);
        DerOutputStream bagAttrContent3 = new DerOutputStream();
        DerOutputStream bagAttrValue3 = new DerOutputStream();
        for (ObjectIdentifier usage : trustedUsage) {
            bagAttrContent3.putOID(usage);
        }
        bagAttr3.write(DerValue.tag_Set, bagAttrContent3);
        bagAttrValue3.write(DerValue.tag_Sequence, bagAttr3);
        trustedKeyUsage = bagAttrValue3.toByteArray();
    }

    DerOutputStream attrs = new DerOutputStream();
    if (friendlyName != null) {
        attrs.write(friendlyName);
    }
    if (localKeyID != null) {
        attrs.write(localKeyID);
    }
    if (trustedKeyUsage != null) {
        attrs.write(trustedKeyUsage);
    }

    if (attributes != null) {
        for (KeyStore.Entry.Attribute attribute : attributes) {
            String attributeName = attribute.getName();
            // skip friendlyName, localKeyId and trustedKeyUsage
            if (CORE_ATTRIBUTES[0].equals(attributeName) ||
                CORE_ATTRIBUTES[1].equals(attributeName) ||
                CORE_ATTRIBUTES[2].equals(attributeName)) {
                continue;
            }
            attrs.write(((PKCS12Attribute) attribute).getEncoded());
        }
    }

    bagAttrs.write(DerValue.tag_Set, attrs);
    return bagAttrs.toByteArray();
}
 
Example #30
Source File: PKCS12KeyStore.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private byte[] getBagAttributes(String alias, byte[] keyId,
    ObjectIdentifier[] trustedUsage,
    Set<KeyStore.Entry.Attribute> attributes) throws IOException {

    byte[] localKeyID = null;
    byte[] friendlyName = null;
    byte[] trustedKeyUsage = null;

    // return null if all three attributes are null
    if ((alias == null) && (keyId == null) && (trustedKeyUsage == null)) {
        return null;
    }

    // SafeBag Attributes
    DerOutputStream bagAttrs = new DerOutputStream();

    // Encode the friendlyname oid.
    if (alias != null) {
        DerOutputStream bagAttr1 = new DerOutputStream();
        bagAttr1.putOID(PKCS9FriendlyName_OID);
        DerOutputStream bagAttrContent1 = new DerOutputStream();
        DerOutputStream bagAttrValue1 = new DerOutputStream();
        bagAttrContent1.putBMPString(alias);
        bagAttr1.write(DerValue.tag_Set, bagAttrContent1);
        bagAttrValue1.write(DerValue.tag_Sequence, bagAttr1);
        friendlyName = bagAttrValue1.toByteArray();
    }

    // Encode the localkeyId oid.
    if (keyId != null) {
        DerOutputStream bagAttr2 = new DerOutputStream();
        bagAttr2.putOID(PKCS9LocalKeyId_OID);
        DerOutputStream bagAttrContent2 = new DerOutputStream();
        DerOutputStream bagAttrValue2 = new DerOutputStream();
        bagAttrContent2.putOctetString(keyId);
        bagAttr2.write(DerValue.tag_Set, bagAttrContent2);
        bagAttrValue2.write(DerValue.tag_Sequence, bagAttr2);
        localKeyID = bagAttrValue2.toByteArray();
    }

    // Encode the trustedKeyUsage oid.
    if (trustedUsage != null) {
        DerOutputStream bagAttr3 = new DerOutputStream();
        bagAttr3.putOID(TrustedKeyUsage_OID);
        DerOutputStream bagAttrContent3 = new DerOutputStream();
        DerOutputStream bagAttrValue3 = new DerOutputStream();
        for (ObjectIdentifier usage : trustedUsage) {
            bagAttrContent3.putOID(usage);
        }
        bagAttr3.write(DerValue.tag_Set, bagAttrContent3);
        bagAttrValue3.write(DerValue.tag_Sequence, bagAttr3);
        trustedKeyUsage = bagAttrValue3.toByteArray();
    }

    DerOutputStream attrs = new DerOutputStream();
    if (friendlyName != null) {
        attrs.write(friendlyName);
    }
    if (localKeyID != null) {
        attrs.write(localKeyID);
    }
    if (trustedKeyUsage != null) {
        attrs.write(trustedKeyUsage);
    }

    if (attributes != null) {
        for (KeyStore.Entry.Attribute attribute : attributes) {
            String attributeName = attribute.getName();
            // skip friendlyName, localKeyId and trustedKeyUsage
            if (CORE_ATTRIBUTES[0].equals(attributeName) ||
                CORE_ATTRIBUTES[1].equals(attributeName) ||
                CORE_ATTRIBUTES[2].equals(attributeName)) {
                continue;
            }
            attrs.write(((PKCS12Attribute) attribute).getEncoded());
        }
    }

    bagAttrs.write(DerValue.tag_Set, attrs);
    return bagAttrs.toByteArray();
}