Search in sources :

Example 1 with GuidInfo

use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.GuidInfo in project GNS by MobilityFirst.

the class NSAuthentication method lookupPublicKeyLocallyWithCacheing.

/**
   * Look up a public key for the {@code guid} using a cache.
   *
   * @param guid
   * @param gnsApp
   * @return public key
   * @throws FailedDBOperationException
   */
public static String lookupPublicKeyLocallyWithCacheing(String guid, GNSApplicationInterface<String> gnsApp) throws FailedDBOperationException {
    String result;
    if ((result = PUBLIC_KEY_CACHE.getIfPresent(guid)) != null) {
        return result;
    }
    GuidInfo guidInfo;
    if ((guidInfo = AccountAccess.lookupGuidInfoLocally(null, guid, gnsApp.getRequestHandler())) == null) {
        ClientSupportConfig.getLogger().log(Level.FINE, "Name {0} : BAD_GUID_ERROR", new Object[] { guid });
        return null;
    } else {
        result = guidInfo.getPublicKey();
        PUBLIC_KEY_CACHE.put(guid, result);
        return result;
    }
}
Also used : GuidInfo(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.GuidInfo)

Example 2 with GuidInfo

use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.GuidInfo in project GNS by MobilityFirst.

the class AclAdd method execute.

@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, ParseException {
    JSONObject json = commandPacket.getCommand();
    String guid = json.getString(GNSProtocol.GUID.toString());
    String field = json.getString(GNSProtocol.FIELD.toString());
    // The guid that wants to access this field
    String accesser = json.getString(GNSProtocol.ACCESSER.toString());
    // allows someone other than guid to change the acl, defaults to guid
    String writer = json.optString(GNSProtocol.WRITER.toString(), guid);
    String accessType = json.getString(GNSProtocol.ACL_TYPE.toString());
    String signature = json.getString(GNSProtocol.SIGNATURE.toString());
    String message = json.getString(GNSProtocol.SIGNATUREFULLMESSAGE.toString());
    // can be null on older client
    Date timestamp = json.has(GNSProtocol.TIMESTAMP.toString()) ? Format.parseDateISO8601UTC(json.getString(GNSProtocol.TIMESTAMP.toString())) : null;
    MetaDataTypeName access;
    if ((access = MetaDataTypeName.valueOf(accessType)) == null) {
        return new CommandResponse(ResponseCode.BAD_ACL_TYPE_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_ACL_TYPE.toString() + "Should be one of " + Arrays.toString(MetaDataTypeName.values()));
    }
    // Lookup the public key of the guid that we're giving access to the field.
    String accessorPublicKey;
    if (GNSProtocol.EVERYONE.toString().equals(accesser)) {
        accessorPublicKey = GNSProtocol.EVERYONE.toString();
    } else {
        GuidInfo accessorGuidInfo;
        if ((accessorGuidInfo = AccountAccess.lookupGuidInfoAnywhere(header, accesser, handler)) == null) {
            return new CommandResponse(ResponseCode.BAD_GUID_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_GUID.toString() + " " + accesser);
        } else {
            accessorPublicKey = accessorGuidInfo.getPublicKey();
        }
    }
    // This is where we update the ACL. Put the public key of the accessing guid in the appropriate ACL list.
    ResponseCode responseCode;
    if (!(responseCode = FieldMetaData.add(header, commandPacket, access, guid, field, accessorPublicKey, writer, signature, message, timestamp, handler)).isExceptionOrError()) {
        return new CommandResponse(ResponseCode.NO_ERROR, GNSProtocol.OK_RESPONSE.toString());
    } else {
        return new CommandResponse(responseCode, responseCode.getProtocolCode());
    }
}
Also used : ResponseCode(edu.umass.cs.gnscommon.ResponseCode) JSONObject(org.json.JSONObject) GuidInfo(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.GuidInfo) CommandResponse(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse) Date(java.util.Date) MetaDataTypeName(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.MetaDataTypeName)

Example 3 with GuidInfo

use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.GuidInfo in project GNS by MobilityFirst.

the class AclRemove method execute.

@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, ParseException {
    JSONObject json = commandPacket.getCommand();
    String guid = json.getString(GNSProtocol.GUID.toString());
    String field = json.getString(GNSProtocol.FIELD.toString());
    // The guid that is losing access to this field
    String accesser = json.getString(GNSProtocol.ACCESSER.toString());
    // allows someone other than guid to change the acl, defaults to guid
    String writer = json.optString(GNSProtocol.WRITER.toString(), guid);
    String accessType = json.getString(GNSProtocol.ACL_TYPE.toString());
    String signature = json.getString(GNSProtocol.SIGNATURE.toString());
    String message = json.getString(GNSProtocol.SIGNATUREFULLMESSAGE.toString());
    Date timestamp = json.has(GNSProtocol.TIMESTAMP.toString()) ? Format.parseDateISO8601UTC(json.getString(GNSProtocol.TIMESTAMP.toString())) : // can be null on older client
    null;
    MetaDataTypeName access;
    if ((access = MetaDataTypeName.valueOf(accessType)) == null) {
        return new CommandResponse(ResponseCode.BAD_ACL_TYPE_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_ACL_TYPE.toString() + "Should be one of " + Arrays.toString(MetaDataTypeName.values()));
    }
    ResponseCode responseCode;
    // We need the public key
    String accessorPublicKey;
    if (GNSProtocol.EVERYONE.toString().equals(accesser)) {
        accessorPublicKey = GNSProtocol.EVERYONE.toString();
    } else {
        GuidInfo accessorGuidInfo;
        if ((accessorGuidInfo = AccountAccess.lookupGuidInfoAnywhere(header, accesser, handler)) == null) {
            return new CommandResponse(ResponseCode.BAD_GUID_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_GUID.toString() + " " + accesser);
        } else {
            accessorPublicKey = accessorGuidInfo.getPublicKey();
        }
    }
    if (!(responseCode = FieldMetaData.removeValue(header, commandPacket, access, guid, accesser, field, accessorPublicKey, writer, signature, message, timestamp, handler)).isExceptionOrError()) {
        return new CommandResponse(ResponseCode.NO_ERROR, GNSProtocol.OK_RESPONSE.toString());
    } else {
        return new CommandResponse(responseCode, responseCode.getProtocolCode());
    }
}
Also used : ResponseCode(edu.umass.cs.gnscommon.ResponseCode) JSONObject(org.json.JSONObject) GuidInfo(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.GuidInfo) CommandResponse(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse) Date(java.util.Date) MetaDataTypeName(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.MetaDataTypeName)

