Mercurial > 510Connectbot
comparison app/src/main/java/ch/ethz/ssh2/packets/PacketKexInit.java @ 438:d29cce60f393
migrate from Eclipse to Android Studio
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 03 Dec 2015 11:23:55 -0800 |
parents | src/ch/ethz/ssh2/packets/PacketKexInit.java@071eccdff8ea |
children |
comparison
equal
deleted
inserted
replaced
437:208b31032318 | 438:d29cce60f393 |
---|---|
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 kp.kex_algorithms = cwl.kexAlgorithms; | |
28 kp.server_host_key_algorithms = cwl.serverHostKeyAlgorithms; | |
29 kp.encryption_algorithms_client_to_server = cwl.c2s_enc_algos; | |
30 kp.encryption_algorithms_server_to_client = cwl.s2c_enc_algos; | |
31 kp.mac_algorithms_client_to_server = cwl.c2s_mac_algos; | |
32 kp.mac_algorithms_server_to_client = cwl.s2c_mac_algos; | |
33 kp.compression_algorithms_client_to_server = cwl.c2s_comp_algos; | |
34 kp.compression_algorithms_server_to_client = cwl.s2c_comp_algos; | |
35 kp.languages_client_to_server = new String[] {""}; | |
36 kp.languages_server_to_client = new String[] {""}; | |
37 kp.first_kex_packet_follows = false; | |
38 kp.reserved_field1 = 0; | |
39 TypesWriter tw = new TypesWriter(); | |
40 tw.writeByte(Packets.SSH_MSG_KEXINIT); | |
41 tw.writeBytes(kp.cookie, 0, 16); | |
42 tw.writeNameList(kp.kex_algorithms); | |
43 tw.writeNameList(kp.server_host_key_algorithms); | |
44 tw.writeNameList(kp.encryption_algorithms_client_to_server); | |
45 tw.writeNameList(kp.encryption_algorithms_server_to_client); | |
46 tw.writeNameList(kp.mac_algorithms_client_to_server); | |
47 tw.writeNameList(kp.mac_algorithms_server_to_client); | |
48 tw.writeNameList(kp.compression_algorithms_client_to_server); | |
49 tw.writeNameList(kp.compression_algorithms_server_to_client); | |
50 tw.writeNameList(kp.languages_client_to_server); | |
51 tw.writeNameList(kp.languages_server_to_client); | |
52 tw.writeBoolean(kp.first_kex_packet_follows); | |
53 tw.writeUINT32(kp.reserved_field1); | |
54 payload = tw.getBytes(); | |
55 } | |
56 | |
57 public PacketKexInit(byte payload[]) throws IOException { | |
58 this.payload = payload; | |
59 TypesReader tr = new TypesReader(payload); | |
60 int packet_type = tr.readByte(); | |
61 | |
62 if (packet_type != Packets.SSH_MSG_KEXINIT) { | |
63 throw new PacketTypeException(packet_type); | |
64 } | |
65 | |
66 kp.cookie = tr.readBytes(16); | |
67 kp.kex_algorithms = tr.readNameList(); | |
68 kp.server_host_key_algorithms = tr.readNameList(); | |
69 kp.encryption_algorithms_client_to_server = tr.readNameList(); | |
70 kp.encryption_algorithms_server_to_client = tr.readNameList(); | |
71 kp.mac_algorithms_client_to_server = tr.readNameList(); | |
72 kp.mac_algorithms_server_to_client = tr.readNameList(); | |
73 kp.compression_algorithms_client_to_server = tr.readNameList(); | |
74 kp.compression_algorithms_server_to_client = tr.readNameList(); | |
75 kp.languages_client_to_server = tr.readNameList(); | |
76 kp.languages_server_to_client = tr.readNameList(); | |
77 kp.first_kex_packet_follows = tr.readBoolean(); | |
78 kp.reserved_field1 = tr.readUINT32(); | |
79 | |
80 if (tr.remain() != 0) { | |
81 throw new PacketFormatException(String.format("Padding in %s", Packets.getMessageName(packet_type))); | |
82 } | |
83 } | |
84 | |
85 public byte[] getPayload() { | |
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 } |