sun.security.util.Debug Java Examples

The following examples show how to use sun.security.util.Debug. 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: DSA.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a human readable rendition of the engine.
 */
public String toString() {
    String printable = "DSA Signature";
    if (presetP != null && presetQ != null && presetG != null) {
        printable += "\n\tp: " + Debug.toHexString(presetP);
        printable += "\n\tq: " + Debug.toHexString(presetQ);
        printable += "\n\tg: " + Debug.toHexString(presetG);
    } else {
        printable += "\n\t P, Q or G not initialized.";
    }
    if (presetY != null) {
        printable += "\n\ty: " + Debug.toHexString(presetY);
    }
    if (presetY == null && presetX == null) {
        printable += "\n\tUNINIIALIZED";
    }
    return printable;
}
 
Example #2
Source File: MultiOptions.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {

        if (!Debug.isOn("access") ||
                !Debug.isOn("stack") ||
                !Debug.isOn("logincontext") ||
                !Debug.isOn("domain") ||
                !Debug.isOn("combiner") ||
                !Debug.isOn("failure") ||
                !Debug.isOn("jar") ||
                !Debug.isOn("permission=sun.dummy.DummyPermission") ||
                Debug.isOn("permission=sun.dummy.dummypermission") ||
                !Debug.isOn("permission=sun.Dummy.DummyPermission2") ||
                !Debug.isOn("permission=sun.dummy.DummyPermission3") ||
                !Debug.isOn("codebase=/dir1/DIR2/Dir3/File.java") ||
                Debug.isOn("codebase=/dir1/dir2/dir3/file.java") ||
                !Debug.isOn("codebase=www.sun.com") ||
                !Debug.isOn("codebase=file:///C:/temp/foo%20more/a.txt") ||
                !Debug.isOn("codebase=http://www.sun.com/search?q=SunMicro") ) {
            throw new Exception("sun.security.Debug failed to parse options");
        }
    }
 
Example #3
Source File: DSA.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a human readable rendition of the engine.
 */
public String toString() {
    String printable = "DSA Signature";
    if (presetP != null && presetQ != null && presetG != null) {
        printable += "\n\tp: " + Debug.toHexString(presetP);
        printable += "\n\tq: " + Debug.toHexString(presetQ);
        printable += "\n\tg: " + Debug.toHexString(presetG);
    } else {
        printable += "\n\t P, Q or G not initialized.";
    }
    if (presetY != null) {
        printable += "\n\ty: " + Debug.toHexString(presetY);
    }
    if (presetY == null && presetX == null) {
        printable += "\n\tUNINIIALIZED";
    }
    return printable;
}
 
Example #4
Source File: MultiOptions.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {

        if (!Debug.isOn("access") ||
                !Debug.isOn("stack") ||
                !Debug.isOn("logincontext") ||
                !Debug.isOn("domain") ||
                !Debug.isOn("combiner") ||
                !Debug.isOn("failure") ||
                !Debug.isOn("jar") ||
                !Debug.isOn("permission=sun.dummy.DummyPermission") ||
                Debug.isOn("permission=sun.dummy.dummypermission") ||
                !Debug.isOn("permission=sun.Dummy.DummyPermission2") ||
                !Debug.isOn("permission=sun.dummy.DummyPermission3") ||
                !Debug.isOn("codebase=/dir1/DIR2/Dir3/File.java") ||
                Debug.isOn("codebase=/dir1/dir2/dir3/file.java") ||
                !Debug.isOn("codebase=www.sun.com") ||
                !Debug.isOn("codebase=file:///C:/temp/foo%20more/a.txt") ||
                !Debug.isOn("codebase=http://www.sun.com/search?q=SunMicro") ) {
            throw new Exception("sun.security.Debug failed to parse options");
        }
    }
 
