nm-setting-8021x.c 129 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */

/*
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
19 20
 * Copyright 2007 - 2013 Red Hat, Inc.
 * Copyright 2007 - 2008 Novell, Inc.
21
 */
22

23
#include "nm-default.h"
24

25 26
#include "nm-setting-8021x.h"

27 28
#include <string.h>
#include <dbus/dbus-glib.h>
29

30 31
#include "nm-param-spec-specialized.h"
#include "nm-utils.h"
32
#include "nm-dbus-glib-types.h"
33
#include "crypto.h"
34
#include "nm-utils-private.h"
35
#include "nm-setting-private.h"
36

37
/**
Dan Williams's avatar
Dan Williams committed
38
 * SECTION:nm-setting-8021x
39 40 41 42 43
 * @short_description: Describes 802.1x-authenticated connection properties
 * @include: nm-setting-8021x.h
 *
 * The #NMSetting8021x object is a #NMSetting subclass that describes
 * properties necessary for connection to 802.1x-authenticated networks, such as
44
 * WPA and WPA2 Enterprise Wi-Fi networks and wired 802.1x networks.  802.1x
45 46 47 48 49 50 51 52 53
 * connections typically use certificates and/or EAP authentication methods to
 * securely verify, identify, and authenticate the client to the network itself,
 * instead of simply relying on a widely shared static key.
 *
 * It's a good idea to read up on wpa_supplicant configuration before using this
 * setting extensively, since most of the options here correspond closely with
 * the relevant wpa_supplicant configuration options.
 *
 * Furthermore, to get a good idea of 802.1x, EAP, TLS, TTLS, etc and their
54
 * applications to Wi-Fi and wired networks, you'll want to get copies of the
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
 * following books.
 *
 *  802.11 Wireless Networks: The Definitive Guide, Second Edition
 *       Author: Matthew Gast
 *       ISBN: 978-0596100520
 *
 *  Cisco Wireless LAN Security
 *       Authors: Krishna Sankar, Sri Sundaralingam, Darrin Miller, and Andrew Balinsky
 *       ISBN: 978-1587051548
 **/

#define SCHEME_PATH "file://"

/**
 * nm_setting_802_1x_error_quark:
 *
 * Registers an error quark for #NMSetting8021x if necessary.
 *
 * Returns: the error quark used for #NMSetting8021x errors.
 **/
75 76 77 78 79 80 81 82 83 84
GQuark
nm_setting_802_1x_error_quark (void)
{
	static GQuark quark;

	if (G_UNLIKELY (!quark))
		quark = g_quark_from_static_string ("nm-setting-802-1x-error-quark");
	return quark;
}

85 86 87 88 89 90
G_DEFINE_TYPE_WITH_CODE (NMSetting8021x, nm_setting_802_1x, NM_TYPE_SETTING,
                         _nm_register_setting (NM_SETTING_802_1X_SETTING_NAME,
                                               g_define_type_id,
                                               2,
                                               NM_SETTING_802_1X_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_802_1X)
91

92 93
#define NM_SETTING_802_1X_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_802_1X, NMSetting8021xPrivate))

94 95 96 97 98
G_STATIC_ASSERT ( (NM_SETTING_802_1X_CK_FORMAT_UNKNOWN == (NMSetting8021xCKFormat) NM_CRYPTO_FILE_FORMAT_UNKNOWN) );
G_STATIC_ASSERT ( (NM_SETTING_802_1X_CK_FORMAT_X509    == (NMSetting8021xCKFormat) NM_CRYPTO_FILE_FORMAT_X509) );
G_STATIC_ASSERT ( (NM_SETTING_802_1X_CK_FORMAT_RAW_KEY == (NMSetting8021xCKFormat) NM_CRYPTO_FILE_FORMAT_RAW_KEY) );
G_STATIC_ASSERT ( (NM_SETTING_802_1X_CK_FORMAT_PKCS12  == (NMSetting8021xCKFormat) NM_CRYPTO_FILE_FORMAT_PKCS12) );

99 100 101 102
typedef struct {
	GSList *eap; /* GSList of strings */
	char *identity;
	char *anonymous_identity;
103
	char *pac_file;
104 105
	GByteArray *ca_cert;
	char *ca_path;
106 107
	char *subject_match;
	GSList *altsubject_matches;
108 109 110 111 112 113 114 115
	GByteArray *client_cert;
	char *phase1_peapver;
	char *phase1_peaplabel;
	char *phase1_fast_provisioning;
	char *phase2_auth;
	char *phase2_autheap;
	GByteArray *phase2_ca_cert;
	char *phase2_ca_path;
116 117
	char *phase2_subject_match;
	GSList *phase2_altsubject_matches;
118 119
	GByteArray *phase2_client_cert;
	char *password;
120
	NMSettingSecretFlags password_flags;
121 122
	GByteArray *password_raw;
	NMSettingSecretFlags password_raw_flags;
123
	char *pin;
124
	NMSettingSecretFlags pin_flags;
125
	GByteArray *private_key;
126
	char *private_key_password;
127
	NMSettingSecretFlags private_key_password_flags;
128
	GByteArray *phase2_private_key;
129
	char *phase2_private_key_password;
130
	NMSettingSecretFlags phase2_private_key_password_flags;
131
	gboolean system_ca_certs;
132 133
} NMSetting8021xPrivate;

134 135 136 137 138
enum {
	PROP_0,
	PROP_EAP,
	PROP_IDENTITY,
	PROP_ANONYMOUS_IDENTITY,
139
	PROP_PAC_FILE,
140 141
	PROP_CA_CERT,
	PROP_CA_PATH,
142 143
	PROP_SUBJECT_MATCH,
	PROP_ALTSUBJECT_MATCHES,
144 145 146 147 148 149 150 151
	PROP_CLIENT_CERT,
	PROP_PHASE1_PEAPVER,
	PROP_PHASE1_PEAPLABEL,
	PROP_PHASE1_FAST_PROVISIONING,
	PROP_PHASE2_AUTH,
	PROP_PHASE2_AUTHEAP,
	PROP_PHASE2_CA_CERT,
	PROP_PHASE2_CA_PATH,
152 153
	PROP_PHASE2_SUBJECT_MATCH,
	PROP_PHASE2_ALTSUBJECT_MATCHES,
154 155
	PROP_PHASE2_CLIENT_CERT,
	PROP_PASSWORD,
156
	PROP_PASSWORD_FLAGS,
157 158
	PROP_PASSWORD_RAW,
	PROP_PASSWORD_RAW_FLAGS,
159
	PROP_PRIVATE_KEY,
160
	PROP_PRIVATE_KEY_PASSWORD,
161
	PROP_PRIVATE_KEY_PASSWORD_FLAGS,
162
	PROP_PHASE2_PRIVATE_KEY,
163
	PROP_PHASE2_PRIVATE_KEY_PASSWORD,
164
	PROP_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS,
165
	PROP_PIN,
166
	PROP_PIN_FLAGS,
167
	PROP_SYSTEM_CA_CERTS,
168 169 170 171

	LAST_PROP
};

172 173 174 175 176 177 178
/**
 * nm_setting_802_1x_new:
 *
 * Creates a new #NMSetting8021x object with default values.
 *
 * Returns: the new empty #NMSetting8021x object
 **/
179 180 181 182 183 184
NMSetting *
nm_setting_802_1x_new (void)
{
	return (NMSetting *) g_object_new (NM_TYPE_SETTING_802_1X, NULL);
}

185 186 187 188 189 190 191 192 193 194 195 196
/**
 * nm_setting_802_1x_get_num_eap_methods:
 * @setting: the #NMSetting8021x
 *
 * Returns the number of eap methods allowed for use when connecting to the
 * network.  Generally only one EAP method is used.  Use the functions
 * nm_setting_802_1x_get_eap_method(), nm_setting_802_1x_add_eap_method(),
 * and nm_setting_802_1x_remove_eap_method() for adding, removing, and retrieving
 * allowed EAP methods.
 *
 * Returns: the number of allowed EAP methods
 **/
197 198 199 200 201 202 203 204
guint32
nm_setting_802_1x_get_num_eap_methods (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), 0);

	return g_slist_length (NM_SETTING_802_1X_GET_PRIVATE (setting)->eap);
}

