View | Details | Raw Unified | Return to bug 235496 | Differences between
and this patch

Collapse All | Expand All

(-)spamd-4.9.1/spamd/sync.c (-20 / +36 lines)
Lines 53-58 Link Here
53
53
54
#include <openssl/hmac.h>
54
#include <openssl/hmac.h>
55
55
56
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
57
# define spamd_hmac_ctx HMAC_CTX *
58
# define spamd_hmac_ctx_init(ctx) ctx = HMAC_CTX_new()
59
# define spamd_hmac_sha1_init(ctx, key, keylen) HMAC_Init_ex(ctx, key, keylen, EVP_sha1(), NULL)
60
# define spamd_hmac_update(ctx, data, datalen) HMAC_Update(ctx, data, datalen)
61
# define spamd_hmac_final(ctx, data, datalen) HMAC_Final(ctx, data, datalen)
62
# define spamd_hmac_cleanup(ctx) HMAC_CTX_free(ctx)
63
#else
64
# define spamd_hmac_ctx HMAC_CTX
65
# define spamd_hmac_ctx_init(ctx) HMAC_CTX_init(&(ctx))
66
# define spamd_hmac_sha1_init(ctx, key, keylen) HMAC_Init_ex(&(ctx), key, keylen, EVP_sha1(), NULL)
67
# define spamd_hmac_update(ctx, data, datalen) HMAC_Update(&(ctx), data, datalen)
68
# define spamd_hmac_final(ctx, data, datalen) HMAC_Final(&(ctx), data, datalen)
69
# define spamd_hmac_cleanup(ctx) HMAC_cleanup(&(ctx))
70
#endif
71
56
#include "sdl.h"
72
#include "sdl.h"
57
#include "grey.h"
73
#include "grey.h"
58
#include "sync.h"
74
#include "sync.h"
Lines 439-445 Link Here
439
	u_int16_t sglen, fromlen, tolen, helolen, padlen;
455
	u_int16_t sglen, fromlen, tolen, helolen, padlen;
440
	char pad[SPAM_ALIGNBYTES];
456
	char pad[SPAM_ALIGNBYTES];
441
	int i = 0;
457
	int i = 0;
442
	HMAC_CTX ctx;
458
	spamd_hmac_ctx ctx;
443
	u_int hmac_len;
459
	u_int hmac_len;
444
460
445
	if (debug)
461
	if (debug)
Lines 455-462 Link Here
455
	tolen = strlen(to) + 1;
471
	tolen = strlen(to) + 1;
456
	helolen = strlen(helo) + 1;
472
	helolen = strlen(helo) + 1;
457
473
458
	HMAC_CTX_init(&ctx);
474
	spamd_hmac_ctx_init(ctx);
459
	HMAC_Init(&ctx, sync_key, strlen(sync_key), EVP_sha1());
475
	spamd_hmac_sha1_init(ctx, sync_key, strlen(sync_key));
460
476
461
	sglen = sizeof(sg) + fromlen + tolen + helolen;
477
	sglen = sizeof(sg) + fromlen + tolen + helolen;
462
	padlen = SPAM_ALIGN(sglen) - sglen;
478
	padlen = SPAM_ALIGN(sglen) - sglen;
Lines 468-474 Link Here
468
	hdr.sh_length = htons(sizeof(hdr) + sglen + padlen + sizeof(end));
484
	hdr.sh_length = htons(sizeof(hdr) + sglen + padlen + sizeof(end));
469
	iov[i].iov_base = &hdr;
485
	iov[i].iov_base = &hdr;
470
	iov[i].iov_len = sizeof(hdr);
486
	iov[i].iov_len = sizeof(hdr);
471
	HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
487
	spamd_hmac_update(ctx, iov[i].iov_base, iov[i].iov_len);
472
	i++;
488
	i++;
473
489
474
	/* Add single SPAM sync greylisting entry */
490
	/* Add single SPAM sync greylisting entry */
Lines 481-507 Link Here
481
	sg.sg_helo_length = htons(helolen);
497
	sg.sg_helo_length = htons(helolen);
482
	iov[i].iov_base = &sg;
498
	iov[i].iov_base = &sg;
483
	iov[i].iov_len = sizeof(sg);
499
	iov[i].iov_len = sizeof(sg);
484
	HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
500
	spamd_hmac_update(ctx, iov[i].iov_base, iov[i].iov_len);
485
	i++;
501
	i++;
486
502
487
	iov[i].iov_base = from;
503
	iov[i].iov_base = from;
488
	iov[i].iov_len = fromlen;
504
	iov[i].iov_len = fromlen;
489
	HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
505
	spamd_hmac_update(ctx, iov[i].iov_base, iov[i].iov_len);
490
	i++;
506
	i++;
491
507
492
	iov[i].iov_base = to;
508
	iov[i].iov_base = to;
493
	iov[i].iov_len = tolen;
509
	iov[i].iov_len = tolen;
494
	HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
510
	spamd_hmac_update(ctx, iov[i].iov_base, iov[i].iov_len);
495
	i++;
511
	i++;
496
512
497
	iov[i].iov_base = helo;
513
	iov[i].iov_base = helo;
