use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.AccountInfo 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());
}
}
use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.AccountInfo in project GNS by MobilityFirst.
the class RemoveAlias 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 name = json.getString(GNSProtocol.NAME.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;
if (AccountAccess.lookupGuidInfoAnywhere(header, guid, handler) == null) {
return new CommandResponse(ResponseCode.BAD_GUID_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_GUID.toString() + " " + guid);
}
AccountInfo accountInfo = AccountAccess.lookupAccountInfoFromGuidAnywhere(header, guid, handler);
if (accountInfo == null) {
return new CommandResponse(ResponseCode.BAD_ACCOUNT_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_ACCOUNT.toString() + " " + guid);
} else if (!accountInfo.isVerified()) {
return new CommandResponse(ResponseCode.VERIFICATION_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.VERIFICATION_ERROR.toString() + " Account not verified");
}
return AccountAccess.removeAlias(header, commandPacket, accountInfo, name, guid, signature, message, timestamp, handler);
}
use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.AccountInfo in project GNS by MobilityFirst.
the class AddAlias method execute.
@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, ParseException {
JSONObject json = commandPacket.getCommand();
// The guid of the account we are adding the alias to
String guid = json.getString(GNSProtocol.GUID.toString());
// The HRN (alias) we are adding to this account guid
String name = json.getString(GNSProtocol.NAME.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;
// Fixme: Does this really need remote access?
AccountInfo accountInfo = AccountAccess.lookupAccountInfoFromGuidAnywhere(header, guid, handler);
if (accountInfo == null) {
return new CommandResponse(ResponseCode.BAD_ACCOUNT_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_ACCOUNT.toString() + " " + guid);
}
if (!accountInfo.isVerified()) {
return new CommandResponse(ResponseCode.VERIFICATION_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.VERIFICATION_ERROR.toString() + " Account not verified");
} else if (accountInfo.getAliases().size() > Config.getGlobalInt(GNSConfig.GNSC.ACCOUNT_GUID_MAX_ALIASES)) {
return new CommandResponse(ResponseCode.TOO_MANY_ALIASES_EXCEPTION, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.TOO_MANY_ALIASES.toString());
} else {
return AccountAccess.addAlias(header, commandPacket, accountInfo, name, guid, signature, message, timestamp, handler);
}
}
use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.AccountInfo in project GNS by MobilityFirst.
the class AddGuid method execute.
@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, UnsupportedEncodingException {
JSONObject json = commandPacket.getCommand();
String name = json.getString(GNSProtocol.NAME.toString());
String accountGuid = json.getString(GNSProtocol.GUID.toString());
String publicKey = json.optString(GNSProtocol.PUBLIC_KEY.toString(), null);
String signature = json.getString(GNSProtocol.SIGNATURE.toString());
String message = json.getString(GNSProtocol.SIGNATUREFULLMESSAGE.toString());
String newGuid;
if (publicKey != null) {
newGuid = SharedGuidUtils.createGuidStringFromBase64PublicKey(publicKey);
} else {
// add a fake public key
publicKey = GuidInfo.KEYLESS_PREFIX + name;
newGuid = SharedGuidUtils.createGuidStringFromPublicKey(publicKey.getBytes());
}
GuidInfo accountGuidInfo;
if ((accountGuidInfo = AccountAccess.lookupGuidInfoAnywhere(header, accountGuid, handler)) == null) {
return new CommandResponse(ResponseCode.BAD_GUID_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_GUID.toString() + " " + accountGuid);
}
if (NSAccessSupport.verifySignature(accountGuidInfo.getPublicKey(), signature, message)) {
AccountInfo accountInfo = AccountAccess.lookupAccountInfoFromGuidAnywhere(header, accountGuid, handler);
if (accountInfo == null) {
return new CommandResponse(ResponseCode.BAD_ACCOUNT_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_ACCOUNT.toString() + " " + accountGuid);
}
if (!accountInfo.isVerified()) {
return new CommandResponse(ResponseCode.VERIFICATION_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.VERIFICATION_ERROR.toString() + " Account not verified");
} else if (accountInfo.getGuids().size() > Config.getGlobalInt(GNSConfig.GNSC.ACCOUNT_GUID_MAX_SUBGUIDS)) {
return new CommandResponse(ResponseCode.TOO_MANY_GUIDS_EXCEPTION, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.TOO_MANY_GUIDS.toString());
} else {
CommandResponse result = AccountAccess.addGuid(header, commandPacket, accountInfo, accountGuidInfo, name, newGuid, publicKey, handler);
if (result.getExceptionOrErrorCode().isOKResult()) {
// Everything is hunkey dorey so return the new guid
return new CommandResponse(ResponseCode.NO_ERROR, newGuid);
} else {
// Otherwise return the error response
return result;
}
}
} else {
// Signature verification failed
return new CommandResponse(ResponseCode.SIGNATURE_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_SIGNATURE.toString());
}
//}
}
use of edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.AccountInfo in project GNS by MobilityFirst.
the class AddMultipleGuids method execute.
@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, UnsupportedEncodingException {
JSONObject json = commandPacket.getCommand();
String guid = json.getString(GNSProtocol.GUID.toString());
String guidCntString = json.optString(GNSProtocol.GUIDCNT.toString());
JSONArray names = json.optJSONArray(GNSProtocol.NAMES.toString());
JSONArray publicKeys = json.optJSONArray(GNSProtocol.PUBLIC_KEYS.toString());
String signature = json.getString(GNSProtocol.SIGNATURE.toString());
String message = json.getString(GNSProtocol.SIGNATUREFULLMESSAGE.toString());
GuidInfo accountGuidInfo;
if ((accountGuidInfo = AccountAccess.lookupGuidInfoAnywhere(header, guid, handler)) == null) {
return new CommandResponse(ResponseCode.BAD_GUID_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_GUID.toString() + " " + guid);
}
if (NSAccessSupport.verifySignature(accountGuidInfo.getPublicKey(), signature, message)) {
AccountInfo accountInfo = AccountAccess.lookupAccountInfoFromGuidAnywhere(header, guid, handler);
if (accountInfo == null) {
return new CommandResponse(ResponseCode.BAD_ACCOUNT_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_ACCOUNT.toString() + " " + guid);
}
if (!accountInfo.isVerified()) {
return new CommandResponse(ResponseCode.VERIFICATION_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.VERIFICATION_ERROR.toString() + " Account not verified");
} else if (accountInfo.getGuids().size() > Config.getGlobalInt(GNSConfig.GNSC.ACCOUNT_GUID_MAX_SUBGUIDS)) {
return new CommandResponse(ResponseCode.TOO_MANY_GUIDS_EXCEPTION, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.TOO_MANY_GUIDS.toString());
} else if (names != null && publicKeys != null) {
GNSConfig.getLogger().log(Level.INFO, "ADD SLOW{0} / {1}", new Object[] { names, publicKeys });
return AccountAccess.addMultipleGuids(header, commandPacket, JSONUtils.JSONArrayToArrayListString(names), JSONUtils.JSONArrayToArrayListString(publicKeys), accountInfo, accountGuidInfo, handler);
} else if (names != null) {
//GNS.getLogger().info("ADD FASTER" + names + " / " + publicKeys);
return AccountAccess.addMultipleGuidsFaster(header, commandPacket, JSONUtils.JSONArrayToArrayListString(names), accountInfo, accountGuidInfo, handler);
} else if (guidCntString != null) {
//GNS.getLogger().info("ADD RANDOM" + names + " / " + publicKeys);
int guidCnt = Integer.parseInt(guidCntString);
return AccountAccess.addMultipleGuidsFasterAllRandom(header, commandPacket, guidCnt, accountInfo, accountGuidInfo, handler);
} else {
return new CommandResponse(ResponseCode.UNSPECIFIED_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.UNSPECIFIED_ERROR.toString() + " bad arguments: need " + GNSProtocol.NAMES.toString() + " or " + GNSProtocol.NAMES.toString() + " and " + GNSProtocol.PUBLIC_KEYS.toString() + " or " + GNSProtocol.GUIDCNT.toString());
}
} else {
return new CommandResponse(ResponseCode.SIGNATURE_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.BAD_SIGNATURE.toString());
}
//}
}
Aggregations