introduce-LWS_WRITE_CLIENT_IGNORE_XOR_MASK.patch
authorAndy Green <andy@warmcat.com>
Sun, 30 Jan 2011 08:24:31 +0000 (08:24 +0000)
committerAndy Green <andy@warmcat.com>
Sun, 30 Jan 2011 08:24:31 +0000 (08:24 +0000)
Signed-off-by: Andy Green <andy@warmcat.com>
lib/libwebsockets.h
lib/parsers.c

index f68a4a3..5700a04 100644 (file)
@@ -47,7 +47,15 @@ enum libwebsocket_write_protocol {
        LWS_WRITE_PING,
        LWS_WRITE_PONG,
 
-       LWS_WRITE_NO_FIN = 0x40
+       /* flags */
+
+       LWS_WRITE_NO_FIN = 0x40,
+       /*
+        * client packet payload goes out on wire unmunged
+        * only useful for security tests since normal servers cannot
+        * decode the content if used
+        */
+       LWS_WRITE_CLIENT_IGNORE_XOR_MASK = 0x80
 };
 
 struct libwebsocket;
index 64d7fb1..a97e75a 100644 (file)
@@ -1131,19 +1131,27 @@ int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf,
 
        if (wsi->client_mode && wsi->ietf_spec_revision == 4) {
 
-               if (libwebsocket_04_frame_mask_generate(wsi)) {
-                       fprintf(stderr, "libwebsocket_write: "
-                                             "frame mask generation failed\n");
-                       return 1;
-               }
-
                /*
-                * use the XOR masking against everything we send
-                * past the frame nonce
+                * this is only useful for security tests where it's required
+                * to control the raw packet payload content
                 */
 
-               for (n = 0; n < (len + pre + post); n++)
-                       buf[n - pre] = xor_mask(wsi, buf[n - pre]);
+               if (!(protocol & LWS_WRITE_CLIENT_IGNORE_XOR_MASK)) {
+
+                       if (libwebsocket_04_frame_mask_generate(wsi)) {
+                               fprintf(stderr, "libwebsocket_write: "
+                                             "frame mask generation failed\n");
+                               return 1;
+                       }
+
+                       /*
+                        * use the XOR masking against everything we send
+                        * past the frame nonce
+                        */
+
+                       for (n = 0; n < (len + pre + post); n++)
+                               buf[n - pre] = xor_mask(wsi, buf[n - pre]);
+               }
 
                /* make space for the frame nonce in clear */
                pre += 4;