cryptshield 1.0.1__tar.gz → 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cryptshield-1.0.1 → cryptshield-1.1.0}/LICENSE +1 -1
- {cryptshield-1.0.1/src/cryptshield.egg-info → cryptshield-1.1.0}/PKG-INFO +72 -11
- {cryptshield-1.0.1 → cryptshield-1.1.0}/README.md +68 -8
- {cryptshield-1.0.1 → cryptshield-1.1.0}/pyproject.toml +2 -2
- {cryptshield-1.0.1 → cryptshield-1.1.0}/setup.py +1 -1
- cryptshield-1.1.0/src/cryptshield/__init__.py +4 -0
- {cryptshield-1.0.1 → cryptshield-1.1.0}/src/cryptshield/cryptshield.py +172 -49
- cryptshield-1.1.0/src/cryptshield/metadata_cleaner.py +642 -0
- {cryptshield-1.0.1 → cryptshield-1.1.0/src/cryptshield.egg-info}/PKG-INFO +72 -11
- {cryptshield-1.0.1 → cryptshield-1.1.0}/src/cryptshield.egg-info/SOURCES.txt +1 -0
- cryptshield-1.0.1/src/cryptshield/__init__.py +0 -4
- {cryptshield-1.0.1 → cryptshield-1.1.0}/setup.cfg +0 -0
- {cryptshield-1.0.1 → cryptshield-1.1.0}/src/cryptshield.egg-info/dependency_links.txt +0 -0
- {cryptshield-1.0.1 → cryptshield-1.1.0}/src/cryptshield.egg-info/requires.txt +0 -0
- {cryptshield-1.0.1 → cryptshield-1.1.0}/src/cryptshield.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2023 Wilmer Martinez <
|
|
3
|
+
Copyright (c) 2023 Wilmer Martinez <https://github.com/wilmerm>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: cryptshield
|
|
3
|
-
Version: 1.0
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: Secure Encryption and Deletion Application
|
|
5
|
-
Author
|
|
5
|
+
Author: Wilmer Martinez
|
|
6
6
|
License: MIT License
|
|
7
7
|
|
|
8
|
-
Copyright (c) 2023 Wilmer Martinez <
|
|
8
|
+
Copyright (c) 2023 Wilmer Martinez <https://github.com/wilmerm>
|
|
9
9
|
|
|
10
10
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
11
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -46,22 +46,24 @@ Requires-Python: >=3.10
|
|
|
46
46
|
Description-Content-Type: text/markdown
|
|
47
47
|
License-File: LICENSE
|
|
48
48
|
Requires-Dist: cryptography
|
|
49
|
+
Dynamic: license-file
|
|
49
50
|
|
|
50
|
-
# Secure Encryption and
|
|
51
|
+
# Secure Encryption, Deletion, and Metadata Cleaning Application
|
|
51
52
|
|
|
52
|
-
This Python application allows you to securely encrypt files and directories using the **Fernet** library
|
|
53
|
+
This Python application allows you to securely encrypt files and directories using the **Fernet** library, permanently delete them with the **shred** command, and clean metadata from various file formats. It is useful for protecting sensitive data and ensuring it cannot be recovered.
|
|
53
54
|
|
|
54
55
|
## **Main Features**
|
|
55
56
|
|
|
56
57
|
- **Secure Encryption:** Uses the Fernet library to encrypt files and directories with a user-provided key.
|
|
57
58
|
- **Permanent Deletion:** Securely removes files and directories using the **shred** command.
|
|
59
|
+
- **Metadata Cleaning:** Removes metadata from images, documents, PDFs, and multimedia files while preserving file functionality.
|
|
58
60
|
- **Recursive Processing:** Supports encrypting and deleting files within directories recursively.
|
|
59
61
|
- **User Confirmation Options:** Can be configured to require user confirmation before encrypting or deleting files.
|
|
60
62
|
|
|
61
63
|
## **Requirements**
|
|
62
64
|
|
|
63
65
|
- Python 3.x
|
|
64
|
-
- Required libraries: `cryptography`, `
|
|
66
|
+
- Required libraries: `cryptography`, `piexif`, `pillow`, `PyPDF2`, `python-docx`, `openpyxl`, `mutagen`
|
|
65
67
|
|
|
66
68
|
---
|
|
67
69
|
|
|
@@ -94,26 +96,85 @@ cryptshield decrypt_text "gAAAAABnsO0xV07ndDmt-fO..." secret_key
|
|
|
94
96
|
|
|
95
97
|
# Secure file deletion
|
|
96
98
|
cryptshield delete /path/to/file
|
|
99
|
+
|
|
100
|
+
# Clean metadata from files
|
|
101
|
+
cryptshield clean_metadata /path/to/image.jpg /path/to/document.pdf
|
|
102
|
+
|
|
103
|
+
# Clean metadata with essential information preserved
|
|
104
|
+
cryptshield clean_metadata /path/to/file.jpg true true true
|
|
105
|
+
|
|
106
|
+
# Clean metadata without backup (not recommended)
|
|
107
|
+
cryptshield clean_metadata /path/to/file.pdf false false true
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## **Metadata Cleaning Feature**
|
|
113
|
+
|
|
114
|
+
The metadata cleaning feature provides secure removal of metadata from various file formats while maintaining the primary functionality of files. This feature complies with DoD 5220.22-M standards for secure deletion.
|
|
115
|
+
|
|
116
|
+
### **Supported File Formats**
|
|
117
|
+
|
|
118
|
+
- **Images:** JPEG, PNG, TIFF, GIF
|
|
119
|
+
- Removes: EXIF data, GPS coordinates, camera information, comments, timestamps
|
|
120
|
+
- **Documents:** PDF, DOCX, XLSX, PPTX
|
|
121
|
+
- Removes: Author information, creation/modification dates, comments, document properties, edit history
|
|
122
|
+
- **Multimedia:** MP3, MP4, AVI, MOV, WAV, FLAC
|
|
123
|
+
- Removes: ID3 tags, artist, album, comments, metadata
|
|
124
|
+
- **Text Files:** TXT, RTF
|
|
125
|
+
- Removes: File system metadata where applicable
|
|
126
|
+
|
|
127
|
+
### **Metadata Cleaning Options**
|
|
128
|
+
|
|
129
|
+
1. **preserve_essential** (true/false): Whether to preserve essential metadata like title and creator
|
|
130
|
+
2. **backup** (true/false): Whether to create backups before cleaning (recommended)
|
|
131
|
+
3. **verify** (true/false): Whether to verify metadata removal after cleaning
|
|
132
|
+
|
|
133
|
+
### **Security Features**
|
|
134
|
+
|
|
135
|
+
- **Secure Backup Management:** Creates temporary backups during processing, removes them after successful verification
|
|
136
|
+
- **Verification Process:** Confirms metadata has been successfully removed
|
|
137
|
+
- **Audit Logging:** Detailed logs of all metadata cleaning operations
|
|
138
|
+
- **DoD 5220.22-M Compliance:** Follows secure deletion standards
|
|
139
|
+
- **Forensic Recovery Prevention:** Ensures metadata cannot be recovered
|
|
140
|
+
|
|
141
|
+
### **Examples**
|
|
142
|
+
|
|
143
|
+
```sh
|
|
144
|
+
# Basic metadata cleaning
|
|
145
|
+
cryptshield clean_metadata /path/to/photo.jpg
|
|
146
|
+
|
|
147
|
+
# Clean multiple files
|
|
148
|
+
cryptshield clean_metadata /path/to/photo.jpg /path/to/document.pdf /path/to/music.mp3
|
|
149
|
+
|
|
150
|
+
# Preserve essential metadata (title, creator)
|
|
151
|
+
cryptshield clean_metadata /path/to/document.pdf true
|
|
152
|
+
|
|
153
|
+
# Clean without backup (faster, but less safe)
|
|
154
|
+
cryptshield clean_metadata /path/to/file.jpg false
|
|
155
|
+
|
|
156
|
+
# Full control: preserve_essential=false, backup=true, verify=true
|
|
157
|
+
cryptshield clean_metadata /path/to/file.jpg false true true
|
|
97
158
|
```
|
|
98
159
|
|
|
99
160
|
---
|
|
100
161
|
|
|
101
162
|
## Release Information
|
|
102
163
|
|
|
103
|
-
### Version 1.
|
|
164
|
+
### Version 1.1.0
|
|
104
165
|
|
|
105
166
|
You can download the latest release of the **Cryptshield** package as a `.deb` file from the following link:
|
|
106
167
|
|
|
107
|
-
[Download Cryptshield 1.
|
|
168
|
+
[Download Cryptshield 1.1.0 (.deb)](https://github.com/wilmerm/cryptshield/releases/download/v1.1.0/cryptshield_1.1.0_all.deb)
|
|
108
169
|
|
|
109
170
|
### Installation
|
|
110
171
|
|
|
111
172
|
To install the package on your system, run the following command:
|
|
112
173
|
|
|
113
174
|
```bash
|
|
114
|
-
wget https://github.com/wilmerm/cryptshield/releases/download/v1.
|
|
175
|
+
wget https://github.com/wilmerm/cryptshield/releases/download/v1.1.0/cryptshield_1.1.0_all.deb
|
|
115
176
|
|
|
116
|
-
sudo dpkg -i cryptshield_1.
|
|
177
|
+
sudo dpkg -i cryptshield_1.1.0_all.deb
|
|
117
178
|
```
|
|
118
179
|
|
|
119
180
|
After installation, you can run the `cryptshield` command by simply typing:
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
# Secure Encryption and
|
|
1
|
+
# Secure Encryption, Deletion, and Metadata Cleaning Application
|
|
2
2
|
|
|
3
|
-
This Python application allows you to securely encrypt files and directories using the **Fernet** library
|
|
3
|
+
This Python application allows you to securely encrypt files and directories using the **Fernet** library, permanently delete them with the **shred** command, and clean metadata from various file formats. It is useful for protecting sensitive data and ensuring it cannot be recovered.
|
|
4
4
|
|
|
5
5
|
## **Main Features**
|
|
6
6
|
|
|
7
7
|
- **Secure Encryption:** Uses the Fernet library to encrypt files and directories with a user-provided key.
|
|
8
8
|
- **Permanent Deletion:** Securely removes files and directories using the **shred** command.
|
|
9
|
+
- **Metadata Cleaning:** Removes metadata from images, documents, PDFs, and multimedia files while preserving file functionality.
|
|
9
10
|
- **Recursive Processing:** Supports encrypting and deleting files within directories recursively.
|
|
10
11
|
- **User Confirmation Options:** Can be configured to require user confirmation before encrypting or deleting files.
|
|
11
12
|
|
|
12
13
|
## **Requirements**
|
|
13
14
|
|
|
14
15
|
- Python 3.x
|
|
15
|
-
- Required libraries: `cryptography`, `
|
|
16
|
+
- Required libraries: `cryptography`, `piexif`, `pillow`, `PyPDF2`, `python-docx`, `openpyxl`, `mutagen`
|
|
16
17
|
|
|
17
18
|
---
|
|
18
19
|
|
|
@@ -45,26 +46,85 @@ cryptshield decrypt_text "gAAAAABnsO0xV07ndDmt-fO..." secret_key
|
|
|
45
46
|
|
|
46
47
|
# Secure file deletion
|
|
47
48
|
cryptshield delete /path/to/file
|
|
49
|
+
|
|
50
|
+
# Clean metadata from files
|
|
51
|
+
cryptshield clean_metadata /path/to/image.jpg /path/to/document.pdf
|
|
52
|
+
|
|
53
|
+
# Clean metadata with essential information preserved
|
|
54
|
+
cryptshield clean_metadata /path/to/file.jpg true true true
|
|
55
|
+
|
|
56
|
+
# Clean metadata without backup (not recommended)
|
|
57
|
+
cryptshield clean_metadata /path/to/file.pdf false false true
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## **Metadata Cleaning Feature**
|
|
63
|
+
|
|
64
|
+
The metadata cleaning feature provides secure removal of metadata from various file formats while maintaining the primary functionality of files. This feature complies with DoD 5220.22-M standards for secure deletion.
|
|
65
|
+
|
|
66
|
+
### **Supported File Formats**
|
|
67
|
+
|
|
68
|
+
- **Images:** JPEG, PNG, TIFF, GIF
|
|
69
|
+
- Removes: EXIF data, GPS coordinates, camera information, comments, timestamps
|
|
70
|
+
- **Documents:** PDF, DOCX, XLSX, PPTX
|
|
71
|
+
- Removes: Author information, creation/modification dates, comments, document properties, edit history
|
|
72
|
+
- **Multimedia:** MP3, MP4, AVI, MOV, WAV, FLAC
|
|
73
|
+
- Removes: ID3 tags, artist, album, comments, metadata
|
|
74
|
+
- **Text Files:** TXT, RTF
|
|
75
|
+
- Removes: File system metadata where applicable
|
|
76
|
+
|
|
77
|
+
### **Metadata Cleaning Options**
|
|
78
|
+
|
|
79
|
+
1. **preserve_essential** (true/false): Whether to preserve essential metadata like title and creator
|
|
80
|
+
2. **backup** (true/false): Whether to create backups before cleaning (recommended)
|
|
81
|
+
3. **verify** (true/false): Whether to verify metadata removal after cleaning
|
|
82
|
+
|
|
83
|
+
### **Security Features**
|
|
84
|
+
|
|
85
|
+
- **Secure Backup Management:** Creates temporary backups during processing, removes them after successful verification
|
|
86
|
+
- **Verification Process:** Confirms metadata has been successfully removed
|
|
87
|
+
- **Audit Logging:** Detailed logs of all metadata cleaning operations
|
|
88
|
+
- **DoD 5220.22-M Compliance:** Follows secure deletion standards
|
|
89
|
+
- **Forensic Recovery Prevention:** Ensures metadata cannot be recovered
|
|
90
|
+
|
|
91
|
+
### **Examples**
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
# Basic metadata cleaning
|
|
95
|
+
cryptshield clean_metadata /path/to/photo.jpg
|
|
96
|
+
|
|
97
|
+
# Clean multiple files
|
|
98
|
+
cryptshield clean_metadata /path/to/photo.jpg /path/to/document.pdf /path/to/music.mp3
|
|
99
|
+
|
|
100
|
+
# Preserve essential metadata (title, creator)
|
|
101
|
+
cryptshield clean_metadata /path/to/document.pdf true
|
|
102
|
+
|
|
103
|
+
# Clean without backup (faster, but less safe)
|
|
104
|
+
cryptshield clean_metadata /path/to/file.jpg false
|
|
105
|
+
|
|
106
|
+
# Full control: preserve_essential=false, backup=true, verify=true
|
|
107
|
+
cryptshield clean_metadata /path/to/file.jpg false true true
|
|
48
108
|
```
|
|
49
109
|
|
|
50
110
|
---
|
|
51
111
|
|
|
52
112
|
## Release Information
|
|
53
113
|
|
|
54
|
-
### Version 1.
|
|
114
|
+
### Version 1.1.0
|
|
55
115
|
|
|
56
116
|
You can download the latest release of the **Cryptshield** package as a `.deb` file from the following link:
|
|
57
117
|
|
|
58
|
-
[Download Cryptshield 1.
|
|
118
|
+
[Download Cryptshield 1.1.0 (.deb)](https://github.com/wilmerm/cryptshield/releases/download/v1.1.0/cryptshield_1.1.0_all.deb)
|
|
59
119
|
|
|
60
120
|
### Installation
|
|
61
121
|
|
|
62
122
|
To install the package on your system, run the following command:
|
|
63
123
|
|
|
64
124
|
```bash
|
|
65
|
-
wget https://github.com/wilmerm/cryptshield/releases/download/v1.
|
|
125
|
+
wget https://github.com/wilmerm/cryptshield/releases/download/v1.1.0/cryptshield_1.1.0_all.deb
|
|
66
126
|
|
|
67
|
-
sudo dpkg -i cryptshield_1.
|
|
127
|
+
sudo dpkg -i cryptshield_1.1.0_all.deb
|
|
68
128
|
```
|
|
69
129
|
|
|
70
130
|
After installation, you can run the `cryptshield` command by simply typing:
|
|
@@ -159,4 +219,4 @@ If you find value in this project and would like to show your support, please co
|
|
|
159
219
|
|
|
160
220
|
[Donate on PayPal](https://paypal.me/martinezwilmer?country.x=DO&locale.x=es_XC)
|
|
161
221
|
|
|
162
|
-
Your generosity helps us to continue improving and maintaining this project. We appreciate every contribution, however small. Thanks for being part of our community!
|
|
222
|
+
Your generosity helps us to continue improving and maintaining this project. We appreciate every contribution, however small. Thanks for being part of our community!
|
|
@@ -4,9 +4,9 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "cryptshield"
|
|
7
|
-
version = "1.0
|
|
7
|
+
version = "1.1.0"
|
|
8
8
|
authors = [
|
|
9
|
-
{ name = "Wilmer Martinez"
|
|
9
|
+
{ name = "Wilmer Martinez" }
|
|
10
10
|
]
|
|
11
11
|
description = "Secure Encryption and Deletion Application"
|
|
12
12
|
readme = "README.md"
|
|
@@ -9,6 +9,12 @@ from typing import List
|
|
|
9
9
|
|
|
10
10
|
from cryptography.fernet import Fernet, InvalidToken
|
|
11
11
|
|
|
12
|
+
try:
|
|
13
|
+
from .metadata_cleaner import clean_metadata, MetadataCleaner
|
|
14
|
+
except ImportError:
|
|
15
|
+
# For direct script execution
|
|
16
|
+
from metadata_cleaner import clean_metadata, MetadataCleaner
|
|
17
|
+
|
|
12
18
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'src')))
|
|
13
19
|
|
|
14
20
|
|
|
@@ -20,6 +26,36 @@ class CryptshieldError(Exception):
|
|
|
20
26
|
pass
|
|
21
27
|
|
|
22
28
|
|
|
29
|
+
def get_logger(
|
|
30
|
+
name='cryptshield',
|
|
31
|
+
level=logging.INFO,
|
|
32
|
+
filename=None,
|
|
33
|
+
formatter='%(levelname)s - %(message)s',
|
|
34
|
+
):
|
|
35
|
+
logger = logging.getLogger(name)
|
|
36
|
+
logger.setLevel(level)
|
|
37
|
+
|
|
38
|
+
# Create console handler and set level to INFO
|
|
39
|
+
console_handler = logging.StreamHandler()
|
|
40
|
+
console_handler.setLevel(level)
|
|
41
|
+
console_formatter = logging.Formatter('%(message)s')
|
|
42
|
+
console_handler.setFormatter(console_formatter)
|
|
43
|
+
logger.addHandler(console_handler)
|
|
44
|
+
|
|
45
|
+
if filename:
|
|
46
|
+
# Create file handler and set level to INFO
|
|
47
|
+
file_info_handler = logging.FileHandler(filename, mode='w')
|
|
48
|
+
file_info_handler.setLevel(logging.INFO)
|
|
49
|
+
file_formatter = logging.Formatter(formatter)
|
|
50
|
+
file_info_handler.setFormatter(file_formatter)
|
|
51
|
+
logger.addHandler(file_info_handler)
|
|
52
|
+
|
|
53
|
+
return logger
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
logger = get_logger()
|
|
57
|
+
|
|
58
|
+
|
|
23
59
|
def secure_delete(*paths) -> List[str]:
|
|
24
60
|
"""
|
|
25
61
|
Securely deletes a file or directory at the specified path.
|
|
@@ -35,7 +71,7 @@ def secure_delete(*paths) -> List[str]:
|
|
|
35
71
|
|
|
36
72
|
for path in paths:
|
|
37
73
|
if not os.path.exists(path):
|
|
38
|
-
|
|
74
|
+
logger.error(f"Path '{path}' does not exist.")
|
|
39
75
|
continue
|
|
40
76
|
|
|
41
77
|
if os.path.isdir(path):
|
|
@@ -43,41 +79,41 @@ def secure_delete(*paths) -> List[str]:
|
|
|
43
79
|
for file in files:
|
|
44
80
|
file_path = os.path.join(root, file)
|
|
45
81
|
try:
|
|
46
|
-
|
|
82
|
+
logger.info(f"({deleted_count + 1}/{total}) Deleting '{file_path}'...")
|
|
47
83
|
subprocess.run(["shred", "-f", "-u", "-n", "3", "-z", file_path], check=True)
|
|
48
84
|
deleted_paths.append(file_path)
|
|
49
85
|
deleted_count += 1
|
|
50
86
|
except subprocess.CalledProcessError as e:
|
|
51
|
-
|
|
87
|
+
logger.error(f"Error deleting file '{file_path}': {e}")
|
|
52
88
|
|
|
53
89
|
for dir_ in dirs:
|
|
54
90
|
dir_path = os.path.join(root, dir_)
|
|
55
91
|
try:
|
|
56
|
-
|
|
92
|
+
logger.info(f"({deleted_count + 1}/{total}) Deleting '{dir_path}'...")
|
|
57
93
|
os.rmdir(dir_path)
|
|
58
94
|
deleted_paths.append(dir_path)
|
|
59
95
|
deleted_count += 1
|
|
60
96
|
except OSError as e:
|
|
61
|
-
|
|
97
|
+
logger.error(f"Error deleting directory '{dir_path}': {e}")
|
|
62
98
|
|
|
63
99
|
try:
|
|
64
|
-
|
|
100
|
+
logger.info(f"({deleted_count + 1}/{total}) Deleting '{path}'...")
|
|
65
101
|
os.rmdir(path)
|
|
66
102
|
deleted_paths.append(path)
|
|
67
103
|
deleted_count += 1
|
|
68
104
|
except OSError as e:
|
|
69
|
-
|
|
105
|
+
logger.error(f"Error deleting directory '{path}': {e}")
|
|
70
106
|
|
|
71
107
|
else:
|
|
72
108
|
try:
|
|
73
|
-
|
|
109
|
+
logger.info(f"({deleted_count + 1}/{total}) Deleting '{path}'...")
|
|
74
110
|
subprocess.run(["shred", "-f", "-u", "-n", "3", "-z", path], check=True)
|
|
75
111
|
deleted_paths.append(path)
|
|
76
112
|
deleted_count += 1
|
|
77
113
|
except subprocess.CalledProcessError as e:
|
|
78
|
-
|
|
114
|
+
logger.error(f"Error deleting file '{path}': {e}")
|
|
79
115
|
|
|
80
|
-
|
|
116
|
+
logger.info(f"Deleted {deleted_count} files and directories.")
|
|
81
117
|
return deleted_paths
|
|
82
118
|
|
|
83
119
|
|
|
@@ -110,7 +146,7 @@ def encrypt(path: str, key: str, delete: bool = True):
|
|
|
110
146
|
if os.path.isdir(path):
|
|
111
147
|
|
|
112
148
|
# First, compress the directory into a ZIP file
|
|
113
|
-
|
|
149
|
+
logger.info(f'Compressing directory "{path}"...')
|
|
114
150
|
subprocess.run(['zip', '-r', f'{path}.zip', path], check=True)
|
|
115
151
|
|
|
116
152
|
# Encrypt the ZIP file
|
|
@@ -120,14 +156,14 @@ def encrypt(path: str, key: str, delete: bool = True):
|
|
|
120
156
|
os.rename(f'{path}.zip.{ENCRYPTED}', f'{path}.{ZIPENCRYPTED}')
|
|
121
157
|
|
|
122
158
|
# Delete the original directory and ZIP file
|
|
123
|
-
|
|
159
|
+
logger.info(f'Deleting "{path}.zip"...')
|
|
124
160
|
secure_delete(f'{path}.zip')
|
|
125
161
|
if delete:
|
|
126
|
-
|
|
162
|
+
logger.info(f'Deleting "{path}"...')
|
|
127
163
|
secure_delete(path)
|
|
128
164
|
|
|
129
165
|
elif os.path.isfile(path) or os.path.islink(path):
|
|
130
|
-
|
|
166
|
+
logger.info(f'Encrypting "{path}"...')
|
|
131
167
|
with open(path, 'rb') as file:
|
|
132
168
|
text = file.read()
|
|
133
169
|
encrypted_text = encrypt_text(text, key)
|
|
@@ -135,7 +171,7 @@ def encrypt(path: str, key: str, delete: bool = True):
|
|
|
135
171
|
encrypted_file.write(encrypted_text)
|
|
136
172
|
|
|
137
173
|
if delete:
|
|
138
|
-
|
|
174
|
+
logger.info(f'Deleting "{path}"...')
|
|
139
175
|
secure_delete(path)
|
|
140
176
|
|
|
141
177
|
else:
|
|
@@ -173,7 +209,7 @@ def decrypt(path: str, key: str, delete: bool = True):
|
|
|
173
209
|
decrypt(_path, key, delete=delete)
|
|
174
210
|
|
|
175
211
|
elif os.path.isfile(path) or os.path.islink(path):
|
|
176
|
-
|
|
212
|
+
logger.info(f'Decrypting "{path}"...')
|
|
177
213
|
with open(path, 'rb') as encrypted_file:
|
|
178
214
|
encrypted_text = encrypted_file.read()
|
|
179
215
|
text = decrypt_text(encrypted_text, key, to_str=False)
|
|
@@ -185,12 +221,12 @@ def decrypt(path: str, key: str, delete: bool = True):
|
|
|
185
221
|
file.write(text)
|
|
186
222
|
|
|
187
223
|
# Decompress the ZIP file
|
|
188
|
-
|
|
224
|
+
logger.info(f'Decompressing "{path.replace(f".{ZIPENCRYPTED}", ".zip", 1)}"...')
|
|
189
225
|
subprocess.run(['unzip', path.replace(f'.{ZIPENCRYPTED}', '.zip', 1)], check=True)
|
|
190
226
|
|
|
191
227
|
# Delete the encrypted ZIP file
|
|
192
228
|
if delete:
|
|
193
|
-
|
|
229
|
+
logger.info(f'Deleting "{path}"...')
|
|
194
230
|
secure_delete(path.replace(f'.{ZIPENCRYPTED}', '.zip', 1))
|
|
195
231
|
secure_delete(path)
|
|
196
232
|
else:
|
|
@@ -199,7 +235,7 @@ def decrypt(path: str, key: str, delete: bool = True):
|
|
|
199
235
|
|
|
200
236
|
# Delete the encrypted file
|
|
201
237
|
if delete:
|
|
202
|
-
|
|
238
|
+
logger.info(f'Deleting "{path}"...')
|
|
203
239
|
secure_delete(path)
|
|
204
240
|
|
|
205
241
|
else:
|
|
@@ -229,7 +265,7 @@ def encrypt_text(text: str | bytes, key: str = None) -> bytes:
|
|
|
229
265
|
"""
|
|
230
266
|
if not key:
|
|
231
267
|
key = get_default_key()
|
|
232
|
-
|
|
268
|
+
logger.debug(f'Using default key: {key}')
|
|
233
269
|
|
|
234
270
|
bkey = get_fernet_key(key)
|
|
235
271
|
fernet = Fernet(bkey)
|
|
@@ -262,7 +298,7 @@ def decrypt_text(encrypted_text: str, key: str, to_str: bool = True) -> str | by
|
|
|
262
298
|
"""
|
|
263
299
|
if not key:
|
|
264
300
|
key = get_default_key()
|
|
265
|
-
|
|
301
|
+
logger.debug(f'Using default key: {key}')
|
|
266
302
|
|
|
267
303
|
bkey = get_fernet_key(key)
|
|
268
304
|
fernet = Fernet(bkey)
|
|
@@ -386,29 +422,106 @@ def confirm(prompt: str) -> bool:
|
|
|
386
422
|
return False
|
|
387
423
|
|
|
388
424
|
|
|
389
|
-
def
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
425
|
+
def clean_file_metadata(*args):
|
|
426
|
+
"""
|
|
427
|
+
Clean metadata from files while preserving primary functionality.
|
|
428
|
+
|
|
429
|
+
This function removes metadata from various file formats including:
|
|
430
|
+
- Images: EXIF, GPS, camera info, comments
|
|
431
|
+
- Documents: Author, creation date, edit history, comments
|
|
432
|
+
- Multimedia: ID3 tags, artist, album, etc.
|
|
433
|
+
- PDFs: Document properties, metadata, annotations
|
|
434
|
+
"""
|
|
435
|
+
|
|
436
|
+
# Parse command line arguments
|
|
437
|
+
file_paths = []
|
|
438
|
+
preserve_essential = False
|
|
439
|
+
backup = True
|
|
440
|
+
verify = True
|
|
441
|
+
|
|
442
|
+
for arg in args:
|
|
443
|
+
# Check if it's a boolean-like argument
|
|
444
|
+
if isinstance(arg, str):
|
|
445
|
+
if arg.lower() in ('true', 'yes', '1', 'on'):
|
|
446
|
+
if not file_paths: # First non-file argument is preserve_essential
|
|
447
|
+
preserve_essential = True
|
|
448
|
+
elif preserve_essential is not None: # Second is backup
|
|
449
|
+
backup = True
|
|
450
|
+
else: # Third is verify
|
|
451
|
+
verify = True
|
|
452
|
+
continue
|
|
453
|
+
elif arg.lower() in ('false', 'no', '0', 'off'):
|
|
454
|
+
if not file_paths: # First non-file argument is preserve_essential
|
|
455
|
+
preserve_essential = False
|
|
456
|
+
elif preserve_essential is not None: # Second is backup
|
|
457
|
+
backup = False
|
|
458
|
+
else: # Third is verify
|
|
459
|
+
verify = False
|
|
460
|
+
continue
|
|
461
|
+
|
|
462
|
+
# Otherwise, treat as file path
|
|
463
|
+
file_paths.append(arg)
|
|
464
|
+
|
|
465
|
+
# If we got boolean arguments, we need to re-parse correctly
|
|
466
|
+
# Arguments order: file_paths... preserve_essential backup verify
|
|
467
|
+
if len(args) > 1:
|
|
468
|
+
# Check if last few arguments are booleans
|
|
469
|
+
bool_args = []
|
|
470
|
+
file_args = list(args)
|
|
471
|
+
|
|
472
|
+
# Process from the end to find boolean arguments
|
|
473
|
+
while file_args and isinstance(file_args[-1], str) and file_args[-1].lower() in ('true', 'false', 'yes', 'no', '1', '0', 'on', 'off'):
|
|
474
|
+
bool_args.insert(0, file_args.pop())
|
|
475
|
+
|
|
476
|
+
file_paths = file_args
|
|
477
|
+
|
|
478
|
+
# Parse boolean arguments
|
|
479
|
+
if len(bool_args) >= 1:
|
|
480
|
+
preserve_essential = bool_args[0].lower() in ('true', 'yes', '1', 'on')
|
|
481
|
+
if len(bool_args) >= 2:
|
|
482
|
+
backup = bool_args[1].lower() in ('true', 'yes', '1', 'on')
|
|
483
|
+
if len(bool_args) >= 3:
|
|
484
|
+
verify = bool_args[2].lower() in ('true', 'yes', '1', 'on')
|
|
485
|
+
|
|
486
|
+
expanded_paths = expand_path(file_paths)
|
|
487
|
+
|
|
488
|
+
if not expanded_paths:
|
|
489
|
+
logger.error("No valid files found to process.")
|
|
490
|
+
return
|
|
491
|
+
|
|
492
|
+
logger.info(f"Starting metadata cleaning for {len(expanded_paths)} files...")
|
|
493
|
+
logger.info(f"Settings: preserve_essential={preserve_essential}, backup={backup}, verify={verify}")
|
|
494
|
+
|
|
495
|
+
results = clean_metadata(
|
|
496
|
+
*expanded_paths,
|
|
497
|
+
preserve_essential=preserve_essential,
|
|
498
|
+
backup=backup,
|
|
499
|
+
verify=verify,
|
|
500
|
+
logger=logger
|
|
501
|
+
)
|
|
502
|
+
|
|
503
|
+
# Summary statistics
|
|
504
|
+
successful = sum(1 for r in results if r.success)
|
|
505
|
+
verified = sum(1 for r in results if r.verified)
|
|
506
|
+
failed = len(results) - successful
|
|
507
|
+
|
|
508
|
+
logger.info(f"Metadata cleaning completed:")
|
|
509
|
+
logger.info(f" Successful: {successful}/{len(results)}")
|
|
510
|
+
if verify:
|
|
511
|
+
logger.info(f" Verified: {verified}/{successful}")
|
|
512
|
+
if failed > 0:
|
|
513
|
+
logger.info(f" Failed: {failed}")
|
|
514
|
+
|
|
515
|
+
# List failed files
|
|
516
|
+
failed_files = [r for r in results if not r.success]
|
|
517
|
+
if failed_files:
|
|
518
|
+
logger.error("Failed to clean metadata from:")
|
|
519
|
+
for result in failed_files:
|
|
520
|
+
logger.error(f" {result.file_path}: {result.error}")
|
|
521
|
+
|
|
522
|
+
# Audit summary
|
|
523
|
+
total_metadata_removed = sum(len(r.metadata_removed) for r in results if r.success)
|
|
524
|
+
logger.info(f"AUDIT SUMMARY: Removed {total_metadata_removed} metadata entries from {successful} files")
|
|
412
525
|
|
|
413
526
|
|
|
414
527
|
# Mapping commands to their respective functions
|
|
@@ -418,6 +531,7 @@ COMMAND_MAP = {
|
|
|
418
531
|
"decrypt": decrypt,
|
|
419
532
|
"encrypt_text": encrypt_text,
|
|
420
533
|
"decrypt_text": decrypt_text,
|
|
534
|
+
"clean_metadata": clean_file_metadata,
|
|
421
535
|
}
|
|
422
536
|
|
|
423
537
|
|
|
@@ -435,13 +549,23 @@ def show_help():
|
|
|
435
549
|
decrypt <path> <key> [--delete]: Decrypt encrypted files or directories.
|
|
436
550
|
encrypt_text <text> <key>: Encrypt text using a key.
|
|
437
551
|
decrypt_text <text> <key>: Decrypt encrypted text using a key.
|
|
552
|
+
clean_metadata <path>... [preserve_essential] [backup] [verify]: Clean metadata from files.
|
|
438
553
|
help: Show this help message.
|
|
554
|
+
|
|
555
|
+
Examples:
|
|
556
|
+
# Clean metadata from files
|
|
557
|
+
cryptshield clean_metadata /path/to/image.jpg /path/to/document.pdf
|
|
558
|
+
|
|
559
|
+
# Clean metadata with essential preservation
|
|
560
|
+
cryptshield clean_metadata /path/to/file.jpg true true true
|
|
561
|
+
|
|
562
|
+
# Clean without backup (not recommended)
|
|
563
|
+
cryptshield clean_metadata /path/to/file.pdf false false true
|
|
439
564
|
"""
|
|
440
565
|
)
|
|
441
566
|
|
|
442
567
|
|
|
443
568
|
def main():
|
|
444
|
-
print(sys.argv)
|
|
445
569
|
if len(sys.argv) < 2:
|
|
446
570
|
print(f"Missing arguments. {sys.argv=}")
|
|
447
571
|
show_help()
|
|
@@ -464,14 +588,13 @@ def main():
|
|
|
464
588
|
|
|
465
589
|
# Execute command
|
|
466
590
|
try:
|
|
467
|
-
|
|
468
|
-
if result is not None:
|
|
469
|
-
print(result)
|
|
591
|
+
command(*options)
|
|
470
592
|
except CryptshieldError as e:
|
|
471
593
|
print(f'Error executing command "{command_name}": {str(e)}')
|
|
472
594
|
sys.exit(1)
|
|
473
595
|
|
|
596
|
+
sys.exit(0)
|
|
597
|
+
|
|
474
598
|
|
|
475
599
|
if __name__ == "__main__":
|
|
476
|
-
set_logging()
|
|
477
600
|
main()
|