diff options
author | Colin Watson <cjwatson@debian.org> | 2015-08-19 14:23:51 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2015-08-19 16:48:11 +0100 |
commit | 0f0841b2d28b7463267d4d91577e72e3340a1d3a (patch) | |
tree | ba55fcd2b6e2cc22b30f5afb561dbb3da4c8b6c7 /monitor_wrap.c | |
parent | f2a5f5dae656759efb0b76c3d94890b65c197a02 (diff) | |
parent | 8698446b972003b63dfe5dcbdb86acfe986afb85 (diff) |
New upstream release (6.8p1).
Diffstat (limited to 'monitor_wrap.c')
-rw-r--r-- | monitor_wrap.c | 255 |
1 files changed, 21 insertions, 234 deletions
diff --git a/monitor_wrap.c b/monitor_wrap.c index 4c57d4df3..a5f4e9d3c 100644 --- a/monitor_wrap.c +++ b/monitor_wrap.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: monitor_wrap.c,v 1.80 2014/04/29 18:01:49 markus Exp $ */ | 1 | /* $OpenBSD: monitor_wrap.c,v 1.84 2015/02/16 22:13:32 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright 2002 Niels Provos <provos@citi.umich.edu> | 3 | * Copyright 2002 Niels Provos <provos@citi.umich.edu> |
4 | * Copyright 2002 Markus Friedl <markus@openbsd.org> | 4 | * Copyright 2002 Markus Friedl <markus@openbsd.org> |
@@ -82,6 +82,8 @@ | |||
82 | #include "servconf.h" | 82 | #include "servconf.h" |
83 | #include "roaming.h" | 83 | #include "roaming.h" |
84 | 84 | ||
85 | #include "ssherr.h" | ||
86 | |||
85 | /* Imports */ | 87 | /* Imports */ |
86 | extern int compat20; | 88 | extern int compat20; |
87 | extern z_stream incoming_stream; | 89 | extern z_stream incoming_stream; |
@@ -151,8 +153,10 @@ mm_request_receive(int sock, Buffer *m) | |||
151 | debug3("%s entering", __func__); | 153 | debug3("%s entering", __func__); |
152 | 154 | ||
153 | if (atomicio(read, sock, buf, sizeof(buf)) != sizeof(buf)) { | 155 | if (atomicio(read, sock, buf, sizeof(buf)) != sizeof(buf)) { |
154 | if (errno == EPIPE) | 156 | if (errno == EPIPE) { |
157 | error("%s: socket closed", __func__); | ||
155 | cleanup_exit(255); | 158 | cleanup_exit(255); |
159 | } | ||
156 | fatal("%s: read: %s", __func__, strerror(errno)); | 160 | fatal("%s: read: %s", __func__, strerror(errno)); |
157 | } | 161 | } |
158 | msg_len = get_u32(buf); | 162 | msg_len = get_u32(buf); |
@@ -215,15 +219,16 @@ mm_choose_dh(int min, int nbits, int max) | |||
215 | #endif | 219 | #endif |
216 | 220 | ||
217 | int | 221 | int |
218 | mm_key_sign(Key *key, u_char **sigp, u_int *lenp, u_char *data, u_int datalen) | 222 | mm_key_sign(Key *key, u_char **sigp, u_int *lenp, |
223 | const u_char *data, u_int datalen) | ||
219 | { | 224 | { |
220 | Kex *kex = *pmonitor->m_pkex; | 225 | struct kex *kex = *pmonitor->m_pkex; |
221 | Buffer m; | 226 | Buffer m; |
222 | 227 | ||
223 | debug3("%s entering", __func__); | 228 | debug3("%s entering", __func__); |
224 | 229 | ||
225 | buffer_init(&m); | 230 | buffer_init(&m); |
226 | buffer_put_int(&m, kex->host_key_index(key)); | 231 | buffer_put_int(&m, kex->host_key_index(key, 0, active_state)); |
227 | buffer_put_string(&m, data, datalen); | 232 | buffer_put_string(&m, data, datalen); |
228 | 233 | ||
229 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SIGN, &m); | 234 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SIGN, &m); |
@@ -486,239 +491,21 @@ mm_key_verify(Key *key, u_char *sig, u_int siglen, u_char *data, u_int datalen) | |||
486 | return (verified); | 491 | return (verified); |
487 | } | 492 | } |
488 | 493 | ||
489 | /* Export key state after authentication */ | ||
490 | Newkeys * | ||
491 | mm_newkeys_from_blob(u_char *blob, int blen) | ||
492 | { | ||
493 | Buffer b; | ||
494 | u_int len; | ||
495 | Newkeys *newkey = NULL; | ||
496 | Enc *enc; | ||
497 | Mac *mac; | ||
498 | Comp *comp; | ||
499 | |||
500 | debug3("%s: %p(%d)", __func__, blob, blen); | ||
501 | #ifdef DEBUG_PK | ||
502 | dump_base64(stderr, blob, blen); | ||
503 | #endif | ||
504 | buffer_init(&b); | ||
505 | buffer_append(&b, blob, blen); | ||
506 | |||
507 | newkey = xcalloc(1, sizeof(*newkey)); | ||
508 | enc = &newkey->enc; | ||
509 | mac = &newkey->mac; | ||
510 | comp = &newkey->comp; | ||
511 | |||
512 | /* Enc structure */ | ||
513 | enc->name = buffer_get_string(&b, NULL); | ||
514 | buffer_get(&b, &enc->cipher, sizeof(enc->cipher)); | ||
515 | enc->enabled = buffer_get_int(&b); | ||
516 | enc->block_size = buffer_get_int(&b); | ||
517 | enc->key = buffer_get_string(&b, &enc->key_len); | ||
518 | enc->iv = buffer_get_string(&b, &enc->iv_len); | ||
519 | |||
520 | if (enc->name == NULL || cipher_by_name(enc->name) != enc->cipher) | ||
521 | fatal("%s: bad cipher name %s or pointer %p", __func__, | ||
522 | enc->name, enc->cipher); | ||
523 | |||
524 | /* Mac structure */ | ||
525 | if (cipher_authlen(enc->cipher) == 0) { | ||
526 | mac->name = buffer_get_string(&b, NULL); | ||
527 | if (mac->name == NULL || mac_setup(mac, mac->name) == -1) | ||
528 | fatal("%s: can not setup mac %s", __func__, mac->name); | ||
529 | mac->enabled = buffer_get_int(&b); | ||
530 | mac->key = buffer_get_string(&b, &len); | ||
531 | if (len > mac->key_len) | ||
532 | fatal("%s: bad mac key length: %u > %d", __func__, len, | ||
533 | mac->key_len); | ||
534 | mac->key_len = len; | ||
535 | } | ||
536 | |||
537 | /* Comp structure */ | ||
538 | comp->type = buffer_get_int(&b); | ||
539 | comp->enabled = buffer_get_int(&b); | ||
540 | comp->name = buffer_get_string(&b, NULL); | ||
541 | |||
542 | len = buffer_len(&b); | ||
543 | if (len != 0) | ||
544 | error("newkeys_from_blob: remaining bytes in blob %u", len); | ||
545 | buffer_free(&b); | ||
546 | return (newkey); | ||
547 | } | ||
548 | |||
549 | int | ||
550 | mm_newkeys_to_blob(int mode, u_char **blobp, u_int *lenp) | ||
551 | { | ||
552 | Buffer b; | ||
553 | int len; | ||
554 | Enc *enc; | ||
555 | Mac *mac; | ||
556 | Comp *comp; | ||
557 | Newkeys *newkey = (Newkeys *)packet_get_newkeys(mode); | ||
558 | |||
559 | debug3("%s: converting %p", __func__, newkey); | ||
560 | |||
561 | if (newkey == NULL) { | ||
562 | error("%s: newkey == NULL", __func__); | ||
563 | return 0; | ||
564 | } | ||
565 | enc = &newkey->enc; | ||
566 | mac = &newkey->mac; | ||
567 | comp = &newkey->comp; | ||
568 | |||
569 | buffer_init(&b); | ||
570 | /* Enc structure */ | ||
571 | buffer_put_cstring(&b, enc->name); | ||
572 | /* The cipher struct is constant and shared, you export pointer */ | ||
573 | buffer_append(&b, &enc->cipher, sizeof(enc->cipher)); | ||
574 | buffer_put_int(&b, enc->enabled); | ||
575 | buffer_put_int(&b, enc->block_size); | ||
576 | buffer_put_string(&b, enc->key, enc->key_len); | ||
577 | packet_get_keyiv(mode, enc->iv, enc->iv_len); | ||
578 | buffer_put_string(&b, enc->iv, enc->iv_len); | ||
579 | |||
580 | /* Mac structure */ | ||
581 | if (cipher_authlen(enc->cipher) == 0) { | ||
582 | buffer_put_cstring(&b, mac->name); | ||
583 | buffer_put_int(&b, mac->enabled); | ||
584 | buffer_put_string(&b, mac->key, mac->key_len); | ||
585 | } | ||
586 | |||
587 | /* Comp structure */ | ||
588 | buffer_put_int(&b, comp->type); | ||
589 | buffer_put_int(&b, comp->enabled); | ||
590 | buffer_put_cstring(&b, comp->name); | ||
591 | |||
592 | len = buffer_len(&b); | ||
593 | if (lenp != NULL) | ||
594 | *lenp = len; | ||
595 | if (blobp != NULL) { | ||
596 | *blobp = xmalloc(len); | ||
597 | memcpy(*blobp, buffer_ptr(&b), len); | ||
598 | } | ||
599 | explicit_bzero(buffer_ptr(&b), len); | ||
600 | buffer_free(&b); | ||
601 | return len; | ||
602 | } | ||
603 | |||
604 | static void | ||
605 | mm_send_kex(Buffer *m, Kex *kex) | ||
606 | { | ||
607 | buffer_put_string(m, kex->session_id, kex->session_id_len); | ||
608 | buffer_put_int(m, kex->we_need); | ||
609 | buffer_put_int(m, kex->hostkey_type); | ||
610 | buffer_put_int(m, kex->kex_type); | ||
611 | buffer_put_string(m, buffer_ptr(&kex->my), buffer_len(&kex->my)); | ||
612 | buffer_put_string(m, buffer_ptr(&kex->peer), buffer_len(&kex->peer)); | ||
613 | buffer_put_int(m, kex->flags); | ||
614 | buffer_put_cstring(m, kex->client_version_string); | ||
615 | buffer_put_cstring(m, kex->server_version_string); | ||
616 | } | ||
617 | |||
618 | void | 494 | void |
619 | mm_send_keystate(struct monitor *monitor) | 495 | mm_send_keystate(struct monitor *monitor) |
620 | { | 496 | { |
621 | Buffer m, *input, *output; | 497 | struct ssh *ssh = active_state; /* XXX */ |
622 | u_char *blob, *p; | 498 | struct sshbuf *m; |
623 | u_int bloblen, plen; | 499 | int r; |
624 | u_int32_t seqnr, packets; | 500 | |
625 | u_int64_t blocks, bytes; | 501 | if ((m = sshbuf_new()) == NULL) |
626 | 502 | fatal("%s: sshbuf_new failed", __func__); | |
627 | buffer_init(&m); | 503 | if ((r = ssh_packet_get_state(ssh, m)) != 0) |
628 | 504 | fatal("%s: get_state failed: %s", | |
629 | if (!compat20) { | 505 | __func__, ssh_err(r)); |
630 | u_char iv[24]; | 506 | mm_request_send(monitor->m_recvfd, MONITOR_REQ_KEYEXPORT, m); |
631 | u_char *key; | ||
632 | u_int ivlen, keylen; | ||
633 | |||
634 | buffer_put_int(&m, packet_get_protocol_flags()); | ||
635 | |||
636 | buffer_put_int(&m, packet_get_ssh1_cipher()); | ||
637 | |||
638 | debug3("%s: Sending ssh1 KEY+IV", __func__); | ||
639 | keylen = packet_get_encryption_key(NULL); | ||
640 | key = xmalloc(keylen+1); /* add 1 if keylen == 0 */ | ||
641 | keylen = packet_get_encryption_key(key); | ||
642 | buffer_put_string(&m, key, keylen); | ||
643 | explicit_bzero(key, keylen); | ||
644 | free(key); | ||
645 | |||
646 | ivlen = packet_get_keyiv_len(MODE_OUT); | ||
647 | packet_get_keyiv(MODE_OUT, iv, ivlen); | ||
648 | buffer_put_string(&m, iv, ivlen); | ||
649 | ivlen = packet_get_keyiv_len(MODE_IN); | ||
650 | packet_get_keyiv(MODE_IN, iv, ivlen); | ||
651 | buffer_put_string(&m, iv, ivlen); | ||
652 | goto skip; | ||
653 | } else { | ||
654 | /* Kex for rekeying */ | ||
655 | mm_send_kex(&m, *monitor->m_pkex); | ||
656 | } | ||
657 | |||
658 | debug3("%s: Sending new keys: %p %p", | ||
659 | __func__, packet_get_newkeys(MODE_OUT), | ||
660 | packet_get_newkeys(MODE_IN)); | ||
661 | |||
662 | /* Keys from Kex */ | ||
663 | if (!mm_newkeys_to_blob(MODE_OUT, &blob, &bloblen)) | ||
664 | fatal("%s: conversion of newkeys failed", __func__); | ||
665 | |||
666 | buffer_put_string(&m, blob, bloblen); | ||
667 | free(blob); | ||
668 | |||
669 | if (!mm_newkeys_to_blob(MODE_IN, &blob, &bloblen)) | ||
670 | fatal("%s: conversion of newkeys failed", __func__); | ||
671 | |||
672 | buffer_put_string(&m, blob, bloblen); | ||
673 | free(blob); | ||
674 | |||
675 | packet_get_state(MODE_OUT, &seqnr, &blocks, &packets, &bytes); | ||
676 | buffer_put_int(&m, seqnr); | ||
677 | buffer_put_int64(&m, blocks); | ||
678 | buffer_put_int(&m, packets); | ||
679 | buffer_put_int64(&m, bytes); | ||
680 | packet_get_state(MODE_IN, &seqnr, &blocks, &packets, &bytes); | ||
681 | buffer_put_int(&m, seqnr); | ||
682 | buffer_put_int64(&m, blocks); | ||
683 | buffer_put_int(&m, packets); | ||
684 | buffer_put_int64(&m, bytes); | ||
685 | |||
686 | debug3("%s: New keys have been sent", __func__); | ||
687 | skip: | ||
688 | /* More key context */ | ||
689 | plen = packet_get_keycontext(MODE_OUT, NULL); | ||
690 | p = xmalloc(plen+1); | ||
691 | packet_get_keycontext(MODE_OUT, p); | ||
692 | buffer_put_string(&m, p, plen); | ||
693 | free(p); | ||
694 | |||
695 | plen = packet_get_keycontext(MODE_IN, NULL); | ||
696 | p = xmalloc(plen+1); | ||
697 | packet_get_keycontext(MODE_IN, p); | ||
698 | buffer_put_string(&m, p, plen); | ||
699 | free(p); | ||
700 | |||
701 | /* Compression state */ | ||
702 | debug3("%s: Sending compression state", __func__); | ||
703 | buffer_put_string(&m, &outgoing_stream, sizeof(outgoing_stream)); | ||
704 | buffer_put_string(&m, &incoming_stream, sizeof(incoming_stream)); | ||
705 | |||
706 | /* Network I/O buffers */ | ||
707 | input = (Buffer *)packet_get_input(); | ||
708 | output = (Buffer *)packet_get_output(); | ||
709 | buffer_put_string(&m, buffer_ptr(input), buffer_len(input)); | ||
710 | buffer_put_string(&m, buffer_ptr(output), buffer_len(output)); | ||
711 | |||
712 | /* Roaming */ | ||
713 | if (compat20) { | ||
714 | buffer_put_int64(&m, get_sent_bytes()); | ||
715 | buffer_put_int64(&m, get_recv_bytes()); | ||
716 | } | ||
717 | |||
718 | mm_request_send(monitor->m_recvfd, MONITOR_REQ_KEYEXPORT, &m); | ||
719 | debug3("%s: Finished sending state", __func__); | 507 | debug3("%s: Finished sending state", __func__); |
720 | 508 | sshbuf_free(m); | |
721 | buffer_free(&m); | ||
722 | } | 509 | } |
723 | 510 | ||
724 | int | 511 | int |