205 206 207 208 209 210 211 212 213
/**
 * nm_setting_802_1x_get_eap_method:
 * @setting: the #NMSetting8021x
 * @i: the index of the EAP method name to return
 *
 * Returns the name of the allowed EAP method at index @i.
 *
 * Returns: the name of the allowed EAP method at index @i
 **/
214 215 216 217 218 219 220 221 222 223 224 225 226
const char *
nm_setting_802_1x_get_eap_method (NMSetting8021x *setting, guint32 i)
{
	NMSetting8021xPrivate *priv;

	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
	g_return_val_if_fail (i <= g_slist_length (priv->eap), NULL);

	return (const char *) g_slist_nth_data (priv->eap, i);
}

227 228 229 230 231 232 233 234 235
/**
 * nm_setting_802_1x_add_eap_method:
 * @setting: the #NMSetting8021x
 * @eap: the name of the EAP method to allow for this connection
 *
 * Adds an allowed EAP method.  The setting is not valid until at least one
 * EAP method has been added.  See #NMSetting8021x:eap property for a list of
 * allowed EAP methods.
 *
236
 * Returns: %TRUE if the EAP method was successfully added, %FALSE if it was
237 238
 *  not a valid method or if it was already allowed.
 **/
239
gboolean
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
nm_setting_802_1x_add_eap_method (NMSetting8021x *setting, const char *eap)
{
	NMSetting8021xPrivate *priv;
	GSList *iter;

	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), FALSE);
	g_return_val_if_fail (eap != NULL, FALSE);

	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
	for (iter = priv->eap; iter; iter = g_slist_next (iter)) {
		if (!strcmp (eap, (char *) iter->data))
			return FALSE;
	}

	priv->eap = g_slist_append (priv->eap, g_ascii_strdown (eap, -1));
255
	g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_EAP);
256 257 258
	return TRUE;
}

259 260 261 262 263 264 265
/**
 * nm_setting_802_1x_remove_eap_method:
 * @setting: the #NMSetting8021x
 * @i: the index of the EAP method to remove
 *
 * Removes the allowed EAP method at the specified index.
 **/
266 267
void
nm_setting_802_1x_remove_eap_method (NMSetting8021x *setting, guint32 i)
268
{
269 270 271 272 273 274 275 276 277 278 279
	NMSetting8021xPrivate *priv;
	GSList *elt;

	g_return_if_fail (NM_IS_SETTING_802_1X (setting));

	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
	elt = g_slist_nth (priv->eap, i);
	g_return_if_fail (elt != NULL);

	g_free (elt->data);
	priv->eap = g_slist_delete_link (priv->eap, elt);
280
	g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_EAP);
281 282
}

283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
/**
 * nm_setting_802_1x_remove_eap_method_by_value:
 * @setting: the #NMSetting8021x
 * @eap: the name of the EAP method to remove
 *
 * Removes the allowed EAP method @method.
 *
 * Returns: %TRUE if the EAP method was founs and removed, %FALSE if it was not.
 *
 * Since: 0.9.10
 **/
gboolean
nm_setting_802_1x_remove_eap_method_by_value (NMSetting8021x *setting,
                                              const char *eap)
{
	NMSetting8021xPrivate *priv;
	GSList *iter;

	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), FALSE);
	g_return_val_if_fail (eap != NULL, FALSE);

	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
	for (iter = priv->eap; iter; iter = g_slist_next (iter)) {
		if (!strcmp (eap, (char *) iter->data)) {
			priv->eap = g_slist_delete_link (priv->eap, iter);
			g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_EAP);
			return TRUE;
		}
	}
	return FALSE;
}

315 316 317 318 319 320
/**
 * nm_setting_802_1x_clear_eap_methods:
 * @setting: the #NMSetting8021x
 *
 * Clears all allowed EAP methods.
 **/
321 322 323 324 325 326 327 328
void
nm_setting_802_1x_clear_eap_methods (NMSetting8021x *setting)
{
	NMSetting8021xPrivate *priv;

	g_return_if_fail (NM_IS_SETTING_802_1X (setting));

	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
329
	g_slist_free_full (priv->eap, g_free);
330
	priv->eap = NULL;
331
	g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_EAP);
332 333
}

334 335 336 337 338 339 340 341 342
/**
 * nm_setting_802_1x_get_identity:
 * @setting: the #NMSetting8021x
 *
 * Returns the identifier used by some EAP methods (like TLS) to
 * authenticate the user.  Often this is a username or login name.
 *
 * Returns: the user identifier
 **/
343 344 345 346 347 348 349 350
const char *
nm_setting_802_1x_get_identity (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->identity;
}

351 352 353 354 355 356 357 358 359 360 361
/**
 * nm_setting_802_1x_get_anonymous_identity:
 * @setting: the #NMSetting8021x
 *
 * Returns the anonymous identifier used by some EAP methods (like TTLS) to
 * authenticate the user in the outer unencrypted "phase 1" authentication.  The
 * inner "phase 2" authentication will use the #NMSetting8021x:identity in
 * a secure form, if applicable for that EAP method.
 *
 * Returns: the anonymous identifier
 **/
362 363 364 365 366 367 368 369
const char *
nm_setting_802_1x_get_anonymous_identity (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->anonymous_identity;
}

370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
/**
 * nm_setting_802_1x_get_pac_file:
 * @setting: the #NMSetting8021x
 *
 * Returns the file containing PAC credentials used by EAP-FAST method.
 *
 * Returns: the PAC file
 **/
const char *
nm_setting_802_1x_get_pac_file (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->pac_file;
}

386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
/**
 * nm_setting_802_1x_get_ca_path:
 * @setting: the #NMSetting8021x
 *
 * Returns the path of the CA certificate directory if previously set.  Systems
 * will often have a directory that contains multiple individual CA certificates
 * which the supplicant can then add to the verification chain.  This may be
 * used in addition to the #NMSetting8021x:ca-cert property to add more CA
 * certificates for verifying the network to client.
 *
 * Returns: the CA certificate directory path
 **/
const char *
nm_setting_802_1x_get_ca_path (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->ca_path;
}

/**
 * nm_setting_802_1x_get_system_ca_certs:
 * @setting: the #NMSetting8021x
 *
 * Sets the #NMSetting8021x:system-ca-certs property. The
 * #NMSetting8021x:ca-path and #NMSetting8021x:phase2-ca-path
 * properties are ignored if the #NMSetting8021x:system-ca-certs property is
413
 * %TRUE, in which case a system-wide CA certificate directory specified at
414
 * compile time (using the --system-ca-path configure option) is used in place
415
 * of these properties.
416
 *
417
 * Returns: %TRUE if a system CA certificate path should be used, %FALSE if not
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
 **/
gboolean
nm_setting_802_1x_get_system_ca_certs (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), FALSE);

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->system_ca_certs;
}

