hs_client.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Copyright (c) 2016-2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file hs_service.c
  5. * \brief Implement next generation hidden service client functionality
  6. **/
  7. #include "or.h"
  8. #include "hs_circuit.h"
  9. #include "hs_ident.h"
  10. #include "connection_edge.h"
  11. #include "rendclient.h"
  12. #include "hs_client.h"
  13. /** A prop224 v3 HS circuit successfully connected to the hidden
  14. * service. Update the stream state at <b>hs_conn_ident</b> appropriately. */
  15. static void
  16. hs_client_attempt_succeeded(const hs_ident_edge_conn_t *hs_conn_ident)
  17. {
  18. (void) hs_conn_ident;
  19. /* TODO: When implementing client side */
  20. return;
  21. }
  22. /** A circuit just finished connecting to a hidden service that the stream
  23. * <b>conn</b> has been waiting for. Let the HS subsystem know about this. */
  24. void
  25. hs_client_note_connection_attempt_succeeded(const edge_connection_t *conn)
  26. {
  27. tor_assert(connection_edge_is_rendezvous_stream(conn));
  28. if (BUG(conn->rend_data && conn->hs_ident)) {
  29. log_warn(LD_BUG, "Stream had both rend_data and hs_ident..."
  30. "Prioritizing hs_ident");
  31. }
  32. if (conn->hs_ident) { /* It's v3: pass it to the prop224 handler */
  33. hs_client_attempt_succeeded(conn->hs_ident);
  34. return;
  35. } else if (conn->rend_data) { /* It's v2: pass it to the legacy handler */
  36. rend_client_note_connection_attempt_ended(conn->rend_data);
  37. return;
  38. }
  39. }
  40. /* With the given encoded descriptor in desc_str and the service key in
  41. * service_identity_pk, decode the descriptor and set the desc pointer with a
  42. * newly allocated descriptor object.
  43. *
  44. * Return 0 on success else a negative value and desc is set to NULL. */
  45. int
  46. hs_client_decode_descriptor(const char *desc_str,
  47. const ed25519_public_key_t *service_identity_pk,
  48. hs_descriptor_t **desc)
  49. {
  50. int ret;
  51. uint8_t subcredential[DIGEST256_LEN];
  52. tor_assert(desc_str);
  53. tor_assert(service_identity_pk);
  54. tor_assert(desc);
  55. /* Create subcredential for this HS so that we can decrypt */
  56. {
  57. ed25519_public_key_t blinded_pubkey;
  58. uint64_t current_time_period = hs_get_time_period_num(approx_time());
  59. hs_build_blinded_pubkey(service_identity_pk, NULL, 0, current_time_period,
  60. &blinded_pubkey);
  61. hs_get_subcredential(service_identity_pk, &blinded_pubkey, subcredential);
  62. }
  63. /* Parse descriptor */
  64. ret = hs_desc_decode_descriptor(desc_str, subcredential, desc);
  65. memwipe(subcredential, 0, sizeof(subcredential));
  66. if (ret < 0) {
  67. log_warn(LD_GENERAL, "Could not parse received descriptor as client");
  68. goto err;
  69. }
  70. return 0;
  71. err:
  72. return -1;
  73. }