eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

dpp-util.h (7817B)


      1 /*
      2  *
      3  *  Wireless daemon for Linux
      4  *
      5  *  Copyright (C) 2021  Intel Corporation. All rights reserved.
      6  *
      7  *  This library is free software; you can redistribute it and/or
      8  *  modify it under the terms of the GNU Lesser General Public
      9  *  License as published by the Free Software Foundation; either
     10  *  version 2.1 of the License, or (at your option) any later version.
     11  *
     12  *  This library is distributed in the hope that it will be useful,
     13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  *  Lesser General Public License for more details.
     16  *
     17  *  You should have received a copy of the GNU Lesser General Public
     18  *  License along with this library; if not, write to the Free Software
     19  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20  *
     21  */
     22 
     23 #include "src/defs.h"
     24 
     25 struct l_ecc_point;
     26 struct l_ecc_scalar;
     27 enum ie_rsn_akm_suite;
     28 struct scan_freq_set;
     29 
     30 struct dpp_uri_info {
     31 	struct scan_freq_set *freqs;
     32 	struct l_ecc_point *boot_public;
     33 	uint8_t mac[6];
     34 	char *information;
     35 	uint8_t version;
     36 	char *host;
     37 };
     38 
     39 enum dpp_frame_type {
     40 	DPP_FRAME_AUTHENTICATION_REQUEST	= 0,
     41 	DPP_FRAME_AUTHENTICATION_RESPONSE	= 1,
     42 	DPP_FRAME_AUTHENTICATION_CONFIRM	= 2,
     43 	/* 3 - 4 reserved */
     44 	DPP_FRAME_PEER_DISCOVERY_REQUEST	= 5,
     45 	DPP_FRAME_PEER_DISCOVERY_RESPONSE	= 6,
     46 	DPP_FRAME_PKEX_VERSION1_XCHG_REQUEST	= 7,
     47 	DPP_FRAME_PKEX_XCHG_RESPONSE		= 8,
     48 	DPP_FRAME_PKEX_COMMIT_REVEAL_REQUEST	= 9,
     49 	DPP_FRAME_PKEX_COMMIT_REVEAL_RESPONSE	= 10,
     50 	DPP_FRAME_CONFIGURATION_RESULT		= 11,
     51 	DPP_FRAME_CONNECTION_STATUS_RESULT	= 12,
     52 	DPP_FRAME_PRESENCE_ANNOUNCEMENT		= 13,
     53 	DPP_FRAME_RECONF_ANNOUNCEMENT		= 14,
     54 	DPP_FRAME_RECONF_AUTHENTICATION_REQUEST	= 15,
     55 	DPP_FRAME_RECONF_AUTHENTICATION_RESPONSE = 16,
     56 	DPP_FRAME_RECONF_AUTHENTICATION_CONFIRM = 17,
     57 	DPP_FRAME_PKEX_XCHG_REQUEST		= 18,
     58 	/* 19 - 255 reserved */
     59 };
     60 
     61 enum dpp_status {
     62 	DPP_STATUS_OK,
     63 	DPP_STATUS_NOT_COMPATIBLE,
     64 	DPP_STATUS_AUTH_FAILURE,
     65 	DPP_STATUS_BAD_CODE,
     66 	DPP_STATUS_BAD_GROUP,
     67 	DPP_STATUS_CONFIGURE_FAILURE,
     68 	DPP_STATUS_RESPONSE_PENDING,
     69 	DPP_STATUS_INVALID_CONNECTOR,
     70 	DPP_STATUS_NO_MATCH,
     71 	DPP_STATUS_CONFIG_REJECTED,
     72 	DPP_STATUS_NO_AP,
     73 	DPP_STATUS_CONFIGURE_PENDING,
     74 	DPP_STATUS_CSR_NEEDED,
     75 	DPP_STATUS_CSR_BAD,
     76 	DPP_STATUS_NEW_KEY_NEEDED,
     77 };
     78 
     79 enum dpp_attribute_type {
     80 	/* 0000 - 0FFF reserved */
     81 	DPP_ATTR_STATUS				= 0x1000,
     82 	DPP_ATTR_INITIATOR_BOOT_KEY_HASH	= 0x1001,
     83 	DPP_ATTR_RESPONDER_BOOT_KEY_HASH	= 0x1002,
     84 	DPP_ATTR_INITIATOR_PROTOCOL_KEY		= 0x1003,
     85 	DPP_ATTR_WRAPPED_DATA			= 0x1004,
     86 	DPP_ATTR_INITIATOR_NONCE		= 0x1005,
     87 	DPP_ATTR_INITIATOR_CAPABILITIES		= 0x1006,
     88 	DPP_ATTR_RESPONDER_NONCE		= 0x1007,
     89 	DPP_ATTR_RESPONDER_CAPABILITIES		= 0x1008,
     90 	DPP_ATTR_RESPONDER_PROTOCOL_KEY		= 0x1009,
     91 	DPP_ATTR_INITIATOR_AUTH_TAG		= 0x100a,
     92 	DPP_ATTR_RESPONDER_AUTH_TAG		= 0x100b,
     93 	DPP_ATTR_CONFIGURATION_OBJECT		= 0x100c,
     94 	DPP_ATTR_CONNECTOR			= 0x100d,
     95 	DPP_ATTR_CONFIGURATION_REQUEST		= 0x100e,
     96 	DPP_ATTR_BOOTSTRAPPING_KEY		= 0x100f,
     97 	/* 1010 - 1011 reserved */
     98 	DPP_ATTR_FINITE_CYCLIC_GROUP		= 0x1012,
     99 	DPP_ATTR_ENCRYPTED_KEY			= 0x1013,
    100 	DPP_ATTR_ENROLLEE_NONCE			= 0x1014,
    101 	DPP_ATTR_CODE_IDENTIFIER		= 0x1015,
    102 	DPP_ATTR_TRANSACTION_ID			= 0x1016,
    103 	DPP_ATTR_BOOTSTRAPPING_INFO		= 0x1017,
    104 	DPP_ATTR_CHANNEL			= 0x1018,
    105 	DPP_ATTR_PROTOCOL_VERSION		= 0x1019,
    106 	DPP_ATTR_ENVELOPED_DATA			= 0x101a,
    107 	DPP_ATTR_SEND_CONN_STATUS		= 0x101b,
    108 	DPP_ATTR_CONN_STATUS			= 0x101c,
    109 	DPP_ATTR_RECONFIGURATION_FLAGS		= 0x101d,
    110 	DPP_ATTR_C_SIGN_KEY_HASH		= 0x101e,
    111 	DPP_ATTR_CSR_ATTRIBUTES_REQUEST		= 0x101f,
    112 	DPP_ATTR_ANONCE				= 0x1020,
    113 	DPP_ATTR_EID				= 0x1021,
    114 	DPP_ATTR_CONFIGURATOR_NONCE		= 0x1022,
    115 };
    116 
    117 struct dpp_configuration {
    118 	char ssid[SSID_MAX_SIZE + 1];
    119 	size_t ssid_len;
    120 	uint32_t akm_suites;
    121 	char *passphrase;
    122 	char *psk;		/* hex string */
    123 
    124 	/* "3rd party extensions" only applicable for two IWD peers */
    125 	bool send_hostname : 1;
    126 	bool hidden : 1;
    127 };
    128 
    129 struct dpp_configuration *dpp_parse_configuration_object(const char *json,
    130 							size_t json_len);
    131 struct dpp_configuration *dpp_configuration_new(
    132 					const struct l_settings *settings,
    133 					const char *ssid,
    134 					enum ie_rsn_akm_suite akm_suite);
    135 char *dpp_configuration_to_json(struct dpp_configuration *config);
    136 void dpp_configuration_free(struct dpp_configuration *conf);
    137 
    138 struct dpp_attr_iter {
    139 	const uint8_t *pos;
    140 	const uint8_t *end;
    141 };
    142 
    143 void dpp_attr_iter_init(struct dpp_attr_iter *iter, const uint8_t *pdu,
    144 			size_t len);
    145 bool dpp_attr_iter_next(struct dpp_attr_iter *iter,
    146 			enum dpp_attribute_type *type, size_t *len,
    147 			const uint8_t **data);
    148 uint8_t *dpp_unwrap_attr(const void *ad0, size_t ad0_len, const void *ad1,
    149 				size_t ad1_len, const void *key, size_t key_len,
    150 				const void *wrapped, size_t wrapped_len,
    151 				size_t *unwrapped_len);
    152 size_t dpp_append_attr(uint8_t *to, enum dpp_attribute_type type,
    153 				void *attr, size_t attr_len);
    154 size_t dpp_append_wrapped_data(const void *ad0, size_t ad0_len, const void *ad1,
    155 				size_t ad1_len, uint8_t *to, size_t to_len,
    156 				const void *key, size_t key_len,
    157 				size_t num_attrs, ...);
    158 
    159 char *dpp_generate_uri(const uint8_t *asn1, size_t asn1_len, uint8_t version,
    160 			const uint8_t *mac, const uint32_t *freqs,
    161 			size_t freqs_len, const char *info, const char *host);
    162 
    163 size_t dpp_nonce_len_from_key_len(size_t len);
    164 
    165 bool dpp_hash(enum l_checksum_type type, uint8_t *out, unsigned int num, ...);
    166 
    167 bool dpp_derive_r_auth(const void *i_nonce, const void *r_nonce,
    168 				size_t nonce_len, struct l_ecc_point *i_proto,
    169 				struct l_ecc_point *r_proto,
    170 				struct l_ecc_point *i_boot,
    171 				struct l_ecc_point *r_boot,
    172 				void *r_auth);
    173 bool dpp_derive_i_auth(const void *r_nonce, const void *i_nonce,
    174 				size_t nonce_len, struct l_ecc_point *r_proto,
    175 				struct l_ecc_point *i_proto,
    176 				struct l_ecc_point *r_boot,
    177 				struct l_ecc_point *i_boot, void *i_auth);
    178 struct l_ecc_scalar *dpp_derive_k1(const struct l_ecc_point *i_proto_public,
    179 				const struct l_ecc_scalar *boot_private,
    180 				void *k1);
    181 struct l_ecc_scalar *dpp_derive_k2(const struct l_ecc_point *i_proto_public,
    182 				const struct l_ecc_scalar *proto_private,
    183 				void *k2);
    184 bool dpp_derive_ke(const uint8_t *i_nonce, const uint8_t *r_nonce,
    185 				struct l_ecc_scalar *m, struct l_ecc_scalar *n,
    186 				struct l_ecc_point *l, void *ke);
    187 
    188 uint8_t *dpp_point_to_asn1(const struct l_ecc_point *p, size_t *len_out);
    189 struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len);
    190 
    191 struct dpp_uri_info *dpp_parse_uri(const char *uri);
    192 void dpp_free_uri_info(struct dpp_uri_info *info);
    193 
    194 struct l_ecc_point *dpp_derive_qi(const struct l_ecc_curve *curve,
    195 					const char *key,
    196 					const char *identifier,
    197 					const uint8_t *mac_initiator);
    198 struct l_ecc_point *dpp_derive_qr(const struct l_ecc_curve *curve,
    199 					const char *key,
    200 					const char *identifier,
    201 					const uint8_t *mac_responder);
    202 struct l_ecc_point *dpp_derive_li(
    203 				const struct l_ecc_point *boot_public,
    204 				const struct l_ecc_point *proto_public,
    205 				const struct l_ecc_scalar *boot_private);
    206 struct l_ecc_point *dpp_derive_lr(
    207 				const struct l_ecc_scalar *boot_private,
    208 				const struct l_ecc_scalar *proto_private,
    209 				const struct l_ecc_point *peer_public);
    210 bool dpp_derive_z(const uint8_t *mac_i, const uint8_t *mac_r,
    211 				const struct l_ecc_point *n,
    212 				const struct l_ecc_point *m,
    213 				const struct l_ecc_point *k,
    214 				const char *key,
    215 				const char *identifier,
    216 				void *z_out, size_t *z_len);
    217 bool dpp_derive_u(const struct l_ecc_point *j,
    218 			const uint8_t *mac_i,
    219 			const struct l_ecc_point *a,
    220 			const struct l_ecc_point *y,
    221 			const struct l_ecc_point *x,
    222 			void *u_out, size_t *u_len);
    223 bool dpp_derive_v(const struct l_ecc_point *l, const uint8_t *mac,
    224 			const struct l_ecc_point *b,
    225 			const struct l_ecc_point *x,
    226 			const struct l_ecc_point *y,
    227 			void *v_out, size_t *v_len);