static NMSetting8021xCKScheme
get_cert_scheme (GByteArray *array)
{
	if (!array || !array->len)
		return NM_SETTING_802_1X_CK_SCHEME_UNKNOWN;

433
	/* interpret the blob as PATH if it starts with "file://". */
434 435
	if (   array->len >= NM_STRLEN (SCHEME_PATH)
	    && !memcmp (array->data, SCHEME_PATH, NM_STRLEN (SCHEME_PATH))) {
436 437 438 439 440
		/* But it must also be NUL terminated, contain at least
		 * one non-NUL character, and contain only one trailing NUL
		 * chracter.
		 * And ensure it's UTF-8 valid too so we can pass it through
		 * D-Bus and stuff like that. */
441
		if (   array->len > NM_STRLEN (SCHEME_PATH) + 1
442
		    && array->data[array->len - 1] == '\0'
443
		    && g_utf8_validate ((const char *) &array->data[NM_STRLEN (SCHEME_PATH)], array->len - (NM_STRLEN (SCHEME_PATH) + 1), NULL))
444 445 446
			return NM_SETTING_802_1X_CK_SCHEME_PATH;
		return NM_SETTING_802_1X_CK_SCHEME_UNKNOWN;
	}
447 448 449 450

	return NM_SETTING_802_1X_CK_SCHEME_BLOB;
}

451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
static GByteArray *
load_and_verify_certificate (const char *cert_path,
                             NMSetting8021xCKScheme scheme,
                             NMCryptoFileFormat *out_file_format,
                             GError **error)
{
	NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN;
	GByteArray *array;

	array = crypto_load_and_verify_certificate (cert_path, &format, error);

	if (!array || !array->len || format == NM_CRYPTO_FILE_FORMAT_UNKNOWN)
		format = NM_CRYPTO_FILE_FORMAT_UNKNOWN;
	else if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB) {
		/* If we load the file as blob, we must ensure that the binary data does not
		 * start with file://. NMSetting8021x cannot represent blobs that start with
		 * file://.
		 * If that's the case, coerce the format to UNKNOWN. The callers will take care
		 * of that and not set the blob. */
		if (get_cert_scheme (array) != NM_SETTING_802_1X_CK_SCHEME_BLOB)
			format = NM_CRYPTO_FILE_FORMAT_UNKNOWN;
	}

	if (out_file_format)
		*out_file_format = format;
	return array;
}

479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
/**
 * nm_setting_802_1x_get_ca_cert_scheme:
 * @setting: the #NMSetting8021x
 *
 * Returns the scheme used to store the CA certificate.  If the returned scheme
 * is %NM_SETTING_802_1X_CK_SCHEME_BLOB, use nm_setting_802_1x_get_ca_cert_blob();
 * if %NM_SETTING_802_1X_CK_SCHEME_PATH, use nm_setting_802_1x_get_ca_cert_path().
 *
 * Returns: scheme used to store the CA certificate (blob or path)
 **/
NMSetting8021xCKScheme
nm_setting_802_1x_get_ca_cert_scheme (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NM_SETTING_802_1X_CK_SCHEME_UNKNOWN);

	return get_cert_scheme (NM_SETTING_802_1X_GET_PRIVATE (setting)->ca_cert);
}

/**
 * nm_setting_802_1x_get_ca_cert_blob:
 * @setting: the #NMSetting8021x
 *
 * Returns the CA certificate blob if the CA certificate is stored using the
 * %NM_SETTING_802_1X_CK_SCHEME_BLOB scheme.  Not all EAP methods use a
 * CA certificate (LEAP for example), and those that can take advantage of the
 * CA certificate allow it to be unset.  Note that lack of a CA certificate
 * reduces security by allowing man-in-the-middle attacks, because the identity
 * of the network cannot be confirmed by the client.
 *
 * Returns: the CA certificate data
 **/
510
const GByteArray *
511
nm_setting_802_1x_get_ca_cert_blob (NMSetting8021x *setting)
512
{
513 514
	NMSetting8021xCKScheme scheme;

515 516
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

517 518 519
	scheme = nm_setting_802_1x_get_ca_cert_scheme (setting);
	g_return_val_if_fail (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB, NULL);

520 521 522
	return NM_SETTING_802_1X_GET_PRIVATE (setting)->ca_cert;
}

523 524 525 526 527 528 529 530 531 532 533 534 535
/**
 * nm_setting_802_1x_get_ca_cert_path:
 * @setting: the #NMSetting8021x
 *
 * Returns the CA certificate path if the CA certificate is stored using the
 * %NM_SETTING_802_1X_CK_SCHEME_PATH scheme.  Not all EAP methods use a
 * CA certificate (LEAP for example), and those that can take advantage of the
 * CA certificate allow it to be unset.  Note that lack of a CA certificate
 * reduces security by allowing man-in-the-middle attacks, because the identity
 * of the network cannot be confirmed by the client.
 *
 * Returns: path to the CA certificate file
 **/
536
const char *
537
nm_setting_802_1x_get_ca_cert_path (NMSetting8021x *setting)
538
{
539 540
	NMSetting8021xCKScheme scheme;

541 542
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

543 544 545 546
	scheme = nm_setting_802_1x_get_ca_cert_scheme (setting);
	g_return_val_if_fail (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH, NULL);

	return (const char *) (NM_SETTING_802_1X_GET_PRIVATE (setting)->ca_cert->data + strlen (SCHEME_PATH));
547 548
}

549 550 551 552
static GByteArray *
path_to_scheme_value (const char *path)
{
	GByteArray *array;
553
	gsize len;
554

555
	g_return_val_if_fail (path != NULL && path[0], NULL);
556

557 558 559 560
	len = strlen (path);

	/* Add the path scheme tag to the front, then the filename */
	array = g_byte_array_sized_new (len + strlen (SCHEME_PATH) + 1);
561
	g_byte_array_append (array, (const guint8 *) SCHEME_PATH, strlen (SCHEME_PATH));
562
	g_byte_array_append (array, (const guint8 *) path, len);
563 564 565 566
	g_byte_array_append (array, (const guint8 *) "\0", 1);
	return array;
}

567 568 569
/**
 * nm_setting_802_1x_set_ca_cert:
 * @setting: the #NMSetting8021x
570 571 572
 * @cert_path: when @scheme is set to either %NM_SETTING_802_1X_CK_SCHEME_PATH
 *   or %NM_SETTING_802_1X_CK_SCHEME_BLOB, pass the path of the CA certificate
 *   file (PEM or DER format).  The path must be UTF-8 encoded; use
573
 *   g_filename_to_utf8() to convert if needed.  Passing %NULL with any @scheme
574
 *   clears the CA certificate.
575 576 577 578 579 580 581 582 583
 * @scheme: desired storage scheme for the certificate
 * @out_format: on successful return, the type of the certificate added
 * @error: on unsuccessful return, an error
 *
 * Reads a certificate from disk and sets the #NMSetting8021x:ca-cert property
 * with the raw certificate data if using the %NM_SETTING_802_1X_CK_SCHEME_BLOB
 * scheme, or with the path to the certificate file if using the
 * %NM_SETTING_802_1X_CK_SCHEME_PATH scheme.
 *
584
 * Returns: %TRUE if the operation succeeded, %FALSE if it was unsuccessful
585
 **/
586
gboolean
587
nm_setting_802_1x_set_ca_cert (NMSetting8021x *setting,
588
                               const char *cert_path,
589 590 591
                               NMSetting8021xCKScheme scheme,
                               NMSetting8021xCKFormat *out_format,
                               GError **error)
592 593
{
	NMSetting8021xPrivate *priv;
594
	NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN;
595
	GByteArray *data;
596

597
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), FALSE);
598

599 600
	if (cert_path) {
		g_return_val_if_fail (g_utf8_validate (cert_path, -1, NULL), FALSE);
601 602 603 604 605 606 607
		g_return_val_if_fail (   scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB
		                      || scheme == NM_SETTING_802_1X_CK_SCHEME_PATH,
		                      FALSE);
	}

	if (out_format)
		g_return_val_if_fail (*out_format == NM_SETTING_802_1X_CK_FORMAT_UNKNOWN, FALSE);
608

609
	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
610

611
	/* Clear out any previous ca_cert blob */
