From 3aa85cd588b745fb2537dbe748580d9c3b980133 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 8 Sep 2015 17:38:07 +0200 Subject: Compilable... --- .../serversession/ServerAuthenticator.java | 33 +++++++++++----------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'src/main/java/org/openslx/imagemaster/serversession/ServerAuthenticator.java') diff --git a/src/main/java/org/openslx/imagemaster/serversession/ServerAuthenticator.java b/src/main/java/org/openslx/imagemaster/serversession/ServerAuthenticator.java index 88697bf..a7c7fde 100644 --- a/src/main/java/org/openslx/imagemaster/serversession/ServerAuthenticator.java +++ b/src/main/java/org/openslx/imagemaster/serversession/ServerAuthenticator.java @@ -6,10 +6,10 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.log4j.Logger; import org.apache.thrift.TException; +import org.openslx.bwlp.thrift.iface.AuthorizationError; +import org.openslx.bwlp.thrift.iface.TAuthorizationException; import org.openslx.encryption.AsymEncryptionHandler; -import org.openslx.imagemaster.db.DbSatellite; -import org.openslx.imagemaster.thrift.iface.AuthenticationError; -import org.openslx.imagemaster.thrift.iface.AuthenticationException; +import org.openslx.imagemaster.db.models.LocalSatellite; import org.openslx.imagemaster.util.RandomString; /** @@ -23,20 +23,20 @@ public class ServerAuthenticator /** * Servers currently doing authentication. Maps from organization to the challenge we sent. */ - private static Map authenticatingServers = new ConcurrentHashMap<>(); + private static Map authenticatingServers = new ConcurrentHashMap<>(); /** * Start the server authentification. * - * @param organization + * @param satelliteId * the organization of the server * @return encrypted random string */ - public static ByteBuffer startServerAuthentication( String organization ) + public static ByteBuffer startServerAuthentication( int satelliteId ) { byte[] secret = RandomString.generateBinary( 100 ); - authenticatingServers.put( organization, secret ); - log.info( "Server of organinzation '" + organization + authenticatingServers.put( satelliteId, secret ); + log.info( "Server of organinzation '" + satelliteId + "' starts to authenticate. And got string: '" + secret.length + "'" ); return ByteBuffer.wrap( secret ); @@ -48,25 +48,24 @@ public class ServerAuthenticator * @param organizationId Is already verified. * @param address * @param challengeResponse - * @return * @throws ServerAuthenticationException * @throws TException */ - public static ServerUser serverAuthenticate( DbSatellite satellite, ByteBuffer challengeResponse ) - throws AuthenticationException + public static void serverAuthenticate( LocalSatellite satellite, ByteBuffer challengeResponse ) + throws TAuthorizationException { byte[] encryptedBytes = new byte[ challengeResponse.remaining() ]; challengeResponse.get( encryptedBytes ); AsymEncryptionHandler verifier = new AsymEncryptionHandler( satellite.getPubkey() ); - if ( !verifier.verifyMessage( encryptedBytes, authenticatingServers.get( satellite.getOrganizationId() ) ) ) - throw new AuthenticationException( AuthenticationError.CHALLENGE_FAILED, "You failed the encryption challenge. private and public key don't seem to match." ); + if ( !verifier.verifyMessage( encryptedBytes, authenticatingServers.get( satellite.satelliteId ) ) ) { + throw new TAuthorizationException( AuthorizationError.CHALLENGE_FAILED, + "You failed the encryption challenge. private and public key don't seem to match." ); + } - log.info( "Server of organinzation " + satellite.getName() + " (" + satellite.getOrganizationId() + ") authenticated." ); + log.info( "Server '" + satellite.satelliteName + "' (" + satellite.organizationId + ") authenticated." ); - authenticatingServers.remove( satellite.getOrganizationId() ); - - return new ServerUser( satellite.getOrganizationId(), satellite.getAddress() ); + authenticatingServers.remove( satellite.organizationId ); } } -- cgit v1.2.3-55-g7522