Example #5
Source File: SignerInfo.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public String toString() {
    HexDumpEncoder hexDump = new HexDumpEncoder();

    String out = "";

    out += "Signer Info for (issuer): " + issuerName + "\n";
    out += "\tversion: " + Debug.toHexString(version) + "\n";
    out += "\tcertificateSerialNumber: " +
           Debug.toHexString(certificateSerialNumber) + "\n";
    out += "\tdigestAlgorithmId: " + digestAlgorithmId + "\n";
    if (authenticatedAttributes != null) {
        out += "\tauthenticatedAttributes: " + authenticatedAttributes +
               "\n";
    }
    out += "\tdigestEncryptionAlgorithmId: " + digestEncryptionAlgorithmId +
        "\n";

    out += "\tencryptedDigest: " + "\n" +
        hexDump.encodeBuffer(encryptedDigest) + "\n";
    if (unauthenticatedAttributes != null) {
        out += "\tunauthenticatedAttributes: " +
               unauthenticatedAttributes + "\n";
    }
    return out;
}
 
Example #6
Source File: DSA.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a human readable rendition of the engine.
 */
public String toString() {
    String printable = "DSA Signature";
    if (presetP != null && presetQ != null && presetG != null) {
        printable += "\n\tp: " + Debug.toHexString(presetP);
        printable += "\n\tq: " + Debug.toHexString(presetQ);
        printable += "\n\tg: " + Debug.toHexString(presetG);
    } else {
        printable += "\n\t P, Q or G not initialized.";
    }
    if (presetY != null) {
        printable += "\n\ty: " + Debug.toHexString(presetY);
    }
    if (presetY == null && presetX == null) {
        printable += "\n\tUNINIIALIZED";
    }
    return printable;
}
 
Example #7
Source File: DSA.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a human readable rendition of the engine.
 */
public String toString() {
    String printable = "DSA Signature";
    if (presetP != null && presetQ != null && presetG != null) {
        printable += "\n\tp: " + Debug.toHexString(presetP);
        printable += "\n\tq: " + Debug.toHexString(presetQ);
        printable += "\n\tg: " + Debug.toHexString(presetG);
    } else {
        printable += "\n\t P, Q or G not initialized.";
    }
    if (presetY != null) {
        printable += "\n\ty: " + Debug.toHexString(presetY);
    }
    if (presetY == null && presetX == null) {
        printable += "\n\tUNINIIALIZED";
    }
    return printable;
}
 
Example #8
Source File: DSA.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a human readable rendition of the engine.
 */
public String toString() {
    String printable = "DSA Signature";
    if (presetP != null && presetQ != null && presetG != null) {
        printable += "\n\tp: " + Debug.toHexString(presetP);
        printable += "\n\tq: " + Debug.toHexString(presetQ);
        printable += "\n\tg: " + Debug.toHexString(presetG);
    } else {
        printable += "\n\t P, Q or G not initialized.";
    }
    if (presetY != null) {
        printable += "\n\ty: " + Debug.toHexString(presetY);
    }
    if (presetY == null && presetX == null) {
        printable += "\n\tUNINIIALIZED";
    }
    return printable;
}
 
Example #9
Source File: SignerInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public String toString() {
    HexDumpEncoder hexDump = new HexDumpEncoder();

    String out = "";

    out += "Signer Info for (issuer): " + issuerName + "\n";
    out += "\tversion: " + Debug.toHexString(version) + "\n";
    out += "\tcertificateSerialNumber: " +
           Debug.toHexString(certificateSerialNumber) + "\n";
    out += "\tdigestAlgorithmId: " + digestAlgorithmId + "\n";
    if (authenticatedAttributes != null) {
        out += "\tauthenticatedAttributes: " + authenticatedAttributes +
               "\n";
    }
    out += "\tdigestEncryptionAlgorithmId: " + digestEncryptionAlgorithmId +
        "\n";

    out += "\tencryptedDigest: " + "\n" +
        hexDump.encodeBuffer(encryptedDigest) + "\n";
    if (unauthenticatedAttributes != null) {
        out += "\tunauthenticatedAttributes: " +
               unauthenticatedAttributes + "\n";
    }
    return out;
}
 