612
	if (priv->ca_cert) {
613 614 615 616
		g_byte_array_free (priv->ca_cert, TRUE);
		priv->ca_cert = NULL;
	}

617
	if (!cert_path) {
618
		g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_CA_CERT);
619
		return TRUE;
620
	}
621

622
	data = load_and_verify_certificate (cert_path, scheme, &format, error);
623
	if (data) {
624
		/* wpa_supplicant can only use raw x509 CA certs */
625
		if (format == NM_CRYPTO_FILE_FORMAT_X509) {
626 627 628 629
			if (out_format)
				*out_format = NM_SETTING_802_1X_CK_FORMAT_X509;

			if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB)
630
				priv->ca_cert = g_byte_array_ref (data);
631
			else if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH)
632
				priv->ca_cert = path_to_scheme_value (cert_path);
633
			else
634
				g_assert_not_reached ();
635
		} else {
636
			g_set_error_literal (error,
637 638
			             NM_SETTING_802_1X_ERROR,
			             NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
639 640
			             _("CA certificate must be in X.509 format"));
			g_prefix_error (error, "%s.%s: ", NM_SETTING_802_1X_SETTING_NAME, NM_SETTING_802_1X_CA_CERT);
641
		}
642
		g_byte_array_unref (data);
643
	}
644

645
	g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_CA_CERT);
646 647 648
	return priv->ca_cert != NULL;
}

649 650 651 652 653 654
/**
 * nm_setting_802_1x_get_subject_match:
 * @setting: the #NMSetting8021x
 *
 * Returns: the #NMSetting8021x:subject-match property. This is the
 * substring to be matched against the subject of the authentication
655
 * server certificate, or %NULL no subject verification is to be
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
 * performed.
 **/
const char *
nm_setting_802_1x_get_subject_match (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->subject_match;
}

/**
 * nm_setting_802_1x_get_num_altsubject_matches:
 * @setting: the #NMSetting8021x
 *
 * Returns the number of entries in the
 * #NMSetting8021x:altsubject-matches property of this setting.
 *
 * Returns: the number of altsubject-matches entries.
 **/
guint32
nm_setting_802_1x_get_num_altsubject_matches (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), 0);

	return g_slist_length (NM_SETTING_802_1X_GET_PRIVATE (setting)->altsubject_matches);
}

/**
 * nm_setting_802_1x_get_altsubject_match:
 * @setting: the #NMSettingConnection
 * @i: the zero-based index of the array of altSubjectName matches
 *
 * Returns the altSubjectName match at index @i.
 *
 * Returns: the altSubjectName match at index @i
 **/
const char *
nm_setting_802_1x_get_altsubject_match (NMSetting8021x *setting, guint32 i)
{
	NMSetting8021xPrivate *priv;

	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
	g_return_val_if_fail (i <= g_slist_length (priv->altsubject_matches), NULL);

	return (const char *) g_slist_nth_data (priv->altsubject_matches, i);
}

/**
 * nm_setting_802_1x_add_altsubject_match:
 * @setting: the #NMSetting8021x
 * @altsubject_match: the altSubjectName to allow for this connection
 *
 * Adds an allowed alternate subject name match.  Until at least one
 * match is added, the altSubjectName of the remote authentication
 * server is not verified.
 *
714 715
 * Returns: %TRUE if the alternative subject name match was
 *  successfully added, %FALSE if it was already allowed.
716 717 718
 **/
gboolean
nm_setting_802_1x_add_altsubject_match (NMSetting8021x *setting,
719
                                        const char *altsubject_match)
720 721 722 723 724 725 726 727 728 729 730 731 732
{
	NMSetting8021xPrivate *priv;
	GSList *iter;

	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), FALSE);
	g_return_val_if_fail (altsubject_match != NULL, FALSE);

	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
	for (iter = priv->altsubject_matches; iter; iter = g_slist_next (iter)) {
		if (!strcmp (altsubject_match, (char *) iter->data))
			return FALSE;
	}

733 734
	priv->altsubject_matches = g_slist_append (priv->altsubject_matches,
	                                           g_strdup (altsubject_match));
735
	g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_ALTSUBJECT_MATCHES);
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
	return TRUE;
}

/**
 * nm_setting_802_1x_remove_altsubject_match:
 * @setting: the #NMSetting8021x
 * @i: the index of the altSubjectName match to remove
 *
 * Removes the allowed altSubjectName at the specified index.
 **/
void
nm_setting_802_1x_remove_altsubject_match (NMSetting8021x *setting, guint32 i)
{
	NMSetting8021xPrivate *priv;
	GSList *elt;

	g_return_if_fail (NM_IS_SETTING_802_1X (setting));

	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
	elt = g_slist_nth (priv->altsubject_matches, i);
	g_return_if_fail (elt != NULL);

	g_free (elt->data);
	priv->altsubject_matches = g_slist_delete_link (priv->altsubject_matches, elt);
760
	g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_ALTSUBJECT_MATCHES);
761 762
}

763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
/**
 * nm_setting_802_1x_remove_altsubject_match_by_value:
 * @setting: the #NMSetting8021x
 * @altsubject_match: the altSubjectName to remove
 *
 * Removes the allowed altSubjectName @altsubject_match.
 *
 * Returns: %TRUE if the alternative subject name match was found and removed,
 *          %FALSE if it was not.
 *
 * Since: 0.9.10
 **/
gboolean
nm_setting_802_1x_remove_altsubject_match_by_value (NMSetting8021x *setting,
                                                    const char *altsubject_match)
{
	NMSetting8021xPrivate *priv;
	GSList *iter;

	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), FALSE);
	g_return_val_if_fail (altsubject_match != NULL, FALSE);

	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
	for (iter = priv->altsubject_matches; iter; iter = g_slist_next (iter)) {
		if (!strcmp (altsubject_match, (char *) iter->data)) {
			priv->altsubject_matches = g_slist_delete_link (priv->altsubject_matches, iter);
			g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_ALTSUBJECT_MATCHES);
			return TRUE;
		}
	}
	return FALSE;
}

796 797 798 799 800 801 802 803 804 805 806 807 808 809
/**
 * nm_setting_802_1x_clear_altsubject_matches:
 * @setting: the #NMSetting8021x
 *
 * Clears all altSubjectName matches.
 **/
void
nm_setting_802_1x_clear_altsubject_matches (NMSetting8021x *setting)
{
	NMSetting8021xPrivate *priv;

	g_return_if_fail (NM_IS_SETTING_802_1X (setting));

	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
810
	g_slist_free_full (priv->altsubject_matches, g_free);
811
	priv->altsubject_matches = NULL;
812
	g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_ALTSUBJECT_MATCHES);
813 814
}

815 816 817 818 819 820 821 822 823 824 825 826
/**
 * nm_setting_802_1x_get_client_cert_scheme:
 * @setting: the #NMSetting8021x
 *
 * Returns the scheme used to store the client certificate.  If the returned scheme
 * is %NM_SETTING_802_1X_CK_SCHEME_BLOB, use nm_setting_802_1x_get_client_cert_blob();
 * if %NM_SETTING_802_1X_CK_SCHEME_PATH, use nm_setting_802_1x_get_client_cert_path().
 *
 * Returns: scheme used to store the client certificate (blob or path)
 **/
NMSetting8021xCKScheme
nm_setting_802_1x_get_client_cert_scheme (NMSetting8021x *setting)
827
{
828
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NM_SETTING_802_1X_CK_SCHEME_UNKNOWN);
829

830
	return get_cert_scheme (NM_SETTING_802_1X_GET_PRIVATE (setting)->client_cert);
831 832
}

833 834 835 836 837 838 839 840 841 842
/**
 * nm_setting_802_1x_get_client_cert_blob:
 * @setting: the #NMSetting8021x
 *
 * Client certificates are used to identify the connecting client to the network
 * when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
 * authentication method.
 *
 * Returns: the client certificate data
 **/
