Search in sources :

Example 76 with UserNotFoundException

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);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Matcher(java.util.regex.Matcher) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SaslException(javax.security.sasl.SaslException)

Example 77 with UserNotFoundException

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);
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Matcher(java.util.regex.Matcher) SaslException(javax.security.sasl.SaslException)

Example 78 with UserNotFoundException

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!)
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Group(org.jivesoftware.openfire.group.Group) SharedGroupException(org.jivesoftware.openfire.SharedGroupException)

Example 79 with UserNotFoundException

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!)
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID)

Example 80 with UserNotFoundException

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);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Roster(org.jivesoftware.openfire.roster.Roster) PacketError(org.xmpp.packet.PacketError) Presence(org.xmpp.packet.Presence)

Aggregations

UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)118 JID (org.xmpp.packet.JID)50 Element (org.dom4j.Element)28 Roster (org.jivesoftware.openfire.roster.Roster)27 RosterItem (org.jivesoftware.openfire.roster.RosterItem)26 User (org.jivesoftware.openfire.user.User)25 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)23 IQ (org.xmpp.packet.IQ)15 ArrayList (java.util.ArrayList)14 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)12 SharedGroupException (org.jivesoftware.openfire.SharedGroupException)11 Group (org.jivesoftware.openfire.group.Group)10 UserManager (org.jivesoftware.openfire.user.UserManager)10 Workgroup (org.jivesoftware.xmpp.workgroup.Workgroup)10 Presence (org.xmpp.packet.Presence)10 NotFoundException (org.jivesoftware.util.NotFoundException)9 SQLException (java.sql.SQLException)8 List (java.util.List)8 IOException (java.io.IOException)7 Connection (java.sql.Connection)7