Commit graph

78 commits

Author SHA1 Message Date
Helder Eijs
3200814a9d Raise ValueError when importing asymmetric key from empty string 2019-03-26 23:27:15 +01:00
Helder Eijs
cd7f0128b6 Make code base suitable for Python 2 and 3 - stop using 2to3 2018-11-04 15:04:23 +01:00
Helder Eijs
066b8969ee More cleanup 2018-10-16 22:09:53 +02:00
Helder Eijs
a0f368a381 Add export_key method for RSA and DSA key objects (to replace exportKey) 2018-03-25 22:29:54 +02:00
Helder Eijs
b9eff9a7b6 More information about RSA consistency errors 2017-08-26 22:24:12 +02:00
Helder Eijs
cb8ab4f121 GH#38 Fixed PEM header for RSA/DSA public keys 2017-08-26 12:04:19 +02:00
Helder Eijs
d710dd3e56 Small API doc fixes 2017-08-23 00:10:28 +02:00
Helder Eijs
9b7192abc5 More asymmetric keys APIs 2017-08-14 23:41:07 +02:00
Helder Eijs
d1dad2ed08 Add RSA to API 2017-08-14 07:22:48 +02:00
Legrandin
d5114c5973 Add 'size_in_bits' and 'size_in_bytes' to RsaKey 2016-02-06 23:12:33 +01:00
Legrandin
f9d3939a46 Clean up RSA code (and revert exportKey) 2016-02-06 23:12:33 +01:00
Legrandin
ab4ed2dcc1 Raise NotImplementedError for dangerous, old PyCrypto methods
Closes #6.
2016-02-05 22:10:59 +01:00
Legrandin
c35ac4c3fd Introduce export_key as alias to exportKey for RsaKey and DsaKey 2016-02-04 21:38:30 +01:00
Legrandin
362e0a5087 Introduce import_key as alias to importKey for RSA and DSA. 2016-02-04 18:50:49 +01:00
Legrandin
c7b491de3f Factor out routine creating subjectPublicKeyInfo 2016-01-31 15:04:09 +01:00
Legrandin
577282d020 Simplify DER parsing for PKCS#8 2016-01-24 15:17:59 +01:00
Legrandin
a53023c304 Simplify RSA and DSA import 2016-01-23 21:33:50 +01:00
Legrandin
ab759b3936 Remove the need to consider EOFError when parsing DER 2016-01-23 20:45:28 +01:00
Legrandin
718501e42a Remove Crypto.Util.asn1.newDerBitString 2016-01-23 20:44:40 +01:00
Legrandin
820176457b Remove Crypto.Util.asn1.newDerSequence 2016-01-23 20:44:33 +01:00
Hannes van Niekerk
9c9afa557d Bug fixes on RsaKey class
Remove reference to ".size()" in RsaKey.__repr__ method and return key
size with alternative implementation.
Fix "hasattr" check in RsaKey.__repr__ method.
Fix broken "in" expressions.

Closes #5
2015-11-13 22:05:14 +01:00
Legrandin
7f14313273 Verify that no faults occur during RSA decryption 2015-09-23 08:58:09 +02:00
Legrandin
d97b240d56 Removed parameter verify_x509_cert from importKey (RSA/DSA) 2015-06-30 20:52:22 +00:00
Legrandin
12b75141c4 Minor simplification to DER decoding code 2015-03-18 08:42:04 +01:00
Legrandin
0701df338c Remove ambiguous method size() from RSA, DSA and ElGamal keys 2015-03-13 20:35:38 +01:00
Legrandin
8e4d6f3518 Update to API documentation. 2015-03-13 20:35:37 +01:00
Legrandin
1f3c1b4fcc Remove Crypto.PublicKey.RSA.RSAImplementation
In the process, we add a "randfunc" parameter to
- Crypto.Cipher.PKCS1_OAEP.new()
- Crypto.Cipher.PKCS1_v1_5.new()
- Crypto.Signature.PKCS1_PSS.new()
to set the PRNG used by each algorithm.
Previously, the PRNG was taken from the RSA key itself.
2015-03-11 11:30:33 -04:00
Legrandin
72aff29a65 Update to API documentation. 2015-03-11 11:30:16 -04:00
Legrandin
06501ae142 RSA modulus size is not required to be a multiple of 256 bits anymore.
RSA key method ``size`` returns the same value as
in PyCrypto.

Use LCM for RSA private exponent.
2015-03-05 21:55:03 +01:00
Legrandin
2cb82bb2a6 Remove progress_func from PublicKey objects 2015-02-25 21:42:49 +01:00
Legrandin
00ab349550 Generic filter for prime number generation 2015-02-25 07:40:29 +01:00
Legrandin
ec7f3c8662 Remove _fastmath and _slowmath from code base 2014-12-06 12:04:12 +01:00
Legrandin
eb03c331b3 Base RSA on Math module (WIP) 2014-12-06 12:04:12 +01:00
Legrandin
b7fba1d134 DSA keys can be loaded from X.509 certificates 2014-07-15 23:01:35 +02:00
Legrandin
bd88e52e32 Add validation flag for import from X.509 cert
This patch forces the user to explicitly assert
that no validation of the X.509 certificate will be
done when importing an RSA key.

