Commit Graph

3684 Commits

Author SHA1 Message Date
Tobias Brunner d3329ee540 wolfssl: Fixes, code style changes and some refactorings
The main fixes are

 * the generation of fingerprints for RSA, ECDSA, and EdDSA
 * the encoding of ECDSA private keys
 * calculating p and q for RSA private keys
 * deriving the public key for raw Ed25519 private keys

Also, instead of numeric literals for buffer lengths ASN.1 related
constants are used.
2019-04-24 12:26:08 +02:00
Tobias Brunner 59be02519a unit-tests: Add tests for ECDSA fingerprints and encoding 2019-04-24 11:40:14 +02:00
Tobias Brunner 179aa72fdf unit-tests: Add tests for RSA fingerprints and encoding 2019-04-24 11:40:14 +02:00
Tobias Brunner a5a8f2bce2 chunk: Add helper to copy a chunk left-padded to a certain length 2019-04-24 11:40:14 +02:00
Sean Parkinson c92eade82c wolfssl: Add wolfSSL plugin for cryptographic implementations 2019-04-24 11:40:14 +02:00
Tobias Brunner 9347f72494 ipsec-types: Move allocation of unique interface IDs to helper function 2019-04-04 09:31:38 +02:00
Tobias Brunner 07166ce25e ipsec-types: Add helper to parse interface ID 2019-04-03 12:00:08 +02:00
Tobias Brunner a21710d380 openssl: Add support for ChaCha20-Poly1305
It's available since OpenSSL 1.1.0.
2019-03-08 15:55:52 +01:00
Tobias Brunner 8fc6b2d0e0 openssl: Generalize the GCM implementation a bit
This will allow us to use the implementation also for other algorithms.
2019-03-08 15:55:52 +01:00
Tobias Brunner d091703a9e agent: Don't keep socket to ssh/gpg-agent open
Instead, create a socket when necessary.  Apparently, it can prevent
the agent from getting terminated (e.g. during system shutdown) if e.g.
charon-nm is still running with an open connection to the agent.
2019-02-20 10:43:19 +01:00
Tobias Brunner 220b0cb29c unit-tests: Verify that E and emailAddress result in the same ID 2019-01-18 11:15:16 +01:00
Tobias Brunner db82c0f594 Fixed some typos, courtesy of codespell 2018-12-18 11:14:19 +01:00
Tobias Brunner 322daff844 openssl: Make sure to release the functional ENGINE reference
The functional reference created by ENGINE_init() was never released,
only the structural one created by ENGINE_by_id().  The functional
reference includes an implicit structural reference, which is also
released by ENGINE_finish().

Closes strongswan/strongswan#119.
2018-12-12 12:00:29 +01:00
Tobias Brunner 25e62f01ea unit-tests: Add test suite for Ed448
Same issue with signature malleability as with Ed25519 and apparently
OpenSSL doesn't even explicitly verify that the most significant 10 bits
are all zero.
2018-11-30 15:57:35 +01:00
Tobias Brunner 8d7bf5b039 unit-tests: Add fingerprint test vectors for Ed25519 2018-11-30 15:47:21 +01:00
Tobias Brunner 2571898d32 curve25519: Prevent Ed25519 signature malleability
As per RFC 8032, section 5.1.7 (and section 8.4) we have to make sure s, which
is the scalar in the second half of the signature value, is smaller than L.
Without that check, L can be added to most signatures at least once to create
another valid signature for the same public key and message.

This could be problematic if, for instance, a blacklist is based on hashes
of certificates.  A new certificate could be created with a different
signature (without knowing the signature key) by simply adding L to s.

