39#include "gnunet_signatures.h"
308 "Hashing over %.*s\n",
344 "Address hash is %s\n",
439 while (NULL != (a =
parser->a_head))
457 while (NULL != (a =
builder->a_head))
498 if (NULL == (e = strstr (
address,
503 "Invalid address `%s'\n",
513 if ( (! isalpha ((
unsigned char) *
p)) &&
528 size_t alen = strlen (
address) + 1;
534 "Failed to add address to builder\n");
549 a->
uri = (
const char *) &a[1];
565 if (block_size <
sizeof (*bh))
571 block +=
sizeof (*bh);
572 block_size -=
sizeof (*bh);
573 while (block_size > 0)
575 const void *
end = memchr (block,
594 block_size -= (
end - block);
651 size_t alen = strlen (
address) + 1;
657 "Failed to add address to builder\n");
672 a->
uri = (
const char *) &a[1];
693 if (0 != strncasecmp (url,
695 strlen (
"gnunet://hello/")))
697 url += strlen (
"gnunet://hello/");
698 s1 = strchr (url,
'/');
704 s2 = strchr (s1 + 1,
'/');
710 q = strchr (url,
'?');
712 q = url + strlen (url);
735 if ( (0 == sscanf (s2 + 1,
761 eq = strchr (
q,
'=');
769 amp = strchr (eq,
'&');
775 if ( (NULL == addr) ||
776 (0 == strlen (addr)) )
830 if (
builder->a_length > UINT16_MAX)
863 blen -
sizeof (*block));
867 msg->url_counter = htons ((uint16_t)
builder->a_length);
882 const char *sep =
"?";
895 "gnunet://hello/%s/%s/%" PRIu64,
910 eou = strstr (a->uri,
918 pfx_len = eou - a->uri;
945 const char *sep =
"?";
952 "gnunet://hello/%s/%s/%" PRIu64,
967 eou = strstr (a->uri,
975 pfx_len = eou - a->uri;
1013 size_t needed =
sizeof (bh);
1023 needed += a->uri_len;
1025 if ( (NULL == block) ||
1026 (needed < *block_size) )
1028 *block_size = needed;
1044 pos = block +
sizeof (bh);
1054 *block_size = needed;
1065 size_t needed =
sizeof (bh);
1073 needed += a->uri_len;
1075 if ( (NULL == block) ||
1076 (needed < *block_size) )
1078 *block_size = needed;
1087 pos = block +
sizeof (bh);
1097 *block_size = needed;
1109 if (
parser->a_length > UINT16_MAX)
1122 msg->url_counter = htons ((uint16_t)
parser->a_length);
1141 if (
builder->a_length > UINT16_MAX)
1156 msg->url_counter = htons ((uint16_t)
builder->a_length);
1231 uint16_t len = ntohs (hello->
size);
1241 if (len <
sizeof (*
msg))
1246 len -=
sizeof (*msg);
1247 *block_size = len +
sizeof (*bh);
1316 size_t *result_size)
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static int ret
Final status code.
static int end
Set if we are to shutdown all services (including ARM).
static char * address
GNS address for this phone.
static struct HostSet * builder
NULL if we are not currently iterating over peer information.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
static int result
Global testing status.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
static struct MyAddress * a_head
Head of addresses of this peer.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_FS_UnindexContext * uc
static struct GNUNET_OS_Process * p
Helper process we started.
Helper library for handling HELLO URIs.
Constants for network protocols.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_from_parser(const struct GNUNET_HELLO_Parser *p)
Allocate builder from parser.
void GNUNET_HELLO_parser_free(struct GNUNET_HELLO_Parser *parser)
Release resources of a builder.
void GNUNET_HELLO_sign_address(const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Absolute mono_time, const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key, void **result, size_t *result_size)
Build address record by signing raw information with private key.
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_msg(const struct GNUNET_MessageHeader *msg)
Parse msg.
void GNUNET_HELLO_builder_free(struct GNUNET_HELLO_Builder *builder)
Release resources of a builder.
char * GNUNET_HELLO_parser_to_url(const struct GNUNET_HELLO_Parser *parser)
Generate GNUnet HELLO URI from a parser.
enum GNUNET_GenericReturnValue GNUNET_HELLO_dht_msg_to_block(const struct GNUNET_MessageHeader *hello, const struct GNUNET_PeerIdentity *pid, void **block, size_t *block_size, struct GNUNET_TIME_Absolute *block_expiration)
Convert a DHT hello message to a HELLO block.
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_new(const struct GNUNET_PeerIdentity *pid)
Allocate builder.
enum GNUNET_GenericReturnValue GNUNET_HELLO_parser_to_block(const struct GNUNET_HELLO_Parser *parser, void *block, size_t *block_size)
Generate DHT block from a parser.
const struct GNUNET_PeerIdentity * GNUNET_HELLO_parser_iterate(const struct GNUNET_HELLO_Parser *parser, GNUNET_HELLO_UriCallback uc, void *uc_cls)
Iterate over URIs in a parser.
struct GNUNET_MQ_Envelope * GNUNET_HELLO_parser_to_env(const struct GNUNET_HELLO_Parser *parser)
Generate envelope with GNUnet HELLO message (including peer ID) from a parser.
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_del_address(struct GNUNET_HELLO_Builder *builder, const char *address)
Remove individual address from the builder.
struct GNUNET_TIME_Absolute GNUNET_HELLO_get_expiration_time_from_msg(const struct GNUNET_MessageHeader *msg)
Get the expiration time for this HELLO.
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_to_block(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, void *block, size_t *block_size, struct GNUNET_TIME_Relative expiration_time)
Generate DHT block from a builder.
const struct GNUNET_PeerIdentity * GNUNET_HELLO_parser_get_id(const struct GNUNET_HELLO_Parser *parser)
Get the PeerIdentity for this builder.
void(* GNUNET_HELLO_UriCallback)(void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri)
Callback function used to extract URIs from a builder.
#define GNUNET_HELLO_ADDRESS_EXPIRATION
For how long are HELLO signatures valid?
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_add_address(struct GNUNET_HELLO_Builder *builder, const char *address)
Add individual address to the builder.
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_url(const char *url)
Parse GNUnet HELLO url.
char * GNUNET_HELLO_builder_to_url(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
Generate GNUnet HELLO URI from a builder.
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_block(const void *block, size_t block_size)
Parse block.
char * GNUNET_HELLO_address_to_prefix(const char *address)
Given an address as a string, extract the prefix that identifies the communicator offering transmissi...
struct GNUNET_MessageHeader * GNUNET_HELLO_builder_to_dht_hello_msg(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_TIME_Relative expiration_time)
Generate DHT HELLO message (without peer ID) from a builder.
struct GNUNET_MQ_Envelope * GNUNET_HELLO_builder_to_env(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_TIME_Relative expiration_time)
Generate envelope with GNUnet HELLO message (including peer ID) from a builder.
char * GNUNET_HELLO_builder_to_url2(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_TIME_Relative validity)
Generate GNUnet HELLO URI from a builder.
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, const void *buf, size_t size)
Add data to be hashed.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
GNUNET_GenericReturnValue
Named constants for return values.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
#define GNUNET_PACKED
gcc-ism to get packed structs.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO
HELLO advertising a neighbours addresses.
#define GNUNET_MESSAGE_TYPE_HELLO_URI
Latest HELLO messages used for communicating peer addresses.
size_t GNUNET_STRINGS_urlencode(size_t len, const char data[static len], char **out)
url/percent encode (RFC3986).
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
size_t GNUNET_STRINGS_urldecode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
static enum GNUNET_GenericReturnValue verify_hello(const struct GNUNET_HELLO_Parser *parser, struct GNUNET_TIME_Absolute et, const struct GNUNET_CRYPTO_EddsaSignature *sig)
Verify HELLO signature.
static void sign_hello(const struct GNUNET_HELLO_Builder *builder, struct GNUNET_TIME_Absolute et, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaSignature *sig)
Create HELLO signature.
static struct GNUNET_HELLO_Parser * parser_new(const struct GNUNET_PeerIdentity *pid)
static void hash_addresses(const struct Address *a_head, struct GNUNET_HashCode *hash)
Compute hash over addresses in builder.
static enum GNUNET_GenericReturnValue check_address(const char *address)
static enum GNUNET_GenericReturnValue parser_add_address(struct GNUNET_HELLO_Parser *parser, const char *address)
static struct GNUNET_MQ_Envelope * GNUNET_HELLO_builder_to_env_(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_TIME_Relative expiration_time, const struct GNUNET_CRYPTO_EddsaSignature *sig)
static unsigned int size
Size of the "table".
#define GNUNET_SIGNATURE_PURPOSE_HELLO
Signature by which a peer affirms its address.
#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS
Signature by a peer affirming that this is one of its addresses for the given time period.
Struct to wrap data to do the merge of to hello uris.
unsigned int merged
Did we found at least one address to merge.
struct GNUNET_HELLO_Builder * builder
The builder of the hello uri we merge with.
unsigned int found
Did we found the actual address to check.
const char * address_uri
The actual address to check, if it is already in the hello uri we merge with.
struct Address * next
Kept in a DLL.
size_t uri_len
Length of uri including 0-terminator.
struct Address * prev
Kept in a DLL.
const char * uri
Actual URI, allocated at the end of this struct.
Message used when a DHT provides its HELLO to direct neighbours.
uint16_t reserved
Reserved.
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the HELLO expire?
struct GNUNET_MessageHeader header
Type must be GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO.
struct GNUNET_CRYPTO_EddsaSignature sig
Signature over the block, of purpose GNUNET_SIGNATURE_PURPOSE_HELLO.
uint16_t url_counter
Number of URLs encoded after the end of the struct, in NBO.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
Private ECC key encoded for transmission.
an ECC signature using EdDSA.
Context for building (or parsing) HELLO URIs.
struct GNUNET_PeerIdentity pid
Public key of the peer.
struct Address * a_tail
Tail of the addresses DLL.
struct Address * a_head
Head of the addresses DLL.
unsigned int a_length
Length of the a_head DLL.
Context for parsing HELLOs.
struct GNUNET_PeerIdentity pid
Public key of the peer.
struct GNUNET_TIME_Absolute et
Expiration time parsed.
struct GNUNET_CRYPTO_EddsaSignature sig
The signature (may have been provided)
struct Address * a_tail
Tail of the addresses DLL.
unsigned int a_length
Length of the a_head DLL.
struct Address * a_head
Head of the addresses DLL.
pid_t pid
PID of the process.
The identity of the host (wraps the signing key of the peer).
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Message signed as part of a HELLO block/URL.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_HELLO.
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the signature expire?
struct GNUNET_HashCode h_addrs
Hash over all addresses.
Message used when gossiping HELLOs between peers.
uint16_t reserved
Reserved.
uint16_t url_counter
Number of URLs encoded after the end of the struct, in NBO.
struct GNUNET_MessageHeader header
Type must be GNUNET_MESSAGE_TYPE_HELLO_URI.
struct MyAddress * next
Kept in a DLL.
Binary block we sign when we sign an address.
struct GNUNET_HashCode addr_hash
Hash of the address.
struct GNUNET_TIME_AbsoluteNBO mono_time
When was the address generated.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS.