如何使用JSS向Firefox添加受信任的证书颁发机构



我想使用JSS和Windows向Mozilla Firefox证书存储库添加一个受信任的证书颁发机构。有人知道怎么做吗?

下面是如何使用JSS 4.3.1完成的!

你会发现你的windows firefox配置文件目录在%APPDATA%/Mozilla/firefox/Profiles。

确保将所有需要的本地库放在一个唯一的目录中,并在java.library中引用该目录。路径,例如:

-Djava.library.path = " C: 开发 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;
    }

相关内容

  • 没有找到相关文章

最新更新