Package com.sshtools.j2ssh.transport.publickey

Examples of com.sshtools.j2ssh.transport.publickey.SshPublicKey


        try {
            baw.writeInt(keys.size());

            Map.Entry entry;
            Iterator it = keys.entrySet().iterator();
            SshPublicKey key;
            String description;

            while (it.hasNext()) {
                entry = (Map.Entry) it.next();
                key = (SshPublicKey) entry.getKey();
                description = (String) entry.getValue();
                baw.writeBinaryString(key.getEncoded());
                baw.writeString(description);
            }
        } catch (IOException ex) {
            throw new InvalidMessageException("Failed to write message data");
        }
View Full Code Here


    public void constructMessage(ByteArrayReader bar)
        throws java.io.IOException,
            com.sshtools.j2ssh.transport.InvalidMessageException {
        try {
            int num = (int) bar.readInt();
            SshPublicKey key;
            String description;
            byte[] buf;

            for (int i = 0; i < num; i++) {
                buf = bar.readBinaryString();
View Full Code Here

        // Iterate the agents keys, find an acceptable key and authenticate
        Map keys = agent.listKeys();
        Iterator it = keys.entrySet().iterator();
        boolean acceptable = false;
        SshPublicKey key = null;
        String description;
        Map.Entry entry;

        while (it.hasNext() && !acceptable) {
            entry = (Map.Entry) it.next();
            key = (SshPublicKey) entry.getKey();
            description = (String) entry.getValue();
            acceptable = acceptsKey(authentication, getUsername(),
                    serviceToStart, key);
            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(),
View Full Code Here

     * @return
     */
    public boolean hasAcceptableKey(SshClient ssh) {
        try {
            Map keys = agent.listKeys();
            SshPublicKey key;

            for (Iterator x = keys.keySet().iterator(); x.hasNext();) {
                key = (SshPublicKey) x.next();

                if (ssh.acceptsKey(getUsername(), key)) {
View Full Code Here

                        StringTokenizer tokens = new StringTokenizer(line, " ");
                        String host = (String) tokens.nextElement();
                        String algorithm = (String) tokens.nextElement();
                        String key = (String) tokens.nextElement();

                        SshPublicKey pk = SshKeyPairFactory.decodePublicKey(Base64.decode(
                            key));
                          /*if (host.indexOf(",") > -1) {
                           host = host.substring(0, host.indexOf(","));
                           }*/
                        putAllowedKey(host, pk);
View Full Code Here

    }

    private boolean validateHost(String names, SshPublicKey pk)
        throws TransportProtocolException {
        // The host is allowed so check the fingerprint
        SshPublicKey pub = getAllowedKey(names, pk.getAlgorithmName()); //shPublicKey) allowedHosts.get(host + "#" + pk.getAlgorithmName());

        if ((pub != null) && pk.equals(pub)) {
            return true;
        } else {
            // The host key does not match the recorded so call the abstract
View Full Code Here

            return checkKey(names, pk);
        }
    }

    private boolean checkKey(String host, SshPublicKey key) {
        SshPublicKey pk = getAllowedKey(host, key.getAlgorithmName()); //shPublicKey) allowedHosts.get(host + "#" + key.getAlgorithmName());

        if (pk != null) {
            if (pk.equals(key)) {
                return true;
            }
        }

        return false;
View Full Code Here

            Iterator it2 = ((Map) entry.getValue()).entrySet().iterator();

            while (it2.hasNext()) {
                entry2 = (Map.Entry) it2.next();

                SshPublicKey pk = (SshPublicKey) entry2.getValue();
                knownhosts += (entry.getKey().toString() + " " +
                pk.getAlgorithmName() + " " +
                Base64.encodeBytes(pk.getEncoded(), true) + "\n");
            }
        }

        return knownhosts;
    }
View Full Code Here

            }

            log.info("Updating authorized keys file");

            // Check the existing keys and add any that are not present
            SshPublicKey pk;

            for (Iterator x = keys.iterator(); x.hasNext();) {
                pk = (SshPublicKey) x.next();

                if (!authorizedKeys.containsKey(pk) &&
View Full Code Here

        }

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

        SshPublicKey pub = key.getPublicKey();
        InetAddress addr = InetAddress.getLocalHost();
        String hostname = addr.getHostName();
        log.info("Preparing hostbased authentication request for " + hostname);

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

        if (clientUser != null) {
            baw.writeString(clientUser);
        } else {
            baw.writeString(getUsername());
        }

        // 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.writeString(pub.getAlgorithmName());
        data.writeBinaryString(pub.getEncoded());
        data.writeString(hostname);

        if (clientUser != null) {
            data.writeString(clientUser);
        } else {
View Full Code Here

TOP

Related Classes of com.sshtools.j2ssh.transport.publickey.SshPublicKey

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.