ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/protocol.C
(Generate patch)

Comparing gvpe/src/protocol.C (file contents):
Revision 1.11 by pcg, Sat Mar 22 21:35:07 2003 UTC vs.
Revision 1.14 by pcg, Sat Mar 22 22:39:11 2003 UTC

445 } 445 }
446#endif 446#endif
447 447
448 EVP_EncryptInit_ex (cctx, 0, 0, 0, 0); 448 EVP_EncryptInit_ex (cctx, 0, 0, 0, 0);
449 449
450 struct {
450#if RAND_SIZE 451#if RAND_SIZE
451 struct {
452 u8 rnd[RAND_SIZE]; 452 u8 rnd[RAND_SIZE];
453#endif
453 u32 seqno; 454 u32 seqno;
454 } datahdr; 455 } datahdr;
455 456
456 datahdr.seqno = seqno; 457 datahdr.seqno = ntohl (seqno);
458#if RAND_SIZE
457 RAND_pseudo_bytes ((unsigned char *) datahdr.rnd, RAND_SIZE); 459 RAND_pseudo_bytes ((unsigned char *) datahdr.rnd, RAND_SIZE);
460#endif
458 461
459 EVP_EncryptUpdate (cctx, 462 EVP_EncryptUpdate (cctx,
460 (unsigned char *) data + outl, &outl2, 463 (unsigned char *) data + outl, &outl2,
461 (unsigned char *) &datahdr, DATAHDR); 464 (unsigned char *) &datahdr, DATAHDR);
462 outl += outl2; 465 outl += outl2;
463#else
464 EVP_EncryptUpdate (cctx,
465 (unsigned char *) data + outl, &outl2,
466 (unsigned char *) &seqno, DATAHDR);
467 outl += outl2;
468#endif
469 466
470 EVP_EncryptUpdate (cctx, 467 EVP_EncryptUpdate (cctx,
471 (unsigned char *) data + outl, &outl2, 468 (unsigned char *) data + outl, &outl2,
472 (unsigned char *) d, l); 469 (unsigned char *) d, l);
473 outl += outl2; 470 outl += outl2;
509 outl += outl2; 506 outl += outl2;
510 507
511 EVP_DecryptFinal_ex (cctx, (unsigned char *)d + outl, &outl2); 508 EVP_DecryptFinal_ex (cctx, (unsigned char *)d + outl, &outl2);
512 outl += outl2; 509 outl += outl2;
513 510
514 seqno = *(u32 *)(d + RAND_SIZE); 511 seqno = ntohl (*(u32 *)(d + RAND_SIZE));
515 512
516 id2mac (dst () ? dst() : THISNODE->id, p->dst); 513 id2mac (dst () ? dst() : THISNODE->id, p->dst);
517 id2mac (src (), p->src); 514 id2mac (src (), p->src);
518 515
519#if ENABLE_COMPRESSION 516#if ENABLE_COMPRESSION
549 u32 digest_nid; 546 u32 digest_nid;
550 547
551 const u8 curflags () const 548 const u8 curflags () const
552 { 549 {
553 return 0x80 550 return 0x80
554 | 0x02
555#if PROTOCOL_MAJOR != 2
556#error hi
557#endif
558 | (ENABLE_COMPRESSION ? 0x01 : 0x00); 551 | (ENABLE_COMPRESSION ? 0x01 : 0x00);
559 } 552 }
560 553
561 void setup (ptype type, int dst) 554 void setup (ptype type, int dst)
562 { 555 {
891 884
892 const rsachallenge *k = rsa_cache.private_decrypt (::conf.rsa_key, p->challenge); 885 const rsachallenge *k = rsa_cache.private_decrypt (::conf.rsa_key, p->challenge);
893 886
894 if (!k) 887 if (!k)
895 { 888 {
896 slog (L_ERR, _("challenge from %s (%s) illegal or corrupted, disabling node"), 889 slog (L_ERR, _("challenge from %s (%s) illegal or corrupted"),
897 conf->nodename, (const char *)sockinfo (ssa)); 890 conf->nodename, (const char *)sockinfo (ssa));
898 connectmode = conf_node::C_DISABLED;
899 break; 891 break;
900 } 892 }
901 893
902 retry_cnt = 0; 894 retry_cnt = 0;
903 establish_connection.set (NOW + 8); //? ;) 895 establish_connection.set (NOW + 8); //? ;)
912 ictx = 0; 904 ictx = 0;
913 905
914 delete octx; 906 delete octx;
915 907
916 octx = new crypto_ctx (*k, 1); 908 octx = new crypto_ctx (*k, 1);
917 oseqno = *(u32 *)&k[CHG_SEQNO] & 0x7fffffff; 909 oseqno = ntohl (*(u32 *)&k[CHG_SEQNO]) & 0x7fffffff;
918 910
919 send_auth (AUTH_REPLY, ssa, k); 911 send_auth (AUTH_REPLY, ssa, k);
920 break; 912 break;
921 913
922 case AUTH_REPLY: 914 case AUTH_REPLY:
924 if (!memcmp ((u8 *)gen_challenge (seqrand, ssa), (u8 *)k, sizeof (rsachallenge))) 916 if (!memcmp ((u8 *)gen_challenge (seqrand, ssa), (u8 *)k, sizeof (rsachallenge)))
925 { 917 {
926 delete ictx; 918 delete ictx;
927 919
928 ictx = new crypto_ctx (*k, 0); 920 ictx = new crypto_ctx (*k, 0);
929 iseqno.reset (*(u32 *)&k[CHG_SEQNO] & 0x7fffffff); // at least 2**31 sequence numbers are valid 921 iseqno.reset (ntohl (*(u32 *)&k[CHG_SEQNO]) & 0x7fffffff); // at least 2**31 sequence numbers are valid
930 922
931 sa = *ssa; 923 sa = *ssa;
932 924
933 rekey.set (NOW + ::conf.rekey); 925 rekey.set (NOW + ::conf.rekey);
934 keepalive.set (NOW + ::conf.keepalive); 926 keepalive.set (NOW + ::conf.keepalive);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines