alias int8 = byte; // -128 — 127 alias int16 = short; // -32768 — 32767 alias int32 = int; // -2147483648 — 2147483647 alias int64 = long; // -9223372036854775808 — 9223372036854775807 alias uint8 = ubyte; // 0 — 255 alias uint16 = ushort; // 0 — 65535 alias uint32 = uint; // 0 — 4294967295 alias uint64 = ulong; // 0 — 18446744073709551615 alias f32 = float; alias f64 = double; // char '\xFF' unsigned 8 bit (UTF-8 code unit) // wchar '\uFFFF' unsigned 16 bit (UTF-16 code unit) // dchar '\U0000FFFF' unsigned 32 bit (UTF-32 code unit) import vibe.core.core; import vibe.http.router; import vibe.http.server; import vibe.http.fileserver; import vibe.http.websockets; import vibe.core.log; import std.stdio; import std.string; import std.array; import std.conv : to; import bert; // https://github.com/221V/dlang_erl_bert https://git.4dev.win/game1/dlang_erl_bert import secured.symmetric; // https://github.com/221V/SecureD // https://github.com/221V/js_AES256CBC import secured.rsa; import session; import mustache; alias MustacheEngine!(string) Mustache; string byte_arr_to_str(ubyte[] arr){ string[] str_arr; foreach(elem; arr){ str_arr ~= to!string(elem); } return "[" ~ str_arr.join(",") ~ "]"; } ubyte[] str_to_byte_arr(string str_arr){ str_arr = str_arr.replace("[", "").replace("]", ""); string[] parts = str_arr.split(","); ubyte[] result; result.reserve(parts.length); foreach(part; parts){ result ~= to!ubyte(part.strip()); } return result; } void ws_bert_handle(scope WebSocket sock){ //foreach(pair; req.headers.byKeyValue()){ // writeln("Header: ", pair.key, " = ", pair.value); //} // simple echo server + :) // https://vibed.org/api/vibe.http.websockets/WebSocket // https://vibed.org/api/vibe.http.websockets/WebSocket.request // https://vibed.org/api/vibe.http.server/HTTPServerRequest //writeln("sock.request = ", sock.request); // GET /ws_login_test HTTP/1.1 //writeln("sock.request.headers = ", sock.request.headers); // ["Host": "127.0.0.1:8080", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:135.0) Gecko/20100101 Firefox/135.0", "Accept": "*/*", "Accept-Language": "uk-UA,uk;q=0.8,en-US;q=0.5,en;q=0.3", "Accept-Encoding": "gzip, deflate, br, zstd", "Sec-WebSocket-Version": "13", "Origin": "http://127.0.0.1:8080", "Sec-WebSocket-Extensions": "permessage-deflate", "Sec-WebSocket-Key": "NW+zQGtSdkuSRHWuU/VevA==", "DNT": "1", "Sec-GPC": "1", "Connection": "keep-alive, Upgrade", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "websocket", "Sec-Fetch-Site": "same-origin", "Pragma": "no-cache", "Cache-Control": "no-cache", "Upgrade": "websocket"] //writeln("sock.request = ", sock.request); //writeln("sock.request.query = ", sock.request.query); // ["client_id": "YaHoAnZo3JPYOwX7yn35"] //string client_id = ""; //if("client_id" in sock.request.query){ // client_id = sock.request.query["client_id"]; //} while(sock.waitForData()){ //auto msg = sock.receiveText(); //sock.send(msg ~ " :)"); auto msg = sock.receiveBinary(); if(msg == "1"){ sock.send("0"); // ws PING - PONG }else{ writeln("Received: ", msg); auto decoder = new BertDecoder( cast(ubyte[])msg.dup ); auto decoded = decoder.decode(); msg_match(decoded, sock); } } // todo delete data in userSessions here } void msg_match(BertValue decoded, WebSocket sock){ writeln("Decoded: ", decoded.toString()); ubyte[] rsa_pub_key0 = [45, 45, 45, 45, 45, 66, 69, 71, 73, 78, 32, 80, 85, 66, 76, 73, 67, 32, 75, 69, 89, 45, 45, 45, 45, 45, 10, 77, 73, 73, 66, 73, 106, 65, 78, 66, 103, 107, 113, 104, 107, 105, 71, 57, 119, 48, 66, 65, 81, 69, 70, 65, 65, 79, 67, 65, 81, 56, 65, 77, 73, 73, 66, 67, 103, 75, 67, 65, 81, 69, 65, 106, 104, 115, 88, 99, 50, 83, 73, 117, 100, 117, 78, 54, 71, 102, 57, 72, 55, 56, 70, 10, 99, 119, 97, 76, 53, 117, 69, 118, 108, 107, 102, 114, 55, 84, 115, 116, 117, 55, 117, 116, 103, 53, 89, 87, 104, 55, 71, 56, 105, 74, 102, 79, 72, 117, 88, 88, 84, 100, 100, 75, 82, 66, 107, 85, 55, 65, 71, 109, 67, 72, 51, 99, 99, 80, 69, 100, 103, 80, 122, 48, 106, 77, 84, 52, 10, 51, 50, 113, 108, 56, 79, 66, 109, 50, 101, 104, 66, 120, 121, 83, 97, 110, 80, 118, 79, 101, 81, 78, 109, 72, 87, 68, 80, 88, 73, 69, 111, 104, 51, 69, 51, 122, 76, 80, 66, 68, 121, 71, 99, 71, 66, 72, 99, 55, 103, 79, 121, 67, 89, 47, 85, 83, 106, 80, 77, 121, 73, 102, 53, 10, 101, 71, 87, 48, 70, 80, 119, 47, 48, 117, 87, 118, 90, 103, 75, 117, 78, 70, 70, 85, 57, 67, 117, 89, 86, 118, 74, 114, 66, 76, 121, 78, 120, 85, 76, 84, 108, 121, 79, 78, 52, 107, 84, 51, 72, 115, 53, 102, 52, 85, 97, 67, 81, 73, 85, 81, 72, 55, 110, 52, 72, 103, 81, 66, 10, 75, 107, 108, 119, 84, 80, 90, 82, 89, 76, 114, 90, 81, 105, 121, 73, 49, 50, 83, 111, 81, 109, 57, 49, 103, 49, 73, 120, 86, 121, 85, 75, 72, 121, 57, 75, 51, 85, 108, 86, 122, 88, 102, 86, 87, 97, 52, 53, 50, 101, 107, 113, 120, 67, 70, 47, 114, 100, 103, 83, 115, 80, 52, 78, 10, 106, 79, 50, 76, 114, 111, 90, 78, 83, 65, 83, 107, 119, 69, 56, 90, 89, 69, 49, 90, 77, 103, 89, 74, 74, 114, 90, 51, 78, 56, 66, 68, 84, 90, 80, 104, 109, 68, 70, 101, 97, 65, 110, 76, 83, 71, 54, 89, 97, 79, 122, 111, 80, 90, 80, 100, 86, 115, 116, 52, 112, 112, 47, 100, 10, 102, 119, 73, 68, 65, 81, 65, 66, 10, 45, 45, 45, 45, 45, 69, 78, 68, 32, 80, 85, 66, 76, 73, 67, 32, 75, 69, 89, 45, 45, 45, 45, 45, 10]; ubyte[] rsa_priv_key0 = [45, 45, 45, 45, 45, 66, 69, 71, 73, 78, 32, 80, 82, 73, 86, 65, 84, 69, 32, 75, 69, 89, 45, 45, 45, 45, 45, 10, 77, 73, 73, 69, 118, 103, 73, 66, 65, 68, 65, 78, 66, 103, 107, 113, 104, 107, 105, 71, 57, 119, 48, 66, 65, 81, 69, 70, 65, 65, 83, 67, 66, 75, 103, 119, 103, 103, 83, 107, 65, 103, 69, 65, 65, 111, 73, 66, 65, 81, 67, 79, 71, 120, 100, 122, 90, 73, 105, 53, 50, 52, 51, 111, 10, 90, 47, 48, 102, 118, 119, 86, 122, 66, 111, 118, 109, 52, 83, 43, 87, 82, 43, 118, 116, 79, 121, 50, 55, 117, 54, 50, 68, 108, 104, 97, 72, 115, 98, 121, 73, 108, 56, 52, 101, 53, 100, 100, 78, 49, 48, 112, 69, 71, 82, 84, 115, 65, 97, 89, 73, 102, 100, 120, 119, 56, 82, 50, 65, 10, 47, 80, 83, 77, 120, 80, 106, 102, 97, 113, 88, 119, 52, 71, 98, 90, 54, 69, 72, 72, 74, 74, 113, 99, 43, 56, 53, 53, 65, 50, 89, 100, 89, 77, 57, 99, 103, 83, 105, 72, 99, 84, 102, 77, 115, 56, 69, 80, 73, 90, 119, 89, 69, 100, 122, 117, 65, 55, 73, 74, 106, 57, 82, 75, 10, 77, 56, 122, 73, 104, 47, 108, 52, 90, 98, 81, 85, 47, 68, 47, 83, 53, 97, 57, 109, 65, 113, 52, 48, 85, 86, 84, 48, 75, 53, 104, 87, 56, 109, 115, 69, 118, 73, 51, 70, 81, 116, 79, 88, 73, 52, 51, 105, 82, 80, 99, 101, 122, 108, 47, 104, 82, 111, 74, 65, 104, 82, 65, 102, 10, 117, 102, 103, 101, 66, 65, 69, 113, 83, 88, 66, 77, 57, 108, 70, 103, 117, 116, 108, 67, 76, 73, 106, 88, 90, 75, 104, 67, 98, 51, 87, 68, 85, 106, 70, 88, 74, 81, 111, 102, 76, 48, 114, 100, 83, 86, 88, 78, 100, 57, 86, 90, 114, 106, 110, 90, 54, 83, 114, 69, 73, 88, 43, 116, 10, 50, 66, 75, 119, 47, 103, 50, 77, 55, 89, 117, 117, 104, 107, 49, 73, 66, 75, 84, 65, 84, 120, 108, 103, 84, 86, 107, 121, 66, 103, 107, 109, 116, 110, 99, 51, 119, 69, 78, 78, 107, 43, 71, 89, 77, 86, 53, 111, 67, 99, 116, 73, 98, 112, 104, 111, 55, 79, 103, 57, 107, 57, 49, 87, 10, 121, 51, 105, 109, 110, 57, 49, 47, 65, 103, 77, 66, 65, 65, 69, 67, 103, 103, 69, 65, 75, 113, 120, 47, 67, 57, 78, 43, 98, 90, 87, 57, 108, 84, 79, 90, 73, 48, 51, 112, 86, 73, 80, 56, 81, 106, 54, 81, 88, 69, 104, 72, 49, 73, 116, 72, 98, 103, 57, 114, 105, 85, 55, 113, 10, 103, 67, 66, 68, 78, 104, 43, 107, 77, 99, 111, 105, 115, 69, 106, 57, 68, 57, 115, 97, 87, 99, 56, 97, 55, 89, 84, 105, 84, 72, 90, 84, 118, 108, 98, 52, 70, 48, 102, 86, 86, 114, 52, 47, 105, 56, 106, 80, 105, 104, 79, 66, 111, 85, 120, 103, 77, 57, 69, 52, 84, 85, 88, 85, 10, 104, 102, 68, 55, 66, 70, 80, 121, 43, 69, 49, 114, 68, 77, 108, 85, 75, 102, 101, 86, 87, 80, 77, 81, 84, 100, 101, 70, 81, 80, 76, 85, 116, 78, 50, 43, 87, 116, 47, 101, 98, 105, 88, 89, 103, 77, 55, 74, 87, 99, 116, 73, 115, 49, 69, 78, 119, 68, 57, 71, 84, 68, 90, 83, 10, 115, 71, 98, 50, 100, 122, 66, 108, 102, 110, 69, 78, 83, 121, 84, 50, 119, 87, 47, 105, 53, 49, 43, 115, 122, 105, 51, 106, 87, 73, 65, 89, 75, 73, 67, 121, 111, 119, 65, 99, 87, 105, 118, 76, 87, 98, 74, 102, 88, 50, 105, 105, 47, 101, 66, 117, 43, 72, 103, 119, 54, 106, 108, 100, 10, 88, 103, 75, 118, 66, 47, 56, 76, 67, 65, 56, 104, 54, 90, 113, 109, 57, 73, 80, 100, 77, 88, 73, 55, 74, 119, 72, 109, 72, 73, 81, 82, 101, 112, 120, 69, 97, 121, 57, 105, 75, 122, 111, 107, 50, 81, 117, 111, 97, 111, 74, 73, 83, 101, 79, 122, 109, 68, 65, 76, 115, 71, 77, 109, 10, 75, 72, 120, 83, 118, 90, 74, 78, 49, 74, 81, 65, 54, 110, 88, 70, 79, 70, 52, 84, 55, 74, 90, 119, 72, 121, 103, 87, 112, 90, 87, 106, 86, 105, 81, 120, 65, 49, 53, 89, 85, 81, 75, 66, 103, 81, 67, 47, 102, 109, 98, 74, 116, 105, 104, 70, 65, 88, 67, 52, 74, 43, 103, 53, 10, 113, 50, 71, 114, 100, 47, 121, 83, 116, 43, 67, 110, 97, 104, 118, 79, 97, 113, 102, 109, 80, 112, 73, 106, 103, 81, 75, 100, 65, 81, 53, 79, 119, 112, 74, 85, 102, 49, 72, 54, 80, 121, 101, 105, 108, 82, 51, 67, 70, 80, 84, 68, 97, 122, 114, 105, 103, 84, 66, 117, 56, 72, 88, 109, 10, 55, 90, 116, 112, 120, 87, 114, 82, 73, 107, 105, 104, 105, 98, 53, 108, 47, 47, 51, 88, 116, 97, 117, 83, 106, 102, 77, 100, 106, 98, 67, 67, 121, 50, 71, 78, 57, 51, 117, 77, 97, 56, 101, 53, 66, 49, 102, 50, 80, 99, 104, 99, 75, 113, 77, 76, 112, 118, 122, 72, 55, 108, 55, 73, 10, 105, 105, 70, 75, 70, 66, 122, 49, 118, 109, 74, 52, 84, 76, 73, 79, 101, 84, 54, 97, 83, 122, 48, 107, 77, 81, 75, 66, 103, 81, 67, 57, 43, 97, 47, 48, 119, 49, 85, 104, 66, 89, 52, 88, 119, 52, 84, 90, 115, 70, 66, 88, 105, 122, 120, 72, 54, 119, 47, 100, 122, 54, 47, 90, 10, 69, 107, 68, 55, 67, 113, 80, 49, 43, 66, 111, 101, 66, 115, 82, 86, 51, 116, 50, 79, 85, 108, 116, 85, 90, 57, 73, 56, 100, 68, 101, 47, 121, 74, 122, 71, 51, 100, 85, 118, 107, 102, 75, 56, 100, 110, 68, 113, 56, 110, 111, 47, 90, 111, 43, 51, 48, 73, 114, 53, 88, 79, 104, 81, 10, 77, 85, 89, 73, 79, 51, 43, 116, 106, 107, 54, 102, 83, 69, 76, 57, 55, 43, 73, 121, 56, 65, 103, 120, 103, 86, 108, 101, 81, 51, 109, 87, 79, 77, 120, 89, 57, 79, 116, 71, 100, 73, 84, 85, 115, 47, 100, 99, 49, 82, 81, 99, 68, 65, 120, 115, 117, 76, 114, 68, 105, 73, 101, 103, 10, 81, 117, 103, 99, 71, 113, 52, 103, 114, 119, 75, 66, 103, 81, 67, 109, 73, 43, 106, 83, 81, 84, 83, 88, 67, 106, 84, 100, 48, 101, 72, 116, 104, 118, 47, 113, 89, 79, 80, 70, 57, 55, 114, 50, 66, 86, 50, 121, 114, 86, 54, 87, 113, 78, 114, 112, 54, 116, 104, 49, 108, 54, 68, 117, 10, 80, 71, 110, 119, 51, 98, 89, 109, 81, 47, 48, 68, 86, 104, 84, 72, 101, 112, 56, 82, 110, 85, 115, 116, 107, 97, 67, 80, 52, 66, 105, 114, 68, 113, 79, 48, 70, 82, 65, 106, 43, 110, 98, 66, 107, 70, 121, 99, 54, 111, 107, 50, 83, 101, 120, 100, 55, 115, 74, 114, 100, 97, 56, 98, 10, 67, 53, 72, 77, 78, 108, 102, 43, 56, 78, 81, 76, 101, 73, 43, 99, 109, 79, 88, 111, 56, 83, 85, 99, 121, 118, 105, 117, 68, 101, 89, 50, 88, 52, 71, 97, 88, 47, 68, 119, 86, 81, 110, 105, 68, 99, 105, 43, 80, 102, 116, 79, 113, 116, 67, 86, 81, 81, 75, 66, 103, 81, 67, 119, 10, 86, 76, 101, 114, 101, 106, 114, 106, 52, 97, 73, 89, 69, 74, 83, 89, 56, 102, 120, 65, 112, 97, 52, 89, 71, 117, 105, 112, 79, 52, 75, 43, 43, 121, 66, 120, 89, 49, 106, 52, 106, 52, 97, 43, 90, 65, 50, 77, 110, 115, 89, 75, 117, 103, 113, 110, 100, 52, 52, 43, 75, 113, 107, 115, 10, 83, 43, 113, 111, 56, 51, 74, 84, 75, 121, 97, 104, 73, 49, 90, 47, 51, 80, 122, 51, 75, 66, 48, 120, 119, 108, 71, 99, 84, 48, 52, 97, 85, 81, 72, 116, 49, 106, 119, 87, 80, 99, 90, 103, 78, 100, 82, 111, 109, 50, 88, 98, 88, 99, 120, 100, 70, 118, 66, 54, 102, 67, 113, 52, 10, 56, 112, 78, 74, 53, 108, 115, 84, 70, 69, 102, 79, 110, 104, 82, 49, 105, 66, 109, 89, 82, 116, 54, 112, 99, 51, 86, 50, 49, 74, 122, 43, 100, 100, 117, 51, 97, 108, 82, 66, 90, 81, 75, 66, 103, 68, 110, 105, 110, 116, 90, 43, 81, 49, 111, 52, 98, 90, 102, 105, 122, 83, 113, 65, 10, 114, 122, 115, 43, 50, 112, 88, 87, 51, 97, 78, 71, 52, 108, 82, 76, 76, 104, 113, 67, 98, 53, 48, 73, 81, 114, 107, 73, 66, 119, 90, 47, 48, 69, 80, 75, 72, 66, 121, 112, 103, 81, 86, 54, 117, 119, 102, 71, 115, 117, 75, 114, 114, 119, 55, 107, 83, 103, 70, 121, 88, 67, 122, 113, 10, 74, 103, 73, 112, 55, 121, 43, 48, 84, 107, 101, 57, 112, 113, 90, 84, 65, 116, 75, 101, 69, 100, 56, 86, 66, 71, 110, 97, 104, 90, 75, 54, 111, 116, 55, 97, 43, 49, 85, 98, 99, 80, 51, 121, 120, 69, 104, 71, 104, 77, 76, 84, 77, 101, 116, 77, 88, 111, 102, 100, 103, 110, 48, 98, 10, 88, 51, 113, 47, 107, 77, 56, 68, 55, 71, 119, 89, 77, 89, 77, 104, 98, 99, 112, 43, 100, 49, 115, 99, 10, 45, 45, 45, 45, 45, 69, 78, 68, 32, 80, 82, 73, 86, 65, 84, 69, 32, 75, 69, 89, 45, 45, 45, 45, 45, 10]; /* ubyte[] encrypted_msg0 = [119, 158, 137, 248, 226, 99, 195, 180, 23, 139, 131, 171, 82, 201, 107, 173, 179, 9, 97, 170, 172, 199, 55, 186, 210, 63, 50, 36, 153, 118, 173, 4, 244, 81, 127, 220, 138, 131, 93, 207, 161, 100, 17, 239, 62, 250, 215, 142, 11, 76, 56, 137, 138, 200, 113, 193, 253, 60, 93, 151, 26, 12, 115, 48, 188, 207, 213, 135, 28, 145, 149, 140, 176, 8, 255, 129, 231, 102, 187, 210, 31, 192, 138, 109, 108, 184, 78, 254, 140, 63, 188, 166, 196, 53, 200, 234, 26, 113, 177, 44, 248, 242, 41, 94, 122, 218, 232, 191, 240, 44, 167, 50, 182, 42, 17, 110, 59, 192, 138, 145, 9, 172, 242, 97, 116, 4, 0, 101, 87, 169, 209, 171, 221, 230, 156, 147, 146, 143, 171, 54, 94, 197, 248, 53, 177, 156, 59, 123, 198, 163, 204, 95, 79, 13, 212, 107, 32, 186, 180, 31, 217, 14, 233, 207, 157, 44, 163, 3, 16, 194, 69, 179, 114, 75, 236, 132, 140, 5, 100, 134, 23, 47, 59, 48, 122, 215, 177, 111, 225, 165, 241, 120, 153, 28, 16, 26, 152, 75, 9, 236, 193, 12, 12, 230, 86, 45, 49, 235, 170, 53, 58, 62, 84, 238, 0, 168, 190, 135, 155, 177, 18, 235, 214, 48, 146, 181, 17, 187, 123, 224, 54, 134, 109, 233, 90, 11, 85, 156, 144, 18, 216, 226, 138, 136, 59, 130, 46, 222, 155, 80, 80, 77, 107, 195, 83, 30]; auto rsa_keypair0 = new RSA(rsa_priv_key0, null); ubyte[] decrypted_msg = rsa_keypair0.decrypt(encrypted_msg0); //writeln("decrypted_msg = ", decrypted_msg); writeln("decrypted_msg = ", cast(string)decrypted_msg); */ auto rsa_keypair = new RSA(2048); // Only allows for (2048/8)-42 = 214 bytes to be asymmetrically RSA encrypted scope(exit) rsa_keypair.destroy(); ubyte[] rsa_private_key = rsa_keypair.getPrivateKey(null); ubyte[] rsa_public_key = rsa_keypair.getPublicKey(); //writeln("rsa_private_key = ", rsa_private_key); // [45, 45, 45, 45, 45, 66, 69, 71, 73, 78, 32, 80, 82, 73, 86, 65, 84, 69, 32, 75, 69, 89, 45, 45, 45, 45, 45, 10, 77, 73, 73, 69, 118, 103, 73, 66, 65, 68, 65, 78, 66, 103, 107, 113, 104, 107, 105, 71, 57, 119, 48, 66, 65, 81, 69, 70, 65, 65, 83, 67, 66, 75, 103, 119, 103, 103, 83, 107, 65, 103, 69, 65, 65, 111, 73, 66, 65, 81, 67, 79, 71, 120, 100, 122, 90, 73, 105, 53, 50, 52, 51, 111, 10, 90, 47, 48, 102, 118, 119, 86, 122, 66, 111, 118, 109, 52, 83, 43, 87, 82, 43, 118, 116, 79, 121, 50, 55, 117, 54, 50, 68, 108, 104, 97, 72, 115, 98, 121, 73, 108, 56, 52, 101, 53, 100, 100, 78, 49, 48, 112, 69, 71, 82, 84, 115, 65, 97, 89, 73, 102, 100, 120, 119, 56, 82, 50, 65, 10, 47, 80, 83, 77, 120, 80, 106, 102, 97, 113, 88, 119, 52, 71, 98, 90, 54, 69, 72, 72, 74, 74, 113, 99, 43, 56, 53, 53, 65, 50, 89, 100, 89, 77, 57, 99, 103, 83, 105, 72, 99, 84, 102, 77, 115, 56, 69, 80, 73, 90, 119, 89, 69, 100, 122, 117, 65, 55, 73, 74, 106, 57, 82, 75, 10, 77, 56, 122, 73, 104, 47, 108, 52, 90, 98, 81, 85, 47, 68, 47, 83, 53, 97, 57, 109, 65, 113, 52, 48, 85, 86, 84, 48, 75, 53, 104, 87, 56, 109, 115, 69, 118, 73, 51, 70, 81, 116, 79, 88, 73, 52, 51, 105, 82, 80, 99, 101, 122, 108, 47, 104, 82, 111, 74, 65, 104, 82, 65, 102, 10, 117, 102, 103, 101, 66, 65, 69, 113, 83, 88, 66, 77, 57, 108, 70, 103, 117, 116, 108, 67, 76, 73, 106, 88, 90, 75, 104, 67, 98, 51, 87, 68, 85, 106, 70, 88, 74, 81, 111, 102, 76, 48, 114, 100, 83, 86, 88, 78, 100, 57, 86, 90, 114, 106, 110, 90, 54, 83, 114, 69, 73, 88, 43, 116, 10, 50, 66, 75, 119, 47, 103, 50, 77, 55, 89, 117, 117, 104, 107, 49, 73, 66, 75, 84, 65, 84, 120, 108, 103, 84, 86, 107, 121, 66, 103, 107, 109, 116, 110, 99, 51, 119, 69, 78, 78, 107, 43, 71, 89, 77, 86, 53, 111, 67, 99, 116, 73, 98, 112, 104, 111, 55, 79, 103, 57, 107, 57, 49, 87, 10, 121, 51, 105, 109, 110, 57, 49, 47, 65, 103, 77, 66, 65, 65, 69, 67, 103, 103, 69, 65, 75, 113, 120, 47, 67, 57, 78, 43, 98, 90, 87, 57, 108, 84, 79, 90, 73, 48, 51, 112, 86, 73, 80, 56, 81, 106, 54, 81, 88, 69, 104, 72, 49, 73, 116, 72, 98, 103, 57, 114, 105, 85, 55, 113, 10, 103, 67, 66, 68, 78, 104, 43, 107, 77, 99, 111, 105, 115, 69, 106, 57, 68, 57, 115, 97, 87, 99, 56, 97, 55, 89, 84, 105, 84, 72, 90, 84, 118, 108, 98, 52, 70, 48, 102, 86, 86, 114, 52, 47, 105, 56, 106, 80, 105, 104, 79, 66, 111, 85, 120, 103, 77, 57, 69, 52, 84, 85, 88, 85, 10, 104, 102, 68, 55, 66, 70, 80, 121, 43, 69, 49, 114, 68, 77, 108, 85, 75, 102, 101, 86, 87, 80, 77, 81, 84, 100, 101, 70, 81, 80, 76, 85, 116, 78, 50, 43, 87, 116, 47, 101, 98, 105, 88, 89, 103, 77, 55, 74, 87, 99, 116, 73, 115, 49, 69, 78, 119, 68, 57, 71, 84, 68, 90, 83, 10, 115, 71, 98, 50, 100, 122, 66, 108, 102, 110, 69, 78, 83, 121, 84, 50, 119, 87, 47, 105, 53, 49, 43, 115, 122, 105, 51, 106, 87, 73, 65, 89, 75, 73, 67, 121, 111, 119, 65, 99, 87, 105, 118, 76, 87, 98, 74, 102, 88, 50, 105, 105, 47, 101, 66, 117, 43, 72, 103, 119, 54, 106, 108, 100, 10, 88, 103, 75, 118, 66, 47, 56, 76, 67, 65, 56, 104, 54, 90, 113, 109, 57, 73, 80, 100, 77, 88, 73, 55, 74, 119, 72, 109, 72, 73, 81, 82, 101, 112, 120, 69, 97, 121, 57, 105, 75, 122, 111, 107, 50, 81, 117, 111, 97, 111, 74, 73, 83, 101, 79, 122, 109, 68, 65, 76, 115, 71, 77, 109, 10, 75, 72, 120, 83, 118, 90, 74, 78, 49, 74, 81, 65, 54, 110, 88, 70, 79, 70, 52, 84, 55, 74, 90, 119, 72, 121, 103, 87, 112, 90, 87, 106, 86, 105, 81, 120, 65, 49, 53, 89, 85, 81, 75, 66, 103, 81, 67, 47, 102, 109, 98, 74, 116, 105, 104, 70, 65, 88, 67, 52, 74, 43, 103, 53, 10, 113, 50, 71, 114, 100, 47, 121, 83, 116, 43, 67, 110, 97, 104, 118, 79, 97, 113, 102, 109, 80, 112, 73, 106, 103, 81, 75, 100, 65, 81, 53, 79, 119, 112, 74, 85, 102, 49, 72, 54, 80, 121, 101, 105, 108, 82, 51, 67, 70, 80, 84, 68, 97, 122, 114, 105, 103, 84, 66, 117, 56, 72, 88, 109, 10, 55, 90, 116, 112, 120, 87, 114, 82, 73, 107, 105, 104, 105, 98, 53, 108, 47, 47, 51, 88, 116, 97, 117, 83, 106, 102, 77, 100, 106, 98, 67, 67, 121, 50, 71, 78, 57, 51, 117, 77, 97, 56, 101, 53, 66, 49, 102, 50, 80, 99, 104, 99, 75, 113, 77, 76, 112, 118, 122, 72, 55, 108, 55, 73, 10, 105, 105, 70, 75, 70, 66, 122, 49, 118, 109, 74, 52, 84, 76, 73, 79, 101, 84, 54, 97, 83, 122, 48, 107, 77, 81, 75, 66, 103, 81, 67, 57, 43, 97, 47, 48, 119, 49, 85, 104, 66, 89, 52, 88, 119, 52, 84, 90, 115, 70, 66, 88, 105, 122, 120, 72, 54, 119, 47, 100, 122, 54, 47, 90, 10, 69, 107, 68, 55, 67, 113, 80, 49, 43, 66, 111, 101, 66, 115, 82, 86, 51, 116, 50, 79, 85, 108, 116, 85, 90, 57, 73, 56, 100, 68, 101, 47, 121, 74, 122, 71, 51, 100, 85, 118, 107, 102, 75, 56, 100, 110, 68, 113, 56, 110, 111, 47, 90, 111, 43, 51, 48, 73, 114, 53, 88, 79, 104, 81, 10, 77, 85, 89, 73, 79, 51, 43, 116, 106, 107, 54, 102, 83, 69, 76, 57, 55, 43, 73, 121, 56, 65, 103, 120, 103, 86, 108, 101, 81, 51, 109, 87, 79, 77, 120, 89, 57, 79, 116, 71, 100, 73, 84, 85, 115, 47, 100, 99, 49, 82, 81, 99, 68, 65, 120, 115, 117, 76, 114, 68, 105, 73, 101, 103, 10, 81, 117, 103, 99, 71, 113, 52, 103, 114, 119, 75, 66, 103, 81, 67, 109, 73, 43, 106, 83, 81, 84, 83, 88, 67, 106, 84, 100, 48, 101, 72, 116, 104, 118, 47, 113, 89, 79, 80, 70, 57, 55, 114, 50, 66, 86, 50, 121, 114, 86, 54, 87, 113, 78, 114, 112, 54, 116, 104, 49, 108, 54, 68, 117, 10, 80, 71, 110, 119, 51, 98, 89, 109, 81, 47, 48, 68, 86, 104, 84, 72, 101, 112, 56, 82, 110, 85, 115, 116, 107, 97, 67, 80, 52, 66, 105, 114, 68, 113, 79, 48, 70, 82, 65, 106, 43, 110, 98, 66, 107, 70, 121, 99, 54, 111, 107, 50, 83, 101, 120, 100, 55, 115, 74, 114, 100, 97, 56, 98, 10, 67, 53, 72, 77, 78, 108, 102, 43, 56, 78, 81, 76, 101, 73, 43, 99, 109, 79, 88, 111, 56, 83, 85, 99, 121, 118, 105, 117, 68, 101, 89, 50, 88, 52, 71, 97, 88, 47, 68, 119, 86, 81, 110, 105, 68, 99, 105, 43, 80, 102, 116, 79, 113, 116, 67, 86, 81, 81, 75, 66, 103, 81, 67, 119, 10, 86, 76, 101, 114, 101, 106, 114, 106, 52, 97, 73, 89, 69, 74, 83, 89, 56, 102, 120, 65, 112, 97, 52, 89, 71, 117, 105, 112, 79, 52, 75, 43, 43, 121, 66, 120, 89, 49, 106, 52, 106, 52, 97, 43, 90, 65, 50, 77, 110, 115, 89, 75, 117, 103, 113, 110, 100, 52, 52, 43, 75, 113, 107, 115, 10, 83, 43, 113, 111, 56, 51, 74, 84, 75, 121, 97, 104, 73, 49, 90, 47, 51, 80, 122, 51, 75, 66, 48, 120, 119, 108, 71, 99, 84, 48, 52, 97, 85, 81, 72, 116, 49, 106, 119, 87, 80, 99, 90, 103, 78, 100, 82, 111, 109, 50, 88, 98, 88, 99, 120, 100, 70, 118, 66, 54, 102, 67, 113, 52, 10, 56, 112, 78, 74, 53, 108, 115, 84, 70, 69, 102, 79, 110, 104, 82, 49, 105, 66, 109, 89, 82, 116, 54, 112, 99, 51, 86, 50, 49, 74, 122, 43, 100, 100, 117, 51, 97, 108, 82, 66, 90, 81, 75, 66, 103, 68, 110, 105, 110, 116, 90, 43, 81, 49, 111, 52, 98, 90, 102, 105, 122, 83, 113, 65, 10, 114, 122, 115, 43, 50, 112, 88, 87, 51, 97, 78, 71, 52, 108, 82, 76, 76, 104, 113, 67, 98, 53, 48, 73, 81, 114, 107, 73, 66, 119, 90, 47, 48, 69, 80, 75, 72, 66, 121, 112, 103, 81, 86, 54, 117, 119, 102, 71, 115, 117, 75, 114, 114, 119, 55, 107, 83, 103, 70, 121, 88, 67, 122, 113, 10, 74, 103, 73, 112, 55, 121, 43, 48, 84, 107, 101, 57, 112, 113, 90, 84, 65, 116, 75, 101, 69, 100, 56, 86, 66, 71, 110, 97, 104, 90, 75, 54, 111, 116, 55, 97, 43, 49, 85, 98, 99, 80, 51, 121, 120, 69, 104, 71, 104, 77, 76, 84, 77, 101, 116, 77, 88, 111, 102, 100, 103, 110, 48, 98, 10, 88, 51, 113, 47, 107, 77, 56, 68, 55, 71, 119, 89, 77, 89, 77, 104, 98, 99, 112, 43, 100, 49, 115, 99, 10, 45, 45, 45, 45, 45, 69, 78, 68, 32, 80, 82, 73, 86, 65, 84, 69, 32, 75, 69, 89, 45, 45, 45, 45, 45, 10] //writeln("rsa_public_key = ", rsa_public_key); // [45, 45, 45, 45, 45, 66, 69, 71, 73, 78, 32, 80, 85, 66, 76, 73, 67, 32, 75, 69, 89, 45, 45, 45, 45, 45, 10, 77, 73, 73, 66, 73, 106, 65, 78, 66, 103, 107, 113, 104, 107, 105, 71, 57, 119, 48, 66, 65, 81, 69, 70, 65, 65, 79, 67, 65, 81, 56, 65, 77, 73, 73, 66, 67, 103, 75, 67, 65, 81, 69, 65, 106, 104, 115, 88, 99, 50, 83, 73, 117, 100, 117, 78, 54, 71, 102, 57, 72, 55, 56, 70, 10, 99, 119, 97, 76, 53, 117, 69, 118, 108, 107, 102, 114, 55, 84, 115, 116, 117, 55, 117, 116, 103, 53, 89, 87, 104, 55, 71, 56, 105, 74, 102, 79, 72, 117, 88, 88, 84, 100, 100, 75, 82, 66, 107, 85, 55, 65, 71, 109, 67, 72, 51, 99, 99, 80, 69, 100, 103, 80, 122, 48, 106, 77, 84, 52, 10, 51, 50, 113, 108, 56, 79, 66, 109, 50, 101, 104, 66, 120, 121, 83, 97, 110, 80, 118, 79, 101, 81, 78, 109, 72, 87, 68, 80, 88, 73, 69, 111, 104, 51, 69, 51, 122, 76, 80, 66, 68, 121, 71, 99, 71, 66, 72, 99, 55, 103, 79, 121, 67, 89, 47, 85, 83, 106, 80, 77, 121, 73, 102, 53, 10, 101, 71, 87, 48, 70, 80, 119, 47, 48, 117, 87, 118, 90, 103, 75, 117, 78, 70, 70, 85, 57, 67, 117, 89, 86, 118, 74, 114, 66, 76, 121, 78, 120, 85, 76, 84, 108, 121, 79, 78, 52, 107, 84, 51, 72, 115, 53, 102, 52, 85, 97, 67, 81, 73, 85, 81, 72, 55, 110, 52, 72, 103, 81, 66, 10, 75, 107, 108, 119, 84, 80, 90, 82, 89, 76, 114, 90, 81, 105, 121, 73, 49, 50, 83, 111, 81, 109, 57, 49, 103, 49, 73, 120, 86, 121, 85, 75, 72, 121, 57, 75, 51, 85, 108, 86, 122, 88, 102, 86, 87, 97, 52, 53, 50, 101, 107, 113, 120, 67, 70, 47, 114, 100, 103, 83, 115, 80, 52, 78, 10, 106, 79, 50, 76, 114, 111, 90, 78, 83, 65, 83, 107, 119, 69, 56, 90, 89, 69, 49, 90, 77, 103, 89, 74, 74, 114, 90, 51, 78, 56, 66, 68, 84, 90, 80, 104, 109, 68, 70, 101, 97, 65, 110, 76, 83, 71, 54, 89, 97, 79, 122, 111, 80, 90, 80, 100, 86, 115, 116, 52, 112, 112, 47, 100, 10, 102, 119, 73, 68, 65, 81, 65, 66, 10, 45, 45, 45, 45, 45, 69, 78, 68, 32, 80, 85, 66, 76, 73, 67, 32, 75, 69, 89, 45, 45, 45, 45, 45, 10] //ubyte[214] plaintext214 = 2; // 2 being an arbitrary value auto plaintext214 = cast(ubyte[])"12345678testтест"; ubyte[] encMessage214 = rsa_keypair.encrypt(plaintext214); //writeln("encMessage214.length = ", encMessage214.length); // 256 //writeln("encMessage214 = ", encMessage214); // [18, 27, 216, 71, 100, 90, 235, 225, 149, 43, 161, 168, 63, 98, 157, 173, 6, 58, 5, 142, 19, 227, 162, 87, 138, 201, 98, 78, 23, 149, 100, 174, 159, 235, 205, 100, 35, 84, 144, 148, 158, 75, 100, 4, 11, 79, 99, 194, 171, 199, 247, 97, 8, 70, 15, 147, 67, 245, 94, 240, 122, 56, 40, 170, 41, 90, 9, 80, 108, 168, 208, 123, 218, 174, 72, 154, 225, 184, 132, 127, 248, 164, 74, 50, 55, 233, 215, 178, 229, 205, 123, 10, 197, 21, 35, 135, 85, 11, 1, 123, 15, 94, 242, 103, 69, 209, 209, 113, 190, 63, 229, 232, 84, 168, 162, 231, 90, 202, 182, 168, 166, 85, 96, 1, 67, 190, 42, 72, 155, 220, 168, 80, 57, 51, 149, 173, 240, 204, 72, 210, 52, 163, 219, 248, 168, 70, 132, 32, 168, 160, 240, 150, 187, 128, 153, 190, 76, 125, 101, 150, 202, 194, 130, 100, 149, 238, 207, 225, 17, 29, 97, 141, 230, 31, 249, 227, 96, 214, 142, 24, 174, 41, 20, 178, 242, 196, 214, 59, 26, 168, 9, 238, 19, 95, 181, 75, 169, 0, 249, 78, 35, 172, 117, 138, 159, 124, 148, 50, 97, 160, 110, 96, 69, 248, 69, 168, 19, 131, 18, 208, 161, 88, 49, 217, 93, 113, 159, 49, 201, 33, 123, 80, 121, 196, 110, 91, 26, 179, 177, 11, 75, 91, 102, 219, 108, 166, 180, 53, 15, 222, 226, 79, 188, 52, 214, 132] ubyte[] decMessage214 = rsa_keypair.decrypt(encMessage214); //writeln("decMessage214 = ", decMessage214); writeln("decMessage214 = ", cast(string)decMessage214); //ubyte[] key; //ubyte[] iv; if(decoded.type_ == BertType.Tuple){ auto decoded1 = decoded.tupleValue; if(decoded1.length == 1){ if(auto num1 = cast(uint8)decoded1[0].intValue){ // we can use js AES for additional password encrypt for login-logout // ws.send(enc(tuple( number(1) ))); if(num1 == 1){ // init login -- get key + iv for encrypt password and send to server /* ubyte[] test_pass = cast(ubyte[])"12345678"; SymmetricKey key = generateSymmetricKey( SymmetricAlgorithm.AES256_CBC ); EncryptedData enc = encrypt(key, test_pass); //auto iv_hex = toHexString!(LetterCase.lower)(enc.iv); //auto encrypt = toHexString!(LetterCase.lower)(enc.cipherText); auto iv_hex = enc.iv; auto encrypt = enc.cipherText; writeln("Key: ", key.key); //writeln("Key: ", key.toString); // base64 encoded string //writeln("IV: ", toHexString!(LetterCase.lower)(enc.iv)); writeln("IV: ", iv_hex); //writeln("Encrypt: ", enc); writeln("Encrypt: ", encrypt); */ SymmetricKeyIV rand_key_iv = generateSymmetricKeyIV(); // default SymmetricAlgorithm.AES256_CBC writeln("rand key: ", rand_key_iv.key); writeln("rand iv: ", rand_key_iv.iv); string client_id = generateCookie(); userSessions[client_id ~ "_key"] = rand_key_iv.key; userSessions[client_id ~ "_iv"] = rand_key_iv.iv; /* //auto test_pass = cast(ubyte[])"12345678"; auto test_pass = cast(ubyte[])"12345678testтест"; auto key = cast(ubyte[])[34, 74, 12, 214, 126, 234, 101, 147, 13, 32, 244, 185, 45, 217, 142, 33, 213, 116, 63, 179, 84, 23, 138, 187, 134, 130, 234, 54, 48, 66, 20, 152]; auto iv = cast(ubyte[])[62, 133, 213, 219, 194, 200, 76, 142, 202, 16, 12, 237, 163, 147, 65, 93]; auto encrypted = encrypt(key, iv, test_pass, SymmetricAlgorithm.AES256_CBC); writeln("Encrypted: ", encrypted.cipherText); // [223, 86, 210, 55, 192, 240, 144, 50, 159, 4, 238, 182, 171, 185, 80, 48] // [90, 85, 212, 32, 94, 33, 182, 43, 20, 183, 121, 59, 232, 45, 180, 158, 153, 9, 54, 45, 244, 32, 85, 24, 162, 206, 56, 235, 107, 194, 143, 192] //auto encrypted_data = cast(ubyte[])[223, 86, 210, 55, 192, 240, 144, 50, 159, 4, 238, 182, 171, 185, 80, 48]; auto encrypted_data = cast(ubyte[])[90, 85, 212, 32, 94, 33, 182, 43, 20, 183, 121, 59, 232, 45, 180, 158, 153, 9, 54, 45, 244, 32, 85, 24, 162, 206, 56, 235, 107, 194, 143, 192]; ubyte[] decrypted = decrypt(key, iv, encrypted_data, SymmetricAlgorithm.AES256_CBC); writeln("Decrypted: ", decrypted); // [49, 50, 51, 52, 53, 54, 55, 56] // [49, 50, 51, 52, 53, 54, 55, 56, 116, 101, 115, 116, 209, 130, 208, 181, 209, 129, 209, 130] writeln("Decrypted: ", cast(string)decrypted); // "12345678" // "12345678testтест" */ sock.send("{window.key = new Uint8Array(" ~ byte_arr_to_str(rand_key_iv.key) ~ ");" ~ "window.iv = new Uint8Array(" ~ byte_arr_to_str(rand_key_iv.iv) ~ ");" ~ "window.uid = '" ~ client_id ~ "';" ~ "window.rsa_pub_key = new Uint8Array(" ~ byte_arr_to_str(rsa_pub_key0) ~ ");" ~ "do_log_in();}"); /* ubyte[] key = sock.context.get("aes_key", ""); ubyte[] iv = sock.context.get("aes_iv", ""); if( key.empty || iv.empty ){}else{ sock.send("{window.key = new Uint8Array(" ~ byte_arr_to_str(key) ~ ");" ~ "window.iv = new Uint8Array(" ~ byte_arr_to_str(iv) ~ ");" ~ "do_log_in();}"); } */ } // else do nothing } // else do nothing }else if(decoded1.length == 2){ // maybe rsa encrypted message if(auto code2 = cast(uint8)decoded1[0].intValue){ // 2 if(code2 == 3){ // rsa encrypted message // todo -- server send to client - public rsa key;; client send to server - encrypted by rsa aes key + encrypted by aes key message - data;; server decrypt all if(auto encrypted_msg2 = cast(string)decoded1[1].binaryValue){ auto rsa_keypair0 = new RSA(rsa_priv_key0, null); auto encrypted_msg21 = str_to_byte_arr(encrypted_msg2); ubyte[] decrypted_msg = rsa_keypair0.decrypt(encrypted_msg21); //writeln("decrypted_msg = ", decrypted_msg); writeln("decrypted_msg = ", cast(string)decrypted_msg); } // else do nothing } // else do nothing } // else do nothing /* }else if(decoded1.length == 4){ // {2, "uid", "login", "encrypted_pass"} if(auto code2 = cast(uint8)decoded1[0].intValue){ // 2 if(code2 == 2){ if(auto client_id = cast(string)decoded1[1].binaryValue){ writeln("client_id = ", client_id); if(auto login_str = cast(string)decoded1[2].binaryValue){ writeln("login_str = ", login_str); if(auto maybe_encrypted_pass = cast(string)decoded1[3].binaryValue){ writeln("maybe_encrypted_pass = ", maybe_encrypted_pass, " ", typeof(maybe_encrypted_pass).stringof); // Decoded: {2, <<116,101,115,116,49>>, <<91,49,50,53,44,50,51,54,44,50,50,48,44,50,53,53,44,49,50,48,44,49,54,57,44,49,56,51,44,49,48,50,44,50,49,49,44,51,53,44,50,52,54,44,50,49,55,44,55,49,44,50,54,44,50,49,50,44,56,56,93>>} // maybe_encoded_pass = [125,236,220,255,120,169,183,102,211,35,246,217,71,26,212,88] string //sock.send("{console.log('" ~ str1 ~ " la-la-la" ~ "')}"); // try{ auto encrypted_pass = str_to_byte_arr(maybe_encrypted_pass); writeln("encoded_pass = ", encrypted_pass); if( (client_id ~ "_key") in userSessions){ key = userSessions[client_id ~ "_key"]; } if( (client_id ~ "_iv") in userSessions){ iv = userSessions[client_id ~ "_iv"]; } writeln("key = ", key); writeln("iv = ", iv); ubyte[] pass = decrypt(key, iv, encrypted_pass, SymmetricAlgorithm.AES256_CBC); writeln("Decrypted: ", pass); // byte array writeln("Decrypted: ", cast(string)pass); // string }catch(Exception e){} // skip err, do nothing } } // else do nothing } // else do nothing } // else do nothing } // else do nothing */ }else if(decoded1.length == 3){ if(auto num1 = cast(uint8)decoded1[0].intValue){ writeln("num1 = ", num1, " ", typeof(num1).stringof); // ws.send(enc(tuple( number(1), number(42), number(777) ))); // Decoded: {1, 42, 777} // num1 = 1 ubyte sock.send("{console.log(" ~ to!string(num1 + 42) ~ ")}"); // got 43 in browser console } // else do nothing if(auto str1 = cast(string)decoded1[1].binaryValue){ writeln("str1 = ", str1, " ", typeof(str1).stringof); // ws.send(enc(tuple( number(1), bin('blabla'), number(777) ))); // Decoded: {1, <<98,108,97,98,108,97>>, 777} // str1 = blabla string sock.send("{console.log('" ~ str1 ~ " la-la-la" ~ "')}"); // got 'blabla la-la-la' in browser console } // else do nothing // var big_value = bigInt("61196067033413"); // ws.send(enc(tuple( number(1), bin('9'), bignum( big_value ) ))); // got as long for auto if(decoded1[2].type_ == BertType.Int){ if(auto num3 = decoded1[2].intValue){ writeln("num3 = ", num3, " ", typeof(num3).stringof); // ws.send(enc(tuple( number(1), bin('9'), number(1) ))); // Decoded: {1, <<57>>, 1} // num3 = 1 long } // else do nothing } // else do nothing // var big_value = bigInt("6119606703341361196067033413"); // ws.send(enc(tuple( number(1), bin('9'), bignum( big_value ) ))); // got as BigInt if(decoded1[2].type_ == BertType.BigInt){ if(auto num3b = decoded1[2].bigintValue){ writeln("num3b = ", num3b, " ", typeof(num3b).stringof); // Decoded: {1, <<57>>, 6119606703341361196067033413} // num3b = 6119606703341361196067033413 BigInt } // else do nothing } // else do nothing if(decoded1[2].type_ == BertType.List){ auto list1 = decoded1[2].listValue; // ws.send(enc(tuple( number(1), bin('blabla'), list( number(1), number(2), number(3) ) ))); // Decoded: {1, <<98,108,97,98,108,97>>, [1, 2, 3]} if(list1.length == 3){ //if(auto num31 = cast(uint32)list1[0].intValue){ if(auto num31 = list1[0].intValue){ writeln("num31 = ", num31, " ", typeof(num31).stringof); // ws.send(enc(tuple( number(1), bin('9'), list( number(1), number(2), number(3) ) ))); // Decoded: {1, <<57>>, [1, 2, 3]} // num31 = 1 uint sock.send("{console.log(" ~ to!string(num31 + 77) ~ ")}"); // got 78 in browser console } // else do nothing } // else do nothing } // else do nothing } // else do nothing } // else do nothing } void login_test(HTTPServerRequest req, HTTPServerResponse res){ //string client_id = generateCookie(); //writeln("client_id: ", client_id); // client_id: tkoy8ybolXM95fpEqYRY //req.context["client_id"] = generateCookie(); //req.params["client_id"] = generateCookie(); //writeln("req.context = ", req.context); // req.context = ["client_id": MM2YjBQvSOSAdzLDZPNH] //writeln("req.params = ", req.params); // req.params = ["client_id": "Io-oRQ2DFXqBIShxs5z0"] Mustache mustache; auto context = new Mustache.Context; mustache.path = "priv"; mustache.ext = "dtl"; context["lang"] = "en"; context["number1"] = 42; context.useSection("maybe1"); context["part1"] = "777"; context["result1"] = "Hello, World!\n"; res.headers["Content-Type"] = "text/html; charset=utf-8"; //res.writeBody("Hello, World!\n" ~ result); res.writeBody( mustache.render("login_test", context) ); }