Commit Graph

3241 Commits

Author SHA1 Message Date
Andreas Steffen a488584b5f Implemented SHA-3 hash algorithm including test vectors 2015-11-03 21:35:09 +01:00
Andreas Steffen de61e2cef4 Defined SHA-3 hashers 2015-11-03 19:07:15 +01:00
Tobias Brunner 35dbf8af7a random: Properly handle errors when reading from /dev/[u]random
If -1 was returned on the first call to read() `done` got SIZE_MAX
and the function returned TRUE even though no actual random data had
been allocated.

Fixes #1156.
2015-10-29 16:17:17 +01:00
Tobias Brunner 858148092d Replace usages of sigwait(3) with sigwaitinfo(2)
This is basically the same call, but it has the advantage of being
supported by FreeBSD's valgrind, which sigwait() is not.

References #1106.
2015-10-29 15:38:37 +01:00
Tobias Brunner 5f18e2c371 openssl: Explicitly include openssl/bn.h
If OpenSSL is compiled with OPENSSL_NO_DEPRECATED some of the headers
we include don't include openssl/bn.h anymore.  Therefore, we have to
explicitly include it ourselves where we use BN_* functions.

Fixes #1113.
2015-09-16 11:57:52 +02:00
Tobias Brunner dc486823aa unit-tests: Add a test to verify that there is no partial matching of RDNs 2015-09-09 14:39:26 +02:00
Tobias Brunner 7a1fed284c Fixed some typos, courtesy of codespell 2015-08-27 12:06:31 +02:00
Tobias Brunner c605a96d7f Fix some Doxygen issues 2015-08-27 12:03:11 +02:00
Tobias Brunner 0737e936e0 unit-tests: Additional test cases to increase coverage 2015-08-27 11:47:36 +02:00
Tobias Brunner fe2443b01c traffic-selector: Use calc_netbits() in RFC 3779 constructor
This properly detects prefixes encoded as ranges.
2015-08-27 11:47:36 +02:00
Tobias Brunner fdb90723b7 auth-cfg: Don't enforce EAP_RADIUS
Basically the same as e79b0e07e4.  EAP_RADIUS is also a virtual method
that will identify itself as a different EAP method later.
2015-08-21 11:40:07 +02:00
Tobias Brunner 58db4edb2c mem-cred: We don't need a write lock when looking for a certificate 2015-08-20 19:19:37 +02:00
Tobias Brunner 522b1920b6 mem-cred: Add a method to atomically replace all certificates 2015-08-20 19:19:12 +02:00
Tobias Brunner e79b0e07e4 auth-cfg: Don't enforce EAP_DYNAMIC
We now store the actual method on the auth config, which won't match
anymore if rightauth=eap-dynamic is configured.
2015-08-20 18:38:16 +02:00
Andreas Steffen 5e1b06ff08 Defined PWG HCD IF-M attributes 2015-08-18 21:25:38 +02:00
Tobias Brunner 774c8c3847 auth-cfg: Matching one CA should be enough, similar to peer certificates
Not sure if defining multiple CA constraints and enforcing _all_ of them,
i.e. the previous behavior, makes even sense.  To ensure a very specific
chain it should be enough to define the last intermediate CA.  On the
other hand, the ability to define multiple CAs could simplify configuration.

This can currently only be used with swanctl/VICI based configs as `rightca`
only takes a single DN.
2015-08-17 14:04:19 +02:00
Tobias Brunner 017dbb1c5e identification: Remove unused ID_USER_ID type 2015-08-17 11:49:12 +02:00
Tobias Brunner d6f70ff689 plugin-feature: Add vendor specific EAP method registration macros
Vendor specific EAP methods may be registered with:

    PLUGIN_CALLBACK(eap_method_register, <constructor>),
        PLUGIN_PROVIDE(EAP_SERVER_VENDOR, <type>, <vendor>),

Same for client implementations via EAP_PEER_VENDOR.

References #969.
2015-08-17 11:28:08 +02:00
Tobias Brunner 6d9cd1d66b utils: Check for dirfd(3)
Not all POSIX compatible systems might provide it yet.  If not, we close
the lowest FD to close and hope it gets reused by opendir().
2015-08-17 11:19:48 +02:00
Tobias Brunner f25f4192c7 utils: Directly use syscall() to close open FDs in closefrom()
This avoids any allocations, since calling malloc() after fork() is
potentially unsafe.

Fixes #990.
2015-08-17 11:19:44 +02:00
Tobias Brunner b410d7f8ff utils: Don't use directory enumerator to close open FDs in closefrom()
Calling malloc() after fork() is potentially unsafe, so we should avoid
it if possible.  opendir() will still require an allocation but that's
less than the variant using the enumerator wrapper, thus, decreasing
the conflict potential.  This way we can also avoid closing the
FD for the enumerated directory itself.

