aboutsummaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/standalone/libs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/cz/crcs/ectester/standalone/libs/BouncyCastleLib.java19
-rw-r--r--src/cz/crcs/ectester/standalone/libs/CECLibrary.java31
-rw-r--r--src/cz/crcs/ectester/standalone/libs/ECLibrary.java21
-rw-r--r--src/cz/crcs/ectester/standalone/libs/JavaECLibrary.java85
-rw-r--r--src/cz/crcs/ectester/standalone/libs/SunECLib.java14
5 files changed, 157 insertions, 13 deletions
diff --git a/src/cz/crcs/ectester/standalone/libs/BouncyCastleLib.java b/src/cz/crcs/ectester/standalone/libs/BouncyCastleLib.java
index 78da737..73cd197 100644
--- a/src/cz/crcs/ectester/standalone/libs/BouncyCastleLib.java
+++ b/src/cz/crcs/ectester/standalone/libs/BouncyCastleLib.java
@@ -1,21 +1,14 @@
package cz.crcs.ectester.standalone.libs;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import java.security.Security;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
-public class BouncyCastleLib {
+/**
+ * @author Jan Jancar johny@neuromancer.sk
+ */
+public class BouncyCastleLib extends JavaECLibrary {
public BouncyCastleLib() {
-
- }
-
- public boolean setUp() {
- try {
- Security.addProvider(new BouncyCastleProvider());
- } catch (NullPointerException | SecurityException ignored) {
- return false;
- }
- return true;
+ super(new BouncyCastleProvider());
}
}
diff --git a/src/cz/crcs/ectester/standalone/libs/CECLibrary.java b/src/cz/crcs/ectester/standalone/libs/CECLibrary.java
new file mode 100644
index 0000000..82a4555
--- /dev/null
+++ b/src/cz/crcs/ectester/standalone/libs/CECLibrary.java
@@ -0,0 +1,31 @@
+package cz.crcs.ectester.standalone.libs;
+
+/**
+ * @author Jan Jancar johny@neuromancer.sk
+ */
+public abstract class CECLibrary implements ECLibrary {
+
+ private String resourcePath;
+ private String libname;
+
+ public CECLibrary(String resourcePath, String libname) {
+ this.resourcePath = resourcePath;
+ this.libname = libname;
+ }
+
+ @Override
+ public boolean initialize() {
+ // load the library here.
+ return false;
+ }
+
+ @Override
+ public String name() {
+ return libname;
+ }
+
+ @Override
+ public String toString() {
+ return name();
+ }
+}
diff --git a/src/cz/crcs/ectester/standalone/libs/ECLibrary.java b/src/cz/crcs/ectester/standalone/libs/ECLibrary.java
new file mode 100644
index 0000000..b2792bd
--- /dev/null
+++ b/src/cz/crcs/ectester/standalone/libs/ECLibrary.java
@@ -0,0 +1,21 @@
+package cz.crcs.ectester.standalone.libs;
+
+import cz.crcs.ectester.standalone.consts.KeyAgreementIdent;
+import cz.crcs.ectester.standalone.consts.SignatureIdent;
+
+import java.util.Set;
+
+/**
+ * @author Jan Jancar johny@neuromancer.sk
+ */
+public interface ECLibrary {
+ boolean initialize();
+
+ boolean isInitialized();
+
+ Set<KeyAgreementIdent> getECKAs();
+
+ Set<SignatureIdent> getECSigs();
+
+ String name();
+}
diff --git a/src/cz/crcs/ectester/standalone/libs/JavaECLibrary.java b/src/cz/crcs/ectester/standalone/libs/JavaECLibrary.java
new file mode 100644
index 0000000..f8848da
--- /dev/null
+++ b/src/cz/crcs/ectester/standalone/libs/JavaECLibrary.java
@@ -0,0 +1,85 @@
+package cz.crcs.ectester.standalone.libs;
+
+import cz.crcs.ectester.standalone.consts.KeyAgreementIdent;
+import cz.crcs.ectester.standalone.consts.SignatureIdent;
+
+import java.security.Provider;
+import java.security.Security;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Jan Jancar johny@neuromancer.sk
+ */
+public abstract class JavaECLibrary implements ECLibrary {
+ private Provider provider;
+ private boolean initialized;
+
+ public JavaECLibrary(Provider provider) {
+ this.provider = provider;
+ this.initialized = false;
+ }
+
+ @Override
+ public boolean initialize() {
+ try {
+ int result = Security.addProvider(provider);
+ if (result == -1) {
+ provider = Security.getProvider(provider.getName());
+ }
+ initialized = true;
+ } catch (NullPointerException | SecurityException ignored) {
+ initialized = false;
+ }
+ return initialized;
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return initialized;
+ }
+
+ @Override
+ public Set<KeyAgreementIdent> getECKAs() {
+ Set<KeyAgreementIdent> results = new HashSet<>();
+ for (Provider.Service service : provider.getServices()) {
+ if (service.getType().equals("KeyAgreement")) {
+ KeyAgreementIdent id = KeyAgreementIdent.get(service.getAlgorithm());
+ if (id != null) {
+ results.add(id);
+ }
+ }
+ }
+ System.out.println(results);
+ return results;
+ }
+
+ @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;
+ }
+
+ @Override
+ public String name() {
+ return provider.getInfo();
+ }
+
+ public Provider getProvider() {
+ return provider;
+ }
+
+ @Override
+ public String toString() {
+ return name();
+ }
+}
diff --git a/src/cz/crcs/ectester/standalone/libs/SunECLib.java b/src/cz/crcs/ectester/standalone/libs/SunECLib.java
new file mode 100644
index 0000000..408908e
--- /dev/null
+++ b/src/cz/crcs/ectester/standalone/libs/SunECLib.java
@@ -0,0 +1,14 @@
+package cz.crcs.ectester.standalone.libs;
+
+import sun.security.ec.SunEC;
+
+/**
+ * @author Jan Jancar johny@neuromancer.sk
+ */
+public class SunECLib extends JavaECLibrary {
+
+ public SunECLib() {
+ super(new SunEC());
+ }
+
+}