diff options
Diffstat (limited to 'src/encryption.c')
| -rw-r--r-- | src/encryption.c | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/src/encryption.c b/src/encryption.c index 382f6d5..aafb972 100644 --- a/src/encryption.c +++ b/src/encryption.c | |||
| @@ -634,77 +634,4 @@ ctqueue * cryptscan() { | |||
| 634 | return res; | 634 | return res; |
| 635 | } | 635 | } |
| 636 | 636 | ||
| 637 | /* | ||
| 638 | int main(void) { | ||
| 639 | // Example code for creating a temp file, writing to it, then linking it back into the fs | ||
| 640 | const char *dir = ".", *testmsg = "we do a little testing\n"; | ||
| 641 | char *path = NULL; | ||
| 642 | |||
| 643 | int fd = maketmp(dir); | ||
| 644 | if(fd < 0) | ||
| 645 | error(1, errno, "Couldn't make temp file at %s", dir); | ||
| 646 | |||
| 647 | if(write(fd, testmsg, strlen(testmsg)) < 0) | ||
| 648 | error(1, errno, "write broke"); | ||
| 649 | |||
| 650 | asprintf(&path, "/proc/self/fd/%d", fd); | ||
| 651 | linkat(AT_FDCWD, path, AT_FDCWD, "./test", AT_SYMLINK_FOLLOW); | ||
| 652 | free(path); | ||
| 653 | |||
| 654 | // Apparently, I don't have the CAP_DAC_READ_SEARCH capibility. Thanks for the solution, linux man pages | ||
| 655 | |||
| 656 | if(close(fd) < 0) | ||
| 657 | error(1, errno, "close broke"); | ||
| 658 | //*/// | ||
| 659 | |||
| 660 | /*// Example code for getting a password using genpassword | ||
| 661 | checksodium(); | ||
| 662 | |||
| 663 | char *password = NULL; | ||
| 664 | genpassword(&password, 20); | ||
| 665 | printf("%s\n", (password != NULL) ? password : "Couldn't get a password"); | ||
| 666 | free(password); | ||
| 667 | //*/// | ||
| 668 | |||
| 669 | /*// Example code for generating a password, derriving a secret key from it, and storing things properly | ||
| 670 | |||
| 671 | // Initialization | ||
| 672 | checksodium(); | ||
| 673 | char *pass = NULL, hpass[crypto_pwhash_STRBYTES]; | ||
| 674 | |||
| 675 | if(genpassword(&pass, 20) < 0) { | ||
| 676 | error(1, 0, "Could not generate password, quitting..."); | ||
| 677 | abort(); // Makes gcc happy. Not sure why gcc randomly decides that error() isn't a proper exit, but hey whatever | ||
| 678 | } | ||
| 679 | sodium_mlock(pass, strlen(pass) + 1); | ||
| 680 | printf("Password:%s\n", pass); | ||
| 681 | |||
| 682 | // Store the password | ||
| 683 | if(crypto_pwhash_str(hpass, pass, strlen(pass) + 1, crypto_pwhash_OPSLIMIT_MODERATE, crypto_pwhash_MEMLIMIT_MODERATE) != 0) | ||
| 684 | error(1, errno, "Couldn't generate password, quitting..."); | ||
| 685 | // Don't know if I want to use MODERATE or SENSITIVE for this. SENSITIVE takes a little bit on my laptop, which honestly | ||
| 686 | // shouldn't be a problem, but it annoys me. MODERATE is quick and snappy, or at least quick enough that the slowdown is | ||
| 687 | // barely noticable. I might do MODERATE for testing and SENSITIVE for release | ||
| 688 | |||
| 689 | sodium_munlock(pass, strlen(pass) + 1); | ||
| 690 | free(pass); | ||
| 691 | |||
| 692 | printf("Hashed password: %s\n", hpass); | ||
| 693 | |||
| 694 | // Check if the password from the user is correct | ||
| 695 | char *uin = NULL; int size = -1; | ||
| 696 | if((size = readwholebuffer(&uin, 1, STDIN_FILENO)) < 0) | ||
| 697 | error(1, errno, "Could not read from stdin"); | ||
| 698 | sodium_mlock(uin, size); | ||
| 699 | |||
| 700 | printf("Valid password? %s\n", (crypto_pwhash_str_verify(hpass, uin, size) == 0) ? "True" : "False"); | ||
| 701 | |||
| 702 | |||
| 703 | sodium_munlock(uin, strlen(uin) + 1); | ||
| 704 | free(uin); | ||
| 705 | |||
| 706 | return 0; | ||
| 707 | } | ||
| 708 | */ | ||
| 709 | |||
| 710 | #endif \ No newline at end of file | 637 | #endif \ No newline at end of file |
