221V 5 days ago
parent
commit
72a0c30397
2 changed files with 154 additions and 9 deletions
  1. 117 4
      vtest/priv/login_test.dtl
  2. 37 5
      vtest/source/ws_bert_login.d

+ 117 - 4
vtest/priv/login_test.dtl

@@ -22,6 +22,11 @@
 <button id="send_pass1" onclick="do_log_in();">Log In</button>
 
 <script>
+function uint8ArrayToStr(arr){
+  return '[' + Array.from(arr).join(',') + ']';
+}
+
+
 async function encryptAES256CBC(key, iv, plaintext){
   const enc = new TextEncoder();
   const cryptoKey = await window.crypto.subtle.importKey(
@@ -76,6 +81,94 @@ var encrypted2 = new Uint8Array([90, 85, 212, 32, 94, 33, 182, 43, 20, 183, 121,
 // "12345678testтест"
 
 */
+
+
+/*
+async function generateRSAKeyPair(){
+  const keyPair = await window.crypto.subtle.generateKey({
+      name: "RSA-OAEP",
+      modulusLength: 2048,
+      publicExponent: new Uint8Array([1, 0, 1]), // 65537
+      hash: "SHA-256"
+    },
+    true, // can use few times
+    ["encrypt", "decrypt"] // use privileges
+  );
+  return keyPair;
+}
+
+
+(async () => {
+  const keys = await generateRSAKeyPair());
+  console.log("keys:", keys);
+})();
+*/
+
+/*
+const publicKeyBytes = new Uint8Array([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]);
+*/
+/* PEM file in bytes, but we need only key - DER (SPKI), not comments
+-----BEGIN PUBLIC KEY-----
+...
+-----END PUBLIC KEY-----
+*/
+
+// needs to Uint8Array → string (PEM) → DER (Uint8Array) → importKey("spki", ...)
+
+/*
+function uint8ArrayToString(array){
+  return new TextDecoder("utf-8").decode(array);
+}
+
+const pemString = uint8ArrayToString(publicKeyBytes);
+console.log(pemString);
+*/
+
+function rsa_pemToRawKey(pem){
+  const pemLines = pem.split('\n');
+  const base64Lines = pemLines
+    .filter(line => line.trim().length > 0 && !line.startsWith('-----'))
+    .join('');
+  
+  const binaryString = atob(base64Lines);
+  const len = binaryString.length;
+  const bytes = new Uint8Array(len);
+
+  for (let i = 0; i < len; i++) {
+    bytes[i] = binaryString.charCodeAt(i);
+  }
+  return bytes; // DER/SPKI key
+}
+
+async function rsa_importPublicKey(byte_array){
+  const key_str = new TextDecoder("utf-8").decode(byte_array);
+  const keyBytes = rsa_pemToRawKey(key_str);
+  const keyBuffer = keyBytes.buffer;
+  const publicKey = await window.crypto.subtle.importKey(
+    "spki", // SubjectPublicKeyInfo - key format
+    keyBuffer,
+    {
+      name: "RSA-OAEP",
+      //hash: "SHA-256"
+      hash: "SHA-1"
+    },
+    true, // extractable
+    ["encrypt"] // allow privileges
+  );
+  return publicKey;
+}
+
+async function rsa_encrypt(plainText, publicKey){
+  const encoder = new TextEncoder();
+  const data = encoder.encode(plainText);
+  const encryptedBuffer = await window.crypto.subtle.encrypt({
+      name: "RSA-OAEP"
+    },
+    publicKey,
+    data
+  );
+  return new Uint8Array(encryptedBuffer); // return Uint8Array, not Base64
+}
 </script>
 
 <script src="/js/BigInteger.min.js" defer></script>
@@ -83,18 +176,17 @@ var encrypted2 = new Uint8Array([90, 85, 212, 32, 94, 33, 182, 43, 20, 183, 121,
 <script src="/js/bert.js" defer></script>
 <script src="/js/ws_conn.js" defer></script>
 <script>
-function uint8ArrayToStr(arr){
-  return '[' + Array.from(arr).join(',') + ']';
-}
+var message0 = '12345678testтест';
 
 function do_log_in(){
-  if(!(window.key && window.iv && window.uid)){ // was not init yet
+  if(!(window.key && window.iv && window.rsa_pub_key && window.uid)){ // was not init yet
     ws.send(enc(tuple( number(1) )));
     return;
   } // else - already was init
   
   console.log('window.key = ', window.key);
   console.log('window.iv = ', window.iv);
+  console.log('window.rsa_pub_key = ', uint8ArrayToStr(window.rsa_pub_key));
   
   var login = qi('login1').value.trim();
   var pass = qi('pass1').value.trim();
@@ -104,6 +196,27 @@ function do_log_in(){
     var enc_pass = await encryptAES256CBC(window.key, window.iv, pass);
     ws.send(enc(tuple( number(2), bin(window.uid), bin(login), bin(uint8ArrayToStr(enc_pass)) )));
   })();
+  
+  // 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
+  (async () => {
+    //const publicKey = await rsa_importPublicKey(publicKeyBytes);
+    //const pemString = uint8ArrayToString(publicKeyBytes);
+    //const publicKeyDer = rsa_pemToRawKey(pemString);
+    //const publicKey = await rsa_importPublicKey(publicKeyDer);
+    //console.log('pemString = ', pemString);
+    //console.log('publicKeyDer = ', publicKeyDer);
+    
+    const publicKey = await rsa_importPublicKey(window.rsa_pub_key);
+    const originalMessage = '12345678testтест';
+    
+    const encrypted = await rsa_encrypt(message0, publicKey);
+    var encrypted12 = uint8ArrayToStr(encrypted);
+    console.log("encrypted (Uint8Array) = ", encrypted12); // this will be different every time
+    
+    ws.send(enc(tuple( number(3), bin(encrypted12) )));
+    
+    // cant decrypt without priv_key
+  })();
 }
 
 

+ 37 - 5
vtest/source/ws_bert_login.d

@@ -107,6 +107,19 @@ void ws_bert_handle(scope WebSocket sock){
 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();
   
@@ -127,8 +140,8 @@ void msg_match(BertValue decoded, WebSocket sock){
   writeln("decMessage214 = ", cast(string)decMessage214);
   
   
-  ubyte[] key;
-  ubyte[] iv;
+  //ubyte[] key;
+  //ubyte[] iv;
   
   if(decoded.type_ == BertType.Tuple){
     auto decoded1 = decoded.tupleValue;
@@ -182,9 +195,9 @@ void msg_match(BertValue decoded, WebSocket sock){
           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", "");
@@ -200,6 +213,26 @@ void msg_match(BertValue decoded, WebSocket sock){
       } // 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){
@@ -237,11 +270,10 @@ void msg_match(BertValue decoded, WebSocket sock){
               
               }
             } // else do nothing
-            
           } // else do nothing
         } // else do nothing
       } // else do nothing
-    
+    */
     
     
     }else if(decoded1.length == 3){