Skip to content

Commit

Permalink
Refactor PKCS10Client (part 2)
Browse files Browse the repository at this point in the history
The PKCS10Client has been modified to create the PKCS #10
request using NSSDatabase.
  • Loading branch information
edewata committed Feb 12, 2025
1 parent a0704b7 commit cd20251
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions base/tools/src/main/java/com/netscape/cmstools/PKCS10Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
import java.io.FileWriter;
import java.io.PrintStream;
import java.security.KeyPair;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.interfaces.DSAPublicKey;
import java.security.interfaces.RSAPublicKey;

import org.dogtagpki.nss.NSSDatabase;
import org.dogtagpki.util.cert.CertUtil;
Expand All @@ -38,7 +34,6 @@
import org.mozilla.jss.netscape.security.x509.Extensions;
import org.mozilla.jss.netscape.security.x509.KeyIdentifier;
import org.mozilla.jss.netscape.security.x509.SubjectKeyIdentifierExtension;
import org.mozilla.jss.netscape.security.x509.X509Key;
import org.mozilla.jss.util.Password;

import com.netscape.cmsutil.crypto.CryptoUtil;
Expand Down Expand Up @@ -352,25 +347,11 @@ public static void main(String args[]) throws Exception {
extns.add(extn);
}

PublicKey publicKey = pair.getPublic();
X509Key key = CryptoUtil.createX509Key(publicKey);

String algorithm;
if (publicKey instanceof RSAPublicKey) {
algorithm = "SHA256withRSA";
} else if (CryptoUtil.isECCKey(key)) {
algorithm = "SHA256withEC";
} else if (publicKey instanceof DSAPublicKey) {
algorithm = "DSA";
} else {
throw new NoSuchAlgorithmException("Unsupported algorithm: " + publicKey.getAlgorithm());
}

PKCS10 certReq = CryptoUtil.createPKCS10Request(
PKCS10 certReq = nssdb.createPKCS10Request(
pair,
subjectName,
enable_encoding,
pair,
algorithm,
"SHA256",
extns);

if (verbose) {
Expand Down

0 comments on commit cd20251

Please sign in to comment.