Home | History | Annotate | Download | only in packets
      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  * PacketUserauthRequestPublicKey.
     11  *
     12  * @author Christian Plattner
     13  * @version 2.50, 03/15/10
     14  */
     15 public class PacketUserauthRequestPublicKey
     16 {
     17 	byte[] payload;
     18 
     19 	String userName;
     20 	String serviceName;
     21 	String password;
     22 	String pkAlgoName;
     23 	byte[] pk;
     24 	byte[] sig;
     25 
     26 	public PacketUserauthRequestPublicKey(String serviceName, String user,
     27 			String pkAlgorithmName, byte[] pk, byte[] sig)
     28 	{
     29 		this.serviceName = serviceName;
     30 		this.userName = user;
     31 		this.pkAlgoName = pkAlgorithmName;
     32 		this.pk = pk;
     33 		this.sig = sig;
     34 	}
     35 
     36 	public PacketUserauthRequestPublicKey(byte payload[], int off, int len) throws IOException
     37 	{
     38 		this.payload = new byte[len];
     39 		System.arraycopy(payload, off, this.payload, 0, len);
     40 
     41 		TypesReader tr = new TypesReader(payload, off, len);
     42 
     43 		int packet_type = tr.readByte();
     44 
     45 		if (packet_type != Packets.SSH_MSG_USERAUTH_REQUEST)
     46 			throw new IOException("This is not a SSH_MSG_USERAUTH_REQUEST! ("
     47 					+ packet_type + ")");
     48 
     49 		throw new IOException("Not implemented!");
     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("publickey");
     61 			tw.writeBoolean(true);
     62 			tw.writeString(pkAlgoName);
     63 			tw.writeString(pk, 0, pk.length);
     64 			tw.writeString(sig, 0, sig.length);
     65 			payload = tw.getBytes();
     66 		}
     67 		return payload;
     68 	}
     69 }
     70