diff options
Diffstat (limited to 'src/main/java/org/openslx/satellitedaemon/App.java')
-rw-r--r-- | src/main/java/org/openslx/satellitedaemon/App.java | 107 |
1 files changed, 51 insertions, 56 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/App.java b/src/main/java/org/openslx/satellitedaemon/App.java index 6a4ebf4..34d61ed 100644 --- a/src/main/java/org/openslx/satellitedaemon/App.java +++ b/src/main/java/org/openslx/satellitedaemon/App.java @@ -29,30 +29,30 @@ public class App String organizationName; String modulus, privExp, pubExp; String ipAddress; - + // Check if there are arguments available and if they start with "--". - if (i < args.length && args[i].startsWith( "--" )) { + if ( i < args.length && args[i].startsWith( "--" ) ) { // Arguments available, take the first one. arg = args[i++]; - if (arg.equals( "--checkconfig" )) { - if (checkConfig()) { + if ( arg.equals( "--checkconfig" ) ) { + if ( checkConfig() ) { System.exit( 0 ); } System.exit( 2 ); - } else if (arg.equals( "--genid" )) { - if (i < args.length) { + } else if ( arg.equals( "--genid" ) ) { + if ( i < args.length ) { organizationName = args[i++]; - if (genId(organizationName)) { + if ( genId( organizationName ) ) { System.exit( 0 ); } - else + else System.exit( 2 ); } else { log.error( "--genid requires an organization name" ); System.exit( 2 ); } - } else if (arg.equals( "--import" )) { - if ((i + 3) < args.length) { + } else if ( arg.equals( "--import" ) ) { + if ( ( i + 3 ) < args.length ) { log.error( "Illelgal option: '--import' requires 4 arguments, <OrgName> <Modulus> <priv_Exponent> <pub_Exponent>" ); System.exit( 2 ); } else { @@ -60,41 +60,41 @@ public class App modulus = args[i++]; privExp = args[i++]; pubExp = args[i++]; - if (importId(organizationName, modulus, privExp, pubExp)) { + if ( importId( organizationName, modulus, privExp, pubExp ) ) { System.exit( 0 ); } else System.exit( 2 ); } - } else if (arg.equals( "--submitkey")) { - if (i < args.length) { + } else if ( arg.equals( "--submitkey" ) ) { + if ( i < args.length ) { ipAddress = args[i++]; - if (submitKey(ipAddress)) + if ( submitKey( ipAddress ) ) System.exit( 0 ); - else + else System.exit( 2 ); } else { log.error( "--submitkey requires <IPADDRESS>" ); System.exit( 2 ); } - } else if (arg.equals( "--updateaddress" )) { - if (i < args.length) { + } else if ( arg.equals( "--updateaddress" ) ) { + if ( i < args.length ) { ipAddress = args[i++]; - if (updateAddress(ipAddress)) { + if ( updateAddress( ipAddress ) ) { System.exit( 0 ); - } else + } else System.exit( 2 ); } else { log.error( "--updateaddress requires <IPADDRESS>" ); System.exit( 2 ); } } - } else if (args.length == 0) { + } else if ( args.length == 0 ) { // No Option choosed, try to load existing identity. - if (!tryLoadIdentity()) { + if ( !tryLoadIdentity() ) { System.exit( 2 ); } } - + if ( !Globals.masterServerSslContextInit() ) { log.error( "Problem with initializing the SSLContext" ); System.exit( 1 ); @@ -105,53 +105,48 @@ public class App Thread downloadWorker = new Thread( new FileDownloadWorker() ); downloadWorker.start(); } - - private static boolean checkConfig() { - if (Identity.getOrganizationName() == null) - return false; - // First check existing members (modulus, privExp, pubExp) of Identity. - if (!Identity.checkMembers()) + + private static boolean checkConfig() + { + if ( Identity.getOrganizationName() == null ) 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; + RSAPublicKey pub = (RSAPublicKey)Identity.getPublicKey(); + RSAPrivateKey priv = (RSAPrivateKey)Identity.getPrivateKey(); + assert ( pub.getModulus() == priv.getModulus() ); + BigInteger modulus = pub.getModulus(); + return Identity.isValidKeyPair( + modulus, + priv.getPrivateExponent(), + pub.getPublicExponent() ); } - - private static boolean genId(String organizationName) { - // TODO. + + private static boolean genId( String organizationName ) + { + if ( Identity.generateIdentity( organizationName ) ) + return true; return false; } - - private static boolean importId(String organizationName, String modulus, String privExp, String pubExp) { + + private static boolean importId( String organizationName, String modulus, String privExp, String pubExp ) + { // TODO. return false; } - - private static boolean submitKey(String ipAddress) { + + private static boolean submitKey( String ipAddress ) + { // TODO. return false; } - - private static boolean updateAddress(String ipAddress) { + + private static boolean updateAddress( String ipAddress ) + { // TODO. return false; } - - private static boolean tryLoadIdentity() { + + private static boolean tryLoadIdentity() + { // TODO. return false; } |