843
const GByteArray *
844
nm_setting_802_1x_get_client_cert_blob (NMSetting8021x *setting)
845
{
846 847
	NMSetting8021xCKScheme scheme;

848 849
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

850 851 852
	scheme = nm_setting_802_1x_get_client_cert_scheme (setting);
	g_return_val_if_fail (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB, NULL);

853
	return NM_SETTING_802_1X_GET_PRIVATE (setting)->client_cert;
854 855
}

856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881
/**
 * nm_setting_802_1x_get_client_cert_path:
 * @setting: the #NMSetting8021x
 *
 * Client certificates are used to identify the connecting client to the network
 * when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
 * authentication method.
 *
 * Returns: path to the client certificate file
 **/
const char *
nm_setting_802_1x_get_client_cert_path (NMSetting8021x *setting)
{
	NMSetting8021xCKScheme scheme;

	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	scheme = nm_setting_802_1x_get_client_cert_scheme (setting);
	g_return_val_if_fail (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH, NULL);

	return (const char *) (NM_SETTING_802_1X_GET_PRIVATE (setting)->client_cert->data + strlen (SCHEME_PATH));
}

/**
 * nm_setting_802_1x_set_client_cert:
 * @setting: the #NMSetting8021x
882 883
 * @cert_path: when @scheme is set to either %NM_SETTING_802_1X_CK_SCHEME_PATH
 *   or %NM_SETTING_802_1X_CK_SCHEME_BLOB, pass the path of the client
Dan Winship's avatar
Dan Winship committed
884
 *   certificate file (PEM, DER, or PKCS#<!-- -->12 format).  The path must be UTF-8
885
 *   encoded; use g_filename_to_utf8() to convert if needed.  Passing %NULL with
886
 *   any @scheme clears the client certificate.
887 888 889 890 891 892 893 894 895 896 897 898 899
 * @scheme: desired storage scheme for the certificate
 * @out_format: on successful return, the type of the certificate added
 * @error: on unsuccessful return, an error
 *
 * Reads a certificate from disk and sets the #NMSetting8021x:client-cert
 * property with the raw certificate data if using the
 * %NM_SETTING_802_1X_CK_SCHEME_BLOB scheme, or with the path to the certificate
 * file if using the %NM_SETTING_802_1X_CK_SCHEME_PATH scheme.
 *
 * Client certificates are used to identify the connecting client to the network
 * when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
 * authentication method.
 *
900
 * Returns: %TRUE if the operation succeeded, %FALSE if it was unsuccessful
901
 **/
902
gboolean
903
nm_setting_802_1x_set_client_cert (NMSetting8021x *setting,
904
                                   const char *cert_path,
905 906 907
                                   NMSetting8021xCKScheme scheme,
                                   NMSetting8021xCKFormat *out_format,
                                   GError **error)
908
{
909
	NMSetting8021xPrivate *priv;
910
	NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN;
911
	GByteArray *data;
912

913
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), FALSE);
914

915 916
	if (cert_path) {
		g_return_val_if_fail (g_utf8_validate (cert_path, -1, NULL), FALSE);
917 918 919 920 921 922 923
		g_return_val_if_fail (   scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB
		                      || scheme == NM_SETTING_802_1X_CK_SCHEME_PATH,
		                      FALSE);
	}

	if (out_format)
		g_return_val_if_fail (*out_format == NM_SETTING_802_1X_CK_FORMAT_UNKNOWN, FALSE);
924

925
	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
926

927
	/* Clear out any previous ca_cert blob */
928
	if (priv->client_cert) {
929 930 931 932
		g_byte_array_free (priv->client_cert, TRUE);
		priv->client_cert = NULL;
	}

933
	if (!cert_path) {
934
		g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_CLIENT_CERT);
935
		return TRUE;
936
	}
937

938
	data = load_and_verify_certificate (cert_path, scheme, &format, error);
939
	if (data) {
940 941
		gboolean valid = FALSE;

942 943
		switch (format) {
		case NM_CRYPTO_FILE_FORMAT_X509:
944 945
			if (out_format)
				*out_format = NM_SETTING_802_1X_CK_FORMAT_X509;
946
			valid = TRUE;
947 948
			break;
		case NM_CRYPTO_FILE_FORMAT_PKCS12:
949 950
			if (out_format)
				*out_format = NM_SETTING_802_1X_CK_FORMAT_PKCS12;
951
			valid = TRUE;
952 953
			break;
		default:
954 955 956 957 958
			g_set_error_literal (error,
			                     NM_SETTING_802_1X_ERROR,
			                     NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
			                     _("invalid certificate format"));
			g_prefix_error (error, "%s.%s: ", NM_SETTING_802_1X_SETTING_NAME, NM_SETTING_802_1X_CLIENT_CERT);
959
			break;
960 961
		}

962
		if (valid) {
963
			if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB)
964
				priv->client_cert = g_byte_array_ref (data);
965
			else if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH)
966
				priv->client_cert = path_to_scheme_value (cert_path);
967
			else
968 969
				g_assert_not_reached ();
		}
970
		g_byte_array_unref (data);
971
	}
972

973
	g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_CLIENT_CERT);
974 975 976
	return priv->client_cert != NULL;
}

977 978 979 980 981 982
/**
 * nm_setting_802_1x_get_phase1_peapver:
 * @setting: the #NMSetting8021x
 *
 * Returns: the "phase 1" PEAP version to be used when authenticating with
 *  EAP-PEAP as contained in the #NMSetting8021x:phase1-peapver property.  Valid
983
 *  values are %NULL (unset), "0" (PEAP version 0), and "1" (PEAP version 1).
984
 **/
985 986 987 988 989 990 991 992
const char *
nm_setting_802_1x_get_phase1_peapver (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->phase1_peapver;
}

993 994 995 996 997 998
/**
 * nm_setting_802_1x_get_phase1_peaplabel:
 * @setting: the #NMSetting8021x
 *
 * Returns: whether the "phase 1" PEAP label is new-style or old-style, to be
 *  used when authenticating with EAP-PEAP, as contained in the
999
 *  #NMSetting8021x:phase1-peaplabel property.  Valid values are %NULL (unset),
1000 1001 1002
 *  "0" (use old-style label), and "1" (use new-style label).  See the
 *  wpa_supplicant documentation for more details.
 **/
1003 1004 1005 1006 1007 1008 1009 1010
const char *
nm_setting_802_1x_get_phase1_peaplabel (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->phase1_peaplabel;
}

1011 1012 1013 1014 1015 1016 1017 1018
/**
 * nm_setting_802_1x_get_phase1_fast_provisioning:
 * @setting: the #NMSetting8021x
 *
 * Returns: whether "phase 1" PEAP fast provisioning should be used, as specified
 *  by the #NMSetting8021x:phase1-fast-provisioning property.  See the
 *  wpa_supplicant documentation for more details.
 **/
1019 1020 1021 1022 1023 1024 1025 1026
const char *
nm_setting_802_1x_get_phase1_fast_provisioning (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->phase1_fast_provisioning;
}

1027 1028 1029 1030 1031 1032 1033
/**
 * nm_setting_802_1x_get_phase2_auth:
 * @setting: the #NMSetting8021x
 *
 * Returns: the "phase 2" non-EAP (ex MD5) allowed authentication method as
 *   specified by the #NMSetting8021x:phase2-auth property.
 **/
1034 1035 1036 1037
const char *
nm_setting_802_1x_get_phase2_auth (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);
1038

1039 1040 1041
	return NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_auth;
}

1042 1043 1044 1045 1046 1047 1048
/**
 * nm_setting_802_1x_get_phase2_autheap:
 * @setting: the #NMSetting8021x
 *
 * Returns: the "phase 2" EAP-based (ex TLS) allowed authentication method as
 *   specified by the #NMSetting8021x:phase2-autheap property.
 **/