References #990.
2015-08-17 11:19:32 +02:00
Tobias Brunner 6967948241 Initialize variables that some compilers seem to warn about 2015-08-13 15:12:38 +02:00
Tobias Brunner f809e485fb Fixed some typos 2015-08-13 15:12:34 +02:00
Tobias Brunner 9593b57ca3 identification: Use UTF8String instead of the legacy T61String to encode DNs
When strings in RDNs contain characters outside the character set for
PrintableString use UTF8String as the passed string is most likely in
that encoding (RFC 5280 actually recommends to use only those two
string types).
2015-08-06 17:25:07 +02:00
Tobias Brunner 520fba4899 identification: Add hash() method
Compared to hashing the encoding we can ignore string types of RDNs when
hashing DNs, making hash() compatible to equals() that does the same.

Fixes #991.
2015-08-06 17:22:32 +02:00
Tobias Brunner b2efc61818 pkcs11: Fix encoding of RSA keys if unnecessarily zero prefixed
Some tokens/libraries seem to prefix all numbers with zero bytes even
if not necessary (e.g. the default exponent 0x010001).  If we don't fix
that, the fingerprints calculated based on the retrieved values will be
incorrect.

Even if the pkcs1 plugin can properly handle numbers that are not in
two's complement since a81bd670b0 ("Added PUBKEY_RSA_MODULUS
encoding type") we prefix them with zero if necessary as other encoders
might expect them in two's complement.

Fixes #1012.
2015-08-06 17:15:25 +02:00
Tobias Brunner 7be8965225 printf-hook-builtin: Fix invalid memory access
When precision is given for a string, we must not run unbounded
strlen() as it will read beyond the given length. It might even cause
a crash if the given pointer is near end of heap or mapping.

Fixes numerous valgrind errors such as:

==19215== Invalid read of size 1
==19215==    at 0x52D36C6: builtin_vsnprintf (printf_hook_builtin.c:853)
==19215==    by 0x52D40A8: builtin_snprintf (printf_hook_builtin.c:1084)
==19215==    by 0x52CE464: dntoa (identification.c:337)
==19215==    by 0x52CE464: identification_printf_hook (identification.c:837)
==19215==    by 0x52D3DAA: builtin_vsnprintf (printf_hook_builtin.c:1010)
==19215==    by 0x57040EB: vlog (bus.c:388)
==19215==    by 0x570427D: log_ (bus.c:430)
==19215==    by 0xA8445D3: load_x509_ca (stroke_cred.c:416)
==19215==    by 0xA8445D3: load_certdir (stroke_cred.c:537)
==19215==    by 0xA846A95: load_certs (stroke_cred.c:1353)
==19215==    by 0xA846A95: stroke_cred_create (stroke_cred.c:1475)
==19215==    by 0xA84073E: stroke_socket_create (stroke_socket.c:782)
==19215==    by 0xA83F27C: register_stroke (stroke_plugin.c:53)
==19215==    by 0x52C3125: load_feature (plugin_loader.c:716)
==19215==    by 0x52C3125: load_provided (plugin_loader.c:778)
==19215==    by 0x52C3A20: load_features (plugin_loader.c:799)
==19215==    by 0x52C3A20: load_plugins (plugin_loader.c:1159)
==19215==  Address 0x50cdb42 is 0 bytes after a block of size 2 alloc'd
==19215==    at 0x4C919FE: malloc (vg_replace_malloc.c:296)
==19215==    by 0x52CD198: chunk_printable (chunk.c:759)
==19215==    by 0x52CE442: dntoa (identification.c:334)
==19215==    by 0x52CE442: identification_printf_hook (identification.c:837)
==19215==    by 0x52D3DAA: builtin_vsnprintf (printf_hook_builtin.c:1010)
==19215==    by 0x57040EB: vlog (bus.c:388)
==19215==    by 0x570427D: log_ (bus.c:430)
==19215==    by 0xA8445D3: load_x509_ca (stroke_cred.c:416)
==19215==    by 0xA8445D3: load_certdir (stroke_cred.c:537)
==19215==    by 0xA846A95: load_certs (stroke_cred.c:1353)
==19215==    by 0xA846A95: stroke_cred_create (stroke_cred.c:1475)
==19215==    by 0xA84073E: stroke_socket_create (stroke_socket.c:782)
==19215==    by 0xA83F27C: register_stroke (stroke_plugin.c:53)
==19215==    by 0x52C3125: load_feature (plugin_loader.c:716)
==19215==    by 0x52C3125: load_provided (plugin_loader.c:778)
==19215==    by 0x52C3A20: load_features (plugin_loader.c:799)
==19215==    by 0x52C3A20: load_plugins (plugin_loader.c:1159)
2015-08-04 14:19:26 +02:00
Tobias Brunner d29a4a5e20 unit-tests: Add unit tests for settings_t.load_string[_section] 2015-07-28 13:27:32 +02:00
Tobias Brunner 08b45fc516 settings: Add methods and a constructor to parse settings from strings 2015-07-28 13:27:32 +02:00
Tobias Brunner 0dba2690c4 settings: Extend parser so we can parse settings from a string 2015-07-28 13:27:32 +02:00
Tobias Brunner 764960e8b9 settings: Add support for multi-line strings
Unterminated strings are now an error.
2015-07-28 13:27:32 +02:00
Tobias Brunner 9577b2d148 settings: Don't replace rarely used special characters 2015-07-28 13:27:31 +02:00
Andreas Steffen e57190c312 Use MGF1 with SHA-512 as BLISS random oracle 2015-07-27 22:09:08 +02:00
Markku-Juhani Olavi Saarinen 7b7c510eec Generalize c_indices generation using SHA-512 random oracle.
This generalization allows the ring dimension n to be different
from the current n = 512 and allows kappa to be > 56. Also the
hash octets are consumed in a more consistent manner.
2015-07-27 19:51:51 +02:00
Markku-Juhani Olavi Saarinen 68d8a16830 Fixed several bugs in the BLISS signature generation/verification step.
The c_indices derived from the SHA-512 random oracle consist of
nine bits (0..511). The leftmost 8 bits of each index are taken
on an octet-by-octet basis from the 56 leftmost octets of the
SHA-512 hash. The 9th bit needed for the LSB is taken from the
extra_bits 64 bit unsigned integer which consists of the 8 rightmost
octets of the SHA-512 hash (in network order). If more than 56
indices must be derived then additional rounds of the random oracle
are executed until all kappa c_indices have been determined.

