Mercurial > 510Connectbot
comparison src/ch/ethz/ssh2/packets/PacketKexInit.java @ 273:91a31873c42a ganymed
start conversion from trilead to ganymed
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 18 Jul 2014 11:21:46 -0700 |
parents | |
children | 071eccdff8ea |
comparison
equal
deleted
inserted
replaced
272:ce2f4e397703 | 273:91a31873c42a |
---|---|
1 /* | |
2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved. | |
3 * Please refer to the LICENSE.txt for licensing details. | |
4 */ | |
5 package ch.ethz.ssh2.packets; | |
6 | |
7 import java.io.IOException; | |
8 import java.security.SecureRandom; | |
9 | |
10 import ch.ethz.ssh2.PacketFormatException; | |
11 import ch.ethz.ssh2.PacketTypeException; | |
12 import ch.ethz.ssh2.crypto.CryptoWishList; | |
13 import ch.ethz.ssh2.transport.KexParameters; | |
14 | |
15 /** | |
16 * @author Christian Plattner | |
17 * @version $Id: PacketKexInit.java 160 2014-05-01 14:30:26Z dkocher@sudo.ch $ | |
18 */ | |
19 public final class PacketKexInit { | |
20 private final byte[] payload; | |
21 | |
22 KexParameters kp = new KexParameters(); | |
23 | |
24 public PacketKexInit(CryptoWishList cwl, SecureRandom rnd) { | |
25 kp.cookie = new byte[16]; | |
26 rnd.nextBytes(kp.cookie); | |
27 | |
28 kp.kex_algorithms = cwl.kexAlgorithms; | |
29 kp.server_host_key_algorithms = cwl.serverHostKeyAlgorithms; | |
30 kp.encryption_algorithms_client_to_server = cwl.c2s_enc_algos; | |
31 kp.encryption_algorithms_server_to_client = cwl.s2c_enc_algos; | |
32 kp.mac_algorithms_client_to_server = cwl.c2s_mac_algos; | |
33 kp.mac_algorithms_server_to_client = cwl.s2c_mac_algos; | |
34 kp.compression_algorithms_client_to_server = cwl.c2s_comp_algos; | |
35 kp.compression_algorithms_server_to_client = cwl.s2c_comp_algos; | |
36 kp.languages_client_to_server = new String[]{""}; | |
37 kp.languages_server_to_client = new String[]{""}; | |
38 kp.first_kex_packet_follows = false; | |
39 kp.reserved_field1 = 0; | |
40 | |
41 TypesWriter tw = new TypesWriter(); | |
42 tw.writeByte(Packets.SSH_MSG_KEXINIT); | |
43 tw.writeBytes(kp.cookie, 0, 16); | |
44 tw.writeNameList(kp.kex_algorithms); | |
45 tw.writeNameList(kp.server_host_key_algorithms); | |
46 tw.writeNameList(kp.encryption_algorithms_client_to_server); | |
47 tw.writeNameList(kp.encryption_algorithms_server_to_client); | |
48 tw.writeNameList(kp.mac_algorithms_client_to_server); | |
49 tw.writeNameList(kp.mac_algorithms_server_to_client); | |
50 tw.writeNameList(kp.compression_algorithms_client_to_server); | |
51 tw.writeNameList(kp.compression_algorithms_server_to_client); | |
52 tw.writeNameList(kp.languages_client_to_server); | |
53 tw.writeNameList(kp.languages_server_to_client); | |
54 tw.writeBoolean(kp.first_kex_packet_follows); | |
55 tw.writeUINT32(kp.reserved_field1); | |
56 payload = tw.getBytes(); | |
57 } | |
58 | |
59 public PacketKexInit(byte payload[]) throws IOException { | |
60 this.payload = payload; | |
61 | |
62 TypesReader tr = new TypesReader(payload); | |
63 | |
64 int packet_type = tr.readByte(); | |
65 | |
66 if(packet_type != Packets.SSH_MSG_KEXINIT) { | |
67 throw new PacketTypeException(packet_type); | |
68 } | |
69 kp.cookie = tr.readBytes(16); | |
70 kp.kex_algorithms = tr.readNameList(); | |
71 kp.server_host_key_algorithms = tr.readNameList(); | |
72 kp.encryption_algorithms_client_to_server = tr.readNameList(); | |
73 kp.encryption_algorithms_server_to_client = tr.readNameList(); | |
74 kp.mac_algorithms_client_to_server = tr.readNameList(); | |
75 kp.mac_algorithms_server_to_client = tr.readNameList(); | |
76 kp.compression_algorithms_client_to_server = tr.readNameList(); | |
77 kp.compression_algorithms_server_to_client = tr.readNameList(); | |
78 kp.languages_client_to_server = tr.readNameList(); | |
79 kp.languages_server_to_client = tr.readNameList(); | |
80 kp.first_kex_packet_follows = tr.readBoolean(); | |
81 kp.reserved_field1 = tr.readUINT32(); | |
82 | |
83 if(tr.remain() != 0) { | |
84 throw new PacketFormatException(String.format("Padding in %s", Packets.getMessageName(packet_type))); | |
85 } | |
86 } | |
87 | |
88 public byte[] getPayload() { | |
89 return payload; | |
90 } | |
91 | |
92 public KexParameters getKexParameters() { | |
93 return kp; | |
94 } | |
95 | |
96 public String[] getCompression_algorithms_client_to_server() { | |
97 return kp.compression_algorithms_client_to_server; | |
98 } | |
99 | |
100 public String[] getCompression_algorithms_server_to_client() { | |
101 return kp.compression_algorithms_server_to_client; | |
102 } | |
103 | |
104 public byte[] getCookie() { | |
105 return kp.cookie; | |
106 } | |
107 | |
108 public String[] getEncryption_algorithms_client_to_server() { | |
109 return kp.encryption_algorithms_client_to_server; | |
110 } | |
111 | |
112 public String[] getEncryption_algorithms_server_to_client() { | |
113 return kp.encryption_algorithms_server_to_client; | |
114 } | |
115 | |
116 public boolean isFirst_kex_packet_follows() { | |
117 return kp.first_kex_packet_follows; | |
118 } | |
119 | |
120 public String[] getKex_algorithms() { | |
121 return kp.kex_algorithms; | |
122 } | |
123 | |
124 public String[] getLanguages_client_to_server() { | |
125 return kp.languages_client_to_server; | |
126 } | |
127 | |
128 public String[] getLanguages_server_to_client() { | |
129 return kp.languages_server_to_client; | |
130 } | |
131 | |
132 public String[] getMac_algorithms_client_to_server() { | |
133 return kp.mac_algorithms_client_to_server; | |
134 } | |
135 | |
136 public String[] getMac_algorithms_server_to_client() { | |
137 return kp.mac_algorithms_server_to_client; | |
138 } | |
139 | |
140 public int getReserved_field1() { | |
141 return kp.reserved_field1; | |
142 } | |
143 | |
144 public String[] getServer_host_key_algorithms() { | |
145 return kp.server_host_key_algorithms; | |
146 } | |
147 } |