Mercurial > 510Connectbot
comparison src/com/trilead/ssh2/packets/PacketUserauthRequestPassword.java @ 0:0ce5cc452d02
initial version
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 22 May 2014 10:41:19 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:0ce5cc452d02 |
---|---|
1 package com.trilead.ssh2.packets; | |
2 | |
3 import java.io.IOException; | |
4 | |
5 /** | |
6 * PacketUserauthRequestPassword. | |
7 * | |
8 * @author Christian Plattner, plattner@trilead.com | |
9 * @version $Id: PacketUserauthRequestPassword.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ | |
10 */ | |
11 public class PacketUserauthRequestPassword { | |
12 byte[] payload; | |
13 | |
14 String userName; | |
15 String serviceName; | |
16 String password; | |
17 | |
18 public PacketUserauthRequestPassword(String serviceName, String user, String pass) { | |
19 this.serviceName = serviceName; | |
20 this.userName = user; | |
21 this.password = pass; | |
22 } | |
23 | |
24 public PacketUserauthRequestPassword(byte payload[], int off, int len) throws IOException { | |
25 this.payload = new byte[len]; | |
26 System.arraycopy(payload, off, this.payload, 0, len); | |
27 TypesReader tr = new TypesReader(payload, off, len); | |
28 int packet_type = tr.readByte(); | |
29 | |
30 if (packet_type != Packets.SSH_MSG_USERAUTH_REQUEST) | |
31 throw new IOException("This is not a SSH_MSG_USERAUTH_REQUEST! (" + packet_type + ")"); | |
32 | |
33 userName = tr.readString(); | |
34 serviceName = tr.readString(); | |
35 String method = tr.readString(); | |
36 | |
37 if (method.equals("password") == false) | |
38 throw new IOException("This is not a SSH_MSG_USERAUTH_REQUEST with type password!"); | |
39 | |
40 /* ... */ | |
41 | |
42 if (tr.remain() != 0) | |
43 throw new IOException("Padding in SSH_MSG_USERAUTH_REQUEST packet!"); | |
44 } | |
45 | |
46 public byte[] getPayload() { | |
47 if (payload == null) { | |
48 TypesWriter tw = new TypesWriter(); | |
49 tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST); | |
50 tw.writeString(userName); | |
51 tw.writeString(serviceName); | |
52 tw.writeString("password"); | |
53 tw.writeBoolean(false); | |
54 tw.writeString(password); | |
55 payload = tw.getBytes(); | |
56 } | |
57 | |
58 return payload; | |
59 } | |
60 } |