1/*
2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 * Please refer to the LICENSE.txt for licensing details.
4 */
5package ch.ethz.ssh2.packets;
6
7import java.io.IOException;
8
9/**
10 * PacketUserauthRequestPassword.
11 *
12 * @author Christian Plattner
13 * @version 2.50, 03/15/10
14 */
15public class PacketUserauthRequestNone
16{
17	byte[] payload;
18
19	String userName;
20	String serviceName;
21
22	public PacketUserauthRequestNone(String serviceName, String user)
23	{
24		this.serviceName = serviceName;
25		this.userName = user;
26	}
27
28	public PacketUserauthRequestNone(byte payload[], int off, int len) throws IOException
29	{
30		this.payload = new byte[len];
31		System.arraycopy(payload, off, this.payload, 0, len);
32
33		TypesReader tr = new TypesReader(payload, off, len);
34
35		int packet_type = tr.readByte();
36
37		if (packet_type != Packets.SSH_MSG_USERAUTH_REQUEST)
38			throw new IOException("This is not a SSH_MSG_USERAUTH_REQUEST! (" + packet_type + ")");
39
40		userName = tr.readString();
41		serviceName = tr.readString();
42
43		String method = tr.readString();
44
45		if (method.equals("none") == false)
46			throw new IOException("This is not a SSH_MSG_USERAUTH_REQUEST with type none!");
47
48		if (tr.remain() != 0)
49			throw new IOException("Padding in SSH_MSG_USERAUTH_REQUEST packet!");
50	}
51
52	public byte[] getPayload()
53	{
54		if (payload == null)
55		{
56			TypesWriter tw = new TypesWriter();
57			tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST);
58			tw.writeString(userName);
59			tw.writeString(serviceName);
60			tw.writeString("none");
61			payload = tw.getBytes();
62		}
63		return payload;
64	}
65}
66