… | |
… | |
335 | int outl = 0, outl2; |
335 | int outl = 0, outl2; |
336 | ptype type = PT_DATA_UNCOMPRESSED; |
336 | ptype type = PT_DATA_UNCOMPRESSED; |
337 | |
337 | |
338 | #if ENABLE_COMPRESSION |
338 | #if ENABLE_COMPRESSION |
339 | u8 cdata[MAX_MTU]; |
339 | u8 cdata[MAX_MTU]; |
340 | u32 cl; |
|
|
341 | |
340 | |
|
|
341 | if (conn->features & ENABLE_COMPRESSION) |
|
|
342 | { |
342 | cl = lzf_compress (d, l, cdata + 2, (l - 2) & ~7); |
343 | u32 cl = lzf_compress (d, l, cdata + 2, (l - 2) & ~7); |
|
|
344 | |
343 | if (cl) |
345 | if (cl) |
344 | { |
346 | { |
345 | type = PT_DATA_COMPRESSED; |
347 | type = PT_DATA_COMPRESSED; |
346 | d = cdata; |
348 | d = cdata; |
347 | l = cl + 2; |
349 | l = cl + 2; |
348 | |
350 | |
349 | d[0] = cl >> 8; |
351 | d[0] = cl >> 8; |
350 | d[1] = cl; |
352 | d[1] = cl; |
|
|
353 | } |
351 | } |
354 | } |
352 | #endif |
355 | #endif |
353 | |
356 | |
354 | require (EVP_EncryptInit_ex (cctx, 0, 0, 0, 0)); |
357 | require (EVP_EncryptInit_ex (cctx, 0, 0, 0, 0)); |
355 | |
358 | |
… | |
… | |
448 | { |
451 | { |
449 | // actually, hmaclen cannot be checked because the hmac |
452 | // actually, hmaclen cannot be checked because the hmac |
450 | // field comes before this data, so peers with other |
453 | // field comes before this data, so peers with other |
451 | // hmacs simply will not work. |
454 | // hmacs simply will not work. |
452 | u8 prot_major, prot_minor, randsize, hmaclen; |
455 | u8 prot_major, prot_minor, randsize, hmaclen; |
453 | u8 flags, challengelen, pad2, pad3; |
456 | u8 flags, challengelen, features, pad3; |
454 | u32 cipher_nid, digest_nid, hmac_nid; |
457 | u32 cipher_nid, digest_nid, hmac_nid; |
455 | |
|
|
456 | const u8 curflags () const |
|
|
457 | { |
|
|
458 | return 0x80 |
|
|
459 | | (ENABLE_COMPRESSION ? 0x01 : 0x00); |
|
|
460 | } |
|
|
461 | |
458 | |
462 | void setup (ptype type, int dst); |
459 | void setup (ptype type, int dst); |
463 | bool chk_config () const; |
460 | bool chk_config () const; |
464 | }; |
461 | }; |
|
|
462 | |
|
|
463 | #define FEATURES ((ENABLE_COMPRESSION ? FEATURE_COMPRESSION : 0) \ |
|
|
464 | | (ENABLE_ROHC ? FEATURE_ROHC : 0)) |
465 | |
465 | |
466 | void config_packet::setup (ptype type, int dst) |
466 | void config_packet::setup (ptype type, int dst) |
467 | { |
467 | { |
468 | prot_major = PROTOCOL_MAJOR; |
468 | prot_major = PROTOCOL_MAJOR; |
469 | prot_minor = PROTOCOL_MINOR; |
469 | prot_minor = PROTOCOL_MINOR; |
470 | randsize = RAND_SIZE; |
470 | randsize = RAND_SIZE; |
471 | hmaclen = HMACLENGTH; |
471 | hmaclen = HMACLENGTH; |
472 | flags = curflags (); |
472 | flags = ENABLE_COMPRESSION ? 0x81 : 0x80; |
473 | challengelen = sizeof (rsachallenge); |
473 | challengelen = sizeof (rsachallenge); |
|
|
474 | features = FEATURES; |
474 | |
475 | |
475 | cipher_nid = htonl (EVP_CIPHER_nid (CIPHER)); |
476 | cipher_nid = htonl (EVP_CIPHER_nid (CIPHER)); |
476 | digest_nid = htonl (EVP_MD_type (RSA_HASH)); |
477 | digest_nid = htonl (EVP_MD_type (RSA_HASH)); |
477 | hmac_nid = htonl (EVP_MD_type (DIGEST)); |
478 | hmac_nid = htonl (EVP_MD_type (DIGEST)); |
478 | |
479 | |
… | |
… | |
486 | slog (L_WARN, _("major version mismatch (remote %d <=> local %d)"), prot_major, PROTOCOL_MAJOR); |
487 | slog (L_WARN, _("major version mismatch (remote %d <=> local %d)"), prot_major, PROTOCOL_MAJOR); |
487 | else if (randsize != RAND_SIZE) |
488 | else if (randsize != RAND_SIZE) |
488 | slog (L_WARN, _("rand size mismatch (remote %d <=> local %d)"), randsize, RAND_SIZE); |
489 | slog (L_WARN, _("rand size mismatch (remote %d <=> local %d)"), randsize, RAND_SIZE); |
489 | else if (hmaclen != HMACLENGTH) |
490 | else if (hmaclen != HMACLENGTH) |
490 | slog (L_WARN, _("hmac length mismatch (remote %d <=> local %d)"), hmaclen, HMACLENGTH); |
491 | slog (L_WARN, _("hmac length mismatch (remote %d <=> local %d)"), hmaclen, HMACLENGTH); |
|
|
492 | #if 0 // this implementation should handle all flag settings |
491 | else if (flags != curflags ()) |
493 | else if (flags != curflags ()) |
492 | slog (L_WARN, _("flag mismatch (remote %x <=> local %x)"), flags, curflags ()); |
494 | slog (L_WARN, _("flag mismatch (remote %x <=> local %x)"), flags, curflags ()); |
|
|
495 | #endif |
493 | else if (challengelen != sizeof (rsachallenge)) |
496 | else if (challengelen != sizeof (rsachallenge)) |
494 | slog (L_WARN, _("challenge length mismatch (remote %d <=> local %d)"), challengelen, sizeof (rsachallenge)); |
497 | slog (L_WARN, _("challenge length mismatch (remote %d <=> local %d)"), challengelen, sizeof (rsachallenge)); |
495 | else if (cipher_nid != htonl (EVP_CIPHER_nid (CIPHER))) |
498 | else if (cipher_nid != htonl (EVP_CIPHER_nid (CIPHER))) |
496 | slog (L_WARN, _("cipher mismatch (remote %x <=> local %x)"), ntohl (cipher_nid), EVP_CIPHER_nid (CIPHER)); |
499 | slog (L_WARN, _("cipher mismatch (remote %x <=> local %x)"), ntohl (cipher_nid), EVP_CIPHER_nid (CIPHER)); |
497 | else if (digest_nid != htonl (EVP_MD_type (RSA_HASH))) |
500 | else if (digest_nid != htonl (EVP_MD_type (RSA_HASH))) |
… | |
… | |
916 | delete octx; |
919 | delete octx; |
917 | |
920 | |
918 | octx = new crypto_ctx (k, 1); |
921 | octx = new crypto_ctx (k, 1); |
919 | oseqno = ntohl (*(u32 *)&k[CHG_SEQNO]) & 0x7fffffff; |
922 | oseqno = ntohl (*(u32 *)&k[CHG_SEQNO]) & 0x7fffffff; |
920 | |
923 | |
|
|
924 | // compatibility code, remove when no longer required |
|
|
925 | if (p->flags & 1) p->features |= FEATURE_COMPRESSION; |
|
|
926 | |
921 | conf->protocols = p->protocols; |
927 | conf->protocols = p->protocols; |
|
|
928 | features = p->features & FEATURES; |
922 | |
929 | |
923 | send_auth_response (rsi, p->id, k); |
930 | send_auth_response (rsi, p->id, k); |
924 | |
931 | |
925 | connection_established (); |
932 | connection_established (); |
926 | |
933 | |