-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
milad.bourhani
committed
Jun 14, 2024
1 parent
62e0575
commit 59cd302
Showing
5 changed files
with
275 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
name = SoftHSM2 | ||
library = /opt/homebrew/Cellar/softhsm/2.6.1/lib/softhsm/libsofthsm2.so | ||
slotListIndex = 0 | ||
library = /opt/homebrew/Cellar/softhsm/2.6.1/lib/softhsm/libsofthsm2.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name = SoftHSM2 | ||
library = /opt/homebrew/Cellar/softhsm/2.6.1/lib/softhsm/libsofthsm2.so | ||
slotListIndex = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.example; | ||
|
||
import java.security.*; | ||
import java.security.cert.X509Certificate; | ||
import java.util.Enumeration; | ||
|
||
public class LoadCertificates { | ||
|
||
public static void main(String[] args) { | ||
if (args.length == 0) { | ||
System.err.println("Must provide PKCS#11 conf file"); | ||
System.exit(1); | ||
} | ||
|
||
try { | ||
// Load the PKCS#11 provider configuration | ||
Provider p = Security.getProvider("SunPKCS11"); | ||
p = p.configure(args[0]); | ||
Security.addProvider(p); | ||
|
||
// Get an instance of the KeyStore | ||
KeyStore ks = KeyStore.getInstance("PKCS11"); | ||
ks.load(null, "5678".toCharArray()); | ||
|
||
// List aliases | ||
Enumeration<String> aliases = ks.aliases(); | ||
while (aliases.hasMoreElements()) { | ||
String alias = aliases.nextElement(); | ||
System.out.println("Alias found: " + alias); | ||
|
||
// Check if it is a certificate | ||
if (ks.isCertificateEntry(alias)) { | ||
X509Certificate cert = (X509Certificate) ks.getCertificate(alias); | ||
System.out.println("Certificate Subject: " + cert.getSubjectX500Principal()); | ||
} | ||
|
||
// Check if it is a key entry | ||
if (ks.isKeyEntry(alias)) { | ||
Key key = ks.getKey(alias, null); | ||
if (key instanceof PrivateKey) { | ||
PrivateKey privateKey = (PrivateKey) key; | ||
System.out.println("Private Key Algorithm: " + privateKey.getAlgorithm()); | ||
} | ||
} | ||
} | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters