Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Unified Diff: third_party/tlslite/tlslite/utils/openssl_rsakey.py

Issue 210323002: Update tlslite to 0.4.6. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Executable bit and --similarity=80 Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/tlslite/tlslite/utils/openssl_rsakey.py
diff --git a/third_party/tlslite/tlslite/utils/openssl_rsakey.py b/third_party/tlslite/tlslite/utils/openssl_rsakey.py
index 9cee35d2efc30ef75cf68047dba55f64a2ffc1fd..f6ec8595819ded254b49e78c652ddf1bfb89bb63 100644
--- a/third_party/tlslite/tlslite/utils/openssl_rsakey.py
+++ b/third_party/tlslite/tlslite/utils/openssl_rsakey.py
@@ -1,9 +1,12 @@
+# Author: Trevor Perrin
+# See the LICENSE file for legal information regarding use of this file.
+
"""OpenSSL/M2Crypto RSA implementation."""
-from cryptomath import *
+from .cryptomath import *
-from rsakey import *
-from python_rsakey import Python_RSAKey
+from .rsakey import *
+from .python_rsakey import Python_RSAKey
#copied from M2Crypto.util.py, so when we load the local copy of m2
#we can still use it
@@ -55,33 +58,16 @@ if m2cryptoLoaded:
def hasPrivateKey(self):
return self._hasPrivateKey
- def hash(self):
- return Python_RSAKey(self.n, self.e).hash()
-
def _rawPrivateKeyOp(self, m):
- s = numberToString(m)
- byteLength = numBytes(self.n)
- if len(s)== byteLength:
- pass
- elif len(s) == byteLength-1:
- s = '\0' + s
- else:
- raise AssertionError()
- c = stringToNumber(m2.rsa_private_encrypt(self.rsa, s,
- m2.no_padding))
+ b = numberToByteArray(m, numBytes(self.n))
+ s = m2.rsa_private_encrypt(self.rsa, bytes(b), m2.no_padding)
+ c = bytesToNumber(bytearray(s))
return c
def _rawPublicKeyOp(self, c):
- s = numberToString(c)
- byteLength = numBytes(self.n)
- if len(s)== byteLength:
- pass
- elif len(s) == byteLength-1:
- s = '\0' + s
- else:
- raise AssertionError()
- m = stringToNumber(m2.rsa_public_decrypt(self.rsa, s,
- m2.no_padding))
+ b = numberToByteArray(c, numBytes(self.n))
+ s = m2.rsa_public_decrypt(self.rsa, bytes(b), m2.no_padding)
+ m = bytesToNumber(bytearray(s))
return m
def acceptsPassword(self): return True
@@ -103,9 +89,6 @@ if m2cryptoLoaded:
m2.bio_free(bio)
return s
- def writeXMLPublicKey(self, indent=''):
- return Python_RSAKey(self.n, self.e).write(indent)
-
def generate(bits):
key = OpenSSL_RSAKey()
def f():pass
@@ -115,6 +98,11 @@ if m2cryptoLoaded:
generate = staticmethod(generate)
def parse(s, passwordCallback=None):
+ # Skip forward to the first PEM header
+ start = s.find("-----BEGIN ")
+ if start == -1:
+ raise SyntaxError()
+ s = s[start:]
if s.startswith("-----BEGIN "):
if passwordCallback==None:
callback = password_callback
« no previous file with comments | « third_party/tlslite/tlslite/utils/openssl_rc4.py ('k') | third_party/tlslite/tlslite/utils/openssl_tripledes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698