Package com.sshtools.j2ssh.io

Examples of com.sshtools.j2ssh.io.ByteArrayWriter


            log.debug("Width=" + String.valueOf(width));
            log.debug("Height=" + String.valueOf(height));
        }

        // This requests a pseudo terminal
        ByteArrayWriter baw = new ByteArrayWriter();
        baw.writeString(term);
        baw.writeInt(cols);
        baw.writeInt(rows);
        baw.writeInt(width);
        baw.writeInt(height);
        baw.writeString(terminalModes);

        return connection.sendChannelRequest(this, "pty-req", true,
            baw.toByteArray());
    }
View Full Code Here


        authentication.registerMessage(SshMsgUserAuthInfoRequest.class,
            SshMsgUserAuthInfoRequest.SSH_MSG_USERAUTH_INFO_REQUEST);

        // Send the authentication request
        ByteArrayWriter baw = new ByteArrayWriter();
        baw.writeString("");
        baw.writeString("");

        SshMessage msg = new SshMsgUserAuthRequest(getUsername(),
                serviceToStart, getMethodName(), baw.toByteArray());
        authentication.sendMessage(msg);

        // Read a message
        while (true) {
            msg = authentication.readMessage(SshMsgUserAuthInfoRequest.SSH_MSG_USERAUTH_INFO_REQUEST);
View Full Code Here

     * @throws IOException
     */
    public boolean startSubsystem(String subsystem) throws IOException {
        log.info("Starting " + subsystem + " subsystem");

        ByteArrayWriter baw = new ByteArrayWriter();
        baw.writeString(subsystem);

        if (connection.sendChannelRequest(this, "subsystem", true,
                    baw.toByteArray())) {
            if (sessionType.equals("Uninitialized")) {
                sessionType = subsystem;
            }

            return true;
View Full Code Here

     * @return
     *
     * @throws IOException
     */
    public byte[] toByteArray() throws IOException {
        ByteArrayWriter baw = new ByteArrayWriter();
        baw.write(SSH_AGENT_CONSTRAINT_TIMEOUT);
        baw.writeUINT32(timeout);
        baw.write(SSH_AGENT_CONSTRAINT_USE_LIMIT);
        baw.writeUINT32(uselimit);
        baw.write(SSH_AGENT_CONSTRAINT_FORWARDING_STEPS);
        baw.writeUINT32(maxsteps);
        baw.write(SSH_AGENT_CONSTRAINT_FORWARDING_PATH);
        baw.writeString(forwardingpath);
        baw.write(SSH_AGENT_CONSTRAINT_SSH1_COMPAT);
        baw.write(compat ? 0 : 1);
        baw.write(SSH_AGENT_CONSTRAINT_NEED_USER_VERIFICATION);
        baw.write(userverify ? 0 : 1);

        return baw.toByteArray();
    }
View Full Code Here

            byte[] payload = pem.decryptPayload(passphrase);
            SimpleASNReader asn = new SimpleASNReader(payload);

            if (PEM.DSA_PRIVATE_KEY.equals(pem.getType())) {
                DSAKeyInfo keyInfo = DSAKeyInfo.getDSAKeyInfo(asn);
                ByteArrayWriter baw = new ByteArrayWriter();
                baw.writeString("ssh-dss");
                baw.writeBigInteger(keyInfo.getP());
                baw.writeBigInteger(keyInfo.getQ());
                baw.writeBigInteger(keyInfo.getG());
                baw.writeBigInteger(keyInfo.getX());

                return baw.toByteArray();
            } else if (PEM.RSA_PRIVATE_KEY.equals(pem.getType())) {
                RSAKeyInfo keyInfo = RSAKeyInfo.getRSAKeyInfo(asn);
                ByteArrayWriter baw = new ByteArrayWriter();
                baw.writeString("ssh-rsa");
                baw.writeBigInteger(keyInfo.getPublicExponent());
                baw.writeBigInteger(keyInfo.getModulus());
                baw.writeBigInteger(keyInfo.getPrivateExponent());

                return baw.toByteArray();
            } else {
                throw new InvalidSshKeyException("Unsupported type: " +
                    pem.getType());
            }
        } catch (GeneralSecurityException e) {
View Full Code Here

        authentication.registerMessage(SshMsgUserAuthPKOK.class,
            SshMsgUserAuthPKOK.SSH_MSG_USERAUTH_PK_OK);
        log.info(
            "Determining if server can accept public key for authentication");

        ByteArrayWriter baw = new ByteArrayWriter();

        // Now prepare and send the message
        baw.write(0);
        baw.writeString(key.getAlgorithmName());
        baw.writeBinaryString(key.getEncoded());

        SshMessage msg = new SshMsgUserAuthRequest(username, serviceToStart,
                getMethodName(), baw.toByteArray());
        authentication.sendMessage(msg);

        try {
            msg = authentication.readMessage(SshMsgUserAuthPKOK.SSH_MSG_USERAUTH_PK_OK);
View Full Code Here

        if ((getUsername() == null) || (key == null)) {
            throw new AuthenticationProtocolException(
                "You must supply a username and a key");
        }

        ByteArrayWriter baw = new ByteArrayWriter();
        log.info("Generating data to sign");

        SshPublicKey pub = key.getPublicKey();
        log.info("Preparing public key authentication request");

        // Now prepare and send the message
        baw.write(1);
        baw.writeString(pub.getAlgorithmName());
        baw.writeBinaryString(pub.getEncoded());

        // Create the signature data
        ByteArrayWriter data = new ByteArrayWriter();
        data.writeBinaryString(authentication.getSessionIdentifier());
        data.write(SshMsgUserAuthRequest.SSH_MSG_USERAUTH_REQUEST);
        data.writeString(getUsername());
        data.writeString(serviceToStart);
        data.writeString(getMethodName());
        data.write(1);
        data.writeString(pub.getAlgorithmName());
        data.writeBinaryString(pub.getEncoded());

        // Generate the signature
        baw.writeBinaryString(key.generateSignature(data.toByteArray()));

        SshMsgUserAuthRequest msg = new SshMsgUserAuthRequest(getUsername(),
                serviceToStart, getMethodName(), baw.toByteArray());
        authentication.sendMessage(msg);
    }
View Full Code Here

        authentication.registerMessage(SshMsgUserAuthPwdChangeReq.class,
            SshMsgUserAuthPwdChangeReq.SSH_MSG_USERAUTH_PWD_CHANGEREQ);

        // Send a password authentication request
        ByteArrayWriter baw = new ByteArrayWriter();
        baw.write(0);
        baw.writeString(password);

        SshMsgUserAuthRequest msg = new SshMsgUserAuthRequest(getUsername(),
                serviceToStart, "password", baw.toByteArray());
        authentication.sendMessage(msg);

        SshMsgUserAuthPwdChangeReq pwd = (SshMsgUserAuthPwdChangeReq) authentication.readMessage(SshMsgUserAuthPwdChangeReq.SSH_MSG_USERAUTH_PWD_CHANGEREQ);

        if (changePrompt != null) {
            String newpassword = changePrompt.changePassword(pwd.getPrompt());

            if (newpassword != null) {
                log.debug("Setting new password");
                baw = new ByteArrayWriter();
                baw.write(1);
                baw.writeString(password);
                baw.writeString(newpassword);
                msg = new SshMsgUserAuthRequest(getUsername(), serviceToStart,
                        "password", baw.toByteArray());
                authentication.sendMessage(msg);
            } else {
                throw new TerminatedStateException(AuthenticationProtocolState.FAILED);
            }
        } else {
View Full Code Here

        authentication.registerMessage(SshMsgUserAuthPKOK.class,
            SshMsgUserAuthPKOK.SSH_MSG_USERAUTH_PK_OK);
        log.info(
            "Determining if server can accept public key for authentication");

        ByteArrayWriter baw = new ByteArrayWriter();

        // Now prepare and send the message
        baw.write(0);
        baw.writeString(key.getAlgorithmName());
        baw.writeBinaryString(key.getEncoded());

        SshMessage msg = new SshMsgUserAuthRequest(username, serviceToStart,
                getMethodName(), baw.toByteArray());
        authentication.sendMessage(msg);

        try {
            msg = authentication.readMessage(SshMsgUserAuthPKOK.SSH_MSG_USERAUTH_PK_OK);
View Full Code Here

            log.info("Agent authentication with key " + key.getFingerprint() +
                " [" + description + "] is " +
                (acceptable ? " acceptable" : " not acceptable"));

            if (acceptable) {
                ByteArrayWriter baw = new ByteArrayWriter();
                log.info("Generating data to sign");
                log.info("Preparing public key authentication request");

                // Now prepare and send the message
                baw.write(1);
                baw.writeString(key.getAlgorithmName());
                baw.writeBinaryString(key.getEncoded());

                // Create the signature data
                ByteArrayWriter data = new ByteArrayWriter();
                data.writeBinaryString(authentication.getSessionIdentifier());
                data.write(SshMsgUserAuthRequest.SSH_MSG_USERAUTH_REQUEST);
                data.writeString(getUsername());
                data.writeString(serviceToStart);
                data.writeString(getMethodName());
                data.write(1);
                data.writeString(key.getAlgorithmName());
                data.writeBinaryString(key.getEncoded());

                // Generate the signature
                baw.writeBinaryString(agent.hashAndSign(key, data.toByteArray()));

                SshMsgUserAuthRequest msg = new SshMsgUserAuthRequest(getUsername(),
                        serviceToStart, getMethodName(), baw.toByteArray());
                authentication.sendMessage(msg);
View Full Code Here

TOP

Related Classes of com.sshtools.j2ssh.io.ByteArrayWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.