Examples of SSHPacket


Examples of com.davfx.ninio.ssh.SshPacket

  public PublicKeyLoader(File file) throws IOException, GeneralSecurityException {
    try (BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8))) {
      List<String> l = Splitter.on(' ').splitToList(r.readLine());
      String publicKeyAlgorithm = l.get(0);
      byte[] b = BaseEncoding.base64().decode(l.get(1));
      SshPacket k = new SshPacket(ByteBuffer.wrap(b));
      String s = k.readString();
      if (!s.equals(publicKeyAlgorithm)) {
        throw new IOException("Invalid algorithm: " + s);
      }
      if (publicKeyAlgorithm.equals("ssh-rsa")) {
        byte[] e = k.readBlob();
        byte[] n = k.readBlob();
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        publicKey = new RsaSshPublicKey((RSAPublicKey) keyFactory.generatePublic(new RSAPublicKeySpec(new BigInteger(n), new BigInteger(e))));
      } else if (publicKeyAlgorithm.equals("ssh-dss")) {
        byte[] p = k.readBlob();
        byte[] q = k.readBlob();
        byte[] g = k.readBlob();
        byte[] y = k.readBlob();

        KeyFactory keyFactory = KeyFactory.getInstance("DSA");
        publicKey = new DssSshPublicKey((DSAPublicKey) keyFactory.generatePublic(new DSAPublicKeySpec(new BigInteger(y), new BigInteger(p), new BigInteger(q), new BigInteger(g))));
      } else {
        throw new IOException("Unknown algorithm: " + publicKeyAlgorithm);
View Full Code Here

Examples of net.schmizz.sshj.common.SSHPacket

    public Promise<SSHPacket, ConnectionException> sendGlobalRequest(String name, boolean wantReply,
                                                                     byte[] specifics)
            throws TransportException {
        synchronized (globalReqPromises) {
            log.info("Making global request for `{}`", name);
            trans.write(new SSHPacket(Message.GLOBAL_REQUEST).putString(name)
                                                             .putBoolean(wantReply)
                                                             .putRawBytes(specifics));

            Promise<SSHPacket, ConnectionException> promise = null;
            if (wantReply) {
View Full Code Here

Examples of net.schmizz.sshj.common.SSHPacket

    }

    @Override
    public void sendOpenFailure(int recipient, Reason reason, String message)
            throws TransportException {
        trans.write(new SSHPacket(Message.CHANNEL_OPEN_FAILURE)
                            .putUInt32(recipient)
                            .putUInt32(reason.getCode())
                            .putString(message));
    }
View Full Code Here

Examples of net.schmizz.sshj.common.SSHPacket

     * @throws TransportException if there is an error while sending the request
     */
    private void sendServiceRequest(String serviceName)
            throws TransportException {
        log.debug("Sending SSH_MSG_SERVICE_REQUEST for {}", serviceName);
        write(new SSHPacket(Message.SERVICE_REQUEST).putString(serviceName));
    }
View Full Code Here

Examples of net.schmizz.sshj.common.SSHPacket

    @Override
    public long sendUnimplemented()
            throws TransportException {
        final long seq = decoder.getSequenceNumber();
        log.info("Sending SSH_MSG_UNIMPLEMENTED for packet #{}", seq);
        return write(new SSHPacket(Message.UNIMPLEMENTED).putUInt32(seq));
    }
View Full Code Here

Examples of net.schmizz.sshj.common.SSHPacket

    private void sendDisconnect(DisconnectReason reason, String message) {
        if (message == null)
            message = "";
        log.debug("Sending SSH_MSG_DISCONNECT: reason=[{}], msg=[{}]", reason, message);
        try {
            write(new SSHPacket(Message.DISCONNECT)
                          .putUInt32(reason.toInt())
                          .putString(message)
                          .putString(""));
        } catch (IOException worthless) {
            log.debug("Error writing packet: {}", worthless.toString());
View Full Code Here

Examples of net.schmizz.sshj.common.SSHPacket

                        checkMAC(inputBuffer.array());

                    // Exclude the padding & MAC
                    inputBuffer.wpos(packetLength + 4 - inputBuffer.readByte());

                    final SSHPacket plain = usingCompression() ? decompressed() : inputBuffer;

                    if (log.isTraceEnabled())
                        log.trace("Received packet #{}: {}", seq, plain.printHex());

                    packetHandler.handle(plain.readMessageID(), plain); // Process the decoded packet

                    inputBuffer.clear();
                    packetLength = -1;

                } else
View Full Code Here

Examples of net.schmizz.sshj.common.SSHPacket

     * @throws ConnectionException if there is an error requesting the forwarding
     * @throws TransportException
     */
    public Forward bind(Forward forward, ConnectListener listener)
            throws ConnectionException, TransportException {
        SSHPacket reply = req(PF_REQ, forward);
        if (forward.port == 0)
            try {
                forward.port = reply.readUInt32AsInt();
            } catch (Buffer.BufferException e) {
                throw new ConnectionException(e);
            }
        log.info("Remote end listening on {}", forward);
        listeners.put(forward, listener);
View Full Code Here

Examples of net.schmizz.sshj.common.SSHPacket

            throws TransportException {
        synchronized (win) {
            final int adjustment = win.neededAdjustment();
            if (adjustment > 0) {
                log.info("Sending SSH_MSG_CHANNEL_WINDOW_ADJUST to #{} for {} bytes", chan.getRecipient(), adjustment);
                trans.write(new SSHPacket(Message.CHANNEL_WINDOW_ADJUST)
                                    .putUInt32(chan.getRecipient()).putUInt32(adjustment));
                win.expand(adjustment);
            }
        }
    }
View Full Code Here

Examples of net.schmizz.sshj.common.SSHPacket

    }

    private void sendNewKeys()
            throws TransportException {
        log.info("Sending SSH_MSG_NEWKEYS");
        transport.write(new SSHPacket(Message.NEWKEYS));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.