bwLehrpool Masterserver
Manages authentication and sharing of virtual machines between participating institutions
ServerAuthenticator.java
Go to the documentation of this file.
1 package org.openslx.imagemaster.serversession;
2 
3 import java.nio.ByteBuffer;
4 import java.util.Map;
5 import java.util.concurrent.ConcurrentHashMap;
6 
7 import org.apache.logging.log4j.LogManager;
8 import org.apache.logging.log4j.Logger;
9 import org.apache.thrift.TException;
10 import org.openslx.bwlp.thrift.iface.AuthorizationError;
11 import org.openslx.bwlp.thrift.iface.TAuthorizationException;
12 import org.openslx.encryption.AsymEncryptionHandler;
15 
19 public class ServerAuthenticator
20 {
21 
22  private static Logger log = LogManager.getLogger( ServerAuthenticator.class );
23 
27  private static Map<Integer, byte[]> authenticatingServers = new ConcurrentHashMap<>();
28 
36  public static ByteBuffer startServerAuthentication( int satelliteId )
37  {
38  byte[] secret = RandomString.generateBinary( 100 );
39  authenticatingServers.put( satelliteId, secret );
40  log.info( "Server of organinzation '" + satelliteId
41  + "' starts to authenticate. And got string: '" + secret.length
42  + "'" );
43  return ByteBuffer.wrap( secret );
44  }
45 
55  public static void serverAuthenticate( LocalSatellite satellite, ByteBuffer challengeResponse )
56  throws TAuthorizationException
57  {
58  byte[] encryptedBytes = new byte[ challengeResponse.remaining() ];
59  challengeResponse.get( encryptedBytes );
60 
61  AsymEncryptionHandler verifier = new AsymEncryptionHandler( satellite.getPubkey() );
62 
63  if ( !verifier.verifyMessage( encryptedBytes, authenticatingServers.get( satellite.satelliteId ) ) ) {
64  throw new TAuthorizationException( AuthorizationError.CHALLENGE_FAILED,
65  "You failed the encryption challenge. private and public key don't seem to match." );
66  }
67 
68  log.info( "Server '" + satellite.satelliteName + "' (" + satellite.organizationId + ") authenticated." );
69 
70  authenticatingServers.remove( Integer.valueOf( satellite.organizationId ) );
71  }
72 }
static ByteBuffer startServerAuthentication(int satelliteId)
Start the server authentification.
Generate secure random strings.
Authenticating a server with message signing.
static Map< Integer, byte[]> authenticatingServers
Servers currently doing authentication.
static void serverAuthenticate(LocalSatellite satellite, ByteBuffer challengeResponse)
Authenticate with the challengeResponse.
static byte[] generateBinary(int length)
Generate random binary data.