Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Unix Operating Systems > OpenBSD > mailing.openbsd.tech

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-18-2008, 09:31 AM
Tom Cosgrove
 
Posts: n/a
Default Calling all isakmpd(8) users

Short version:

PLEASE TRY RUNNING WITH THIS DIFF.

If it stops your current setup working, please let me and the lists know
as soon as possible. If things continue to work, just send an email
direct to me - I would like to get this put in for 4.2.

This diff fixes a long-standing interoperability issue between OpenBSD
isakmpd and Cisco IOS (and possibly others). There is a small
possibility that it may break existing configurations, and it is that
which we would like to rule out.

I'm looking for configurations that are OpenBSD-to-OpenBSD, as well as
OpenBSD-to-non-OpenBSD. Testing of different versions, as well as
patched-to-unpatched, gets extra bonus points.


Long version:

When performing Phase 1 key exchange using RSA signature authentication,
an OpenBSD isakmpd always sends the certificate of its claimed
identity. We assume that the remote end will do the same: we don't
send a CERT_REQUEST message.

This works fine when we're talking to OpenBSD and most other systems,
but Cisco IOS will not send its certificate unless it first receives a
CERT_REQUEST message.

(There's an interoperability test that hit this issue at
http://www.hsc.fr/ressources/ipsec/i.../index.html.en, and a
discussion about CERT_REQUEST payloads at
http://www.sandelman.ca/ipsec/2000/01/msg00118.html, for those who
are interested.)

Now, the CERT_REQUEST message gets sent before we have authenticated
the peer (of course!). So we're giving out information about which
CA(s) we trust to all and sundry, possibly allowing them to target a
weak CA.

So what this diff does it to *only* send a CERT_REQUEST if the peer
first sends us one (i.e. this is for IOS as initiator and OpenBSD as
responder). And all we do is reflect back the CA that came in the
inbound CERT_REQUEST. (Not nice, but it avoids the information leak.
And since we don't know the ID that the initiator will claim at this
point, we either have to send all CAs that we will accept or randomly
pick one. This seems to be the best compromise.)

Further, we only do this if we do actually have at least one CA
certificate in our CA-directory (usually /etc/isakmpd/ca/). And this
is for working with ipsec.conf, rather than keynote.

Anyway, many people have helped me with this diff, including cloder@,
hshoexer@ and mpf@. And Stuart Henderson helped with some of the
testing earlier in the year.

All this for three pairs of messages!

Thanks

Tom


Index: cert.c
================================================== =================
RCS file: /cvs/src/sbin/isakmpd/cert.c,v
retrieving revision 1.31
diff -u -p -r1.31 cert.c
--- cert.c 8 Apr 2005 22:32:09 -0000 1.31
+++ cert.c 31 Jul 2007 19:56:06 -0000
@@ -49,7 +49,8 @@ struct cert_handler cert_handler[] = {
x509_cert_insert, x509_cert_free,
x509_certreq_validate, x509_certreq_decode, x509_free_aca,
x509_cert_obtain, x509_cert_get_key, x509_cert_get_subjects,
- x509_cert_dup, x509_serialize, x509_printable, x509_from_printable
+ x509_cert_dup, x509_serialize, x509_printable, x509_from_printable,
+ x509_ca_count
},
{
ISAKMP_CERTENC_KEYNOTE,
@@ -58,7 +59,7 @@ struct cert_handler cert_handler[] = {
keynote_certreq_validate, keynote_certreq_decode, keynote_free_aca,
keynote_cert_obtain, keynote_cert_get_key, keynote_cert_get_subjects,
keynote_cert_dup, keynote_serialize, keynote_printable,
- keynote_from_printable
+ keynote_from_printable, keynote_ca_count
},
};

@@ -118,18 +119,32 @@ certreq_decode(u_int16_t type, u_int8_t

aca.id = type;
aca.handler = handler;
+ aca.data = aca.raw_ca = NULL;

if (datalen > 0) {
- aca.data = handler->certreq_decode(data, datalen);
- if (!aca.data)
+ int rc;
+
+ rc = handler->certreq_decode(&aca.data, data, datalen);
+ if (!rc)
+ return 0;
+
+ aca.raw_ca = malloc(datalen);
+ if (aca.raw_ca == NULL) {
+ log_error("certreq_decode: malloc (%lu) failed",
+ (unsigned long)datalen);
+ handler->free_aca(aca.data);
return 0;
- } else
- aca.data = 0;
+ }
+
+ memcpy(aca.raw_ca, data, datalen);
+ }
+ aca.raw_ca_len = datalen;

