Commit Graph

97 Commits

Author SHA1 Message Date
Andrew Zaborowski
977d298c5f libnm-core: 8021x: Allow a new eap value "external"
To allow connections that mirror IWD's configured WPA-Enterprise
networks to be seen as valid by NM, add a new value for the eap key in
802-1x settings.  802-1x.eap stores EAP method names.  In the IWD
connections we don't know what EAP method is configured and we don't
have any of the other 802-1x properties that would be required for the
settings to verify.

These connections can't be activated on devices managed by wpa_supplicant.
2018-09-05 15:24:04 +02:00
Thomas Haller
e3ac45c026 ifcfg-rh: don't use 802-1x certifcate setter functions
The certificate setter function like nm_setting_802_1x_set_ca_cert()
actually load the file from disk, and validate whether it is a valid
certificate. That is very wrong to do.

For one, the certificates are external files, which are not embedded
into the NMConnection. That means, strongly validating the files while
loading the ifcfg files, is wrong because:
 - if validation fails, loading the file fails in its entirety with
   a warning in the log. That is not helpful to the user, who now
   can no longer use nmcli to fix the path of the certificate (because
   the profile failed to load in the first place).
 - even if the certificate is valid at load-time, there is no guarantee
   that it is valid later on, when we actually try to use the file. What
   good does such a validation do? nm_setting_802_1x_set_ca_cert() might
   make sense during nmcli_connection_modify(). At the moment when we
   create or update the profile, we do want to validate the input and
   be helpful to the user. Validating the file later on, when reloading
   the profile from disk seems undesirable.
 - note how keyfile also does not perform such validations (for good
   reasons, I presume).

Also, there is so much wrong with how ifcfg reader handles EAP files.
There is a lot of duplication, and trying to be too smart. I find it
wrong how the "eap_readers" are nested. E.g. both eap_peap_reader() and
"tls" method call to eap_tls_reader(), making it look like that
NMSetting8021x can handle multiple EAP profiles separately. But it cannot. The
802-1x profile is a flat set of properties like ca-cert and others. All
EAP methods share these properties, so having this complex parsing
is not only complicated, but also wrong. The reader should simply parse
the shell variables, and let NMSetting8021x::verify() handle validation
of the settings. Anyway, the patch does not address that.

Also, the setting of the likes of NM_SETTING_802_1X_CLIENT_CERT_PASSWORD was
awkwardly only done when
     privkey_format != NM_SETTING_802_1X_CK_FORMAT_PKCS12
  && scheme == NM_SETTING_802_1X_CK_SCHEME_PKCS11
It is too smart. Just read it from file, if it contains invalid data, let
verify() reject it. That is only partly addressed.

Also note, how writer never actually writes the likes of
IEEE_8021X_CLIENT_CERT_PASSWORD. That is another bug and not fixed
either.
2018-09-04 07:38:30 +02:00
Thomas Haller
9e3ebfdebb libnm/802-1x: refactor getting private-key format
Move similar code to a helper function/macro.
2018-09-04 07:38:30 +02:00
Thomas Haller
068d316822 libnm/802-1x: refactor setting certificate from path
NMSetting8021x has various utility functions to set
the certificate:
  - nm_setting_802_1x_set_ca_cert()
  - nm_setting_802_1x_set_client_cert()
  - nm_setting_802_1x_set_private_key()
  - nm_setting_802_1x_set_phase2_ca_cert()
  - nm_setting_802_1x_set_phase2_client_cert()
  - nm_setting_802_1x_set_phase2_private_key()

They support:

 - accepting a plain PKCS11 URI, with scheme set to
   NM_SETTING_802_1X_CK_SCHEME_PKCS11.
 - accepting a filename, with scheme set to
   NM_SETTING_802_1X_CK_SCHEME_BLOB or
   NM_SETTING_802_1X_CK_SCHEME_PATH.

In the latter case, the function tries to load the file and verify it.
In case of the private-key setters, this also involves accepting a
password. Depending on whether the scheme is BLOB or PATH, the function
will either set the certificate to a PATH blob, or take the blob that
was read from file.

The functions seem misdesigned to me, because their behavior is
rather obscure. E.g. they behave fundamentally different, depending
on whether scheme is PKCS11 or BLOB/PATH.

