Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a854c3ccf | |||
| 877add0dbf | |||
| 482687cb68 | |||
| e35d94243e |
@@ -1 +0,0 @@
|
|||||||
Test file content for decryption
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
-----BEGIN OTP MESSAGE-----
|
|
||||||
Version: v0.2.72
|
|
||||||
Pad-ChkSum: 97d9d82b5414a9439102f3811fb90ab1d6368a00d33229a18b306476f9d04f82
|
|
||||||
Pad-Offset: 2873419
|
|
||||||
|
|
||||||
iR6J7HHK1Oc6
|
|
||||||
-----END OTP MESSAGE-----
|
|
||||||
|
|
||||||
|
|
||||||
30
otp.c
30
otp.c
@@ -138,11 +138,16 @@ int main(int argc, char* argv[]) {
|
|||||||
// Check for piped input first (before any output)
|
// Check for piped input first (before any output)
|
||||||
int is_pipe_mode = (argc == 1 && has_stdin_data());
|
int is_pipe_mode = (argc == 1 && has_stdin_data());
|
||||||
|
|
||||||
|
// Check for decrypt command with piped input
|
||||||
|
int is_decrypt_pipe = (argc == 2 &&
|
||||||
|
(strcmp(argv[1], "decrypt") == 0 || strcmp(argv[1], "-d") == 0) &&
|
||||||
|
has_stdin_data());
|
||||||
|
|
||||||
// Check for OTP thumb drive on startup
|
// Check for OTP thumb drive on startup
|
||||||
char otp_drive_path[512];
|
char otp_drive_path[512];
|
||||||
if (detect_otp_thumb_drive(otp_drive_path, sizeof(otp_drive_path))) {
|
if (detect_otp_thumb_drive(otp_drive_path, sizeof(otp_drive_path))) {
|
||||||
// Only show messages in interactive/command mode, not pipe mode
|
// Only show messages in interactive/command mode, not pipe mode
|
||||||
if (!is_pipe_mode) {
|
if (!is_pipe_mode && !is_decrypt_pipe) {
|
||||||
printf("Detected OTP thumb drive: %s\n", otp_drive_path);
|
printf("Detected OTP thumb drive: %s\n", otp_drive_path);
|
||||||
printf("Using as default pads directory for this session.\n\n");
|
printf("Using as default pads directory for this session.\n\n");
|
||||||
}
|
}
|
||||||
@@ -1621,38 +1626,59 @@ int decrypt_text_silent(const char* pad_identifier, const char* encrypted_messag
|
|||||||
char base64_data[MAX_INPUT_SIZE * 2] = {0};
|
char base64_data[MAX_INPUT_SIZE * 2] = {0};
|
||||||
int in_data_section = 0;
|
int in_data_section = 0;
|
||||||
|
|
||||||
|
fprintf(stderr, "DEBUG: decrypt_text_silent called\n");
|
||||||
|
fprintf(stderr, "DEBUG: encrypted_message is %s\n", encrypted_message ? "not NULL" : "NULL");
|
||||||
|
|
||||||
if (encrypted_message != NULL) {
|
if (encrypted_message != NULL) {
|
||||||
|
fprintf(stderr, "DEBUG: Message length: %lu\n", strlen(encrypted_message));
|
||||||
|
fprintf(stderr, "DEBUG: First 50 chars: %.50s\n", encrypted_message);
|
||||||
|
|
||||||
// Parse provided encrypted message
|
// Parse provided encrypted message
|
||||||
char *message_copy = strdup(encrypted_message);
|
char *message_copy = strdup(encrypted_message);
|
||||||
char *line_ptr = strtok(message_copy, "\n");
|
char *line_ptr = strtok(message_copy, "\n");
|
||||||
|
|
||||||
int found_begin = 0;
|
int found_begin = 0;
|
||||||
while (line_ptr != NULL) {
|
while (line_ptr != NULL) {
|
||||||
|
fprintf(stderr, "DEBUG: Processing line: '%s'\n", line_ptr);
|
||||||
|
|
||||||
if (strcmp(line_ptr, "-----BEGIN OTP MESSAGE-----") == 0) {
|
if (strcmp(line_ptr, "-----BEGIN OTP MESSAGE-----") == 0) {
|
||||||
found_begin = 1;
|
found_begin = 1;
|
||||||
|
fprintf(stderr, "DEBUG: Found BEGIN header\n");
|
||||||
}
|
}
|
||||||
else if (strcmp(line_ptr, "-----END OTP MESSAGE-----") == 0) {
|
else if (strcmp(line_ptr, "-----END OTP MESSAGE-----") == 0) {
|
||||||
|
fprintf(stderr, "DEBUG: Found END header\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (found_begin) {
|
else if (found_begin) {
|
||||||
if (strncmp(line_ptr, "Pad-ChkSum: ", 12) == 0) {
|
if (strncmp(line_ptr, "Pad-ChkSum: ", 12) == 0) {
|
||||||
strncpy(stored_chksum, line_ptr + 12, 64);
|
strncpy(stored_chksum, line_ptr + 12, 64);
|
||||||
stored_chksum[64] = '\0';
|
stored_chksum[64] = '\0';
|
||||||
|
fprintf(stderr, "DEBUG: Found checksum: %.16s...\n", stored_chksum);
|
||||||
}
|
}
|
||||||
else if (strncmp(line_ptr, "Pad-Offset: ", 12) == 0) {
|
else if (strncmp(line_ptr, "Pad-Offset: ", 12) == 0) {
|
||||||
pad_offset = strtoull(line_ptr + 12, NULL, 10);
|
pad_offset = strtoull(line_ptr + 12, NULL, 10);
|
||||||
|
fprintf(stderr, "DEBUG: Found offset: %lu\n", pad_offset);
|
||||||
}
|
}
|
||||||
else if (strlen(line_ptr) == 0) {
|
else if (strlen(line_ptr) == 0) {
|
||||||
in_data_section = 1;
|
in_data_section = 1;
|
||||||
|
fprintf(stderr, "DEBUG: Entering data section\n");
|
||||||
}
|
}
|
||||||
else if (in_data_section) {
|
else if (in_data_section) {
|
||||||
strncat(base64_data, line_ptr, sizeof(base64_data) - strlen(base64_data) - 1);
|
strncat(base64_data, line_ptr, sizeof(base64_data) - strlen(base64_data) - 1);
|
||||||
|
fprintf(stderr, "DEBUG: Added data line: %s\n", line_ptr);
|
||||||
|
}
|
||||||
|
else if (strncmp(line_ptr, "Version:", 8) != 0 && strncmp(line_ptr, "Pad-", 4) != 0) {
|
||||||
|
// This might be base64 data without a blank line separator
|
||||||
|
strncat(base64_data, line_ptr, sizeof(base64_data) - strlen(base64_data) - 1);
|
||||||
|
fprintf(stderr, "DEBUG: Added potential data line: %s\n", line_ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
line_ptr = strtok(NULL, "\n");
|
line_ptr = strtok(NULL, "\n");
|
||||||
}
|
}
|
||||||
free(message_copy);
|
free(message_copy);
|
||||||
|
|
||||||
|
fprintf(stderr, "DEBUG: Parsing complete. found_begin=%d, base64_data='%s'\n", found_begin, base64_data);
|
||||||
|
|
||||||
if (!found_begin) {
|
if (!found_begin) {
|
||||||
fprintf(stderr, "Error: Invalid message format - missing BEGIN header\n");
|
fprintf(stderr, "Error: Invalid message format - missing BEGIN header\n");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -1725,7 +1751,7 @@ int decrypt_text_silent(const char* pad_identifier, const char* encrypted_messag
|
|||||||
plaintext[ciphertext_len] = '\0';
|
plaintext[ciphertext_len] = '\0';
|
||||||
|
|
||||||
// Output only the decrypted text - no extra messages
|
// Output only the decrypted text - no extra messages
|
||||||
printf("%s\n", plaintext);
|
printf("%s", plaintext);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
free(ciphertext);
|
free(ciphertext);
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
Testing updated files directory functionality
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Testing files directory functionality
|
|
||||||
BIN
test_new.txt.otp
BIN
test_new.txt.otp
Binary file not shown.
Reference in New Issue
Block a user