I am implementing a radius proxy with a help of TinyRadius lib. PAP & CHAP proxying without any problems but EAP messages not. So, i am recalculate Request Authenticator for radius packet after adding a proxy attribute, then i recalculate Message-Authenticator according to RFC3579.
And there is two question:
According to RFC3579: Message-Authenticator = HMAC-MD5 (Type, Identifier, Length, Request Authenticator, Attributes)
1) Length=? Is it a length of radius packet or EAP-message?
2) Request Authenticator - this is authenticator for radius packet, am i right? So, if i add it to the Message-Authenticator attribute into the radius packet - radius packet will be changed and i must to recalculate Request Authenticator but if i recalculate Request Authenticator - Message-Authenticator will be invalid because it depends on Request Authenticator.
Shared secrets for clients and endpoint radius server is the same (checked many times).
All i need - is to teach proxy to proxying EAP messages, but always get:
Received Access-Request Id 191 from 192.168.200.250:1814 to 192.168.200.250:10000 length 171
Dropping packet without response because of error: Received packet from 192.168.200.250 with invalid Message-Authenticator! (Shared secret is incorrect.)
UPDATE:
Request-Authentificator generating:
protected byte[] createRequestAuthenticator(String sharedSecret){
MessageDigest md5=getMd5Digest();
md5.reset();
byte[] requestAuthenticator=new byte[16];
Random r=new Random();
for(int i=0;i<16;i++){
requestAuthenticator[i]=(byte)r.nextInt();
}
md5.update(sharedSecret.getBytes(),0,sharedSecret.length());
md5.update(requestAuthenticator,0,requestAuthenticator.length);
return md5.digest();
}
Message-Authenticator generating:
protected byte[] createRFC3579MessageAuthenticator(String sharedSecret,int packetLength,byte[] requestAuthenticator,byte[] attributes){
try{
Mac mac=Mac.getInstance("HmacMD5");
mac.init(new SecretKeySpec(sharedSecret.getBytes(),"HmacMD5"));
mac.update((byte)getPacketType());
mac.update((byte)getPacketIdentifier());
mac.update((byte)(packetLength>>8));
mac.update((byte)(packetLength&0x0ff));
mac.update(requestAuthenticator,0,requestAuthenticator.length);
mac.update(attributes,0,attributes.length);
return mac.doFinal();
}catch(NoSuchAlgorithmException|InvalidKeyException ex){
Logger.getLogger(RadiusPacket.class.getName()).log(Level.SEVERE,null,ex);
return null;
}
}