The bug fix shifts the extra_bits value by one bit in each loop
iteration so that the LSB of each index is random. Also iterate
through the hash array using the loop variable j not the c_indices
variable i.
2015-07-27 19:51:50 +02:00
Tobias Brunner 65579569ad host: Properly handle NULL in host_create_from_string[_and_family] 2015-07-27 11:53:26 +02:00
Martin Willi 80d7f44198 unit-tests: Increase failure message buffer to hold larger hex dumps 2015-07-12 13:25:50 +02:00
Martin Willi ee9f691915 unit-tests: Forward variable argument list in TEST_SUITE_DEPEND
For some plugin features, such as crypters or AEADs, we have some additional
feature arguments, such as the key size.
2015-07-12 13:25:50 +02:00
Martin Willi fe5d6eaa9f chapoly: Process two Poly1305 blocks in parallel in SSSE3 driver
By using a derived key r^2 we can improve performance, as we can do loop
unrolling and slightly better utilize SIMD instructions.

Overall ChaCha20-Poly1305 performance increases by ~12%.

Converting integers to/from our 5-word representation in SSE does not seem
to pay off, so we work on individual words.
2015-07-12 13:25:50 +02:00
Martin Willi b499777cbf chapoly: Process four ChaCha20 blocks in parallel in SSSE3 driver
As we don't have to shuffle the state in each ChaCha round, overall performance
for ChaCha20-Poly1305 increases by ~40%.
2015-07-12 13:25:36 +02:00
Martin Willi 755dadcfda chapoly: Add an SSSE3 based driver
We always build the driver on x86/x64, but enable it only if SSSE3 support
is detected during runtime.

Poly1305 uses parallel 32-bit multiplication operands yielding a 64-bit result,
for which two can be done in parallel in SSE. This is minimally faster than
multiplication with 64-bit operands, and also works on 32-bit builds not having
a __int128 result type.

On a 32-bit architecture, this is more than twice as fast as the portable
driver, and on 64-bit it is ~30% faster.
2015-06-29 17:32:14 +02:00
Martin Willi bf86fd7ccc chapoly: Add a ChaCha20/Poly1305 driver implemented in portable C 2015-06-29 17:32:14 +02:00
Martin Willi 370fb3feb0 chapoly: Provide a generic ChaCha20/Poly1305 AEAD supporting driver backends 2015-06-29 17:32:14 +02:00
Martin Willi 82f7f5882f test-vectors: Add some initial ChaCha20/Poly1305 AEAD test vector 2015-06-29 17:32:14 +02:00
Martin Willi b211f283b7 proposal: Add a chacha20poly1305 proposal keyword 2015-06-29 17:32:13 +02:00
Martin Willi 9e110cc54c crypter: Define a ChaCha20/Poly1305 AEAD algorithm identifier 2015-06-29 17:32:03 +02:00
Tobias Brunner b01b331afe capabilities: Handle ERANGE in user and group lookups
As it turns out, getpwnam_r, getgrnam_r, and friends will return
ERANGE if _any_ user or group on the system is larger than will fit
into the scratch buffer you pass to them.

This reworks the resolve_uid and resolve_gid methods plus
init_supplementary_groups to use a variable-size buffer that is grown
until the results fit.

Based on a patch by Evan Broder.

Closes strongswan/strongswan#12.
2015-06-23 10:03:38 +02:00
Tobias Brunner d13c8f8f7f Remove accidentally added stamp-h1
Was added in bc47488323 ("Add a return value to prf_t.get_bytes()").
2015-06-15 14:17:28 +02:00
Tobias Brunner f146104736 settings: Fix out-of-tree build
The header file was created in the source directory before, where it
wasn't found by the generated C files in the build directory.
2015-06-11 12:34:55 +02:00
Tobias Brunner 523ea82ed5 unit-tests: Add tests for iv_gen_seq_t 2015-06-05 13:44:42 +02:00