In other words, public keys can only be imported in the following way:

    >>> cert_data = open("cert.pem", "rb").read()
    >>> key = RSA.importKey(cert_data, verify_x509_cert=False)

Not passing the parameter "verify_x509_cert" will raise an exception.
2014-07-15 23:01:35 +02:00
Legrandin
11651f3b34 Add ability to read in RSA keys from X.509 certs 2014-07-15 23:01:34 +02:00
Legrandin
1c3c049a4c Clean up Crypto.PublicKey module
This patch does a few things to simplify the public key classes
(RSA, DSA and ElGamal):

* It removes the Crypto.PublicKey.pubkey module. The 3 classes
  do not have an ancestor anymore.
* Methods sign(), verify(), encrypt(), and decrypt() are removed.
* Methods blind() and unblind() are removed.
* Methods can_sign() and can_encrypt() are removed.
* The 3 classes cannot be pickled anymore.
2014-06-16 22:00:03 +02:00
Legrandin
d83380a048 Removed support for Python<2.4 2014-06-16 20:36:35 +02:00
Legrandin
5f8632c7ec Merge branch 'raw_rsa_boundary' of https://github.com/Legrandin/pycrypto 2014-05-11 15:58:28 +02:00
Legrandin
4019275161 Extended fix for the RSA boundary check 2014-05-07 12:22:03 +02:00
Legrandin
50cf75c103 FIX #1193521: mpz_powm_sec crashes when modulus is odd
When importing a key, we verify that all components
that will be used as modulus for mpz_powm_sec() are odd.
2013-12-22 13:42:37 +01:00
Legrandin
8acf0d7011 Add checks to verify correctness of RSA/DSA/ElGamal keys
When the various components are assembled into an RSA,
DSA or ElGamal key via the construct() method, we must verify
as much as possible if the result is indeed a valid key.
2013-12-22 13:42:37 +01:00
Legrandin
f9a0fc77e1 FIX #1191411: RSA export example
Closes: https://bugs.launchpad.net/pycrypto/+bug/1191411
2013-07-14 23:08:47 -07:00
Legrandin
90d6d3dbcf Added support for PKCS#8-encrypted private keys.
The patch contains the following changes:

- Private RSA keys can be imported/exported in encrypted form,
  protected according to PKCS#8 and:

  * PBKDF2WithHMAC-SHA1AndDES-EDE3-CBC.
  * PBKDF2WithHMAC-SHA1AndAES128-CBC
  * PBKDF2WithHMAC-SHA1AndAES192-CBC
  * PBKDF2WithHMAC-SHA1AndAES256-CBC

  In addition to that, it is possible to import keys i the
  following weak formats:

  * pbeWithMD5AndDES-CBC
  * pbeWithSHA1AndRC2-CBC
  * pbeWithMD5AndRC2-CBC
  * pbeWithSHA1AndDES-CBC

- The following new module (and 1 new package) are added:

  * Crypto.Util.Padding for simple padding/unpadding logic
  * Crypto.IO._PBES for PBE-related PKCS#5 logic
  * Crypto.IO.PEM for PEM wrapping/unwrapping
  * Crypto.IO.PKCS8 for PKCS#8 wrapping/unwrapping

- All Object ID (OIDs) are now in dotted form to increase
  readability.

- Add AES support to PEM format (decode only).
  The PEM module can decrypt messages protected with AES-CBC.

- Update RSA import test cases.

- Updated to PKCS8 test cases
2013-07-14 21:16:46 -07:00
Frank Sievertsen
db52ac71e8 Fix RSA object serialization 2013-02-16 11:14:09 -08:00
Dwayne C. Litzenberger
125a4f93fa Merge remote-tracking branch 'sebastinas/reenable-tests' 2012-05-28 08:13:54 -04:00
Sebastian Ramacher
8c0572a871 Except shadows builtin IndexError.
Constructs like

 try:
   ...
 except ValueError, IndexError:
   ...

don't work as expected. This only catches a ValueError and replaces the builtin
IndexError with the catches ValueError object. See [1] for details.

[1] http://docs.python.org/whatsnew/2.6.html#pep-3110-exception-handling-changes
2012-05-28 13:32:13 +02:00
Sebastian Ramacher
0c2625df74 Raise a ValueError as documented.
Also add a test case for it.
2012-05-28 13:27:42 +02:00
Sebastian Ramacher
ab25c6fe95 Return a byte string if format is set to OpenSSH.
RSA.exportKey claims to return a byte string, so really return one.
2012-05-28 13:19:22 +02:00
Legrandin
cdcc48b064 Add ability to import RSAPublicKey objects (encoded in DER or PEM) 2012-05-18 22:54:57 +02:00