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