亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? accessrequest.java

?? TinyRadius is a simple, small and fast Java Radius library capable of sending and receiving Radius
?? JAVA
字號:
/**
 * $Id: AccessRequest.java,v 1.3 2005/11/17 18:36:34 wuttke Exp $
 * Created on 08.04.2005
 * @author Matthias Wuttke
 * @version $Revision: 1.3 $
 */
package org.tinyradius.packet;

import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.tinyradius.attribute.RadiusAttribute;
import org.tinyradius.attribute.StringAttribute;
import org.tinyradius.util.RadiusException;
import org.tinyradius.util.RadiusUtil;

/**
 * This class represents an Access-Request Radius packet.
 */
public class AccessRequest extends RadiusPacket {

	/**
	 * Passphrase Authentication Protocol
	 */
	public static final String AUTH_PAP = "pap";
	
	/**
	 * Challenged Handshake Authentication Protocol
	 */
	public static final String AUTH_CHAP = "chap";

	/**
	 * Constructs an empty Access-Request packet.
	 */
	public AccessRequest() {
		super();
	}
	
	/**
	 * Constructs an Access-Request packet, sets the
	 * code, identifier and adds an User-Name and an
	 * User-Password attribute (PAP).
	 * @param userName user name
	 * @param userPassword user password
	 */
	public AccessRequest(String userName, String userPassword) {
		super(ACCESS_REQUEST, getNextPacketIdentifier());
		setUserName(userName);
		setUserPassword(userPassword);
	}
	
	/**
	 * Sets the User-Name attribute of this Access-Request.
	 * @param userName user name to set
	 */
	public void setUserName(String userName) {
		if (userName == null)
			throw new NullPointerException("user name not set");
		if (userName.length() == 0)
			throw new IllegalArgumentException("empty user name not allowed");
		
		removeAttributes(USER_NAME);
		addAttribute(new StringAttribute(USER_NAME, userName));		
	}
	
	/**
	 * Sets the plain-text user password.
	 * @param userPassword user password to set
	 */
	public void setUserPassword(String userPassword) {
		if (userPassword == null || userPassword.length() == 0)
			throw new IllegalArgumentException("password is empty");
		this.password = userPassword;
	}
	
	/**
	 * Retrieves the plain-text user password.
	 * Returns null for CHAP - use verifyPassword().
	 * @see #verifyPassword(String)
	 * @return user password
	 */
	public String getUserPassword() {
		return password;
	}
	
	/**
	 * Retrieves the user name from the User-Name attribute.
	 * @return user name
	 */
	public String getUserName() {
		List attrs = getAttributes(USER_NAME);
		if (attrs.size() < 1 || attrs.size() > 1)
			throw new RuntimeException("exactly one User-Name attribute required");
		
		RadiusAttribute ra = (RadiusAttribute)attrs.get(0);
		return ((StringAttribute)ra).getAttributeValue();
	}
	
	/**
	 * Returns the protocol used for encrypting the passphrase.
	 * @return AUTH_PAP or AUTH_CHAP
	 */
	public String getAuthProtocol() {
		return authProtocol;
	}

	/**
	 * Selects the protocol to use for encrypting the passphrase when
	 * encoding this Radius packet.
	 * @param authProtocol AUTH_PAP or AUTH_CHAP
	 */
	public void setAuthProtocol(String authProtocol) {
		if (authProtocol != null && (authProtocol.equals(AUTH_PAP) || authProtocol.equals(AUTH_CHAP)))
			this.authProtocol = authProtocol;
		else
			throw new IllegalArgumentException("protocol must be pap or chap");
	}
	
	/**
	 * Verifies that the passed plain-text password matches the password
	 * (hash) send with this Access-Request packet. Works with both PAP
	 * and CHAP.
	 * @param plaintext
	 * @return true if the password is valid, false otherwise
	 */
	public boolean verifyPassword(String plaintext) 
	throws RadiusException {
		if (plaintext == null || plaintext.length() == 0)
			throw new IllegalArgumentException("password is empty");
		if (getAuthProtocol().equals(AUTH_CHAP))
			return verifyChapPassword(plaintext);
		else
			return getUserPassword().equals(plaintext);
	}