Example 4 with GuidInfo

use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.GuidInfo in project GNS by MobilityFirst.

the class ResendAuthenticationEmail method execute.

@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, ParseException, UnsupportedEncodingException {
    JSONObject json = commandPacket.getCommand();
    String guid = json.getString(GNSProtocol.GUID.toString());
    String signature = json.getString(GNSProtocol.SIGNATURE.toString());
    String message = json.getString(GNSProtocol.SIGNATUREFULLMESSAGE.toString());
    GuidInfo guidInfo;
    if ((guidInfo = AccountAccess.lookupGuidInfoLocally(header, guid, handler)) == null) {
        return new CommandResponse(ResponseCode.BAD_GUID_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_GUID.toString() + " " + guid);
    }
    if (!NSAccessSupport.verifySignature(guidInfo.getPublicKey(), signature, message)) {
        return new CommandResponse(ResponseCode.SIGNATURE_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_SIGNATURE.toString());
    }
    AccountInfo accountInfo;
    if ((accountInfo = AccountAccess.lookupAccountInfoFromGuidLocally(header, guid, handler)) == null) {
        return new CommandResponse(ResponseCode.BAD_ACCOUNT_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_ACCOUNT.toString() + " " + guid);
    } else {
        try {
            return AccountAccess.resendAuthenticationEmail(header, commandPacket, accountInfo, guid, signature, message, handler);
        } catch (UnknownHostException e) {
            return new CommandResponse(ResponseCode.UNSPECIFIED_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.UNSPECIFIED_ERROR.toString() + " " + e.getMessage());
        }
    }
}
Also used : JSONObject(org.json.JSONObject) UnknownHostException(java.net.UnknownHostException) GuidInfo(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.GuidInfo) CommandResponse(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse) AccountInfo(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.AccountInfo)

Example 5 with GuidInfo

use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.GuidInfo in project GNS by MobilityFirst.

the class RemoveAccount method execute.

@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, UnsupportedEncodingException, InternalRequestException {
    JSONObject json = commandPacket.getCommand();
    // The name of the account we are removing.
    String name = json.getString(GNSProtocol.NAME.toString());
    // The guid of the account we are removing.
    String guid = json.getString(GNSProtocol.GUID.toString());
    String signature = json.getString(GNSProtocol.SIGNATURE.toString());
    String message = json.getString(GNSProtocol.SIGNATUREFULLMESSAGE.toString());
    GuidInfo guidInfo;
    if ((guidInfo = AccountAccess.lookupGuidInfoLocally(header, guid, handler)) == null) {
        // Removing a non-existant guid is not longer an error.
        return new CommandResponse(ResponseCode.NO_ERROR, GNSProtocol.OK_RESPONSE.toString());
    //return new CommandResponse(ResponseCode.BAD_GUID_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_GUID.toString() + " " + guid);
    }
    if (NSAccessSupport.verifySignature(guidInfo.getPublicKey(), signature, message)) {
        AccountInfo accountInfo = AccountAccess.lookupAccountInfoFromNameAnywhere(header, name, handler);
        if (accountInfo != null) {
            return AccountAccess.removeAccount(header, commandPacket, accountInfo, handler);
        } else {
            return new CommandResponse(ResponseCode.BAD_ACCOUNT_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_ACCOUNT.toString());
        }
    } else {
        return new CommandResponse(ResponseCode.SIGNATURE_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_SIGNATURE.toString());
    }
}
Also used : JSONObject(org.json.JSONObject) GuidInfo(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.GuidInfo) CommandResponse(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse) AccountInfo(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.AccountInfo)

Aggregations

GuidInfo (edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.GuidInfo)15 JSONObject (org.json.JSONObject)13 CommandResponse (edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse)11 AccountInfo (edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.AccountInfo)6 ResponseCode (edu.umass.cs.gnscommon.ResponseCode)4 MetaDataTypeName (edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.MetaDataTypeName)4 Date (java.util.Date)4 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)2 FailedDBOperationException (edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException)1 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.server.FieldNotFoundException)1 AbstractRecordCursor (edu.umass.cs.gnsserver.database.AbstractRecordCursor)1 AdminRequestPacket (edu.umass.cs.gnsserver.gnsapp.packet.admin.AdminRequestPacket)1 DumpRequestPacket (edu.umass.cs.gnsserver.gnsapp.packet.admin.DumpRequestPacket)1 NameRecord (edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord)1 IOException (java.io.IOException)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 UnknownHostException (java.net.UnknownHostException)1 ParseException (java.text.ParseException)1