0
|
1
|
|
2 package com.trilead.ssh2.packets;
|
|
3
|
|
4 import java.io.IOException;
|
|
5 import java.security.SecureRandom;
|
|
6
|
|
7 import com.trilead.ssh2.crypto.CryptoWishList;
|
|
8 import com.trilead.ssh2.transport.KexParameters;
|
|
9
|
|
10
|
|
11 /**
|
|
12 * PacketKexInit.
|
|
13 *
|
|
14 * @author Christian Plattner, plattner@trilead.com
|
|
15 * @version $Id: PacketKexInit.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
|
|
16 */
|
|
17 public class PacketKexInit {
|
|
18 byte[] payload;
|
|
19
|
|
20 KexParameters kp = new KexParameters();
|
|
21
|
|
22 public PacketKexInit(CryptoWishList cwl) {
|
|
23 kp.cookie = new byte[16];
|
|
24 new SecureRandom().nextBytes(kp.cookie);
|
|
25 kp.kex_algorithms = cwl.kexAlgorithms;
|
|
26 kp.server_host_key_algorithms = cwl.serverHostKeyAlgorithms;
|
|
27 kp.encryption_algorithms_client_to_server = cwl.c2s_enc_algos;
|
|
28 kp.encryption_algorithms_server_to_client = cwl.s2c_enc_algos;
|
|
29 kp.mac_algorithms_client_to_server = cwl.c2s_mac_algos;
|
|
30 kp.mac_algorithms_server_to_client = cwl.s2c_mac_algos;
|
|
31 kp.compression_algorithms_client_to_server = cwl.c2s_comp_algos;
|
|
32 kp.compression_algorithms_server_to_client = cwl.s2c_comp_algos;
|
|
33 kp.languages_client_to_server = new String[] {};
|
|
34 kp.languages_server_to_client = new String[] {};
|
|
35 kp.first_kex_packet_follows = false;
|
|
36 kp.reserved_field1 = 0;
|
|
37 }
|
|
38
|
|
39 public PacketKexInit(byte payload[], int off, int len) throws IOException {
|
|
40 this.payload = new byte[len];
|
|
41 System.arraycopy(payload, off, this.payload, 0, len);
|
|
42 TypesReader tr = new TypesReader(payload, off, len);
|
|
43 int packet_type = tr.readByte();
|
|
44
|
|
45 if (packet_type != Packets.SSH_MSG_KEXINIT)
|
|
46 throw new IOException("This is not a KexInitPacket! (" + packet_type + ")");
|
|
47
|
|
48 kp.cookie = tr.readBytes(16);
|
|
49 kp.kex_algorithms = tr.readNameList();
|
|
50 kp.server_host_key_algorithms = tr.readNameList();
|
|
51 kp.encryption_algorithms_client_to_server = tr.readNameList();
|
|
52 kp.encryption_algorithms_server_to_client = tr.readNameList();
|
|
53 kp.mac_algorithms_client_to_server = tr.readNameList();
|
|
54 kp.mac_algorithms_server_to_client = tr.readNameList();
|
|
55 kp.compression_algorithms_client_to_server = tr.readNameList();
|
|
56 kp.compression_algorithms_server_to_client = tr.readNameList();
|
|
57 kp.languages_client_to_server = tr.readNameList();
|
|
58 kp.languages_server_to_client = tr.readNameList();
|
|
59 kp.first_kex_packet_follows = tr.readBoolean();
|
|
60 kp.reserved_field1 = tr.readUINT32();
|
|
61
|
|
62 if (tr.remain() != 0)
|
|
63 throw new IOException("Padding in KexInitPacket!");
|
|
64 }
|
|
65
|
|
66 public byte[] getPayload() {
|
|
67 if (payload == null) {
|
|
68 TypesWriter tw = new TypesWriter();
|
|
69 tw.writeByte(Packets.SSH_MSG_KEXINIT);
|
|
70 tw.writeBytes(kp.cookie, 0, 16);
|
|
71 tw.writeNameList(kp.kex_algorithms);
|
|
72 tw.writeNameList(kp.server_host_key_algorithms);
|
|
73 tw.writeNameList(kp.encryption_algorithms_client_to_server);
|
|
74 tw.writeNameList(kp.encryption_algorithms_server_to_client);
|
|
75 tw.writeNameList(kp.mac_algorithms_client_to_server);
|
|
76 tw.writeNameList(kp.mac_algorithms_server_to_client);
|
|
77 tw.writeNameList(kp.compression_algorithms_client_to_server);
|
|
78 tw.writeNameList(kp.compression_algorithms_server_to_client);
|
|
79 tw.writeNameList(kp.languages_client_to_server);
|
|
80 tw.writeNameList(kp.languages_server_to_client);
|
|
81 tw.writeBoolean(kp.first_kex_packet_follows);
|
|
82 tw.writeUINT32(kp.reserved_field1);
|
|
83 payload = tw.getBytes();
|
|
84 }
|
|
85
|
|
86 return payload;
|
|
87 }
|
|
88
|
|
89 public KexParameters getKexParameters() {
|
|
90 return kp;
|
|
91 }
|
|
92
|
|
93 public String[] getCompression_algorithms_client_to_server() {
|
|
94 return kp.compression_algorithms_client_to_server;
|
|
95 }
|
|
96
|
|
97 public String[] getCompression_algorithms_server_to_client() {
|
|
98 return kp.compression_algorithms_server_to_client;
|
|
99 }
|
|
100
|
|
101 public byte[] getCookie() {
|
|
102 return kp.cookie;
|
|
103 }
|
|
104
|
|
105 public String[] getEncryption_algorithms_client_to_server() {
|
|
106 return kp.encryption_algorithms_client_to_server;
|
|
107 }
|
|
108
|
|
109 public String[] getEncryption_algorithms_server_to_client() {
|
|
110 return kp.encryption_algorithms_server_to_client;
|
|
111 }
|
|
112
|
|
113 public boolean isFirst_kex_packet_follows() {
|
|
114 return kp.first_kex_packet_follows;
|
|
115 }
|
|
116
|
|
117 public String[] getKex_algorithms() {
|
|
118 return kp.kex_algorithms;
|
|
119 }
|
|
120
|
|
121 public String[] getLanguages_client_to_server() {
|
|
122 return kp.languages_client_to_server;
|
|
123 }
|
|
124
|
|
125 public String[] getLanguages_server_to_client() {
|
|
126 return kp.languages_server_to_client;
|
|
127 }
|
|
128
|
|
129 public String[] getMac_algorithms_client_to_server() {
|
|
130 return kp.mac_algorithms_client_to_server;
|
|
131 }
|
|
132
|
|
133 public String[] getMac_algorithms_server_to_client() {
|
|
134 return kp.mac_algorithms_server_to_client;
|
|
135 }
|
|
136
|
|
137 public int getReserved_field1() {
|
|
138 return kp.reserved_field1;
|
|
139 }
|
|
140
|
|
141 public String[] getServer_host_key_algorithms() {
|
|
142 return kp.server_host_key_algorithms;
|
|
143 }
|
|
144 }
|