AccessRequest extends RadiusPacket { protected String createMSCHAPV2Response(String username, byte[] password, byte ident, byte[] ntResponse, byte[] peerChallenge, byte[] authenticator) { byte[] authResponse = Authenticator.GenerateAuthenticatorResponse( password, ntResponse, peerChallenge, authenticator, username.getBytes() ); System.err.println("authResponse (" + RadiusUtils.byteArrayToHexString(authResponse) + ")"); String successResponse = (char)ident + "S=" + RadiusUtils.byteArrayToHexString(authResponse).toUpperCase(); System.err.println("successResponse (" + successResponse + ")"); return successResponse; } AccessRequest();  AccessRequest(String userName, String userPassword); void setUserName(String userName); void setUserPassword(String userPassword); String getUserPassword(); byte[] getChapChallenge(); byte[] getPeerChallenge(); byte[] getNtResponse(); String getUserName(); String getAuthProtocol(); void setAuthProtocol(String authProtocol); boolean verifyPassword(String plaintext); boolean verifyMSChapV2Password(String password); void addMSCHAPV2Response(RadiusPacket responsePacket, String secret); static final String AUTH_PAP; static final String AUTH_CHAP; static final String AUTH_MSCHAPV2; }
@Test public void it_correctly_generates_mschapv2_responses() throws RadiusException { String username = "gerhard"; String password = "test12345"; byte[] authenticatorChallenge = {(byte)0x84, (byte)0x9B, (byte)0x32, (byte)0xDD, (byte)0xFB, (byte)0x96, (byte)0x0, (byte)0x95, (byte)0x17, (byte)0x32, (byte)0x7D, (byte)0x3C, (byte)0x2D, (byte)0x33, (byte)0x63, (byte)0x5A, }; AccessRequest accessRequest = new AccessRequest(); byte ident = 0x01; byte[] ntResponse = {(byte)0x8D,(byte)0xF1,(byte)0x2E,(byte)0xAE,(byte)0x74,(byte)0x7,(byte)0xEB,(byte)0x6A,(byte)0x31,(byte)0x58,(byte)0x16,(byte)0x2A,(byte)0xB0,(byte)0x7F,(byte)0xDD,(byte)0x98,(byte)0xDC,(byte)0x84,(byte)0xAA,(byte)0x80,(byte)0xB8,(byte)0x5F,(byte)0x96,(byte)0x9E,}; System.err.println("ntResponse (" + RadiusUtils.byteArrayToHexString(ntResponse) + ")"); byte[] peerChallenge = {(byte)0x45, (byte)0xC1, (byte)0x27, (byte)0x66, (byte)0x91, (byte)0x19, (byte)0x68, (byte)0xA5, (byte)0x1F, (byte)0xD3, (byte)0x8C, (byte)0xA8, (byte)0xD1, (byte)0x6F, (byte)0x7F, (byte)0xA4, }; System.err.println("peerChallenge (" + RadiusUtils.byteArrayToHexString(peerChallenge) + ")"); String mschapResponse = accessRequest.createMSCHAPV2Response(username, password.getBytes(), ident, ntResponse, peerChallenge, authenticatorChallenge); byte[] expectedDigest = {(byte)0xDB, (byte)0x28, (byte)0xF4, (byte)0xEC, (byte)0x5E, (byte)0xD9, (byte)0x3, (byte)0x2A, (byte)0x40, (byte)0x75, (byte)0xEB, (byte)0x31, (byte)0x22, (byte)0xB6, (byte)0x69, (byte)0xA6, (byte)0x9B, (byte)0x7E, (byte)0xE1, (byte)0xCC, }; System.err.println("expectedDigest (" + RadiusUtils.byteArrayToHexString(expectedDigest) + ")"); System.err.println("mschapResponse (" + mschapResponse + ")"); byte[] response = {0x01, 0x53, 0x3D, 0x44, 0x42, 0x32, 0x38, 0x46, 0x34, 0x45, 0x43, 0x35, 0x45, 0x44, 0x39, 0x30, 0x33, 0x32, 0x41, 0x34, 0x30, 0x37, 0x35, 0x45, 0x42, 0x33, 0x31, 0x32, 0x32, 0x42, 0x36, 0x36, 0x39, 0x41, 0x36, 0x39, 0x42, 0x37, 0x45, 0x45, 0x31, 0x43, 0x43, }; System.err.println("response (" + RadiusUtils.byteArrayToHexString(response) + ")"); }