All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.sshd.common.session.SessionContext Maven / Gradle / Ivy

There is a newer version: 2.14.0
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.sshd.common.session;

import java.util.Map;

import org.apache.sshd.common.AttributeStore;
import org.apache.sshd.common.auth.UsernameHolder;
import org.apache.sshd.common.kex.KexProposalOption;
import org.apache.sshd.common.kex.KexState;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.net.ConnectionEndpointsIndicator;

/**
 * A "succinct" summary of the most important attributes of an SSH session
 *
 * @author Apache MINA SSHD Project
 */
public interface SessionContext
        extends ConnectionEndpointsIndicator,
                UsernameHolder,
                SessionHeartbeatController,
                AttributeStore {
    /**
     * Default prefix expected for the client / server identification string
     * @see RFC 4253 - section 4.2
     */
    String DEFAULT_SSH_VERSION_PREFIX = "SSH-2.0-";

    /**
     * Backward compatible special prefix
     * @see RFC 4253 - section 5
     */
    String FALLBACK_SSH_VERSION_PREFIX = "SSH-1.99-";

    /**
     * Maximum number of characters for any single line sent as part
     * of the initial handshake - according to
     * RFC 4253 - section 4.2:
* *

* The maximum length of the string is 255 characters, * including the Carriage Return and Line Feed. *

*/ int MAX_VERSION_LINE_LENGTH = 256; /** * @return A clone of the established session identifier - {@code null} if * not yet established */ byte[] getSessionId(); /** * Retrieve the client version for this session. * * @return the client version - may be {@code null}/empty if versions not yet exchanged */ String getClientVersion(); /** * @return An un-modifiable map of the latest KEX client proposal options * May be empty if KEX not yet completed or re-keying in progress * @see #getKexState() */ Map getClientKexProposals(); /** * Retrieve the server version for this session. * * @return the server version - may be {@code null}/empty if versions not yet exchanged */ String getServerVersion(); /** * @return An un-modifiable map of the latest KEX client proposal options. * May be empty if KEX not yet completed or re-keying in progress * @see #getKexState() */ Map getServerKexProposals(); KexState getKexState(); Map getKexNegotiationResult(); /** * Retrieve one of the negotiated values during the KEX stage * * @param paramType The request {@link KexProposalOption} value * - ignored if {@code null} * @return The negotiated parameter value - {@code null} if invalid * parameter or no negotiated value. * @see #getKexState() */ String getNegotiatedKexParameter(KexProposalOption paramType); /** * @return {@code true} if session has successfully completed the authentication phase */ boolean isAuthenticated(); /** * @param version The reported client/server version * @return {@code true} if version not empty and starts with either * {@value #DEFAULT_SSH_VERSION_PREFIX} or {@value #FALLBACK_SSH_VERSION_PREFIX} */ static boolean isValidVersionPrefix(String version) { return GenericUtils.isNotEmpty(version) && (version.startsWith(DEFAULT_SSH_VERSION_PREFIX) || version.startsWith(FALLBACK_SSH_VERSION_PREFIX)); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy