summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Hagemeister2014-10-15 15:42:58 +0200
committerBjörn Hagemeister2014-10-15 15:42:58 +0200
commit1bb7917efc9747d1dc05970513a5ea673835a8c9 (patch)
treeffae6b3af2bf9d712fa2f924ab3ebc987962bf4c
parentImplemented --genId command line option. (diff)
downloadsatellite-daemon-1bb7917efc9747d1dc05970513a5ea673835a8c9.tar.gz
satellite-daemon-1bb7917efc9747d1dc05970513a5ea673835a8c9.tar.xz
satellite-daemon-1bb7917efc9747d1dc05970513a5ea673835a8c9.zip
Implemented --importId command line option and adapted TODO.txt.
-rw-r--r--TODO.txt2
-rw-r--r--src/main/java/org/openslx/satellitedaemon/App.java19
-rw-r--r--src/main/java/org/openslx/satellitedaemon/Identity.java42
3 files changed, 51 insertions, 12 deletions
diff --git a/TODO.txt b/TODO.txt
index b8fa8fe..5622586 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -17,7 +17,7 @@ Befehlszeilenoptionen:
generiert ein neues Schlüsselpaar. Alles in die identity.properties speichern
und bei Erfolg System.exit(0), sonst >0.
-[ ] * Option --import <ORGANAME> <MODULUS> <PRIV_EXP> <PUB_EXP>
+[x] * Option --import <ORGANAME> <MODULUS> <PRIV_EXP> <PUB_EXP>
Die Übergebene Identity in identity.properties speichern. Dabei sollte auch
überprüft werden, ob es sich um ein gültiges Schlüsselpaar handelt. Wenn alles
klappt. wieder exit(0), sonst >0.
diff --git a/src/main/java/org/openslx/satellitedaemon/App.java b/src/main/java/org/openslx/satellitedaemon/App.java
index 34d61ed..b413280 100644
--- a/src/main/java/org/openslx/satellitedaemon/App.java
+++ b/src/main/java/org/openslx/satellitedaemon/App.java
@@ -27,7 +27,7 @@ public class App
int i = 0;
String arg;
String organizationName;
- String modulus, privExp, pubExp;
+ BigInteger modulus, privExp, pubExp;
String ipAddress;
// Check if there are arguments available and if they start with "--".
@@ -57,9 +57,9 @@ public class App
System.exit( 2 );
} else {
organizationName = args[i++];
- modulus = args[i++];
- privExp = args[i++];
- pubExp = args[i++];
+ modulus = new BigInteger( args[i++] );
+ privExp = new BigInteger( args[i++] );
+ pubExp = new BigInteger( args[i++] );
if ( importId( organizationName, modulus, privExp, pubExp ) ) {
System.exit( 0 );
} else
@@ -122,15 +122,14 @@ public class App
private static boolean genId( String organizationName )
{
- if ( Identity.generateIdentity( organizationName ) )
- return true;
- return false;
+ return Identity.generateIdentity( organizationName );
}
- private static boolean importId( String organizationName, String modulus, String privExp, String pubExp )
+ private static boolean importId( String organizationName, BigInteger modulus, BigInteger privExp, BigInteger pubExp )
{
- // TODO.
- return false;
+ if ( !Identity.isValidKeyPair( modulus, privExp, pubExp ) )
+ return false;
+ return Identity.importIdentity( organizationName, modulus, privExp, pubExp );
}
private static boolean submitKey( String ipAddress )
diff --git a/src/main/java/org/openslx/satellitedaemon/Identity.java b/src/main/java/org/openslx/satellitedaemon/Identity.java
index 6e5c877..ce6b753 100644
--- a/src/main/java/org/openslx/satellitedaemon/Identity.java
+++ b/src/main/java/org/openslx/satellitedaemon/Identity.java
@@ -147,6 +147,13 @@ public class Identity
return isPassed;
}
+ /**
+ * Generate new identity with given organization name and new key pair.
+ * Write new identity to "config/identity.properties".
+ *
+ * @param organizationName
+ * @return true, if successful.
+ */
public static boolean generateIdentity( String organizationName )
{
Identity.organizationName = organizationName;
@@ -163,6 +170,39 @@ public class Identity
Identity.pubExponent );
}
+ /**
+ * Import given identity with organization name, modulus, private and public
+ * exponent and store this identity to "config/identity.properties".
+ *
+ * @param organizationName
+ * @param modulus
+ * @param privateExp
+ * @param publicExp
+ * @return true, if successful.
+ */
+ public static boolean importIdentity( String organizationName, BigInteger modulus, BigInteger privateExp, BigInteger publicExp )
+ {
+ Identity.organizationName = organizationName;
+ Identity.modulus = modulus;
+ Identity.privExponent = privateExp;
+ Identity.pubExponent = publicExp;
+ return writeIdToFile(
+ Identity.organizationName,
+ Identity.modulus,
+ Identity.privExponent,
+ Identity.pubExponent );
+ }
+
+ /**
+ * Write given organization name, modulus, public and private exponent to
+ * "config/identity.properties".
+ *
+ * @param organizationName
+ * @param modulus
+ * @param privateExp
+ * @param publicExp
+ * @return true, if successful.
+ */
private static boolean writeIdToFile( String organizationName, BigInteger modulus, BigInteger privateExp, BigInteger publicExp )
{
File configFile = new File( "config/identity.properties" );
@@ -173,7 +213,7 @@ public class Identity
log.error( "FileNotFoundException", e );
return false;
}
-
+
// create strings for writing to file.
String orgNameString = "ORGANIZATION_NAME=" + organizationName + "\n";
String modString = "MODULUS=" + modulus.toString() + "\n";