From fffaa68a16df723fb7ce058874078b8fed60fbce Mon Sep 17 00:00:00 2001 From: Björn Hagemeister Date: Wed, 22 Oct 2014 14:06:33 +0200 Subject: Store publickey in DbSatellite with prefix mod: and exp: for better indicating of the two numbers. --- .../org/openslx/imagemaster/db/DbSatellite.java | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/openslx/imagemaster/db/DbSatellite.java b/src/main/java/org/openslx/imagemaster/db/DbSatellite.java index 7a6ef2f..4f2576e 100644 --- a/src/main/java/org/openslx/imagemaster/db/DbSatellite.java +++ b/src/main/java/org/openslx/imagemaster/db/DbSatellite.java @@ -114,11 +114,27 @@ public class DbSatellite { if ( publickey == null && publickeyString != null ) { String parts[] = publickeyString.split( " " ); - if ( parts.length != 2 ) + BigInteger mod = null; + BigInteger exp = null; + for ( int i = 0; i < parts.length; ++i ) { + if ( parts[i].startsWith( "mod:" ) ) { + // modulus found. + mod = new BigInteger( parts[i].substring( 4 ) ); + } + if ( parts[i].startsWith( "exp:" ) ) { + // exponent found. + exp = new BigInteger( parts[i].substring( 4 ) ); + } + } + if ( mod == null ) { + LOG.error( "No modulus for building public key was found." ); + return null; + } + if ( exp == null ) { + LOG.error( "No public exponent for building public key was found." ); return null; + } try { - BigInteger mod = new BigInteger( parts[0] ); - BigInteger exp = new BigInteger( parts[1] ); publickey = new AsymKeyHolder( null, exp, mod ).getPublicKey(); } catch ( InvalidKeySpecException | NoSuchAlgorithmException e ) { LOG.info( "PubKey of " + this.name + " is not valid.", e ); @@ -133,7 +149,7 @@ public class DbSatellite { this.address = address; this.organizationId = organization; - MySQL.update( "UPDATE satellite SET address = ? WHERE organizationid = ?", address, organization); + MySQL.update( "UPDATE satellite SET address = ? WHERE organizationid = ?", address, organization ); } } -- cgit v1.2.3-55-g7522