Currently, both OpenSSL 1.1.1 and Botan 2.8.0 are vulnerable to this, which is
why the unit test currently only warns about it.
2018-11-30 15:35:01 +01:00
Tobias Brunner 69756c0bff openssl: Use separate DRBG for RNG_STRONG and RNG_TRUE with OpenSSL 1.1.1
OpenSSL 1.1.1 introduces DRGBs and provides two sources (same security
profile etc. but separate internal state), which allows us to use one for
RNG_WEAK (e.g. for nonces that are directly publicly visible) and the other
for stronger random data like keys.
2018-11-30 15:35:01 +01:00
Tobias Brunner 6fc90cea74 leak-detective: Whitelist functions added in OpenSSL 1.1.1 2018-11-30 15:35:01 +01:00
Tobias Brunner cbf07ab5b0 openssl: Add support for Ed25519/Ed448 2018-11-30 15:35:01 +01:00
Tobias Brunner 9dfbe9442b test-vectors: Add vector for X448 2018-11-30 14:54:33 +01:00
Tobias Brunner 57cb4c8d2c openssl: Add support for X25519 and X448
While X25519 was already added with 1.1.0a, its use would be a lot more
complicated, as the helpers like EVP_PKEY_new_raw_public_key() were only
added in 1.1.1, which also added X448.
2018-11-30 14:53:38 +01:00
Tobias Brunner 97c4551ec8 Avoid inclusion of unistd.h in generated lexers
Because the file is not available on all platforms the inclusion comes
after the user options in order to disable including it.  But that means
the inclusion also follows after the defined scanner states, which are
generated as simple #defines to numbers.  If the included unistd.h e.g.
uses variables in function definitions with the same names this could
result in compilation errors.

Interactive mode has to be disabled too as it relies on isatty() from
unistd.h.  Since we don't use the scanners interactively, this is not a
problem and might even make the scanners a bit faster.

Fixes #2806.
2018-11-22 11:17:35 +01:00
Tobias Brunner fa4599d160 gcrypt: Don't use thread callbacks for newer versions of libgcrypt
According to gcrypt.h these callbacks are not used anymore since
version 1.6 and with clang these actually cause deprecation warnings
that let the build on travis (-Werror) fail.
2018-11-21 14:36:38 +01:00
Tobias Brunner f92174dcd1 botan: Initialize p and q before calling calculate_pq() 2018-11-12 17:36:22 +01:00
Tobias Brunner 8eea28063d leak-detective: Use hashtable to cache ignored/whitelisted backtraces
Checking for whitelisted functions in every backtrace is not very
efficient.  And because OpenSSL 1.1 does no proper cleanup anymore until
the process is terminated there are now a lot more "leaks" to ignore.
For instance, in the openssl-ikev2/rw-cert scenario, just starting and
stopping the daemon (test vectors are checked) now causes 3594 whitelisted
leaks compared to the 849 before.  This prolonged the shutdown of the
daemon on each guest in every scenario, amounting to multiple seconds of
additional runtime for every affected scenario.  But even with this
patch there is still some overhead, compared to running the scenarios on
jessie.
2018-11-06 12:27:16 +01:00
Tobias Brunner 0f7055b22c leak-detective: Whitelist additional OpenSSL functions used by libcurl 2018-11-06 12:27:01 +01:00
Tobias Brunner 8b4c2a1d8e openssl: Fix some const issues with OpenSSL 1.1.0 2018-10-31 15:50:36 +01:00
Tobias Brunner fd3947d9e5 openssl: Don't use functions deprecated with OpenSSL 1.1.0 2018-10-31 15:50:36 +01:00
Andreas Steffen 9be6dee6a4 botan: SHA-3 support 2018-10-30 16:06:15 +01:00
Tobias Brunner a61b1a6ee4 mysql: Don't release the connection if transactions are still using it
Fixes #2779.
2018-10-26 11:18:43 +02:00
Tobias Brunner 147363c169 botan: Fix build without specific asymmetric crypto 2018-10-26 11:06:45 +02:00
Tobias Brunner 37ae912271 botan: Fix build without AES and its modes 2018-10-26 11:06:45 +02:00
Tobias Brunner 3f960e38a1 botan: Add support for AES-CCM 2018-10-26 11:06:45 +02:00
Tobias Brunner b1ab9782e2 test-vectors: Add another ChaCha20/Poly1305 test vector from RFC 7539 2018-10-26 11:06:45 +02:00
Tobias Brunner cb7b83017d botan: Add support for ChaCha20/Poly1305 AEAD algorithm 2018-10-26 11:06:45 +02:00
Tobias Brunner 4bcc4bacd4 botan: Add support for Ed25519 keys 2018-10-26 11:06:45 +02:00
Tobias Brunner 5cd24d26e2 botan: Add helper function for signature verification 2018-10-26 11:06:45 +02:00
Tobias Brunner 8f23e64ee5 agent: Support signatures with Ed25519/Ed448 keys 2018-10-26 11:01:10 +02:00
Tobias Brunner 87dd08b139 sshkey: Support encoding Ed25519/Ed448 SSH public keys 2018-10-26 11:01:10 +02:00
Tobias Brunner 7de0729357 sshkey: Add support for parsing Ed25519/Ed448 SSH keys 2018-10-26 11:01:10 +02:00
Tobias Brunner 20f74adbae curve25519: Support loading Ed25519 public keys from simple blobs 2018-10-26 11:01:10 +02:00
Tobias Brunner 153eb8199a agent: Enumerate only the supported signature schemes for RSA keys
SHA-384 is not supported but is selected by signature_schemes_for_key()
for keys between 3072 and 7680 bits.

