… | |
… | |
479 | } |
479 | } |
480 | |
480 | |
481 | bool config_packet::chk_config () const |
481 | bool config_packet::chk_config () const |
482 | { |
482 | { |
483 | if (prot_major != PROTOCOL_MAJOR) |
483 | if (prot_major != PROTOCOL_MAJOR) |
484 | slog (L_WARN, _("major version mismatch (%d <=> %d)"), prot_major, PROTOCOL_MAJOR); |
484 | slog (L_WARN, _("major version mismatch (remote %d <=> local %d)"), prot_major, PROTOCOL_MAJOR); |
485 | else if (randsize != RAND_SIZE) |
485 | else if (randsize != RAND_SIZE) |
486 | slog (L_WARN, _("rand size mismatch (%d <=> %d)"), randsize, RAND_SIZE); |
486 | slog (L_WARN, _("rand size mismatch (remote %d <=> local %d)"), randsize, RAND_SIZE); |
487 | else if (hmaclen != HMACLENGTH) |
487 | else if (hmaclen != HMACLENGTH) |
488 | slog (L_WARN, _("hmac length mismatch (%d <=> %d)"), hmaclen, HMACLENGTH); |
488 | slog (L_WARN, _("hmac length mismatch (remote %d <=> local %d)"), hmaclen, HMACLENGTH); |
489 | else if (flags != curflags ()) |
489 | else if (flags != curflags ()) |
490 | slog (L_WARN, _("flag mismatch (%x <=> %x)"), flags, curflags ()); |
490 | slog (L_WARN, _("flag mismatch (remote %x <=> local %x)"), flags, curflags ()); |
491 | else if (challengelen != sizeof (rsachallenge)) |
491 | else if (challengelen != sizeof (rsachallenge)) |
492 | slog (L_WARN, _("challenge length mismatch (%d <=> %d)"), challengelen, sizeof (rsachallenge)); |
492 | slog (L_WARN, _("challenge length mismatch (remote %d <=> local %d)"), challengelen, sizeof (rsachallenge)); |
493 | else if (cipher_nid != htonl (EVP_CIPHER_nid (CIPHER))) |
493 | else if (cipher_nid != htonl (EVP_CIPHER_nid (CIPHER))) |
494 | slog (L_WARN, _("cipher mismatch (%x <=> %x)"), ntohl (cipher_nid), EVP_CIPHER_nid (CIPHER)); |
494 | slog (L_WARN, _("cipher mismatch (remote %x <=> local %x)"), ntohl (cipher_nid), EVP_CIPHER_nid (CIPHER)); |
495 | else if (digest_nid != htonl (EVP_MD_type (RSA_HASH))) |
495 | else if (digest_nid != htonl (EVP_MD_type (RSA_HASH))) |
496 | slog (L_WARN, _("digest mismatch (%x <=> %x)"), ntohl (digest_nid), EVP_MD_type (RSA_HASH)); |
496 | slog (L_WARN, _("digest mismatch (remote %x <=> local %x)"), ntohl (digest_nid), EVP_MD_type (RSA_HASH)); |
497 | else if (hmac_nid != htonl (EVP_MD_type (DIGEST))) |
497 | else if (hmac_nid != htonl (EVP_MD_type (DIGEST))) |
498 | slog (L_WARN, _("hmac mismatch (%x <=> %x)"), ntohl (hmac_nid), EVP_MD_type (DIGEST)); |
498 | slog (L_WARN, _("hmac mismatch (remote %x <=> local %x)"), ntohl (hmac_nid), EVP_MD_type (DIGEST)); |
499 | else |
499 | else |
500 | return true; |
500 | return true; |
501 | |
501 | |
502 | return false; |
502 | return false; |
503 | } |
503 | } |
… | |
… | |
675 | connection::send_auth_request (const sockinfo &si, bool initiate) |
675 | connection::send_auth_request (const sockinfo &si, bool initiate) |
676 | { |
676 | { |
677 | auth_req_packet *pkt = new auth_req_packet (conf->id, initiate, THISNODE->protocols); |
677 | auth_req_packet *pkt = new auth_req_packet (conf->id, initiate, THISNODE->protocols); |
678 | |
678 | |
679 | rsachallenge chg; |
679 | rsachallenge chg; |
680 | |
|
|
681 | rsa_cache.gen (pkt->id, chg); |
680 | rsa_cache.gen (pkt->id, chg); |
682 | |
681 | rsa_encrypt (conf->rsa_key, chg, pkt->encr); |
683 | if (0 > RSA_public_encrypt (sizeof chg, |
|
|
684 | (unsigned char *)&chg, (unsigned char *)&pkt->encr, |
|
|
685 | conf->rsa_key, RSA_PKCS1_OAEP_PADDING)) |
|
|
686 | fatal ("RSA_public_encrypt error"); |
|
|
687 | |
682 | |
688 | slog (L_TRACE, ">>%d PT_AUTH_REQ [%s]", conf->id, (const char *)si); |
683 | slog (L_TRACE, ">>%d PT_AUTH_REQ [%s]", conf->id, (const char *)si); |
689 | |
684 | |
690 | send_vpn_packet (pkt, si, IPTOS_RELIABILITY | IPTOS_LOWDELAY); // rsa is very very costly |
685 | send_vpn_packet (pkt, si, IPTOS_RELIABILITY | IPTOS_LOWDELAY); // rsa is very very costly |
691 | |
686 | |
… | |
… | |
908 | if (p->initiate) |
903 | if (p->initiate) |
909 | send_auth_request (rsi, false); |
904 | send_auth_request (rsi, false); |
910 | |
905 | |
911 | rsachallenge k; |
906 | rsachallenge k; |
912 | |
907 | |
913 | if (0 > RSA_private_decrypt (sizeof (p->encr), |
908 | if (!rsa_decrypt (::conf.rsa_key, p->encr, k)) |
914 | (unsigned char *)&p->encr, (unsigned char *)&k, |
909 | { |
915 | ::conf.rsa_key, RSA_PKCS1_OAEP_PADDING)) |
|
|
916 | slog (L_ERR, _("%s(%s): challenge illegal or corrupted (%s). mismatched key or config file?"), |
910 | slog (L_ERR, _("%s(%s): challenge illegal or corrupted (%s). mismatched key or config file?"), |
917 | conf->nodename, (const char *)rsi, ERR_error_string (ERR_get_error (), 0)); |
911 | conf->nodename, (const char *)rsi, ERR_error_string (ERR_get_error (), 0)); |
|
|
912 | break; |
|
|
913 | } |
918 | else |
914 | else |
919 | { |
915 | { |
920 | delete octx; |
916 | delete octx; |
921 | |
917 | |
922 | octx = new crypto_ctx (k, 1); |
918 | octx = new crypto_ctx (k, 1); |