• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
10  * PacketUserauthRequestPassword.
11  *
12  * @author Christian Plattner
13  * @version 2.50, 03/15/10
14  */
15 public class PacketUserauthRequestPassword
16 {
17 	byte[] payload;
18 
19 	String userName;
20 	String serviceName;
21 	String password;
22 
PacketUserauthRequestPassword(String serviceName, String user, String pass)23 	public PacketUserauthRequestPassword(String serviceName, String user, String pass)
24 	{
25 		this.serviceName = serviceName;
26 		this.userName = user;
27 		this.password = pass;
28 	}
29 
PacketUserauthRequestPassword(byte payload[], int off, int len)30 	public PacketUserauthRequestPassword(byte payload[], int off, int len) throws IOException
31 	{
32 		this.payload = new byte[len];
33 		System.arraycopy(payload, off, this.payload, 0, len);
34 
35 		TypesReader tr = new TypesReader(payload, off, len);
36 
37 		int packet_type = tr.readByte();
38 
39 		if (packet_type != Packets.SSH_MSG_USERAUTH_REQUEST)
40 			throw new IOException("This is not a SSH_MSG_USERAUTH_REQUEST! (" + packet_type + ")");
41 
42 		userName = tr.readString();
43 		serviceName = tr.readString();
44 
45 		String method = tr.readString();
46 
47 		if (method.equals("password") == false)
48 			throw new IOException("This is not a SSH_MSG_USERAUTH_REQUEST with type password!");
49 
50 		/* ... */
51 
52 		if (tr.remain() != 0)
53 			throw new IOException("Padding in SSH_MSG_USERAUTH_REQUEST packet!");
54 	}
55 
getPayload()56 	public byte[] getPayload()
57 	{
58 		if (payload == null)
59 		{
60 			TypesWriter tw = new TypesWriter();
61 			tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST);
62 			tw.writeString(userName);
63 			tw.writeString(serviceName);
64 			tw.writeString("password");
65 			tw.writeBoolean(false);
66 			tw.writeString(password);
67 			payload = tw.getBytes();
68 		}
69 		return payload;
70 	}
71 }
72