Example #10
Source File: MultiOptions.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {

        if (!Debug.isOn("access") ||
                !Debug.isOn("stack") ||
                !Debug.isOn("logincontext") ||
                !Debug.isOn("domain") ||
                !Debug.isOn("combiner") ||
                !Debug.isOn("failure") ||
                !Debug.isOn("jar") ||
                !Debug.isOn("permission=sun.dummy.DummyPermission") ||
                Debug.isOn("permission=sun.dummy.dummypermission") ||
                !Debug.isOn("permission=sun.Dummy.DummyPermission2") ||
                !Debug.isOn("permission=sun.dummy.DummyPermission3") ||
                !Debug.isOn("codebase=/dir1/DIR2/Dir3/File.java") ||
                Debug.isOn("codebase=/dir1/dir2/dir3/file.java") ||
                !Debug.isOn("codebase=www.sun.com") ||
                !Debug.isOn("codebase=file:///C:/temp/foo%20more/a.txt") ||
                !Debug.isOn("codebase=http://www.sun.com/search?q=SunMicro") ) {
            throw new Exception("sun.security.Debug failed to parse options");
        }
    }
 
Example #11
Source File: SignerInfo.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public String toString() {
    HexDumpEncoder hexDump = new HexDumpEncoder();

    String out = "";

    out += "Signer Info for (issuer): " + issuerName + "\n";
    out += "\tversion: " + Debug.toHexString(version) + "\n";
    out += "\tcertificateSerialNumber: " +
           Debug.toHexString(certificateSerialNumber) + "\n";
    out += "\tdigestAlgorithmId: " + digestAlgorithmId + "\n";
    if (authenticatedAttributes != null) {
        out += "\tauthenticatedAttributes: " + authenticatedAttributes +
               "\n";
    }
    out += "\tdigestEncryptionAlgorithmId: " + digestEncryptionAlgorithmId +
        "\n";

    out += "\tencryptedDigest: " + "\n" +
        hexDump.encodeBuffer(encryptedDigest) + "\n";
    if (unauthenticatedAttributes != null) {
        out += "\tunauthenticatedAttributes: " +
               unauthenticatedAttributes + "\n";
    }
    return out;
}
 
Example #12
Source File: CryptoUtil.java    From julongchain with Apache License 2.0 6 votes vote down vote up
/**
 * 读取私钥文件
 * @param skPath
 * @return
 * @throws CspException
 * @throws IOException
 */
public static byte[] readSkFile(String skPath) throws CspException, IOException {
    InputStreamReader reader = new InputStreamReader(new FileInputStream(skPath));
    PemReader pemReader = new PemReader(reader);
    PemObject pemObject = pemReader.readPemObject();
    reader.close();
    byte[] encodedData = pemObject.getContent();
    DerValue derValue = new DerValue(new ByteArrayInputStream(encodedData));
    byte[] rawPrivateKey = null;
    if (derValue.tag != 48) {
        throw new CspException("invalid key format");
    } else {
        BigInteger version = derValue.data.getBigInteger();
        if (!version.equals(BigInteger.ZERO)) {
            throw new CspException("version mismatch: (supported: " + Debug.toHexString(BigInteger.ZERO) + ", parsed: " + Debug.toHexString(version));
        } else {
            AlgorithmId algId = AlgorithmId.parse(derValue.data.getDerValue());
            rawPrivateKey = derValue.data.getOctetString();
        }
        return rawPrivateKey;
    }
}
 
Example #13
Source File: SignerInfo.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public String toString() {
    HexDumpEncoder hexDump = new HexDumpEncoder();

    String out = "";

    out += "Signer Info for (issuer): " + issuerName + "\n";
    out += "\tversion: " + Debug.toHexString(version) + "\n";
    out += "\tcertificateSerialNumber: " +
           Debug.toHexString(certificateSerialNumber) + "\n";
    out += "\tdigestAlgorithmId: " + digestAlgorithmId + "\n";
    if (authenticatedAttributes != null) {
        out += "\tauthenticatedAttributes: " + authenticatedAttributes +
               "\n";
    }
    out += "\tdigestEncryptionAlgorithmId: " + digestEncryptionAlgorithmId +
        "\n";

    out += "\tencryptedDigest: " + "\n" +
        hexDump.encodeBuffer(encryptedDigest) + "\n";
    if (unauthenticatedAttributes != null) {
        out += "\tunauthenticatedAttributes: " +
               unauthenticatedAttributes + "\n";
    }
    return out;
}
 
