1 package ch.ethz.ssh2.packets; 2 3 import java.io.IOException ; 4 5 11 public class PacketUserauthRequestPassword 12 { 13 byte[] payload; 14 15 String userName; 16 String serviceName; 17 String password; 18 19 public PacketUserauthRequestPassword(String serviceName, String user, String pass) 20 { 21 this.serviceName = serviceName; 22 this.userName = user; 23 this.password = pass; 24 } 25 26 public PacketUserauthRequestPassword(byte payload[], int off, int len) throws IOException  27 { 28 this.payload = new byte[len]; 29 System.arraycopy(payload, off, this.payload, 0, len); 30 31 TypesReader tr = new TypesReader(payload, off, len); 32 33 int packet_type = tr.readByte(); 34 35 if (packet_type != Packets.SSH_MSG_USERAUTH_REQUEST) 36 throw new IOException ("This is not a SSH_MSG_USERAUTH_REQUEST! (" + packet_type + ")"); 37 38 userName = tr.readString(); 39 serviceName = tr.readString(); 40 41 String method = tr.readString(); 42 43 if (method.equals("password") == false) 44 throw new IOException ("This is not a SSH_MSG_USERAUTH_REQUEST with type password!"); 45 46 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("password"); 61 tw.writeBoolean(false); 62 tw.writeString(password); 63 payload = tw.getBytes(); 64 } 65 return payload; 66 } 67 } 68 | Popular Tags |