Skip to content

Commit

Permalink
Replace InternalCertificate with PK11Cert
Browse files Browse the repository at this point in the history
  • Loading branch information
edewata committed Jul 26, 2024
1 parent 94b00c5 commit 1904b72
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import java.util.Enumeration;

import org.mozilla.jss.crypto.InternalCertificate;
import org.mozilla.jss.CryptoManager;
import org.mozilla.jss.pkcs11.PK11Cert;

/**
Expand Down Expand Up @@ -59,8 +59,8 @@ public boolean approve(
if (trust_the_server_cert) {
System.out.println("importing certificate.");
try {
InternalCertificate newcert = org.mozilla.jss.CryptoManager.getInstance().importCertToPerm(servercert,
"testnick");
CryptoManager cm = CryptoManager.getInstance();
PK11Cert newcert = (PK11Cert) cm.importCertToPerm(servercert, "testnick");
newcert.setSSLTrust(PK11Cert.TRUSTED_PEER | PK11Cert.VALID_PEER);
} catch (Exception e) {
System.out.println("thrown exception: " + e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.mozilla.jss.asn1.OCTET_STRING;
import org.mozilla.jss.asn1.SEQUENCE;
import org.mozilla.jss.crypto.CryptoToken;
import org.mozilla.jss.crypto.InternalCertificate;
import org.mozilla.jss.crypto.SignatureAlgorithm;
import org.mozilla.jss.crypto.X509Certificate;
import org.mozilla.jss.pkcs11.PK11Cert;
Expand Down Expand Up @@ -205,7 +204,7 @@ private void doIt(String[] args) throws Exception {
caPair.getPrivate(), caPair.getPublic(), serialNum, extensions);
X509Certificate nssCaCert = cm.importUserCACertPackage(
ASN1Util.encode(caCert), caCertNick);
InternalCertificate intern = (InternalCertificate)nssCaCert;
PK11Cert intern = (PK11Cert) nssCaCert;
intern.setSSLTrust(
PK11Cert.TRUSTED_CA |
PK11Cert.TRUSTED_CLIENT_CA |
Expand Down
9 changes: 5 additions & 4 deletions base/src/test/java/org/mozilla/jss/tests/ListCACerts.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.mozilla.jss.tests;

import org.mozilla.jss.CryptoManager;
import org.mozilla.jss.crypto.*;
import org.mozilla.jss.crypto.X509Certificate;
import org.mozilla.jss.pkcs11.PK11Cert;

public class ListCACerts {
public static void main(String args[]) throws Exception {
Expand All @@ -21,9 +22,9 @@ public static void main(String args[]) throws Exception {
if (args.length == 2 && args[1].equalsIgnoreCase("verbose")) {
for (int i = 0; i < certs.length; i++) {
System.out.println(certs[i].getSubjectDN().toString());
InternalCertificate ic = (InternalCertificate) certs[i];
System.out.println("SSL: " + ic.getSSLTrust() +
", Email: " + ic.getEmailTrust() +
PK11Cert ic = (PK11Cert) certs[i];
System.out.println("SSL: " + ic.getSSLTrust() +
", Email: " + ic.getEmailTrust() +
", Object Signing: " + ic.getObjectSigningTrust());
}
}
Expand Down
3 changes: 1 addition & 2 deletions base/src/test/java/org/mozilla/jss/tests/SSLClientAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.mozilla.jss.asn1.OCTET_STRING;
import org.mozilla.jss.asn1.SEQUENCE;
import org.mozilla.jss.crypto.CryptoToken;
import org.mozilla.jss.crypto.InternalCertificate;
import org.mozilla.jss.crypto.NoSuchItemOnTokenException;
import org.mozilla.jss.crypto.ObjectNotFoundException;
import org.mozilla.jss.crypto.SignatureAlgorithm;
Expand Down Expand Up @@ -211,7 +210,7 @@ private void generateCerts(CryptoManager cm, int serialNum) {
caPair.getPrivate(), caPair.getPublic(), serialNum, extensions);
X509Certificate nssCaCert = cm.importUserCACertPackage(
ASN1Util.encode(caCert), "SSLCA-"+serialNum);
InternalCertificate intern = (InternalCertificate)nssCaCert;
PK11Cert intern = (PK11Cert) nssCaCert;
intern.setSSLTrust(
PK11Cert.TRUSTED_CA |
PK11Cert.TRUSTED_CLIENT_CA |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import java.util.Enumeration;

import org.mozilla.jss.crypto.InternalCertificate;
import org.mozilla.jss.CryptoManager;
import org.mozilla.jss.pkcs11.PK11Cert;
import org.mozilla.jss.ssl.SSLCertificateApprovalCallback;
import org.slf4j.Logger;
Expand Down Expand Up @@ -67,9 +67,8 @@ public boolean approve(
logger.debug("importing certificate.");

try {
InternalCertificate newcert =
org.mozilla.jss.CryptoManager.getInstance().
importCertToPerm(servercert,"testnick");
CryptoManager cm = CryptoManager.getInstance();
PK11Cert newcert = (PK11Cert) cm.importCertToPerm(servercert, "testnick");
newcert.setSSLTrust(PK11Cert.TRUSTED_PEER | PK11Cert.VALID_PEER);
} catch (Exception e) {
System.out.println("thrown exception: "+e);
Expand Down

0 comments on commit 1904b72

Please sign in to comment.