01: package ch.ethz.ssh2.packets;
02:
03: import java.io.IOException;
04:
05: /**
06: * PacketUserauthRequestPassword.
07: *
08: * @author Christian Plattner, plattner@inf.ethz.ch
09: * @version $Id: PacketUserauthRequestPassword.java,v 1.3 2005/08/24 17:54:09 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,
19: String user, String pass) {
20: this .serviceName = serviceName;
21: this .userName = user;
22: this .password = pass;
23: }
24:
25: public PacketUserauthRequestPassword(byte payload[], int off,
26: int len) throws IOException {
27: this .payload = new byte[len];
28: System.arraycopy(payload, off, this .payload, 0, len);
29:
30: TypesReader tr = new TypesReader(payload, off, len);
31:
32: int packet_type = tr.readByte();
33:
34: if (packet_type != Packets.SSH_MSG_USERAUTH_REQUEST)
35: throw new IOException(
36: "This is not a SSH_MSG_USERAUTH_REQUEST! ("
37: + packet_type + ")");
38:
39: userName = tr.readString();
40: serviceName = tr.readString();
41:
42: String method = tr.readString();
43:
44: if (method.equals("password") == false)
45: throw new IOException(
46: "This is not a SSH_MSG_USERAUTH_REQUEST with type password!");
47:
48: /* ... */
49:
50: if (tr.remain() != 0)
51: throw new IOException(
52: "Padding in SSH_MSG_USERAUTH_REQUEST packet!");
53: }
54:
55: public byte[] getPayload() {
56: if (payload == null) {
57: TypesWriter tw = new TypesWriter();
58: tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST);
59: tw.writeString(userName);
60: tw.writeString(serviceName);
61: tw.writeString("password");
62: tw.writeBoolean(false);
63: tw.writeString(password);
64: payload = tw.getBytes();
65: }
66: return payload;
67: }
68: }
|