summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/server/ApiServer.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/server/ApiServer.java')
-rw-r--r--src/main/java/org/openslx/imagemaster/server/ApiServer.java37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/main/java/org/openslx/imagemaster/server/ApiServer.java b/src/main/java/org/openslx/imagemaster/server/ApiServer.java
index ada6a21..0927e16 100644
--- a/src/main/java/org/openslx/imagemaster/server/ApiServer.java
+++ b/src/main/java/org/openslx/imagemaster/server/ApiServer.java
@@ -1,10 +1,16 @@
package org.openslx.imagemaster.server;
import java.nio.ByteBuffer;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.InvalidKeySpecException;
import java.util.ArrayList;
import java.util.List;
+import org.apache.log4j.Logger;
+import org.openslx.encryption.AsymKeyHolder;
import org.openslx.imagemaster.db.DbImage;
+import org.openslx.imagemaster.db.DbPendingSatellite;
import org.openslx.imagemaster.db.DbSatellite;
import org.openslx.imagemaster.db.DbUser;
import org.openslx.imagemaster.serverconnection.ImageProcessor;
@@ -31,6 +37,7 @@ import org.openslx.imagemaster.thrift.iface.SessionData;
import org.openslx.imagemaster.thrift.iface.UploadData;
import org.openslx.imagemaster.thrift.iface.UploadException;
import org.openslx.imagemaster.thrift.iface.UserInfo;
+import org.openslx.imagemaster.util.Util;
/**
* API Server This is where all the requests from the outside arrive. We don't
@@ -46,6 +53,8 @@ import org.openslx.imagemaster.thrift.iface.UserInfo;
public class ApiServer
{
+ private static final Logger LOG = Logger.getLogger( ApiServer.class );
+
/**
* Request for authentication
*
@@ -167,10 +176,10 @@ public class ApiServer
public static boolean publishUser( String serverSessionId, UserInfo user ) throws AuthorizationException
{
// Check session.
- if (SessionManager.getSessionFromSessionId( serverSessionId ) == null) {
+ if ( SessionManager.getSessionFromSessionId( serverSessionId ) == null ) {
throw new AuthorizationException( AuthorizationError.NOT_AUTHENTICATED, "Session ID not valid" );
}
- if (DbUser.forLogin( user.userId ) == null) {
+ if ( DbUser.forLogin( user.userId ) == null ) {
// User not known by server. Insert into server database.
return DbUser.insertOrUpdate( user );
}
@@ -200,4 +209,28 @@ public class ApiServer
throw new AuthorizationException( AuthorizationError.NOT_AUTHENTICATED, "Session ID not valid" );
return DbImage.asImageDataList( page * 100, ( page + 1 ) * 100 );
}
+
+ public static boolean registerSatellite( String organizationId, String address, String modulus, String exponent )
+ {
+ if ( organizationId == null || address == null || exponent == null || modulus == null )
+ return false;
+ Key newKey;
+ try {
+ newKey = new AsymKeyHolder( null, Util.tryToParseBigInt( exponent ), Util.tryToParseBigInt( modulus ) ).getPublicKey();
+ } catch ( NoSuchAlgorithmException | InvalidKeySpecException e ) {
+ LOG.warn( "Invalid public key in registerOrganization for " + organizationId + " (" + address + ")", e );
+ return false;
+ }
+ if ( newKey == null ) {
+ LOG.warn( "Uninstantiable public key in registerOrganization for " + organizationId + " (" + address + ")" );
+ return false;
+ }
+ DbSatellite existing = DbSatellite.fromSuffix( organizationId );
+ if ( existing != null ) {
+ Key existingKey = existing.getPubkey();
+ if ( existingKey != null && Util.keysEqual( newKey, existingKey ) )
+ return true;
+ }
+ return DbPendingSatellite.add( organizationId, address, modulus, exponent );
+ }
}