forked from shaba/openuds
Removed PyCrypto code and translated to cryptography code
This commit is contained in:
parent
f6ddc7eef1
commit
3b18597d8e
@ -29,10 +29,6 @@
|
|||||||
'''
|
'''
|
||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from base64 import b64decode
|
|
||||||
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
@ -41,8 +37,8 @@ import socket
|
|||||||
import stat
|
import stat
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import base64
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from .log import logger
|
from .log import logger
|
||||||
|
|
||||||
@ -53,7 +49,7 @@ _execBeforeExit = []
|
|||||||
sys_fs_enc = sys.getfilesystemencoding() or 'mbcs'
|
sys_fs_enc = sys.getfilesystemencoding() or 'mbcs'
|
||||||
|
|
||||||
# Public key for scripts
|
# Public key for scripts
|
||||||
PUBLIC_KEY = '''-----BEGIN PUBLIC KEY-----
|
PUBLIC_KEY = b'''-----BEGIN PUBLIC KEY-----
|
||||||
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAuNURlGjBpqbglkTTg2lh
|
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAuNURlGjBpqbglkTTg2lh
|
||||||
dU5qPbg9Q+RofoDDucGfrbY0pjB9ULgWXUetUWDZhFG241tNeKw+aYFTEorK5P+g
|
dU5qPbg9Q+RofoDDucGfrbY0pjB9ULgWXUetUWDZhFG241tNeKw+aYFTEorK5P+g
|
||||||
ud7h9KfyJ6huhzln9eyDu3k+kjKUIB1PLtA3lZLZnBx7nmrHRody1u5lRaLVplsb
|
ud7h9KfyJ6huhzln9eyDu3k+kjKUIB1PLtA3lZLZnBx7nmrHRody1u5lRaLVplsb
|
||||||
@ -179,13 +175,21 @@ def verifySignature(script, signature):
|
|||||||
return: Boolean. True if the signature is valid; False otherwise.
|
return: Boolean. True if the signature is valid; False otherwise.
|
||||||
'''
|
'''
|
||||||
# For signature checking
|
# For signature checking
|
||||||
from Crypto.PublicKey import RSA
|
from cryptography.hazmat.backends import default_backend
|
||||||
from Crypto.Signature import PKCS1_v1_5
|
from cryptography.hazmat.primitives import serialization, hashes
|
||||||
from Crypto.Hash import SHA256
|
from cryptography.hazmat.primitives.asymmetric import utils, padding
|
||||||
|
|
||||||
rsakey = RSA.importKey(PUBLIC_KEY)
|
public_key = serialization.load_pem_public_key(data=PUBLIC_KEY)
|
||||||
signer = PKCS1_v1_5.new(rsakey)
|
|
||||||
digest = SHA256.new(script) # Script is "binary string" here
|
try:
|
||||||
if signer.verify(digest, b64decode(signature)):
|
public_key.verify(
|
||||||
return True
|
base64.b64decode(signature),
|
||||||
return False
|
script,
|
||||||
|
padding.PKCS1v15(),
|
||||||
|
hashes.SHA256()
|
||||||
|
)
|
||||||
|
except Exception: # InvalidSignature
|
||||||
|
return False
|
||||||
|
|
||||||
|
# If no exception, the script was fine...
|
||||||
|
return True
|
||||||
|
Loading…
Reference in New Issue
Block a user