… | |
… | |
478 | { |
478 | { |
479 | prot_major = PROTOCOL_MAJOR; |
479 | prot_major = PROTOCOL_MAJOR; |
480 | prot_minor = PROTOCOL_MINOR; |
480 | prot_minor = PROTOCOL_MINOR; |
481 | randsize = RAND_SIZE; |
481 | randsize = RAND_SIZE; |
482 | hmaclen = HMACLENGTH; |
482 | hmaclen = HMACLENGTH; |
483 | flags = ENABLE_COMPRESSION ? 0x81 : 0x80; |
483 | flags = 0; |
484 | challengelen = sizeof (rsachallenge); |
484 | challengelen = sizeof (rsachallenge); |
485 | features = get_features (); |
485 | features = get_features (); |
486 | |
486 | |
487 | cipher_nid = htonl (EVP_CIPHER_nid (CIPHER)); |
487 | cipher_nid = htonl (EVP_CIPHER_nid (CIPHER)); |
488 | digest_nid = htonl (EVP_MD_type (RSA_HASH)); |
488 | digest_nid = htonl (EVP_MD_type (RSA_HASH)); |
… | |
… | |
498 | slog (L_WARN, _("major version mismatch (remote %d <=> local %d)"), prot_major, PROTOCOL_MAJOR); |
498 | slog (L_WARN, _("major version mismatch (remote %d <=> local %d)"), prot_major, PROTOCOL_MAJOR); |
499 | else if (randsize != RAND_SIZE) |
499 | else if (randsize != RAND_SIZE) |
500 | slog (L_WARN, _("rand size mismatch (remote %d <=> local %d)"), randsize, RAND_SIZE); |
500 | slog (L_WARN, _("rand size mismatch (remote %d <=> local %d)"), randsize, RAND_SIZE); |
501 | else if (hmaclen != HMACLENGTH) |
501 | else if (hmaclen != HMACLENGTH) |
502 | slog (L_WARN, _("hmac length mismatch (remote %d <=> local %d)"), hmaclen, HMACLENGTH); |
502 | slog (L_WARN, _("hmac length mismatch (remote %d <=> local %d)"), hmaclen, HMACLENGTH); |
503 | #if 0 // this implementation should handle all flag settings |
|
|
504 | else if (flags != curflags ()) |
|
|
505 | slog (L_WARN, _("flag mismatch (remote %x <=> local %x)"), flags, curflags ()); |
|
|
506 | #endif |
|
|
507 | else if (challengelen != sizeof (rsachallenge)) |
503 | else if (challengelen != sizeof (rsachallenge)) |
508 | slog (L_WARN, _("challenge length mismatch (remote %d <=> local %d)"), challengelen, sizeof (rsachallenge)); |
504 | slog (L_WARN, _("challenge length mismatch (remote %d <=> local %d)"), challengelen, sizeof (rsachallenge)); |
509 | else if (cipher_nid != htonl (EVP_CIPHER_nid (CIPHER))) |
505 | else if (cipher_nid != htonl (EVP_CIPHER_nid (CIPHER))) |
510 | slog (L_WARN, _("cipher mismatch (remote %x <=> local %x)"), ntohl (cipher_nid), EVP_CIPHER_nid (CIPHER)); |
506 | slog (L_WARN, _("cipher mismatch (remote %x <=> local %x)"), ntohl (cipher_nid), EVP_CIPHER_nid (CIPHER)); |
511 | else if (digest_nid != htonl (EVP_MD_type (RSA_HASH))) |
507 | else if (digest_nid != htonl (EVP_MD_type (RSA_HASH))) |
… | |
… | |
745 | && conf != THISNODE |
741 | && conf != THISNODE |
746 | && connectmode != conf_node::C_NEVER |
742 | && connectmode != conf_node::C_NEVER |
747 | && connectmode != conf_node::C_DISABLED |
743 | && connectmode != conf_node::C_DISABLED |
748 | && NOW > w.at) |
744 | && NOW > w.at) |
749 | { |
745 | { |
750 | double retry_int = double (retry_cnt & 3 ? (retry_cnt & 3) : 1 << (retry_cnt >> 2)) * 0.6; |
746 | w.at = TSTAMP_MAX; // first disable this watcher in case of recursion |
751 | |
747 | |
752 | if (retry_int < conf->max_retry) |
748 | double retry_int = double (retry_cnt & 3 |
753 | retry_cnt++; |
749 | ? (retry_cnt & 3) + 1 |
754 | else |
750 | : 1 << (retry_cnt >> 2)); |
755 | retry_int = conf->max_retry; |
|
|
756 | |
|
|
757 | w.start (NOW + retry_int); |
|
|
758 | |
751 | |
759 | reset_si (); |
752 | reset_si (); |
|
|
753 | |
|
|
754 | bool slow = si.prot & PROT_SLOW; |
760 | |
755 | |
761 | if (si.prot && !si.host) |
756 | if (si.prot && !si.host) |
762 | vpn->send_connect_request (conf->id); |
757 | vpn->send_connect_request (conf->id); |
763 | else |
758 | else |
764 | { |
759 | { |
765 | const sockinfo &dsi = forward_si (si); |
760 | const sockinfo &dsi = forward_si (si); |
|
|
761 | |
|
|
762 | slow = slow || (dsi.prot & PROT_SLOW); |
766 | |
763 | |
767 | if (dsi.valid () && auth_rate_limiter.can (dsi)) |
764 | if (dsi.valid () && auth_rate_limiter.can (dsi)) |
768 | { |
765 | { |
769 | if (retry_cnt < 4) |
766 | if (retry_cnt < 4) |
770 | send_auth_request (dsi, true); |
767 | send_auth_request (dsi, true); |
771 | else |
768 | else |
772 | send_ping (dsi, 0); |
769 | send_ping (dsi, 0); |
773 | } |
770 | } |
774 | } |
771 | } |
|
|
772 | |
|
|
773 | retry_int *= slow ? 3. : 0.7; |
|
|
774 | |
|
|
775 | if (retry_int < conf->max_retry) |
|
|
776 | retry_cnt++; |
|
|
777 | else |
|
|
778 | retry_int = conf->max_retry; |
|
|
779 | |
|
|
780 | w.start (NOW + retry_int); |
775 | } |
781 | } |
776 | } |
782 | } |
777 | |
783 | |
778 | void |
784 | void |
779 | connection::reset_connection () |
785 | connection::reset_connection () |
… | |
… | |
938 | delete octx; |
944 | delete octx; |
939 | |
945 | |
940 | octx = new crypto_ctx (k, 1); |
946 | octx = new crypto_ctx (k, 1); |
941 | oseqno = ntohl (*(u32 *)&k[CHG_SEQNO]) & 0x7fffffff; |
947 | oseqno = ntohl (*(u32 *)&k[CHG_SEQNO]) & 0x7fffffff; |
942 | |
948 | |
943 | // compatibility code, remove when no longer required |
|
|
944 | if (p->flags & 1) p->features |= FEATURE_COMPRESSION; |
|
|
945 | |
|
|
946 | conf->protocols = p->protocols; |
949 | conf->protocols = p->protocols; |
947 | features = p->features & config_packet::get_features (); |
950 | features = p->features & config_packet::get_features (); |
948 | |
951 | |
949 | send_auth_response (rsi, p->id, k); |
952 | send_auth_response (rsi, p->id, k); |
950 | |
953 | |