	/**
	 * Decrypts the User-Password attribute.
	 * @see org.tinyradius.packet.RadiusPacket#decodeRequestAttributes(java.lang.String)
	 */
	protected void decodeRequestAttributes(String sharedSecret) 
	throws RadiusException {
		// detect auth protocol 
		RadiusAttribute userPassword = getAttribute(USER_PASSWORD);
		RadiusAttribute chapPassword = getAttribute(CHAP_PASSWORD);
		RadiusAttribute chapChallenge = getAttribute(CHAP_CHALLENGE);
		
		if (userPassword != null) {
			setAuthProtocol(AUTH_PAP);
			this.password = decodePapPassword(userPassword.getAttributeData(), RadiusUtil.getUtf8Bytes(sharedSecret));
			// copy truncated data
			userPassword.setAttributeData(RadiusUtil.getUtf8Bytes(this.password));
		} else if (chapPassword != null && chapChallenge != null) {
			setAuthProtocol(AUTH_CHAP);
			this.chapPassword = chapPassword.getAttributeData();
			this.chapChallenge = chapChallenge.getAttributeData();
		} else
			throw new RadiusException("Access-Request: User-Password or CHAP-Password/CHAP-Challenge missing");
	}

	/**
	 * Sets and encrypts the User-Password attribute.
	 * @see org.tinyradius.packet.RadiusPacket#encodeRequestAttributes(java.lang.String)
	 */
	protected void encodeRequestAttributes(String sharedSecret) {
		if (password == null || password.length() == 0)
			return;
			// ok for proxied packets whose CHAP password is already encrypted
			//throw new RuntimeException("no password set");
		
		if (getAuthProtocol().equals(AUTH_PAP)) {
			byte[] pass = encodePapPassword(RadiusUtil.getUtf8Bytes(this.password), RadiusUtil.getUtf8Bytes(sharedSecret));
			removeAttributes(USER_PASSWORD);
			addAttribute(new RadiusAttribute(USER_PASSWORD, pass));
		} else if (getAuthProtocol().equals(AUTH_CHAP)) {
			byte[] challenge = createChapChallenge();
			byte[] pass = encodeChapPassword(password, challenge);
			removeAttributes(CHAP_PASSWORD);
			removeAttributes(CHAP_CHALLENGE);
			addAttribute(new RadiusAttribute(CHAP_PASSWORD, pass));
			addAttribute(new RadiusAttribute(CHAP_CHALLENGE, challenge));
		}
	}

	/**
	 * This method encodes the plaintext user password according to RFC 2865.
	 * @param userPass the password to encrypt
	 * @param sharedSecret shared secret
	 * @return the byte array containing the encrypted password
	 */
	private byte[] encodePapPassword(final byte[] userPass, byte[] sharedSecret) {
	    // the password must be a multiple of 16 bytes and less than or equal
	    // to 128 bytes. If it isn't a multiple of 16 bytes fill it out with zeroes
	    // to make it a multiple of 16 bytes. If it is greater than 128 bytes
	    // truncate it at 128.
	    byte[] userPassBytes = null;
	    if (userPass.length > 128){
	        userPassBytes = new byte[128];
	        System.arraycopy(userPass, 0, userPassBytes, 0, 128);
	    } else {
	        userPassBytes = userPass;
	    }
	    
	    // declare the byte array to hold the final product
	    byte[] encryptedPass = null;
	    if (userPassBytes.length < 128) {
	        if (userPassBytes.length % 16 == 0) {
	            // tt is already a multiple of 16 bytes
	            encryptedPass = new byte[userPassBytes.length];
	        } else {
	            // make it a multiple of 16 bytes
	            encryptedPass = new byte[((userPassBytes.length / 16) * 16) + 16];
	        }
	    } else {
	        // the encrypted password must be between 16 and 128 bytes
	        encryptedPass = new byte[128];
	    }
	
	    // copy the userPass into the encrypted pass and then fill it out with zeroes
	    System.arraycopy(userPassBytes, 0, encryptedPass, 0, userPassBytes.length);
	    for (int i = userPassBytes.length; i < encryptedPass.length; i++) {
	        encryptedPass[i] = 0;
	    }
	
	    // digest shared secret and authenticator
	    MessageDigest md5 = getMd5Digest();
	    md5.reset();
	    md5.update(sharedSecret);
	    md5.update(getAuthenticator());
	    byte bn[] = md5.digest();
	
	    // perform the XOR as specified by RFC 2865
	    for (int i = 0; i < 16; i++){
	        encryptedPass[i] = (byte)(bn[i] ^ encryptedPass[i]);
	    }
	
	    if (encryptedPass.length > 16) {
	        for (int i = 16; i < encryptedPass.length; i += 16) {
	            md5.reset();
	            md5.update(sharedSecret);
	            // add the previous (encrypted) 16 bytes of the user password
	            md5.update(encryptedPass, i - 16, 16);
	            bn = md5.digest();
	
	            // perform the XOR as specified by RFC 2865.
	            for (int j = 0; j < 16; j++) {
	                encryptedPass[i + j] = (byte)(bn[j] ^ encryptedPass[i + j]);
	            }
	        }
	    }
	    
	    return encryptedPass;
	}

