|
Lines 60-65
Link Here
|
| 60 |
#include <signal.h> |
60 |
#include <signal.h> |
| 61 |
|
61 |
|
| 62 |
#include "xmalloc.h" |
62 |
#include "xmalloc.h" |
|
|
63 |
#include "audit.h" |
| 63 |
#include "buffer.h" |
64 |
#include "buffer.h" |
| 64 |
#include "packet.h" |
65 |
#include "packet.h" |
| 65 |
#include "crc32.h" |
66 |
#include "crc32.h" |
|
Lines 472-477
packet_get_connection_out(void)
Link Here
|
| 472 |
return active_state->connection_out; |
473 |
return active_state->connection_out; |
| 473 |
} |
474 |
} |
| 474 |
|
475 |
|
|
|
476 |
static int |
| 477 |
packet_state_has_keys (const struct session_state *state) |
| 478 |
{ |
| 479 |
return state != NULL && |
| 480 |
(state->newkeys[MODE_IN] != NULL || state->newkeys[MODE_OUT] != NULL); |
| 481 |
} |
| 482 |
|
| 475 |
/* Closes the connection and clears and frees internal data structures. */ |
483 |
/* Closes the connection and clears and frees internal data structures. */ |
| 476 |
|
484 |
|
| 477 |
void |
485 |
void |
|
Lines 480-492
packet_close(void)
Link Here
|
| 480 |
if (!active_state->initialized) |
488 |
if (!active_state->initialized) |
| 481 |
return; |
489 |
return; |
| 482 |
active_state->initialized = 0; |
490 |
active_state->initialized = 0; |
| 483 |
if (active_state->connection_in == active_state->connection_out) { |
|
|
| 484 |
shutdown(active_state->connection_out, SHUT_RDWR); |
| 485 |
close(active_state->connection_out); |
| 486 |
} else { |
| 487 |
close(active_state->connection_in); |
| 488 |
close(active_state->connection_out); |
| 489 |
} |
| 490 |
buffer_free(&active_state->input); |
491 |
buffer_free(&active_state->input); |
| 491 |
buffer_free(&active_state->output); |
492 |
buffer_free(&active_state->output); |
| 492 |
buffer_free(&active_state->outgoing_packet); |
493 |
buffer_free(&active_state->outgoing_packet); |
|
Lines 495-502
packet_close(void)
Link Here
|
| 495 |
buffer_free(&active_state->compression_buffer); |
496 |
buffer_free(&active_state->compression_buffer); |
| 496 |
buffer_compress_uninit(); |
497 |
buffer_compress_uninit(); |
| 497 |
} |
498 |
} |
| 498 |
cipher_cleanup(&active_state->send_context); |
499 |
if (packet_state_has_keys(active_state)) { |
| 499 |
cipher_cleanup(&active_state->receive_context); |
500 |
cipher_cleanup(&active_state->send_context); |
|
|
501 |
cipher_cleanup(&active_state->receive_context); |
| 502 |
audit_session_key_free(2); |
| 503 |
} |
| 504 |
if (active_state->connection_in == active_state->connection_out) { |
| 505 |
shutdown(active_state->connection_out, SHUT_RDWR); |
| 506 |
close(active_state->connection_out); |
| 507 |
} else { |
| 508 |
close(active_state->connection_in); |
| 509 |
close(active_state->connection_out); |
| 510 |
} |
| 500 |
} |
511 |
} |
| 501 |
|
512 |
|
| 502 |
/* Sets remote side protocol flags. */ |
513 |
/* Sets remote side protocol flags. */ |
|
Lines 731-736
packet_send1(void)
Link Here
|
| 731 |
*/ |
742 |
*/ |
| 732 |
} |
743 |
} |
| 733 |
|
744 |
|
|
|
745 |
static void |
| 746 |
newkeys_destroy_and_free(Newkeys *newkeys) |
| 747 |
{ |
| 748 |
if (newkeys == NULL) |
| 749 |
return; |
| 750 |
|
| 751 |
xfree(newkeys->enc.name); |
| 752 |
|
| 753 |
mac_clear(&newkeys->mac); |
| 754 |
xfree(newkeys->mac.name); |
| 755 |
|
| 756 |
xfree(newkeys->comp.name); |
| 757 |
|
| 758 |
newkeys_destroy(newkeys); |
| 759 |
xfree(newkeys); |
| 760 |
} |
| 761 |
|
| 734 |
void |
762 |
void |
| 735 |
set_newkeys(int mode) |
763 |
set_newkeys(int mode) |
| 736 |
{ |
764 |
{ |
|
Lines 756-773
set_newkeys(int mode)
Link Here
|
| 756 |
} |
784 |
} |
| 757 |
if (active_state->newkeys[mode] != NULL) { |
785 |
if (active_state->newkeys[mode] != NULL) { |
| 758 |
debug("set_newkeys: rekeying"); |
786 |
debug("set_newkeys: rekeying"); |
|
|
787 |
audit_session_key_free(mode); |
| 759 |
cipher_cleanup(cc); |
788 |
cipher_cleanup(cc); |
| 760 |
enc = &active_state->newkeys[mode]->enc; |
789 |
newkeys_destroy_and_free(active_state->newkeys[mode]); |
| 761 |
mac = &active_state->newkeys[mode]->mac; |
|
|
| 762 |
comp = &active_state->newkeys[mode]->comp; |
| 763 |
mac_clear(mac); |
| 764 |
xfree(enc->name); |
| 765 |
xfree(enc->iv); |
| 766 |
xfree(enc->key); |
| 767 |
xfree(mac->name); |
| 768 |
xfree(mac->key); |
| 769 |
xfree(comp->name); |
| 770 |
xfree(active_state->newkeys[mode]); |
| 771 |
} |
790 |
} |
| 772 |
active_state->newkeys[mode] = kex_get_newkeys(mode); |
791 |
active_state->newkeys[mode] = kex_get_newkeys(mode); |
| 773 |
if (active_state->newkeys[mode] == NULL) |
792 |
if (active_state->newkeys[mode] == NULL) |
|
Lines 1912-1917
packet_get_newkeys(int mode)
Link Here
|
| 1912 |
return (void *)active_state->newkeys[mode]; |
1931 |
return (void *)active_state->newkeys[mode]; |
| 1913 |
} |
1932 |
} |
| 1914 |
|
1933 |
|
|
|
1934 |
static void |
| 1935 |
packet_destroy_state(struct session_state *state) |
| 1936 |
{ |
| 1937 |
if (state == NULL) |
| 1938 |
return; |
| 1939 |
|
| 1940 |
cipher_cleanup(&state->receive_context); |
| 1941 |
cipher_cleanup(&state->send_context); |
| 1942 |
|
| 1943 |
buffer_free(&state->input); |
| 1944 |
buffer_free(&state->output); |
| 1945 |
buffer_free(&state->outgoing_packet); |
| 1946 |
buffer_free(&state->incoming_packet); |
| 1947 |
buffer_free(&state->compression_buffer); |
| 1948 |
newkeys_destroy_and_free(state->newkeys[MODE_IN]); |
| 1949 |
state->newkeys[MODE_IN] = NULL; |
| 1950 |
newkeys_destroy_and_free(state->newkeys[MODE_OUT]); |
| 1951 |
state->newkeys[MODE_OUT] = NULL; |
| 1952 |
mac_destroy(state->packet_discard_mac); |
| 1953 |
// TAILQ_HEAD(, packet) outgoing; |
| 1954 |
// memset(state, 0, sizeof(state)); |
| 1955 |
} |
| 1956 |
|
| 1957 |
void |
| 1958 |
packet_destroy_all(int audit_it, int privsep) |
| 1959 |
{ |
| 1960 |
if (audit_it) |
| 1961 |
audit_it = packet_state_has_keys (active_state) || |
| 1962 |
packet_state_has_keys (backup_state); |
| 1963 |
packet_destroy_state(active_state); |
| 1964 |
packet_destroy_state(backup_state); |
| 1965 |
if (audit_it) { |
| 1966 |
#ifdef SSH_AUDIT_EVENTS |
| 1967 |
if (privsep) |
| 1968 |
audit_session_key_free(2); |
| 1969 |
else |
| 1970 |
audit_session_key_free_body(2, getpid(), getuid()); |
| 1971 |
#endif |
| 1972 |
} |
| 1973 |
} |
| 1974 |
|
| 1915 |
/* |
1975 |
/* |
| 1916 |
* Save the state for the real connection, and use a separate state when |
1976 |
* Save the state for the real connection, and use a separate state when |
| 1917 |
* resuming a suspended connection. |
1977 |
* resuming a suspended connection. |
|
Lines 1919-1936
packet_get_newkeys(int mode)
Link Here
|
| 1919 |
void |
1979 |
void |
| 1920 |
packet_backup_state(void) |
1980 |
packet_backup_state(void) |
| 1921 |
{ |
1981 |
{ |
| 1922 |
struct session_state *tmp; |
|
|
| 1923 |
|
| 1924 |
close(active_state->connection_in); |
1982 |
close(active_state->connection_in); |
| 1925 |
active_state->connection_in = -1; |
1983 |
active_state->connection_in = -1; |
| 1926 |
close(active_state->connection_out); |
1984 |
close(active_state->connection_out); |
| 1927 |
active_state->connection_out = -1; |
1985 |
active_state->connection_out = -1; |
| 1928 |
if (backup_state) |
|
|
| 1929 |
tmp = backup_state; |
| 1930 |
else |
| 1931 |
tmp = alloc_session_state(); |
| 1932 |
backup_state = active_state; |
1986 |
backup_state = active_state; |
| 1933 |
active_state = tmp; |
1987 |
active_state = alloc_session_state(); |
| 1934 |
} |
1988 |
} |
| 1935 |
|
1989 |
|
| 1936 |
/* |
1990 |
/* |
|
Lines 1947-1955
packet_restore_state(void)
Link Here
|
| 1947 |
backup_state = active_state; |
2001 |
backup_state = active_state; |
| 1948 |
active_state = tmp; |
2002 |
active_state = tmp; |
| 1949 |
active_state->connection_in = backup_state->connection_in; |
2003 |
active_state->connection_in = backup_state->connection_in; |
| 1950 |
backup_state->connection_in = -1; |
|
|
| 1951 |
active_state->connection_out = backup_state->connection_out; |
2004 |
active_state->connection_out = backup_state->connection_out; |
| 1952 |
backup_state->connection_out = -1; |
|
|
| 1953 |
len = buffer_len(&backup_state->input); |
2005 |
len = buffer_len(&backup_state->input); |
| 1954 |
if (len > 0) { |
2006 |
if (len > 0) { |
| 1955 |
buf = buffer_ptr(&backup_state->input); |
2007 |
buf = buffer_ptr(&backup_state->input); |
|
Lines 1957-1960
packet_restore_state(void)
Link Here
|
| 1957 |
buffer_clear(&backup_state->input); |
2009 |
buffer_clear(&backup_state->input); |
| 1958 |
add_recv_bytes(len); |
2010 |
add_recv_bytes(len); |
| 1959 |
} |
2011 |
} |
|
|
2012 |
backup_state->connection_in = -1; |
| 2013 |
backup_state->connection_out = -1; |
| 2014 |
packet_destroy_state(backup_state); |
| 2015 |
xfree(backup_state); |
| 2016 |
backup_state = NULL; |
| 1960 |
} |
2017 |
} |
|
|
2018 |
|