Example #14
Source File: MultiOptions.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {

        if (!Debug.isOn("access") ||
                !Debug.isOn("stack") ||
                !Debug.isOn("logincontext") ||
                !Debug.isOn("domain") ||
                !Debug.isOn("combiner") ||
                !Debug.isOn("failure") ||
                !Debug.isOn("jar") ||
                !Debug.isOn("permission=sun.dummy.DummyPermission") ||
                Debug.isOn("permission=sun.dummy.dummypermission") ||
                !Debug.isOn("permission=sun.Dummy.DummyPermission2") ||
                !Debug.isOn("permission=sun.dummy.DummyPermission3") ||
                !Debug.isOn("codebase=/dir1/DIR2/Dir3/File.java") ||
                Debug.isOn("codebase=/dir1/dir2/dir3/file.java") ||
                !Debug.isOn("codebase=www.sun.com") ||
                !Debug.isOn("codebase=file:///C:/temp/foo%20more/a.txt") ||
                !Debug.isOn("codebase=http://www.sun.com/search?q=SunMicro") ) {
            throw new Exception("sun.security.Debug failed to parse options");
        }
    }
 
Example #15
Source File: SocketPermission.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static synchronized Debug getDebug() {
    if (!debugInit) {
        debug = Debug.getInstance("access");
        debugInit = true;
    }
    return debug;
}
 
Example #16
Source File: AdaptableX509CertSelector.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private boolean matchSubjectKeyID(X509Certificate xcert) {
    if (ski == null) {
        return true;
    }
    try {
        byte[] extVal = xcert.getExtensionValue("2.5.29.14");
        if (extVal == null) {
            if (debug != null && Debug.isVerbose()) {
                debug.println("AdaptableX509CertSelector.match: "
                    + "no subject key ID extension. Subject: "
                    + xcert.getSubjectX500Principal());
            }
            return true;
        }
        DerInputStream in = new DerInputStream(extVal);
        byte[] certSubjectKeyID = in.getOctetString();
        if (certSubjectKeyID == null ||
                !Arrays.equals(ski, certSubjectKeyID)) {
            if (debug != null && Debug.isVerbose()) {
                debug.println("AdaptableX509CertSelector.match: "
                    + "subject key IDs don't match. "
                    + "Expected: " + Arrays.toString(ski) + " "
                    + "Cert's: " + Arrays.toString(certSubjectKeyID));
            }
            return false;
        }
    } catch (IOException ex) {
        if (debug != null && Debug.isVerbose()) {
            debug.println("AdaptableX509CertSelector.match: "
                + "exception in subject key ID check");
        }
        return false;
    }
    return true;
}
 
Example #17
Source File: AccessControlContext.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
static Debug getDebug()
{
    if (debugInit)
        return debug;
    else {
        if (Policy.isSet()) {
            debug = Debug.getInstance("access");
            debugInit = true;
        }
        return debug;
    }
}
 
Example #18
Source File: SocketPermission.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private boolean isUntrusted()
    throws UnknownHostException
{
    if (trusted) return false;
    if (invalid || untrusted) return true;
    try {
        if (!trustNameService && (defaultDeny ||
            sun.net.www.URLConnection.isProxiedHost(hostname))) {
            if (this.cname == null) {
                this.getCanonName();
            }
            if (!match(cname, hostname)) {
                // Last chance
                if (!authorized(hostname, addresses[0].getAddress())) {
                    untrusted = true;
                    Debug debug = getDebug();
                    if (debug != null && Debug.isOn("failure")) {
                        debug.println("socket access restriction: proxied host " + "(" + addresses[0] + ")" + " does not match " + cname + " from reverse lookup");
                    }
                    return true;
                }
            }
            trusted = true;
        }
    } catch (UnknownHostException uhe) {
        invalid = true;
        throw uhe;
    }
    return false;
}
 
