routerparse.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file routerparse.h
  8. * \brief Header file for routerparse.c.
  9. **/
  10. #ifndef TOR_ROUTERPARSE_H
  11. #define TOR_ROUTERPARSE_H
  12. int router_get_router_hash(const char *s, size_t s_len, char *digest);
  13. int router_get_dir_hash(const char *s, char *digest);
  14. int router_get_networkstatus_v3_hashes(const char *s,
  15. common_digests_t *digests);
  16. int router_get_networkstatus_v3_signed_boundaries(const char *s,
  17. const char **start_out,
  18. const char **end_out);
  19. int router_get_networkstatus_v3_sha3_as_signed(uint8_t *digest_out,
  20. const char *s);
  21. int router_get_extrainfo_hash(const char *s, size_t s_len, char *digest);
  22. #define DIROBJ_MAX_SIG_LEN 256
  23. char *router_get_dirobj_signature(const char *digest,
  24. size_t digest_len,
  25. const crypto_pk_t *private_key);
  26. int router_append_dirobj_signature(char *buf, size_t buf_len,
  27. const char *digest,
  28. size_t digest_len,
  29. crypto_pk_t *private_key);
  30. int router_parse_list_from_string(const char **s, const char *eos,
  31. smartlist_t *dest,
  32. saved_location_t saved_location,
  33. int is_extrainfo,
  34. int allow_annotations,
  35. const char *prepend_annotations,
  36. smartlist_t *invalid_digests_out);
  37. routerinfo_t *router_parse_entry_from_string(const char *s, const char *end,
  38. int cache_copy,
  39. int allow_annotations,
  40. const char *prepend_annotations,
  41. int *can_dl_again_out);
  42. struct digest_ri_map_t;
  43. extrainfo_t *extrainfo_parse_entry_from_string(const char *s, const char *end,
  44. int cache_copy, struct digest_ri_map_t *routermap,
  45. int *can_dl_again_out);
  46. MOCK_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string,
  47. (const char *s, int assume_action, int *malformed_list));
  48. version_status_t tor_version_is_obsolete(const char *myversion,
  49. const char *versionlist);
  50. int tor_version_parse_platform(const char *platform,
  51. tor_version_t *version_out,
  52. int strict);
  53. int tor_version_as_new_as(const char *platform, const char *cutoff);
  54. int tor_version_parse(const char *s, tor_version_t *out);
  55. int tor_version_compare(tor_version_t *a, tor_version_t *b);
  56. int tor_version_same_series(tor_version_t *a, tor_version_t *b);
  57. void sort_version_list(smartlist_t *lst, int remove_duplicates);
  58. void assert_addr_policy_ok(smartlist_t *t);
  59. void dump_distinct_digest_count(int severity);
  60. int compare_vote_routerstatus_entries(const void **_a, const void **_b);
  61. int networkstatus_verify_bw_weights(networkstatus_t *ns, int);
  62. networkstatus_t *networkstatus_parse_vote_from_string(const char *s,
  63. const char **eos_out,
  64. networkstatus_type_t ns_type);
  65. ns_detached_signatures_t *networkstatus_parse_detached_signatures(
  66. const char *s, const char *eos);
  67. smartlist_t *microdescs_parse_from_string(const char *s, const char *eos,
  68. int allow_annotations,
  69. saved_location_t where,
  70. smartlist_t *invalid_digests_out);
  71. authority_cert_t *authority_cert_parse_from_string(const char *s,
  72. const char **end_of_string);
  73. int rend_parse_v2_service_descriptor(rend_service_descriptor_t **parsed_out,
  74. char *desc_id_out,
  75. char **intro_points_encrypted_out,
  76. size_t *intro_points_encrypted_size_out,
  77. size_t *encoded_size_out,
  78. const char **next_out, const char *desc,
  79. int as_hsdir);
  80. int rend_decrypt_introduction_points(char **ipos_decrypted,
  81. size_t *ipos_decrypted_size,
  82. const char *descriptor_cookie,
  83. const char *ipos_encrypted,
  84. size_t ipos_encrypted_size);
  85. int rend_parse_introduction_points(rend_service_descriptor_t *parsed,
  86. const char *intro_points_encoded,
  87. size_t intro_points_encoded_size);
  88. int rend_parse_client_keys(strmap_t *parsed_clients, const char *str);
  89. void routerparse_init(void);
  90. void routerparse_free_all(void);
  91. #ifdef ROUTERPARSE_PRIVATE
  92. /*
  93. * One entry in the list of dumped descriptors; filename dumped to, length,
  94. * SHA-256 and timestamp.
  95. */
  96. typedef struct {
  97. char *filename;
  98. size_t len;
  99. uint8_t digest_sha256[DIGEST256_LEN];
  100. time_t when;
  101. } dumped_desc_t;
  102. EXTERN(uint64_t, len_descs_dumped)
  103. EXTERN(smartlist_t *, descs_dumped)
  104. STATIC int routerstatus_parse_guardfraction(const char *guardfraction_str,
  105. networkstatus_t *vote,
  106. vote_routerstatus_t *vote_rs,
  107. routerstatus_t *rs);
  108. MOCK_DECL(STATIC dumped_desc_t *, dump_desc_populate_one_file,
  109. (const char *dirname, const char *f));
  110. STATIC void dump_desc_populate_fifo_from_directory(const char *dirname);
  111. STATIC void dump_desc_fifo_cleanup(void);
  112. struct memarea_t;
  113. STATIC routerstatus_t *routerstatus_parse_entry_from_string(
  114. struct memarea_t *area,
  115. const char **s, smartlist_t *tokens,
  116. networkstatus_t *vote,
  117. vote_routerstatus_t *vote_rs,
  118. int consensus_method,
  119. consensus_flavor_t flav);
  120. MOCK_DECL(STATIC void,dump_desc,(const char *desc, const char *type));
  121. MOCK_DECL(STATIC int, router_compute_hash_final,(char *digest,
  122. const char *start, size_t len,
  123. digest_algorithm_t alg));
  124. MOCK_DECL(STATIC int, signed_digest_equals,
  125. (const uint8_t *d1, const uint8_t *d2, size_t len));
  126. STATIC void summarize_protover_flags(protover_summary_flags_t *out,
  127. const char *protocols,
  128. const char *version);
  129. #endif /* defined(ROUTERPARSE_PRIVATE) */
  130. #define ED_DESC_SIGNATURE_PREFIX "Tor router descriptor signature v1"
  131. #endif /* !defined(TOR_ROUTERPARSE_H) */