diff options
| author | @syxhe <https://t.me/syxhe> | 2024-09-03 01:28:19 -0500 |
|---|---|---|
| committer | @syxhe <https://t.me/syxhe> | 2024-09-03 01:28:19 -0500 |
| commit | bed4b90c91037dc4727303b241321c9af03b757a (patch) | |
| tree | ead55e198e36fbf898c5e26a4b14be815e27c830 /src | |
| parent | 73d97e960befcd5ef75ea1ae30e9b9222cf22ddf (diff) | |
Consolidate encryption and decryption function
Diffstat (limited to 'src')
| -rw-r--r-- | src/VX-GAMBLEGROUND.c | 27 | ||||
| -rw-r--r-- | src/encryption.c | 49 | ||||
| -rw-r--r-- | src/encryption.h | 8 |
3 files changed, 54 insertions, 30 deletions
diff --git a/src/VX-GAMBLEGROUND.c b/src/VX-GAMBLEGROUND.c index d7e1842..393ed48 100644 --- a/src/VX-GAMBLEGROUND.c +++ b/src/VX-GAMBLEGROUND.c | |||
| @@ -159,7 +159,8 @@ int scanundencrypt(void *passed) { | |||
| 159 | struct sande *p = (struct sande *)passed; | 159 | struct sande *p = (struct sande *)passed; |
| 160 | 160 | ||
| 161 | p->scanned = scanfiles(p->STARTPATH, p->cmp); | 161 | p->scanned = scanfiles(p->STARTPATH, p->cmp); |
| 162 | encryptvxgg(p->scanned, p->passphrase); | 162 | //encryptvxgg(p->scanned, p->passphrase); |
| 163 | ENorDE_cryptvxgg(p->scanned, p->passphrase, VXGG_ENCRYPT); | ||
| 163 | 164 | ||
| 164 | return 0; | 165 | return 0; |
| 165 | } | 166 | } |
| @@ -226,16 +227,20 @@ int main(int argc, char *argv[]) { | |||
| 226 | 227 | ||
| 227 | 228 | ||
| 228 | // Deal with decrypting flag | 229 | // Deal with decrypting flag |
| 229 | // if((args.flags & SKIPSLOTS) && (args.inputpass != NULL)) { | 230 | if((args.flags & SKIPSLOTS) && (args.inputpass != NULL)) { |
| 230 | // struct sande pass = { | 231 | // struct sande pass = { |
| 231 | // .cmp = alphasort, | 232 | // .cmp = alphasort, |
| 232 | // .passphrase = passphrase, | 233 | // .passphrase = passphrase, |
| 233 | // .scanned = NULL, | 234 | // .scanned = NULL, |
| 234 | // .STARTPATH = FILESCAN_START | 235 | // .STARTPATH = FILESCAN_START |
| 235 | // }; | 236 | // }; |
| 236 | // decrypt((void*)&pass); | 237 | // decrypt((void*)&pass); |
| 237 | // return 0; | 238 | |
| 238 | // } | 239 | struct nodelist *files = NULL; |
| 240 | files = scanfiles(FILESCAN_START, alphasort); | ||
| 241 | ENorDE_cryptvxgg(files, passphrase, VXGG_DECRYPT); | ||
| 242 | return 0; | ||
| 243 | } | ||
| 239 | 244 | ||
| 240 | struct bullshit stuff; | 245 | struct bullshit stuff; |
| 241 | struct nodelist *files = NULL; | 246 | struct nodelist *files = NULL; |
diff --git a/src/encryption.c b/src/encryption.c index 8b0055c..8cccca8 100644 --- a/src/encryption.c +++ b/src/encryption.c | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | #include "encryption.h" | 10 | #include "encryption.h" |
| 11 | #include "ll.h" | 11 | #include "ll.h" |
| 12 | #include "VX-GAMBLEGROUND.h" | ||
| 12 | 13 | ||
| 13 | #include <sys/types.h> | 14 | #include <sys/types.h> |
| 14 | #include <sys/stat.h> | 15 | #include <sys/stat.h> |
| @@ -202,47 +203,57 @@ int rename_format(const char *fullpath, const char *format, ...) { | |||
| 202 | } | 203 | } |
| 203 | 204 | ||
| 204 | 205 | ||
| 205 | 206 | int ENorDE_cryptvxgg(const struct nodelist *list, const char *passphrase, int flag) { | |
| 206 | int encryptvxgg(const struct nodelist *list, const char *passphrase) { | ||
| 207 | int fd = -1; | 207 | int fd = -1; |
| 208 | |||
| 209 | regex_t encext; | 208 | regex_t encext; |
| 210 | regcomp(&encext, "(.+\\.vxgg)$", REG_EXTENDED | REG_ICASE | REG_NEWLINE); | 209 | regcomp(&encext, "(.+\\.vxgg)$", REG_EXTENDED | REG_ICASE | REG_NEWLINE); |
| 211 | 210 | ||
| 212 | // Encrypt everything | ||
| 213 | for(const struct nodelist *p = list; p != NULL; p = p->next) { | 211 | for(const struct nodelist *p = list; p != NULL; p = p->next) { |
| 214 | if(p->fullpath == NULL) // Make sure I don't accidentally do anything with that last element | 212 | if(p->fullpath == NULL) |
| 215 | continue; | 213 | continue; |
| 216 | if(regexec(&encext, p->fullpath, 0, NULL, 0) != REG_NOMATCH) // Don't encrypt already encrypted files | 214 | if(regexec(&encext, p->fullpath, 0, NULL, 0) != REG_NOMATCH && flag == VXGG_ENCRYPT) // Don't encrypt already encrypted files |
| 215 | continue; | ||
| 216 | if(regexec(&encext, p->fullpath, 0, NULL, 0) == REG_NOMATCH && flag == VXGG_DECRYPT) // Skip non-matching files | ||
| 217 | continue; | 217 | continue; |
| 218 | 218 | ||
| 219 | fd = open(p->fullpath, O_RDWR); | 219 | fd = open(p->fullpath, O_RDWR); |
| 220 | if(fd < 0) { | 220 | if(fd < 0) { |
| 221 | #ifdef TESTING | 221 | #ifdef TESTING |
| 222 | error(0, errno, "<encryptvxgg> Could not open \"%s\" for encryption", p->fullpath); | 222 | error(0, 0, "<decryptvxgg> Couldn't open \"%s\" for %s", p->fullpath, (flag == VXGG_ENCRYPT) ? "encryption" : "decryption"); |
| 223 | #endif | 223 | #endif |
| 224 | continue; | 224 | continue; |
| 225 | } | 225 | } |
| 226 | |||
| 227 | passencblock(fd, passphrase); | 226 | passencblock(fd, passphrase); |
| 228 | close(fd); | 227 | close(fd); |
| 229 | #ifndef TESTING | 228 | |
| 230 | rename_format(p->fullpath, "%s.vxgg", p->fullpath); | 229 | if(flag == VXGG_ENCRYPT) { |
| 231 | #else | 230 | #ifndef TESTING |
| 232 | rename_format(p->fullpath, "%s_%s.vxgg", p->fullpath, passphrase); | 231 | rename_format(p->fullpath, "%s.vxgg", p->fullpath); |
| 233 | #endif | 232 | #else |
| 233 | rename_format(p->fullpath, "%s_%s.vxgg", p->fullpath, passphrase); | ||
| 234 | #endif | ||
| 235 | } | ||
| 236 | |||
| 237 | if(flag == VXGG_DECRYPT) { | ||
| 238 | char *newname = NULL; | ||
| 239 | #ifndef TESTING | ||
| 240 | asprintf(&newname, "%%0.%lds", strlen(p->fullpath) - strlen(".vxgg")); | ||
| 241 | #else | ||
| 242 | asprintf(&newname, "%%0.%lds", strlen(p->fullpath) - strlen(".vxgg") - PHRASESIZE - 1); | ||
| 243 | #endif | ||
| 244 | rename_format(p->fullpath, newname, p->fullpath); | ||
| 245 | free(newname); | ||
| 246 | } | ||
| 234 | 247 | ||
| 235 | } | 248 | } |
| 236 | 249 | ||
| 250 | /* The beauty of my shitty encryption function is that it's reversible by just running it again with the | ||
| 251 | // same password. Most of this function is just picking the right files to operate on and deciding how to | ||
| 252 | // rename them */ | ||
| 253 | |||
| 237 | return 0; | 254 | return 0; |
| 238 | } | 255 | } |
| 239 | 256 | ||
| 240 | // int decryptvxgg(const struct nodelist *list, const char *passphrase) { | ||
| 241 | |||
| 242 | |||
| 243 | // return 0; | ||
| 244 | // } | ||
| 245 | |||
| 246 | /* | 257 | /* |
| 247 | int main() { | 258 | int main() { |
| 248 | int fd = open("test.txt", O_RDWR); | 259 | int fd = open("test.txt", O_RDWR); |
diff --git a/src/encryption.h b/src/encryption.h index 15dd568..664e4e6 100644 --- a/src/encryption.h +++ b/src/encryption.h | |||
| @@ -13,4 +13,12 @@ size_t passencblock(int fd, const char *passphrase); | |||
| 13 | // Encrypt a nodelist | 13 | // Encrypt a nodelist |
| 14 | int encryptvxgg(const struct nodelist *list, const char *passphrase); | 14 | int encryptvxgg(const struct nodelist *list, const char *passphrase); |
| 15 | 15 | ||
| 16 | // Decrypt a nodelist | ||
| 17 | int decryptvxgg(const struct nodelist *list, const char *passphrase); | ||
| 18 | |||
| 19 | // Encrypt or decrypt a nodelist | ||
| 20 | #define VXGG_ENCRYPT 0 | ||
| 21 | #define VXGG_DECRYPT 1 | ||
| 22 | int ENorDE_cryptvxgg(const struct nodelist *list, const char *passphrase, int flag); | ||
| 23 | |||
| 16 | #endif \ No newline at end of file | 24 | #endif \ No newline at end of file |