Anyway, improve them:

- refactor the common code into a function _cert_impl_set(). Previously,
  their non-trivial implementations were copy+pasted several times,
  now they all use the same implementation.
- if the function is going to fail, don't touch the setting. Previously,
  the functions would first clear the certificate before trying to
  validate the input. It's more logical, that if a functions is going
  to fail to check for failure first and don't modify the settings.
- not every blob can be represented. For example, if we have a blob
  which starts with "file://", then there is no way to set it, simply
  because we don't support a prefix for blobs (like "data:;base64,").
  This means, if we try to set the certificate to a particular binary,
  we must check that the binary is interpreted with the expected scheme.
  Add this check.
2018-09-04 07:38:30 +02:00
Thomas Haller
f33dec3067 libnm/802-1x: cleanup NMSetting8021x:verify() 2018-09-04 07:38:30 +02:00
Thomas Haller
5ab6875d4e libnm/802-1x: don't verify certificates in GObject property setter
First of all, g_warning() is not a suitable error handling. In
particular, note how this code is reached when obtaining a setting
from D-Bus, that is, the user is not at fault.

The proper way to handle this, is allowing the setter to set the invalid
value. Only later, during verify() we will fail. This way,
NetworkManager can extend the format and older libnm clients don't
break. This is how forward-compatibility (with older libnm vs. newer
daemon) is supposed to work.
2018-09-04 07:38:30 +02:00
Thomas Haller
53ca365407 libnm/802-1x: refactor certificate handling in settings
- all this code duplication. Add functions and macros to simplify
  the implementation of certificate properties.

Overall, pretty trival. Replace code with a macro.
2018-09-04 07:38:30 +02:00
Thomas Haller
6d6016f83d libnm/802-1x: call g_bytes_unref() directly without checking for NULL
Since its inception, g_bytes_unref() is fine with NULL argument.
2018-09-04 07:38:30 +02:00
Thomas Haller
d0a26c6713 libnm/802-1x/trivial: reorder code 2018-09-04 07:38:30 +02:00
Thomas Haller
1cd1bf7d2f libnm/802-1x: refactor GObject properties of NMSetting8021x 2018-09-04 07:38:30 +02:00
Thomas Haller
b91e60b1d6 libnm: cleanup conversion from NMCryptoFileFormat to NMSetting8021xCKFormat enum 2018-09-04 07:38:30 +02:00
Thomas Haller
44ceb16195 libnm: fix race in nm-setting-x802-1x's setting private key functions
Do not first load the file during nm_crypto_verify_private_key(),
and later re-load it, in case we are setting a blob. Instead,
ensure we only load the file once.

This fixes a race, and also the very wrong assertion:

    priv->phase2_private_key = nm_crypto_read_file (value, NULL);
    nm_assert (priv->phase2_private_key);

We should never assert that an IO operation succeeds.

Also, we encode blobs, paths, and pkcs11 URIs all inside a binary
field. Unfortunately, there is no defined prefix for blobs (TODO).
That means, if you have a blob that happens to start with "file://"
it cannot be expressed. At least, check that the binary field that
we are setting gets detected as correct scheme type.
2018-09-04 07:38:30 +02:00
Thomas Haller
b6377b8082 libnm: clear private-key passwords in NMSetting8021x
Yes, there are countless other places where we don't get this right
and leave sensitive data in memory. Anyway, fix these places.
2018-09-04 07:38:30 +02:00
Thomas Haller
b0c3af6c84 libnm: avoid intermediate GByteArray in path_to_scheme_value()
It's not that to directly initialize the GBytes without an
intermediate GByteArray.
2018-09-04 07:38:30 +02:00
Thomas Haller
2be0bb8287 libnm/crypto: fix loading certificates from file securely
file_to_secure_bytes() tried to load the file from disk and ensure that
the data will be cleared. It did so poorely, because g_file_get_contents()
cannot be used for that.

Add a helper function nm_crypto_read_file() to get this right.
2018-09-04 07:38:30 +02:00
Thomas Haller
896a47da53 libnm/crypto: refactor nm_crypto_load_and_verify_certificate() and return GBytes
The GBytes has a suitable cleanup function, which zeros the certificate
from memory.

