273
|
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
|
|
9 import ch.ethz.ssh2.PacketFormatException;
|
|
10 import ch.ethz.ssh2.PacketTypeException;
|
|
11
|
|
12 /**
|
|
13 * @author Christian Plattner
|
|
14 * @version $Id: PacketUserauthRequestPublicKey.java 160 2014-05-01 14:30:26Z dkocher@sudo.ch $
|
|
15 */
|
|
16 public final class PacketUserauthRequestPublicKey {
|
|
17
|
|
18 private final byte[] payload;
|
|
19
|
|
20 public PacketUserauthRequestPublicKey(String serviceName, String user,
|
|
21 String pkAlgorithmName, byte[] pk, byte[] sig) {
|
|
22 TypesWriter tw = new TypesWriter();
|
|
23 tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST);
|
|
24 tw.writeString(user);
|
|
25 tw.writeString(serviceName);
|
|
26 tw.writeString("publickey");
|
|
27 tw.writeBoolean(true);
|
|
28 tw.writeString(pkAlgorithmName);
|
|
29 tw.writeString(pk, 0, pk.length);
|
|
30 tw.writeString(sig, 0, sig.length);
|
|
31 payload = tw.getBytes();
|
|
32 }
|
|
33
|
|
34 public PacketUserauthRequestPublicKey(byte payload[]) throws IOException {
|
|
35 this.payload = payload;
|
|
36 TypesReader tr = new TypesReader(payload);
|
|
37 int packet_type = tr.readByte();
|
|
38
|
307
|
39 if (packet_type != Packets.SSH_MSG_USERAUTH_REQUEST) {
|
273
|
40 throw new PacketTypeException(packet_type);
|
|
41 }
|
307
|
42
|
273
|
43 String userName = tr.readString();
|
|
44 String serviceName = tr.readString();
|
|
45 String method = tr.readString();
|
|
46
|
307
|
47 if (!method.equals("publickey")) {
|
273
|
48 throw new IOException(String.format("Unexpected method %s", method));
|
|
49 }
|
307
|
50
|
|
51 if (tr.remain() != 0) {
|
273
|
52 throw new PacketFormatException(String.format("Padding in %s", Packets.getMessageName(packet_type)));
|
|
53 }
|
|
54 }
|
|
55
|
|
56 public byte[] getPayload() {
|
|
57 return payload;
|
|
58 }
|
|
59 }
|