1049 1050 1051 1052 1053 1054 1055 1056
const char *
nm_setting_802_1x_get_phase2_autheap (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_autheap;
}

1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
/**
 * nm_setting_802_1x_get_phase2_ca_path:
 * @setting: the #NMSetting8021x
 *
 * Returns the path of the "phase 2" CA certificate directory if previously set.
 * Systems will often have a directory that contains multiple individual CA
 * certificates which the supplicant can then add to the verification chain.
 * This may be used in addition to the #NMSetting8021x:phase2-ca-cert property
 * to add more CA certificates for verifying the network to client.
 *
 * Returns: the "phase 2" CA certificate directory path
 **/
const char *
nm_setting_802_1x_get_phase2_ca_path (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_ca_path;
}

/**
 * nm_setting_802_1x_get_phase2_ca_cert_scheme:
 * @setting: the #NMSetting8021x
 *
 * Returns the scheme used to store the "phase 2" CA certificate.  If the
 * returned scheme is %NM_SETTING_802_1X_CK_SCHEME_BLOB, use
 * nm_setting_802_1x_get_ca_cert_blob(); if %NM_SETTING_802_1X_CK_SCHEME_PATH,
 * use nm_setting_802_1x_get_ca_cert_path().
 *
 * Returns: scheme used to store the "phase 2" CA certificate (blob or path)
 **/
NMSetting8021xCKScheme
nm_setting_802_1x_get_phase2_ca_cert_scheme (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NM_SETTING_802_1X_CK_SCHEME_UNKNOWN);

	return get_cert_scheme (NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_ca_cert);
}

/**
 * nm_setting_802_1x_get_phase2_ca_cert_blob:
 * @setting: the #NMSetting8021x
 *
 * Returns the "phase 2" CA certificate blob if the CA certificate is stored
 * using the %NM_SETTING_802_1X_CK_SCHEME_BLOB scheme.  Not all EAP methods use
 * a CA certificate (LEAP for example), and those that can take advantage of the
 * CA certificate allow it to be unset.  Note that lack of a CA certificate
 * reduces security by allowing man-in-the-middle attacks, because the identity
 * of the network cannot be confirmed by the client.
 *
 * Returns: the "phase 2" CA certificate data
 **/
1109
const GByteArray *
1110
nm_setting_802_1x_get_phase2_ca_cert_blob (NMSetting8021x *setting)
1111
{
1112 1113
	NMSetting8021xCKScheme scheme;

1114
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);
1115

1116 1117 1118
	scheme = nm_setting_802_1x_get_phase2_ca_cert_scheme (setting);
	g_return_val_if_fail (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB, NULL);

1119 1120 1121
	return NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_ca_cert;
}

1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134
/**
 * nm_setting_802_1x_get_phase2_ca_cert_path:
 * @setting: the #NMSetting8021x
 *
 * Returns the "phase 2" CA certificate path if the CA certificate is stored
 * using the %NM_SETTING_802_1X_CK_SCHEME_PATH scheme.  Not all EAP methods use
 * a CA certificate (LEAP for example), and those that can take advantage of the
 * CA certificate allow it to be unset.  Note that lack of a CA certificate
 * reduces security by allowing man-in-the-middle attacks, because the identity
 * of the network cannot be confirmed by the client.
 *
 * Returns: path to the "phase 2" CA certificate file
 **/
1135
const char *
1136
nm_setting_802_1x_get_phase2_ca_cert_path (NMSetting8021x *setting)
1137
{
1138 1139
	NMSetting8021xCKScheme scheme;

1140 1141
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

1142 1143 1144 1145
	scheme = nm_setting_802_1x_get_phase2_ca_cert_scheme (setting);
	g_return_val_if_fail (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH, NULL);

	return (const char *) (NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_ca_cert->data + strlen (SCHEME_PATH));
1146 1147
}

1148 1149 1150
/**
 * nm_setting_802_1x_set_phase2_ca_cert:
 * @setting: the #NMSetting8021x
1151 1152
 * @cert_path: when @scheme is set to either %NM_SETTING_802_1X_CK_SCHEME_PATH
 *   or %NM_SETTING_802_1X_CK_SCHEME_BLOB, pass the path of the "phase2" CA
1153
 *   certificate file (PEM or DER format).  The path must be UTF-8 encoded; use
1154
 *   g_filename_to_utf8() to convert if needed.  Passing %NULL with any @scheme
1155
 *   clears the "phase2" CA certificate.
1156 1157 1158 1159 1160 1161 1162 1163 1164
 * @scheme: desired storage scheme for the certificate
 * @out_format: on successful return, the type of the certificate added
 * @error: on unsuccessful return, an error
 *
 * Reads a certificate from disk and sets the #NMSetting8021x:phase2-ca-cert
 * property with the raw certificate data if using the
 * %NM_SETTING_802_1X_CK_SCHEME_BLOB scheme, or with the path to the certificate
 * file if using the %NM_SETTING_802_1X_CK_SCHEME_PATH scheme.
 *
1165
 * Returns: %TRUE if the operation succeeded, %FALSE if it was unsuccessful
1166
 **/
1167
gboolean
1168
nm_setting_802_1x_set_phase2_ca_cert (NMSetting8021x *setting,
1169
                                      const char *cert_path,
1170 1171 1172
                                      NMSetting8021xCKScheme scheme,
                                      NMSetting8021xCKFormat *out_format,
                                      GError **error)
1173
{
1174
	NMSetting8021xPrivate *priv;
1175
	NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN;
1176
	GByteArray *data;
1177

1178
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), FALSE);
1179

1180 1181
	if (cert_path) {
		g_return_val_if_fail (g_utf8_validate (cert_path, -1, NULL), FALSE);
1182 1183 1184 1185 1186 1187 1188
		g_return_val_if_fail (   scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB
		                      || scheme == NM_SETTING_802_1X_CK_SCHEME_PATH,
		                      FALSE);
	}

	if (out_format)
		g_return_val_if_fail (*out_format == NM_SETTING_802_1X_CK_FORMAT_UNKNOWN, FALSE);
1189

1190
	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
1191

1192
	/* Clear out any previous ca_cert blob */
1193
	if (priv->phase2_ca_cert) {
1194 1195 1196 1197
		g_byte_array_free (priv->phase2_ca_cert, TRUE);
		priv->phase2_ca_cert = NULL;
	}

1198
	if (!cert_path) {
1199
		g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_PHASE2_CA_CERT);
1200
		return TRUE;
1201
	}
1202

1203
	data = load_and_verify_certificate (cert_path, scheme, &format, error);
1204 1205
	if (data) {
		/* wpa_supplicant can only use raw x509 CA certs */
1206
		if (format == NM_CRYPTO_FILE_FORMAT_X509) {
1207 1208 1209 1210
			if (out_format)
				*out_format = NM_SETTING_802_1X_CK_FORMAT_X509;

			if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB)
1211
				priv->phase2_ca_cert = g_byte_array_ref (data);
1212
			else if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH)
1213
				priv->phase2_ca_cert = path_to_scheme_value (cert_path);
1214
			else
1215
				g_assert_not_reached ();
1216
		} else {
1217 1218 1219 1220 1221
			g_set_error_literal (error,
			                     NM_SETTING_802_1X_ERROR,
			                     NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
			                     _("invalid certificate format"));
			g_prefix_error (error, "%s.%s: ", NM_SETTING_802_1X_SETTING_NAME, NM_SETTING_802_1X_PHASE2_CA_CERT);
1222
		}
1223
		g_byte_array_unref (data);
1224
	}
1225

1226
	g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_PHASE2_CA_CERT);
1227
	return priv->phase2_ca_cert != NULL;