Also, all callers that require the certificate, actually later converted
it into a GBytes anyway. This way, they can re-used the same instance
(avoiding an additionaly copying of the data), and they will properly
clear the memory when freed.
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
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
Thomas Haller
98ca7022e3 libnm: fix leaking private-key in nm_setting_802_1x_set_phase2_private_key() 2018-09-04 07:38:30 +02:00
Thomas Haller
3793804314 libnm: rework setting metadata for property handling
NMSetting internally already tracked a list of all proper GObject properties
and D-Bus-only properties.

Rework the tracking of the list, so that:

- instead of attaching the data to the GType of the setting via
  g_type_set_qdata(), it is tracked in a static array indexed by
  NMMetaSettingType. This allows to find the setting-data by simple
  pointer arithmetic, instead of taking a look and iterating (like
  g_type_set_qdata() does).

  Note, that this is still thread safe, because the static table entry is
  initialized in the class-init function with _nm_setting_class_commit().
  And it only accessed by following a NMSettingClass instance, thus
  the class constructor already ran (maybe not for all setting classes,
  but for the particular one that we look up).

  I think this makes initialization of the metadata simpler to
  understand.
  Previously, in a first phase each class would attach the metadata
  to the GType as setting_property_overrides_quark(). Then during
  nm_setting_class_ensure_properties() it would merge them and
  set as setting_properties_quark(). Now, during the first phase,
  we only incrementally build a properties_override GArray, which
  we finally hand over during nm_setting_class_commit().

- sort the property infos by name and do binary search.

Also expose this meta data types as internal API in nm-setting-private.h.
While not accessed yet, it can prove beneficial, to have direct (internal)
access to these structures.

Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct
naming scheme. We already have 40+ subclasses of NMSetting that are called
NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a
new, distinct name.
2018-08-10 10:38:19 +02:00
Thomas Haller
9c47e2ce30 libnm: use NMMetaSettingInfo for tracking setting priority
Previously, each (non abstract) NMSetting class had to register
its name and priority via _nm_register_setting().

Note, that libnm-core.la already links against "nm-meta-setting.c",
which also redundantly keeps track of the settings name and gtype
as well.

Re-use NMMetaSettingInfo also in libnm-core.la, to track this meta
data.

The goal is to get rid of private data structures that track
meta data about NMSetting classes. In this case, "registered_settings"
hash. Instead, we should have one place where all this meta data
is tracked. This was, it is also accessible as internal API,
which can be useful (for keyfile).

Note that NMSettingClass has some overlap with NMMetaSettingInfo.
One difference is, that NMMetaSettingInfo is const, while NMSettingClass
is only initialized during the class_init() method. Appart from that,
it's mostly a matter of taste, whether we attach meta data to
NMSettingClass, to NMMetaSettingInfo, or to a static-array indexed
by NMMetaSettingType.

Note, that previously, _nm_register_setting() was private API. That
means, no user could subclass a functioning NMSetting instance. The same
is still true: NMMetaSettingInfo is internal API and users cannot access
it to create their own NMSetting subclasses. But that is almost desired.
libnm is not designed, to be extensible via subclassing, nor is it
clear why that would be a useful thing to do. One day, we should remove
the NMSetting and NMSettingClass definitions from public headers. Their
only use is subclassing the types, which however does not work.

While libnm-core was linking already against nm-meta-setting.c,
nm_meta_setting_infos was unreferenced. So, this change increases
the binary size of libnm and NetworkManager (1032 bytes). Note however
that roughly the same information was previously allocated at runtime.
2018-08-10 10:38:19 +02:00
Thomas Haller
23adc37377 libnm/trivial: cleanup variable names in settings' class-init functions
- Don't use @parent_class name. This local variable (and @object_class) is
  the class instance up-cast to the pointer types of the parents. The point
  here is not that it is the direct parent. The point is, that it's the
  NMSettingClass type.
  Also, it can only be used inconsistently, in face of NMSettingIP4Config,
  who's parent type is NMSettingIPConfig. Clearly, inside
  nm-setting-ip4-config.c we wouldn't want to use the "parent_class"
  name. Consistently rename @parent_class to @setting_class.

- Also rename the pointer to the own class to @klass. "setting_class" is also the
  wrong name for that, because the right name would be something like
  "setting_6lowpan_class".
  However, "klass" is preferred over the latter, because we commonly create new
  GObject implementations by copying an existing one. Generic names like "klass"
  and "self" inside a type implementation make that simpler.

- drop useless comments like

     /* virtual functions */
     /* Properties */

  It's better to logically and visually structure the code, and avoid trival
  remarks about that. They only end up being used inconsistently. If you
  even need a stronger visual separator, then an 80 char /****/ line
  should be preferred.
2018-08-10 10:38:19 +02:00
Thomas Haller
e1c7a2b5d0 all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.

    $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    587
    $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    21114

One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during

  g_object_set (obj, PROPERTY, (gint) value, NULL);

However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.

Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).

A simple style guide is instead: don't use these typedefs.

No manual actions, I only ran the bash script:

  FILES=($(git ls-files '*.[hc]'))
  sed -i \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>  /\1   /g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
      "${FILES[@]}"
2018-07-11 12:02:06 +02:00
Thomas Haller
fa9fe466db libnm: avoid constructor function for registering NMSetting types
constructor functions are ugly, because code is running before
main() starts. Instead, as the registration code for NMSetting types
is insid the GType constructor, we just need to ensure at the
right place, that the GType was created.

The right place here is _register_settings_ensure_inited(), because
that is called before we need the registration information.
2018-07-01 18:17:31 +02:00
Beniamino Galvani
1b5925ce88 all: remove consecutive empty lines
Normalize coding style by removing consecutive empty lines from C
sources and headers.

https://github.com/NetworkManager/NetworkManager/pull/108
2018-04-30 16:24:52 +02:00
Thomas Haller
51a3d8a861 libnm: make nm_setting_802_1x_set_private_key() self-assignment safe
nmcli calls nm_setting_802_1x_set_private_key() with a password pointer that
it just got from the setting connection itself. Make this less fragile, by
not freeing the current password before assigning it.
2017-12-12 15:19:43 +01:00
Thomas Haller
2730dc60de all: move setting 802-1x.auth-retries to connection.auth-retries
The number of authentication retires is useful also for passwords aside
802-1x settings. For example, src/devices/wifi/nm-device-wifi.c also has
a retry counter and uses a hard-coded value of 3.

Move the setting, so that it can be used in general. Although it is still
not implemented for other settings.

