|
33 | 33 | import net.schmizz.sshj.transport.kex.KeyExchange;
|
34 | 34 | import net.schmizz.sshj.transport.mac.MAC;
|
35 | 35 | import net.schmizz.sshj.transport.verification.HostKeyVerifier;
|
| 36 | +import net.schmizz.sshj.transport.verification.AlgorithmsVerifier; |
| 37 | + |
36 | 38 | import org.slf4j.Logger;
|
37 | 39 | import org.slf4j.LoggerFactory;
|
38 | 40 |
|
@@ -68,6 +70,8 @@ private static enum Expected {
|
68 | 70 | */
|
69 | 71 | private final Queue<HostKeyVerifier> hostVerifiers = new LinkedList<HostKeyVerifier>();
|
70 | 72 |
|
| 73 | + private final Queue<AlgorithmsVerifier> algorithmVerifiers = new LinkedList<AlgorithmsVerifier>(); |
| 74 | + |
71 | 75 | private final AtomicBoolean kexOngoing = new AtomicBoolean();
|
72 | 76 |
|
73 | 77 | /** What we are expecting from the next packet */
|
@@ -108,6 +112,10 @@ synchronized void addHostKeyVerifier(HostKeyVerifier hkv) {
|
108 | 112 | hostVerifiers.add(hkv);
|
109 | 113 | }
|
110 | 114 |
|
| 115 | + synchronized void addAlgorithmsVerifier(AlgorithmsVerifier verifier) { |
| 116 | + algorithmVerifiers.add(verifier); |
| 117 | + } |
| 118 | + |
111 | 119 | /**
|
112 | 120 | * Returns the session identifier computed during key exchange.
|
113 | 121 | *
|
@@ -218,6 +226,13 @@ private void gotKexInit(SSHPacket buf)
|
218 | 226 | final Proposal serverProposal = new Proposal(buf);
|
219 | 227 | negotiatedAlgs = clientProposal.negotiate(serverProposal);
|
220 | 228 | log.debug("Negotiated algorithms: {}", negotiatedAlgs);
|
| 229 | + for(AlgorithmsVerifier v: algorithmVerifiers) { |
| 230 | + log.debug("Trying to verify algorithms with {}", v); |
| 231 | + if(!v.verify(negotiatedAlgs)) { |
| 232 | + throw new TransportException(DisconnectReason.KEY_EXCHANGE_FAILED, |
| 233 | + "Failed to verify negotiated algorithms `" + negotiatedAlgs + "`"); |
| 234 | + } |
| 235 | + } |
221 | 236 | kex = Factory.Named.Util.create(transport.getConfig().getKeyExchangeFactories(),
|
222 | 237 | negotiatedAlgs.getKeyExchangeAlgorithm());
|
223 | 238 | try {
|
|
0 commit comments