1228 1229
}

1230 1231 1232 1233 1234 1235
/**
 * nm_setting_802_1x_get_phase2_subject_match:
 * @setting: the #NMSetting8021x
 *
 * Returns: the #NMSetting8021x:phase2-subject-match property. This is
 * the substring to be matched against the subject of the "phase 2"
1236
 * authentication server certificate, or %NULL no subject verification
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
 * is to be performed.
 **/
const char *
nm_setting_802_1x_get_phase2_subject_match (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_subject_match;
}

/**
 * nm_setting_802_1x_get_num_phase2_altsubject_matches:
 * @setting: the #NMSetting8021x
 *
 * Returns the number of entries in the
 * #NMSetting8021x:phase2-altsubject-matches property of this setting.
 *
 * Returns: the number of phase2-altsubject-matches entries.
 **/
guint32
nm_setting_802_1x_get_num_phase2_altsubject_matches (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), 0);

	return g_slist_length (NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_altsubject_matches);
}

/**
 * nm_setting_802_1x_get_phase2_altsubject_match:
 * @setting: the #NMSettingConnection
 * @i: the zero-based index of the array of "phase 2" altSubjectName matches
 *
 * Returns the "phase 2" altSubjectName match at index @i.
 *
 * Returns: the "phase 2" altSubjectName match at index @i
 **/
const char *
nm_setting_802_1x_get_phase2_altsubject_match (NMSetting8021x *setting, guint32 i)
{
	NMSetting8021xPrivate *priv;

	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
	g_return_val_if_fail (i <= g_slist_length (priv->phase2_altsubject_matches), NULL);

	return (const char *) g_slist_nth_data (priv->phase2_altsubject_matches, i);
}

/**
 * nm_setting_802_1x_add_phase2_altsubject_match:
 * @setting: the #NMSetting8021x
1289
 * @phase2_altsubject_match: the "phase 2" altSubjectName to allow for this
1290 1291 1292 1293 1294 1295
 * connection
 *
 * Adds an allowed alternate subject name match for "phase 2".  Until
 * at least one match is added, the altSubjectName of the "phase 2"
 * remote authentication server is not verified.
 *
1296 1297
 * Returns: %TRUE if the "phase 2" alternative subject name match was
 *  successfully added, %FALSE if it was already allowed.
1298 1299 1300
 **/
gboolean
nm_setting_802_1x_add_phase2_altsubject_match (NMSetting8021x *setting,
1301
                                               const char *phase2_altsubject_match)
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
{
	NMSetting8021xPrivate *priv;
	GSList *iter;

	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), FALSE);
	g_return_val_if_fail (phase2_altsubject_match != NULL, FALSE);

	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
	for (iter = priv->phase2_altsubject_matches; iter; iter = g_slist_next (iter)) {
		if (!strcmp (phase2_altsubject_match, (char *) iter->data))
			return FALSE;
	}

1315 1316
	priv->phase2_altsubject_matches = g_slist_append (priv->phase2_altsubject_matches,
	                                                  g_strdup (phase2_altsubject_match));
1317
	g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES);
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341
	return TRUE;
}

/**
 * nm_setting_802_1x_remove_phase2_altsubject_match:
 * @setting: the #NMSetting8021x
 * @i: the index of the "phase 2" altSubjectName match to remove
 *
 * Removes the allowed "phase 2" altSubjectName at the specified index.
 **/
void
nm_setting_802_1x_remove_phase2_altsubject_match (NMSetting8021x *setting, guint32 i)
{
	NMSetting8021xPrivate *priv;
	GSList *elt;

	g_return_if_fail (NM_IS_SETTING_802_1X (setting));

	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
	elt = g_slist_nth (priv->phase2_altsubject_matches, i);
	g_return_if_fail (elt != NULL);

	g_free (elt->data);
	priv->phase2_altsubject_matches = g_slist_delete_link (priv->phase2_altsubject_matches, elt);
1342
	g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES);
1343 1344
}

1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378

/**
 * nm_setting_802_1x_remove_phase2_altsubject_match_by_value:
 * @setting: the #NMSetting8021x
 * @phase2_altsubject_match: the "phase 2" altSubjectName to remove
 *
 * Removes the allowed "phase 2" altSubjectName @phase2_altsubject_match.
 *
 * Returns: %TRUE if the alternative subject name match for "phase 2" was found and removed,
 *          %FALSE if it was not.
 *
 * Since: 0.9.10
 **/
gboolean
nm_setting_802_1x_remove_phase2_altsubject_match_by_value (NMSetting8021x *setting,
                                                           const char *phase2_altsubject_match)
{
	NMSetting8021xPrivate *priv;
	GSList *iter;

	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), FALSE);
	g_return_val_if_fail (phase2_altsubject_match != NULL, FALSE);

	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
	for (iter = priv->phase2_altsubject_matches; iter; iter = g_slist_next (iter)) {
		if (!strcmp (phase2_altsubject_match, (char *) iter->data)) {
			priv->phase2_altsubject_matches = g_slist_delete_link (priv->phase2_altsubject_matches, iter);
			g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES);
			return TRUE;
		}
	}
	return FALSE;
}

1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392
/**
 * nm_setting_802_1x_clear_phase2_altsubject_matches:
 * @setting: the #NMSetting8021x
 *
 * Clears all "phase 2" altSubjectName matches.
 **/
void
nm_setting_802_1x_clear_phase2_altsubject_matches (NMSetting8021x *setting)
{
	NMSetting8021xPrivate *priv;

	g_return_if_fail (NM_IS_SETTING_802_1X (setting));

	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
1393
	g_slist_free_full (priv->phase2_altsubject_matches, g_free);
1394
	priv->phase2_altsubject_matches = NULL;
1395
	g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES);
1396 1397
}

1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427
/**
 * nm_setting_802_1x_get_phase2_client_cert_scheme:
 * @setting: the #NMSetting8021x
 *
 * Returns the scheme used to store the "phase 2" client certificate.  If the
 * returned scheme is %NM_SETTING_802_1X_CK_SCHEME_BLOB, use
 * nm_setting_802_1x_get_client_cert_blob(); if
 * %NM_SETTING_802_1X_CK_SCHEME_PATH, use
 * nm_setting_802_1x_get_client_cert_path().
 *
 * Returns: scheme used to store the "phase 2" client certificate (blob or path)
 **/
NMSetting8021xCKScheme
nm_setting_802_1x_get_phase2_client_cert_scheme (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NM_SETTING_802_1X_CK_SCHEME_UNKNOWN);

	return get_cert_scheme (NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_client_cert);
}

/**
 * nm_setting_802_1x_get_phase2_client_cert_blob:
 * @setting: the #NMSetting8021x
 *
 * Client certificates are used to identify the connecting client to the network
 * when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
 * authentication method.
 *
 * Returns: the "phase 2" client certificate data
 **/
1428
const GByteArray *
1429
nm_setting_802_1x_get_phase2_client_cert_blob (NMSetting8021x *setting)
1430
{
1431 1432
	NMSetting8021xCKScheme scheme;

1433 1434
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

1435 1436 1437
	scheme = nm_setting_802_1x_get_phase2_client_cert_scheme (setting);
	g_return_val_if_fail (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB, NULL);

1438 1439 1440
	return NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_client_cert;
}

1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466
/**
 * nm_setting_802_1x_get_phase2_client_cert_path:
 * @setting: the #NMSetting8021x
 *
 * Client certificates are used to identify the connecting client to the network
 * when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
 * authentication method.
 *
 * Returns: path to the "phase 2" client certificate file
 **/
const char *
nm_setting_802_1x_get_phase2_client_cert_path (NMSetting8021x *setting)
{
	NMSetting8021xCKScheme scheme;

	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	scheme = nm_setting_802_1x_get_phase2_client_cert_scheme (setting);
	g_return_val_if_fail (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH, NULL);

	return (const char *) (NM_SETTING_802_1X_GET_PRIVATE (setting)->phase2_client_cert->data + strlen (SCHEME_PATH));
}

