📄 authpacket.java
字号:
package com.ibm.atp.auth;/* * @(#)AuthPacket.java * * IBM Confidential-Restricted * * OCO Source Materials * * 03L7246 (c) Copyright IBM Corp. 1996, 1998 * * The source code for this program is not published or otherwise * divested of its trade secrets, irrespective of what has been * deposited with the U.S. Copyright Office. */import java.security.AccessController;import java.security.PrivilegedAction;import com.ibm.awb.misc.Resource;import com.ibm.awb.misc.URIEncoder;import com.ibm.awb.misc.Hexadecimal;// import java.io.InputStream;import java.io.OutputStream;import java.io.DataInputStream;import java.io.DataInput;import java.io.IOException;import java.net.Socket;import java.net.InetAddress;import java.util.Calendar;import java.util.Date;import java.util.Vector;import java.util.Enumeration;import java.util.StringTokenizer;import java.security.Certificate;import com.ibm.atp.AtpConstants;import com.ibm.aglet.system.AgletRuntime;import org.aglets.log.*;/** * The <tt>AuthPacket</tt> class is the challenge-response authentication * packet class. * * @version 1.00 $Date: 2002/02/20 22:17:18 $ * @author ONO Kouichi */public class AuthPacket extends Object { // Logging private final static LogCategory log = LogInitializer.getCategory( AuthPacket.class.getName() ); /** * carriage return & line feed */ protected final static String CRLF = "\r\n"; /** * end of packet */ protected final static String END_OF_PACKET = "."; /** * Authentication protocol version */ protected final static String AUTHENTICATION_PROTOCOL_VERSION = "AUTH/0.1"; /** * Field separator */ protected final static String FIELD_SEPARATOR = ":"; /** * Identifier of aglet server */ protected final static String SERVERID_FIELDNAME = "Server-ID"; /** * Security Domain */ protected final static String DOMAIN_SEPARATOR = ","; protected final static String DOMAINS_FIELDNAME = "Domains"; protected final static String DOMAIN_FIELDNAME = "Domain"; /** * Authentication manner */ protected final static String AUTH_MANNER_FIELDNAME = "AuthManner"; protected final static String AUTH_MANNER_DIGEST = "DIGEST"; protected final static String AUTH_MANNER_SIGNATURE = "SIGNATURE"; /** * Challenge */ protected final static String CHALLENGE_FIELDNAME = "Challenge"; /** * Response */ protected final static String RESPONSE_FIELDNAME = "Response"; /** * Identifier of aglet server */ private static String SERVERID = null; private String _serverid = null; /** * verbose */ private static boolean verbose = false; static { Resource res = Resource.getResourceFor("system"); if (res != null) { verbose = res.getBoolean("verbose", false); } if (SERVERID == null) { StringBuffer buf = new StringBuffer(); String serveraddress = null; String ownerName = null; String date = null; AgletRuntime runtime = AgletRuntime.getAgletRuntime(); if (runtime != null) { serveraddress = runtime.getServerAddress(); ownerName = runtime.getOwnerName(); } Calendar cal = Calendar.getInstance(); Date time = cal.getTime(); long mills = time.getTime(); date = Hexadecimal.valueOf(mills); buf.append(serveraddress); buf.append(":"); buf.append(ownerName); buf.append(":"); buf.append(date); SERVERID = buf.toString(); } } /** * Step of authentication protocol */ protected final static String STEP_START = "AUTH_START"; protected final static String STEP_FIRST_TURN = "AUTH_FIRST_TURN"; protected final static String STEP_SECOND_TURN = "AUTH_SECOND_TURN"; protected final static String STEP_END = "AUTH_END"; /** * */ private int _step = Authentication.STEP_NOT_AUTHENTICATED; /** * Status of authentication */ private int _status = Authentication.STATUS_NORMAL; /** * Security domain */ // - private String[] _domains = null; private Vector _domains = null; private String _domain = null; /** * Authentication manner */ private int _manner = AtpConstants.NO_AUTHENTICATION_MANNER; /** * Challenge */ private Challenge _challenge = null; /** * ByteSequence */ private Response _response = null; /** * Constructor for sending packet * @param step step of authentication protocol * @param status status of authentication protocol * @param domain security domain name * @param manner authenticatoin manner by challenge-response * @param challenge challenge for authentication * @param response response of challenge */ public AuthPacket(int step, int status, String domain, int manner, Challenge challenge, Response response) { setServerID(SERVERID); setStep(step); setStatus(status); setSecurityDomain(domain); setAuthManner(manner); setChallenge(challenge); setResponse(response); } /** * Constructor for sending packet * @param step step of authentication protocol * @param status status of authentication protocol * @param domains security domain names * @param manner authenticatoin manner by challenge-response * @param challenge challenge for authentication * @param response response of challenge */ public AuthPacket(int step, int status, Enumeration domains, int manner, Challenge challenge, Response response) { setServerID(SERVERID); setStep(step); setStatus(status); setSecurityDomains(domains); setAuthManner(manner); setChallenge(challenge); setResponse(response); } // /** // * Constructor for receiving packet // * @param in input stream for packet // */ // public AuthPacket(InputStream in) { // try { // readFrom(in); // } // catch(IOException excpt) { // clear(); // } // } // // /** // * Constructor for receiving packet // * @param topLine top line of packet // * @param in input stream for packet // */ // public AuthPacket(String topLine, InputStream in) { // try { // readFrom(topLine, in); // } // catch(IOException excpt) { // clear(); // } // } // /** * Constructor for receiving packet * @param in data input stream for packet */ public AuthPacket(DataInput di) { try { readFrom(di); } catch (IOException excpt) { System.err.println("IOException : " + excpt); clear(); } } /** * Clear */ private final void clear() { _step = Authentication.STEP_NOT_AUTHENTICATED; _status = Authentication.STATUS_NORMAL; _domains = null; _domain = null; _manner = AtpConstants.NO_AUTHENTICATION_MANNER; _challenge = null; _response = null; } private static String decode(String str) { if (str == null) { return null; } String s = null; try { final String fStr = str; s = (String)AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return URIEncoder.decode(fStr); } }); } catch (Exception ex) { ex.printStackTrace(); } return s; } private static String encode(String str) { if (str == null) { return null; } String s = null; try { final String fStr = str; s = (String)AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return URIEncoder.encode(fStr); } }); } catch (Exception ex) { ex.printStackTrace(); } return s; } /** * Gets authentication manner. * @return authentication manner */ public final int getAuthManner() { return _manner; } /** * Gets authentication manner field. * @return authentication manner field */ protected final String getAuthMannerField() { String str = toAuthMannerString(_manner); if (str != null) { str = AUTH_MANNER_FIELDNAME + FIELD_SEPARATOR + " " + str; } return str; } /** * Gets challenge. * @return challenge */ public final Challenge getChallenge() { return _challenge; } /** * Gets challenge field. * @return challenge field */ protected final String getChallengeField() { String str = null; if (_challenge != null) { str = CHALLENGE_FIELDNAME + FIELD_SEPARATOR + " " + _challenge.toString(); } return str; } /** * Gets response to challenge. * @return response to challenge */ public final Response getResponse() { return _response; } /** * Gets response to challenge field. * @return response to challenge field */ protected final String getResponseField() { String str = null; if (_response != null) { str = RESPONSE_FIELDNAME + FIELD_SEPARATOR + " " + _response.toString(); } return str; } /** * Gets security domain name. * @return security domain name */ public final String getSecurityDomain() { return _domain; } /** * Gets security domain field. * @return security domain field */ protected final String getSecurityDomainField() { String str = null; if (_domain != null) { str = DOMAIN_FIELDNAME + FIELD_SEPARATOR + " " + _domain; } return str; } /** * Gets security domain name list. * @return security domain name list (URI encoded) */ public final String getSecurityDomainList() { Enumeration domains = getSecurityDomains(); if (domains == null) { return null; } StringBuffer buf = new StringBuffer(); boolean bFirst = true; while (domains.hasMoreElements()) { String domainName = (String)domains.nextElement(); if (!bFirst) { buf.append(DOMAIN_SEPARATOR); } buf.append(encode(domainName)); bFirst = false; } return buf.toString(); } /** * Gets security domain names. * @return security domain names */ public final Enumeration getSecurityDomains() { if (_domains == null) { return null; } return _domains.elements(); } /** * Gets security domains field. * @return security domains field */ protected final String getSecurityDomainsField() { String str = null; String domainlist = getSecurityDomainList(); if (domainlist != null) { str = DOMAINS_FIELDNAME + FIELD_SEPARATOR + " " + domainlist; } return str; } /** * Gets server ID. * @return server ID */ public final String getServerID() { return _serverid; } /** * Gets server ID field. * @return server ID field */ protected final String getServerIDField() { String str = null; if (_serverid != null) { str = SERVERID_FIELDNAME + FIELD_SEPARATOR + " " + _serverid; } return str; } /** * Gets authentication status. * @return authentication status */ public final int getStatus() { return _status; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -