anastasis.h (37069B)
1 /* 2 This file is part of Anastasis 3 Copyright (C) 2020, 2021 Anastasis SARL 4 5 Anastasis is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 Anastasis; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file include/anastasis.h 18 * @brief anastasis high-level client api 19 * @author Christian Grothoff 20 * @author Dominik Meister 21 * @author Dennis Neufeld 22 */ 23 #ifndef ANASTASIS_H 24 #define ANASTASIS_H 25 26 #include "anastasis_service.h" 27 #include <taler/taler_json_lib.h> 28 #include <gnunet/gnunet_util_lib.h> 29 #include <stdbool.h> 30 31 32 /* ********************* Recovery api *********************** */ 33 34 /** 35 * Defines the instructions for a challenge, what does the user have 36 * to do to fulfill the challenge. Also defines the method and other 37 * information for the challenge like a link for the video indent or a 38 * information to which address an e-mail was sent. 39 */ 40 struct ANASTASIS_Challenge; 41 42 43 /** 44 * Defines the instructions for a challenge, what does the user have 45 * to do to fulfill the challenge. Also defines the method and other 46 * information for the challenge like a link for the video indent or a 47 * information to which address an e-mail was sent. 48 */ 49 struct ANASTASIS_ChallengeDetails 50 { 51 52 /** 53 * UUID which identifies this challenge 54 */ 55 struct ANASTASIS_CRYPTO_TruthUUIDP uuid; 56 57 /** 58 * Which type is this challenge (E-Mail, Security Question, SMS...) 59 */ 60 const char *type; 61 62 /** 63 * Defines the base URL of the Anastasis provider used for the challenge. 64 */ 65 const char *provider_url; 66 67 /** 68 * Instructions for solving the challenge (generic, set client-side 69 * when challenge was established). 70 */ 71 const char *instructions; 72 73 /** 74 * true if challenge was already solved, else false. 75 */ 76 bool solved; 77 78 /** 79 * true if challenge is awaiting asynchronous 80 * resolution by the user. 81 */ 82 bool async; 83 84 /** 85 * true if @e answer_pin is set. 86 */ 87 bool have_answer_pin; 88 89 /** 90 * Answer code the user must eventually confirm for an asynchronous 91 * challenge; only valid if @e have_answer_pin. Persisted across 92 * serialization so that a suspended recovery can resume polling. 93 */ 94 uint64_t answer_pin; 95 96 }; 97 98 99 /** 100 * Return public details about a challenge. 101 * 102 * @param challenge the challenge to inspect 103 * @return public details about the challenge 104 */ 105 const struct ANASTASIS_ChallengeDetails * 106 ANASTASIS_challenge_get_details (struct ANASTASIS_Challenge *challenge); 107 108 109 /** 110 * Mark @a challenge as awaiting asynchronous resolution by the user, 111 * remembering the @a answer_pin the user must eventually confirm. 112 * 113 * Both values are part of the serialized form of the recovery 114 * operation, so they survive suspending and resuming a recovery. 115 * 116 * @param[in,out] challenge the challenge to mark 117 * @param answer_pin answer code to remember 118 */ 119 void 120 ANASTASIS_challenge_set_async (struct ANASTASIS_Challenge *challenge, 121 uint64_t answer_pin); 122 123 124 /** 125 * Remember the @a answer_pin the user supplied for @a challenge without 126 * declaring the challenge asynchronous. Used when an answer was given 127 * up front, so that it is still around if the provider later turns the 128 * challenge into an asynchronous one. 129 * 130 * @param[in,out] challenge the challenge to update 131 * @param answer_pin answer code to remember 132 */ 133 void 134 ANASTASIS_challenge_set_answer_pin (struct ANASTASIS_Challenge *challenge, 135 uint64_t answer_pin); 136 137 138 /** 139 * Possible outcomes of trying to start a challenge operation. 140 */ 141 enum ANASTASIS_ChallengeStartStatus 142 { 143 144 /** 145 * We encountered an error talking to the Anastasis service. 146 */ 147 ANASTASIS_CHALLENGE_START_STATUS_SERVER_FAILURE, 148 149 /** 150 * Payment is required before the challenge can be answered. 151 */ 152 ANASTASIS_CHALLENGE_START_STATUS_PAYMENT_REQUIRED, 153 154 /** 155 * The server does not know this truth. 156 */ 157 ANASTASIS_CHALLENGE_START_STATUS_TRUTH_UNKNOWN, 158 159 /** 160 * A filename with the TAN has been provided. 161 */ 162 ANASTASIS_CHALLENGE_START_STATUS_FILENAME_PROVIDED, 163 164 /** 165 * A TAN has been send, address hint is provided. 166 */ 167 ANASTASIS_CHALLENGE_START_STATUS_TAN_SENT_HINT_PROVIDED, 168 169 /** 170 * A TAN has been sent before. 171 */ 172 ANASTASIS_CHALLENGE_START_STATUS_TAN_ALREADY_SENT, 173 174 /** 175 * Wire transfer required, banking details provided. 176 */ 177 ANASTASIS_CHALLENGE_START_STATUS_BANK_TRANSFER_REQUIRED 178 179 }; 180 181 182 /** 183 * Response from an #ANASTASIS_challenge_start() operation. 184 */ 185 struct ANASTASIS_ChallengeStartResponse 186 { 187 188 /** 189 * HTTP status returned by the server. 190 */ 191 unsigned int http_status; 192 193 /** 194 * Taler-specific error code. 195 */ 196 enum TALER_ErrorCode ec; 197 198 /** 199 * What is our status on satisfying this challenge. Determines @e details. 200 */ 201 enum ANASTASIS_ChallengeStartStatus cs; 202 203 /** 204 * Which challenge is this about? 205 */ 206 struct ANASTASIS_Challenge *challenge; 207 208 /** 209 * Details depending on @e cs 210 */ 211 union 212 { 213 214 /** 215 * Challenge details provided if 216 * @e cs is #ANASTASIS_CHALLENGE_START_STATUS_FILENAME_PROVIDED. 217 */ 218 const char *tan_filename; 219 220 /** 221 * Challenge details provided if 222 * @e cs is #ANASTASIS_CHALLENGE_START_STATUS_TAN_SENT_HINT_PROVIDED. 223 */ 224 const char *tan_address_hint; 225 226 /** 227 * Challenge details provided if 228 * @e cs is #ANASTASIS_CHALLENGE_START_STATUS_BANK_TRANSFER_REQUIRED. 229 */ 230 struct ANASTASIS_WireFundsDetails bank_transfer_required; 231 232 /** 233 * Response with instructions for how to pay, if 234 * @e cs is #ANASTASIS_CHALLENGE_START_STATUS_PAYMENT_REQUIRED. 235 */ 236 struct 237 { 238 239 /** 240 * "taler://pay" URI with details how to pay for the challenge. 241 */ 242 const char *taler_pay_uri; 243 244 /** 245 * Payment secret from @e taler_pay_uri. 246 */ 247 struct ANASTASIS_PaymentSecretP payment_secret; 248 249 } payment_required; 250 251 } details; 252 }; 253 254 255 /** 256 * Defines a callback for the response status for a challenge start 257 * operation. 258 * 259 * @param cls closure 260 * @param csr response details 261 */ 262 typedef void 263 (*ANASTASIS_ChallengeStartFeedback)( 264 void *cls, 265 const struct ANASTASIS_ChallengeStartResponse *csr); 266 267 268 /** 269 * User starts a challenge which reponds out of bounds (E-Mail, SMS, 270 * Postal..) If the challenge is zero cost, the challenge 271 * instructions will be sent to the client. If the challenge needs 272 * payment a payment link is sent to the client. After payment the 273 * challenge start method has to be called again. 274 * 275 * @param c reference to the escrow challenge which is started 276 * @param psp payment secret, NULL if no payment was yet made 277 * @param af reference to the answerfeedback which is passed back to the user 278 * @param af_cls closure for @a af 279 * @return #GNUNET_OK if the challenge was successfully started 280 */ 281 enum GNUNET_GenericReturnValue 282 ANASTASIS_challenge_start (struct ANASTASIS_Challenge *c, 283 const struct ANASTASIS_PaymentSecretP *psp, 284 ANASTASIS_ChallengeStartFeedback af, 285 void *af_cls); 286 287 288 /** 289 * Possible outcomes of trying to start a challenge operation. 290 */ 291 enum ANASTASIS_ChallengeAnswerStatus 292 { 293 294 /** 295 * The challenge has been solved. 296 */ 297 ANASTASIS_CHALLENGE_ANSWER_STATUS_SOLVED, 298 299 /** 300 * Payment is required before the challenge can be answered. 301 */ 302 ANASTASIS_CHALLENGE_ANSWER_STATUS_PAYMENT_REQUIRED, 303 304 /** 305 * We encountered an error talking to the Anastasis service. 306 */ 307 ANASTASIS_CHALLENGE_ANSWER_STATUS_SERVER_FAILURE, 308 309 /** 310 * The server does not know this truth. 311 */ 312 ANASTASIS_CHALLENGE_ANSWER_STATUS_TRUTH_UNKNOWN, 313 314 /** 315 * The answer was wrong. 316 */ 317 ANASTASIS_CHALLENGE_ANSWER_STATUS_INVALID_ANSWER, 318 319 /** 320 * The rate limit for solving the challenge was exceeded. 321 */ 322 ANASTASIS_CHALLENGE_ANSWER_STATUS_RATE_LIMIT_EXCEEDED 323 324 }; 325 326 327 /** 328 * Response from an #ANASTASIS_challenge_start() operation. 329 */ 330 struct ANASTASIS_ChallengeAnswerResponse 331 { 332 333 /** 334 * HTTP status returned by the server. 335 */ 336 unsigned int http_status; 337 338 /** 339 * Taler-specific error code. 340 */ 341 enum TALER_ErrorCode ec; 342 343 /** 344 * What is our status on satisfying this challenge. Determines @e details. 345 */ 346 enum ANASTASIS_ChallengeAnswerStatus cs; 347 348 /** 349 * Which challenge is this about? 350 */ 351 struct ANASTASIS_Challenge *challenge; 352 353 /** 354 * Details depending on @e cs 355 */ 356 union 357 { 358 359 /** 360 * Details for #ANASTASIS_CHALLENGE_ANSWER_STATUS_RATE_LIMIT_EXCEEDED. 361 */ 362 struct 363 { 364 365 /** 366 * How many requests are allowed at most per @e request_frequency? 367 */ 368 uint32_t request_limit; 369 370 /** 371 * Frequency at which requests are allowed / new challenges are 372 * created. 373 */ 374 struct GNUNET_TIME_Relative request_frequency; 375 376 } rate_limit_exceeded; 377 378 /** 379 * Response with instructions for how to pay, if 380 * @e cs is #ANASTASIS_CHALLENGE_ANSWER_STATUS_PAYMENT_REQUIRED. 381 */ 382 struct 383 { 384 385 /** 386 * "taler://pay" URI with details how to pay for the challenge. 387 */ 388 const char *taler_pay_uri; 389 390 /** 391 * Payment secret from @e taler_pay_uri. 392 */ 393 struct ANASTASIS_PaymentSecretP payment_secret; 394 395 } payment_required; 396 397 } details; 398 }; 399 400 401 /** 402 * Defines a callback for the response status for a challenge start 403 * operation. 404 * 405 * @param cls closure 406 * @param car response details 407 */ 408 typedef void 409 (*ANASTASIS_AnswerFeedback)( 410 void *cls, 411 const struct ANASTASIS_ChallengeAnswerResponse *car); 412 413 414 /** 415 * Challenge answer for a security question. Is referenced to 416 * a challenge and sends back an AnswerFeedback. Convenience 417 * wrapper around #ANASTASIS_challenge_start that hashes @a answer 418 * for security questions. 419 * 420 * @param c reference to the challenge which is answered 421 * @param psp information about payment made for the recovery 422 * @param timeout how long to wait for payment 423 * @param answer user input instruction defines which input is needed 424 * @param csf function to call with the result 425 * @param csf_cls closure for @a csf 426 * @return #GNUNET_OK on success 427 */ 428 enum GNUNET_GenericReturnValue 429 ANASTASIS_challenge_answer (struct ANASTASIS_Challenge *c, 430 const struct ANASTASIS_PaymentSecretP *psp, 431 struct GNUNET_TIME_Relative timeout, 432 const char *answer, 433 ANASTASIS_AnswerFeedback csf, 434 void *csf_cls); 435 436 437 /** 438 * Challenge answer from the user like input SMS TAN or e-mail wpin. Is 439 * referenced to a challenge and sends back an AnswerFeedback. 440 * Convenience wrapper around #ANASTASIS_challenge_start that hashes 441 * numeric (unsalted) @a answer. Variant for numeric answers. 442 * 443 * @param c reference to the challenge which is answered 444 * @param psp information about payment made for the recovery 445 * @param timeout how long to wait for payment 446 * @param answer user input instruction defines which input is needed 447 * @param af reference to the answerfeedback which is passed back to the user 448 * @param af_cls closure for @a af 449 * @return #GNUNET_OK on success 450 */ 451 enum GNUNET_GenericReturnValue 452 ANASTASIS_challenge_answer2 (struct ANASTASIS_Challenge *c, 453 const struct ANASTASIS_PaymentSecretP *psp, 454 struct GNUNET_TIME_Relative timeout, 455 uint64_t answer, 456 ANASTASIS_AnswerFeedback af, 457 void *af_cls); 458 459 460 /** 461 * User starts a challenge which reponds out of bounds (E-Mail, SMS, 462 * Postal..) If the challenge is zero cost, the challenge 463 * instructions will be sent to the client. If the challenge needs 464 * payment a payment link is sent to the client. After payment the 465 * challenge start method has to be called again. 466 * 467 * @param c reference to the escrow challenge which is started 468 * @param psp payment secret, NULL if no payment was yet made 469 * @param timeout how long to wait for payment 470 * @param hashed_answer answer to the challenge 471 * @param af reference to the answerfeedback which is passed back to the user 472 * @param af_cls closure for @a af 473 * @return #GNUNET_OK if the challenge was successfully started 474 */ 475 enum GNUNET_GenericReturnValue 476 ANASTASIS_challenge_answer3 (struct ANASTASIS_Challenge *c, 477 const struct ANASTASIS_PaymentSecretP *psp, 478 struct GNUNET_TIME_Relative timeout, 479 const struct GNUNET_HashCode *hashed_answer, 480 ANASTASIS_AnswerFeedback af, 481 void *af_cls); 482 483 484 /** 485 * Abort answering challenge. 486 * 487 * @param c reference to the escrow challenge which was started 488 */ 489 void 490 ANASTASIS_challenge_abort (struct ANASTASIS_Challenge *c); 491 492 493 /** 494 * Handle for an operation to get available recovery 495 * document versions. 496 */ 497 struct ANASTASIS_VersionCheck; 498 499 500 /** 501 * Callback which passes back meta data about one of the 502 * recovery documents available at the provider. 503 * 504 * @param cls closure for the callback 505 * @param version version number of the policy document, 506 * 0 for the end of the list 507 * @param server_time time of the backup at the provider 508 * @param recdoc_id hash of the compressed recovery document, uniquely 509 * identifies the document; NULL for the end of the list 510 * @param secret_name name of the secret as chosen by the user, 511 * or NULL if the user did not provide a name 512 */ 513 #ifndef ANASTASIS_META_POLICY_RESULT_CLOSURE 514 /** 515 * Type of the closure for #ANASTASIS_MetaPolicyCallback. 516 */ 517 #define ANASTASIS_META_POLICY_RESULT_CLOSURE void 518 #endif 519 typedef void 520 (*ANASTASIS_MetaPolicyCallback)(ANASTASIS_META_POLICY_RESULT_CLOSURE *cls, 521 uint32_t version, 522 struct GNUNET_TIME_Timestamp server_time, 523 const struct GNUNET_HashCode *recdoc_id, 524 const char *secret_name); 525 526 527 /** 528 * Obtain an overview of available recovery policies from the 529 * specified provider. 530 * 531 * @param ctx context for making HTTP requests 532 * @param id_data contains the users identity, (user account on providers) 533 * @param version defines the version which will be downloaded, 0 for latest version 534 * @param anastasis_provider_url provider url 535 * @param provider_salt the server salt 536 * @param mpc function called with the available versions 537 * @param mpc_cls closure for @a mpc callback 538 * @return recovery operation handle 539 */ 540 struct ANASTASIS_VersionCheck * 541 ANASTASIS_recovery_get_versions ( 542 struct GNUNET_CURL_Context *ctx, 543 const json_t *id_data, 544 unsigned int max_version, 545 const char *anastasis_provider_url, 546 const struct ANASTASIS_CRYPTO_ProviderSaltP *provider_salt, 547 ANASTASIS_MetaPolicyCallback mpc, 548 ANASTASIS_META_POLICY_RESULT_CLOSURE *mpc_cls); 549 550 551 /** 552 * Cancel version check operation. 553 * 554 * @param vc operation to cancel 555 */ 556 void 557 ANASTASIS_recovery_get_versions_cancel (struct ANASTASIS_VersionCheck *vc); 558 559 560 /** 561 * Defines a Decryption Policy with multiple escrow methods 562 */ 563 struct ANASTASIS_DecryptionPolicy 564 { 565 /** 566 * Array of challenges needed to solve for this decryption policy. 567 */ 568 struct ANASTASIS_Challenge **challenges; 569 570 /** 571 * Length of the @a challenges in this policy. 572 */ 573 unsigned int challenges_length; 574 575 }; 576 577 578 /** 579 * Defines the recovery information (possible policies and version of the recovery document) 580 */ 581 struct ANASTASIS_RecoveryInformation 582 { 583 584 /** 585 * Array of @e dps_len policies that would allow recovery of the core secret. 586 */ 587 struct ANASTASIS_DecryptionPolicy **dps; 588 589 /** 590 * Array of all @e cs_len challenges to be solved (for any of the policies). 591 */ 592 struct ANASTASIS_Challenge **cs; 593 594 /** 595 * Name of the secret being recovered, possibly NULL. 596 */ 597 const char *secret_name; 598 599 /** 600 * Length of the @e dps array. 601 */ 602 unsigned int dps_len; 603 604 /** 605 * Length of the @e cs array. 606 */ 607 unsigned int cs_len; 608 609 /** 610 * Actual recovery document version obtained. 611 */ 612 unsigned int version; 613 }; 614 615 616 /** 617 * Callback which passes back the recovery document and its possible 618 * policies. Also passes back the version of the document for the user 619 * to check. 620 * 621 * @param cls closure for the callback 622 * @param ri recovery information struct which contains the policies 623 */ 624 #ifndef ANASTASIS_POLICY_RESULT_CLOSURE 625 /** 626 * Type of the closure for #ANASTASIS_PolicyCallback. 627 */ 628 #define ANASTASIS_POLICY_RESULT_CLOSURE void 629 #endif 630 typedef void 631 (*ANASTASIS_PolicyCallback)(ANASTASIS_POLICY_RESULT_CLOSURE *cls, 632 const struct ANASTASIS_RecoveryInformation *ri); 633 634 635 /** 636 * Possible outcomes of a recovery process. 637 */ 638 enum ANASTASIS_RecoveryStatus 639 { 640 641 /** 642 * Recovery succeeded. 643 */ 644 ANASTASIS_RS_SUCCESS = 0, 645 646 /** 647 * The HTTP download of the policy failed. 648 */ 649 ANASTASIS_RS_POLICY_DOWNLOAD_FAILED, 650 651 /** 652 * We did not get a valid policy document. 653 */ 654 ANASTASIS_RS_POLICY_DOWNLOAD_NO_POLICY, 655 656 /** 657 * The decompressed policy document was too big for available memory. 658 */ 659 ANASTASIS_RS_POLICY_DOWNLOAD_TOO_BIG, 660 661 /** 662 * The decrypted policy document was not compressed. 663 */ 664 ANASTASIS_RS_POLICY_DOWNLOAD_INVALID_COMPRESSION, 665 666 /** 667 * The decompressed policy document was not in JSON. 668 */ 669 ANASTASIS_RS_POLICY_DOWNLOAD_NO_JSON, 670 671 /** 672 * The decompressed policy document was in malformed JSON. 673 */ 674 ANASTASIS_RS_POLICY_MALFORMED_JSON, 675 676 /** 677 * The Anastasis server reported a transient error. 678 */ 679 ANASTASIS_RS_POLICY_SERVER_ERROR, 680 681 /** 682 * The Anastasis server no longer has a policy (likely expired). 683 */ 684 ANASTASIS_RS_POLICY_GONE, 685 686 /** 687 * The Anastasis server reported that the account is unknown. 688 */ 689 ANASTASIS_RS_POLICY_UNKNOWN, 690 691 /** 692 * The recovery document could not be decrypted with the key derived 693 * from the identity attributes. 694 */ 695 ANASTASIS_RS_POLICY_DECRYPTION_FAILED, 696 697 /** 698 * The core secret could not be reassembled from the key shares we 699 * obtained; at least one of them must have been wrong. 700 */ 701 ANASTASIS_RS_CORE_SECRET_RECOVERY_FAILED 702 }; 703 704 705 /** 706 * This function is called whenever the recovery process ends. 707 * On success, the secret is returned in @a secret. 708 * 709 * @param cls closure 710 * @param ec error code 711 * @param secret contains the core secret which is passed to the user 712 * @param secret_size defines the size of the core secret 713 */ 714 #ifndef ANASTASIS_CORE_SECRET_RESULT_CLOSURE 715 /** 716 * Type of the closure for #ANASTASIS_CoreSecretCallback. 717 */ 718 #define ANASTASIS_CORE_SECRET_RESULT_CLOSURE void 719 #endif 720 typedef void 721 (*ANASTASIS_CoreSecretCallback)(ANASTASIS_CORE_SECRET_RESULT_CLOSURE *cls, 722 enum ANASTASIS_RecoveryStatus rc, 723 const void *secret, 724 size_t secret_size); 725 726 727 /** 728 * stores provider URIs, identity key material, decrypted recovery document (internally!) 729 */ 730 struct ANASTASIS_Recovery; 731 732 733 /** 734 * Starts the recovery process by opening callbacks for the coresecret and a policy callback. A list of 735 * providers is checked for policies and passed back to the client. 736 * 737 * @param ctx context for making HTTP requests 738 * @param id_data contains the users identity, (user account on providers) 739 * @param version defines the version which will be downloaded, 0 for latest version 740 * @param anastasis_provider_url provider REST API endpoint url 741 * @param provider_salt the provider's salt 742 * @param pc opens the policy call back which holds the downloaded version and the policies 743 * @param pc_cls closure for callback 744 * @param csc core secret callback is opened, with this the core secert is passed to the client after the authentication 745 * @param csc_cls handle for the callback 746 * @return recovery operation handle 747 */ 748 struct ANASTASIS_Recovery * 749 ANASTASIS_recovery_begin ( 750 struct GNUNET_CURL_Context *ctx, 751 const json_t *id_data, 752 unsigned int version, 753 const char *anastasis_provider_url, 754 const struct ANASTASIS_CRYPTO_ProviderSaltP *provider_salt, 755 ANASTASIS_PolicyCallback pc, 756 ANASTASIS_POLICY_RESULT_CLOSURE *pc_cls, 757 ANASTASIS_CoreSecretCallback csc, 758 ANASTASIS_CORE_SECRET_RESULT_CLOSURE *csc_cls); 759 760 761 /** 762 * Serialize recovery operation state and returning it. 763 * The recovery MAY still continue, applications should call 764 * #ANASTASIS_recovery_abort() to truly end the recovery. 765 * 766 * @param r recovery operation to suspend. 767 * @return JSON serialized state of @a r 768 */ 769 json_t * 770 ANASTASIS_recovery_serialize (const struct ANASTASIS_Recovery *r); 771 772 773 /** 774 * Deserialize recovery operation. 775 * 776 * The returned handle is inert: no callbacks are installed and no 777 * network activity is started. Call #ANASTASIS_recovery_resume() to 778 * continue the recovery, or simply #ANASTASIS_recovery_serialize() it 779 * again and #ANASTASIS_recovery_abort() it if all you needed was to 780 * inspect it. 781 * 782 * @param ctx context for making HTTP requests 783 * @param input result from #ANASTASIS_recovery_serialize() 784 * @return recovery operation handle, NULL if @a input is malformed 785 */ 786 struct ANASTASIS_Recovery * 787 ANASTASIS_recovery_deserialize (struct GNUNET_CURL_Context *ctx, 788 const json_t *input); 789 790 791 /** 792 * Resume a recovery operation obtained from 793 * #ANASTASIS_recovery_deserialize(): install the callbacks and start 794 * the policy lookup (or, if the policies are already known, arrange 795 * for @a pc to be called from the scheduler). 796 * 797 * May be called at most once per handle. 798 * 799 * @param[in,out] r recovery operation to resume 800 * @param pc opens the policy call back which holds the downloaded version and the policies 801 * @param pc_cls closure for callback 802 * @param csc core secret callback is opened, with this the core secert is passed to the client after the authentication 803 * @param csc_cls handle for the callback 804 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the lookup could 805 * not be started 806 */ 807 enum GNUNET_GenericReturnValue 808 ANASTASIS_recovery_resume (struct ANASTASIS_Recovery *r, 809 ANASTASIS_PolicyCallback pc, 810 ANASTASIS_POLICY_RESULT_CLOSURE *pc_cls, 811 ANASTASIS_CoreSecretCallback csc, 812 ANASTASIS_CORE_SECRET_RESULT_CLOSURE *csc_cls); 813 814 815 /** 816 * Obtain the recovery information (policies and challenges) known for 817 * @a r. Valid until @a r is aborted. 818 * 819 * @param r recovery operation to inspect 820 * @return recovery information, never NULL 821 */ 822 const struct ANASTASIS_RecoveryInformation * 823 ANASTASIS_recovery_get_info (const struct ANASTASIS_Recovery *r); 824 825 826 /** 827 * Find the challenge with the given @a uuid in @a r. 828 * 829 * @param r recovery operation to search 830 * @param uuid UUID of the challenge to find 831 * @return NULL if @a r has no such challenge 832 */ 833 struct ANASTASIS_Challenge * 834 ANASTASIS_recovery_get_challenge ( 835 const struct ANASTASIS_Recovery *r, 836 const struct ANASTASIS_CRYPTO_TruthUUIDP *uuid); 837 838 839 /** 840 * Cancels the recovery process 841 * 842 * @param r handle to the recovery struct 843 */ 844 void 845 ANASTASIS_recovery_abort (struct ANASTASIS_Recovery *r); 846 847 848 /* ************************* Backup API ***************************** */ 849 850 851 /** 852 * Represents a truth object, which is a key share and the respective 853 * challenge to be solved with an Anastasis provider to recover the 854 * key share. 855 */ 856 struct ANASTASIS_Truth; 857 858 859 /** 860 * Extracts truth data from JSON. 861 * 862 * @param json JSON encoding to decode; truth returned ONLY valid as long 863 * as the JSON remains valid (do not decref until the truth 864 * is truly finished) 865 * @return decoded truth object, NULL on error 866 */ 867 struct ANASTASIS_Truth * 868 ANASTASIS_truth_from_json (const json_t *json); 869 870 871 /** 872 * Returns JSON-encoded truth data. 873 * Creates a policy with a set of truth's. Creates the policy key 874 * with the different key shares from the @a truths. The policy key 875 * will then be used to encrypt/decrypt the escrow master key. 876 * 877 * @param t object to return JSON encoding for 878 * @return JSON encoding of @a t 879 */ 880 json_t * 881 ANASTASIS_truth_to_json (const struct ANASTASIS_Truth *t); 882 883 884 /** 885 * Handle for the operation to establish a truth object by sharing 886 * an encrypted key share with an Anastasis provider. 887 */ 888 struct ANASTASIS_TruthUpload; 889 890 891 /** 892 * Upload result information. The resulting truth object can be used 893 * to create policies. If payment is required, the @a taler_pay_url 894 * is returned and the operation must be retried after payment. 895 * Callee MUST free @a t using ANASTASIS_truth_free(). 896 * 897 * @param cls closure for callback 898 * @param t truth object to create policies, NULL on failure 899 * @param ud upload details, useful to continue in case of errors, NULL on success 900 */ 901 #ifndef ANASTASIS_TRUTH_RESULT_CLOSURE 902 /** 903 * Type of the closure for #ANASTASIS_TruthCallback. 904 */ 905 #define ANASTASIS_TRUTH_RESULT_CLOSURE void 906 #endif 907 typedef void 908 (*ANASTASIS_TruthCallback)(ANASTASIS_TRUTH_RESULT_CLOSURE *cls, 909 struct ANASTASIS_Truth *t, 910 const struct ANASTASIS_UploadDetails *ud); 911 912 913 /** 914 * Uploads truth data to an escrow provider. The resulting truth object 915 * is returned via the @a tc function. If payment is required, it is 916 * requested via the @a tcp callback. 917 * 918 * @param ctx the CURL context used to connect to the backend 919 * @param user_id user identifier derived from user data and backend salt 920 * @param provider_url base URL of the provider to upload to 921 * @param type defines the type of the challenge (secure question, sms, email) 922 * @param instructions depending on @a type! usually only for security question/answer! 923 * @param mime_type format of the challenge 924 * @param provider_salt the providers salt 925 * @param truth_data contains the truth for this challenge i.e. phone number, email address 926 * @param truth_data_size size of the @a truth_data 927 * @param payment_years_requested for how many years would the client like the service to store the truth? 928 * @param pay_timeout how long to wait for payment 929 * @param tc opens the truth callback which contains the status of the upload 930 * @param tc_cls closure for the @a tc callback 931 */ 932 struct ANASTASIS_TruthUpload * 933 ANASTASIS_truth_upload ( 934 struct GNUNET_CURL_Context *ctx, 935 const struct ANASTASIS_CRYPTO_UserIdentifierP *user_id, 936 const char *provider_url, 937 const char *type, 938 const char *instructions, 939 const char *mime_type, 940 const struct ANASTASIS_CRYPTO_ProviderSaltP *provider_salt, 941 const void *truth_data, 942 size_t truth_data_size, 943 uint32_t payment_years_requested, 944 struct GNUNET_TIME_Relative pay_timeout, 945 ANASTASIS_TruthCallback tc, 946 ANASTASIS_TRUTH_RESULT_CLOSURE *tc_cls); 947 948 949 /** 950 * Retries upload of truth data to an escrow provider. The resulting 951 * truth object is returned via the @a tc function. If payment is 952 * required, it is requested via the @a tcp callback. 953 * 954 * @param ctx the CURL context used to connect to the backend 955 * @param user_id user identifier derived from user data and backend salt 956 * @param provider_url base URL of the provider to upload to 957 * @param type defines the type of the challenge (secure question, sms, email) 958 * @param instructions depending on @a type! usually only for security question/answer! 959 * @param mime_type format of the challenge 960 * @param provider_salt the providers salt 961 * @param truth_data contains the truth for this challenge i.e. phone number, email address 962 * @param truth_data_size size of the @a truth_data 963 * @param payment_years_requested for how many years would the client like the service to store the truth? 964 * @param pay_timeout how long to wait for payment 965 * @param nonce nonce to use for symmetric encryption 966 * @param uuid truth UUID to use 967 * @param salt salt to use to hash security questions 968 * @param truth_key symmetric encryption key to use to encrypt @a truth_data 969 * @param key_share share of the overall key to store in this truth object 970 * @param tc opens the truth callback which contains the status of the upload 971 * @param tc_cls closure for the @a tc callback 972 */ 973 struct ANASTASIS_TruthUpload * 974 ANASTASIS_truth_upload2 ( 975 struct GNUNET_CURL_Context *ctx, 976 const struct ANASTASIS_CRYPTO_UserIdentifierP *user_id, 977 const char *provider_url, 978 const char *type, 979 const char *instructions, 980 const char *mime_type, 981 const struct ANASTASIS_CRYPTO_ProviderSaltP *provider_salt, 982 const void *truth_data, 983 size_t truth_data_size, 984 uint32_t payment_years_requested, 985 struct GNUNET_TIME_Relative pay_timeout, 986 const struct ANASTASIS_CRYPTO_NonceP *nonce, 987 const struct ANASTASIS_CRYPTO_TruthUUIDP *uuid, 988 const struct ANASTASIS_CRYPTO_QuestionSaltP *salt, 989 const struct ANASTASIS_CRYPTO_TruthKeyP *truth_key, 990 const struct ANASTASIS_CRYPTO_KeyShareP *key_share, 991 ANASTASIS_TruthCallback tc, 992 ANASTASIS_TRUTH_RESULT_CLOSURE *tc_cls); 993 994 995 /** 996 * Retries upload of truth data to an escrow provider using an 997 * existing truth object. If payment is required, it is requested via 998 * the @a tc callback. 999 * 1000 * @param ctx the CURL context used to connect to the backend 1001 * @param user_id user identifier derived from user data and backend salt 1002 * @param[in] t truth details, reference is consumed 1003 * @param truth_data contains the truth for this challenge i.e. phone number, email address 1004 * @param truth_data_size size of the @a truth_data 1005 * @param payment_years_requested for how many years would the client like the service to store the truth? 1006 * @param pay_timeout how long to wait for payment 1007 * @param tc opens the truth callback which contains the status of the upload 1008 * @param tc_cls closure for the @a tc callback 1009 */ 1010 struct ANASTASIS_TruthUpload * 1011 ANASTASIS_truth_upload3 (struct GNUNET_CURL_Context *ctx, 1012 const struct ANASTASIS_CRYPTO_UserIdentifierP *user_id, 1013 struct ANASTASIS_Truth *t, 1014 const void *truth_data, 1015 size_t truth_data_size, 1016 uint32_t payment_years_requested, 1017 struct GNUNET_TIME_Relative pay_timeout, 1018 ANASTASIS_TruthCallback tc, 1019 ANASTASIS_TRUTH_RESULT_CLOSURE *tc_cls); 1020 1021 1022 /** 1023 * Cancels a truth upload process. 1024 * 1025 * @param tu handle for the upload 1026 */ 1027 void 1028 ANASTASIS_truth_upload_cancel (struct ANASTASIS_TruthUpload *tu); 1029 1030 1031 /** 1032 * Free's the truth object which was returned to a #ANASTASIS_TruthCallback. 1033 * 1034 * @param t object to clean up 1035 */ 1036 void 1037 ANASTASIS_truth_free (struct ANASTASIS_Truth *t); 1038 1039 1040 /** 1041 * Policy object, representing a set of truths (and thus challenges 1042 * to satisfy) to recover a secret. 1043 */ 1044 struct ANASTASIS_Policy; 1045 1046 1047 /** 1048 * Creates a policy with a set of truth's. Creates the policy key 1049 * with the different key shares from the @a truths. The policy key 1050 * will then be used to encrypt/decrypt the escrow master key. 1051 * 1052 * @param truths array of truths which are stored on different providers 1053 * @param truths_len length of the @a truths array 1054 */ 1055 struct ANASTASIS_Policy * 1056 ANASTASIS_policy_create (const struct ANASTASIS_Truth *truths[], 1057 unsigned int truths_len); 1058 1059 1060 /** 1061 * Destroys a policy object. 1062 * 1063 * @param p handle for the policy to destroy 1064 */ 1065 void 1066 ANASTASIS_policy_destroy (struct ANASTASIS_Policy *p); 1067 1068 1069 /** 1070 * Information about a provider requesting payment for storing a policy. 1071 */ 1072 struct ANASTASIS_SharePaymentRequest 1073 { 1074 /** 1075 * Payment request URL. 1076 */ 1077 const char *payment_request_url; 1078 1079 /** 1080 * Base URL of the provider requesting payment. 1081 */ 1082 const char *provider_url; 1083 1084 /** 1085 * The payment secret (aka order ID) extracted from the @e payment_request_url. 1086 */ 1087 struct ANASTASIS_PaymentSecretP payment_secret; 1088 }; 1089 1090 1091 /** 1092 * Result of uploading share data. 1093 */ 1094 enum ANASTASIS_ShareStatus 1095 { 1096 /** 1097 * Upload successful. 1098 */ 1099 ANASTASIS_SHARE_STATUS_SUCCESS = 0, 1100 1101 /** 1102 * Upload requires payment. 1103 */ 1104 ANASTASIS_SHARE_STATUS_PAYMENT_REQUIRED, 1105 1106 /** 1107 * Failure to upload secret share at the provider. 1108 */ 1109 ANASTASIS_SHARE_STATUS_PROVIDER_FAILED 1110 }; 1111 1112 1113 /** 1114 * Per-provider status upon successful backup. 1115 */ 1116 struct ANASTASIS_ProviderSuccessStatus 1117 { 1118 /** 1119 * Base URL of the provider. 1120 */ 1121 const char *provider_url; 1122 1123 /** 1124 * When will the policy expire? 1125 */ 1126 struct GNUNET_TIME_Timestamp policy_expiration; 1127 1128 /** 1129 * Version number of the policy at the provider. 1130 */ 1131 unsigned long long policy_version; 1132 1133 }; 1134 1135 1136 /** 1137 * Complete result of a secret sharing operation. 1138 */ 1139 struct ANASTASIS_ShareResult 1140 { 1141 /** 1142 * Status of the share secret operation. 1143 */ 1144 enum ANASTASIS_ShareStatus ss; 1145 1146 /** 1147 * Details about the result, depending on @e ss. 1148 */ 1149 union 1150 { 1151 1152 struct 1153 { 1154 1155 /** 1156 * Array of status details for each provider. 1157 */ 1158 const struct ANASTASIS_ProviderSuccessStatus *pss; 1159 1160 /** 1161 * Length of the @e policy_version and @e provider_urls arrays. 1162 */ 1163 unsigned int num_providers; 1164 1165 } success; 1166 1167 struct 1168 { 1169 /** 1170 * Array of URLs with requested payments. 1171 */ 1172 struct ANASTASIS_SharePaymentRequest *payment_requests; 1173 1174 /** 1175 * Length of the payment_requests array. 1176 */ 1177 unsigned int payment_requests_length; 1178 } payment_required; 1179 1180 struct 1181 { 1182 /** 1183 * Base URL of the failed provider. 1184 */ 1185 const char *provider_url; 1186 1187 /** 1188 * HTTP status returned by the provider. 1189 */ 1190 unsigned int http_status; 1191 1192 /** 1193 * Upload status of the provider. 1194 */ 1195 enum ANASTASIS_UploadStatus ec; 1196 1197 } provider_failure; 1198 1199 } details; 1200 1201 }; 1202 1203 1204 /** 1205 * Function called with the results of a #ANASTASIS_secret_share(). 1206 * 1207 * @param cls closure 1208 * @param sr share result 1209 */ 1210 #ifndef ANASTASIS_SHARE_RESULT_CLOSURE 1211 /** 1212 * Type of the closure for #ANASTASIS_ShareResultCallback. 1213 */ 1214 #define ANASTASIS_SHARE_RESULT_CLOSURE void 1215 #endif 1216 typedef void 1217 (*ANASTASIS_ShareResultCallback)(ANASTASIS_SHARE_RESULT_CLOSURE *cls, 1218 const struct ANASTASIS_ShareResult *sr); 1219 1220 1221 /** 1222 * Defines a recovery document upload process (recovery document 1223 * consists of multiple policies) 1224 */ 1225 struct ANASTASIS_SecretShare; 1226 1227 1228 /** 1229 * Details of a past payment 1230 */ 1231 struct ANASTASIS_ProviderDetails 1232 { 1233 /** 1234 * URL of the provider backend. 1235 */ 1236 const char *provider_url; 1237 1238 /** 1239 * Payment order ID / secret of a past payment. 1240 */ 1241 struct ANASTASIS_PaymentSecretP payment_secret; 1242 1243 /** 1244 * Server salt. Points into a truth object from which we got the 1245 * salt. 1246 */ 1247 struct ANASTASIS_CRYPTO_ProviderSaltP provider_salt; 1248 }; 1249 1250 1251 /** 1252 * Creates a recovery document with the created policies and uploads it to 1253 * all servers. 1254 * 1255 * @param ctx the CURL context used to connect to the backend 1256 * @param id_data used to create a account identifier on the escrow provider 1257 * @param providers array of providers with URLs to upload the policies to 1258 * @param pss_length length of the @a providers array 1259 * @param policies list of policies which are included in this recovery document 1260 * @param policies_len length of the @a policies array 1261 * @param payment_years_requested for how many years would the client like the service to store the truth? 1262 * @param pay_timeout how long to wait for payment 1263 * @param src callback for the upload process 1264 * @param src_cls closure for the @a src upload callback 1265 * @param secret_name name of the core secret 1266 * @param core_secret input of the user which is secured by anastasis e.g. (wallet private key) 1267 * @param core_secret_size size of the @a core_secret 1268 * @return NULL on error 1269 */ 1270 struct ANASTASIS_SecretShare * 1271 ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx, 1272 const json_t *id_data, 1273 const struct ANASTASIS_ProviderDetails providers[], 1274 unsigned int pss_length, 1275 const struct ANASTASIS_Policy *policies[], 1276 unsigned int policies_len, 1277 uint32_t payment_years_requested, 1278 struct GNUNET_TIME_Relative pay_timeout, 1279 ANASTASIS_ShareResultCallback src, 1280 ANASTASIS_SHARE_RESULT_CLOSURE *src_cls, 1281 const char *secret_name, 1282 const void *core_secret, 1283 size_t core_secret_size); 1284 1285 1286 /** 1287 * Cancels a secret share request. 1288 * 1289 * @param ss handle to the request 1290 */ 1291 void 1292 ANASTASIS_secret_share_cancel (struct ANASTASIS_SecretShare *ss); 1293 1294 1295 #endif