summaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorSebastian Hahn <sebastian@torproject.org>2011-10-26 23:30:27 +0200
committerSebastian Hahn <sebastian@torproject.org>2011-10-26 23:30:27 +0200
commitdf05e5ef4d5e379e50b38e29fa23228e5b260e8a (patch)
tree36f76e0bf35cd6a92229114959e200dfe7ce4a17 /src/or
parentf85c56182f485bea483288a26fd74cefcb87653a (diff)
parenta74e7fd40f1a77eb4000d8216bb5b80cdd8a6193 (diff)
downloadtor-df05e5ef4d5e379e50b38e29fa23228e5b260e8a.tar.gz
tor-df05e5ef4d5e379e50b38e29fa23228e5b260e8a.zip
Merge branch 'maint-0.2.1_secfix' into maint-0.2.2_secfix
Conflicts: src/or/connection_or.c
Diffstat (limited to 'src/or')
-rw-r--r--src/or/command.c13
-rw-r--r--src/or/connection_or.c7
-rw-r--r--src/or/or.h6
3 files changed, 24 insertions, 2 deletions
diff --git a/src/or/command.c b/src/or/command.c
index 12b4c30f5c..1fa8bc6a7e 100644
--- a/src/or/command.c
+++ b/src/or/command.c
@@ -232,6 +232,7 @@ static void
command_process_create_cell(cell_t *cell, or_connection_t *conn)
{
or_circuit_t *circ;
+ or_options_t *options = get_options();
int id_is_high;
if (we_are_hibernating()) {
@@ -243,9 +244,11 @@ command_process_create_cell(cell_t *cell, or_connection_t *conn)
return;
}
- if (!server_mode(get_options())) {
+ if (!server_mode(options) ||
+ (!public_server_mode(options) && conn->is_outgoing)) {
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
- "Received create cell (type %d) from %s:%d, but we're a client. "
+ "Received create cell (type %d) from %s:%d, but we're connected "
+ "to it as a client. "
"Sending back a destroy.",
(int)cell->command, conn->_base.address, conn->_base.port);
connection_or_send_destroy(cell->circ_id, conn,
@@ -305,7 +308,13 @@ command_process_create_cell(cell_t *cell, or_connection_t *conn)
* a CPU worker. */
char keys[CPATH_KEY_MATERIAL_LEN];
char reply[DIGEST_LEN*2];
+
tor_assert(cell->command == CELL_CREATE_FAST);
+
+ /* Make sure we never try to use the OR connection on which we
+ * received this cell to satisfy an EXTEND request, */
+ conn->is_connection_with_client = 1;
+
if (fast_server_handshake(cell->payload, (uint8_t*)reply,
(uint8_t*)keys, sizeof(keys))<0) {
log_warn(LD_OR,"Failed to generate key material. Closing.");
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index c019f6592b..27a34d3d15 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -548,6 +548,11 @@ connection_or_get_for_extend(const char *digest,
tor_assert(tor_memeq(conn->identity_digest, digest, DIGEST_LEN));
if (conn->_base.marked_for_close)
continue;
+ /* Never return a connection on which the other end appears to be
+ * a client. */
+ if (conn->is_connection_with_client) {
+ continue;
+ }
/* Never return a non-open connection. */
if (conn->_base.state != OR_CONN_STATE_OPEN) {
/* If the address matches, don't launch a new connection for this
@@ -808,6 +813,8 @@ connection_or_connect(const tor_addr_t *_addr, uint16_t port,
conn->_base.state = OR_CONN_STATE_CONNECTING;
control_event_or_conn_status(conn, OR_CONN_EVENT_LAUNCHED, 0);
+ conn->is_outgoing = 1;
+
/* use a proxy server if available */
if (options->HTTPSProxy) {
using_proxy = 1;
diff --git a/src/or/or.h b/src/or/or.h
index 31deb897c7..8638f20997 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1068,6 +1068,12 @@ typedef struct or_connection_t {
* router itself has a problem.
*/
unsigned int is_bad_for_new_circs:1;
+ /** True iff we have decided that the other end of this connection
+ * is a client. Connections with this flag set should never be used
+ * to satisfy an EXTEND request. */
+ unsigned int is_connection_with_client:1;
+ /** True iff this is an outgoing connection. */
+ unsigned int is_outgoing:1;
uint8_t link_proto; /**< What protocol version are we using? 0 for
* "none negotiated yet." */
circid_t next_circ_id; /**< Which circ_id do we try to use next on