use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class ScramSha1SaslServer method generateServerFinalMessage.
/**
* Final response returns the server signature.
*/
private byte[] generateServerFinalMessage(final byte[] response) throws SaslException {
String clientFinalMessage = new String(response, StandardCharsets.UTF_8);
Matcher m = CLIENT_FINAL_MESSAGE.matcher(clientFinalMessage);
if (!m.matches()) {
throw new SaslException("Invalid client final message");
}
String clientFinalMessageWithoutProof = m.group(1);
// String channelBinding = m.group(2);
String clientNonce = m.group(3);
String proof = m.group(4);
if (!nonce.equals(clientNonce)) {
throw new SaslException("Client final message has incorrect nonce value");
}
try {
String authMessage = clientFirstMessageBare + "," + serverFirstMessage + "," + clientFinalMessageWithoutProof;
byte[] storedKey = getStoredKey(username);
if (storedKey == null) {
throw new SaslException("No stored key for user '" + username + "'");
}
byte[] serverKey = getServerKey(username);
if (serverKey == null) {
throw new SaslException("No server key for user '" + username + "'");
}
byte[] clientSignature = ScramUtils.computeHmac(storedKey, authMessage);
byte[] serverSignature = ScramUtils.computeHmac(serverKey, authMessage);
byte[] clientKey = clientSignature.clone();
byte[] decodedProof = DatatypeConverter.parseBase64Binary(proof);
for (int i = 0; i < clientKey.length; i++) {
clientKey[i] ^= decodedProof[i];
}
if (!Arrays.equals(storedKey, MessageDigest.getInstance("SHA-1").digest(clientKey))) {
throw new SaslException("Authentication failed");
}
return ("v=" + DatatypeConverter.printBase64Binary(serverSignature)).getBytes(StandardCharsets.UTF_8);
} catch (UserNotFoundException | NoSuchAlgorithmException e) {
throw new SaslException(e.getMessage(), e);
}
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class ScramSha1SaslServer method generateServerFirstMessage.
/**
* First response returns:
* - the nonce (client nonce appended with our own random UUID)
* - the salt
* - the number of iterations
*/
private byte[] generateServerFirstMessage(final byte[] response) throws SaslException {
String clientFirstMessage = new String(response, StandardCharsets.UTF_8);
Matcher m = CLIENT_FIRST_MESSAGE.matcher(clientFirstMessage);
if (!m.matches()) {
throw new SaslException("Invalid first client message");
}
// String gs2Header = m.group(1);
// String gs2CbindFlag = m.group(2);
// String gs2CbindName = m.group(3);
// String authzId = m.group(4);
clientFirstMessageBare = m.group(5);
username = m.group(6);
String clientNonce = m.group(7);
nonce = clientNonce + UUID.randomUUID().toString();
try {
serverFirstMessage = String.format("r=%s,s=%s,i=%d", nonce, DatatypeConverter.printBase64Binary(getSalt(username)), getIterations(username));
} catch (UserNotFoundException e) {
throw new SaslException(e.getMessage(), e);
}
return serverFirstMessage.getBytes(StandardCharsets.UTF_8);
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class Roster method deleteSharedUser.
void deleteSharedUser(JID deletedUser, Group deletedGroup) {
try {
// Get the RosterItem for the *local* user to remove
RosterItem item = getRosterItem(deletedUser);
int groupSize = item.getSharedGroups().size() + item.getInvisibleSharedGroups().size();
if (item.isOnlyShared() && groupSize == 1 && // subcription status will change
!(deletedGroup.isUser(deletedUser) && RosterManager.isPublicSharedGroup(deletedGroup))) {
// Delete the roster item from the roster since it exists only because of this
// group which is being removed
deleteRosterItem(deletedUser, false);
} else {
// public group
if (!(deletedGroup.isUser(deletedUser) && RosterManager.isPublicSharedGroup(deletedGroup))) {
item.removeSharedGroup(deletedGroup);
}
// Get the groups of the deleted user
Collection<Group> groups = GroupManager.getInstance().getGroups(deletedUser);
// Remove all invalid shared groups from the roster item
for (Group group : groups) {
if (!rosterManager.isGroupVisible(group, getUserJID())) {
// Remove the shared group from the list of shared groups
item.removeSharedGroup(group);
}
}
// Update the subscription of the item **based on the item groups**
if (item.isOnlyShared()) {
Collection<Group> userGroups = GroupManager.getInstance().getGroups(getUserJID());
// that is mutually visible with a shared group of the new roster item
if (rosterManager.hasMutualVisibility(getUsername(), userGroups, deletedUser, groups)) {
item.setSubStatus(RosterItem.SUB_BOTH);
} else {
// Assume by default that the contact has subscribed from the presence of
// this user
item.setSubStatus(RosterItem.SUB_FROM);
// Check if the user may see the new contact in a shared group
for (Group group : groups) {
if (rosterManager.isGroupVisible(group, getUserJID())) {
item.setSubStatus(RosterItem.SUB_TO);
}
}
}
// Fire event indicating that a roster item has been updated
RosterEventDispatcher.contactUpdated(this, item);
} else {
// Fire event indicating that a roster item has been removed
RosterEventDispatcher.contactDeleted(this, item);
}
// Brodcast to all the user resources of the updated roster item
broadcast(item, false);
}
} catch (SharedGroupException e) {
// Do nothing. Checkings are disabled so this exception should never happen.
} catch (UserNotFoundException e) {
// Do nothing since the contact does not exist in the user's roster. (strange case!)
}
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class Roster method shareGroupRenamed.
/**
* A shared group of the user has been renamed. Update the existing roster items with the new
* name of the shared group and make a roster push for all the available resources.
*
* @param users group users of the renamed group.
*/
void shareGroupRenamed(Collection<JID> users) {
JID userJID = getUserJID();
for (JID user : users) {
if (userJID.equals(user)) {
continue;
}
RosterItem item;
try {
// Get the RosterItem for the *local* user to add
item = getRosterItem(user);
// Brodcast to all the user resources of the updated roster item
broadcast(item, true);
} catch (UserNotFoundException e) {
// Do nothing since the contact does not exist in the user's roster. (strange case!)
}
}
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class PresenceManagerImpl method handleProbe.
@Override
public void handleProbe(Presence packet) throws UnauthorizedException {
String username = packet.getTo().getNode();
try {
Roster roster = rosterManager.getRoster(username);
RosterItem item = roster.getRosterItem(packet.getFrom());
if (item.getSubStatus() == RosterItem.SUB_FROM || item.getSubStatus() == RosterItem.SUB_BOTH) {
probePresence(packet.getFrom(), packet.getTo());
} else {
PacketError.Condition error = PacketError.Condition.not_authorized;
if ((item.getSubStatus() == RosterItem.SUB_NONE && item.getRecvStatus() != RosterItem.RECV_SUBSCRIBE) || (item.getSubStatus() == RosterItem.SUB_TO && item.getRecvStatus() != RosterItem.RECV_SUBSCRIBE)) {
error = PacketError.Condition.forbidden;
}
Presence presenceToSend = new Presence();
presenceToSend.setError(error);
presenceToSend.setTo(packet.getFrom());
presenceToSend.setFrom(packet.getTo());
deliverer.deliver(presenceToSend);
}
} catch (UserNotFoundException e) {
Presence presenceToSend = new Presence();
presenceToSend.setError(PacketError.Condition.forbidden);
presenceToSend.setTo(packet.getFrom());
presenceToSend.setFrom(packet.getTo());
deliverer.deliver(presenceToSend);
}
}
Aggregations