Secure key exchange with libsodium

I want to make a test application that uses libsodium to communicate with a client on a server.

There are many ports for many languages: C # , PHP , ...

and there is always an example with "bob" and "alice". This is normal, but they never show how to exchange public keys over the network using a secure one .

So, it is recommended that you use the public keys for "alice / client" and "bob / server".

They always use the same file or the same computer to generate key pairs.

Here is an excerpt from the libsodium-php extension :

$alice_kp = crypto_box_keypair();
$alice_secretkey = crypto_box_secretkey($alice_kp);
$alice_publickey = crypto_box_publickey($alice_kp);

$bob_kp = crypto_box_keypair();
$bob_secretkey = crypto_box_secretkey($bob_kp);
$bob_publickey = crypto_box_publickey($bob_kp);

$alice_to_bob_kp = crypto_box_keypair_from_secretkey_and_publickey
  ($alice_secretkey, $bob_publickey);

$bob_to_alice_kp = crypto_box_keypair_from_secretkey_and_publickey
  ($bob_secretkey, $alice_publickey);

$alice_to_bob_message_nonce = randombytes_buf(CRYPTO_BOX_NONCEBYTES);

$alice_to_bob_ciphertext = crypto_box('Hi, this is Alice',
                                      $alice_to_bob_message_nonce,
                                      $alice_to_bob_kp);

$alice_message_decrypted_by_bob = crypto_box_open($alice_to_bob_ciphertext,
                                                  $alice_to_bob_message_nonce,
                                                  $bob_to_alice_kp);

$bob_to_alice_message_nonce = randombytes_buf(CRYPTO_BOX_NONCEBYTES);

$bob_to_alice_ciphertext = crypto_box('Hi Alice! This is Bob',
                                      $bob_to_alice_message_nonce,
                                      $bob_to_alice_kp);

$bob_message_decrypted_by_alice = crypto_box_open($bob_to_alice_ciphertext,
                                                  $bob_to_alice_message_nonce,
                                                  $alice_to_bob_kp);
+4
1

Libsodium . :

  • " " , com- , . (, BittorrentSync, QR-, , ).

  • , , . (, SSL/TLS)

  • (, Google Chrome URL- Google)

, , SSL/TLS, , , . , /, PHP, , .

, , . , Bob Alice. .

, Bob ( ) Bob.

, , . , .

?

, Eve, , , .

. , , , .

Eve Alice, , Alice Bob, , , Eve Bob.

, ( Eve Bob's). , ( SSL/TLS ) / .

. .

QR- - HTTPS , - ( , , SQRL), QR- , uri.

QR code/uri - HTTPS, crypto_secretbox().

, / , , base64, base32 hex, , .

, ?

, / , ( , ). - , Forward Secrecy .

( 24 ), , - , OpenSSL Heartbleed.

- PHP , reset HTTP-. memcached- , .

+6

Source: https://habr.com/ru/post/1532773/


All Articles