Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
base repository: Yawning/tor
base: master
head repository: Yawning/tor
compare: feature6411_v2
Checking mergeability… Don’t worry, you can still create the pull request.
  • 13 commits
  • 8 files changed
  • 0 comments
  • 1 contributor
Commits on Mar 14, 2015
These commands allow for the creation and management of ephemeral
Onion ("Hidden") services that are either bound to the lifetime of
the originating control connection, or optionally the lifetime of
the tor instance.

Implements #6411.
Commits on Mar 20, 2015
Since the target parsing bug was simple and stupid, I will leave the
current code as is instead of trying to expose
rend_service.c:parse_port_config() or changing the config line format.
How did that assert get there?  I thought I removed that.
Commits on Mar 23, 2015
"GETINFO onions/current" returns a list of Onion Services that are
owned by the current control port connection.

"GETINFO onions/detached" returns a list of Onion Services that are
owned by no particular control port connection.

The original commit message for this feature should be altered on the
final rebase/squash to mention this.
Commits on Mar 25, 2015
From round 2 of dgoulet's review.
From round 2 of dgoulet's review.  For asthetic reasons, I opted not to
change the flag error messages, because having an equal sign after the
arg looks ugly.
Showing with 690 additions and 23 deletions.
  1. +7 −0 changes/feature6411
  2. +75 −0 src/common/crypto.c
  3. +3 −0 src/common/crypto.h
  4. +7 −0 src/or/connection.c
  5. +372 −0 src/or/control.c
  6. +3 −0 src/or/or.h
  7. +218 −23 src/or/rendservice.c
  8. +5 −0 src/or/rendservice.h
@@ -0,0 +1,7 @@
o Major features (controller):
- Add the ADD_ONION and DEL_ONION commands that allows the creation
and management of hidden services via the controller. Closes
ticket 6411.
- New "GETINFO onions/current" and "GETINFO onions/detached" to get
information about hidden services created via the controller.
Part of ticket 6411.
@@ -1397,6 +1397,81 @@ crypto_pk_get_hashed_fingerprint(crypto_pk_t *pk, char *fp_out)
return 0;
}

/** Given a crypto_pk_t <b>pk</b>, allocate a new buffer containing the
* Base64 encoding of the DER representation of the private key as a NUL
* terminated string, and return it via <b>priv_out</b>. Return 0 on
* sucess, -1 on failure.
*
* It is the caller's responsibility to sanitize and free the resulting buffer.
*/
int
crypto_pk_base64_encode(const crypto_pk_t *pk, char **priv_out)
{
unsigned char *der = NULL;
int der_len;
int ret = -1;

*priv_out = NULL;

der_len = i2d_RSAPrivateKey(pk->key, &der);
if (der_len < 0 || der == NULL)
return ret;

char *priv = tor_calloc(der_len, 2);
if (base64_encode(priv, der_len * 2, (char *)der, der_len) >= 0) {
tor_strstrip(priv, "\r\n");
size_t priv_len = strlen(priv);
memwipe(priv + priv_len, 0, 2 * der_len - priv_len);
*priv_out = priv;
ret = 0;
} else {
tor_free(priv);
}

memwipe(der, 0, der_len);
OPENSSL_free(der);
return ret;
}


/** Given a string containing the Base64 encoded DER representation of the
* private key <b>str</b>, decode and return the result on success, or NULL
* on failure.
*/
crypto_pk_t *
crypto_pk_base64_decode(const char *str, size_t len)
{
crypto_pk_t *pk = NULL;

char *der = tor_malloc_zero(len + 1);
size_t der_len = base64_decode(der, len, str, len);
if (der_len <= 0) {
log_warn(LD_CRYPTO, "Stored DER RSA private key seems corrupted (base64).");
goto out;
}

const unsigned char *dp = (unsigned char*)der; /* Shut the compiler up. */
RSA *rsa = d2i_RSAPrivateKey(NULL, &dp, der_len);
if (!rsa) {
crypto_log_errors(LOG_WARN, "decoding private key");
goto out;
}

pk = crypto_new_pk_from_rsa_(rsa);

/* Make sure it's valid. */
if (crypto_pk_check_key(pk) <= 0) {
crypto_pk_free(pk);
pk = NULL;
goto out;
}

out:
memwipe(der, 0, der_len);
tor_free(der);
return pk;
}

/* symmetric crypto */

/** Return a pointer to the key set for the cipher in <b>env</b>.
@@ -185,6 +185,9 @@ int crypto_pk_get_all_digests(crypto_pk_t *pk, digests_t *digests_out);
int crypto_pk_get_fingerprint(crypto_pk_t *pk, char *fp_out,int add_space);
int crypto_pk_get_hashed_fingerprint(crypto_pk_t *pk, char *fp_out);

int crypto_pk_base64_encode(const crypto_pk_t *pk, char **priv_out);
crypto_pk_t *crypto_pk_base64_decode(const char *str, size_t len);

/* symmetric crypto */
const char *crypto_cipher_get_key(crypto_cipher_t *env);

@@ -586,6 +586,13 @@ connection_free_(connection_t *conn)
control_connection_t *control_conn = TO_CONTROL_CONN(conn);
tor_free(control_conn->safecookie_client_hash);
tor_free(control_conn->incoming_cmd);
if (control_conn->ephemeral_onion_services) {
SMARTLIST_FOREACH(control_conn->ephemeral_onion_services, char *, cp, {
memwipe(cp, 0, strlen(cp));
tor_free(cp);
});
smartlist_free(control_conn->ephemeral_onion_services);
}
}

/* Probably already freed by connection_free. */

No commit comments for this range