This is an API and ABI break.
2017-11-02 11:41:01 +01:00
Thomas Haller
89e518db5a libnm,cli,ifcfg-rh: add NMSetting8021x:auth-retries property 2017-10-31 19:35:33 +01:00
Beniamino Galvani
a83ab252ee ifcfg-rh: add support for 802-1x.password-raw property
When the ifcfg-rh plugin writes a 802-1x setting it currently ignores
the password-raw property and so the password disappears when the
connection is saved. Add support for the property.
2017-10-31 10:19:49 +01:00
Beniamino Galvani
699492c1a5 libnm-core: 8021x: fix check on private key password
Commit df0dc912cc ("8021x: don't request secrets if they are empty
and system owned") changed need_private_key_password() to return FALSE
when flags are NONE. This broke authentication using an encrypted
private key because after this the key password is never added to the
applied connection.

Don't require a password with NONE flags only for the PKCS11 scheme.

Fixes: df0dc912cc
2017-06-27 10:11:44 +02:00
Thomas Haller
488029d74b libnm: use enum for setting priorities 2017-06-07 09:07:17 +02:00
Lubomir Rintel
7b5712acd2 core: allow two priorities of base settings
We'll need two "base" settings for Bluetooth NAP connections: bridge to set up
the actual link and bluetooth to identify the HCI to register the network
server with.

Let's use two priorities for base setting, with "1" marking one of higher
priority and "2" of lower priority when both are present.
2017-05-31 20:15:01 +02:00
Yuri Chornoivan
0050e8bd34 all: fix typos in documentation, translated strings and comments
https://bugzilla.gnome.org/show_bug.cgi?id=783173
2017-05-28 17:33:37 +02:00
Lubomir Rintel
df0dc912cc 8021x: don't request secrets if they are empty and system owned
Empty secrets are fine. In particular, for PKCS#11 it means that protected
authentication path is used (the secrets are obtained on-demand from the
pinpad).
2017-04-10 10:33:23 +02:00
Yuri Chornoivan
4c6edb22b7 all: fix typos in documentation and comments
https://bugzilla.gnome.org/show_bug.cgi?id=780199

[thaller@redhat.com: reworded commit message]
2017-03-17 15:11:20 +01:00
Thomas Haller
f95b6cadd2 libnm: fix gtk-doc comment for nm_setting_802_1x_get_phase2_ca_cert_password()
Fixes: 538e510473
2017-02-22 13:57:31 +01:00
Beniamino Galvani
556a46959f ifcfg-rh: add support for 802-1x.auth-timeout property 2017-02-21 09:18:53 +01:00
Beniamino Galvani
078bd7b1a9 libnm-core: add auth-timeout property to the 802.1x setting
The property can be used to tune the authentication timeout. It's
especially useful to speed up the failure in case the port doesn't
support 802.1X and make NM try a different, non-authenticated
connection.
2017-02-21 09:18:53 +01:00
Beniamino Galvani
436eec6083 ifcfg-rh: support 802-1x.phase1-auth-alg 2017-02-20 14:06:14 +01:00
Thomas Haller
2a11c57c4e libnm/wifi: rework NMSetting8021xAuthFlags to explicitly disable TLS version
The wpa_supplicant API supports to enable/disable each TLS version
individually, or leave it at the default. Currently, the default
means to enable a TLS version, thus, the only meaningful option
for the momemnt means to explicitly disable it.

In the future, supplicant may disable options by default, and
the inverse option can become interesting to configure
"tls_disable_tlsv1_0=0". When that happens, we can solve it by
adding another flag NM_SETTING_802_1X_AUTH_FLAGS_TLS_1_0_ENABLE.

Change the previous behavior of the NMSetting8021xAuthFlags.
Previously, when not specifying TLS_DISABLE_DEFAULT, all
options were unspecified. On the other hand, when specifying
a single TLS disable flag, all versions were explicitly enabled
or disabled.

Instead, change the meaning of the disable flags. When present,
it explicitly disables an option. But it does not explicitly enable
it.
2017-02-20 14:06:14 +01:00
Leorize
e3a9f1b32a libnm-core/8021x: add phase1-auth-flags configuration items 2017-02-20 13:45:32 +01:00
Thomas Haller
2c9ef8cf2e shared: move NMSetting8021xSchemeVtable to "shared/nm-setting-metadata.h" 2017-02-17 19:52:13 +01:00
Thomas Haller
324cf7ce82 ifcfg-rh: reuse file-suffix from NMSetting8021xSchemeVtable
Keyfile writer computes the file extension and only uses
the file suffix from the vtable.

Do that for ifcfg-rh too. No change in behavior.
2017-02-17 14:24:34 +01:00
Thomas Haller
01b8520447 ifcfg-rh: merge ObjectType with NMSetting8021xSchemeVtable in ifcfg-rh writer 2017-02-17 14:24:34 +01:00
Thomas Haller
1c6b67b0cb libnm-core: add and use internal struct NMSetting8021xSchemeVtable in keyfile 2017-02-17 14:24:34 +01:00
Lubomir Rintel
57e379320e core/8021x: request secrets for keys and certificates PKCS#11 tokens
Unless the secrets are explicitely flagged as not needed we probably require
the PINs.
2017-02-17 14:24:34 +01:00
Lubomir Rintel
538e510473 core/8021x: add password properties for certificates
Useful for certificates that are stored on PKCS#11 tokens. We fail
verification if someone tries tu specify a password for a blob or a flat
file.
2017-02-17 14:24:34 +01:00
Thomas Haller
803467fe93 libnm: fix leak in nm_setting_802_1x_set_phase2_ca_cert()
Fixes: 2b09cee6fa
2017-01-16 17:20:35 +01:00
Lubomir Rintel
33c3ed8991 libnm-core/8021x: don't prefix PKCS#11 URIs with "pkcs11:"
They already include the scheme prefix.
2017-01-10 23:30:18 +01:00
Lubomir Rintel
2b09cee6fa libnm-core/8021x: fix up scheme handling in setters
Fixes: 690e33bdf2
2017-01-06 16:14:13 +01:00