@@ -213,6 +213,7 @@ impl StunAgent {
213
213
}
214
214
}
215
215
} else {
216
+ // XXX: may need to return this as 'Unvalididated'.
216
217
debug ! ( "no remote credentials, ignoring" ) ;
217
218
self . outstanding_requests
218
219
. insert ( msg. transaction_id ( ) , request) ;
@@ -935,6 +936,45 @@ pub(crate) mod tests {
935
936
assert ! ( !agent. is_validated_peer( remote_addr) ) ;
936
937
}
937
938
939
+ #[ test]
940
+ fn agent_response_without_credentials ( ) {
941
+ init ( ) ;
942
+ let local_addr = "10.0.0.1:12345" . parse ( ) . unwrap ( ) ;
943
+ let remote_addr = "10.0.0.2:3478" . parse ( ) . unwrap ( ) ;
944
+
945
+ let mut agent = StunAgent :: builder ( TransportType :: Udp , local_addr) . build ( ) ;
946
+ let local_credentials = ShortTermCredentials :: new ( String :: from ( "local_password" ) ) ;
947
+ agent. set_local_credentials ( local_credentials. clone ( ) . into ( ) ) ;
948
+
949
+ let mut msg = Message :: builder_request ( BINDING ) ;
950
+ let transaction_id = msg. transaction_id ( ) ;
951
+ msg. add_message_integrity ( & local_credentials. into ( ) , IntegrityAlgorithm :: Sha1 )
952
+ . unwrap ( ) ;
953
+ let transmit = agent. send ( msg, remote_addr) . unwrap ( ) ;
954
+
955
+ let request = Message :: from_bytes ( & transmit. data ) . unwrap ( ) ;
956
+
957
+ let mut response = Message :: builder_success ( & request) ;
958
+ response
959
+ . add_attribute ( & XorMappedAddress :: new (
960
+ transmit. from ,
961
+ request. transaction_id ( ) ,
962
+ ) )
963
+ . unwrap ( ) ;
964
+
965
+ let data = response. build ( ) ;
966
+ let to = transmit. to ;
967
+ let response = Message :: from_bytes ( & data) . unwrap ( ) ;
968
+ let reply = agent. handle_stun ( response, to) ;
969
+ // reply is ignored as it does not have credentials
970
+ assert ! ( matches!( reply, HandleStunReply :: Drop ) ) ;
971
+ assert ! ( agent. request_transaction( transaction_id) . is_some( ) ) ;
972
+ assert ! ( agent. mut_request_transaction( transaction_id) . is_some( ) ) ;
973
+
974
+ // unvalidated peer data should be dropped
975
+ assert ! ( !agent. is_validated_peer( remote_addr) ) ;
976
+ }
977
+
938
978
#[ test]
939
979
fn response_with_incorrect_credentials ( ) {
940
980
init ( ) ;
0 commit comments