Commit graph

1763 commits

Author SHA1 Message Date
Paul Kehrer
1d865a8b78 Backport three fixes from master to 2.3.x (#4396)
* make a certificate expire a few years in the future, fixes doctests (#4383)

* make a certificate expire a few years in the future, fixes doctests

👋 to future alex when this test breaks in two years

* short lived certs are a good idea

* Fixes #4388 -- when running the aws-encryption-sdk tests only point pytest at one directory (#4391)

* Fixes #4388 -- when running the aws-encryption-sdk tests only point pytest at one directory

* Drop -l, there's no purpose for how we use these

* Updated wycheproof tests for new upstream vectors (#4378)

* updated tests for upstream wycheproof changes

* Updated AES tests

* oops, flake8
2018-08-14 12:45:29 -04:00
Alex Gaynor
feb134586e Refs #3331 -- integrated wycheproof ECDH tests (#4354)
* Refs #3331 -- integrated wycheproof ECDH tests

* flake8 + missing assert

* Handle this error case

* skip on unsupported

* shouldn't need to try here any more
2018-07-18 18:20:48 +08:00
Paul Kehrer
dfb332da50 improve skip msg when skipping an ECDH test in test_ec (#4355) 2018-07-18 05:12:15 -05:00
Paul Kehrer
4de004955b add wycheproof gcm tests (#4349)
* add wycheproof gcm tests

* add AEAD test
2018-07-17 12:44:55 -04:00
Paul Kehrer
db62ec9967 also check iv length for GCM nonce in AEAD (#4350)
* also check iv length for GCM nonce in AEAD

* ugh
2018-07-17 12:06:10 -04:00
Paul Kehrer
12a1cacb6a raise ValueError on zero length GCM IV (#4348) 2018-07-17 10:56:12 -04:00
Paul Kehrer
7ca0e46d82 add chacha20poly1305 wycheproof tests (#4345)
* add chacha20poly1305 wycheproof tests

* flake8

* review
2018-07-17 10:40:02 -04:00
Paul Kehrer
14faf3ca00 add wycheproof tests for AES CMAC (#4344)
* add wycheproof tests for AES CMAC

* review feedback
2018-07-17 10:39:06 -04:00
Paul Kehrer
d4378e4293 disallow implicit tag truncation with finalize_with_tag (#4342) 2018-07-17 09:49:03 -04:00
Alex Gaynor
c574e7554c Refs #3331 -- integrated wycheproof ECDSA tests (#4341)
* Refs #3331 -- integrated wycheproof ECDSA tests

* Also handle these key loading errors

* review

* empty commit to trigger jenkins
2018-07-17 21:20:13 +08:00
Paul Kehrer
160c9b20d4 add aes cbc pkcs5 wycheproof tests (#4347) 2018-07-17 08:27:52 -04:00
Paul Kehrer
d1c73fd782 add DSA wycheproof tests (#4346) 2018-07-17 07:33:05 -04:00
Paul Kehrer
5d18740277 add crl.get_revoked_certificate method (#4331)
* add crl.get_revoked_certificate method

* lexicographic is the best ographic

* rename
2018-07-16 11:19:51 -04:00
Alex Gaynor
2e85a925b4 Refs #3331 -- added initial wycheproof integration, starting with x25519, rsa, and keywrap (#4310)
* Refs #3331 -- added initial wycheproof integration, starting with x25519 tests
2018-07-16 20:48:33 +05:30
Alex Gaynor
b09b9ecd69 Change the exception we raise in keywrap unwrapping on invalid length (#4337)
I believe this can reasonably be considered backwards compatible since other invalid inputs already lead to InvalidUnwrap, and clients shouldn't be distinguishing between these two conditions, and ValueError wasn't documented anyways.
2018-07-16 06:18:57 +05:30
Paul Kehrer
bb23c6c7cb document one shot AEAD length restrictions (#4322)
* document one shot AEAD length restrictions

* write a test that won't consume infinity ram

continue to raise OverflowError since that's what cffi did.

* this applies to associated_data too

* remove unneeded arg

* review feedback on docs
2018-07-14 23:45:16 -04:00
Paul Kehrer
0fba4e28de raise valueerror for null x25519 derived keys (#4332)
* raise valueerror for null x25519 derived keys

OpenSSL errors when it hits this edge case and a null shared key is bad
anyway so let's raise an error

* empty commit
2018-07-12 12:49:20 -04:00
Paul Kehrer
43d02e7eab we don't actually care about the errstack here, it's an invalid signature (#4325)
* we don't actually care about the errstack here, it's an invalid signature

We previously had no cases where we could error without getting errors
on the error stack, but wycheproof contains test cases that can error
without adding anything to the stack. Accordingly, we should clear the
stack but raise InvalidSignature no matter what (rather than
InternalError if we have no error msgs)

* add a test
2018-07-10 09:14:45 -04:00
Paul Kehrer
40baa274f9 fix a memory leak when calling X25519PrivateKey.public_key() (#4326) 2018-07-10 07:09:00 -04:00
Paul Kehrer
20ae2c8084 fix encoding BMPString in x509 name entries (#4321)
Previously we encoded them as UTF-8, but as best I can tell in reality a
BMPString is fixed-width basic multilingual plane big endian encoding.
This is basically UCS-2 (aka original Unicode). However, Python doesn't
support UCS-2 encoding so we need to use utf_16_be. This means you can encode
surrogate code points that are invalid in the context of what a
BMPString is supposed to be, but in reality I strongly suspect the sane
encoding ship has sailed and dozens if not hundreds of implementations
both do this and expect other systems to handle their nonsense.
2018-07-09 19:25:02 -04:00
Marti Raudsepp
9e1873af35 Make RelativeDistinguishedName preserve attribtue order (#4306)
Duplicate attributes now raise an error instead of silently discarding
duplicates.
2018-07-09 18:41:18 +05:30
Paul Kehrer
0a00eaff40 reduce number of deprecated signer/verifier calls in test_rsa (#4314) 2018-07-06 08:43:54 -04:00
Alex Gaynor
e2a0493e98 Fixes #4242 -- added an additional assert to make this test more resillient (#4308) 2018-07-04 20:16:36 +05:30
Alex Gaynor
58fd9c412a Perform an OPENSSL_cleanup before checking the heap in our memleak tests (#4293)
* Perform an OPENSSL_cleanup before checking the heap in our memleak tests

* Make this binding conditional

* typo

* need to put this call before we reset the function ptrs
2018-06-20 10:50:33 -05:00
Vladyslav Moisieienkov
2d0afd3485 Add clearer message when key type is not bytes (#4289)
* Add clearer message in Cipher when key is not bytes

* Change location of key type check to verify_key_size function

* Replace formated error message with static

* Add key type check tests to all ciphers constructors

* Change key type error message to lowercase
2018-06-20 05:21:33 -07:00
Alex Gaynor
d88d721343 Correctly pass bytes; refs #4289 (#4290) 2018-06-19 22:36:16 -05:00
Alex Gaynor
1b17cb2aa4 Correct pass bytes; refs #4289 (#4291) 2018-06-19 22:36:08 -05:00
Paul Kehrer
0154838307 simplify and parametrize DSA tests (#4267) 2018-05-30 16:00:30 -04:00
Paul Kehrer
830a172072 parametrize a few things in test_ec (#4268) 2018-05-30 09:55:40 -04:00
Eric Brown
50bad375f5 Future proofing use of the six python version constants (#4238)
* Future proofing use of the six python version constants

After reading [1], noticed that cryptography uses a lot of if six.PY3
blocks. The issue with this is that whenever Python 4 is released,
this code in the else block will be executed even though it was
only intended for Python 2.

[1] http://astrofrog.github.io/blog/2016/01/12/stop-writing-python-4-incompatible-code/

Signed-off-by: Eric Brown <browne@vmware.com>

* Use not PY2 instead
2018-05-14 23:47:57 -04:00
David Benjamin
763990efa6 Validate the public/private halves of EC keys on import. (#4241)
* Validate the public/private halves of EC keys on import.

OpenSSL's API is a little finicky. If one sets the public key before the
private key, it does not validate that they match. If set in the other
order, it does validate this.

In particular, KASValidityTest_ECCStaticUnified_NOKC_ZZOnly_init.fax
describes error code 7 as:

  Result = F (7 - IUT's Static private key d changed-prikey validity)

Reordering the two operations makes those tests to fail on key import,
which is what CAVP appears to have intended.

* Wrap to 79 rather than 80 columns
2018-05-14 22:49:24 -04:00
Paul Kehrer
36ad98fd5e Add support for extracting timestamp from a Fernet token (#4229)
* Add API for retrieving the seconds-to-expiry for the token, given a TTL.

* Process PR feedback:

* Do compute the TTL, but just the age of the token. The caller
can decided what to do next.

* Factored out the HMAC signature verification to a separate function.

* Fixed a copy&paste mistake in the test cases

* Tests cleanup.

* `struct` no longer needed

* Document `def age()`

* typo in `age()` documentation

* token, not data

* remove test for TTL expiry that is already covered by the parameterized `test_invalid()`.

* let's call this extract_timestamp and just return timestamp

* review comments

* it's UNIX I know this
2018-05-12 11:57:32 -04:00
Joshua Crowgey
25f2b4e2ed Raise ve on bad gt (#4180)
* Raise a ValueError when conversion to generalizedtime fails

* added test for badasn1time value error

* pep8 compliance

* Addressing code review

+ VE now raises with ```{!r}``` formatting
+ Test now checks that the bad string made it into the VE message

* using ValueError.match
2018-04-03 19:24:06 -04:00
Paul Kehrer
f903da081b fix bug with n % 8 length wrapping on AESKWP (#4160)
* fix bug with n % 8 length wrapping on AESKWP

* review feedback
2018-03-20 13:33:57 -04:00
Alex Gaynor
79748a9e84 Revert "don't allow GeneralNames to be an empty list (#4128)" (#4161)
This breaks the urllib3 tests, as well as several in-the-wild certs

This reverts commit 388d1bd3e9.
2018-03-20 13:12:13 -04:00
Paul Kehrer
cd6cf4aa75 implement AES KW with padding (RFC 5649) (#3880)
* implement AES KW with padding (RFC 5649)

fixes #3791

* oops, 2.2

* make sure this is the right valueerror

* more match

* make key padding easier to read

* review feedback

* review feedback
2018-03-18 22:06:13 -04:00
Paul Kehrer
47a66f19bd Allow DSA q=224 (#4147)
* load Q=224 vectors

* DSA parameters should support 224 for q length

* oxford comma
2018-03-18 10:12:14 -04:00
Paul Kehrer
17c8f126c7 Brainpool curves (#4129)
* added brainpool ec-curves key_length >= 256bit

* limit brainpool curves to the set that appear required + docs

* oops

* typos all around me

* add brainpool ECDH kex tests

* switch to using rfc 7027 vectors

* review feedback

* empty commits are the best
2018-03-15 13:35:10 -04:00
Paul Kehrer
388d1bd3e9 don't allow GeneralNames to be an empty list (#4128)
* don't allow GeneralNames to be an empty list

* flake8
2018-03-05 10:36:08 -05:00
Paul Kehrer
1fdf29e6e0 fix a memory leak in ec derive_private_key (#4096)
* fix a memory leak in ec derive_private_key

fixes #4095

* pep8!
2018-02-04 09:24:07 -05:00
Alex Gaynor
d2c12683d3 Fixes #4076 - simplify the implementation of int_from_bytes on python2 (#4077)
* Fixes #4076 - simplify the implementation of int_from_bytes on python2

* whitespace

* Added a test
2018-01-10 08:17:09 -05:00
Paul Kehrer
858a429d88 The HKDF limit is actually 255 * digest_length_in_bytes (#4037)
* The HKDF limit is actually 255 * digest_length_in_bytes

Previously we had a bug where we divided digest_size by 8...but
HashAlgorithm.digest_size is already in bytes.

* test longer output

* changelog
2018-01-06 18:55:27 -05:00
Tux
fbb0c12c87 Expose BN_clear_free in the OpenSSL backend (#4071)
* Expose BN_clear_free

* Use BN_clear_free in test_int_to_bn
2018-01-05 17:44:54 -05:00
Alex Gaynor
5db4e5e77e Fixed #4058 -- use the thread-safe API from OpenSSL, not the danger one (#4059) 2017-12-18 09:24:17 -06:00
Alex Gaynor
740f3cd344 Fixed 120 warnings from the RSA tests (#4052)
* Fixed 120 warnings from the RSA tests

* typo
2017-12-11 08:07:14 +08:00
Alex Gaynor
fe06f3a26e Fixed DSA tests to not emit 200 warnings (#4050) 2017-12-10 15:03:32 +08:00
Alex Gaynor
77c94270bc update the ec tests to not emit 3000 warnings (#4048) 2017-12-10 11:46:07 +08:00
Alex Gaynor
0242c08ee3 In RSA test vectors, use verify() to avoid warnings (#4047)
* In RSA test vectors, use verify() to avoid warnings

* whoops
2017-12-10 09:58:52 +08:00
Alex Gaynor
b916fa9def Fixed deprecation warnings in x509 tests (#4040) 2017-12-04 08:16:22 +08:00
Paul Kehrer
4662d44fd3 Fix ASN1 string type encoding for several Name OIDs (#4035)
* Fix ASN1 string type encoding for several Name OIDs

When we changed over to the new type encoding system we didn't verify
that the new code exactly matched the ASN1 string types that OpenSSL was
previously choosing. This caused serialNumber, dnQualifier,
emailAddress, and domainComponent to change from their proper encodings
to UTF8String as of version 2.1.

Now we check to see if there's a sentinel value (indicating no custom
type has been passed) and then check if the OID has a different default
than UTF8. If it does, we set it.

This PR also adds tests for the ASN1 string type of ever supported
NameOID.

* review feedback
2017-11-30 20:48:56 -06:00