Updated Branches: refs/heads/master fea5aa335 -> 562288bb6
Improve a few logging statements Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/562288bb Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/562288bb Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/562288bb Branch: refs/heads/master Commit: 562288bb678831d1e993100641f9da48f25f95ce Parents: fea5aa3 Author: Guillaume Nodet <[email protected]> Authored: Fri Jan 24 14:56:00 2014 +0100 Committer: Guillaume Nodet <[email protected]> Committed: Fri Jan 24 14:56:00 2014 +0100 ---------------------------------------------------------------------- .../client/channel/AbstractClientChannel.java | 2 +- .../keyverifier/AcceptAllServerKeyVerifier.java | 6 ++- .../sshd/common/session/AbstractSession.java | 8 +++ .../apache/sshd/common/util/BufferUtils.java | 6 ++- .../org/apache/sshd/common/util/KeyUtils.java | 55 ++++++++++++++++++++ 5 files changed, 73 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/562288bb/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java index 5108cf3..fd5e180 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java @@ -251,7 +251,7 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C } public boolean handleRequest(String req, Buffer buffer) throws IOException { - log.info("Received SSH_MSG_CHANNEL_REQUEST on channel {}", id); + log.info("Received SSH_MSG_CHANNEL_REQUEST {} on channel {}", req, id); if ("exit-status".equals(req)) { exitStatus = buffer.getInt(); notifyStateChanged(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/562288bb/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/AcceptAllServerKeyVerifier.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/AcceptAllServerKeyVerifier.java b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/AcceptAllServerKeyVerifier.java index 22aed42..8fa9005 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/AcceptAllServerKeyVerifier.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/AcceptAllServerKeyVerifier.java @@ -23,7 +23,7 @@ import java.security.PublicKey; import org.apache.sshd.ClientSession; import org.apache.sshd.client.ServerKeyVerifier; -import org.apache.sshd.common.util.BufferUtils; +import org.apache.sshd.common.util.KeyUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,7 +42,9 @@ public class AcceptAllServerKeyVerifier implements ServerKeyVerifier { } public boolean verifyServerKey(ClientSession sshClientSession, SocketAddress remoteAddress, PublicKey serverKey) { - log.warn("Server at {} presented unverified key: ", remoteAddress, BufferUtils.printHex(serverKey.getEncoded())); + log.warn("Server at {} presented unverified {} key: {}", + new Object[] { remoteAddress, serverKey.getAlgorithm(), KeyUtils.getFingerPrint(serverKey) }); return true; } + } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/562288bb/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java index 61666a9..7766a53 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java @@ -977,6 +977,14 @@ public abstract class AbstractSession implements Session { } } negociated = guess; + log.info("Kex: server->client {} {} {}", + new Object[] { negociated[SshConstants.PROPOSAL_ENC_ALGS_STOC], + negociated[SshConstants.PROPOSAL_MAC_ALGS_STOC], + negociated[SshConstants.PROPOSAL_COMP_ALGS_STOC]}); + log.info("Kex: client->server {} {} {}", + new Object[] { negociated[SshConstants.PROPOSAL_ENC_ALGS_CTOS], + negociated[SshConstants.PROPOSAL_MAC_ALGS_CTOS], + negociated[SshConstants.PROPOSAL_COMP_ALGS_CTOS]}); } protected void requestSuccess(Buffer buffer) throws Exception{ http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/562288bb/sshd-core/src/main/java/org/apache/sshd/common/util/BufferUtils.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/BufferUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/BufferUtils.java index 823887d..dde95e6 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/BufferUtils.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/BufferUtils.java @@ -30,11 +30,15 @@ public class BufferUtils { } public static String printHex(byte[] array, int offset, int len) { + return printHex(array, offset, len, ' '); + } + + public static String printHex(byte[] array, int offset, int len, char sep) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i++) { byte b = array[offset + i]; if (sb.length() > 0) { - sb.append(' '); + sb.append(sep); } sb.append(digits[(b >> 4) & 0x0F]); sb.append(digits[b & 0x0F]); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/562288bb/sshd-core/src/main/java/org/apache/sshd/common/util/KeyUtils.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/KeyUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/KeyUtils.java new file mode 100644 index 0000000..cd9fd65 --- /dev/null +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/KeyUtils.java @@ -0,0 +1,55 @@ +/* + * 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.util; + +import java.security.PublicKey; + +import org.apache.sshd.common.digest.MD5; + +/** + * Utility class for keys + * + * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> + */ +public class KeyUtils { + + /** + * Retrieve the public key fingerprint + * + * @param key the public key + * @return the fingerprint + */ + public static String getFingerPrint(PublicKey key) { + try { + Buffer buffer = new Buffer(); + buffer.putRawPublicKey(key); + MD5 md5 = new MD5(); + md5.init(); + md5.update(buffer.array(), 0, buffer.wpos()); + byte[] data = md5.digest(); + return BufferUtils.printHex(data, 0, data.length, ':'); + } catch (Exception e) { + return "Unable to compute fingerprint"; + } + } + + private KeyUtils() { + } + +}
