diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/fs/fs_uri.c | 184 | ||||
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 6 | ||||
-rw-r--r-- | src/include/gnunet_strings_lib.h | 1 | ||||
-rw-r--r-- | src/util/strings.c | 4 |
4 files changed, 53 insertions, 142 deletions
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index 578fc6820..48fc96a1a 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c | |||
@@ -118,7 +118,7 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, | |||
118 | case GNUNET_FS_URI_LOC: | 118 | case GNUNET_FS_URI_LOC: |
119 | GNUNET_CRYPTO_hash (&uri->data.loc.fi, | 119 | GNUNET_CRYPTO_hash (&uri->data.loc.fi, |
120 | sizeof (struct FileIdentifier) + | 120 | sizeof (struct FileIdentifier) + |
121 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), | 121 | sizeof (struct GNUNET_PeerIdentity), |
122 | key); | 122 | key); |
123 | break; | 123 | break; |
124 | default: | 124 | default: |
@@ -442,70 +442,6 @@ uri_chk_parse (const char *s, char **emsg) | |||
442 | } | 442 | } |
443 | 443 | ||
444 | 444 | ||
445 | /** | ||
446 | * Convert a character back to the binary value | ||
447 | * that it represents (given base64-encoding). | ||
448 | * | ||
449 | * @param a character to convert | ||
450 | * @return offset in the "tbl" array | ||
451 | */ | ||
452 | static unsigned int | ||
453 | c2v (unsigned char a) | ||
454 | { | ||
455 | if ((a >= '0') && (a <= '9')) | ||
456 | return a - '0'; | ||
457 | if ((a >= 'A') && (a <= 'Z')) | ||
458 | return (a - 'A' + 10); | ||
459 | if ((a >= 'a') && (a <= 'z')) | ||
460 | return (a - 'a' + 36); | ||
461 | if (a == '_') | ||
462 | return 62; | ||
463 | if (a == '=') | ||
464 | return 63; | ||
465 | return -1; | ||
466 | } | ||
467 | |||
468 | |||
469 | /** | ||
470 | * Convert string back to binary data. | ||
471 | * | ||
472 | * @param input '\\0'-terminated string | ||
473 | * @param data where to write binary data | ||
474 | * @param size how much data should be converted | ||
475 | * @return number of characters processed from input, | ||
476 | * -1 on error | ||
477 | */ | ||
478 | static int | ||
479 | enc2bin (const char *input, void *data, size_t size) | ||
480 | { | ||
481 | size_t len; | ||
482 | size_t pos; | ||
483 | unsigned int bits; | ||
484 | unsigned int hbits; | ||
485 | |||
486 | len = size * 8 / 6; | ||
487 | if (((size * 8) % 6) != 0) | ||
488 | len++; | ||
489 | if (strlen (input) < len) | ||
490 | return -1; /* error! */ | ||
491 | bits = 0; | ||
492 | hbits = 0; | ||
493 | len = 0; | ||
494 | for (pos = 0; pos < size; pos++) | ||
495 | { | ||
496 | while (hbits < 8) | ||
497 | { | ||
498 | bits |= (c2v (input[len++]) << hbits); | ||
499 | hbits += 6; | ||
500 | } | ||
501 | (((unsigned char *) data)[pos]) = (unsigned char) bits; | ||
502 | bits >>= 8; | ||
503 | hbits -= 8; | ||
504 | } | ||
505 | return len; | ||
506 | } | ||
507 | |||
508 | |||
509 | GNUNET_NETWORK_STRUCT_BEGIN | 445 | GNUNET_NETWORK_STRUCT_BEGIN |
510 | /** | 446 | /** |
511 | * Structure that defines how the contents of a location URI must be | 447 | * Structure that defines how the contents of a location URI must be |
@@ -540,6 +476,8 @@ GNUNET_NETWORK_STRUCT_END | |||
540 | 476 | ||
541 | #define GNUNET_FS_URI_LOC_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_LOC_INFIX | 477 | #define GNUNET_FS_URI_LOC_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_LOC_INFIX |
542 | 478 | ||
479 | #define SIGNATURE_ASCII_LENGTH 103 | ||
480 | |||
543 | /** | 481 | /** |
544 | * Parse a LOC URI. | 482 | * Parse a LOC URI. |
545 | * Also verifies validity of the location URI. | 483 | * Also verifies validity of the location URI. |
@@ -561,10 +499,8 @@ uri_loc_parse (const char *s, char **emsg) | |||
561 | struct GNUNET_TIME_Absolute et; | 499 | struct GNUNET_TIME_Absolute et; |
562 | struct GNUNET_CRYPTO_EddsaSignature sig; | 500 | struct GNUNET_CRYPTO_EddsaSignature sig; |
563 | struct LocUriAssembly ass; | 501 | struct LocUriAssembly ass; |
564 | int ret; | ||
565 | size_t slen; | 502 | size_t slen; |
566 | 503 | ||
567 | GNUNET_assert (s != NULL); | ||
568 | slen = strlen (s); | 504 | slen = strlen (s); |
569 | pos = strlen (GNUNET_FS_URI_LOC_PREFIX); | 505 | pos = strlen (GNUNET_FS_URI_LOC_PREFIX); |
570 | if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || | 506 | if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || |
@@ -602,28 +538,43 @@ uri_loc_parse (const char *s, char **emsg) | |||
602 | goto ERR; | 538 | goto ERR; |
603 | } | 539 | } |
604 | npos++; | 540 | npos++; |
605 | ret = | 541 | if ( (strlen (&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) || |
606 | enc2bin (&s[npos], &ass.peer, | 542 | ('.' != s[npos+GNUNET_CRYPTO_PKEY_ASCII_LENGTH]) ) |
607 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 543 | { |
608 | if (ret == -1) | 544 | *emsg = |
545 | GNUNET_strdup (_("LOC URI malformed (could not decode public key)")); | ||
546 | } | ||
547 | if (GNUNET_OK != | ||
548 | GNUNET_CRYPTO_eddsa_public_key_from_string (&s[npos], | ||
549 | GNUNET_CRYPTO_PKEY_ASCII_LENGTH, | ||
550 | &ass.peer.public_key)) | ||
609 | { | 551 | { |
610 | *emsg = | 552 | *emsg = |
611 | GNUNET_strdup (_("LOC URI malformed (could not decode public key)")); | 553 | GNUNET_strdup (_("LOC URI malformed (could not decode public key)")); |
612 | goto ERR; | 554 | goto ERR; |
613 | } | 555 | } |
614 | npos += ret; | 556 | npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH; |
615 | if (s[npos++] != '.') | 557 | if (s[npos++] != '.') |
616 | { | 558 | { |
617 | *emsg = GNUNET_strdup (_("SKS URI malformed (could not find signature)")); | 559 | *emsg = GNUNET_strdup (_("SKS URI malformed (could not find signature)")); |
618 | goto ERR; | 560 | goto ERR; |
619 | } | 561 | } |
620 | ret = enc2bin (&s[npos], &sig, sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); | 562 | if ( (strlen (&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) || |
621 | if (ret == -1) | 563 | ('.' != s[npos + SIGNATURE_ASCII_LENGTH]) ) |
622 | { | 564 | { |
623 | *emsg = GNUNET_strdup (_("SKS URI malformed (could not decode signature)")); | 565 | *emsg = GNUNET_strdup (_("SKS URI malformed (could not decode signature)")); |
624 | goto ERR; | 566 | goto ERR; |
625 | } | 567 | } |
626 | npos += ret; | 568 | if (GNUNET_OK != |
569 | GNUNET_STRINGS_string_to_data (&s[npos], | ||
570 | SIGNATURE_ASCII_LENGTH, | ||
571 | &sig, | ||
572 | sizeof (struct GNUNET_CRYPTO_EddsaSignature))) | ||
573 | { | ||
574 | *emsg = GNUNET_strdup (_("SKS URI malformed (could not decode signature)")); | ||
575 | goto ERR; | ||
576 | } | ||
577 | npos += SIGNATURE_ASCII_LENGTH; | ||
627 | if (s[npos++] != '.') | 578 | if (s[npos++] != '.') |
628 | { | 579 | { |
629 | *emsg = GNUNET_strdup (_("SKS URI malformed")); | 580 | *emsg = GNUNET_strdup (_("SKS URI malformed")); |
@@ -632,8 +583,7 @@ uri_loc_parse (const char *s, char **emsg) | |||
632 | if (1 != SSCANF (&s[npos], "%llu", &exptime)) | 583 | if (1 != SSCANF (&s[npos], "%llu", &exptime)) |
633 | { | 584 | { |
634 | *emsg = | 585 | *emsg = |
635 | GNUNET_strdup (_ | 586 | GNUNET_strdup (_("SKS URI malformed (could not parse expiration time)")); |
636 | ("SKS URI malformed (could not parse expiration time)")); | ||
637 | goto ERR; | 587 | goto ERR; |
638 | } | 588 | } |
639 | ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); | 589 | ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); |
@@ -700,7 +650,6 @@ GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri) | |||
700 | { | 650 | { |
701 | unsigned int i; | 651 | unsigned int i; |
702 | 652 | ||
703 | GNUNET_assert (uri != NULL); | ||
704 | switch (uri->type) | 653 | switch (uri->type) |
705 | { | 654 | { |
706 | case GNUNET_FS_URI_KSK: | 655 | case GNUNET_FS_URI_KSK: |
@@ -720,6 +669,7 @@ GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri) | |||
720 | GNUNET_free (uri); | 669 | GNUNET_free (uri); |
721 | } | 670 | } |
722 | 671 | ||
672 | |||
723 | /** | 673 | /** |
724 | * How many keywords are ANDed in this keyword URI? | 674 | * How many keywords are ANDed in this keyword URI? |
725 | * | 675 | * |
@@ -754,7 +704,7 @@ GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, | |||
754 | 704 | ||
755 | if (uri->type != GNUNET_FS_URI_KSK) | 705 | if (uri->type != GNUNET_FS_URI_KSK) |
756 | return -1; | 706 | return -1; |
757 | if (iterator == NULL) | 707 | if (NULL == iterator) |
758 | return uri->data.ksk.keywordCount; | 708 | return uri->data.ksk.keywordCount; |
759 | for (i = 0; i < uri->data.ksk.keywordCount; i++) | 709 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
760 | { | 710 | { |
@@ -777,7 +727,8 @@ GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, | |||
777 | * @param is_mandatory is this keyword mandatory? | 727 | * @param is_mandatory is this keyword mandatory? |
778 | */ | 728 | */ |
779 | void | 729 | void |
780 | GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, const char *keyword, | 730 | GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, |
731 | const char *keyword, | ||
781 | int is_mandatory) | 732 | int is_mandatory) |
782 | { | 733 | { |
783 | unsigned int i; | 734 | unsigned int i; |
@@ -859,7 +810,6 @@ GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri) | |||
859 | } | 810 | } |
860 | 811 | ||
861 | 812 | ||
862 | |||
863 | /** | 813 | /** |
864 | * Obtain the URI of the content itself. | 814 | * Obtain the URI of the content itself. |
865 | * | 815 | * |
@@ -1965,53 +1915,6 @@ uri_chk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1965 | return ret; | 1915 | return ret; |
1966 | } | 1916 | } |
1967 | 1917 | ||
1968 | /** | ||
1969 | * Convert binary data to a string. | ||
1970 | * | ||
1971 | * @param data binary data to convert | ||
1972 | * @param size number of bytes in data | ||
1973 | * @return converted data | ||
1974 | */ | ||
1975 | static char * | ||
1976 | bin2enc (const void *data, size_t size) | ||
1977 | { | ||
1978 | /** | ||
1979 | * 64 characters for encoding, 6 bits per character | ||
1980 | */ | ||
1981 | static char *tbl = | ||
1982 | "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_="; | ||
1983 | |||
1984 | size_t len; | ||
1985 | size_t pos; | ||
1986 | unsigned int bits; | ||
1987 | unsigned int hbits; | ||
1988 | char *ret; | ||
1989 | |||
1990 | GNUNET_assert (strlen (tbl) == 64); | ||
1991 | len = size * 8 / 6; | ||
1992 | if (((size * 8) % 6) != 0) | ||
1993 | len++; | ||
1994 | ret = GNUNET_malloc (len + 1); | ||
1995 | ret[len] = '\0'; | ||
1996 | len = 0; | ||
1997 | bits = 0; | ||
1998 | hbits = 0; | ||
1999 | for (pos = 0; pos < size; pos++) | ||
2000 | { | ||
2001 | bits |= ((((const unsigned char *) data)[pos]) << hbits); | ||
2002 | hbits += 8; | ||
2003 | while (hbits >= 6) | ||
2004 | { | ||
2005 | ret[len++] = tbl[bits & 63]; | ||
2006 | bits >>= 6; | ||
2007 | hbits -= 6; | ||
2008 | } | ||
2009 | } | ||
2010 | if (hbits > 0) | ||
2011 | ret[len] = tbl[bits & 63]; | ||
2012 | return ret; | ||
2013 | } | ||
2014 | |||
2015 | 1918 | ||
2016 | /** | 1919 | /** |
2017 | * Convert a LOC URI to a string. | 1920 | * Convert a LOC URI to a string. |
@@ -2025,27 +1928,28 @@ uri_loc_to_string (const struct GNUNET_FS_Uri *uri) | |||
2025 | char *ret; | 1928 | char *ret; |
2026 | struct GNUNET_CRYPTO_HashAsciiEncoded keyhash; | 1929 | struct GNUNET_CRYPTO_HashAsciiEncoded keyhash; |
2027 | struct GNUNET_CRYPTO_HashAsciiEncoded queryhash; | 1930 | struct GNUNET_CRYPTO_HashAsciiEncoded queryhash; |
2028 | char *peerId; | 1931 | char *peer_id; |
2029 | char *peerSig; | 1932 | char peer_sig[SIGNATURE_ASCII_LENGTH + 1]; |
2030 | 1933 | ||
2031 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash); | 1934 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash); |
2032 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); | 1935 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); |
2033 | peerId = | 1936 | peer_id = |
2034 | bin2enc (&uri->data.loc.peer, | 1937 | GNUNET_CRYPTO_eddsa_public_key_to_string (&uri->data.loc.peer.public_key); |
2035 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 1938 | GNUNET_assert (NULL != |
2036 | peerSig = | 1939 | GNUNET_STRINGS_data_to_string (&uri->data.loc.contentSignature, |
2037 | bin2enc (&uri->data.loc.contentSignature, | 1940 | sizeof (struct GNUNET_CRYPTO_EddsaSignature), |
2038 | sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); | 1941 | peer_sig, |
1942 | sizeof (peer_sig))); | ||
2039 | GNUNET_asprintf (&ret, | 1943 | GNUNET_asprintf (&ret, |
2040 | "%s%s%s.%s.%llu.%s.%s.%llu", GNUNET_FS_URI_PREFIX, | 1944 | "%s%s%s.%s.%llu.%s.%s.%llu", GNUNET_FS_URI_PREFIX, |
2041 | GNUNET_FS_URI_LOC_INFIX, (const char *) &keyhash, | 1945 | GNUNET_FS_URI_LOC_INFIX, (const char *) &keyhash, |
2042 | (const char *) &queryhash, | 1946 | (const char *) &queryhash, |
2043 | (unsigned long long) GNUNET_ntohll (uri->data.loc. | 1947 | (unsigned long long) GNUNET_ntohll (uri->data.loc. |
2044 | fi.file_length), peerId, | 1948 | fi.file_length), |
2045 | peerSig, | 1949 | peer_id, |
1950 | peer_sig, | ||
2046 | (unsigned long long) uri->data.loc.expirationTime.abs_value_us / 1000000LL); | 1951 | (unsigned long long) uri->data.loc.expirationTime.abs_value_us / 1000000LL); |
2047 | GNUNET_free (peerSig); | 1952 | GNUNET_free (peer_id); |
2048 | GNUNET_free (peerId); | ||
2049 | return ret; | 1953 | return ret; |
2050 | } | 1954 | } |
2051 | 1955 | ||
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index ebe500339..a82b2fdd6 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -111,6 +111,12 @@ enum GNUNET_CRYPTO_Quality | |||
111 | #define GNUNET_CRYPTO_HASH_LENGTH (512/8) | 111 | #define GNUNET_CRYPTO_HASH_LENGTH (512/8) |
112 | 112 | ||
113 | /** | 113 | /** |
114 | * How many characters (without 0-terminator) are our ASCII-encoded | ||
115 | * public keys (ECDSA/EDDSA/ECDHE). | ||
116 | */ | ||
117 | #define GNUNET_CRYPTO_PKEY_ASCII_LENGTH 52 | ||
118 | |||
119 | /** | ||
114 | * @brief 0-terminated ASCII encoding of a struct GNUNET_HashCode. | 120 | * @brief 0-terminated ASCII encoding of a struct GNUNET_HashCode. |
115 | */ | 121 | */ |
116 | struct GNUNET_CRYPTO_HashAsciiEncoded | 122 | struct GNUNET_CRYPTO_HashAsciiEncoded |
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h index f93148df5..eb16a339d 100644 --- a/src/include/gnunet_strings_lib.h +++ b/src/include/gnunet_strings_lib.h | |||
@@ -328,6 +328,7 @@ GNUNET_STRINGS_string_to_data (const char *enc, | |||
328 | size_t | 328 | size_t |
329 | GNUNET_STRINGS_base64_encode (const char *data, size_t len, char **output); | 329 | GNUNET_STRINGS_base64_encode (const char *data, size_t len, char **output); |
330 | 330 | ||
331 | |||
331 | /** | 332 | /** |
332 | * Decode from Base64. | 333 | * Decode from Base64. |
333 | * | 334 | * |
diff --git a/src/util/strings.c b/src/util/strings.c index cb3209215..92e24c1b7 100644 --- a/src/util/strings.c +++ b/src/util/strings.c | |||
@@ -1287,7 +1287,7 @@ GNUNET_STRINGS_to_address_ip (const char *addr, | |||
1287 | 1287 | ||
1288 | /** | 1288 | /** |
1289 | * Makes a copy of argv that consists of a single memory chunk that can be | 1289 | * Makes a copy of argv that consists of a single memory chunk that can be |
1290 | * freed with a single call to GNUNET_free (); | 1290 | * freed with a single call to GNUNET_free(); |
1291 | */ | 1291 | */ |
1292 | static char *const * | 1292 | static char *const * |
1293 | _make_continuous_arg_copy (int argc, | 1293 | _make_continuous_arg_copy (int argc, |
@@ -1318,7 +1318,7 @@ _make_continuous_arg_copy (int argc, | |||
1318 | * other than W32. | 1318 | * other than W32. |
1319 | * Returned argv has u8argv[u8argc] == NULL. | 1319 | * Returned argv has u8argv[u8argc] == NULL. |
1320 | * Returned argv is a single memory block, and can be freed with a single | 1320 | * Returned argv is a single memory block, and can be freed with a single |
1321 | * GNUNET_free () call. | 1321 | * GNUNET_free() call. |
1322 | * | 1322 | * |
1323 | * @param argc argc (as given by main()) | 1323 | * @param argc argc (as given by main()) |
1324 | * @param argv argv (as given by main()) | 1324 | * @param argv argv (as given by main()) |