498
	iov[i].iov_len = helolen;
514
	iov[i].iov_len = helolen;
499
	HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
515
	spamd_hmac_update(ctx, iov[i].iov_base, iov[i].iov_len);
500
	i++;
516
	i++;
501
517
502
	iov[i].iov_base = pad;
518
	iov[i].iov_base = pad;
503
	iov[i].iov_len = padlen;
519
	iov[i].iov_len = padlen;
504
	HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
520
	spamd_hmac_update(ctx, iov[i].iov_base, iov[i].iov_len);
505
	i++;
521
	i++;
506
522
507
	/* Add end marker */
523
	/* Add end marker */
Lines 509-522 Link Here
509
	end.st_length = htons(sizeof(end));
525
	end.st_length = htons(sizeof(end));
510
	iov[i].iov_base = &end;
526
	iov[i].iov_base = &end;
511
	iov[i].iov_len = sizeof(end);
527
	iov[i].iov_len = sizeof(end);
512
	HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
528
	spamd_hmac_update(ctx, iov[i].iov_base, iov[i].iov_len);
513
	i++;
529
	i++;
514
530
515
	HMAC_Final(&ctx, hdr.sh_hmac, &hmac_len);
531
	spamd_hmac_final(ctx, hdr.sh_hmac, &hmac_len);
516
532
517
	/* Send message to the target hosts */
533
	/* Send message to the target hosts */
518
	sync_send(iov, i);
534
	sync_send(iov, i);
519
	HMAC_CTX_cleanup(&ctx);
535
	spamd_hmac_cleanup(ctx);
520
}
536
}
521
537
522
void
538
void
Lines 527-533 Link Here
527
	struct spam_synctlv_addr sd;
543
	struct spam_synctlv_addr sd;
528
	struct spam_synctlv_hdr end;
544
	struct spam_synctlv_hdr end;
529
	int i = 0;
545
	int i = 0;
530
	HMAC_CTX ctx;
546
	spamd_hmac_ctx ctx;
531
	u_int hmac_len;
547
	u_int hmac_len;
532
548
533
	if (debug)
549
	if (debug)
Lines 537-544 Link Here
537
	bzero(&hdr, sizeof(hdr));
553
	bzero(&hdr, sizeof(hdr));
538
	bzero(&sd, sizeof(sd));
554
	bzero(&sd, sizeof(sd));
539
555
540
	HMAC_CTX_init(&ctx);
556
	spamd_hmac_ctx_init(ctx);
541
	HMAC_Init(&ctx, sync_key, strlen(sync_key), EVP_sha1());
557
	spamd_hmac_sha1_init(ctx, sync_key, strlen(sync_key));
542
558
543
	/* Add SPAM sync packet header */
559
	/* Add SPAM sync packet header */
544
	hdr.sh_version = SPAM_SYNC_VERSION;
560
	hdr.sh_version = SPAM_SYNC_VERSION;
Lines 547-553 Link Here
547
	hdr.sh_length = htons(sizeof(hdr) + sizeof(sd) + sizeof(end));
563
	hdr.sh_length = htons(sizeof(hdr) + sizeof(sd) + sizeof(end));
548
	iov[i].iov_base = &hdr;
564
	iov[i].iov_base = &hdr;
549
	iov[i].iov_len = sizeof(hdr);
565
	iov[i].iov_len = sizeof(hdr);
550
	HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
566
	spamd_hmac_update(ctx, iov[i].iov_base, iov[i].iov_len);
551
	i++;
567
	i++;
552
568
553
	/* Add single SPAM sync address entry */
569
	/* Add single SPAM sync address entry */
Lines 558-564 Link Here
558
	sd.sd_ip = inet_addr(ip);
574
	sd.sd_ip = inet_addr(ip);
559
	iov[i].iov_base = &sd;
575
	iov[i].iov_base = &sd;
560
	iov[i].iov_len = sizeof(sd);
576
	iov[i].iov_len = sizeof(sd);
561
	HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
577
	spamd_hmac_update(ctx, iov[i].iov_base, iov[i].iov_len);
562
	i++;
578
	i++;
563
579
564
	/* Add end marker */
580
	/* Add end marker */
Lines 566-579 Link Here
566
	end.st_length = htons(sizeof(end));
582
	end.st_length = htons(sizeof(end));
567
	iov[i].iov_base = &end;
583
	iov[i].iov_base = &end;
568
	iov[i].iov_len = sizeof(end);
584
	iov[i].iov_len = sizeof(end);
569
	HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
585
	spamd_hmac_update(ctx, iov[i].iov_base, iov[i].iov_len);
570
	i++;
586
	i++;
571
587
572
	HMAC_Final(&ctx, hdr.sh_hmac, &hmac_len);
588
	spamd_hmac_final(ctx, hdr.sh_hmac, &hmac_len);
573
589
574
	/* Send message to the target hosts */
590
	/* Send message to the target hosts */
575
	sync_send(iov, i);
591
	sync_send(iov, i);
576
	HMAC_CTX_cleanup(&ctx);
592
	spamd_hmac_cleanup(ctx);
577
}
593
}
578
594
579
void
595
void

Return to bug 235496