|Two Way Authentication Plugin Overview|
Securely verify a password known in advance by a pair of systems
Normally with RakNet you can transmit data securely using secure connections. However, sometimes a pair of systems may not have secure connections active. For example, on mobiles the security code may take too much memory, be too slow, or not compile. In this case you can still verify a remote system using a password known to two systems in advance. RakNet implements this using two way authentication. Instead of sending the password itself, a one way hash of the password is sent. The hash is verified as correct or not, and the results returned to the user.
// Attach the plugin to an instance of RakPeerInterface
If the other system is also running the two way authentication plugin, and had also set the same password, you will get ID_TWO_WAY_AUTHENTICATION_INCOMING_CHALLENGE_SUCCESS and the other system will get ID_TWO_WAY_AUTHENTICATION_OUTGOING_CHALLENGE_SUCCESS. If the other system is running the plugin but has a different password, they will get ID_TWO_WAY_AUTHENTICATION_INCOMING_CHALLENGE_FAILURE and you will get ID_TWO_WAY_AUTHENTICATION_OUTGOING_CHALLENGE_FAILURE. If the other system is not running the plugin you will get ID_TWO_WAY_AUTHENTICATION_OUTGOING_CHALLENGE_TIMEOUT.
In the case of
RakNet::BitStream bs(packet->data, packet->length, false);
All this system does is verify a password between two parties. It does not enable or disable any RakNet features, or prevent any other message from being sent during the challenge phase. However, you can pair this plugin with the MessageFilter plugin so that a new connection cannot send any other messages until validated. To do so, attach the MessageFilter plugin to RakPeerInterface before this one (actually it should be first). Call MessageFilter::SetAutoAddNewConnectionsToFilter() so that new connections are filtered. Make sure that the two way authentication messages are allowed on that same filter channel by calling MessageFilter::SetAllowMessageID(). When a connection has been validated, change the channel for that system using MessageFilter::SetSystemFilterSet().
See Samples/TwoWayAuthentication for a complete sample. See TwoWayAuthentication.h for a complete list of all documented functions and parameters.
Message Filter plugin