Commit 7b386f23 authored by George Kadianakis's avatar George Kadianakis
Browse files

Merge branch 'tor-github/pr/908'

parents 86aa1415 ebbc2c3d
Loading
Loading
Loading
Loading

changes/ticket29660

0 → 100644
+5 −0
Original line number Diff line number Diff line
  o Code simplification and refactoring:
    - Remove redundant return values in crypto_format, and the associated
      return value checks elsewhere in the code. Make the implementations in
      crypto_format consistent, and remove redundant code.
      Resolves ticket 29660.
+1 −2
Original line number Diff line number Diff line
@@ -3914,8 +3914,7 @@ dirvote_format_microdesc_vote_line(char *out_buf, size_t out_buf_len,
                               ",");
  tor_assert(microdesc_consensus_methods);

  if (digest256_to_base64(d64, md->digest)<0)
    goto out;
  digest256_to_base64(d64, md->digest);

  if (tor_snprintf(out_buf, out_buf_len, "m %s sha256=%s\n",
                   microdesc_consensus_methods, d64)<0)
+3 −13
Original line number Diff line number Diff line
@@ -165,9 +165,7 @@ purge_hid_serv_request(const ed25519_public_key_t *identity_pk)
   * some point and we don't care about those anymore. */
  hs_build_blinded_pubkey(identity_pk, NULL, 0,
                          hs_get_time_period_num(0), &blinded_pk);
  if (BUG(ed25519_public_to_base64(base64_blinded_pk, &blinded_pk) < 0)) {
    return;
  }
  ed25519_public_to_base64(base64_blinded_pk, &blinded_pk);
  /* Purge last hidden service request from cache for this blinded key. */
  hs_purge_hid_serv_from_last_hid_serv_requests(base64_blinded_pk);
}
@@ -354,7 +352,6 @@ directory_launch_v3_desc_fetch(const ed25519_public_key_t *onion_identity_pk,
  ed25519_public_key_t blinded_pubkey;
  char base64_blinded_pubkey[ED25519_BASE64_LEN + 1];
  hs_ident_dir_conn_t hs_conn_dir_ident;
  int retval;

  tor_assert(hsdir);
  tor_assert(onion_identity_pk);
@@ -363,10 +360,7 @@ directory_launch_v3_desc_fetch(const ed25519_public_key_t *onion_identity_pk,
  hs_build_blinded_pubkey(onion_identity_pk, NULL, 0,
                          current_time_period, &blinded_pubkey);
  /* ...and base64 it. */
  retval = ed25519_public_to_base64(base64_blinded_pubkey, &blinded_pubkey);
  if (BUG(retval < 0)) {
    return HS_CLIENT_FETCH_ERROR;
  }
  ed25519_public_to_base64(base64_blinded_pubkey, &blinded_pubkey);

  /* Copy onion pk to a dir_ident so that we attach it to the dir conn */
  hs_ident_dir_conn_init(onion_identity_pk, &blinded_pubkey,
@@ -405,7 +399,6 @@ directory_launch_v3_desc_fetch(const ed25519_public_key_t *onion_identity_pk,
STATIC routerstatus_t *
pick_hsdir_v3(const ed25519_public_key_t *onion_identity_pk)
{
  int retval;
  char base64_blinded_pubkey[ED25519_BASE64_LEN + 1];
  uint64_t current_time_period = hs_get_time_period_num(0);
  smartlist_t *responsible_hsdirs = NULL;
@@ -418,10 +411,7 @@ pick_hsdir_v3(const ed25519_public_key_t *onion_identity_pk)
  hs_build_blinded_pubkey(onion_identity_pk, NULL, 0,
                          current_time_period, &blinded_pubkey);
  /* ...and base64 it. */
  retval = ed25519_public_to_base64(base64_blinded_pubkey, &blinded_pubkey);
  if (BUG(retval < 0)) {
    return NULL;
  }
  ed25519_public_to_base64(base64_blinded_pubkey, &blinded_pubkey);

  /* Get responsible hsdirs of service for this time period */
  responsible_hsdirs = smartlist_new();
+5 −18
Original line number Diff line number Diff line
@@ -74,10 +74,7 @@ hs_control_desc_event_failed(const hs_ident_dir_conn_t *ident,
  tor_assert(reason);

  /* Build onion address and encoded blinded key. */
  IF_BUG_ONCE(ed25519_public_to_base64(base64_blinded_pk,
                                       &ident->blinded_pk) < 0) {
    return;
  }
  ed25519_public_to_base64(base64_blinded_pk, &ident->blinded_pk);
  hs_build_address(&ident->identity_pk, HS_VERSION_THREE, onion_address);

  control_event_hsv3_descriptor_failed(onion_address, base64_blinded_pk,
@@ -99,10 +96,7 @@ hs_control_desc_event_received(const hs_ident_dir_conn_t *ident,
  tor_assert(hsdir_id_digest);

  /* Build onion address and encoded blinded key. */
  IF_BUG_ONCE(ed25519_public_to_base64(base64_blinded_pk,
                                       &ident->blinded_pk) < 0) {
    return;
  }
  ed25519_public_to_base64(base64_blinded_pk, &ident->blinded_pk);
  hs_build_address(&ident->identity_pk, HS_VERSION_THREE, onion_address);

  control_event_hsv3_descriptor_received(onion_address, base64_blinded_pk,
@@ -123,9 +117,7 @@ hs_control_desc_event_created(const char *onion_address,
  tor_assert(blinded_pk);

  /* Build base64 encoded blinded key. */
  IF_BUG_ONCE(ed25519_public_to_base64(base64_blinded_pk, blinded_pk) < 0) {
    return;
  }
  ed25519_public_to_base64(base64_blinded_pk, blinded_pk);

  /* Version 3 doesn't use the replica number in its descriptor ID computation
   * so we pass negative value so the control port subsystem can ignore it. */
@@ -151,9 +143,7 @@ hs_control_desc_event_upload(const char *onion_address,
  tor_assert(hsdir_index);

  /* Build base64 encoded blinded key. */
  IF_BUG_ONCE(ed25519_public_to_base64(base64_blinded_pk, blinded_pk) < 0) {
    return;
  }
  ed25519_public_to_base64(base64_blinded_pk, blinded_pk);

  control_event_hs_descriptor_upload(onion_address, hsdir_id_digest,
                                     base64_blinded_pk,
@@ -196,10 +186,7 @@ hs_control_desc_event_content(const hs_ident_dir_conn_t *ident,
  tor_assert(hsdir_id_digest);

  /* Build onion address and encoded blinded key. */
  IF_BUG_ONCE(ed25519_public_to_base64(base64_blinded_pk,
                                       &ident->blinded_pk) < 0) {
    return;
  }
  ed25519_public_to_base64(base64_blinded_pk, &ident->blinded_pk);
  hs_build_address(&ident->identity_pk, HS_VERSION_THREE, onion_address);

  control_event_hs_descriptor_content(onion_address, base64_blinded_pk,
+7 −20
Original line number Diff line number Diff line
@@ -403,9 +403,7 @@ encode_enc_key(const hs_desc_intro_point_t *ip)
  tor_assert(ip);

  /* Base64 encode the encryption key for the "enc-key" field. */
  if (curve25519_public_to_base64(key_b64, &ip->enc_key) < 0) {
    goto done;
  }
  curve25519_public_to_base64(key_b64, &ip->enc_key);
  if (tor_cert_encode_ed22519(ip->enc_key_cert, &encoded_cert) < 0) {
    goto done;
  }
@@ -421,7 +419,7 @@ encode_enc_key(const hs_desc_intro_point_t *ip)
}

/* Encode an introduction point onion key. Return a newly allocated string
 * with it. On failure, return NULL. */
 * with it. Can not fail. */
static char *
encode_onion_key(const hs_desc_intro_point_t *ip)
{
@@ -431,12 +429,9 @@ encode_onion_key(const hs_desc_intro_point_t *ip)
  tor_assert(ip);

  /* Base64 encode the encryption key for the "onion-key" field. */
  if (curve25519_public_to_base64(key_b64, &ip->onion_key) < 0) {
    goto done;
  }
  curve25519_public_to_base64(key_b64, &ip->onion_key);
  tor_asprintf(&encoded, "%s ntor %s", str_ip_onion_key, key_b64);

 done:
  return encoded;
}

@@ -797,8 +792,8 @@ get_inner_encrypted_layer_plaintext(const hs_descriptor_t *desc)
/* Create the middle layer of the descriptor, which includes the client auth
 * data and the encrypted inner layer (provided as a base64 string at
 * <b>layer2_b64_ciphertext</b>). Return a newly-allocated string with the
 * layer plaintext, or NULL if an error occurred. It's the responsibility of
 * the caller to free the returned string. */
 * layer plaintext. It's the responsibility of the caller to free the returned
 * string. Can not fail. */
static char *
get_outer_encrypted_layer_plaintext(const hs_descriptor_t *desc,
                                    const char *layer2_b64_ciphertext)
@@ -817,10 +812,7 @@ get_outer_encrypted_layer_plaintext(const hs_descriptor_t *desc,
    tor_assert(!tor_mem_is_zero((char *) ephemeral_pubkey->public_key,
                                CURVE25519_PUBKEY_LEN));

    if (curve25519_public_to_base64(ephemeral_key_base64,
                                    ephemeral_pubkey) < 0) {
      goto done;
    }
    curve25519_public_to_base64(ephemeral_key_base64, ephemeral_pubkey);
    smartlist_add_asprintf(lines, "%s %s\n",
                           str_desc_auth_key, ephemeral_key_base64);

@@ -845,7 +837,6 @@ get_outer_encrypted_layer_plaintext(const hs_descriptor_t *desc,

  layer1_str = smartlist_join_strings(lines, "", 0, NULL);

 done:
  /* We need to memwipe all lines because it contains the ephemeral key */
  SMARTLIST_FOREACH(lines, char *, a, memwipe(a, 0, strlen(a)));
  SMARTLIST_FOREACH(lines, char *, a, tor_free(a));
@@ -1091,11 +1082,7 @@ desc_encode_v3(const hs_descriptor_t *desc,
      tor_free(encoded_str);
      goto err;
    }
    if (ed25519_signature_to_base64(ed_sig_b64, &sig) < 0) {
      log_warn(LD_BUG, "Can't base64 encode descriptor signature!");
      tor_free(encoded_str);
      goto err;
    }
    ed25519_signature_to_base64(ed_sig_b64, &sig);
    /* Create the signature line. */
    smartlist_add_asprintf(lines, "%s %s", str_signature, ed_sig_b64);
  }
Loading