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.java58
1 files changed, 25 insertions, 33 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/Identity.java b/src/main/java/org/openslx/satellitedaemon/Identity.java
index ae28def..8126aa9 100644
--- a/src/main/java/org/openslx/satellitedaemon/Identity.java
+++ b/src/main/java/org/openslx/satellitedaemon/Identity.java
@@ -19,10 +19,6 @@ public class Identity
private static Logger log = Logger.getLogger( Identity.class );
private static final Properties properties = new Properties();
- private static BigInteger mod = null;
- private static BigInteger privExp = null;
- private static BigInteger pubExp = null;
-
private static AsymKeyHolder akh = null;
public static String getOrganizationName()
@@ -30,47 +26,44 @@ public class Identity
return properties.getProperty( "ORGANIZATION_NAME" );
}
- public static BigInteger getModulus()
+ private static BigInteger getModulus()
{
- String privateModulus = properties.getProperty( "MODULUS" );
- mod = new BigInteger( privateModulus );
- return mod;
+ return toBigInt( properties.getProperty( "MODULUS" ) );
}
- public static BigInteger getPublicExponent()
+ private static BigInteger getPublicExponent()
{
- String publicModulus = properties.getProperty( "PUBLIC_EXPONENT" );
- pubExp = new BigInteger( publicModulus );
- return pubExp;
+ return toBigInt( properties.getProperty( "PUBLIC_EXPONENT" ) );
}
- public static BigInteger getPrivateExponent()
+ private static BigInteger getPrivateExponent()
{
- String exponent = properties.getProperty( "PRIVATE_EXPONENT" );
- privExp = new BigInteger( exponent );
- return privExp;
+ return toBigInt( properties.getProperty( "PRIVATE_EXPONENT" ) );
}
/**
* Load properties
*/
static {
+ InputStreamReader stream = null;
try {
// Load all entries of the config file into properties
- InputStreamReader stream = new InputStreamReader(
+ stream = new InputStreamReader(
new FileInputStream( "config/identity.properties" ), StandardCharsets.UTF_8 );
properties.load( stream );
stream.close();
} catch ( IOException e ) {
- log.error( "Could not load properties. Exiting." );
+ log.error( "Could not load identity.properties. Exiting." );
System.exit( 2 );
+ } finally {
+ Util.streamClose( stream );
}
-
+
Util.notNullOrEmptyFatal( getOrganizationName(), "Organiziation Name must not be empty!" );
try {
- akh = new AsymKeyHolder( privExp, pubExp, mod );
+ akh = new AsymKeyHolder( getPrivateExponent(), getPublicExponent(), getModulus() );
} catch ( InvalidKeySpecException e ) {
- log.error( "InvalidKeySpecException", e);
+ log.error( "InvalidKeySpecException", e );
} catch ( NoSuchAlgorithmException e ) {
log.error( "NoSuchAlgorithmException", e );
}
@@ -83,15 +76,10 @@ public class Identity
*/
public static PrivateKey getPrivateKey()
{
- if (akh != null) {
+ if ( akh != null ) {
return akh.getPrivateKey();
- }
- try {
- akh = new AsymKeyHolder();
- } catch ( NoSuchAlgorithmException e ) {
- log.error( "NoSuchAlgorithmException", e );
- return null;
}
+ akh = new AsymKeyHolder();
return akh.getPrivateKey();
}
@@ -102,14 +90,18 @@ public class Identity
*/
public static PublicKey getPublicKey()
{
- if (akh != null)
+ if ( akh != null )
return akh.getPublicKey();
+ akh = new AsymKeyHolder();
+ return akh.getPublicKey();
+ }
+
+ private static BigInteger toBigInt( String str )
+ {
try {
- akh = new AsymKeyHolder();
- } catch ( NoSuchAlgorithmException e) {
- log.error("NoSuchAlgorithmException", e);
+ return new BigInteger( str );
+ } catch ( Exception e ) {
return null;
}
- return akh.getPublicKey();
}
}