	/**
	 * Decodes the passed encrypted password and returns the clear-text form.
	 * @param encryptedPass encrypted password
	 * @param sharedSecret shared secret
	 * @return decrypted password
	 */
	private String decodePapPassword(byte[] encryptedPass, byte[] sharedSecret) 
	throws RadiusException {
		if (encryptedPass == null || encryptedPass.length < 16) {
			// PAP passwords require at least 16 bytes
			logger.warn("invalid Radius packet: User-Password attribute with malformed PAP password, length = " +
					encryptedPass.length + ", but length must be greater than 15");
			throw new RadiusException("malformed User-Password attribute");
		}
		
		MessageDigest md5 = getMd5Digest();
	    md5.reset();
	    md5.update(sharedSecret);
	    md5.update(getAuthenticator());
	    byte bn[] = md5.digest();
	
	    // perform the XOR as specified by RFC 2865
	    for (int i = 0; i < 16; i++){
	        encryptedPass[i] = (byte)(bn[i] ^ encryptedPass[i]);
	    }
	
	    if (encryptedPass.length > 16) {
	        for (int i = 16; i < encryptedPass.length; i += 16) {
	            md5.reset();
	            md5.update(sharedSecret);
	            // add the previous (encrypted) 16 bytes of the user password
	            md5.update(encryptedPass, i - 16, 16);
	            bn = md5.digest();
	
	            // perform the XOR as specified by RFC 2865.
	            for (int j = 0; j < 16; j++) {
	                encryptedPass[i + j] = (byte)(bn[j] ^ encryptedPass[i + j]);
	            }
	        }
	    }
	    
	    // remove trailing zeros
	    int len = encryptedPass.length;
	    while (len > 0 && encryptedPass[len - 1] == 0)
	    	len--;
	    byte[] passtrunc = new byte[len];
	    System.arraycopy(encryptedPass, 0, passtrunc, 0, len);
	    
	    // convert to string
	   return RadiusUtil.getStringFromUtf8(passtrunc);
	}
	
	/**
	 * Creates a random CHAP challenge using a secure random algorithm.
	 * @return 16 byte CHAP challenge
	 */
	private byte[] createChapChallenge() {
		byte[] challenge = new byte[16];
		random.nextBytes(challenge);
		return challenge;
	}
	
	/**
	 * Encodes a plain-text password using the given CHAP challenge.
	 * @param plaintext plain-text password
	 * @param chapChallenge CHAP challenge
	 * @return CHAP-encoded password
	 */
	private byte[] encodeChapPassword(String plaintext, byte[] chapChallenge) {
        // see RFC 2865 section 2.2
        byte chapIdentifier = (byte)random.nextInt(256);
        byte[] chapPassword = new byte[17];
        chapPassword[0] = chapIdentifier;

        MessageDigest md5 = getMd5Digest();
        md5.reset();
        md5.update(chapIdentifier);
        md5.update(RadiusUtil.getUtf8Bytes(plaintext));
        byte[] chapHash = md5.digest(chapChallenge);

        System.arraycopy(chapHash, 0, chapPassword, 1, 16);
        return chapPassword;
	}

