Ticket #18119: tor_short.patch

File tor_short.patch, 3.9 KB (added by azazar, 5 years ago)

patch to resolve short .onion domains (eg xxxyyy.onion to xxxyyyaaaaaaaaaa.onion)

  • .gitignore

    diff --git a/.gitignore b/.gitignore
    index b141e80..b03f422 100644
    a b  
    6666/Tor*Bundle.dmg
    6767/tor-*-win32.exe
    6868/coverage_html/
     69/nbproject
    6970
    7071# /contrib/
    7172/contrib/dist/tor.sh
  • src/or/or.h

    diff --git a/src/or/or.h b/src/or/or.h
    index 52bf337..6b749a9 100644
    a b  
    702702#define REND_SERVICE_ID_LEN_BASE32 16
    703703
    704704/** Length of 'y.onion' including '.onion' URL. */
    705 #define REND_SERVICE_ADDRESS_LEN (16+1+5)
     705#define REND_SERVICE_ADDRESS_LEN ((REND_SERVICE_ID_LEN_BASE32)+1+5)
    706706
    707707/** Length of a binary-encoded rendezvous service ID. */
    708708#define REND_SERVICE_ID_LEN 10
  • src/or/rendcache.c

    diff --git a/src/or/rendcache.c b/src/or/rendcache.c
    index c69671e..92d4cb6 100644
    a b  
    887887    goto err;
    888888  }
    889889  if (rend_query->onion_address[0] != '\0' &&
    890       strcmp(rend_query->onion_address, service_id)) {
     890      rend_cmp_service_ids(rend_query->onion_address, service_id)) {
    891891    log_warn(LD_REND, "Received service descriptor for service ID %s; "
    892892             "expected descriptor for service ID %s.",
    893893             service_id, safe_str(rend_query->onion_address));
  • src/or/rendcommon.c

    diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c
    index 8c02b67..d134198 100644
    a b  
    2222
    2323/** Return 0 if one and two are the same service ids, else -1 or 1 */
    2424int
    25 rend_cmp_service_ids(const char *one, const char *two)
     25rend_cmp_service_ids(const char *a, const char *b)
    2626{
    27   return strcasecmp(one,two);
     27    size_t la = strlen(a);
     28    size_t lb = strlen(b);
     29
     30    char* ca = alloca(la + 1);
     31    memcpy(ca, a, la + 1);
     32
     33    char* cb = alloca(lb + 1);
     34    memcpy(cb, b, lb + 1);
     35
     36    while (la > 0 && (ca[la - 1] == 'a' || ca[la - 1] == 'A')) {
     37        ca[--la] = 0;
     38    }
     39
     40    while (lb > 0 && (cb[lb - 1] == 'a' || cb[lb - 1] == 'A')) {
     41        cb[--lb] = 0;
     42    }
     43
     44    return strcasecmp(ca, cb);
     45}
     46
     47/** Fix incomplete IDs */
     48char *rend_service_id_complete(const char *service_id, char *buffer) {
     49    size_t n = strlcpy(buffer, service_id, REND_SERVICE_ID_LEN_BASE32);
     50   
     51    while(n < REND_SERVICE_ID_LEN_BASE32) {
     52        buffer[n++] = 'a';
     53    }
     54   
     55    buffer[REND_SERVICE_ID_LEN_BASE32] = 0;
     56   
     57    return buffer;
    2858}
    2959
    3060/** Free the storage held by the service descriptor <b>desc</b>.
     
    135165  char secret_id_part[DIGEST_LEN];
    136166  uint32_t time_period;
    137167  if (!service_id ||
    138       strlen(service_id) != REND_SERVICE_ID_LEN_BASE32) {
     168      strlen(service_id) > REND_SERVICE_ID_LEN_BASE32) {
    139169    log_warn(LD_REND, "Could not compute v2 descriptor ID: "
    140170                      "Illegal service ID: %s",
    141171             safe_str(service_id));
     
    722752int
    723753rend_valid_service_id(const char *query)
    724754{
    725   if (strlen(query) != REND_SERVICE_ID_LEN_BASE32)
     755  if (strlen(query) > REND_SERVICE_ID_LEN_BASE32)
    726756    return 0;
    727757
    728   if (strspn(query, BASE32_CHARS) != REND_SERVICE_ID_LEN_BASE32)
     758  if (strspn(query, BASE32_CHARS) > REND_SERVICE_ID_LEN_BASE32)
    729759    return 0;
    730760
    731761  return 1;
     
    917947    memcpy(rend_data->desc_id_fetch, desc_id,
    918948           sizeof(rend_data->desc_id_fetch));
    919949  }
     950 
    920951  if (onion_address) {
    921     strlcpy(rend_data->onion_address, onion_address,
     952    char complete_onion_address[REND_SERVICE_ID_LEN_BASE32 + 1];
     953    rend_service_id_complete(onion_address, complete_onion_address);
     954
     955    strlcpy(rend_data->onion_address, complete_onion_address,
    922956            sizeof(rend_data->onion_address));
    923957    if (compute_desc_id(rend_data) < 0) {
    924958      goto error;
  • src/or/rendcommon.h

    diff --git a/src/or/rendcommon.h b/src/or/rendcommon.h
    index 04e34af..f505307 100644
    a b  
    3232}
    3333
    3434int rend_cmp_service_ids(const char *one, const char *two);
     35char *rend_service_id_complete(const char *service_id, char *buffer);
    3536
    3637void rend_process_relay_cell(circuit_t *circ, const crypt_path_t *layer_hint,
    3738                             int command, size_t length,