summaryrefslogtreecommitdiff
path: root/src/encryption.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/encryption.c')
-rw-r--r--src/encryption.c63
1 files changed, 41 insertions, 22 deletions
diff --git a/src/encryption.c b/src/encryption.c
index 6da9603..828bde2 100644
--- a/src/encryption.c
+++ b/src/encryption.c
@@ -23,43 +23,60 @@ int checkSodium(void) {
23} 23}
24 24
25// To encrypt: 25// To encrypt:
26// 1- Create a temp file with the correct name in the root folder of the partition being encrypted 26// 1- Create a temp file with the correct name in the root folder of the partition being encrypted --
27 // 1.1- Detect the partition and find the root folder 27 // 1.1- Detect the partition and find the root folder -- DONE || NOT NECESSARY
28 // 1.2- Create the temp file with the correct name 28 // 1.2- Create the temp file -- DONE
29// 2- Encrypt the file's contents to the temp file 29// 2- Encrypt the file's contents to the temp file --
30 // 2.1- Open the file 30 // 2.1- Open the file --
31 // 2.2- Stream the file's contents into some encryption algo 31 // 2.2- Stream the file's contents into some encryption algo --
32 // 2.3- Pipe the output of the encryption into the temp file 32 // 2.3- Pipe the output of the encryption into the temp file --
33// 3- Once the file has been encrypted, hard link it back to the original location 33// 3- Once the file has been encrypted, hard link it back to the original location, with the right name --
34// 4- Delete the original file 34// 4- Delete the original file --
35// 5- Delete the temp file 35// 5- Delete the temp file --
36 36
37 37
38int maketmp(const char *dest) { 38int maketmp(const char *dest) {
39 int fd = open(dest, (O_TMPFILE | O_WRONLY | O_CLOEXEC | O_SYNC), (S_IRUSR | S_IWUSR)); 39 return open(dest, (O_TMPFILE | O_WRONLY | O_CLOEXEC | O_SYNC), (S_IRUSR | S_IWUSR));
40 if(fd < 0) 40}
41 error(1, errno, "Couldn't open temp file at %s", dest); 41
42int encrypttotmp(const char *toencrypt) {
43 struct stat esb;
44 int efd = -1;
45
46 // Make sure the file is real and an actual file that can be encrypted
47 if(stat(toencrypt, &esb) < 0)
48 return -1;
49 if(!S_ISREG(esb.st_mode))
50 return -2;
42 51
43 return fd; 52 // Open the file as read-only
53 if((efd = open(toencrypt, O_RDONLY)) < 0)
54 return -3;
55
56 // Need to get a secret key from a password and then set up cryptostream from libsodium
57
58 return 0;
44} 59}
45 60
61#define TESTING
62#ifdef TESTING
46 63
47#include <string.h> 64#include <string.h>
48 65
49int main(void) { 66int main(void) {
50 const char *testmsg = "we do a little testing\n"; 67 const char *dir = ".", *testmsg = "we do a little testing\n";
68 char *path = NULL;
51 69
52 int fd = maketmp("."); 70 int fd = maketmp(dir);
71 if(fd < 0)
72 error(1, errno, "Couldn't make temp file at %s", dir);
53 73
54 if(write(fd, testmsg, strlen(testmsg)) < 0) 74 if(write(fd, testmsg, strlen(testmsg)) < 0)
55 error(1, errno, "write broke"); 75 error(1, errno, "write broke");
56 76
57 // if(linkat(fd, "", AT_FDCWD, "kys/now", AT_EMPTY_PATH) < 0)
58 // error(1, errno, "linkat broke");
59
60 char *path = NULL;
61 asprintf(&path, "/proc/self/fd/%d", fd); 77 asprintf(&path, "/proc/self/fd/%d", fd);
62 linkat(AT_FDCWD, path, AT_FDCWD, "./test", AT_SYMLINK_FOLLOW); 78 linkat(AT_FDCWD, path, AT_FDCWD, "./test", AT_SYMLINK_FOLLOW);
79 free(path);
63 80
64 // Apparently, I don't have the CAP_DAC_READ_SEARCH capibility. Thanks for the solution, linux man pages 81 // Apparently, I don't have the CAP_DAC_READ_SEARCH capibility. Thanks for the solution, linux man pages
65 82
@@ -67,4 +84,6 @@ int main(void) {
67 error(1, errno, "close broke"); 84 error(1, errno, "close broke");
68 85
69 return 0; 86 return 0;
70} \ No newline at end of file 87}
88
89#endif \ No newline at end of file