mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 15:20:54 +03:00
Compare commits
3 Commits
2d3e045190
...
issue-670
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f3d751431 | ||
|
|
9051c8c7e9 | ||
|
|
cf7309c866 |
@@ -2,6 +2,8 @@ FROM sickp/alpine-sshd:7.5-r2
|
|||||||
|
|
||||||
ADD authorized_keys /home/sshj/.ssh/authorized_keys
|
ADD authorized_keys /home/sshj/.ssh/authorized_keys
|
||||||
|
|
||||||
|
ADD test-container/ssh_host_dsa_key /etc/ssh/ssh_host_dsa_key
|
||||||
|
ADD test-container/ssh_host_dsa_key.pub /etc/ssh/ssh_host_dsa_key.pub
|
||||||
ADD test-container/ssh_host_ecdsa_key /etc/ssh/ssh_host_ecdsa_key
|
ADD test-container/ssh_host_ecdsa_key /etc/ssh/ssh_host_ecdsa_key
|
||||||
ADD test-container/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
|
ADD test-container/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
|
||||||
ADD test-container/ssh_host_ed25519_key /etc/ssh/ssh_host_ed25519_key
|
ADD test-container/ssh_host_ed25519_key /etc/ssh/ssh_host_ed25519_key
|
||||||
|
|||||||
21
src/itest/docker-image/test-container/ssh_host_dsa_key
Normal file
21
src/itest/docker-image/test-container/ssh_host_dsa_key
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
-----BEGIN OPENSSH PRIVATE KEY-----
|
||||||
|
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABsgAAAAdzc2gtZH
|
||||||
|
NzAAAAgQDGUD3XnEQf3S4iB8LbVAw9diSaTTbaKGRt+D89d6QWHJ75I684F6iehXzr7iKq
|
||||||
|
PmmVy2Bp3BfSM1m6P4wJftHbVW6dbJSeVW1Ov6SIRA5XEG/hrY1DmlC9aXhksqYKUKffYx
|
||||||
|
WOEg4p2eCtvGyu/j9Euc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
||||||
|
KCWbSQ32AlTpFlLPi8pkgTwGT/6G1eBxe+/xHR5KEAAAAUCbVJM+EkJ5K/JWd08304hz+O
|
||||||
|
Cq8AAAANYWp2YW5lcnBAdGhvcgECAwQF
|
||||||
|
-----END OPENSSH PRIVATE KEY-----
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
ssh-dss AAAAB3NzaC1kc3MAAACBAMZQPdecRB/dLiIHwttUDD12JJpNNtooZG34Pz13pBYcnvkjrzgXqJ6FfOvuIqo+aZXLYGncF9IzWbo/jAl+0dtVbp1slJ5VbU6/pIhEDlcQb+GtjUOaUL1peGSypgpQp99jFY4SDinZ4K28bK7+P0S5wasLvoGtoRugAeleyiM3AAAAFQC4R7F34WwxJs1KwnP30dw07syHLwAAAIEAv74W9zJfw9ntV5CP6C7QKQOFkzXgik0Yoo4EMW9lNQgsccbtOeSMFHUcnD9tGXCS+u9gL7XnmxP8ELY4qlWSJTILDUsoZW0kFqztSWqZNribV8QaNpZfRvU6naGnCnEKSaOpLTseUL+cQewQQx0Jr0fEJ9sR0yZR0s1LARUms8AAAACAAZvonbhFrh/Pnm+UrW+3fi7f3Rh0yDVEuIJrh0W5tzySEQxgqnAEijIQKCUnIN0tee4lCLBXM2BfVrPHXQbzh3lAKgBk9ApYrWhaOPysH7iC0SMTWwHt9mTFJcX8FpElA+KCWbSQ32AlTpFlLPi8pkgTwGT/6G1eBxe+/xHR5KE= ajvanerp@thor
|
||||||
@@ -128,9 +128,13 @@ Subsystem sftp /usr/lib/ssh/sftp-server
|
|||||||
# PermitTTY no
|
# PermitTTY no
|
||||||
# ForceCommand cvs server
|
# ForceCommand cvs server
|
||||||
|
|
||||||
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1
|
|
||||||
macs umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com
|
|
||||||
|
|
||||||
TrustedUserCAKeys /etc/ssh/users_rsa_ca.pub
|
TrustedUserCAKeys /etc/ssh/users_rsa_ca.pub
|
||||||
|
|
||||||
Ciphers 3des-cbc,blowfish-cbc,aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
|
KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1
|
||||||
|
macs +hmac-ripemd160-etm@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com
|
||||||
|
Ciphers +3des-cbc,blowfish-cbc,aes128-cbc,aes192-cbc,aes256-cbc
|
||||||
|
PubKeyAcceptedKeyTypes +ssh-dss
|
||||||
|
HostKeyAlgorithms +ssh-dss
|
||||||
|
HostbasedAcceptedKeyTypes +ssh-dss
|
||||||
|
|||||||
@@ -16,6 +16,11 @@
|
|||||||
package com.hierynomus.sshj
|
package com.hierynomus.sshj
|
||||||
|
|
||||||
import com.hierynomus.sshj.key.KeyAlgorithms
|
import com.hierynomus.sshj.key.KeyAlgorithms
|
||||||
|
import com.hierynomus.sshj.transport.kex.DHGroups
|
||||||
|
import com.hierynomus.sshj.transport.cipher.BlockCiphers
|
||||||
|
import com.hierynomus.sshj.transport.mac.Macs
|
||||||
|
import net.schmizz.sshj.transport.verification.PromiscuousVerifier
|
||||||
|
|
||||||
import net.schmizz.sshj.DefaultConfig
|
import net.schmizz.sshj.DefaultConfig
|
||||||
import net.schmizz.sshj.SSHClient
|
import net.schmizz.sshj.SSHClient
|
||||||
import net.schmizz.sshj.transport.TransportException
|
import net.schmizz.sshj.transport.TransportException
|
||||||
@@ -92,4 +97,22 @@ class IntegrationSpec extends IntegrationBaseSpec {
|
|||||||
thrown(UserAuthException.class)
|
thrown(UserAuthException.class)
|
||||||
!client.isAuthenticated()
|
!client.isAuthenticated()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def "should correctly connect using parameters in #670"() {
|
||||||
|
given:
|
||||||
|
def config = new DefaultConfig()
|
||||||
|
// config.setKeyAlgorithms(Collections.singletonList(KeyAlgorithms.SSHDSA())) // Can't get openssh to offer ssh-dss
|
||||||
|
config.setKeyExchangeFactories(DHGroups.Group1SHA1())
|
||||||
|
config.setCipherFactories(BlockCiphers.TripleDESCBC())
|
||||||
|
config.setMACFactories(Macs.HMACSHA1())
|
||||||
|
SSHClient sshClient = new SSHClient(config)
|
||||||
|
sshClient.addHostKeyVerifier(new PromiscuousVerifier())
|
||||||
|
|
||||||
|
when:
|
||||||
|
sshClient.connect(SERVER_IP, DOCKER_PORT)
|
||||||
|
|
||||||
|
then:
|
||||||
|
sshClient.isConnected()
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
package net.schmizz.sshj.transport;
|
package net.schmizz.sshj.transport;
|
||||||
|
|
||||||
import net.schmizz.sshj.common.Buffer;
|
import net.schmizz.sshj.common.Buffer;
|
||||||
|
import net.schmizz.sshj.common.ByteArrayUtils;
|
||||||
import net.schmizz.sshj.common.LoggerFactory;
|
import net.schmizz.sshj.common.LoggerFactory;
|
||||||
import net.schmizz.sshj.common.SSHPacket;
|
import net.schmizz.sshj.common.SSHPacket;
|
||||||
import net.schmizz.sshj.transport.cipher.Cipher;
|
import net.schmizz.sshj.transport.cipher.Cipher;
|
||||||
@@ -73,7 +74,7 @@ final class Encoder
|
|||||||
}
|
}
|
||||||
|
|
||||||
final int payloadSize = buffer.available();
|
final int payloadSize = buffer.available();
|
||||||
int lengthWithoutPadding;
|
final int lengthWithoutPadding;
|
||||||
if (etm) {
|
if (etm) {
|
||||||
// in Encrypt-Then-Mac mode, the length field is not encrypted, so we should keep it out of the
|
// in Encrypt-Then-Mac mode, the length field is not encrypted, so we should keep it out of the
|
||||||
// padding length calculation
|
// padding length calculation
|
||||||
@@ -83,18 +84,36 @@ final class Encoder
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compute padding length
|
// Compute padding length
|
||||||
int padLen = cipherSize - (lengthWithoutPadding % cipherSize);
|
// random padding - Arbitrary-length padding, such that the total length of
|
||||||
if (padLen < 4 || (authMode && padLen < cipherSize)) {
|
// (packet_length || padding_length || payload || random padding)
|
||||||
padLen += cipherSize;
|
// is a multiple of the cipher block size or 8, whichever is
|
||||||
|
// larger. There MUST be at least four bytes of padding. The
|
||||||
|
// padding SHOULD consist of random bytes. The maximum amount of
|
||||||
|
// padding is 255 bytes.
|
||||||
|
final int mod = cipherSize > 8 ? cipherSize : 8;
|
||||||
|
|
||||||
|
// (lengthWithoutPadding + padLen) % mod == 0 where 4 <= padLen < 256
|
||||||
|
int padLen = mod - (lengthWithoutPadding % mod);
|
||||||
|
if (padLen < 4 || (authMode && padLen < mod)) {
|
||||||
|
padLen += mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int startOfPacket = buffer.rpos() - 5;
|
final int startOfPacket = buffer.rpos() - 5;
|
||||||
int packetLen = 1 + payloadSize + padLen; // packetLength = padLen (1 byte) + payload + padding
|
int packetLen = 1 + payloadSize + padLen; // packetLength = padLen (1 byte) + payload + padding
|
||||||
|
|
||||||
if (packetLen < 16) {
|
// The minimum size of a packet is 16 (or the cipher block size,
|
||||||
padLen += cipherSize;
|
// whichever is larger) bytes (plus 'mac'). Implementations SHOULD
|
||||||
|
// decrypt the length after receiving the first 8 (or cipher block size,
|
||||||
|
// whichever is larger) bytes of a packet.
|
||||||
|
// if (packetLen < 16) {
|
||||||
|
// padLen += cipherSize;
|
||||||
|
// packetLen = 1 + payloadSize + padLen;
|
||||||
|
// }
|
||||||
|
while (packetLen < Math.max(16, cipherSize)) {
|
||||||
|
padLen += mod; // Increment with the mod so that multiple holds
|
||||||
packetLen = 1 + payloadSize + padLen;
|
packetLen = 1 + payloadSize + padLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In AES-GCM ciphers, they require packets must be a multiple of 16 bytes (which is also block size of AES)
|
* In AES-GCM ciphers, they require packets must be a multiple of 16 bytes (which is also block size of AES)
|
||||||
* as mentioned in RFC5647 Section 7.2. So we are calculating the extra padding as necessary here
|
* as mentioned in RFC5647 Section 7.2. So we are calculating the extra padding as necessary here
|
||||||
@@ -130,17 +149,23 @@ final class Encoder
|
|||||||
if (mac != null) {
|
if (mac != null) {
|
||||||
putMAC(buffer, startOfPacket, endOfPadding);
|
putMAC(buffer, startOfPacket, endOfPadding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (log.isTraceEnabled()) {
|
||||||
|
log.trace("Encrypting packet #{}: {}", seq, ByteArrayUtils.printHex(buffer.array(), startOfPacket, 4 + packetLen));
|
||||||
|
}
|
||||||
|
|
||||||
cipher.update(buffer.array(), startOfPacket, 4 + packetLen);
|
cipher.update(buffer.array(), startOfPacket, 4 + packetLen);
|
||||||
}
|
}
|
||||||
buffer.rpos(startOfPacket); // Make ready-to-read
|
buffer.rpos(startOfPacket); // Make ready-to-read
|
||||||
|
|
||||||
|
|
||||||
return seq;
|
return seq;
|
||||||
} finally {
|
} finally {
|
||||||
encodeLock.unlock();
|
encodeLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void aeadOutgoingBuffer(Buffer buf, int offset, int len) {
|
protected void aeadOutgoingBuffer(Buffer<?> buf, int offset, int len) {
|
||||||
if (cipher == null || cipher.getAuthenticationTagSize() == 0) {
|
if (cipher == null || cipher.getAuthenticationTagSize() == 0) {
|
||||||
throw new IllegalArgumentException("AEAD mode requires an AEAD cipher");
|
throw new IllegalArgumentException("AEAD mode requires an AEAD cipher");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user