ret = malloc(sizeof aca);
if (!ret) {
log_error("certreq_decode: malloc (%lu) failed",
(unsigned long)sizeof aca);
+ free(aca.raw_ca);
handler->free_aca(aca.data);
return 0;
}
Index: cert.h
================================================== =================
RCS file: /cvs/src/sbin/isakmpd/cert.h,v
retrieving revision 1.14
diff -u -p -r1.14 cert.h
--- cert.h 14 May 2004 08:42:56 -0000 1.14
+++ cert.h 31 Jul 2007 19:56:06 -0000
@@ -52,6 +52,7 @@
* cert_printable - for X509, the hex representation of the serialized form;
* for KeyNote, itself.
* cert_from_printable - the reverse of cert_printable
+ * ca_count - how many CAs we have in our store (for CERT_REQ processing)
*/

struct cert_handler {
@@ -63,7 +64,7 @@ struct cert_handler {
int (*cert_insert)(int, void *);
void (*cert_free)(void *);
int (*certreq_validate)(u_int8_t *, u_int32_t);
- void *(*certreq_decode)(u_int8_t *, u_int32_t);
+ int (*certreq_decode)(void **, u_int8_t *, u_int32_t);
void (*free_aca)(void *);
int (*cert_obtain)(u_int8_t *, size_t, void *, u_int8_t **,
u_int32_t *);
@@ -74,6 +75,7 @@ struct cert_handler {
void (*cert_serialize) (void *, u_int8_t **, u_int32_t *);
char *(*cert_printable) (void *);
void *(*cert_from_printable) (char *);
+ int (*ca_count)(void);
};

/* The acceptable authority of cert request. */
@@ -85,6 +87,10 @@ struct certreq_aca {

/* If data is a null pointer, everything is acceptable. */
void *data;
+
+ /* Copy of raw CA value received */
+ u_int32_t raw_ca_len;
+ void *raw_ca;
};

struct certreq_aca *certreq_decode(u_int16_t, u_int8_t *, u_int32_t);
Index: exchange.c
================================================== =================
RCS file: /cvs/src/sbin/isakmpd/exchange.c,v
retrieving revision 1.130
diff -u -p -r1.130 exchange.c
--- exchange.c 16 Apr 2007 13:01:39 -0000 1.130
+++ exchange.c 31 Jul 2007 19:56:07 -0000
@@ -1593,6 +1593,8 @@ exchange_free_aca_list(struct exchange *

for (aca = TAILQ_FIRST(&exchange->aca_list); aca;
aca = TAILQ_FIRST(&exchange->aca_list)) {
+ if (aca->raw_ca)
+ free(aca->raw_ca);
if (aca->data) {
if (aca->handler)
aca->handler->free_aca(aca->data);
@@ -1601,6 +1603,58 @@ exchange_free_aca_list(struct exchange *
TAILQ_REMOVE(&exchange->aca_list, aca, link);
free(aca);
}
+}
+
+/* Add any CERTREQs we should send. */
+int
+exchange_add_certreqs(struct message *msg)
+{
+ struct exchange *exchange = msg->exchange;
+ struct certreq_aca *aca;
+ u_int8_t *buf;
+
+ /*
+ * Some peers (e.g. Cisco IOS) won't send their cert unless we
+ * specifically ask beforehand with CERTREQ. We reflect any
+ * CERTREQs we receive from the initiator in order to do this.
+ * This avoids leaking information about which CAs we trust,
+ * and works in the most common case where both ends trust the
+ * same CA.
+ */
+ for (aca = TAILQ_FIRST(&exchange->aca_list); aca;
+ aca = TAILQ_NEXT(aca, link)) {
+
+ /* But only do this if we have at least one CA */
+ if (aca->handler != NULL && aca->handler->ca_count() == 0) {
+ LOG_DBG((LOG_EXCHANGE, 10,
+ "exchange_add_certreqs: no CA, so not "
+ "sending a CERTREQ"));
+ continue;
+ }
+
+ if (aca->raw_ca_len) {
+ buf = malloc(ISAKMP_CERTREQ_SZ + aca->raw_ca_len);
+ if (buf == NULL) {
+ log_error("exchange_add_certreqs: "
+ "malloc (%lu) failed",
+ ISAKMP_CERTREQ_SZ +
+ (unsigned long)aca->raw_ca_len);
+ return -1;
+ }
+
+ buf[ISAKMP_CERTREQ_TYPE_OFF] = aca->id;
+ memcpy(buf + ISAKMP_CERTREQ_AUTHORITY_OFF,
+ aca->raw_ca, aca->raw_ca_len);
+
+ if (message_add_payload(msg, ISAKMP_PAYLOAD_CERT_REQ,
+ buf, ISAKMP_CERTREQ_SZ + aca->raw_ca_len, 1)) {
+ free(buf);
+ return -1;
+ }
+ }
+ }
+
+ return 0;
}

/* Obtain certificates from acceptable certification authority. */
Index: exchange.h
================================================== =================
RCS file: /cvs/src/sbin/isakmpd/exchange.h,v
retrieving revision 1.32
diff -u -p -r1.32 exchange.h
--- exchange.h 2 Jul 2006 13:19:00 -0000 1.32
+++ exchange.h 31 Jul 2007 19:56:08 -0000
@@ -224,6 +224,7 @@ struct exchange {
#define EXCHANGE_FLAG_OPENBSD 0x0200 /* Peer is OpenBSD */

extern int exchange_add_certs(struct message *);
+extern int exchange_add_certreqs(struct message *);
extern void exchange_finalize(struct message *);
extern void exchange_free(struct exchange *);
extern void exchange_free_aca_list(struct exchange *);
Index: ike_phase_1.c
================================================== =================
RCS file: /cvs/src/sbin/isakmpd/ike_phase_1.c,v
retrieving revision 1.69
diff -u -p -r1.69 ike_phase_1.c
--- ike_phase_1.c 7 May 2007 18:19:56 -0000 1.69
+++ ike_phase_1.c 31 Jul 2007 19:56:09 -0000
@@ -548,6 +548,11 @@ ike_phase_1_send_KE_NONCE(struct message
/* XXX Log? */
return -1;
}
+ /* Are there any CERTREQs to send? */
+ if (exchange_add_certreqs(msg)) {
+ /* XXX Log? */
+ return -1;
+ }
/* Try to add certificates which are acceptable for the CERTREQs */
if (exchange_add_certs(msg)) {
/* XXX Log? */
Index: policy.c
================================================== =================
RCS file: /cvs/src/sbin/isakmpd/policy.c,v
retrieving revision 1.90
diff -u -p -r1.90 policy.c
--- policy.c 16 Apr 2007 13:01:39 -0000 1.90
+++ policy.c 31 Jul 2007 19:56:11 -0000
@@ -2096,11 +2096,11 @@ keynote_certreq_validate(u_int8_t *data,
}

/* Beats me what we should be doing with this. */
-void *
-keynote_certreq_decode(u_int8_t *data, u_int32_t len)
+int
+keynote_certreq_decode(void **pdata, u_int8_t *data, u_int32_t len)
{
/* XXX */
- return NULL;
+ return 0;
}

void
@@ -2301,4 +2301,11 @@ void *
keynote_from_printable(char *cert)
{
return strdup(cert);
+}
+
+/* Number of CAs we trust (currently this is x509 only) */
+int
+keynote_ca_count(void)
+{
+ return 0;
}
Index: policy.h
================================================== =================
RCS file: /cvs/src/sbin/isakmpd/policy.h,v
retrieving revision 1.16
diff -u -p -r1.16 policy.h
--- policy.h 5 Apr 2005 22:53:50 -0000 1.16
+++ policy.h 31 Jul 2007 19:56:13 -0000
@@ -54,7 +54,7 @@ extern int keynote_cert_validate(vo
extern int keynote_cert_insert(int, void *);
extern void keynote_cert_free(void *);
extern int keynote_certreq_validate(u_int8_t *, u_int32_t);
-extern void *keynote_certreq_decode(u_int8_t *, u_int32_t);
+extern int keynote_certreq_decode(void **, u_int8_t *, u_int32_t);
extern void keynote_free_aca(void *);
extern int keynote_cert_obtain(u_int8_t *, size_t, void *,
u_int8_t **, u_int32_t *);
@@ -65,4 +65,5 @@ extern void *keynote_cert_dup(void *)
extern void keynote_serialize(void *, u_int8_t **, u_int32_t *);
extern char *keynote_printable(void *);
extern void *keynote_from_printable(char *);
+extern int keynote_ca_count(void);
#endif /* _POLICY_H_ */
Index: x509.c
================================================== =================
RCS file: /cvs/src/sbin/isakmpd/x509.c,v
retrieving revision 1.109
diff -u -p -r1.109 x509.c
--- x509.c 16 Apr 2007 13:01:39 -0000 1.109
+++ x509.c 31 Jul 2007 19:56:13 -0000
@@ -1,4 +1,4 @@
-/* $OpenBSD: x509.c,v 1.109 2007/04/16 13:01:39 moritz Exp $ */
+/* $OpenBSD: x509.c,v 1.108 2007/03/03 20:03:03 tom Exp $ */
/* $EOM: x509.c,v 1.54 2001/01/16 18:42:16 ho Exp $ */

/*
@@ -78,6 +78,8 @@ static int x509_hash_enter(X509 *);
static X509_STORE *x509_certs = 0;
static X509_STORE *x509_cas = 0;

+static int n_x509_cas = 0;
+
/* Initial number of bits used as hash. */
#define INITIAL_BUCKET_BITS 6

@@ -571,7 +573,7 @@ x509_hash_enter(X509 *cert)
/* X509 Certificate Handling functions. */

int
-x509_read_from_dir(X509_STORE *ctx, char *name, int hash)
+x509_read_from_dir(X509_STORE *ctx, char *name, int hash, int *pcount)
{
FILE *certfp;
X509 *cert;
@@ -628,6 +630,10 @@ x509_read_from_dir(X509_STORE *ctx, char
"failed for %s", file);
continue;
}
+
+ if (pcount != NULL)
+ (*pcount)++;
+
if (!X509_STORE_add_cert(ctx, cert)) {
/*
* This is actually expected if we have several
@@ -752,7 +758,7 @@ x509_cert_init(void)
log_print("x509_cert_init: creating new X509_STORE failed");
return 0;
}
- if (!x509_read_from_dir(x509_cas, dirname, 0)) {
+ if (!x509_read_from_dir(x509_cas, dirname, 0, &n_x509_cas)) {
log_print("x509_cert_init: x509_read_from_dir failed");
return 0;
}
@@ -771,7 +777,7 @@ x509_cert_init(void)
log_print("x509_cert_init: creating new X509_STORE failed");
return 0;
}
- if (!x509_read_from_dir(x509_certs, dirname, 1)) {
+ if (!x509_read_from_dir(x509_certs, dirname, 1, NULL)) {
log_print("x509_cert_init: x509_read_from_dir failed");
return 0;
}
@@ -949,8 +955,8 @@ x509_certreq_validate(u_int8_t *asn, u_i
}

/* Decode the BER Encoding of a RDNSequence in the CERT_REQ payload. */
-void *
-x509_certreq_decode(u_int8_t *asn, u_int32_t len)
+int
+x509_certreq_decode(void **pdata, u_int8_t *asn, u_int32_t len)
{
#if 0
/* XXX This needs to be done later. */
@@ -993,7 +999,7 @@ x509_certreq_decode(u_int8_t *asn, u_int
fail:
asn_free(&aca);
#endif
- return 0;
+ return 1;
}

void
@@ -1001,11 +1007,13 @@ x509_free_aca(void *blob)
{
struct x509_aca *aca = blob;

- free(aca->name1.type);
- free(aca->name1.val);
+ if (aca != NULL) {
+ free(aca->name1.type);
+ free(aca->name1.val);

- free(aca->name2.type);
- free(aca->name2.val);
+ free(aca->name2.type);
+ free(aca->name2.val);
+ }
}

X509 *
@@ -1338,3 +1346,9 @@ x509_DN_string(u_int8_t *asn1, size_t sz
return strdup(buf);
}

+/* Number of CAs we trust (to decide whether we can send CERT_REQ) */
+int
+x509_ca_count(void)
+{
+ return n_x509_cas;
+}
Index: x509.h
================================================== =================
RCS file: /cvs/src/sbin/isakmpd/x509.h,v
retrieving revision 1.21
diff -u -p -r1.21 x509.h
--- x509.h 23 May 2004 18:17:56 -0000 1.21
+++ x509.h 31 Jul 2007 19:56:13 -0000
@@ -61,7 +61,7 @@ struct X509_STORE;
/* Functions provided by cert handler. */

int x509_certreq_validate(u_int8_t *, u_int32_t);
-void *x509_certreq_decode(u_int8_t *, u_int32_t);
+int x509_certreq_decode(void **, u_int8_t *, u_int32_t);
void x509_cert_free(void *);
void *x509_cert_get(u_int8_t *, u_int32_t);
int x509_cert_get_key(void *, void *);
@@ -76,6 +76,7 @@ void *x509_cert_dup(void *);
void x509_serialize(void *, u_int8_t **, u_int32_t *);
char *x509_printable(void *);
void *x509_from_printable(char *);
+int x509_ca_count(void);

/* Misc. X509 certificate functions. */

@@ -84,7 +85,7 @@ int x509_cert_insert(int, vo
int x509_cert_subjectaltname(X509 * cert, u_char **, u_int *);
X509 *x509_from_asn(u_char *, u_int);
int x509_generate_kn(int, X509 *);
-int x509_read_from_dir(X509_STORE *, char *, int);
+int x509_read_from_dir(X509_STORE *, char *, int, int *);
int x509_read_crls_from_dir(X509_STORE *, char *);

#endif /* _X509_H_ */

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:28 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054