Skip to content

Commit c2b879d

Browse files
committed
Fix PONG response frame from client side.
As stated in RFC 6455 - 5.1 all frames from client side must be masked. Fixes V825-006.
1 parent 8274eb0 commit c2b879d

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/core/aws-net-websocket-protocol-rfc6455.adb

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Ada Web Server --
33
-- --
4-
-- Copyright (C) 2012-2017, AdaCore --
4+
-- Copyright (C) 2012-2022, AdaCore --
55
-- --
66
-- This library is free software; you can redistribute it and/or modify --
77
-- it under terms of the GNU General Public License as published by the --
@@ -673,12 +673,21 @@ package body AWS.Net.WebSocket.Protocol.RFC6455 is
673673

674674
Error_Code_Needed : constant Boolean :=
675675
Opcd = O_Connection_Close and then Error > 0;
676-
677676
Frame_Length : constant Stream_Element_Offset :=
678677
Data'Length + (if Error_Code_Needed then 2 else 0);
678+
From_Client : constant Boolean := Socket.Is_Client_Side;
679+
Mask : Masking_Key;
680+
Mask_Pos : Masking_Key_Index := 0;
679681

680682
begin
681-
Send_Frame_Header (Protocol, Socket, Opcd, Frame_Length);
683+
if From_Client then
684+
Mask := Create_Random_Mask;
685+
end if;
686+
687+
Send_Frame_Header
688+
(Protocol, Socket, Opcd, Frame_Length,
689+
Has_Mask => From_Client,
690+
Mask => Mask);
682691

683692
-- Send the 2-byte error code for close control frame
684693

@@ -697,7 +706,22 @@ package body AWS.Net.WebSocket.Protocol.RFC6455 is
697706

698707
-- Send payload
699708

700-
Net.Buffered.Write (Socket, Data);
709+
if From_Client then
710+
declare
711+
D : Stream_Element_Array (Data'Range);
712+
begin
713+
for Idx in Data'Range loop
714+
D (Idx) := Data (Idx)
715+
xor Mask (Stream_Element_Offset (Mask_Pos));
716+
Mask_Pos := Mask_Pos + 1;
717+
end loop;
718+
719+
Net.Buffered.Write (Socket, D);
720+
end;
721+
722+
else
723+
Net.Buffered.Write (Socket, Data);
724+
end if;
701725

702726
Net.Buffered.Flush (Socket);
703727
end Send_Frame;

0 commit comments

Comments
 (0)