Example #19
Source File: SocketPermission.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private boolean isUntrusted()
    throws UnknownHostException
{
    if (trusted) return false;
    if (invalid || untrusted) return true;
    try {
        if (!trustNameService && (defaultDeny ||
            sun.net.www.URLConnection.isProxiedHost(hostname))) {
            if (this.cname == null) {
                this.getCanonName();
            }
            if (!match(cname, hostname)) {
                // Last chance
                if (!authorized(hostname, addresses[0].getAddress())) {
                    untrusted = true;
                    Debug debug = getDebug();
                    if (debug != null && Debug.isOn("failure")) {
                        debug.println("socket access restriction: proxied host " + "(" + addresses[0] + ")" + " does not match " + cname + " from reverse lookup");
                    }
                    return true;
                }
            }
            trusted = true;
        }
    } catch (UnknownHostException uhe) {
        invalid = true;
        throw uhe;
    }
    return false;
}
 
Example #20
Source File: SocketPermission.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private boolean isUntrusted()
    throws UnknownHostException
{
    if (trusted) return false;
    if (invalid || untrusted) return true;
    try {
        if (!trustNameService && (defaultDeny ||
            sun.net.www.URLConnection.isProxiedHost(hostname))) {
            if (this.cname == null) {
                this.getCanonName();
            }
            if (!match(cname, hostname)) {
                // Last chance
                if (!authorized(hostname, addresses[0].getAddress())) {
                    untrusted = true;
                    Debug debug = getDebug();
                    if (debug != null && Debug.isOn("failure")) {
                        debug.println("socket access restriction: proxied host " + "(" + addresses[0] + ")" + " does not match " + cname + " from reverse lookup");
                    }
                    return true;
                }
            }
            trusted = true;
        }
    } catch (UnknownHostException uhe) {
        invalid = true;
        throw uhe;
    }
    return false;
}
 
Example #21
Source File: SocketPermission.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private static synchronized Debug getDebug() {
    if (!debugInit) {
        debug = Debug.getInstance("access");
        debugInit = true;
    }
    return debug;
}
 
Example #22
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 #23
Source File: AccessController.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Determines whether the access request indicated by the
 * specified permission should be allowed or denied, based on
 * the current AccessControlContext and security policy.
 * This method quietly returns if the access request
 * is permitted, or throws an AccessControlException otherwise. The
 * getPermission method of the AccessControlException returns the
 * {@code perm} Permission object instance.
 *
 * @param perm the requested permission.
 *
 * @exception AccessControlException if the specified permission
 *            is not permitted, based on the current security policy.
 * @exception NullPointerException if the specified permission
 *            is {@code null} and is checked based on the
 *            security policy currently in effect.
 */

public static void checkPermission(Permission perm)
    throws AccessControlException
{
    //System.err.println("checkPermission "+perm);
    //Thread.currentThread().dumpStack();

    if (perm == null) {
        throw new NullPointerException("permission can't be null");
    }

    AccessControlContext stack = getStackAccessControlContext();
    // if context is null, we had privileged system code on the stack.
    if (stack == null) {
        Debug debug = AccessControlContext.getDebug();
        boolean dumpDebug = false;
        if (debug != null) {
            dumpDebug = !Debug.isOn("codebase=");
            dumpDebug &= !Debug.isOn("permission=") ||
                Debug.isOn("permission=" + perm.getClass().getCanonicalName());
        }

        if (dumpDebug && Debug.isOn("stack")) {
            Thread.dumpStack();
        }

        if (dumpDebug && Debug.isOn("domain")) {
            debug.println("domain (context is null)");
        }

        if (dumpDebug) {
            debug.println("access allowed "+perm);
        }
        return;
    }

    AccessControlContext acc = stack.optimize();
    acc.checkPermission(perm);
}
 
Example #24
Source File: AccessControlContext.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
static Debug getDebug()
{
    if (debugInit)
        return debug;
    else {
        if (Policy.isSet()) {
            debug = Debug.getInstance("access");
            debugInit = true;
        }
        return debug;
    }
}
 