Since this is only called for IKEv2 signature authentication we don't
even provide SHA-1 anymore.  We always provide both schemes, though,
which is what pubkey-authenticator does too for RSA.

Older agents apparently just ignore the flags and always return a SHA-1
signature.  If that's the case, charon.signature_authentication has to
be disabled.
2018-10-26 09:55:08 +02:00
Tobias Brunner 5e03675a19 agent: Add support for RSA signatures with SHA256 and SHA512 2018-10-26 09:55:07 +02:00
Tobias Brunner ecfe67550d signature-params: Provide option for maximum RSA/PSS salt length
However, the length now has to be resolved early, so we don't operate on
the negative constant values e.g. when generating the encoding.
2018-10-26 09:03:26 +02:00
Tobias Brunner 1c4738325d private-key: Add optional method that returns supported signature schemes 2018-10-25 17:21:32 +02:00
ambiso 6b3dfe9c38 openssl: Remove extra semicolon 2018-10-24 09:49:25 +02:00
ambiso b9e45b5b4a openssl: Remove arbitrary keyid length check 2018-10-24 09:49:18 +02:00
ambiso b148517c6b openssl: Fix invalid keyid length check
Check was designed for base64 conversion, however a hex conversion is
being performed, which requires more memory.
2018-10-24 09:48:56 +02:00
Tobias Brunner 129ab919a8 gmp: Fix buffer overflow with very small RSA keys
Because `keylen` is unsigned the subtraction results in an integer
underflow if the key length is < 11 bytes.

This is only a problem when verifying signatures with a public key (for
private keys the plugin enforces a minimum modulus length) and to do so
we usually only use trusted keys.  However, the x509 plugin actually
calls issued_by() on a parsed certificate to check if it is self-signed,
which is the reason this issue was found by OSS-Fuzz in the first place.
So, unfortunately, this can be triggered by sending an invalid client
cert to a peer.

Fixes: 5955db5b12 ("gmp: Don't parse PKCS1 v1.5 RSA signatures to verify them")
Fixes: CVE-2018-17540
2018-09-26 10:10:48 +02:00
Tobias Brunner 5955db5b12 gmp: Don't parse PKCS1 v1.5 RSA signatures to verify them
Instead we generate the expected signature encoding and compare it to the
decrypted value.

Due to the lenient nature of the previous parsing code (minimum padding
length was not enforced, the algorithmIdentifier/OID parser accepts arbitrary
data after OIDs and in the parameters field etc.) it was susceptible to
Daniel Bleichenbacher's low-exponent attack (from 2006!), which allowed
forging signatures for keys that use low public exponents (i.e. e=3).

Since the public exponent is usually set to 0x10001 (65537) since quite a
while, the flaws in the previous code should not have had that much of a
practical impact in recent years.

Fixes: CVE-2018-16151, CVE-2018-16152
2018-09-21 18:51:58 +02:00