/**
 * nm_setting_802_1x_set_phase2_client_cert:
 * @setting: the #NMSetting8021x
1467 1468
 * @cert_path: when @scheme is set to either %NM_SETTING_802_1X_CK_SCHEME_PATH
 *   or %NM_SETTING_802_1X_CK_SCHEME_BLOB, pass the path of the "phase2" client
Dan Winship's avatar
Dan Winship committed
1469
 *   certificate file (PEM, DER, or PKCS#<!-- -->12 format).  The path must be UTF-8
1470
 *   encoded; use g_filename_to_utf8() to convert if needed.  Passing %NULL with
1471
 *   any @scheme clears the "phase2" client certificate.
1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484
 * @scheme: desired storage scheme for the certificate
 * @out_format: on successful return, the type of the certificate added
 * @error: on unsuccessful return, an error
 *
 * Reads a certificate from disk and sets the #NMSetting8021x:phase2-client-cert
 * property with the raw certificate data if using the
 * %NM_SETTING_802_1X_CK_SCHEME_BLOB scheme, or with the path to the certificate
 * file if using the %NM_SETTING_802_1X_CK_SCHEME_PATH scheme.
 *
 * Client certificates are used to identify the connecting client to the network
 * when EAP-TLS is used as either the "phase 1" or "phase 2" 802.1x
 * authentication method.
 *
1485
 * Returns: %TRUE if the operation succeeded, %FALSE if it was unsuccessful
1486
 **/
1487
gboolean
1488
nm_setting_802_1x_set_phase2_client_cert (NMSetting8021x *setting,
1489
                                          const char *cert_path,
1490 1491 1492
                                          NMSetting8021xCKScheme scheme,
                                          NMSetting8021xCKFormat *out_format,
                                          GError **error)
1493
{
1494
	NMSetting8021xPrivate *priv;
1495
	NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN;
1496
	GByteArray *data;
1497

1498
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), FALSE);
1499

1500 1501
	if (cert_path) {
		g_return_val_if_fail (g_utf8_validate (cert_path, -1, NULL), FALSE);
1502 1503 1504 1505 1506 1507 1508
		g_return_val_if_fail (   scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB
		                      || scheme == NM_SETTING_802_1X_CK_SCHEME_PATH,
		                      FALSE);
	}

	if (out_format)
		g_return_val_if_fail (*out_format == NM_SETTING_802_1X_CK_FORMAT_UNKNOWN, FALSE);
1509

1510
	priv = NM_SETTING_802_1X_GET_PRIVATE (setting);
1511

1512
	/* Clear out any previous ca_cert blob */
1513
	if (priv->phase2_client_cert) {
1514 1515 1516 1517
		g_byte_array_free (priv->phase2_client_cert, TRUE);
		priv->phase2_client_cert = NULL;
	}

1518
	if (!cert_path) {
1519
		g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_PHASE2_CLIENT_CERT);
1520
		return TRUE;
1521
	}
1522

1523
	data = load_and_verify_certificate (cert_path, scheme, &format, error);
1524
	if (data) {
1525 1526
		gboolean valid = FALSE;

1527
		/* wpa_supplicant can only use raw x509 CA certs */
1528 1529
		switch (format) {
		case NM_CRYPTO_FILE_FORMAT_X509:
1530 1531
			if (out_format)
				*out_format = NM_SETTING_802_1X_CK_FORMAT_X509;
1532
			valid = TRUE;
1533 1534
			break;
		case NM_CRYPTO_FILE_FORMAT_PKCS12:
1535 1536
			if (out_format)
				*out_format = NM_SETTING_802_1X_CK_FORMAT_PKCS12;
1537
			valid = TRUE;
1538 1539
			break;
		default:
1540 1541 1542 1543 1544
			g_set_error_literal (error,
			                     NM_SETTING_802_1X_ERROR,
			                     NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
			                     _("invalid certificate format"));
			g_prefix_error (error, "%s.%s: ", NM_SETTING_802_1X_SETTING_NAME, NM_SETTING_802_1X_PHASE2_CLIENT_CERT);
1545
			break;
1546 1547
		}

1548
		if (valid) {
1549
			if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB)
1550
				priv->phase2_client_cert = g_byte_array_ref (data);
1551
			else if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH)
1552
				priv->phase2_client_cert = path_to_scheme_value (cert_path);
1553
			else
1554 1555
				g_assert_not_reached ();
		}
1556
		g_byte_array_unref (data);
1557
	}
1558

1559
	g_object_notify (G_OBJECT (setting), NM_SETTING_802_1X_PHASE2_CLIENT_CERT);
1560 1561
	return priv->phase2_client_cert != NULL;
}
1562

1563 1564 1565 1566 1567 1568 1569
/**
 * nm_setting_802_1x_get_password:
 * @setting: the #NMSetting8021x
 *
 * Returns: the password used by the authentication method, if any, as specified
 *   by the #NMSetting8021x:password property
 **/
1570 1571 1572 1573
const char *
nm_setting_802_1x_get_password (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);
1574

1575 1576 1577
	return NM_SETTING_802_1X_GET_PRIVATE (setting)->password;
}

1578 1579 1580 1581 1582 1583 1584 1585 1586
/**
 * nm_setting_802_1x_get_password_flags:
 * @setting: the #NMSetting8021x
 *
 * Returns: the #NMSettingSecretFlags pertaining to the #NMSetting8021x:password
 **/
NMSettingSecretFlags
nm_setting_802_1x_get_password_flags (NMSetting8021x *setting)
{
1587
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NM_SETTING_SECRET_FLAG_NONE);
1588 1589 1590 1591

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->password_flags;
}

1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622
/**
 * nm_setting_802_1x_get_password_raw:
 * @setting: the #NMSetting8021x
 *
 * Returns: the password used by the authentication method as a
 * UTF-8-encoded array of bytes, as specified by the
 * #NMSetting8021x:password-raw property
 **/
const GByteArray *
nm_setting_802_1x_get_password_raw (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->password_raw;
}

/**
 * nm_setting_802_1x_get_password_raw_flags:
 * @setting: the #NMSetting8021x
 *
 * Returns: the #NMSettingSecretFlags pertaining to the
 *   #NMSetting8021x:password-raw
 **/
NMSettingSecretFlags
nm_setting_802_1x_get_password_raw_flags (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NM_SETTING_SECRET_FLAG_NONE);

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->password_raw_flags;
}

1623 1624 1625 1626 1627 1628 1629
/**
 * nm_setting_802_1x_get_pin:
 * @setting: the #NMSetting8021x
 *
 * Returns: the PIN used by the authentication method, if any, as specified
 *   by the #NMSetting8021x:pin property
 **/
1630 1631 1632 1633 1634 1635 1636 1637
const char *
nm_setting_802_1x_get_pin (NMSetting8021x *setting)
{
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NULL);

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->pin;
}

1638 1639 1640 1641 1642 1643 1644 1645 1646 1647
/**
 * nm_setting_802_1x_get_pin_flags:
 * @setting: the #NMSetting8021x
 *
 * Returns: the #NMSettingSecretFlags pertaining to the
 * #NMSetting8021x:pin
 **/
NMSettingSecretFlags
nm_setting_802_1x_get_pin_flags (NMSetting8021x *setting)
{
1648
	g_return_val_if_fail (NM_IS_SETTING_802_1X (setting), NM_SETTING_SECRET_FLAG_NONE);
1649 1650 1651 1652

	return NM_SETTING_802_1X_GET_PRIVATE (setting)->pin_flags;
}

1653 1654 1655 1656 1657 1658 1659