Implement `has_sufficient_permissions` function for checking certificate files

This commit is contained in:
Shreya 2021-06-03 16:11:33 +05:30
parent c9a53833e2
commit c1463b4a18
1 changed files with 10 additions and 3 deletions

View File

@ -14,10 +14,17 @@ def setup_certificate(config_options: IslandConfigOptions) -> (str, str):
raise FileNotFoundError(f"File not found at {file}. Exiting.")
if not has_sufficient_permissions(file):
raise InsecurePermissionsError(f"{file} has insecure permissions. Exiting.")
raise InsecurePermissionsError(
f"{file} has insecure permissions. Required permissions: r--------. Exiting."
)
return crt_path, key_path
def has_sufficient_permissions():
pass
def has_sufficient_permissions(path: str) -> bool:
required_permissions = "0o400"
file_mode = os.stat(path).st_mode
file_permissions = oct(file_mode & 0o777)
return file_permissions == required_permissions