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_v4
Checking mergeability… Don’t worry, you can still create the pull request.
  • 2 commits
  • 13 files changed
  • 0 comments
  • 1 contributor
Commits on Apr 25, 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.
Showing with 980 additions and 45 deletions.
  1. +7 −0 changes/feature6411
  2. +72 −0 src/common/crypto.c
  3. +3 −0 src/common/crypto.h
  4. +7 −0 src/or/connection.c
  5. +405 −0 src/or/control.c
  6. +5 −0 src/or/control.h
  7. +3 −0 src/or/or.h
  8. +257 −44 src/or/rendservice.c
  9. +19 −0 src/or/rendservice.h
  10. +1 −0 src/test/include.am
  11. +3 −1 src/test/test.c
  12. +161 −0 src/test/test_controller.c
  13. +37 −0 src/test/test_crypto.c
@@ -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,78 @@ 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;

size_t priv_len = base64_encode_size(der_len, 0) + 1;
char *priv = tor_malloc_zero(priv_len);
if (base64_encode(priv, priv_len, (char *)der, der_len, 0) >= 0) {
*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);
int der_len = base64_decode(der, len, str, len);
if (der_len <= 0) {
log_warn(LD_CRYPTO, "Stored 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, len + 1);
tor_free(der);
return pk;
}

/* symmetric crypto */

/** Return a pointer to the key set for the cipher in <b>env</b>.
@@ -184,6 +184,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