	/**
	 * Verifies a CHAP password against the given plaintext password.
	 * @return plain-text password
	 */
	private boolean verifyChapPassword(String plaintext) 
	throws RadiusException {
		if (plaintext == null || plaintext.length() == 0)
			throw new IllegalArgumentException("plaintext must not be empty");
		if (chapChallenge == null || chapChallenge.length != 16)
			throw new RadiusException("CHAP challenge must be 16 bytes");
		if (chapPassword == null || chapPassword.length != 17)
			throw new RadiusException("CHAP password must be 17 bytes");
		
		byte chapIdentifier = chapPassword[0];
		MessageDigest md5 = getMd5Digest();
	    md5.reset();
	    md5.update(chapIdentifier);
	    md5.update(RadiusUtil.getUtf8Bytes(plaintext));
	    byte[] chapHash = md5.digest(chapChallenge);
	    
	    // compare
	    for (int i = 0; i < 16; i++)
	    	if (chapHash[i] != chapPassword[i + 1])
	    		return false;
	    return true;
	}
	
	/**
     * Temporary storage for the unencrypted User-Password
     * attribute.
     */
    private String password;
    
    /**
     * Authentication protocol for this access request.
     */
    private String authProtocol = AUTH_PAP;

	/**
	 * CHAP password from a decoded CHAP Access-Request.
	 */
	private byte[] chapPassword;

	/**
	 * CHAP challenge from a decoded CHAP Access-Request.
	 */
	private byte[] chapChallenge;

	/**
	 * Random generator
	 */
	private static SecureRandom random = new SecureRandom();
	
    /**
     * Radius type code for Radius attribute User-Name
     */
	private static final int USER_NAME = 1;

	/**
	 * Radius attribute type for User-Password attribute.
	 */
	private static final int USER_PASSWORD = 2;

	/**
	 * Radius attribute type for CHAP-Password attribute.
	 */
	private static final int CHAP_PASSWORD = 3;
	
	/**
	 * Radius attribute type for CHAP-Challenge attribute.
	 */
	private static final int CHAP_CHALLENGE = 60;
	
