2008-07-27 20:03:46 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
2014-07-04 17:33:18 +00:00
|
|
|
/*
|
2008-07-27 20:03:46 +00:00
|
|
|
* 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.
|
2007-09-12 16:23:53 +00:00
|
|
|
*
|
2008-07-27 20:03:46 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2007-09-12 16:23:53 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-07-27 20:03:46 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2007-09-12 16:23:53 +00:00
|
|
|
*
|
2008-07-27 20:03:46 +00:00
|
|
|
* 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.
|
2007-09-12 16:23:53 +00:00
|
|
|
*
|
2014-07-04 17:33:18 +00:00
|
|
|
* Copyright 2005 - 2013 Red Hat, Inc.
|
2007-09-12 16:23:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NM_UTILS_H
|
|
|
|
#define NM_UTILS_H
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2007-10-23 10:54:37 +00:00
|
|
|
#include "nm-connection.h"
|
2012-02-08 17:56:52 +00:00
|
|
|
#include "nm-utils-enum-types.h"
|
2007-10-23 10:54:37 +00:00
|
|
|
|
2010-05-18 08:14:59 +00:00
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
2008-09-08 18:35:21 +00:00
|
|
|
/* init, deinit nm_utils */
|
|
|
|
gboolean nm_utils_init (GError **error);
|
|
|
|
void nm_utils_deinit (void);
|
|
|
|
|
2007-10-09 08:57:35 +00:00
|
|
|
/* SSID helpers */
|
2011-02-23 17:31:25 +00:00
|
|
|
gboolean nm_utils_is_empty_ssid (const guint8 *ssid, int len);
|
|
|
|
const char *nm_utils_escape_ssid (const guint8 *ssid, guint32 len);
|
|
|
|
gboolean nm_utils_same_ssid (const GByteArray *ssid1,
|
|
|
|
const GByteArray *ssid2,
|
|
|
|
gboolean ignore_trailing_null);
|
|
|
|
char * nm_utils_ssid_to_utf8 (const GByteArray *ssid);
|
2007-10-09 10:04:07 +00:00
|
|
|
|
2007-09-12 16:23:53 +00:00
|
|
|
GHashTable *nm_utils_gvalue_hash_dup (GHashTable *hash);
|
2008-07-17 17:15:38 +00:00
|
|
|
|
2014-02-12 17:28:52 +00:00
|
|
|
NM_DEPRECATED_IN_0_9_10
|
2011-02-23 17:31:25 +00:00
|
|
|
void nm_utils_slist_free (GSList *list, GDestroyNotify elem_destroy_fn);
|
2007-11-07 16:06:43 +00:00
|
|
|
|
2011-08-23 01:23:33 +00:00
|
|
|
/**
|
|
|
|
* NMUtilsSecurityType:
|
|
|
|
* @NMU_SEC_INVALID: unknown or invalid security, placeholder and not used
|
|
|
|
* @NMU_SEC_NONE: unencrypted and open
|
|
|
|
* @NMU_SEC_STATIC_WEP: static WEP keys are used for encryption
|
|
|
|
* @NMU_SEC_LEAP: Cisco LEAP is used for authentication and for generating the
|
|
|
|
* dynamic WEP keys automatically
|
|
|
|
* @NMU_SEC_DYNAMIC_WEP: standard 802.1x is used for authentication and
|
|
|
|
* generating the dynamic WEP keys automatically
|
|
|
|
* @NMU_SEC_WPA_PSK: WPA1 is used with Pre-Shared Keys (PSK)
|
|
|
|
* @NMU_SEC_WPA_ENTERPRISE: WPA1 is used with 802.1x authentication
|
|
|
|
* @NMU_SEC_WPA2_PSK: WPA2/RSN is used with Pre-Shared Keys (PSK)
|
|
|
|
* @NMU_SEC_WPA2_ENTERPRISE: WPA2 is used with 802.1x authentication
|
|
|
|
*
|
|
|
|
* Describes generic security mechanisms that 802.11 access points may offer.
|
|
|
|
* Used with nm_utils_security_valid() for checking whether a given access
|
|
|
|
* point is compatible with a network device.
|
|
|
|
**/
|
2007-10-17 21:40:17 +00:00
|
|
|
typedef enum {
|
|
|
|
NMU_SEC_INVALID = 0,
|
|
|
|
NMU_SEC_NONE,
|
|
|
|
NMU_SEC_STATIC_WEP,
|
|
|
|
NMU_SEC_LEAP,
|
|
|
|
NMU_SEC_DYNAMIC_WEP,
|
|
|
|
NMU_SEC_WPA_PSK,
|
|
|
|
NMU_SEC_WPA_ENTERPRISE,
|
|
|
|
NMU_SEC_WPA2_PSK,
|
2008-05-13 16:57:01 +00:00
|
|
|
NMU_SEC_WPA2_ENTERPRISE
|
2007-10-17 21:40:17 +00:00
|
|
|
} NMUtilsSecurityType;
|
|
|
|
|
|
|
|
gboolean nm_utils_security_valid (NMUtilsSecurityType type,
|
2011-08-23 01:23:33 +00:00
|
|
|
NMDeviceWifiCapabilities wifi_caps,
|
2007-10-17 21:40:17 +00:00
|
|
|
gboolean have_ap,
|
2007-12-27 07:17:50 +00:00
|
|
|
gboolean adhoc,
|
2011-08-23 01:23:33 +00:00
|
|
|
NM80211ApFlags ap_flags,
|
|
|
|
NM80211ApSecurityFlags ap_wpa,
|
|
|
|
NM80211ApSecurityFlags ap_rsn);
|
2007-10-17 21:40:17 +00:00
|
|
|
|
2012-10-12 19:38:49 +00:00
|
|
|
gboolean nm_utils_ap_mode_security_valid (NMUtilsSecurityType type,
|
|
|
|
NMDeviceWifiCapabilities wifi_caps);
|
|
|
|
|
2013-02-04 10:36:10 +00:00
|
|
|
gboolean nm_utils_wep_key_valid (const char *key, NMWepKeyType wep_type);
|
|
|
|
gboolean nm_utils_wpa_psk_valid (const char *psk);
|
|
|
|
|
2008-05-06 21:41:08 +00:00
|
|
|
GSList *nm_utils_ip4_addresses_from_gvalue (const GValue *value);
|
|
|
|
void nm_utils_ip4_addresses_to_gvalue (GSList *list, GValue *value);
|
|
|
|
|
2008-08-06 22:23:48 +00:00
|
|
|
GSList *nm_utils_ip4_routes_from_gvalue (const GValue *value);
|
|
|
|
void nm_utils_ip4_routes_to_gvalue (GSList *list, GValue *value);
|
|
|
|
|
2008-11-23 22:55:03 +00:00
|
|
|
guint32 nm_utils_ip4_netmask_to_prefix (guint32 netmask);
|
|
|
|
guint32 nm_utils_ip4_prefix_to_netmask (guint32 prefix);
|
2010-02-26 00:52:10 +00:00
|
|
|
guint32 nm_utils_ip4_get_default_prefix (guint32 ip);
|
2008-07-07 18:57:37 +00:00
|
|
|
|
2009-06-11 19:52:11 +00:00
|
|
|
GSList *nm_utils_ip6_addresses_from_gvalue (const GValue *value);
|
|
|
|
void nm_utils_ip6_addresses_to_gvalue (GSList *list, GValue *value);
|
|
|
|
|
|
|
|
GSList *nm_utils_ip6_routes_from_gvalue (const GValue *value);
|
|
|
|
void nm_utils_ip6_routes_to_gvalue (GSList *list, GValue *value);
|
|
|
|
|
|
|
|
GSList *nm_utils_ip6_dns_from_gvalue (const GValue *value);
|
|
|
|
void nm_utils_ip6_dns_to_gvalue (GSList *list, GValue *value);
|
|
|
|
|
2008-08-27 02:57:21 +00:00
|
|
|
char *nm_utils_uuid_generate (void);
|
|
|
|
char *nm_utils_uuid_generate_from_string (const char *s);
|
|
|
|
|
libnm-util: add nm_utils_rsa_key_encrypt() and fix crypto padding mixups
To be backwards compatible clients need to handle both paths to private
keys and the decrypted private key data, which is what used to get passed
in the private-key and phase2-private-key attributes of the 802.1x setting.
When moving a connection around between system-settings and user-settings,
if the private key is decrypted data, the settings service needs to store
that decrypted data somewhere so that the key can be sent to NM during
the connection process.
But we don't want to store the decrypted private key data, so we have to
re-encrypt it (possibly generating a private key password if one wasn't
sent with the decrypted data) and save it to disk, then send NM a path
to that private key during connection.
To help clients do this, and so that they don't have to carry around
multiple crypto implementations depending on whether they want to use
NSS or gnutls/gcrypt, add a helper to libnm-util.
Furthermore, I misunderstood a bunch of stuff with crypto padding when
writing the encrypt/decrypt functions long ago, so fix that up. Don't
return padding as part of the decrypted data, and make sure to verify
the padding's expected lengths and values when decrypting. Many thanks
to Nalin Dahyabhai for pointing me in the right direction.
2009-09-15 23:01:50 +00:00
|
|
|
GByteArray *nm_utils_rsa_key_encrypt (const GByteArray *data,
|
|
|
|
const char *in_password,
|
|
|
|
char **out_password,
|
|
|
|
GError **error);
|
2014-05-09 11:48:30 +00:00
|
|
|
GByteArray *nm_utils_rsa_key_encrypt_aes (const GByteArray *data,
|
|
|
|
const char *in_password,
|
|
|
|
char **out_password,
|
|
|
|
GError **error);
|
2012-07-16 12:42:06 +00:00
|
|
|
gboolean nm_utils_file_is_pkcs12 (const char *filename);
|
libnm-util: add nm_utils_rsa_key_encrypt() and fix crypto padding mixups
To be backwards compatible clients need to handle both paths to private
keys and the decrypted private key data, which is what used to get passed
in the private-key and phase2-private-key attributes of the 802.1x setting.
When moving a connection around between system-settings and user-settings,
if the private key is decrypted data, the settings service needs to store
that decrypted data somewhere so that the key can be sent to NM during
the connection process.
But we don't want to store the decrypted private key data, so we have to
re-encrypt it (possibly generating a private key password if one wasn't
sent with the decrypted data) and save it to disk, then send NM a path
to that private key during connection.
To help clients do this, and so that they don't have to carry around
multiple crypto implementations depending on whether they want to use
NSS or gnutls/gcrypt, add a helper to libnm-util.
Furthermore, I misunderstood a bunch of stuff with crypto padding when
writing the encrypt/decrypt functions long ago, so fix that up. Don't
return padding as part of the decrypted data, and make sure to verify
the padding's expected lengths and values when decrypting. Many thanks
to Nalin Dahyabhai for pointing me in the right direction.
2009-09-15 23:01:50 +00:00
|
|
|
|
2010-05-31 13:32:13 +00:00
|
|
|
guint32 nm_utils_wifi_freq_to_channel (guint32 freq);
|
|
|
|
guint32 nm_utils_wifi_channel_to_freq (guint32 channel, const char *band);
|
|
|
|
guint32 nm_utils_wifi_find_next_channel (guint32 channel, int direction, char *band);
|
|
|
|
gboolean nm_utils_wifi_is_channel_valid (guint32 channel, const char *band);
|
|
|
|
|
2011-10-10 20:00:28 +00:00
|
|
|
/**
|
|
|
|
* NM_UTILS_HWADDR_LEN_MAX:
|
|
|
|
*
|
2014-06-13 13:47:29 +00:00
|
|
|
* The maximum length of hardware addresses handled by NetworkManager itself,
|
|
|
|
* nm_utils_hwaddr_len(), and nm_utils_hwaddr_aton().
|
2011-10-10 20:00:28 +00:00
|
|
|
*/
|
|
|
|
#define NM_UTILS_HWADDR_LEN_MAX 20 /* INFINIBAND_ALEN */
|
|
|
|
|
|
|
|
int nm_utils_hwaddr_len (int type) G_GNUC_PURE;
|
2014-02-12 17:28:52 +00:00
|
|
|
NM_DEPRECATED_IN_0_9_10
|
2011-11-18 17:11:26 +00:00
|
|
|
int nm_utils_hwaddr_type (int len) G_GNUC_PURE;
|
2011-10-10 20:00:28 +00:00
|
|
|
char *nm_utils_hwaddr_ntoa (gconstpointer addr, int type);
|
|
|
|
GByteArray *nm_utils_hwaddr_atoba (const char *asc, int type);
|
|
|
|
guint8 *nm_utils_hwaddr_aton (const char *asc, int type, gpointer buffer);
|
|
|
|
|
2014-02-12 17:28:52 +00:00
|
|
|
NM_AVAILABLE_IN_0_9_10
|
2013-06-05 19:08:52 +00:00
|
|
|
char *nm_utils_hwaddr_ntoa_len (gconstpointer addr, gsize length);
|
2014-02-12 17:28:52 +00:00
|
|
|
NM_AVAILABLE_IN_0_9_10
|
2013-06-05 19:08:52 +00:00
|
|
|
guint8 *nm_utils_hwaddr_aton_len (const char *asc, gpointer buffer, gsize length);
|
|
|
|
|
2014-02-12 17:28:52 +00:00
|
|
|
NM_AVAILABLE_IN_0_9_10
|
2013-06-11 14:20:44 +00:00
|
|
|
gboolean nm_utils_hwaddr_valid (const char *asc);
|
|
|
|
|
2014-02-12 17:28:52 +00:00
|
|
|
NM_AVAILABLE_IN_0_9_10
|
2013-03-28 11:10:36 +00:00
|
|
|
char *nm_utils_bin2hexstr (const char *bytes, int len, int final_len);
|
2014-02-12 17:28:52 +00:00
|
|
|
NM_AVAILABLE_IN_0_9_10
|
2013-03-28 11:10:36 +00:00
|
|
|
int nm_utils_hex2byte (const char *hex);
|
2014-02-12 17:28:52 +00:00
|
|
|
NM_AVAILABLE_IN_0_9_10
|
2013-03-28 11:10:36 +00:00
|
|
|
char *nm_utils_hexstr2bin (const char *hex, size_t len);
|
|
|
|
|
2012-05-23 14:19:25 +00:00
|
|
|
gboolean nm_utils_iface_valid_name(const char *name);
|
|
|
|
|
2012-09-19 14:36:07 +00:00
|
|
|
gboolean nm_utils_is_uuid (const char *str);
|
|
|
|
|
2013-10-28 10:54:22 +00:00
|
|
|
/**
|
|
|
|
* NM_UTILS_INET_ADDRSTRLEN:
|
|
|
|
*
|
|
|
|
* Defines the minimal length for a char buffer that is suitable as @dst argument
|
|
|
|
* for both nm_utils_inet4_ntop() and nm_utils_inet6_ntop().
|
|
|
|
**/
|
|
|
|
#define NM_UTILS_INET_ADDRSTRLEN INET6_ADDRSTRLEN
|
2014-02-12 17:28:52 +00:00
|
|
|
NM_AVAILABLE_IN_0_9_10
|
2013-10-28 10:54:22 +00:00
|
|
|
const char *nm_utils_inet4_ntop (in_addr_t inaddr, char *dst);
|
2014-02-12 17:28:52 +00:00
|
|
|
NM_AVAILABLE_IN_0_9_10
|
2013-10-28 10:54:22 +00:00
|
|
|
const char *nm_utils_inet6_ntop (const struct in6_addr *in6addr, char *dst);
|
|
|
|
|
2014-02-11 14:53:35 +00:00
|
|
|
NM_AVAILABLE_IN_0_9_10
|
|
|
|
gboolean nm_utils_check_virtual_device_compatibility (GType virtual_type, GType other_type);
|
|
|
|
|
2011-05-31 12:06:13 +00:00
|
|
|
G_END_DECLS
|
|
|
|
|
2007-09-12 16:23:53 +00:00
|
|
|
#endif /* NM_UTILS_H */
|