diff options
author | Simon Rettberg | 2014-09-29 18:16:52 +0200 |
---|---|---|
committer | Simon Rettberg | 2014-09-29 18:16:52 +0200 |
commit | 9af765479c941d3664516ebcb8e203f4331264a9 (patch) | |
tree | 4a9e775d82542da320ef3b9d268316d99ad9ff61 /src/main/java/org/openslx/imagemaster/server | |
parent | [Db*] Fix SELECT for DbImage, change Timestamp to long, load public key from ... (diff) | |
download | masterserver-9af765479c941d3664516ebcb8e203f4331264a9.tar.gz masterserver-9af765479c941d3664516ebcb8e203f4331264a9.tar.xz masterserver-9af765479c941d3664516ebcb8e203f4331264a9.zip |
Use KeyPair classes for satellite authentication
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/server')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/server/ApiServer.java | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/main/java/org/openslx/imagemaster/server/ApiServer.java b/src/main/java/org/openslx/imagemaster/server/ApiServer.java index ce20020..b39a517 100644 --- a/src/main/java/org/openslx/imagemaster/server/ApiServer.java +++ b/src/main/java/org/openslx/imagemaster/server/ApiServer.java @@ -119,15 +119,17 @@ public class ApiServer * key of the requesting satellite server * @throws ServerAuthenticationException when organization is invalid/unknown */ - public static String startServerAuthentication( String organization ) + public static ByteBuffer startServerAuthentication( String organization ) throws ServerAuthenticationException { - if ( organization == null || organization.isEmpty() ) { + if ( organization == null || organization.isEmpty() ) throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_ORGANIZATION, "Empty organization" ); - } - if ( DbSatellite.fromOrganization( organization ) == null ) { - throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_ORGANIZATION, "Unknown organization" ); - } + + DbSatellite satellite = DbSatellite.fromOrganization( organization ); + if ( satellite == null ) + throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_ORGANIZATION, "Unknown organization: '" + organization + "'" ); + if ( satellite.getPubkey() == null ) + throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_KEY, "There is no public key known for your organization." ); return ServerAuthenticator.startServerAuthentication( organization ); } @@ -148,11 +150,12 @@ public class ApiServer throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_ORGANIZATION, "Empty organization or challengeResponse" ); } DbSatellite satellite = DbSatellite.fromOrganization( organization ); - if ( satellite == null ) { + if ( satellite == null ) throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_ORGANIZATION, "Unknown organization" ); - } - final ServerUser serverUser = ServerAuthenticator.serverAuthenticate( - organization, satellite.getAddress(), challengeResponse ); + if ( satellite.getPubkey() == null ) + throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_KEY, "There is no public key known for your organization." ); + + final ServerUser serverUser = ServerAuthenticator.serverAuthenticate( satellite, challengeResponse ); final ServerSession session = new ServerSession( serverUser ); return ServerSessionManager.addSession( session ); |