summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/satellitedaemon/Identity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/satellitedaemon/Identity.java')
-rw-r--r--src/main/java/org/openslx/satellitedaemon/Identity.java42
1 files changed, 41 insertions, 1 deletions
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";