Skip to content

Commit 48574fe

Browse files
committed
Crypto - Restrict private key permissions
Set mod to 600 when saving the private key Fixes #111
1 parent 598e94a commit 48574fe

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

cterasdk/lib/crypto.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import os
23
from cryptography.hazmat.primitives.asymmetric import rsa
34
from cryptography.hazmat.primitives.serialization import Encoding, PrivateFormat, PublicFormat, NoEncryption
45

@@ -25,6 +26,7 @@ def save(self, dirpath, key_filename):
2526

2627
logging.getLogger().info('Saving private key.')
2728
path = filesystem.save(dirpath, '{}.pem'.format(key_filename), self.private_key)
29+
os.chmod(path, 0o600)
2830
logging.getLogger().info('Saved private key. %s', {'filepath': path, 'format': 'PEM'})
2931

3032
logging.getLogger().info('Saving public key.')

0 commit comments

Comments
 (0)