联想天工 802.1x认证 报文响应

package ZClient;
import java.io.ByteArrayInputStream;
import java.util.EventListener;
import java.util.Scanner;
import javax.swing.event.EventListenerList;
import jpcap.PacketReceiver;
import jpcap.packet.Packet;
import ZClient.EAPSender.EAPNameExcetion;

/**
 * A 802.1x packet process class
 * @author Lingle<p>
 * Email: mea08@126.com<p>
 */
public class PacketProc implements PacketReceiver{

	private final static byte EAP_SUCCESS=3;//data[4]
	private final static byte EAP_FAILURE=4;
	private final static byte EAP_REQUEST=1;//data[4],data[8]
	private byte authCode;//Extensible Authentication Protocol Code: 1 Request
	private byte authType;//Extensible Authentication Protocol Type: 1 Identity
	private byte id;
	private EAPSender eapSender =null;
	private static String messsage =null;
	private byte[] attachkey=new byte[16];
	private EventListenerList listeners =null;
	
	public interface EAPListener extends EventListener {
		public void pktRecivedAction(String messsage);
		public void successEventAction();
		public void failureEventAction();
	}
	public void addEapListener(EAPListener listener) {
		if (listeners==null) {
			listeners=new EventListenerList();
		}
		listeners.add(EAPListener.class, listener);
	}
	private void notifyEapRecived(String messsage) {
		for (EAPListener listener: listeners.getListeners(EAPListener.class)) {
			listener.pktRecivedAction(messsage);
		}
	}
	private void notifyEapSuccess() {
		for (EAPListener listener: listeners.getListeners(EAPListener.class)) {
			listener.successEventAction();
		}
	}
	private void notifyEapFailure() {
		for (EAPListener listener: listeners.getListeners(EAPListener.class)) {
			listener.failureEventAction();
		}
	}
	
	public PacketProc(EAPSender sender) {
		this.eapSender=sender;
	}

@Override
	public void receivePacket(Packet p) {
		id=p.data[5];
		authCode=p.data[4];
		authType=p.data[8];
		System.arraycopy(p.data, 10, attachkey, 0, attachkey.length);
		if (authCode==EAP_SUCCESS){
			messsage="EAP_SUCCESS";
			eapSender.sendEapOnline();
			this.notifyEapSuccess();
		}
		if (authCode==EAP_FAILURE) {
			if(p.data[12]!=0){
				byte[] msg=new byte[p.data[12]];
				System.arraycopy(p.data, 13, msg, 0, msg.length);
				messsage=new Scanner(new ByteArrayInputStream(msg)).nextLine();
				this.notifyEapFailure();
			}
		}
		if (authCode == EAP_REQUEST) {
			if (authType == EAP_REQUEST) {
				try {
					eapSender.sendEapName(id);
					messsage="Send EAP_USERNAME";
				} catch (EAPNameExcetion e) {
					messsage=e.getMessage();
				}
			} else {
				try {
					eapSender.sendEapPassWord(id, attachkey);
					messsage="Send EAP_PASSWORD";
				} catch (EAPNameExcetion e) {
					messsage=e.getMessage();
				}
			}
		}
		this.notifyEapRecived(messsage);
	}
}

转载于:https://my.oschina.net/u/212925/blog/106848

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值