aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-01-18 11:05:41 +0100
committerMartin Schanzenbach <schanzen@gnunet.org>2022-01-18 11:05:41 +0100
commit54554ca531d018b965cc04fe5046e7df68eb27f9 (patch)
treec2c2128b3465f80d355a0d97d9c5ac30e5b01c91
parent56b8101fe913c113fdb9fa2f9149861752bbea12 (diff)
downloadgnunet-54554ca531d018b965cc04fe5046e7df68eb27f9.tar.gz
gnunet-54554ca531d018b965cc04fe5046e7df68eb27f9.zip
GNS: Towards NFC
-rw-r--r--src/gnsrecord/gnsrecord_crypto.c207
-rw-r--r--src/gnsrecord/gnsrecord_misc.c14
-rw-r--r--src/include/gnunet_gnsrecord_lib.h9
-rw-r--r--src/include/gnunet_strings_lib.h12
-rw-r--r--src/namestore/gnunet-service-namestore.c4
-rw-r--r--src/util/strings.c17
6 files changed, 167 insertions, 96 deletions
diff --git a/src/gnsrecord/gnsrecord_crypto.c b/src/gnsrecord/gnsrecord_crypto.c
index feb60ade9..fe7db88b9 100644
--- a/src/gnsrecord/gnsrecord_crypto.c
+++ b/src/gnsrecord/gnsrecord_crypto.c
@@ -447,28 +447,36 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key,
447 unsigned int rd_count) 447 unsigned int rd_count)
448{ 448{
449 struct GNUNET_IDENTITY_PublicKey pkey; 449 struct GNUNET_IDENTITY_PublicKey pkey;
450 struct GNUNET_GNSRECORD_Block *res = NULL;
451 char *norm_label;
452
450 GNUNET_IDENTITY_key_get_public (key, 453 GNUNET_IDENTITY_key_get_public (key,
451 &pkey); 454 &pkey);
455 norm_label = GNUNET_GNSRECORD_string_normalize (label);
456
452 switch (ntohl (key->type)) 457 switch (ntohl (key->type))
453 { 458 {
454 case GNUNET_GNSRECORD_TYPE_PKEY: 459 case GNUNET_GNSRECORD_TYPE_PKEY:
455 return block_create_ecdsa (&key->ecdsa_key, 460 res = block_create_ecdsa (&key->ecdsa_key,
456 &pkey.ecdsa_key, 461 &pkey.ecdsa_key,
457 expire, 462 expire,
458 label, 463 norm_label,
459 rd, 464 rd,
460 rd_count); 465 rd_count);
461 case GNUNET_GNSRECORD_TYPE_EDKEY: 466 break;
462 return block_create_eddsa (&key->eddsa_key, 467 case GNUNET_GNSRECORD_TYPE_EDKEY:
463 &pkey.eddsa_key, 468 res = block_create_eddsa (&key->eddsa_key,
464 expire, 469 &pkey.eddsa_key,
465 label, 470 expire,
466 rd, 471 norm_label,
467 rd_count); 472 rd,
468 default: 473 rd_count);
469 GNUNET_assert (0); 474 break;
475 default:
476 GNUNET_assert (0);
470 } 477 }
471 return NULL; 478 GNUNET_free (norm_label);
479 return res;
472} 480}
473 481
474 482
@@ -510,6 +518,10 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *pkey,
510{ 518{
511 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key; 519 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key;
512 struct GNUNET_CRYPTO_EddsaPublicKey edpubkey; 520 struct GNUNET_CRYPTO_EddsaPublicKey edpubkey;
521 struct GNUNET_GNSRECORD_Block *res = NULL;
522 char *norm_label;
523
524 norm_label = GNUNET_GNSRECORD_string_normalize (label);
513 525
514 if (GNUNET_IDENTITY_TYPE_ECDSA == ntohl (pkey->type)) 526 if (GNUNET_IDENTITY_TYPE_ECDSA == ntohl (pkey->type))
515 { 527 {
@@ -529,25 +541,26 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *pkey,
529 &line->pkey); 541 &line->pkey);
530 } 542 }
531#undef CSIZE 543#undef CSIZE
532 return block_create_ecdsa (key, 544 res = block_create_ecdsa (key,
533 &line->pkey, 545 &line->pkey,
534 expire, 546 expire,
535 label, 547 norm_label,
536 rd, 548 rd,
537 rd_count); 549 rd_count);
538 } 550 }
539 else if (GNUNET_IDENTITY_TYPE_EDDSA == ntohl (pkey->type)) 551 else if (GNUNET_IDENTITY_TYPE_EDDSA == ntohl (pkey->type))
540 { 552 {
541 GNUNET_CRYPTO_eddsa_key_get_public (&pkey->eddsa_key, 553 GNUNET_CRYPTO_eddsa_key_get_public (&pkey->eddsa_key,
542 &edpubkey); 554 &edpubkey);
543 return block_create_eddsa (&pkey->eddsa_key, 555 res = block_create_eddsa (&pkey->eddsa_key,
544 &edpubkey, 556 &edpubkey,
545 expire, 557 expire,
546 label, 558 norm_label,
547 rd, 559 rd,
548 rd_count); 560 rd_count);
549 } 561 }
550 return NULL; 562 GNUNET_free (norm_label);
563 return res;
551} 564}
552 565
553 566
@@ -563,20 +576,20 @@ GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block)
563{ 576{
564 switch (ntohl (block->type)) 577 switch (ntohl (block->type))
565 { 578 {
566 case GNUNET_GNSRECORD_TYPE_PKEY: 579 case GNUNET_GNSRECORD_TYPE_PKEY:
567 return GNUNET_CRYPTO_ecdsa_verify_ ( 580 return GNUNET_CRYPTO_ecdsa_verify_ (
568 GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, 581 GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN,
569 &block->ecdsa_block.purpose, 582 &block->ecdsa_block.purpose,
570 &block->ecdsa_block.signature, 583 &block->ecdsa_block.signature,
571 &block->ecdsa_block.derived_key); 584 &block->ecdsa_block.derived_key);
572 case GNUNET_GNSRECORD_TYPE_EDKEY: 585 case GNUNET_GNSRECORD_TYPE_EDKEY:
573 return GNUNET_CRYPTO_eddsa_verify_ ( 586 return GNUNET_CRYPTO_eddsa_verify_ (
574 GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, 587 GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN,
575 &block->eddsa_block.purpose, 588 &block->eddsa_block.purpose,
576 &block->eddsa_block.signature, 589 &block->eddsa_block.signature,
577 &block->eddsa_block.derived_key); 590 &block->eddsa_block.derived_key);
578 default: 591 default:
579 return GNUNET_NO; 592 return GNUNET_NO;
580 } 593 }
581} 594}
582 595
@@ -590,8 +603,8 @@ block_decrypt_ecdsa (const struct GNUNET_GNSRECORD_EcdsaBlock *block,
590 void *proc_cls) 603 void *proc_cls)
591{ 604{
592 size_t payload_len = ntohl (block->purpose.size) 605 size_t payload_len = ntohl (block->purpose.size)
593 - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) 606 - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
594 - sizeof(struct GNUNET_TIME_AbsoluteNBO); 607 - sizeof(struct GNUNET_TIME_AbsoluteNBO);
595 unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2]; 608 unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
596 unsigned char key[GNUNET_CRYPTO_AES_KEY_LENGTH]; 609 unsigned char key[GNUNET_CRYPTO_AES_KEY_LENGTH];
597 610
@@ -718,8 +731,8 @@ block_decrypt_eddsa (const struct GNUNET_GNSRECORD_EddsaBlock *block,
718 void *proc_cls) 731 void *proc_cls)
719{ 732{
720 size_t payload_len = ntohl (block->purpose.size) 733 size_t payload_len = ntohl (block->purpose.size)
721 - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) 734 - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
722 - sizeof(struct GNUNET_TIME_AbsoluteNBO); 735 - sizeof(struct GNUNET_TIME_AbsoluteNBO);
723 unsigned char nonce[crypto_secretbox_NONCEBYTES]; 736 unsigned char nonce[crypto_secretbox_NONCEBYTES];
724 unsigned char key[crypto_secretbox_KEYBYTES]; 737 unsigned char key[crypto_secretbox_KEYBYTES];
725 738
@@ -856,17 +869,25 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
856 GNUNET_GNSRECORD_RecordCallback proc, 869 GNUNET_GNSRECORD_RecordCallback proc,
857 void *proc_cls) 870 void *proc_cls)
858{ 871{
872 enum GNUNET_GenericReturnValue res = GNUNET_SYSERR;
873 char *norm_label;
874
875 norm_label = GNUNET_GNSRECORD_string_normalize (label);
859 switch (ntohl (zone_key->type)) 876 switch (ntohl (zone_key->type))
860 { 877 {
861 case GNUNET_IDENTITY_TYPE_ECDSA: 878 case GNUNET_IDENTITY_TYPE_ECDSA:
862 return block_decrypt_ecdsa (&block->ecdsa_block, 879 res = block_decrypt_ecdsa (&block->ecdsa_block,
863 &zone_key->ecdsa_key, label, proc, proc_cls); 880 &zone_key->ecdsa_key, norm_label, proc, proc_cls);
864 case GNUNET_IDENTITY_TYPE_EDDSA: 881 break;
865 return block_decrypt_eddsa (&block->eddsa_block, 882 case GNUNET_IDENTITY_TYPE_EDDSA:
866 &zone_key->eddsa_key, label, proc, proc_cls); 883 res = block_decrypt_eddsa (&block->eddsa_block,
867 default: 884 &zone_key->eddsa_key, norm_label, proc, proc_cls);
868 return GNUNET_SYSERR; 885 break;
886 default:
887 return GNUNET_SYSERR;
869 } 888 }
889 GNUNET_free (norm_label);
890 return res;
870} 891}
871 892
872 893
@@ -883,21 +904,25 @@ GNUNET_GNSRECORD_query_from_private_key (const struct
883 const char *label, 904 const char *label,
884 struct GNUNET_HashCode *query) 905 struct GNUNET_HashCode *query)
885{ 906{
907 char *norm_label;
886 struct GNUNET_IDENTITY_PublicKey pub; 908 struct GNUNET_IDENTITY_PublicKey pub;
909
910 norm_label = GNUNET_GNSRECORD_string_normalize (label);
887 switch (ntohl (zone->type)) 911 switch (ntohl (zone->type))
888 { 912 {
889 case GNUNET_GNSRECORD_TYPE_PKEY: 913 case GNUNET_GNSRECORD_TYPE_PKEY:
890 case GNUNET_GNSRECORD_TYPE_EDKEY: 914 case GNUNET_GNSRECORD_TYPE_EDKEY:
891 915
892 GNUNET_IDENTITY_key_get_public (zone, 916 GNUNET_IDENTITY_key_get_public (zone,
893 &pub); 917 &pub);
894 GNUNET_GNSRECORD_query_from_public_key (&pub, 918 GNUNET_GNSRECORD_query_from_public_key (&pub,
895 label, 919 norm_label,
896 query); 920 query);
897 break; 921 break;
898 default: 922 default:
899 GNUNET_assert (0); 923 GNUNET_assert (0);
900 } 924 }
925 GNUNET_free (norm_label);
901} 926}
902 927
903 928
@@ -915,33 +940,37 @@ GNUNET_GNSRECORD_query_from_public_key (const struct
915 const char *label, 940 const char *label,
916 struct GNUNET_HashCode *query) 941 struct GNUNET_HashCode *query)
917{ 942{
943 char *norm_label;
918 struct GNUNET_IDENTITY_PublicKey pd; 944 struct GNUNET_IDENTITY_PublicKey pd;
919 945
946 norm_label = GNUNET_GNSRECORD_string_normalize (label);
947
920 switch (ntohl (pub->type)) 948 switch (ntohl (pub->type))
921 { 949 {
922 case GNUNET_GNSRECORD_TYPE_PKEY: 950 case GNUNET_GNSRECORD_TYPE_PKEY:
923 pd.type = pub->type; 951 pd.type = pub->type;
924 GNUNET_CRYPTO_ecdsa_public_key_derive (&pub->ecdsa_key, 952 GNUNET_CRYPTO_ecdsa_public_key_derive (&pub->ecdsa_key,
925 label, 953 norm_label,
926 "gns", 954 "gns",
927 &pd.ecdsa_key); 955 &pd.ecdsa_key);
928 GNUNET_CRYPTO_hash (&pd.ecdsa_key, 956 GNUNET_CRYPTO_hash (&pd.ecdsa_key,
929 sizeof (pd.ecdsa_key), 957 sizeof (pd.ecdsa_key),
930 query); 958 query);
931 break; 959 break;
932 case GNUNET_GNSRECORD_TYPE_EDKEY: 960 case GNUNET_GNSRECORD_TYPE_EDKEY:
933 pd.type = pub->type; 961 pd.type = pub->type;
934 GNUNET_CRYPTO_eddsa_public_key_derive (&pub->eddsa_key, 962 GNUNET_CRYPTO_eddsa_public_key_derive (&pub->eddsa_key,
935 label, 963 norm_label,
936 "gns", 964 "gns",
937 &(pd.eddsa_key)); 965 &(pd.eddsa_key));
938 GNUNET_CRYPTO_hash (&pd.eddsa_key, 966 GNUNET_CRYPTO_hash (&pd.eddsa_key,
939 sizeof (pd.eddsa_key), 967 sizeof (pd.eddsa_key),
940 query); 968 query);
941 break; 969 break;
942 default: 970 default:
943 GNUNET_assert (0); 971 GNUNET_assert (0);
944 } 972 }
973 GNUNET_free (norm_label);
945} 974}
946 975
947 976
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c
index 8d3a6421f..c6f07ccd0 100644
--- a/src/gnsrecord/gnsrecord_misc.c
+++ b/src/gnsrecord/gnsrecord_misc.c
@@ -37,11 +37,6 @@
37 37
38#define LOG(kind, ...) GNUNET_log_from (kind, "gnsrecord", __VA_ARGS__) 38#define LOG(kind, ...) GNUNET_log_from (kind, "gnsrecord", __VA_ARGS__)
39 39
40/**
41 * Convert a UTF-8 string to UTF-8 lowercase
42 * @param src source string
43 * @return converted result
44 */
45char * 40char *
46GNUNET_GNSRECORD_string_to_lowercase (const char *src) 41GNUNET_GNSRECORD_string_to_lowercase (const char *src)
47{ 42{
@@ -52,6 +47,15 @@ GNUNET_GNSRECORD_string_to_lowercase (const char *src)
52 return res; 47 return res;
53} 48}
54 49
50char *
51GNUNET_GNSRECORD_string_normalize (const char *src)
52{
53 char *res;
54 res = GNUNET_strdup (src);
55 GNUNET_STRINGS_utf8_tolower (src, res);
56 GNUNET_STRINGS_utf8_normalize (src, res);
57 return res;
58}
55 59
56/** 60/**
57 * Convert a zone key to a string (for printing debug messages). 61 * Convert a zone key to a string (for printing debug messages).
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h
index f00a5d0f8..94e20323d 100644
--- a/src/include/gnunet_gnsrecord_lib.h
+++ b/src/include/gnunet_gnsrecord_lib.h
@@ -418,6 +418,15 @@ GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd);
418 418
419 419
420/** 420/**
421 * Normalize a UTF-8 string to UTF-8 NFC
422 * @param src source string
423 * @return converted result
424 */
425char *
426GNUNET_GNSRECORD_string_normalize (const char *src);
427
428
429/**
421 * Convert a UTF-8 string to UTF-8 lowercase 430 * Convert a UTF-8 string to UTF-8 lowercase
422 * @param src source string 431 * @param src source string
423 * @return converted result 432 * @return converted result
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h
index ef9d5ac58..9dd2f733e 100644
--- a/src/include/gnunet_strings_lib.h
+++ b/src/include/gnunet_strings_lib.h
@@ -158,6 +158,18 @@ GNUNET_STRINGS_to_utf8 (const char *input,
158 158
159 159
160/** 160/**
161 * Normalize the utf-8 input string to NFC.
162 * Output needs to be allocated appropriately.
163 *
164 * @param input input string
165 * @param output output buffer
166 */
167void
168GNUNET_STRINGS_utf8_normalize (const char *input,
169 char *output);
170
171
172/**
161 * Convert the len bytes-long UTF-8 string 173 * Convert the len bytes-long UTF-8 string
162 * given in input to the given charset. 174 * given in input to the given charset.
163 * 175 *
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index cd953492e..cf1b555a5 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -1366,7 +1366,7 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1366 "Received NAMESTORE_RECORD_LOOKUP message for name `%s'\n", 1366 "Received NAMESTORE_RECORD_LOOKUP message for name `%s'\n",
1367 name_tmp); 1367 name_tmp);
1368 1368
1369 conv_name = GNUNET_GNSRECORD_string_to_lowercase (name_tmp); 1369 conv_name = GNUNET_GNSRECORD_string_normalize (name_tmp);
1370 if (NULL == conv_name) 1370 if (NULL == conv_name)
1371 { 1371 {
1372 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1372 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1490,7 +1490,7 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1490 } 1490 }
1491 1491
1492 /* Extracting and converting private key */ 1492 /* Extracting and converting private key */
1493 conv_name = GNUNET_GNSRECORD_string_to_lowercase (name_tmp); 1493 conv_name = GNUNET_GNSRECORD_string_normalize (name_tmp);
1494 if (NULL == conv_name) 1494 if (NULL == conv_name)
1495 { 1495 {
1496 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1496 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/util/strings.c b/src/util/strings.c
index 76125b92e..ece096f72 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -427,6 +427,23 @@ GNUNET_STRINGS_from_utf8 (const char *input,
427 427
428 428
429void 429void
430GNUNET_STRINGS_utf8_normalize (const char *input,
431 char *output)
432{
433 uint8_t *tmp;
434 size_t len;
435
436 tmp = u8_normalize (UNINORM_NFC,
437 (uint8_t *) input,
438 strlen ((char*) input),
439 NULL,
440 &len);
441 GNUNET_memcpy (output, tmp, len);
442 output[len] = '\0';
443 free (tmp);
444}
445
446void
430GNUNET_STRINGS_utf8_tolower (const char *input, 447GNUNET_STRINGS_utf8_tolower (const char *input,
431 char *output) 448 char *output)
432{ 449{