Search in sources :

Example 1 with Buffer

use of org.apache.sshd.common.util.buffer.Buffer in project gerrit by GerritCodeReview.

the class SshDaemon method computeHostKeys.

private List<HostKey> computeHostKeys() {
    if (listen.isEmpty()) {
        return Collections.emptyList();
    }
    final List<PublicKey> keys = myHostKeys();
    final List<HostKey> r = new ArrayList<>();
    for (final PublicKey pub : keys) {
        final Buffer buf = new ByteArrayBuffer();
        buf.putRawPublicKey(pub);
        final byte[] keyBin = buf.getCompactData();
        for (final String addr : advertised) {
            try {
                r.add(new HostKey(addr, keyBin));
            } catch (JSchException e) {
                sshDaemonLog.warn(String.format("Cannot format SSHD host key [%s]: %s", pub.getAlgorithm(), e.getMessage()));
            }
        }
    }
    return Collections.unmodifiableList(r);
}
Also used : ByteArrayBuffer(org.apache.sshd.common.util.buffer.ByteArrayBuffer) Buffer(org.apache.sshd.common.util.buffer.Buffer) JSchException(com.jcraft.jsch.JSchException) HostKey(com.jcraft.jsch.HostKey) PublicKey(java.security.PublicKey) ArrayList(java.util.ArrayList) ByteArrayBuffer(org.apache.sshd.common.util.buffer.ByteArrayBuffer)

Example 2 with Buffer

use of org.apache.sshd.common.util.buffer.Buffer in project gitblit by gitblit.

the class SshKey method getRawData.

public String getRawData() {
    if (rawData == null && publicKey != null) {
        // build the raw data manually from the public key
        Buffer buf = new ByteArrayBuffer();
        // 1: identify the algorithm
        buf.putRawPublicKey(publicKey);
        String alg = buf.getString();
        // 2: encode the key
        buf.clear();
        buf.putPublicKey(publicKey);
        String b64 = Base64.encodeBase64String(buf.getBytes());
        String c = getComment();
        rawData = alg + " " + b64 + (StringUtils.isEmpty(c) ? "" : (" " + c));
    }
    return rawData;
}
Also used : Buffer(org.apache.sshd.common.util.buffer.Buffer) ByteArrayBuffer(org.apache.sshd.common.util.buffer.ByteArrayBuffer) ByteArrayBuffer(org.apache.sshd.common.util.buffer.ByteArrayBuffer)

Aggregations

Buffer (org.apache.sshd.common.util.buffer.Buffer)2 ByteArrayBuffer (org.apache.sshd.common.util.buffer.ByteArrayBuffer)2 HostKey (com.jcraft.jsch.HostKey)1 JSchException (com.jcraft.jsch.JSchException)1 PublicKey (java.security.PublicKey)1 ArrayList (java.util.ArrayList)1