You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@warble.apache.org by hu...@apache.org on 2018/06/26 14:17:57 UTC
[incubator-warble-node] 01/05: pull in changes to crypto from
server repo
This is an automated email from the ASF dual-hosted git repository.
humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-warble-node.git
commit 15e754cc5d28c97fa0d238974870c025aba9564d
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Tue Jun 26 09:01:21 2018 -0500
pull in changes to crypto from server repo
---
plugins/basics/crypto.py | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/plugins/basics/crypto.py b/plugins/basics/crypto.py
index af662a9..291a25a 100644
--- a/plugins/basics/crypto.py
+++ b/plugins/basics/crypto.py
@@ -31,6 +31,7 @@ import cryptography.hazmat.primitives.asymmetric.rsa
import cryptography.hazmat.primitives.asymmetric.utils
import cryptography.hazmat.primitives.asymmetric.padding
import cryptography.hazmat.primitives.hashes
+import hashlib
def keypair(bits = 4096):
""" Generate a private+public key pair for encryption/signing """
@@ -60,6 +61,14 @@ def loadpublic(filepath):
)
return public_key
+def loads(text):
+ """ Loads a public key from a string """
+ public_key = cryptography.hazmat.primitives.serialization.load_pem_public_key(
+ bytes(text, 'ascii', errors = 'strict'),
+ backend=cryptography.hazmat.backends.default_backend()
+ )
+ return public_key
+
def pem(key):
""" Turn a key (public or private) into PEM format """
# Private key?
@@ -75,7 +84,21 @@ def pem(key):
encoding=cryptography.hazmat.primitives.serialization.Encoding.PEM,
format=cryptography.hazmat.primitives.serialization.PublicFormat.SubjectPublicKeyInfo
)
-
+
+
+def fingerprint(key):
+ """ Derives a digest fingerprint from a key """
+ print(type(key))
+ if isinstance(key, cryptography.hazmat.backends.openssl.rsa._RSAPublicKey):
+ _pem = pem(key)
+ print("key is rsa")
+ elif type(key) is str:
+ _pem = bytes(key, 'ascii', errors = 'replace')
+ else:
+ _pem = key
+ sha = hashlib.sha256(_pem).hexdigest()
+ return sha
+
def decrypt(key, text):
""" Decrypt a message encrypted with the public key, by using the private key on-disk """
retval = b""
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@warble.apache.org
For additional commands, e-mail: commits-help@warble.apache.org