50,528
社区成员
发帖
与我相关
我的任务
分享
String authMode ="eap-tls";
RadiusAuthenticator authenticator = RadiusClient.getAuthProtocol(authMode);
if(authenticator instanceof EAPTLSAuthenticator) {
final String CERT_FILE_PATH = "/home/Khevz/Desktop/";
EAPTLSAuthenticator eapTlsAuth = (EAPTLSAuthenticator)authenticator;
// client cert
eapTlsAuth.setKeyFileType("pkcs12");
eapTlsAuth.setKeyFile(CERT_FILE_PATH + "client.p12");
eapTlsAuth.setKeyPassword("password");
// ca cert
eapTlsAuth.setCaFileType("pkcs12");
eapTlsAuth.setCaFile(CERT_FILE_PATH+"ca.p12");
eapTlsAuth.setCaPassword("password");
//eapTlsAuth.setTrustAll(true);
}
RadiusClient radClient = null;
try {
InetAddress host = InetAddress.getByName("localhost");
radClient = new RadiusClient(host, "password", 1812, 1813, 10);
}
catch(Exception se) {
}
AttributeList attrs = new AttributeList();
attrs.add(new Attr_UserName("Devices"));
attrs.add(new Attr_NASPortType(Attr_NASPortType.Wireless80211));
attrs.add(new Attr_NASPort(new Long(1)));
//attrs.add(new Attr_UserPassword("password")); // not for eap-tls
AccessRequest accessRequest = new AccessRequest(radClient, attrs);
accessRequest.addAttribute(new Attr_UserPassword("password"));
RadiusPacket reply = null;
try {
// RadiusClient.authenticate() handles authenticators
// processChallenge that throws exception by default except
// EAPAuthenticator.
if(authenticator instanceof EAPAuthenticator) {
reply = radClient.authenticate(accessRequest, authenticator, 5);
}
else {
authenticator.setupRequest(radClient, accessRequest);
authenticator.processRequest(accessRequest);
InetAddress host = null;
try {
host = InetAddress.getByName("localhost");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
reply = radClient.sendReceive(accessRequest, host, 1812, 5);
}
}
catch(RadiusException e) {
}
if(reply==null) {
System.out.println("reply is null");
return;
}
String replyMessage = (String) reply.getAttributeValue(Attr_ReplyMessage.TYPE);
System.out.println("reply: "+replyMessage);
if (reply instanceof AccessReject) {
}
else if (reply instanceof AccessAccept) {
}
else if( reply instanceof AccessChallenge) {
}
}
}