	/**
	 * Logger for logging information about malformed packets
	 */
	private static Log logger = LogFactory.getLog(AccessRequest.class);
		
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
懂色av一区二区三区蜜臀| 久久人人爽人人爽| 亚洲精品成人a在线观看| 99riav一区二区三区| 亚洲色图一区二区| 欧美性生活一区| 亚洲va天堂va国产va久| 欧美日韩另类国产亚洲欧美一级| 调教+趴+乳夹+国产+精品| 51久久夜色精品国产麻豆| 美女一区二区视频| 久久精品视频一区二区| jlzzjlzz亚洲日本少妇| 亚洲综合色噜噜狠狠| 欧美成人三级在线| 成人综合婷婷国产精品久久蜜臀| 亚洲色图在线视频| 在线综合亚洲欧美在线视频| 久久av老司机精品网站导航| 国产三级精品三级在线专区| 色哟哟欧美精品| 美腿丝袜一区二区三区| 欧美激情一区在线| 国产亚洲综合性久久久影院| 色悠悠久久综合| 久久精品久久精品| 亚洲欧洲日韩在线| 日韩一级二级三级| 91在线视频在线| 精品一区二区三区久久| 国产精品国产三级国产aⅴ无密码 国产精品国产三级国产aⅴ原创 | 图片区日韩欧美亚洲| 欧美成va人片在线观看| 99精品视频免费在线观看| 日韩经典一区二区| 中文字幕在线观看不卡| 4438x亚洲最大成人网| 粉嫩av一区二区三区粉嫩| 亚洲h在线观看| 亚洲婷婷国产精品电影人久久| 日韩写真欧美这视频| 91色在线porny| 国内成人精品2018免费看| 亚洲国产精品自拍| 国产精品免费视频观看| 欧美一区二区三区四区五区| 99久久久久免费精品国产| 国产一区二区不卡在线| 琪琪久久久久日韩精品| 国产露脸91国语对白| 亚洲国产成人av| 中文av一区特黄| 精品国产区一区| 337p亚洲精品色噜噜狠狠| 99国产精品久| 成人黄色综合网站| 国产在线日韩欧美| 精品一区二区三区在线观看国产| 亚洲制服丝袜一区| 一区二区三区免费看视频| 中文在线一区二区| 精品国产凹凸成av人网站| 91亚洲午夜精品久久久久久| 色爱区综合激月婷婷| 九九视频精品免费| 91黄色免费版| 日韩精品一区第一页| 91影院在线免费观看| 国产不卡免费视频| 国产伦精品一区二区三区在线观看| 一区二区三区欧美| 亚洲美女视频在线| 成人免费在线观看入口| 国产精品嫩草影院av蜜臀| 午夜伊人狠狠久久| 亚洲欧美一区二区三区孕妇| 国产亚洲成aⅴ人片在线观看| 国产亚洲欧美日韩俺去了| 精品福利av导航| www国产精品av| 久久久久一区二区三区四区| 久久一留热品黄| 久久综合色天天久久综合图片| 日韩一区二区三区视频在线 | 国产在线观看免费一区| 视频一区二区欧美| 偷窥国产亚洲免费视频| 日韩电影网1区2区| 久久99精品视频| 国产99一区视频免费| 国产91丝袜在线播放九色| 国产成人免费在线视频| 成人网男人的天堂| 99久久伊人精品| 色狠狠色狠狠综合| 7777女厕盗摄久久久| 久久综合久久99| 国产精品网站在线| 亚洲一区中文日韩| 青青草97国产精品免费观看无弹窗版 | 精品成人在线观看| 国产日产欧美一区| 亚洲人成在线播放网站岛国| 亚洲综合视频在线| 久久精品久久综合| 欧美色图在线观看| 色呦呦一区二区三区| 欧美日韩视频在线一区二区| 亚洲女人****多毛耸耸8| 一区二区三区在线看| 五月综合激情婷婷六月色窝| 国产在线精品不卡| 在线观看免费成人| 精品国产髙清在线看国产毛片| 中国色在线观看另类| 亚洲自拍与偷拍| 激情综合网天天干| 色94色欧美sute亚洲线路二| 欧美一区日韩一区| 中文字幕av免费专区久久| 亚洲国产一区二区a毛片| 黄色资源网久久资源365| 91免费版在线看| 久久综合久久综合久久综合| 亚洲欧美日韩中文字幕一区二区三区| 日韩精品一区第一页| 成人aa视频在线观看| 91精品国产日韩91久久久久久| 久久久久久一二三区| 亚洲国产你懂的| 国产mv日韩mv欧美| 欧美一区二区三区免费| 亚洲乱码国产乱码精品精可以看 | 精品国产91乱码一区二区三区 | 青青青爽久久午夜综合久久午夜| 不卡一二三区首页| 欧美一级淫片007| 亚洲美女少妇撒尿| 国产成人av一区二区三区在线 | 自拍偷拍欧美激情| 激情综合一区二区三区| 在线不卡免费欧美| 一区二区在线观看av| 国产成人免费高清| 精品国产91亚洲一区二区三区婷婷 | 欧美日免费三级在线| 国产精品不卡在线| 国产福利精品一区二区| 精品少妇一区二区三区免费观看 | 亚洲日本中文字幕区| 国模无码大尺度一区二区三区| 欧美日韩一级片在线观看| 亚洲欧美视频一区| 99久久久久久| 亚洲国产精品成人综合色在线婷婷 | 亚洲精品精品亚洲| 成人av电影免费观看| 中文字幕巨乱亚洲| 国产成人亚洲综合a∨婷婷| 日韩一区二区在线观看| 日本最新不卡在线| 欧美一区二区三区啪啪| 日韩精品久久理论片| 欧美日韩国产综合草草| 亚洲国产裸拍裸体视频在线观看乱了| 日韩限制级电影在线观看| 日韩极品在线观看| 日韩欧美一二三四区| 久久不见久久见免费视频7| 日韩一区国产二区欧美三区| 蜜臀va亚洲va欧美va天堂| 欧美成人女星排行榜| 老司机午夜精品99久久| 精品成人免费观看| 国产乱码一区二区三区| 久久久久久一二三区| 波多野结衣中文字幕一区 | 91福利视频网站| 亚洲欧美另类小说| 欧美日韩在线电影| 青青草国产精品97视觉盛宴| 精品成人私密视频| 成人综合婷婷国产精品久久| 国产精品久久久久7777按摩| 色哟哟亚洲精品| 日韩高清不卡一区二区三区| 欧美一卡在线观看| 国产一本一道久久香蕉| 国产日产欧美一区| 日本韩国欧美在线| 日日夜夜精品视频天天综合网| 日韩欧美中文字幕公布| 国产不卡高清在线观看视频| 中文字幕欧美一区| 在线成人午夜影院| 国产麻豆一精品一av一免费| 国产精品久久网站| 欧美日韩一区二区三区视频| 久久99国产精品尤物| 国产精品女主播在线观看|