mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-08 07:18:47 +00:00
Merge pull request #279 from PR0M3TH3AN/codex/fix-permission-error-in-seedpass-windows-installation
Fix Windows file permissions error
This commit is contained in:
@@ -168,8 +168,11 @@ class BackupManager:
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with exclusive_lock(backup_file):
|
with exclusive_lock(backup_file) as fh_src, open(
|
||||||
shutil.copy2(backup_file, self.index_file)
|
self.index_file, "wb"
|
||||||
|
) as dst:
|
||||||
|
fh_src.seek(0)
|
||||||
|
shutil.copyfileobj(fh_src, dst)
|
||||||
logger.info(f"Restored the index file from backup '{backup_file}'.")
|
logger.info(f"Restored the index file from backup '{backup_file}'.")
|
||||||
print(
|
print(
|
||||||
colored(
|
colored(
|
||||||
|
@@ -77,9 +77,11 @@ class EncryptionManager:
|
|||||||
encrypted_data = self.encrypt_data(data)
|
encrypted_data = self.encrypt_data(data)
|
||||||
|
|
||||||
# Write the encrypted data to the file with locking
|
# Write the encrypted data to the file with locking
|
||||||
with exclusive_lock(self.parent_seed_file):
|
with exclusive_lock(self.parent_seed_file) as fh:
|
||||||
with open(self.parent_seed_file, "wb") as f:
|
fh.seek(0)
|
||||||
f.write(encrypted_data)
|
fh.truncate()
|
||||||
|
fh.write(encrypted_data)
|
||||||
|
fh.flush()
|
||||||
|
|
||||||
# Set file permissions to read/write for the user only
|
# Set file permissions to read/write for the user only
|
||||||
os.chmod(self.parent_seed_file, 0o600)
|
os.chmod(self.parent_seed_file, 0o600)
|
||||||
@@ -106,9 +108,9 @@ class EncryptionManager:
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
parent_seed_path = self.fingerprint_dir / "parent_seed.enc"
|
parent_seed_path = self.fingerprint_dir / "parent_seed.enc"
|
||||||
with exclusive_lock(parent_seed_path):
|
with exclusive_lock(parent_seed_path) as fh:
|
||||||
with open(parent_seed_path, "rb") as f:
|
fh.seek(0)
|
||||||
encrypted_data = f.read()
|
encrypted_data = fh.read()
|
||||||
|
|
||||||
decrypted_data = self.decrypt_data(encrypted_data)
|
decrypted_data = self.decrypt_data(encrypted_data)
|
||||||
parent_seed = decrypted_data.decode("utf-8").strip()
|
parent_seed = decrypted_data.decode("utf-8").strip()
|
||||||
@@ -182,9 +184,11 @@ class EncryptionManager:
|
|||||||
encrypted_data = self.encrypt_data(data)
|
encrypted_data = self.encrypt_data(data)
|
||||||
|
|
||||||
# Write the encrypted data to the file with locking
|
# Write the encrypted data to the file with locking
|
||||||
with exclusive_lock(file_path):
|
with exclusive_lock(file_path) as fh:
|
||||||
with open(file_path, "wb") as f:
|
fh.seek(0)
|
||||||
f.write(encrypted_data)
|
fh.truncate()
|
||||||
|
fh.write(encrypted_data)
|
||||||
|
fh.flush()
|
||||||
|
|
||||||
# Set file permissions to read/write for the user only
|
# Set file permissions to read/write for the user only
|
||||||
os.chmod(file_path, 0o600)
|
os.chmod(file_path, 0o600)
|
||||||
@@ -216,9 +220,9 @@ class EncryptionManager:
|
|||||||
file_path = self.fingerprint_dir / relative_path
|
file_path = self.fingerprint_dir / relative_path
|
||||||
|
|
||||||
# Read the encrypted data with locking
|
# Read the encrypted data with locking
|
||||||
with exclusive_lock(file_path):
|
with exclusive_lock(file_path) as fh:
|
||||||
with open(file_path, "rb") as f:
|
fh.seek(0)
|
||||||
encrypted_data = f.read()
|
encrypted_data = fh.read()
|
||||||
|
|
||||||
# Decrypt the data
|
# Decrypt the data
|
||||||
decrypted_data = self.decrypt_data(encrypted_data)
|
decrypted_data = self.decrypt_data(encrypted_data)
|
||||||
@@ -328,9 +332,9 @@ class EncryptionManager:
|
|||||||
file_path = self.fingerprint_dir / relative_path
|
file_path = self.fingerprint_dir / relative_path
|
||||||
logger.debug("Calculating checksum of the encrypted file bytes.")
|
logger.debug("Calculating checksum of the encrypted file bytes.")
|
||||||
|
|
||||||
with exclusive_lock(file_path):
|
with exclusive_lock(file_path) as fh:
|
||||||
with open(file_path, "rb") as f:
|
fh.seek(0)
|
||||||
encrypted_bytes = f.read()
|
encrypted_bytes = fh.read()
|
||||||
|
|
||||||
checksum = hashlib.sha256(encrypted_bytes).hexdigest()
|
checksum = hashlib.sha256(encrypted_bytes).hexdigest()
|
||||||
logger.debug(f"New checksum: {checksum}")
|
logger.debug(f"New checksum: {checksum}")
|
||||||
@@ -338,9 +342,11 @@ class EncryptionManager:
|
|||||||
checksum_file = file_path.parent / f"{file_path.stem}_checksum.txt"
|
checksum_file = file_path.parent / f"{file_path.stem}_checksum.txt"
|
||||||
|
|
||||||
# Write the checksum to the file with locking
|
# Write the checksum to the file with locking
|
||||||
with exclusive_lock(checksum_file):
|
with exclusive_lock(checksum_file) as fh:
|
||||||
with open(checksum_file, "w") as f:
|
fh.seek(0)
|
||||||
f.write(checksum)
|
fh.truncate()
|
||||||
|
fh.write(checksum.encode("utf-8"))
|
||||||
|
fh.flush()
|
||||||
|
|
||||||
# Set file permissions to read/write for the user only
|
# Set file permissions to read/write for the user only
|
||||||
os.chmod(checksum_file, 0o600)
|
os.chmod(checksum_file, 0o600)
|
||||||
@@ -380,9 +386,10 @@ class EncryptionManager:
|
|||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
with exclusive_lock(self.fingerprint_dir / relative_path):
|
file_path = self.fingerprint_dir / relative_path
|
||||||
with open(self.fingerprint_dir / relative_path, "rb") as file:
|
with exclusive_lock(file_path) as fh:
|
||||||
encrypted_data = file.read()
|
fh.seek(0)
|
||||||
|
encrypted_data = fh.read()
|
||||||
|
|
||||||
logger.debug(f"Encrypted index data read from '{relative_path}'.")
|
logger.debug(f"Encrypted index data read from '{relative_path}'.")
|
||||||
return encrypted_data
|
return encrypted_data
|
||||||
|
Reference in New Issue
Block a user