Example #25
Source File: Policy.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if a custom (not AUTH_POLICY) system-wide policy object
 * has been set or installed. This method is called by
 * SubjectDomainCombiner to provide backwards compatibility for
 * developers that provide their own javax.security.auth.Policy
 * implementations.
 *
 * @return true if a custom (not AUTH_POLICY) system-wide policy object
 * has been set; false otherwise
 */
static boolean isCustomPolicySet(Debug debug) {
    if (policy != null) {
        if (debug != null && isCustomPolicy) {
            debug.println("Providing backwards compatibility for " +
                          "javax.security.auth.policy implementation: " +
                          policy.toString());
        }
        return isCustomPolicy;
    }
    // check if custom policy has been set using auth.policy.provider prop
    String policyClass = java.security.AccessController.doPrivileged
        (new java.security.PrivilegedAction<String>() {
            public String run() {
                return Security.getProperty("auth.policy.provider");
            }
    });
    if (policyClass != null && !policyClass.equals(AUTH_POLICY)) {
        if (debug != null) {
            debug.println("Providing backwards compatibility for " +
                          "javax.security.auth.policy implementation: " +
                          policyClass);
        }
        return true;
    }
    return false;
}
 
Example #26
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 #27
Source File: Policy.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if a custom (not AUTH_POLICY) system-wide policy object
 * has been set or installed. This method is called by
 * SubjectDomainCombiner to provide backwards compatibility for
 * developers that provide their own javax.security.auth.Policy
 * implementations.
 *
 * @return true if a custom (not AUTH_POLICY) system-wide policy object
 * has been set; false otherwise
 */
static boolean isCustomPolicySet(Debug debug) {
    if (policy != null) {
        if (debug != null && isCustomPolicy) {
            debug.println("Providing backwards compatibility for " +
                          "javax.security.auth.policy implementation: " +
                          policy.toString());
        }
        return isCustomPolicy;
    }
    // check if custom policy has been set using auth.policy.provider prop
    String policyClass = java.security.AccessController.doPrivileged
        (new java.security.PrivilegedAction<String>() {
            public String run() {
                return Security.getProperty("auth.policy.provider");
            }
    });
    if (policyClass != null && !policyClass.equals(AUTH_POLICY)) {
        if (debug != null) {
            debug.println("Providing backwards compatibility for " +
                          "javax.security.auth.policy implementation: " +
                          policyClass);
        }
        return true;
    }
    return false;
}
 
Example #28
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 #29
Source File: OCSPNonceExtension.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a printable representation of the {@code OCSPNonceExtension}.
 *
 * @return a string representation of the extension.
 */
@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append(super.toString()).append(EXTENSION_NAME).append(": ");
    sb.append((nonceData == null) ? "" : Debug.toString(nonceData));
    sb.append("\n");
    return sb.toString();
}
 
Example #30
Source File: Policy.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Returns true if a custom (not AUTH_POLICY) system-wide policy object
 * has been set or installed. This method is called by
 * SubjectDomainCombiner to provide backwards compatibility for
 * developers that provide their own javax.security.auth.Policy
 * implementations.
 *
 * @return true if a custom (not AUTH_POLICY) system-wide policy object
 * has been set; false otherwise
 */
static boolean isCustomPolicySet(Debug debug) {
    if (policy != null) {
        if (debug != null && isCustomPolicy) {
            debug.println("Providing backwards compatibility for " +
                          "javax.security.auth.policy implementation: " +
                          policy.toString());
        }
        return isCustomPolicy;
    }
    // check if custom policy has been set using auth.policy.provider prop
    String policyClass = java.security.AccessController.doPrivileged
        (new java.security.PrivilegedAction<String>() {
            public String run() {
                return Security.getProperty("auth.policy.provider");
            }
    });
    if (policyClass != null && !policyClass.equals(AUTH_POLICY)) {
        if (debug != null) {
            debug.println("Providing backwards compatibility for " +
                          "javax.security.auth.policy implementation: " +
                          policyClass);
        }
        return true;
    }
    return false;
}