diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index f794c67b2b..353afd6c52 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -1913,9 +1913,8 @@ nmc_property_set_bytes (NMSetting *setting, const char *prop, const char *value, gs_free char *val_strip = NULL; gs_free const char **strv = NULL; const char **iter; - GBytes *bytes; - GByteArray *array = NULL; - gboolean success = TRUE; + gs_unref_bytes GBytes *bytes = NULL; + GByteArray *array; nm_assert (!error || !*error); @@ -1937,8 +1936,7 @@ nmc_property_set_bytes (NMSetting *setting, const char *prop, const char *value, if (v == -1) { g_set_error (error, 1, 0, _("'%s' is not a valid hex character"), *iter); g_byte_array_free (array, TRUE); - success = FALSE; - goto done; + return FALSE; } v8 = v; g_byte_array_append (array, &v8, 1); @@ -1946,13 +1944,8 @@ nmc_property_set_bytes (NMSetting *setting, const char *prop, const char *value, bytes = g_byte_array_free_to_bytes (array); done: - if (success) - g_object_set (setting, prop, bytes, NULL); - - if (bytes) - g_bytes_unref (bytes); - - return success; + g_object_set (setting, prop, bytes, NULL); + return TRUE; } /*****************************************************************************/ diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index 172f9c99e4..5f406cc64a 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -1124,6 +1124,29 @@ _normalize_wireless_mac_address_randomization (NMConnection *self, GHashTable *p return FALSE; } +static gboolean +_normalize_macsec (NMConnection *self, GHashTable *parameters) +{ + NMSettingMacsec *s_macsec = nm_connection_get_setting_macsec (self); + gboolean changed = FALSE; + + if (!s_macsec) + return FALSE; + + if (nm_setting_macsec_get_mode (s_macsec) != NM_SETTING_MACSEC_MODE_PSK) { + if (nm_setting_macsec_get_mka_cak (s_macsec)) { + g_object_set (s_macsec, NM_SETTING_MACSEC_MKA_CAK, NULL, NULL); + changed = TRUE; + } + if (nm_setting_macsec_get_mka_ckn (s_macsec)) { + g_object_set (s_macsec, NM_SETTING_MACSEC_MKA_CKN, NULL, NULL); + changed = TRUE; + } + } + + return changed; +} + static gboolean _normalize_team_config (NMConnection *self, GHashTable *parameters) { @@ -1564,6 +1587,7 @@ nm_connection_normalize (NMConnection *connection, was_modified |= _normalize_bond_mode (connection, parameters); was_modified |= _normalize_bond_options (connection, parameters); was_modified |= _normalize_wireless_mac_address_randomization (connection, parameters); + was_modified |= _normalize_macsec (connection, parameters); was_modified |= _normalize_team_config (connection, parameters); was_modified |= _normalize_team_port_config (connection, parameters); was_modified |= _normalize_bluetooth_type (connection, parameters); diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index f0d4e40f93..8b36bbd27b 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -212,15 +212,26 @@ guint nm_setting_ethtool_init_features (NMSettingEthtool *setting, guint8 *_nm_utils_hwaddr_aton (const char *asc, gpointer buffer, gsize buffer_length, gsize *out_length); const char *nm_utils_hwaddr_ntoa_buf (gconstpointer addr, gsize addr_len, gboolean upper_case, char *buf, gsize buf_len); -char *_nm_utils_bin2str (gconstpointer addr, gsize length, gboolean upper_case); -void _nm_utils_bin2str_full (gconstpointer addr, gsize length, const char delimiter, gboolean upper_case, char *out); +char *_nm_utils_bin2hexstr_full (gconstpointer addr, gsize length, const char delimiter, gboolean upper_case, char *out); -guint8 *_nm_utils_str2bin_full (const char *asc, - gboolean delimiter_required, - const char *delimiter_candidates, - guint8 *buffer, - gsize buffer_length, - gsize *out_len); +guint8 *_nm_utils_hexstr2bin_full (const char *hexstr, + gboolean allow_0x_prefix, + gboolean delimiter_required, + const char *delimiter_candidates, + gsize required_len, + guint8 *buffer, + gsize buffer_len, + gsize *out_len); + +#define _nm_utils_hexstr2bin_buf(hexstr, allow_0x_prefix, delimiter_required, delimiter_candidates, buffer) \ + _nm_utils_hexstr2bin_full ((hexstr), (allow_0x_prefix), (delimiter_required), (delimiter_candidates), G_N_ELEMENTS (buffer), (buffer), G_N_ELEMENTS (buffer), NULL) + +guint8 *_nm_utils_hexstr2bin_alloc (const char *hexstr, + gboolean allow_0x_prefix, + gboolean delimiter_required, + const char *delimiter_candidates, + gsize required_len, + gsize *out_len); GSList * _nm_utils_hash_values_to_slist (GHashTable *hash); diff --git a/libnm-core/nm-setting-macsec.c b/libnm-core/nm-setting-macsec.c index 2c7cff23b1..a9b1d550ad 100644 --- a/libnm-core/nm-setting-macsec.c +++ b/libnm-core/nm-setting-macsec.c @@ -25,6 +25,8 @@ #include #include +#include "nm-utils/nm-secret-utils.h" + #include "nm-utils.h" #include "nm-core-types-internal.h" #include "nm-setting-connection.h" @@ -254,7 +256,7 @@ verify_macsec_key (const char *key, gboolean cak, GError **error) req_len = cak ? NM_SETTING_MACSEC_MKA_CAK_LENGTH : NM_SETTING_MACSEC_MKA_CKN_LENGTH; - if (strlen (key) != req_len) { + if (strlen (key) != (gsize) req_len) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -340,6 +342,10 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) g_prefix_error (error, "%s.%s: ", NM_SETTING_MACSEC_SETTING_NAME, NM_SETTING_MACSEC_MKA_CKN); return FALSE; } + if (!verify_macsec_key (priv->mka_cak, TRUE, error)) { + g_prefix_error (error, "%s.%s: ", NM_SETTING_MACSEC_SETTING_NAME, NM_SETTING_MACSEC_MKA_CAK); + return FALSE; + } } else if (priv->mode == NM_SETTING_MACSEC_MODE_EAP) { if (!s_8021x) { g_set_error (error, @@ -350,6 +356,13 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) g_prefix_error (error, "%s: ", NM_SETTING_MACSEC_SETTING_NAME); return FALSE; } + } else { + g_set_error_literal (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("must be either psk (0) or eap (1)")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_MACSEC_SETTING_NAME, NM_SETTING_MACSEC_MODE); + return FALSE; } if (priv->port <= 0 || priv->port > 65534) { @@ -362,6 +375,17 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } + if ( priv->mode != NM_SETTING_MACSEC_MODE_PSK + && (priv->mka_cak || priv->mka_ckn)) { + g_set_error_literal (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("only valid for psk mode")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_MACSEC_SETTING_NAME, + priv->mka_cak ? NM_SETTING_MACSEC_MKA_CAK : NM_SETTING_MACSEC_MKA_CKN); + return NM_SETTING_VERIFY_NORMALIZABLE; + } + return TRUE; } @@ -389,7 +413,7 @@ set_property (GObject *object, guint prop_id, priv->encrypt = g_value_get_boolean (value); break; case PROP_MKA_CAK: - g_free (priv->mka_cak); + nm_free_secret (priv->mka_cak); priv->mka_cak = g_value_dup_string (value); break; case PROP_MKA_CAK_FLAGS: @@ -462,10 +486,7 @@ finalize (GObject *object) NMSettingMacsecPrivate *priv = NM_SETTING_MACSEC_GET_PRIVATE (setting); g_free (priv->parent); - if (priv->mka_cak) { - memset (priv->mka_cak, 0, strlen (priv->mka_cak)); - g_free (priv->mka_cak); - } + nm_free_secret (priv->mka_cak); g_free (priv->mka_ckn); G_OBJECT_CLASS (nm_setting_macsec_parent_class)->finalize (object); diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index b880f0f5aa..724c1a6c24 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -3527,60 +3527,68 @@ nm_utils_hwaddr_len (int type) } guint8 * -_nm_utils_str2bin_full (const char *asc, - gboolean delimiter_required, - const char *delimiter_candidates, - guint8 *buffer, - gsize buffer_length, - gsize *out_len) +_nm_utils_hexstr2bin_full (const char *hexstr, + gboolean allow_0x_prefix, + gboolean delimiter_required, + const char *delimiter_candidates, + gsize required_len, + guint8 *buffer, + gsize buffer_len, + gsize *out_len) { - const char *in = asc; + const char *in = hexstr; guint8 *out = buffer; gboolean delimiter_has = TRUE; guint8 delimiter = '\0'; + gsize len; - nm_assert (asc); + nm_assert (hexstr); nm_assert (buffer); - nm_assert (buffer_length); - nm_assert (out_len); + nm_assert (required_len > 0 || out_len); + + if ( allow_0x_prefix + && in[0] == '0' + && in[1] == 'x') + in += 2; while (TRUE) { const guint8 d1 = in[0]; guint8 d2; + int i1, i2; - if (!g_ascii_isxdigit (d1)) - return NULL; - -#define HEXVAL(c) ((c) <= '9' ? (c) - '0' : ((c) & 0x4F) - ('A' - 10)) + i1 = nm_utils_hexchar_to_int (d1); + if (i1 < 0) + goto fail; /* If there's no leading zero (ie "aa:b:cc") then fake it */ d2 = in[1]; - if (d2 && g_ascii_isxdigit (d2)) { - *out++ = (HEXVAL (d1) << 4) + HEXVAL (d2); + if ( d2 + && (i2 = nm_utils_hexchar_to_int (d2)) >= 0) { + *out++ = (i1 << 4) + i2; d2 = in[2]; if (!d2) break; in += 2; } else { /* Fake leading zero */ - *out++ = HEXVAL (d1); + *out++ = i1; if (!d2) { if (!delimiter_has) { /* when using no delimiter, there must be pairs of hex chars */ - return NULL; + goto fail; } break; } in += 1; } - if (--buffer_length == 0) - return NULL; + if (--buffer_len == 0) + goto fail; if (delimiter_has) { if (d2 != delimiter) { if (delimiter) - return NULL; + goto fail; if (delimiter_candidates) { while (delimiter_candidates[0]) { if (delimiter_candidates++[0] == d2) @@ -3589,7 +3597,7 @@ _nm_utils_str2bin_full (const char *asc, } if (!delimiter) { if (delimiter_required) - return NULL; + goto fail; delimiter_has = FALSE; continue; } @@ -3598,11 +3606,66 @@ _nm_utils_str2bin_full (const char *asc, } } - *out_len = out - buffer; - return buffer; + len = out - buffer; + if ( required_len == 0 + || len == required_len) { + NM_SET_OUT (out_len, len); + return buffer; + } + +fail: + NM_SET_OUT (out_len, 0); + return NULL; } -#define hwaddr_aton(asc, buffer, buffer_length, out_len) _nm_utils_str2bin_full ((asc), TRUE, ":-", (buffer), (buffer_length), (out_len)) +guint8 * +_nm_utils_hexstr2bin_alloc (const char *hexstr, + gboolean allow_0x_prefix, + gboolean delimiter_required, + const char *delimiter_candidates, + gsize required_len, + gsize *out_len) +{ + guint8 *buffer; + gsize buffer_len, len; + + g_return_val_if_fail (hexstr, NULL); + + nm_assert (required_len > 0 || out_len); + + if ( allow_0x_prefix + && hexstr[0] == '0' + && hexstr[1] == 'x') + hexstr += 2; + + if (!hexstr[0]) + goto fail; + + if (required_len > 0) + buffer_len = required_len; + else + buffer_len = strlen (hexstr) / 2 + 3; + + buffer = g_malloc (buffer_len); + + if (_nm_utils_hexstr2bin_full (hexstr, + FALSE, + delimiter_required, + delimiter_candidates, + required_len, + buffer, + buffer_len, + &len)) { + NM_SET_OUT (out_len, len); + return buffer; + } + + g_free (buffer); + +fail: + NM_SET_OUT (out_len, 0); + return NULL; +} /** * nm_utils_hexstr2bin: @@ -3619,23 +3682,17 @@ GBytes * nm_utils_hexstr2bin (const char *hex) { guint8 *buffer; - gsize buffer_length, len; + gsize len; - g_return_val_if_fail (hex != NULL, NULL); - - if (hex[0] == '0' && hex[1] == 'x') - hex += 2; - - buffer_length = strlen (hex) / 2 + 3; - buffer = g_malloc (buffer_length); - if (!_nm_utils_str2bin_full (hex, FALSE, ":", buffer, buffer_length, &len)) { - g_free (buffer); + buffer = _nm_utils_hexstr2bin_alloc (hex, TRUE, FALSE, ":", 0, &len); + if (!buffer) return NULL; - } buffer = g_realloc (buffer, len); return g_bytes_new_take (buffer, len); } +#define hwaddr_aton(asc, buffer, buffer_len, out_len) _nm_utils_hexstr2bin_full ((asc), FALSE, TRUE, ":-", 0, (buffer), (buffer_len), (out_len)) + /** * nm_utils_hwaddr_atoba: * @asc: the ASCII representation of a hardware address @@ -3728,16 +3785,46 @@ nm_utils_hwaddr_aton (const char *asc, gpointer buffer, gsize length) return buffer; } -void -_nm_utils_bin2str_full (gconstpointer addr, gsize length, const char delimiter, gboolean upper_case, char *out) +/** + * _nm_utils_bin2hexstr_full: + * @addr: pointer of @length bytes. + * @length: number of bytes in @addr + * @delimiter: either '\0', otherwise the output string will have the + * given delimiter character between each two hex numbers. + * @upper_case: if TRUE, use upper case ASCII characters for hex. + * @out: if %NULL, the function will allocate a new buffer of + * either (@length*2+1) or (@length*3) bytes, depending on whether + * a @delimiter is specified. In that case, the allocated buffer will + * be returned and must be freed by the caller. + * If not %NULL, the buffer must already be preallocated and contain + * at least (@length*2+1) or (@length*3) bytes, depending on the delimiter. + * + * Returns: the binary value converted to a hex string. If @out is given, + * this always returns @out. If @out is %NULL, a newly allocated string + * is returned. + */ +char * +_nm_utils_bin2hexstr_full (gconstpointer addr, + gsize length, + char delimiter, + gboolean upper_case, + char *out) { const guint8 *in = addr; const char *LOOKUP = upper_case ? "0123456789ABCDEF" : "0123456789abcdef"; + char *out0; nm_assert (addr); - nm_assert (out); nm_assert (length > 0); + if (out) + out0 = out; + else { + out0 = out = g_new (char, delimiter == '\0' + ? length * 2 + 1 + : length * 3); + } + /* @out must contain at least @length*3 bytes if @delimiter is set, * otherwise, @length*2+1. */ @@ -3754,6 +3841,7 @@ _nm_utils_bin2str_full (gconstpointer addr, gsize length, const char delimiter, } *out = 0; + return out0; } /** @@ -3779,7 +3867,8 @@ nm_utils_bin2hexstr (gconstpointer src, gsize len, int final_len) g_return_val_if_fail (final_len < 0 || (gsize) final_len < buflen, NULL); result = g_malloc (buflen); - _nm_utils_bin2str_full (src, len, '\0', FALSE, result); + + _nm_utils_bin2hexstr_full (src, len, '\0', FALSE, result); /* Cut converted key off at the correct length for this cipher type */ if (final_len >= 0 && (gsize) final_len < buflen) @@ -3800,14 +3889,10 @@ nm_utils_bin2hexstr (gconstpointer src, gsize len, int final_len) char * nm_utils_hwaddr_ntoa (gconstpointer addr, gsize length) { - char *result; - g_return_val_if_fail (addr, g_strdup ("")); g_return_val_if_fail (length > 0, g_strdup ("")); - result = g_malloc (length * 3); - _nm_utils_bin2str_full (addr, length, ':', TRUE, result); - return result; + return _nm_utils_bin2hexstr_full (addr, length, ':', TRUE, NULL); } const char * @@ -3819,31 +3904,7 @@ nm_utils_hwaddr_ntoa_buf (gconstpointer addr, gsize addr_len, gboolean upper_cas if (buf_len < addr_len * 3) g_return_val_if_reached (NULL); - _nm_utils_bin2str_full (addr, addr_len, ':', upper_case, buf); - return buf; -} - -/** - * _nm_utils_bin2str: - * @addr: (type guint8) (array length=length): a binary hardware address - * @length: the length of @addr - * @upper_case: the case for the hexadecimal digits. - * - * Converts @addr to textual form. - * - * Return value: (transfer full): the textual form of @addr - */ -char * -_nm_utils_bin2str (gconstpointer addr, gsize length, gboolean upper_case) -{ - char *result; - - g_return_val_if_fail (addr, g_strdup ("")); - g_return_val_if_fail (length > 0, g_strdup ("")); - - result = g_malloc (length * 3); - _nm_utils_bin2str_full (addr, length, ':', upper_case, result); - return result; + return _nm_utils_bin2hexstr_full (addr, addr_len, ':', upper_case, buf); } /** @@ -4510,7 +4571,7 @@ _nm_utils_dhcp_duid_valid (const char *duid, GBytes **out_duid_bin) return TRUE; } - if (_nm_utils_str2bin_full (duid, FALSE, ":", duid_arr, sizeof (duid_arr), &duid_len)) { + if (_nm_utils_hexstr2bin_full (duid, FALSE, FALSE, ":", 0, duid_arr, sizeof (duid_arr), &duid_len)) { /* MAX DUID length is 128 octects + the type code (2 octects). */ if ( duid_len > 2 && duid_len <= (128 + 2)) { diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 0a7cea9782..a232f5ccf6 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -14417,9 +14417,11 @@ nm_device_spawn_iface_helper (NMDevice *self) if (client_id) { g_ptr_array_add (argv, g_strdup ("--dhcp4-clientid")); g_ptr_array_add (argv, - _nm_utils_bin2str (g_bytes_get_data (client_id, NULL), - g_bytes_get_size (client_id), - FALSE)); + _nm_utils_bin2hexstr_full (g_bytes_get_data (client_id, NULL), + g_bytes_get_size (client_id), + ':', + FALSE, + NULL)); } hostname = nm_dhcp_client_get_hostname (priv->dhcp4.client); @@ -14457,9 +14459,11 @@ nm_device_spawn_iface_helper (NMDevice *self) if (nm_device_get_ip_iface_identifier (self, &iid, FALSE)) { g_ptr_array_add (argv, g_strdup ("--iid")); g_ptr_array_add (argv, - _nm_utils_bin2str (iid.id_u8, - sizeof (NMUtilsIPv6IfaceId), - FALSE)); + _nm_utils_bin2hexstr_full (iid.id_u8, + sizeof (NMUtilsIPv6IfaceId), + ':', + FALSE, + NULL)); } g_ptr_array_add (argv, g_strdup ("--addr-gen-mode")); diff --git a/src/dhcp/nm-dhcp-utils.c b/src/dhcp/nm-dhcp-utils.c index 6bbc670b28..9b1653b8f9 100644 --- a/src/dhcp/nm-dhcp-utils.c +++ b/src/dhcp/nm-dhcp-utils.c @@ -726,10 +726,10 @@ nm_dhcp_utils_duid_to_string (GBytes *duid) gconstpointer data; gsize len; - g_return_val_if_fail (duid != NULL, NULL); + g_return_val_if_fail (duid, NULL); data = g_bytes_get_data (duid, &len); - return _nm_utils_bin2str (data, len, FALSE); + return _nm_utils_bin2hexstr_full (data, len, ':', FALSE, NULL); } /** diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index c7c5b90131..a3a878e10e 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -189,7 +189,7 @@ _secret_password_raw_to_bytes (const char *ifcfg_key, password_raw += 2; secret = nm_secret_buf_new (strlen (password_raw) / 2 + 3); - if (!_nm_utils_str2bin_full (password_raw, FALSE, ":", secret->bin, secret->len, &len)) { + if (!_nm_utils_hexstr2bin_full (password_raw, FALSE, FALSE, ":", 0, secret->bin, secret->len, &len)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid hex password in %s", ifcfg_key); diff --git a/src/supplicant/nm-supplicant-config.c b/src/supplicant/nm-supplicant-config.c index 845dade570..0f99f9a70c 100644 --- a/src/supplicant/nm-supplicant-config.c +++ b/src/supplicant/nm-supplicant-config.c @@ -26,6 +26,8 @@ #include #include +#include "nm-core-internal.h" + #include "nm-supplicant-settings-verify.h" #include "nm-setting.h" #include "nm-auth-subject.h" @@ -371,7 +373,6 @@ nm_supplicant_config_add_setting_macsec (NMSupplicantConfig * self, NMSettingMacsec * setting, GError **error) { - gs_unref_bytes GBytes *bytes = NULL; const char *value; char buf[32]; int port; @@ -395,45 +396,50 @@ nm_supplicant_config_add_setting_macsec (NMSupplicantConfig * self, } if (nm_setting_macsec_get_mode (setting) == NM_SETTING_MACSEC_MODE_PSK) { + guint8 buffer_cak[NM_SETTING_MACSEC_MKA_CAK_LENGTH/2]; + guint8 buffer_ckn[NM_SETTING_MACSEC_MKA_CKN_LENGTH/2]; + if (!nm_supplicant_config_add_option (self, "key_mgmt", "NONE", -1, NULL, error)) return FALSE; - /* CAK */ value = nm_setting_macsec_get_mka_cak (setting); - if (!value) { + if ( !value + || !_nm_utils_hexstr2bin_buf (value, + FALSE, + FALSE, + NULL, + buffer_cak)) { g_set_error_literal (error, NM_SUPPLICANT_ERROR, NM_SUPPLICANT_ERROR_CONFIG, - "missing MKA CAK"); + value ? "invalid MKA CAK" : "missing MKA CAK"); return FALSE; } - - bytes = nm_utils_hexstr2bin (value); if (!nm_supplicant_config_add_option (self, "mka_cak", - g_bytes_get_data (bytes, NULL), - g_bytes_get_size (bytes), + (char *) buffer_cak, + sizeof (buffer_cak), "", error)) return FALSE; - /* CKN */ value = nm_setting_macsec_get_mka_ckn (setting); - if (!value) { + if ( !value + || !_nm_utils_hexstr2bin_buf (value, + FALSE, + FALSE, + NULL, + buffer_ckn)) { g_set_error_literal (error, NM_SUPPLICANT_ERROR, NM_SUPPLICANT_ERROR_CONFIG, - "missing MKA CKN"); + value ? "invalid MKA CKN" : "missing MKA CKN"); return FALSE; } - - - g_bytes_unref (bytes); - bytes = nm_utils_hexstr2bin (value); if (!nm_supplicant_config_add_option (self, "mka_ckn", - g_bytes_get_data (bytes, NULL), - g_bytes_get_size (bytes), + (char *) buffer_ckn, + sizeof (buffer_cak), NULL, error)) return FALSE; @@ -699,10 +705,16 @@ add_wep_key (NMSupplicantConfig *self, if ( (wep_type == NM_WEP_KEY_TYPE_UNKNOWN) || (wep_type == NM_WEP_KEY_TYPE_KEY)) { if ((key_len == 10) || (key_len == 26)) { - gs_unref_bytes GBytes *bytes = NULL; + guint8 buffer[26/2]; - bytes = nm_utils_hexstr2bin (key); - if (!bytes) { + if (!_nm_utils_hexstr2bin_full (key, + FALSE, + FALSE, + NULL, + key_len / 2, + buffer, + sizeof (buffer), + NULL)) { g_set_error (error, NM_SUPPLICANT_ERROR, NM_SUPPLICANT_ERROR_CONFIG, "cannot add wep-key %s to suplicant config because key is not hex", name); @@ -710,8 +722,8 @@ add_wep_key (NMSupplicantConfig *self, } if (!nm_supplicant_config_add_option (self, name, - g_bytes_get_data (bytes, NULL), - g_bytes_get_size (bytes), + (char *) buffer, + key_len / 2, "", error)) return FALSE; @@ -798,20 +810,22 @@ nm_supplicant_config_add_setting_wireless_security (NMSupplicantConfig *self, size_t psk_len = strlen (psk); if (psk_len == 64) { - gs_unref_bytes GBytes *bytes = NULL; + guint8 buffer[32]; /* Hex PSK */ - bytes = nm_utils_hexstr2bin (psk); - if (!bytes) { + if (!_nm_utils_hexstr2bin_buf (psk, + FALSE, + FALSE, + NULL, + buffer)) { g_set_error (error, NM_SUPPLICANT_ERROR, NM_SUPPLICANT_ERROR_CONFIG, "Cannot add psk to supplicant config due to invalid hex"); return FALSE; } - if (!nm_supplicant_config_add_option (self, "psk", - g_bytes_get_data (bytes, NULL), - g_bytes_get_size (bytes), + (char *) buffer, + sizeof (buffer), "", error)) return FALSE;