diff options
Diffstat (limited to 'src/main/java/org/openslx/satellitedaemon/Identity.java')
-rw-r--r-- | src/main/java/org/openslx/satellitedaemon/Identity.java | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/Identity.java b/src/main/java/org/openslx/satellitedaemon/Identity.java index ce6b753..e95cf99 100644 --- a/src/main/java/org/openslx/satellitedaemon/Identity.java +++ b/src/main/java/org/openslx/satellitedaemon/Identity.java @@ -11,12 +11,15 @@ import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.PublicKey; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; import java.security.spec.InvalidKeySpecException; import java.util.Properties; import java.util.Random; import org.apache.log4j.Logger; import org.openslx.encryption.AsymKeyHolder; +import org.openslx.satellitedaemon.filetransfer.ThriftConnection; import org.openslx.satellitedaemon.util.Util; public class Identity @@ -24,31 +27,26 @@ public class Identity private static Logger log = Logger.getLogger( Identity.class ); private static final Properties properties = new Properties(); - private static String organizationName = null; - private static BigInteger privExponent = null; - private static BigInteger pubExponent = null; - private static BigInteger modulus = null; - private static AsymKeyHolder akh = null; public static String getOrganizationName() { - return organizationName = properties.getProperty( "ORGANIZATION_NAME" ); + return properties.getProperty( "ORGANIZATION_NAME" ); } private static BigInteger getModulus() { - return modulus = toBigInt( properties.getProperty( "MODULUS" ) ); + return toBigInt( properties.getProperty( "MODULUS" ) ); } private static BigInteger getPublicExponent() { - return pubExponent = toBigInt( properties.getProperty( "PUBLIC_EXPONENT" ) ); + return toBigInt( properties.getProperty( "PUBLIC_EXPONENT" ) ); } private static BigInteger getPrivateExponent() { - return privExponent = toBigInt( properties.getProperty( "PRIVATE_EXPONENT" ) ); + return toBigInt( properties.getProperty( "PRIVATE_EXPONENT" ) ); } /** @@ -156,18 +154,9 @@ public class Identity */ public static boolean generateIdentity( String organizationName ) { - Identity.organizationName = organizationName; // generate new key pair. Identity.akh = new AsymKeyHolder(); - Identity.modulus = akh.getModulus(); - Identity.privExponent = akh.getPrivateExponent(); - Identity.pubExponent = akh.getPublicExponent(); - - return writeIdToFile( - Identity.organizationName, - Identity.modulus, - Identity.privExponent, - Identity.pubExponent ); + return writeIdToFile( organizationName, akh.getModulus(), akh.getPrivateExponent(), akh.getPublicExponent() ); } /** @@ -182,15 +171,25 @@ public class Identity */ 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 ); + return writeIdToFile( organizationName, modulus, privateExp, publicExp ); + } + + public static boolean submitKey( String ipAddress ) + { + RSAPublicKey pubKey = (RSAPublicKey)getPublicKey(); + RSAPrivateKey privKey = (RSAPrivateKey)getPrivateKey(); + assert ( pubKey.getModulus() == privKey.getModulus() ); + + if ( !Identity.isValidKeyPair( + privKey.getModulus(), + privKey.getPrivateExponent(), + pubKey.getPublicExponent() ) ) + return false; + return ThriftConnection.registerSatellite( + getOrganizationName(), + ipAddress, + pubKey.getModulus().toString(), + pubKey.getPublicExponent().toString() ); } /** |