diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-12-30 00:06:02 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-12-30 00:06:02 +0100 |
commit | 9f7a6d50b4c6a79ab16dfabe2c57510565bc4cf2 (patch) | |
tree | 445f5929acde578e82967e6e849ca11ce6e987a7 | |
parent | 1b40f010dcb1bd2ecfe8355088c5306968e6de1a (diff) | |
download | anastasis-9f7a6d50b4c6a79ab16dfabe2c57510565bc4cf2.tar.gz anastasis-9f7a6d50b4c6a79ab16dfabe2c57510565bc4cf2.zip |
simplify pin entry by breaking up into groups and auto-completion (#7088)
-rw-r--r-- | src/authorization/anastasis_authorization_plugin_email.c | 2 | ||||
-rw-r--r-- | src/authorization/anastasis_authorization_plugin_post.c | 2 | ||||
-rw-r--r-- | src/authorization/anastasis_authorization_plugin_sms.c | 4 | ||||
-rw-r--r-- | src/authorization/authorization-email-messages.json | 4 | ||||
-rw-r--r-- | src/authorization/authorization-post-messages.json | 2 | ||||
-rw-r--r-- | src/include/anastasis_util_lib.h | 33 | ||||
-rw-r--r-- | src/lib/anastasis_recovery.c | 2 | ||||
-rw-r--r-- | src/stasis/plugin_anastasis_postgres.c | 8 | ||||
-rw-r--r-- | src/util/Makefile.am | 3 | ||||
-rw-r--r-- | src/util/pin.c | 84 |
10 files changed, 129 insertions, 15 deletions
diff --git a/src/authorization/anastasis_authorization_plugin_email.c b/src/authorization/anastasis_authorization_plugin_email.c index d968252..2284988 100644 --- a/src/authorization/anastasis_authorization_plugin_email.c +++ b/src/authorization/anastasis_authorization_plugin_email.c | |||
@@ -378,7 +378,7 @@ email_process (struct ANASTASIS_AUTHORIZATION_State *as, | |||
378 | get_message (as->ctx->messages, | 378 | get_message (as->ctx->messages, |
379 | connection, | 379 | connection, |
380 | "body"), | 380 | "body"), |
381 | (unsigned long long) as->code, | 381 | ANASTASIS_pin2s (as->code), |
382 | ANASTASIS_CRYPTO_uuid2s (&as->truth_uuid)); | 382 | ANASTASIS_CRYPTO_uuid2s (&as->truth_uuid)); |
383 | 383 | ||
384 | { | 384 | { |
diff --git a/src/authorization/anastasis_authorization_plugin_post.c b/src/authorization/anastasis_authorization_plugin_post.c index 4692317..4f901d2 100644 --- a/src/authorization/anastasis_authorization_plugin_post.c +++ b/src/authorization/anastasis_authorization_plugin_post.c | |||
@@ -452,7 +452,7 @@ post_process (struct ANASTASIS_AUTHORIZATION_State *as, | |||
452 | get_message (as->ctx->messages, | 452 | get_message (as->ctx->messages, |
453 | connection, | 453 | connection, |
454 | "body"), | 454 | "body"), |
455 | (unsigned long long) as->code, | 455 | ANASTASIS_pin2s (as->code), |
456 | ANASTASIS_CRYPTO_uuid2s (&as->truth_uuid)); | 456 | ANASTASIS_CRYPTO_uuid2s (&as->truth_uuid)); |
457 | { | 457 | { |
458 | const char *off = as->msg; | 458 | const char *off = as->msg; |
diff --git a/src/authorization/anastasis_authorization_plugin_sms.c b/src/authorization/anastasis_authorization_plugin_sms.c index 2fed576..98152ef 100644 --- a/src/authorization/anastasis_authorization_plugin_sms.c +++ b/src/authorization/anastasis_authorization_plugin_sms.c | |||
@@ -374,8 +374,8 @@ sms_process (struct ANASTASIS_AUTHORIZATION_State *as, | |||
374 | GNUNET_assert (NULL != pipe_stdin); | 374 | GNUNET_assert (NULL != pipe_stdin); |
375 | GNUNET_DISK_pipe_close (p); | 375 | GNUNET_DISK_pipe_close (p); |
376 | GNUNET_asprintf (&as->msg, | 376 | GNUNET_asprintf (&as->msg, |
377 | "A-%llu\nAnastasis\n: %s", | 377 | "%s\nAnastasis\n: %s", |
378 | (unsigned long long) as->code, | 378 | ANASTASIS_pin2s (as->code), |
379 | ANASTASIS_CRYPTO_uuid2s (&as->truth_uuid)); | 379 | ANASTASIS_CRYPTO_uuid2s (&as->truth_uuid)); |
380 | { | 380 | { |
381 | const char *off = as->msg; | 381 | const char *off = as->msg; |
diff --git a/src/authorization/authorization-email-messages.json b/src/authorization/authorization-email-messages.json index 5a2e048..5e4ddb3 100644 --- a/src/authorization/authorization-email-messages.json +++ b/src/authorization/authorization-email-messages.json | |||
@@ -3,8 +3,8 @@ | |||
3 | "instructions_i18n" : { | 3 | "instructions_i18n" : { |
4 | "de_DE" : "Ein Authorisierungscode wurde an %.*s@DOMAIN geschickt" | 4 | "de_DE" : "Ein Authorisierungscode wurde an %.*s@DOMAIN geschickt" |
5 | }, | 5 | }, |
6 | "body" : "Your Anastasis recovery code is:\nA-%llu\n\nThis is for challenge %s.\n", | 6 | "body" : "Your Anastasis recovery code is:\n%s\n\nThis is for challenge %s.\n", |
7 | "body_i18n" : { | 7 | "body_i18n" : { |
8 | "de_DE" : "Ihr Anastasis Autorisierungscode ist:\nA-%llu\n\nDies ist der Code für den Vorgang %s.\n" | 8 | "de_DE" : "Ihr Anastasis Autorisierungscode ist:\n%s\n\nDies ist der Code für den Vorgang %s.\n" |
9 | } | 9 | } |
10 | } | 10 | } |
diff --git a/src/authorization/authorization-post-messages.json b/src/authorization/authorization-post-messages.json index d2ac83a..c48c8ab 100644 --- a/src/authorization/authorization-post-messages.json +++ b/src/authorization/authorization-post-messages.json | |||
@@ -3,5 +3,5 @@ | |||
3 | "instructions_i18n" : { | 3 | "instructions_i18n" : { |
4 | "de_DE" : "Ein Authorisierungscode wurde an eine Addresse mit der Postleitzahl %s geschickt" | 4 | "de_DE" : "Ein Authorisierungscode wurde an eine Addresse mit der Postleitzahl %s geschickt" |
5 | }, | 5 | }, |
6 | "body" : "Dear Customer\n\nThe Anastasis recovery code you need to\nrecover your data is A-%llu.\nThis is for challenge %s.\n\nBest regards\n\nYour Anastasis provider" | 6 | "body" : "Dear Customer\n\nThe Anastasis recovery code you need to\nrecover your data is %s.\nThis is for challenge %s.\n\nBest regards\n\nYour Anastasis provider" |
7 | } | 7 | } |
diff --git a/src/include/anastasis_util_lib.h b/src/include/anastasis_util_lib.h index 07b021b..602e1cc 100644 --- a/src/include/anastasis_util_lib.h +++ b/src/include/anastasis_util_lib.h | |||
@@ -30,6 +30,17 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Maximum value allowed for PINs. Limited to 10^15 < 2^52 to ensure the | ||
34 | * numeric value survives a conversion to float by JavaScript. | ||
35 | * | ||
36 | * NOTE: Do not change this value, we map it to a string like | ||
37 | * 42353-256-6521-241 and that mapping fails if the number | ||
38 | * does not have exactly 15 digits! | ||
39 | */ | ||
40 | #define ANASTASIS_PIN_MAX_VALUE 1000000000000000 | ||
41 | |||
42 | |||
43 | /** | ||
33 | * Return default project data used by Anastasis. | 44 | * Return default project data used by Anastasis. |
34 | */ | 45 | */ |
35 | const struct GNUNET_OS_ProjectData * | 46 | const struct GNUNET_OS_ProjectData * |
@@ -86,4 +97,26 @@ void | |||
86 | ANASTASIS_wait_child_cancel (struct ANASTASIS_ChildWaitHandle *cwh); | 97 | ANASTASIS_wait_child_cancel (struct ANASTASIS_ChildWaitHandle *cwh); |
87 | 98 | ||
88 | 99 | ||
100 | /** | ||
101 | * Convert input string @a as into @a pin. | ||
102 | * | ||
103 | * @param as input of the form 42355-256-2262-265 | ||
104 | * @param[out] pin set to numeric pin | ||
105 | * @return false if @as is malformed | ||
106 | */ | ||
107 | bool | ||
108 | ANASTASIS_scan_pin (const char *as, | ||
109 | unsigned long long *pin); | ||
110 | |||
111 | |||
112 | /** | ||
113 | * Convert numeric pin to human-readable number for display. | ||
114 | * | ||
115 | * @param pin number to convert | ||
116 | * @return static (!) buffer with the text to show | ||
117 | */ | ||
118 | const char * | ||
119 | ANASTASIS_pin2s (uint64_t pin); | ||
120 | |||
121 | |||
89 | #endif | 122 | #endif |
diff --git a/src/lib/anastasis_recovery.c b/src/lib/anastasis_recovery.c index 528bbd1..b85b0f6 100644 --- a/src/lib/anastasis_recovery.c +++ b/src/lib/anastasis_recovery.c | |||
@@ -1033,6 +1033,8 @@ ANASTASIS_recovery_serialize (const struct ANASTASIS_Recovery *r) | |||
1033 | cs = GNUNET_JSON_PACK ( | 1033 | cs = GNUNET_JSON_PACK ( |
1034 | GNUNET_JSON_pack_data_auto ("uuid", | 1034 | GNUNET_JSON_pack_data_auto ("uuid", |
1035 | &c->ci.uuid), | 1035 | &c->ci.uuid), |
1036 | GNUNET_JSON_pack_string ("uuid-display", | ||
1037 | ANASTASIS_CRYPTO_uuid2s (&c->ci.uuid)), | ||
1036 | GNUNET_JSON_pack_data_auto ("truth_key", | 1038 | GNUNET_JSON_pack_data_auto ("truth_key", |
1037 | &c->truth_key), | 1039 | &c->truth_key), |
1038 | GNUNET_JSON_pack_data_auto ("salt", | 1040 | GNUNET_JSON_pack_data_auto ("salt", |
diff --git a/src/stasis/plugin_anastasis_postgres.c b/src/stasis/plugin_anastasis_postgres.c index 813da94..6bb7f32 100644 --- a/src/stasis/plugin_anastasis_postgres.c +++ b/src/stasis/plugin_anastasis_postgres.c | |||
@@ -38,12 +38,6 @@ | |||
38 | */ | 38 | */ |
39 | #define MAX_RETRIES 3 | 39 | #define MAX_RETRIES 3 |
40 | 40 | ||
41 | /** | ||
42 | * Maximum value allowed for nonces. Limited to 2^52 to ensure the | ||
43 | * numeric value survives a conversion to float by JavaScript. | ||
44 | */ | ||
45 | #define NONCE_MAX_VALUE (1LLU << 52) | ||
46 | |||
47 | 41 | ||
48 | /** | 42 | /** |
49 | * Type of the "cls" argument given to each of the functions in | 43 | * Type of the "cls" argument given to each of the functions in |
@@ -2629,7 +2623,7 @@ postgres_create_challenge_code ( | |||
2629 | } | 2623 | } |
2630 | 2624 | ||
2631 | *code = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE, | 2625 | *code = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE, |
2632 | NONCE_MAX_VALUE); | 2626 | ANASTASIS_PIN_MAX_VALUE); |
2633 | *retransmission_date = GNUNET_TIME_UNIT_ZERO_TS; | 2627 | *retransmission_date = GNUNET_TIME_UNIT_ZERO_TS; |
2634 | { | 2628 | { |
2635 | struct GNUNET_PQ_QueryParam params[] = { | 2629 | struct GNUNET_PQ_QueryParam params[] = { |
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 22c7a1c..4e64c0e 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -34,7 +34,8 @@ lib_LTLIBRARIES = \ | |||
34 | 34 | ||
35 | libanastasisutil_la_SOURCES = \ | 35 | libanastasisutil_la_SOURCES = \ |
36 | anastasis_crypto.c \ | 36 | anastasis_crypto.c \ |
37 | os_installation.c | 37 | os_installation.c \ |
38 | pin.c | ||
38 | libanastasisutil_la_LIBADD = \ | 39 | libanastasisutil_la_LIBADD = \ |
39 | -lgnunetutil \ | 40 | -lgnunetutil \ |
40 | $(LIBGCRYPT_LIBS) \ | 41 | $(LIBGCRYPT_LIBS) \ |
diff --git a/src/util/pin.c b/src/util/pin.c new file mode 100644 index 0000000..0285bb0 --- /dev/null +++ b/src/util/pin.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /* | ||
2 | This file is part of GNU Anastasis. | ||
3 | Copyright (C) 2021 Anastasis SARL | ||
4 | |||
5 | Anastasis is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | Anastasis is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with Anastasis; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file anastasis/src/util/pin.c | ||
23 | * @brief pin conversion functions | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "anastasis_util_lib.h" | ||
28 | |||
29 | |||
30 | bool | ||
31 | ANASTASIS_scan_pin (const char *as, | ||
32 | unsigned long long *pin) | ||
33 | { | ||
34 | char dummy; | ||
35 | char s[16]; | ||
36 | |||
37 | if ( (NULL != as) && | ||
38 | (0 == strncasecmp ("A-", as, 2)) ) | ||
39 | as += 2; /* skip "A-" prefix if present */ | ||
40 | if (strlen (as) != 18) | ||
41 | return false; | ||
42 | if ( ('-' != as[5]) || | ||
43 | ('-' != as[9]) || | ||
44 | ('-' != as[14]) ) | ||
45 | return false; | ||
46 | GNUNET_snprintf (s, | ||
47 | sizeof (s), | ||
48 | "%.5s%.3s%.4s%.3s", | ||
49 | as, | ||
50 | &as[6], | ||
51 | &as[10], | ||
52 | &as[15]); | ||
53 | if (1 != sscanf (s, | ||
54 | "%llu%c", | ||
55 | pin, | ||
56 | &dummy)) | ||
57 | { | ||
58 | GNUNET_break (0); | ||
59 | return false; | ||
60 | } | ||
61 | return true; | ||
62 | } | ||
63 | |||
64 | |||
65 | const char * | ||
66 | ANASTASIS_pin2s (uint64_t pin) | ||
67 | { | ||
68 | static char buf[22]; | ||
69 | char tmp[16]; | ||
70 | |||
71 | GNUNET_assert (pin < ANASTASIS_PIN_MAX_VALUE); | ||
72 | GNUNET_snprintf (tmp, | ||
73 | sizeof (tmp), | ||
74 | "%015llu", | ||
75 | (unsigned long long) pin); | ||
76 | GNUNET_snprintf (buf, | ||
77 | sizeof (buf), | ||
78 | "A-%.5s-%.3s-%.4s-%.3s", | ||
79 | tmp, | ||
80 | &tmp[5], | ||
81 | &tmp[8], | ||
82 | &tmp[12]); | ||
83 | return buf; | ||
84 | } | ||