diff options
author | Björn Hagemeister | 2014-10-15 13:31:41 +0200 |
---|---|---|
committer | Björn Hagemeister | 2014-10-15 13:31:41 +0200 |
commit | 615b6b7361c0bbb00a359a47e045a248110218ce (patch) | |
tree | 90b7f4d7bcecba100cb99edfb2ca8a0522eac633 | |
parent | ... (diff) | |
download | satellite-daemon-615b6b7361c0bbb00a359a47e045a248110218ce.tar.gz satellite-daemon-615b6b7361c0bbb00a359a47e045a248110218ce.tar.xz satellite-daemon-615b6b7361c0bbb00a359a47e045a248110218ce.zip |
completed implementing --checkConfig command line option.
-rw-r--r-- | src/main/java/org/openslx/satellitedaemon/App.java | 15 | ||||
-rw-r--r-- | src/main/java/org/openslx/satellitedaemon/Identity.java | 15 |
2 files changed, 23 insertions, 7 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/App.java b/src/main/java/org/openslx/satellitedaemon/App.java index 7c87401..6a4ebf4 100644 --- a/src/main/java/org/openslx/satellitedaemon/App.java +++ b/src/main/java/org/openslx/satellitedaemon/App.java @@ -109,25 +109,26 @@ public class App private static boolean checkConfig() { if (Identity.getOrganizationName() == null) return false; - // TODO: check members of identity.java. - // Testing encryption and description + // First check existing members (modulus, privExp, pubExp) of Identity. + if (!Identity.checkMembers()) + return false; + + // Testing encryption and description with given public and private key. + // Idea: creating random text for encrypting and decrypting again. Random rnd = new Random(); if (Identity.keySize() != -1) { int size = rnd.nextInt(Identity.keySize() - 1); BigInteger text = new BigInteger(size,rnd); RSAPublicKey pub = (RSAPublicKey) Identity.getPublicKey(); RSAPrivateKey priv = (RSAPrivateKey) Identity.getPrivateKey(); + // Encrypt. BigInteger cipher = text.modPow(pub.getPublicExponent(), pub.getModulus()); + // Decrypt again. BigInteger decrypted = cipher.modPow(priv.getPrivateExponent(), priv.getModulus()); boolean isPassed = text.equals(decrypted); return isPassed; } return false; -// System.out.println("--- RSA encryption test ---"); -// System.out.println("Is test passed: "+isPassed); -// System.out.println("Original text: "+text); -// System.out.println("Cipher text: "+cipher); -// System.out.println("Decrypted text: "+decrypted); } private static boolean genId(String organizationName) { diff --git a/src/main/java/org/openslx/satellitedaemon/Identity.java b/src/main/java/org/openslx/satellitedaemon/Identity.java index b79ad68..92bf425 100644 --- a/src/main/java/org/openslx/satellitedaemon/Identity.java +++ b/src/main/java/org/openslx/satellitedaemon/Identity.java @@ -97,12 +97,27 @@ public class Identity return akh.getPublicKey(); } + /** + * Get bit - length of key. + * @return + */ public static int keySize() { if (getModulus() != null) return getModulus().bitLength(); return -1; } + public static boolean checkMembers() { + return ( + (getModulus() != null) && + (getPrivateExponent() != null) && + (getPublicExponent() != null)); + } + /** + * Get BigInteger of read String number. + * @param str + * @return + */ private static BigInteger toBigInt( String str ) { try { |