Java 如何使用JSS向Firefox添加受信任的证书Autority

Java 如何使用JSS向Firefox添加受信任的证书Autority,java,firefox,ssl,certificate,nss,Java,Firefox,Ssl,Certificate,Nss,我想使用JSS和Windows向您的Mozilla Firefox证书存储库添加一个受信任的证书autority。 有人知道如何做到这一点吗?以下是如何使用JSS 4.3.1做到这一点 您将在%APPDATA%/Mozilla/firefox/Profiles上找到您的windows firefox配置文件目录 确保将所有需要的本机lib放在一个唯一的目录中,并在java.library.path中引用该目录,例如: -Djava.library.path=“C:\dev\firefox\jss

我想使用JSS和Windows向您的Mozilla Firefox证书存储库添加一个受信任的证书autority。
有人知道如何做到这一点吗?

以下是如何使用JSS 4.3.1做到这一点

您将在%APPDATA%/Mozilla/firefox/Profiles上找到您的windows firefox配置文件目录

确保将所有需要的本机lib放在一个唯一的目录中,并在java.library.path中引用该目录,例如:

-Djava.library.path=“C:\dev\firefox\jss native” 以下是示例代码:

File firefoxProfilesDir = new File(appData + "/Mozilla/Firefox/Profiles");

    boolean firefoxInstalled = firefoxProfilesDir.exists() && firefoxProfilesDir.isDirectory();
    if (!firefoxInstalled) {
        LOG.info("Firefox profiles not found, abort");
        return;
    }

    LOG.info("Firefox profiles found");

    LOG.info("Browsing for firefox profile");

    File[] profilesDir = firefoxProfilesDir.listFiles();
    for (File profileDir : profilesDir) {
        if (!profileDir.isDirectory()) {
            continue;
        }

        LOG.info("Found firefox profile {}", profileDir.getName());

        // Autority
        CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
        Certificate rootCertificate = certificateFactory.generateCertificate(Dispatcher.class
                .getResourceAsStream("/certificates/myautoritycert.cer"));

        // Load native libs
        System.loadLibrary("nspr4");
        System.loadLibrary("plc4");
        System.loadLibrary("plds4");
        System.loadLibrary("nssutil3");
        System.loadLibrary("nss3");
        System.loadLibrary("smime3");
        System.loadLibrary("freebl3");
        System.loadLibrary("nssckbi");
        System.loadLibrary("nssdbm3");
        System.loadLibrary("sqlite3");
        System.loadLibrary("ssl3");

        // Initialize mozilla crypto
        CryptoManager.initialize(profileDir.getAbsolutePath());
        CryptoManager manager = CryptoManager.getInstance();
        CryptoToken token = manager.getInternalKeyStorageToken();
        manager.setThreadToken(token);

        // Autority
        X509Certificate cert = manager.importCACertPackage(rootCertificate.getEncoded());
        InternalCertificate certInternal = manager.importCertToPerm(cert , "somealias");
        certInternal.setSSLTrust(InternalCertificate.TRUSTED_CA);

        LOG.info("Certificate {} loaded into firefox profile {}", "somealias", profileDir.getName());

        break;
    }

我希望这将是有益的:)虽然可以回答你自己的问题,所以它仍然需要在问答的格式。请将此问题分成一个独立的问题(包括相关内容)和一个答案。这似乎是离题的,因为它不是一个问题。看起来海报将Stack Overflow用作他/她自己的个人博客。我将其拆分为问答格式。问题是我在解决自己的问题时遇到了很多麻烦,所以我想与其他人分享。如果我违反了任何规则,我很抱歉,这是我在stackoverflow上的第一篇帖子。