summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cz/crcs/ectester/standalone/ECTesterStandalone.java25
-rw-r--r--src/cz/crcs/ectester/standalone/consts/KeyPairGeneratorIdent.java36
-rw-r--r--src/cz/crcs/ectester/standalone/libs/ECLibrary.java3
-rw-r--r--src/cz/crcs/ectester/standalone/libs/JavaECLibrary.java35
4 files changed, 79 insertions, 20 deletions
diff --git a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java
index 47b7121..016d095 100644
--- a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java
+++ b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java
@@ -3,12 +3,17 @@ package cz.crcs.ectester.standalone;
import cz.crcs.ectester.applet.EC_Consts;
import cz.crcs.ectester.common.ec.EC_Curve;
import cz.crcs.ectester.data.EC_Store;
+import cz.crcs.ectester.standalone.consts.KeyPairGeneratorIdent;
import cz.crcs.ectester.standalone.libs.BouncyCastleLib;
import cz.crcs.ectester.standalone.libs.ECLibrary;
+import cz.crcs.ectester.standalone.libs.JavaECLibrary;
import cz.crcs.ectester.standalone.libs.SunECLib;
import org.apache.commons.cli.*;
import java.io.IOException;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
/**
@@ -45,9 +50,23 @@ public class ECTesterStandalone {
cfg = new Config();
dataStore = new EC_Store();
for (ECLibrary lib : libs) {
- lib.initialize();
- lib.getECKAs();
- lib.getECSigs();
+ if (lib instanceof JavaECLibrary) {
+ JavaECLibrary jlib = (JavaECLibrary) lib;
+ lib.initialize();
+ lib.getECKAs();
+ lib.getECSigs();
+ for (KeyPairGeneratorIdent ident : lib.getKPGs()) {
+ try {
+ KeyPairGenerator kpg = ident.getInstance(jlib.getProvider());
+ kpg.initialize(192);
+ KeyPair kp = kpg.genKeyPair();
+ System.out.println(kp);
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
}
System.out.println(Arrays.toString(libs));
diff --git a/src/cz/crcs/ectester/standalone/consts/KeyPairGeneratorIdent.java b/src/cz/crcs/ectester/standalone/consts/KeyPairGeneratorIdent.java
new file mode 100644
index 0000000..f806282
--- /dev/null
+++ b/src/cz/crcs/ectester/standalone/consts/KeyPairGeneratorIdent.java
@@ -0,0 +1,36 @@
+package cz.crcs.ectester.standalone.consts;
+
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.Provider;
+import java.util.LinkedList;
+import java.util.List;
+
+public class KeyPairGeneratorIdent extends Ident {
+ private static final List<KeyPairGeneratorIdent> ALL = new LinkedList<>();
+
+ static {
+ ALL.add(new KeyPairGeneratorIdent("EC"));
+ ALL.add(new KeyPairGeneratorIdent("ECDH"));
+ ALL.add(new KeyPairGeneratorIdent("ECDSA"));
+ ALL.add(new KeyPairGeneratorIdent("ECDHC"));
+ ALL.add(new KeyPairGeneratorIdent("ECMQV"));
+ }
+
+ public static KeyPairGeneratorIdent get(String ident) {
+ for (KeyPairGeneratorIdent kg : ALL) {
+ if (kg.getIdents().contains(ident)) {
+ return kg;
+ }
+ }
+ return null;
+ }
+
+ public KeyPairGeneratorIdent(String name, String... aliases) {
+ super(name, aliases);
+ }
+
+ public KeyPairGenerator getInstance(Provider provider) throws NoSuchAlgorithmException {
+ return KeyPairGenerator.getInstance(name, provider);
+ }
+}
diff --git a/src/cz/crcs/ectester/standalone/libs/ECLibrary.java b/src/cz/crcs/ectester/standalone/libs/ECLibrary.java
index b2792bd..7e26dbe 100644
--- a/src/cz/crcs/ectester/standalone/libs/ECLibrary.java
+++ b/src/cz/crcs/ectester/standalone/libs/ECLibrary.java
@@ -1,6 +1,7 @@
package cz.crcs.ectester.standalone.libs;
import cz.crcs.ectester.standalone.consts.KeyAgreementIdent;
+import cz.crcs.ectester.standalone.consts.KeyPairGeneratorIdent;
import cz.crcs.ectester.standalone.consts.SignatureIdent;
import java.util.Set;
@@ -17,5 +18,7 @@ public interface ECLibrary {
Set<SignatureIdent> getECSigs();
+ Set<KeyPairGeneratorIdent> getKPGs();
+
String name();
}
diff --git a/src/cz/crcs/ectester/standalone/libs/JavaECLibrary.java b/src/cz/crcs/ectester/standalone/libs/JavaECLibrary.java
index f8848da..5689b2b 100644
--- a/src/cz/crcs/ectester/standalone/libs/JavaECLibrary.java
+++ b/src/cz/crcs/ectester/standalone/libs/JavaECLibrary.java
@@ -1,12 +1,15 @@
package cz.crcs.ectester.standalone.libs;
+import cz.crcs.ectester.standalone.consts.Ident;
import cz.crcs.ectester.standalone.consts.KeyAgreementIdent;
+import cz.crcs.ectester.standalone.consts.KeyPairGeneratorIdent;
import cz.crcs.ectester.standalone.consts.SignatureIdent;
import java.security.Provider;
import java.security.Security;
import java.util.HashSet;
import java.util.Set;
+import java.util.function.Function;
/**
* @author Jan Jancar johny@neuromancer.sk
@@ -39,34 +42,32 @@ public abstract class JavaECLibrary implements ECLibrary {
return initialized;
}
- @Override
- public Set<KeyAgreementIdent> getECKAs() {
- Set<KeyAgreementIdent> results = new HashSet<>();
+ private <T extends Ident> Set<T> getIdents(String type, Function<String, T> getter) {
+ Set<T> results = new HashSet<>();
for (Provider.Service service : provider.getServices()) {
- if (service.getType().equals("KeyAgreement")) {
- KeyAgreementIdent id = KeyAgreementIdent.get(service.getAlgorithm());
+ if (service.getType().equals(type)) {
+ T id = getter.apply(service.getAlgorithm());
if (id != null) {
results.add(id);
}
}
}
- System.out.println(results);
return results;
}
@Override
+ public Set<KeyAgreementIdent> getECKAs() {
+ return getIdents("KeyAgreement", KeyAgreementIdent::get);
+ }
+
+ @Override
public Set<SignatureIdent> getECSigs() {
- Set<SignatureIdent> results = new HashSet<>();
- for (Provider.Service service : provider.getServices()) {
- if (service.getType().equals("Signature")) {
- SignatureIdent id = SignatureIdent.get(service.getAlgorithm());
- if (id != null) {
- results.add(id);
- }
- }
- }
- System.out.println(results);
- return results;
+ return getIdents("Signature", SignatureIdent::get);
+ }
+
+ @Override
+ public Set<KeyPairGeneratorIdent> getKPGs() {
+ return getIdents("KeyPairGenerator", KeyPairGeneratorIdent::get);
}
@Override