Commit Graph

11 Commits

Author SHA1 Message Date
Thomas Haller
116ee7a4bf libnm/crypto: clean crypto implementations for gnutls/nss
- refactor to use cleanup attribute and return-early

- reorder some code
2018-09-04 07:38:30 +02:00
Thomas Haller
08c80dd2e3 libnm/crypto: rework endianness detection for crypto_verify_pkcs12()
At other places, we already use __BYTE_ORDER define to detect endianness.
We don't need multiple mechanisms.

Also note that meson did not do the correct thing as AC_C_BIGENDIAN,
so meson + nss + big-endian was possibly broken.
2018-09-04 07:38:30 +02:00
Thomas Haller
858d5c3e91 libnm/crypto: refactor to use enum for supported ciphers
We need to (and already did) define our own identifier for ciphers,
because the gnutls/nss identifiers must be abstracted.

Don't use a string for that. The number of supported ciphers
is not generic but fixed and known at compiler time. An enum
is better suited.
2018-09-04 07:38:30 +02:00
Thomas Haller
1f550790bb libnm/crypto: remove unused argument key_type for decrypt functions 2018-09-04 07:38:30 +02:00
Thomas Haller
2456298da0 libnm/crypto: adjust signature of crypto functions
- avoid "const gsize" as type for function arguments.

- consistently use "guint8 *" type for binary data, instead
  of "char *", which indicates a NUL terminated C string.
2018-09-04 07:38:30 +02:00
Thomas Haller
67f36f880e libnm/crypto: rename crypto functions used for testing only
- drop nm_crypto_encrypt(). It's not actually used outside of
  "nm-crypto.c".
- rename internal _nm_crypto_*() functions that are only used
  in tests. It's so much nicer to visually recognize functions
  that are used for testing only.
2018-09-04 07:38:30 +02:00
Thomas Haller
4c996da5bc libnm/crypto: use nm_explicit_bzero() instead of plain memset() 2018-09-04 07:38:30 +02:00
Thomas Haller
105254a15b libnm/crypto: rework _nm_crypto_verify_cert() to return boolean
Rename _nm_crypto_verify_cert() to _nm_crypto_verify_x509().
Also, don't let it return a NMCryptoFileFormat result. This
function only checks for a particular format, hence it
should only return true/false.

Also, fix setting error output argument when the function fails.
2018-09-04 07:38:30 +02:00
Thomas Haller
c172675c13 libnm/crypto: rename libnm crypto API to have consistent NM prefix
Follow our convention, that items in headers are all named with
an "NM" prefix.

Also, "nm-crypto-impl.h" contains internal functions that are to be implemented
by the corresponding crypto backends. Distinguish their names as well.
2018-09-04 07:38:30 +02:00
Thomas Haller
6435040881 libnm/crypto: add header "nm-crypto-impl.h" for crypto implementation
There are two aspects: the public crypto API that is provided by
"nm-crypto.h" header, and the internal header which crypto backends
need to implement. Split them.
2018-09-04 07:38:30 +02:00
Thomas Haller
4106f2968d libnm/crypto: rename libnm's crypto files
"crypto.h" did not follow our common NM style naming. Rename
the files.
2018-09-04 07:38:30 +02:00