anastasis_database_plugin.h (27923B)
1 /* 2 This file is part of Anastasis 3 Copyright (C) 2019-2022 Anastasis SARL 4 5 Anastasis is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero 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 Affero General Public License for more details. 12 13 You should have received a copy of the GNU Affero 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_database_plugin.h 18 * @brief database access for Anastasis 19 * @author Christian Grothoff 20 */ 21 #ifndef ANASTASIS_DATABASE_PLUGIN_H 22 #define ANASTASIS_DATABASE_PLUGIN_H 23 24 #include "anastasis_service.h" 25 #include <gnunet/gnunet_db_lib.h> 26 27 /** 28 * How long is an offer for a challenge payment valid for payment? 29 */ 30 #define ANASTASIS_CHALLENGE_OFFER_LIFETIME GNUNET_TIME_UNIT_HOURS 31 32 /** 33 * Return values for checking code validity. 34 */ 35 enum ANASTASIS_DB_CodeStatus 36 { 37 /** 38 * Provided authentication code does not match database content. 39 */ 40 ANASTASIS_DB_CODE_STATUS_CHALLENGE_CODE_MISMATCH = -3, 41 42 /** 43 * Encountered hard error talking to DB. 44 */ 45 ANASTASIS_DB_CODE_STATUS_HARD_ERROR = -2, 46 47 /** 48 * Encountered serialization error talking to DB. 49 */ 50 ANASTASIS_DB_CODE_STATUS_SOFT_ERROR = -1, 51 52 /** 53 * We have no challenge in the database. 54 */ 55 ANASTASIS_DB_CODE_STATUS_NO_RESULTS = 0, 56 57 /** 58 * The provided challenge matches what we have in the database. 59 */ 60 ANASTASIS_DB_CODE_STATUS_VALID_CODE_STORED = 1, 61 }; 62 63 64 /** 65 * Return values for checking account validity. 66 */ 67 enum ANASTASIS_DB_AccountStatus 68 { 69 /** 70 * Account is unknown, user should pay to establish it. 71 */ 72 ANASTASIS_DB_ACCOUNT_STATUS_PAYMENT_REQUIRED = -3, 73 74 /** 75 * Encountered hard error talking to DB. 76 */ 77 ANASTASIS_DB_ACCOUNT_STATUS_HARD_ERROR = -2, 78 79 /** 80 * Account is valid, but we have no policy stored yet. 81 */ 82 ANASTASIS_DB_ACCOUNT_STATUS_NO_RESULTS = 0, 83 84 /** 85 * Account is valid, and we have a policy stored. 86 */ 87 ANASTASIS_DB_ACCOUNT_STATUS_VALID_HASH_RETURNED = 1, 88 }; 89 90 91 /** 92 * Return values for storing data in database with payment. 93 */ 94 enum ANASTASIS_DB_StoreStatus 95 { 96 /** 97 * The client has stored too many policies, should pay to store more. 98 */ 99 ANASTASIS_DB_STORE_STATUS_STORE_LIMIT_EXCEEDED = -4, 100 101 /** 102 * The client needs to pay to store policies. 103 */ 104 ANASTASIS_DB_STORE_STATUS_PAYMENT_REQUIRED = -3, 105 106 /** 107 * Encountered hard error talking to DB. 108 */ 109 ANASTASIS_DB_STORE_STATUS_HARD_ERROR = -2, 110 111 /** 112 * Despite retrying, we encountered serialization errors. 113 */ 114 ANASTASIS_DB_STORE_STATUS_SOFT_ERROR = -1, 115 116 /** 117 * Database did not need an update (document exists). 118 */ 119 ANASTASIS_DB_STORE_STATUS_NO_RESULTS = 0, 120 121 /** 122 * We successfully stored the document. 123 */ 124 ANASTASIS_DB_STORE_STATUS_SUCCESS = 1, 125 }; 126 127 128 /** 129 * Function called on all pending payments for an account or challenge. 130 * 131 * @param cls closure 132 * @param timestamp for how long have we been waiting 133 * @param payment_secret payment secret / order id in the backend 134 * @param amount how much is the order for 135 */ 136 typedef void 137 (*ANASTASIS_DB_PaymentPendingIterator)( 138 void *cls, 139 struct GNUNET_TIME_Timestamp timestamp, 140 const struct ANASTASIS_PaymentSecretP *payment_secret, 141 const struct TALER_Amount *amount); 142 143 144 /** 145 * Function called to test if a given wire transfer 146 * satisfied the authentication requirement of the 147 * IBAN plugin. 148 * 149 * @param cls closure 150 * @param credit amount that was transferred 151 * @param wire_subject subject provided in the wire transfer 152 * @return true if this wire transfer satisfied the authentication check 153 */ 154 typedef bool 155 (*ANASTASIS_DB_AuthIbanTransfercheck)( 156 void *cls, 157 const struct TALER_Amount *credit, 158 const char *wire_subject); 159 160 161 /** 162 * Function called on matching meta data. Note that if the client did 163 * not provide meta data for @a version, the function will be called 164 * with @a recovery_meta_data being NULL. 165 * 166 * @param cls closure 167 * @param version the version of the recovery document 168 * @param ts timestamp when the document was uploaded 169 * @param recovery_meta_data contains meta data about the encrypted recovery document 170 * @param recovery_meta_data_size size of @a recovery_meta_data blob 171 * @return #GNUNET_OK to continue to iterate, #GNUNET_NO to abort iteration 172 */ 173 typedef enum GNUNET_GenericReturnValue 174 (*ANASTASIS_DB_RecoveryMetaCallback)(void *cls, 175 uint32_t version, 176 struct GNUNET_TIME_Timestamp ts, 177 const void *recovery_meta_data, 178 size_t recovery_meta_data_size); 179 180 181 /** 182 * Handle to interact with the database. 183 * 184 * Functions ending with "_TR" run their OWN transaction scope 185 * and MUST NOT be called from within a transaction setup by the 186 * caller. Functions ending with "_NT" require the caller to 187 * setup a transaction scope. Functions without a suffix are 188 * simple, single SQL queries that MAY be used either way. 189 */ 190 struct ANASTASIS_DatabasePlugin 191 { 192 193 /** 194 * Closure for all callbacks. 195 */ 196 void *cls; 197 198 /** 199 * Name of the library which generated this plugin. Set by the 200 * plugin loader. 201 */ 202 char *library_name; 203 204 /** 205 * Drop anastasis tables. Used for testcases. 206 * 207 * @param cls closure 208 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 209 */ 210 enum GNUNET_GenericReturnValue 211 (*drop_tables)(void *cls); 212 213 /** 214 * Connect to the database. 215 * 216 * @param cls closure 217 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 218 */ 219 enum GNUNET_GenericReturnValue 220 (*connect)(void *cls); 221 222 /** 223 * Initialize merchant tables 224 * 225 * @param cls closure 226 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 227 */ 228 enum GNUNET_GenericReturnValue 229 (*create_tables)(void *cls); 230 231 /** 232 * Function called to perform "garbage collection" on the 233 * database, expiring records we no longer require. Deletes 234 * all user records that are not paid up (and by cascade deletes 235 * the associated recovery documents). Also deletes expired 236 * truth and financial records older than @a fin_expire. 237 * 238 * @param cls closure 239 * @param expire_backups backups older than the given time stamp should be garbage collected 240 * @param expire_pending_payments payments still pending from since before 241 * this value should be garbage collected 242 * @return transaction status 243 */ 244 enum GNUNET_DB_QueryStatus 245 (*gc)(void *cls, 246 struct GNUNET_TIME_Absolute expire, 247 struct GNUNET_TIME_Absolute expire_pending_payments); 248 249 /** 250 * Do a pre-flight check that we are not in an uncommitted transaction. 251 * If we are, try to commit the previous transaction and output a warning. 252 * Does not return anything, as we will continue regardless of the outcome. 253 * 254 * @param cls the `struct PostgresClosure` with the plugin-specific state 255 * @return #GNUNET_OK if everything is fine 256 * #GNUNET_NO if a transaction was rolled back 257 * #GNUNET_SYSERR on hard errors 258 */ 259 enum GNUNET_GenericReturnValue 260 (*preflight)(void *cls); 261 262 /** 263 * Check that the database connection is still up. 264 * 265 * @param pg connection to check 266 */ 267 void 268 (*check_connection) (void *cls); 269 270 /** 271 * Roll back the current transaction of a database connection. 272 * 273 * @param cls the `struct PostgresClosure` with the plugin-specific state 274 * @return #GNUNET_OK on success 275 */ 276 void 277 (*rollback) (void *cls); 278 279 /** 280 * Start a transaction. 281 * 282 * @param cls the `struct PostgresClosure` with the plugin-specific state 283 * @param name unique name identifying the transaction (for debugging), 284 * must point to a constant 285 * @return #GNUNET_OK on success 286 */ 287 int 288 (*start) (void *cls, 289 const char *name); 290 291 /** 292 * Commit the current transaction of a database connection. 293 * 294 * @param cls the `struct PostgresClosure` with the plugin-specific state 295 * @return transaction status code 296 */ 297 enum GNUNET_DB_QueryStatus 298 (*commit)(void *cls); 299 300 301 /** 302 * Register callback to be invoked on events of type @a es. 303 * 304 * @param cls database context to use 305 * @param es specification of the event to listen for 306 * @param timeout how long to wait for the event 307 * @param cb function to call when the event happens, possibly 308 * multiple times (until cancel is invoked) 309 * @param cb_cls closure for @a cb 310 * @return handle useful to cancel the listener 311 */ 312 struct GNUNET_DB_EventHandler * 313 (*event_listen)(void *cls, 314 const struct GNUNET_DB_EventHeaderP *es, 315 struct GNUNET_TIME_Relative timeout, 316 GNUNET_DB_EventCallback cb, 317 void *cb_cls); 318 319 /** 320 * Stop notifications. 321 * 322 * @param eh handle to unregister. 323 */ 324 void 325 (*event_listen_cancel)(struct GNUNET_DB_EventHandler *eh); 326 327 328 /** 329 * Notify all that listen on @a es of an event. 330 * 331 * @param cls database context to use 332 * @param es specification of the event to generate 333 * @param extra additional event data provided 334 * @param extra_size number of bytes in @a extra 335 */ 336 void 337 (*event_notify)(void *cls, 338 const struct GNUNET_DB_EventHeaderP *es, 339 const void *extra, 340 size_t extra_size); 341 342 343 /** 344 * Store encrypted recovery document. 345 * 346 * @param cls closure 347 * @param account_pub public key of the user's account 348 * @param account_sig signature affirming storage request 349 * @param recovery_data_hash hash of @a data 350 * @param recovery_data contains encrypted recovery document 351 * @param recovery_data_size size of @a recovery_data blob 352 * @param recovery_meta_data contains meta data about the encrypted recovery document 353 * @param recovery_meta_data_size size of @a recovery_meta_data blob 354 * @param payment_secret identifier for the payment, used to later charge on uploads 355 * @param[out] version set to the version assigned to the document by the database 356 * @return transaction status, 0 if upload could not be finished because @a payment_secret 357 * did not have enough upload left; HARD error if @a payment_secret is unknown, ... 358 */ 359 enum ANASTASIS_DB_StoreStatus 360 (*store_recovery_document)( 361 void *cls, 362 const struct ANASTASIS_CRYPTO_AccountPublicKeyP *account_pub, 363 const struct ANASTASIS_AccountSignatureP *account_sig, 364 const struct GNUNET_HashCode *recovery_data_hash, 365 const void *recovery_data, 366 size_t recovery_data_size, 367 const void *recovery_meta_data, 368 size_t recovery_meta_data_size, 369 const struct ANASTASIS_PaymentSecretP *payment_secret, 370 uint32_t *version); 371 372 373 /** 374 * Fetch recovery document meta data for user. Returns 375 * meta data in descending order from @a max_version. 376 * The size of the result set may be limited. 377 * 378 * @param cls closure 379 * @param account_pub public key of the user's account 380 * @param max_version the maximum version number the user requests 381 * @param cb function to call on each result 382 * @param cb_cls closure for @a cb 383 * @return transaction status 384 */ 385 enum GNUNET_DB_QueryStatus 386 (*get_recovery_meta_data)( 387 void *cls, 388 const struct ANASTASIS_CRYPTO_AccountPublicKeyP *account_pub, 389 uint32_t max_version, 390 ANASTASIS_DB_RecoveryMetaCallback cb, 391 void *cb_cls); 392 393 394 /** 395 * Fetch recovery document for user according given version. 396 * 397 * @param cls closure 398 * @param account_pub public key of the user's account 399 * @param version the version number of the policy the user requests 400 * @param[out] account_sig signature 401 * @param[out] recovery_data_hash hash of the current recovery data 402 * @param[out] data_size size of data blob 403 * @param[out] data blob which contains the recovery document 404 * @return transaction status 405 */ 406 enum GNUNET_DB_QueryStatus 407 (*get_recovery_document)( 408 void *cls, 409 const struct ANASTASIS_CRYPTO_AccountPublicKeyP *account_pub, 410 uint32_t version, 411 struct ANASTASIS_AccountSignatureP *account_sig, 412 struct GNUNET_HashCode *recovery_data_hash, 413 size_t *data_size, 414 void **data); 415 416 417 /** 418 * Fetch latest recovery document for user. 419 * 420 * @param cls closure 421 * @param account_pub public key of the user's account 422 * @param account_sig signature 423 * @param recovery_data_hash hash of the current recovery data 424 * @param[out] data_size set to size of @a data blob 425 * @param[out] data set to blob which contains the recovery document 426 * @param[out] version set to the version number of the policy being returned 427 * @return transaction status 428 */ 429 enum GNUNET_DB_QueryStatus 430 (*get_latest_recovery_document)( 431 void *cls, 432 const struct ANASTASIS_CRYPTO_AccountPublicKeyP *account_pub, 433 struct ANASTASIS_AccountSignatureP *account_sig, 434 struct GNUNET_HashCode *recovery_data_hash, 435 size_t *data_size, 436 void **data, 437 uint32_t *version); 438 439 440 /** 441 * Upload Truth, which contains the Truth and the KeyShare. 442 * 443 * @param cls closure 444 * @param truth_uuid the identifier for the Truth 445 * @param key_share_data contains information of an EncryptedKeyShare 446 * @param mime_type presumed mime type of data in @a encrypted_truth 447 * @param encrypted_truth contains the encrypted Truth which includes the ground truth i.e. H(challenge answer), phonenumber, SMS 448 * @param encrypted_truth_size the size of the Truth 449 * @param method name of method 450 * @param truth_expiration time till the according data will be stored 451 * @return transaction status 452 */ 453 enum GNUNET_DB_QueryStatus 454 (*store_truth)( 455 void *cls, 456 const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, 457 const struct ANASTASIS_CRYPTO_EncryptedKeyShareP *key_share_data, 458 const char *mime_type, 459 const void *encrypted_truth, 460 size_t encrypted_truth_size, 461 const char *method, 462 struct GNUNET_TIME_Relative truth_expiration); 463 464 465 /** 466 * Get the encrypted truth to validate the challenge response 467 * 468 * @param cls closure 469 * @param truth_uuid the identifier for the Truth 470 * @param[out] truth contains the encrypted truth 471 * @param[out] truth_size size of the encrypted truth 472 * @param[out] truth_mime mime type of truth 473 * @param[out] method type of the challenge 474 * @return transaction status 475 */ 476 enum GNUNET_DB_QueryStatus 477 (*get_escrow_challenge)( 478 void *cls, 479 const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, 480 void **truth, 481 size_t *truth_size, 482 char **truth_mime, 483 char **method); 484 485 486 /** 487 * Lookup (encrypted) key share by @a truth_uuid. 488 * 489 * @param cls closure 490 * @param truth_uuid the identifier for the Truth 491 * @param[out] key_share set to the encrypted Keyshare 492 * @return transaction status 493 */ 494 enum GNUNET_DB_QueryStatus 495 (*get_key_share)( 496 void *cls, 497 const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, 498 struct ANASTASIS_CRYPTO_EncryptedKeyShareP *key_share); 499 500 501 /** 502 * Check if an account exists, and if so, return the 503 * current @a recovery_document_hash. 504 * 505 * @param cls closure 506 * @param account_pub account identifier 507 * @param[out] paid_until until when is the account paid up? 508 * @param[out] recovery_data_hash set to hash of @a recovery document 509 * @param[out] version set to the recovery policy version 510 * @return transaction status 511 */ 512 enum ANASTASIS_DB_AccountStatus 513 (*lookup_account)( 514 void *cls, 515 const struct ANASTASIS_CRYPTO_AccountPublicKeyP *account_pub, 516 struct GNUNET_TIME_Timestamp *paid_until, 517 struct GNUNET_HashCode *recovery_data_hash, 518 uint32_t *version); 519 520 521 /** 522 * Check payment identifier. Used to check if a payment identifier given by 523 * the user is valid (existing and paid). 524 * 525 * @param cls closure 526 * @param payment_secret payment secret which the user must provide with every upload 527 * @param[out] paid bool value to show if payment is paid 528 * @param[out] valid_counter bool value to show if post_counter is > 0 529 * @return transaction status 530 */ 531 enum GNUNET_DB_QueryStatus 532 (*check_payment_identifier)( 533 void *cls, 534 const struct ANASTASIS_PaymentSecretP *payment_secret, 535 bool *paid, 536 bool *valid_counter); 537 538 539 /** 540 * Check payment identifier. Used to check if a payment identifier given by 541 * the user is valid (existing and paid). 542 * 543 * @param cls closure 544 * @param payment_secret payment secret which the user must provide with every upload 545 * @param truth_uuid unique identifier of the truth the user must satisfy the challenge 546 * @param[out] paid bool value to show if payment is paid 547 * @return transaction status 548 */ 549 enum GNUNET_DB_QueryStatus 550 (*check_challenge_payment)( 551 void *cls, 552 const struct ANASTASIS_PaymentSecretP *payment_secret, 553 const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, 554 bool *paid); 555 556 557 /** 558 * Increment account lifetime by @a lifetime. 559 * 560 * @param cls closure 561 * @param account_pub which account received a payment 562 * @param payment_identifier proof of payment, must be unique and match pending payment 563 * @param lifetime for how long is the account now paid (increment) 564 * @param[out] paid_until set to the end of the lifetime after the operation 565 * @return transaction status 566 */ 567 enum GNUNET_DB_QueryStatus 568 (*increment_lifetime)( 569 void *cls, 570 const struct ANASTASIS_CRYPTO_AccountPublicKeyP *account_pub, 571 const struct ANASTASIS_PaymentSecretP *payment_identifier, 572 struct GNUNET_TIME_Relative lifetime, 573 struct GNUNET_TIME_Timestamp *paid_until); 574 575 576 /** 577 * Update account lifetime to the maximum of the current 578 * value and @a eol. 579 * 580 * @param cls closure 581 * @param account_pub which account received a payment 582 * @param payment_identifier proof of payment, must be unique and match pending payment 583 * @param eol for how long is the account now paid (absolute) 584 * @return transaction status 585 */ 586 enum GNUNET_DB_QueryStatus 587 (*update_lifetime)( 588 void *cls, 589 const struct ANASTASIS_CRYPTO_AccountPublicKeyP *account_pub, 590 const struct ANASTASIS_PaymentSecretP *payment_identifier, 591 struct GNUNET_TIME_Timestamp eol); 592 593 594 /** 595 * Store payment. Used to begin a payment, not indicative 596 * that the payment actually was made. (That is done 597 * when we increment the account's lifetime.) 598 * 599 * @param cls closure 600 * @param account_pub anastasis's public key 601 * @param post_counter how many uploads does @a amount pay for 602 * @param payment_secret payment secret which the user must provide with every upload 603 * @param amount how much we asked for 604 * @return transaction status 605 */ 606 enum GNUNET_DB_QueryStatus 607 (*record_recdoc_payment)( 608 void *cls, 609 const struct ANASTASIS_CRYPTO_AccountPublicKeyP *account_pub, 610 uint32_t post_counter, 611 const struct ANASTASIS_PaymentSecretP *payment_secret, 612 const struct TALER_Amount *amount); 613 614 615 /** 616 * Record truth upload payment was made. 617 * 618 * @param cls closure 619 * @param uuid the truth's UUID 620 * @param amount the amount that was paid 621 * @param duration how long is the truth paid for 622 * @return transaction status 623 */ 624 enum GNUNET_DB_QueryStatus 625 (*record_truth_upload_payment)( 626 void *cls, 627 const struct ANASTASIS_CRYPTO_TruthUUIDP *uuid, 628 const struct TALER_Amount *amount, 629 struct GNUNET_TIME_Relative duration); 630 631 632 /** 633 * Inquire whether truth upload payment was made. 634 * 635 * @param cls closure 636 * @param uuid the truth's UUID 637 * @param[out] paid_until set for how long this truth is paid for 638 * @return transaction status 639 */ 640 enum GNUNET_DB_QueryStatus 641 (*check_truth_upload_paid)( 642 void *cls, 643 const struct ANASTASIS_CRYPTO_TruthUUIDP *uuid, 644 struct GNUNET_TIME_Timestamp *paid_until); 645 646 647 /** 648 * Verify the provided code with the code on the server. 649 * If the code matches the function will return with success, if the code 650 * does not match, the retry counter will be decreased by one. 651 * 652 * @param cls closure 653 * @param truth_uuid identification of the challenge which the code corresponds to 654 * @param hashed_code code which the user provided and wants to verify 655 * @param[out] code set to the original numeric code 656 * @param[out] satisfied set to true if the challenge is set to satisfied 657 * @return transaction status 658 */ 659 enum ANASTASIS_DB_CodeStatus 660 (*verify_challenge_code)( 661 void *cls, 662 const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, 663 const struct GNUNET_HashCode *hashed_code, 664 uint64_t *code, 665 bool *satisfied); 666 667 668 /** 669 * Set the 'satisfied' bit for the given challenge and code to 670 * 'true'. 671 * 672 * @param cls closure 673 * @param truth_uuid identification of the challenge which the code corresponds to 674 * @param code code which is now satisfied 675 * @return transaction status 676 */ 677 enum GNUNET_DB_QueryStatus 678 (*mark_challenge_code_satisfied)( 679 void *cls, 680 const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, 681 uint64_t code); 682 683 684 /** 685 * Check if the 'satisfied' bit for the given challenge and code is 686 * 'true' and the challenge code is not yet expired. 687 * 688 * @param cls closure 689 * @param truth_uuid identification of the challenge which the code corresponds to 690 * @param code code which is now satisfied 691 * @param after after what time must the challenge have been created 692 * @return transaction status, 693 * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the challenge code is not satisfied or expired 694 * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if the challenge code has been marked as satisfied 695 */ 696 enum GNUNET_DB_QueryStatus 697 (*test_challenge_code_satisfied)( 698 void *cls, 699 const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, 700 const uint64_t code, 701 struct GNUNET_TIME_Timestamp after); 702 703 704 /** 705 * Insert a new challenge code for a given challenge identified by the challenge 706 * public key. The function will first check if there is already a valid code 707 * for this challenge present and won't insert a new one in this case. 708 * 709 * @param cls closure 710 * @param truth_uuid the identifier for the challenge 711 * @param rotation_period for how long is the code available 712 * @param validity_period for how long is the code available 713 * @param retry_counter amount of retries allowed 714 * @param[out] retransmission_date when to next retransmit 715 * @param[out] code set to the code which will be checked for later 716 * @return transaction status, 717 * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if we are out of valid tries, 718 * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if @a code is now in the DB 719 */ 720 enum GNUNET_DB_QueryStatus 721 (*create_challenge_code)( 722 void *cls, 723 const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, 724 struct GNUNET_TIME_Relative rotation_period, 725 struct GNUNET_TIME_Relative validity_period, 726 uint32_t retry_counter, 727 struct GNUNET_TIME_Timestamp *retransmission_date, 728 uint64_t *code); 729 730 731 /** 732 * Remember in the database that we successfully sent a challenge. 733 * 734 * @param cls closure 735 * @param truth_uuid the identifier for the challenge 736 * @param code the challenge that was sent 737 */ 738 enum GNUNET_DB_QueryStatus 739 (*mark_challenge_sent)( 740 void *cls, 741 const struct ANASTASIS_PaymentSecretP *payment_secret, 742 const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, 743 uint64_t code); 744 745 746 /** 747 * Store payment for challenge. 748 * 749 * @param cls closure 750 * @param truth_key identifier of the challenge to pay 751 * @param payment_secret payment secret which the user must provide with every upload 752 * @param amount how much we asked for 753 * @return transaction status 754 */ 755 enum GNUNET_DB_QueryStatus 756 (*record_challenge_payment)( 757 void *cls, 758 const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, 759 const struct ANASTASIS_PaymentSecretP *payment_secret, 760 const struct TALER_Amount *amount); 761 762 763 /** 764 * Record refund for challenge. 765 * 766 * @param cls closure 767 * @param truth_uuid identifier of the challenge to refund 768 * @param payment_secret payment secret which the user must provide with every upload 769 * @return transaction status 770 */ 771 enum GNUNET_DB_QueryStatus 772 (*record_challenge_refund)( 773 void *cls, 774 const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, 775 const struct ANASTASIS_PaymentSecretP *payment_secret); 776 777 778 /** 779 * Lookup for a pending payment for a certain challenge 780 * 781 * @param cls closure 782 * @param truth_uuid identification of the challenge 783 * @param[out] payment_secret set to the challenge payment secret 784 * @return transaction status 785 */ 786 enum GNUNET_DB_QueryStatus 787 (*lookup_challenge_payment)( 788 void *cls, 789 const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, 790 struct ANASTASIS_PaymentSecretP *payment_secret); 791 792 793 /** 794 * Update payment status of challenge 795 * 796 * @param cls closure 797 * @param truth_uuid which challenge received a payment 798 * @param payment_identifier proof of payment, must be unique and match pending payment 799 * @return transaction status 800 */ 801 enum GNUNET_DB_QueryStatus 802 (*update_challenge_payment)( 803 void *cls, 804 const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, 805 const struct ANASTASIS_PaymentSecretP *payment_identifier); 806 807 808 /** 809 * Store inbound IBAN payment made for authentication. 810 * 811 * @param cls closure 812 * @param wire_reference unique identifier inside LibEuFin/Nexus 813 * @param wire_subject subject of the wire transfer 814 * @param amount how much was transferred 815 * @param debit_account account that was debited 816 * @param credit_account Anastasis operator account credited 817 * @param execution_date when was the transfer made 818 * @return transaction status 819 */ 820 enum GNUNET_DB_QueryStatus 821 (*record_auth_iban_payment)( 822 void *cls, 823 uint64_t wire_reference, 824 const char *wire_subject, 825 const struct TALER_Amount *amount, 826 const char *debit_account, 827 const char *credit_account, 828 struct GNUNET_TIME_Timestamp execution_date); 829 830 831 /** 832 * Function to check if we are aware of a wire transfer 833 * that satisfies the IBAN plugin's authentication check. 834 * 835 * @param cls closure 836 * @param debit_account which debit account to check 837 * @param earliest_date earliest date to check 838 * @param cb function to call on all entries found 839 * @param cb_cls closure for @a cb 840 * @return transaction status, 841 * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if @a cb 842 * returned 'true' once 843 * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if no 844 * wire transfers existed for which @a cb returned true 845 */ 846 enum GNUNET_DB_QueryStatus 847 (*test_auth_iban_payment)( 848 void *cls, 849 const char *debit_account, 850 struct GNUNET_TIME_Timestamp earliest_date, 851 ANASTASIS_DB_AuthIbanTransfercheck cb, 852 void *cb_cls); 853 854 855 /** 856 * Function to check the last known IBAN payment. 857 * 858 * @param cls closure 859 * @param credit_account which credit account to check 860 * @param[out] last_row set to the last known row 861 * @return transaction status, 862 * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if @a cb 863 * returned 'true' once 864 * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if no 865 * wire transfers existed for which @a cb returned true 866 */ 867 enum GNUNET_DB_QueryStatus 868 (*get_last_auth_iban_payment_row)( 869 void *cls, 870 const char *credit_account, 871 uint64_t *last_row); 872 873 874 /** 875 * Function called to remove all expired codes from the database. 876 * 877 * @return transaction status 878 */ 879 enum GNUNET_DB_QueryStatus 880 (*challenge_gc)(void *cls); 881 882 883 }; 884 #endif