eap-tls: Make use of l_pem_load_container_file()
PATCH 1/2 eap-tls: Make use of l_pem_load_container_file()
This allows .p12 files and other formats to be used. When a single file contains both the client certificates and the private key, it can be given as either EAP-{TLS,PEAP,TTLS}-ClientCert or -ClientKey. Also both settings can point to the same or different files and only the certificates will be loaded from one and only the key from the other (if different).
--- src/eap-tls-common.c | 302 +++++++++++++++++++++++++------------------ 1 file changed, 178 insertions(+), 124 deletions(-)
src/eap-tls-common.c +178 -124
@@ -864,31 +864,25 @@ static struct l_queue *eap_tls_load_ca_cert(struct l_settings *settings,return l_pem_load_certificate_list_from_data (pem,strlen (pem)); } -static struct l_certchain *eap_tls_load_client_cert (struct l_settings *settings, -const char *value) +static struct l_certchain *eap_tls_load_embedded_cert ( +struct l_settings *settings, +const char *value) { -const char *pem; - -if (!is_embedded (value)) -return l_pem_load_certificate_chain (value); +const char *pem =load_embedded_pem (settings, value); - pem =load_embedded_pem (settings, value);if (!pem)return NULL ;return l_pem_load_certificate_chain_from_data (pem,strlen (pem)); } -static struct l_key *eap_tls_load_priv_key (struct l_settings *settings, -const char *value,const char *passphrase, -bool *is_encrypted) +static struct l_key *eap_tls_load_embedded_priv_key (struct l_settings *settings, +const char *value, +const char *passphrase, +bool *is_encrypted) { -const char *pem; +const char *pem =load_embedded_pem (settings, value); -if (!is_embedded (value)) -return l_pem_load_private_key (value, passphrase, is_encrypted); - - pem =load_embedded_pem (settings, value);if (!pem)return NULL ;
@@ -903,11 +897,14 @@ int eap_tls_common_settings_check(struct l_settings *settings, {char setting_key[72 ];char client_cert_setting[72 ]; +char client_key_setting[72 ];char passphrase_setting[72 ];struct l_queue *cacerts =NULL ;struct l_certchain *cert =NULL ;struct l_key *priv_key =NULL ; -bool is_encrypted, is_public; +bool is_public; +bool cert_is_encrypted; +bool key_is_encrypted;int ret;const char *error_str;size_t size;
@@ -916,17 +913,32 @@ int eap_tls_common_settings_check(struct l_settings *settings,struct l_key *pub_key;const char *domain_mask_str; - L_AUTO_FREE_VAR(char *, value); + L_AUTO_FREE_VAR(char *, ca_cert); L_AUTO_FREE_VAR(char *, client_cert) = NULL; + L_AUTO_FREE_VAR(char *, client_key) = NULL; L_AUTO_FREE_VAR(char *, passphrase) = NULL; +snprintf (passphrase_setting,sizeof (passphrase_setting), +"%sClientKeyPassphrase" , prefix); + passphrase =l_settings_get_string (settings,"Security" , + passphrase_setting); + +if (!passphrase) { +const struct eap_secret_info *secret; + + secret =l_queue_find (secrets, eap_secret_info_match, + passphrase_setting); +if (secret) + passphrase =l_strdup (secret->value); + } +snprintf (setting_key,sizeof (setting_key),"%sCACert" , prefix); - value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - cacerts =eap_tls_load_ca_cert (settings, value); + ca_cert =l_settings_get_string (settings,"Security" , setting_key); +if (ca_cert) { + cacerts =eap_tls_load_ca_cert (settings, ca_cert);if (!cacerts) { -l_error ("Failed to load %s" , value); +l_error ("Failed to load %s" , ca_cert);return -EIO ; } }
@@ -935,113 +947,146 @@ int eap_tls_common_settings_check(struct l_settings *settings, "%sClientCert", prefix); client_cert =l_settings_get_string (settings,"Security" , client_cert_setting); -if (client_cert) { - cert =eap_tls_load_client_cert (settings, client_cert); - -if (!cert) { -l_error ("Failed to load %s" , client_cert); - ret = -EIO ; - goto done; - } -/* -* Sanity check that certchain provided is valid. We do not -* verify the certchain against the provided CA, since the -* CA that issued user certificates might be different from -* the one that is used to verify the peer -*/ -if (!l_certchain_verify (cert,NULL , &error_str)) { -l_error ("Certificate chain %s fails verification: %s" , - client_cert, error_str); - ret = -EINVAL ; - goto done; - } - } +snprintf (client_key_setting,sizeof (client_key_setting), +"%sClientKey" , prefix); + client_key =l_settings_get_string (settings,"Security" , + client_key_setting); -l_free (value); - -snprintf (setting_key,sizeof (setting_key),"%sClientKey" , prefix); - value =l_settings_get_string (settings,"Security" , setting_key); +/* +* If ClientCert and ClientKey are both provided, try to load only the +* certificate chain from the former and only the private key from the +* latter. If only one is present and is a file path, take whatever +* the file contains. +*/ -if (value && !client_cert) { -l_error ("%s present but no client certificate (%s)" , - setting_key, client_cert_setting); - ret = -ENOENT ; - goto done; - }else if (!value && client_cert) { -l_error ("%s present but no client private key (%s)" , - client_cert_setting, setting_key); - ret = -ENOENT ; - goto done; +if (client_cert &&is_embedded (client_cert)) { + cert =eap_tls_load_embedded_cert (settings, client_cert); + cert_is_encrypted = false; + }else if (client_cert) { +l_pem_load_container_file (client_cert, passphrase, + &cert, + client_key ?NULL : &priv_key, + &cert_is_encrypted); } -snprintf (passphrase_setting,sizeof (passphrase_setting), -"%sClientKeyPassphrase" , prefix); - passphrase =l_settings_get_string (settings,"Security" , - passphrase_setting); +if (client_key &&is_embedded (client_key)) + priv_key =eap_tls_load_embedded_priv_key (settings, client_key, + passphrase, + &key_is_encrypted); +else if (client_key) { +l_pem_load_container_file (client_key, passphrase, + client_cert ?NULL : &cert, + &priv_key, + &key_is_encrypted); + } -if (!passphrase) { -const struct eap_secret_info *secret; +/* Analyze all possible error condition */ - secret =l_queue_find (secrets, eap_secret_info_match, - passphrase_setting); -if (secret) - passphrase =l_strdup (secret->value); - } +if (client_cert && !cert) { +if (!cert_is_encrypted) { +l_error ("Failed to load %s" , client_cert); + ret = -EIO ; + goto done; + } -if (!value) {if (passphrase) { -l_error ("%s present but no client private key" -" value set (%s)" , passphrase_setting, - setting_key); - ret = -ENOENT ; +l_error ("Error loading encrypted contents from %s" , + client_cert); + ret = -EACCES ; goto done; } +/* +* We've got an encrypted file and passphrase was not saved +* in the network settings, need to request the passphrase. +*/ +eap_append_secret (out_missing, +EAP_SECRET_LOCAL_PKEY_PASSPHRASE , + passphrase_setting,NULL , client_cert, +EAP_CACHE_TEMPORARY ); ret =0 ; goto done; } - priv_key =eap_tls_load_priv_key (settings, value, passphrase, - &is_encrypted); - -if (!priv_key) { -if (!is_encrypted) { -l_error ("Error loading client private key %s" , value); +if (client_key && !priv_key) { +if (!key_is_encrypted) { +l_error ("Failed to load %s" , client_key); ret = -EIO ; goto done; }if (passphrase) { -l_error ("Error loading encrypted client private key %s" , - value); +l_error ("Error loading encrypted contents from %s" , + client_key); ret = -EACCES ; goto done; }/* -* We've got an encrypted key and passphrase was not saved +* We've got an encrypted file and passphrase was not saved * in the network settings, need to request the passphrase. */ eap_append_secret (out_missing,EAP_SECRET_LOCAL_PKEY_PASSPHRASE , - passphrase_setting,NULL , value, + passphrase_setting,NULL , client_key,EAP_CACHE_TEMPORARY ); ret =0 ; goto done; } -if (passphrase && !is_encrypted) { -l_error ("%s present but client private key %s is not encrypted" , - passphrase_setting, value); +/* We now know that the provided certificate and key (if any) load */ + +if (cert && !priv_key) { +/* priv_key is NULL so ClientKey must have been unset */ +l_error ("A client certificate was loaded (%s) but no client " +"private key found, please set %s" , + client_cert, client_key_setting); + ret = -ENOENT ; + goto done; + }else if (!cert && priv_key) { +/* cert is NULL so ClientCert must have been unset */ +l_error ("A client private key was loaded (%s) but no client " +"certificate found, please set %s" , + client_key, client_cert_setting); + ret = -ENOENT ; + goto done; + }else if (!priv_key && passphrase) { +l_error ("%s was set but no client private key (%s)" , + passphrase_setting, client_key_setting); + ret = -ENOENT ; + goto done; + }else if (!cert_is_encrypted && !key_is_encrypted && passphrase) { +l_error ("%s was set but client %sprivate key file (%s) is " +"not encrypted" , passphrase_setting, + (!client_key || !client_cert) ?"certificate and " :"" , + client_key ?: client_cert); ret = -ENOENT ; goto done; } +if (!cert) { + ret =0 ; + goto done; + } + +/* +* Sanity check that provided certchain is valid. We do not verify +* the certchain against the provided CA, since the CA that issued +* user certificates might be different from the one that is used +* to verify the peer. +*/ +if (!l_certchain_verify (cert,NULL , &error_str)) { +l_error ("The certificate chain in %s fails verification: %s" , + client_cert ?: client_key, error_str); + ret = -EINVAL ; + goto done; + } +if (!l_key_get_info (priv_key,L_KEY_RSA_PKCS1_V1_5 ,L_CHECKSUM_NONE , &size, &is_public) || is_public) { -l_error ("%s is not a private key or l_key_get_info fails" , - value); +l_error ("The key in %s is not a private key or l_key_get_info " +"fails" , client_key ?: client_cert); ret = -EINVAL ; goto done; }
@@ -1052,7 +1097,8 @@ int eap_tls_common_settings_check(struct l_settings *settings, pub_key =l_cert_get_pubkey (l_certchain_get_leaf (cert));if (!pub_key) { -l_error ("l_cert_get_pubkey fails for %s" , client_cert); +l_error ("l_cert_get_pubkey fails for the certificate in %s" , + client_cert ?: client_key); ret = -EIO ; goto done; }
@@ -1062,7 +1108,8 @@ int eap_tls_common_settings_check(struct l_settings *settings,l_key_free (pub_key);if (result != (ssize_t ) size) { -l_error ("l_key_encrypt fails with %s: %s" , client_cert, +l_error ("l_key_encrypt fails with the public key in the " +"certificate in %s: %s" , client_cert ?: client_key,strerror (-result)); ret = result; goto done;
@@ -1071,15 +1118,16 @@ int eap_tls_common_settings_check(struct l_settings *settings, result =l_key_decrypt (priv_key,L_KEY_RSA_PKCS1_V1_5 ,L_CHECKSUM_NONE , encrypted, decrypted, size, size);if (result <0 ) { -l_error ("l_key_decrypt fails with %s: %s" , value, -strerror (-result)); +l_error ("l_key_decrypt fails with the private key in %s: %s" , + client_key ?: client_cert,strerror (-result)); ret = result; goto done; }if (result !=1 || decrypted[0 ] !=0 ) { -l_error ("Private key %s does not match certificate %s" , value, - client_cert); +l_error ("The private key in %s does not match certificate in " +"%s" , client_key ?: client_cert, + client_cert ?: client_key); ret = -EINVAL ; goto done; }
@@ -1121,7 +1169,9 @@ bool eap_tls_common_settings_load(struct eap_state *eap,struct eap_tls_state *eap_tls;char setting_key[72 ];char *domain_mask_str; - L_AUTO_FREE_VAR(char *, value) = NULL; + L_AUTO_FREE_VAR(char *, ca_cert) = NULL; + L_AUTO_FREE_VAR(char *, client_cert) = NULL; + L_AUTO_FREE_VAR(char *, client_key) = NULL; L_AUTO_FREE_VAR(char *, passphrase) = NULL; eap_tls = l_new(struct eap_tls_state, 1);
@@ -1130,47 +1180,51 @@ bool eap_tls_common_settings_load(struct eap_state *eap, eap_tls->variant_ops = variant_ops; eap_tls->variant_data = variant_data; +snprintf (setting_key,sizeof (setting_key),"%sClientKeyPassphrase" , + prefix); + passphrase =l_settings_get_string (settings,"Security" , setting_key); +snprintf (setting_key,sizeof (setting_key),"%sCACert" , prefix); - value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - eap_tls->ca_cert =eap_tls_load_ca_cert (settings, value); -if (!eap_tls->ca_cert) { -l_error ("Could not load CACert %s" , value); + ca_cert =l_settings_get_string (settings,"Security" , setting_key); +if (ca_cert) { + eap_tls->ca_cert =eap_tls_load_ca_cert (settings, ca_cert); +if (!eap_tls->ca_cert) goto load_error; - } } -l_free (value); -snprintf (setting_key,sizeof (setting_key),"%sClientCert" , prefix); - value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - eap_tls->client_cert =eap_tls_load_client_cert (settings, - value); -if (!eap_tls->client_cert) { -l_error ("Could not load ClientCert %s" , value); - goto load_error; - } - } - -l_free (value); - -snprintf (setting_key,sizeof (setting_key),"%sClientKeyPassphrase" , - prefix); - passphrase =l_settings_get_string (settings,"Security" , setting_key); + client_cert =l_settings_get_string (settings,"Security" , setting_key);snprintf (setting_key,sizeof (setting_key),"%sClientKey" , prefix); - value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - eap_tls->client_key =eap_tls_load_priv_key (settings, value, + client_key =l_settings_get_string (settings,"Security" , setting_key); + +if (client_cert &&is_embedded (client_cert)) + eap_tls->client_cert =eap_tls_load_embedded_cert (settings, + client_cert); +else if (client_cert) { +l_pem_load_container_file (client_cert, passphrase, + &eap_tls->client_cert, + client_key ?NULL : + &eap_tls->client_key,NULL ); + } + +if (client_key &&is_embedded (client_key)) + eap_tls->client_key =eap_tls_load_embedded_priv_key (settings, + client_key, passphrase,NULL ); -if (!eap_tls->client_key) { -l_error ("Could not load ClientKey %s" , value); - goto load_error; - } +else if (client_key) { +l_pem_load_container_file (client_key, passphrase, + client_cert ?NULL : + &eap_tls->client_cert, + &eap_tls->client_key,NULL ); } +if ((client_cert && !eap_tls->client_cert) || + (client_key && !eap_tls->client_key) || + !eap_tls->client_cert != !eap_tls->client_key) + goto load_error; +snprintf (setting_key,sizeof (setting_key),"%sServerDomainMask" , prefix); domain_mask_str = l_settings_get_string(settings, "Security",
Signature · 1 line
2.27.0
PATCH 2/2 eap-tls: Don't skip a ServerDomainMask vs. CACert check
The check that requires CACert if ServerDomainMask is given should be independent of whether a client certificate and key are set, but was in the part of eap_tls_common_settings_check() that only runs if a certificate and key are given, move it up and simplify the logic slightly.
--- src/eap-tls-common.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-)
src/eap-tls-common.c +21 -21
@@ -899,7 +899,6 @@ int eap_tls_common_settings_check(struct l_settings *settings,char client_cert_setting[72 ];char client_key_setting[72 ];char passphrase_setting[72 ]; -struct l_queue *cacerts =NULL ;struct l_certchain *cert =NULL ;struct l_key *priv_key =NULL ;bool is_public;
@@ -913,7 +912,7 @@ int eap_tls_common_settings_check(struct l_settings *settings,struct l_key *pub_key;const char *domain_mask_str; - L_AUTO_FREE_VAR(char *, ca_cert); + L_AUTO_FREE_VAR(char *, ca_cert) = NULL; L_AUTO_FREE_VAR(char *, client_cert) = NULL; L_AUTO_FREE_VAR(char *, client_key) = NULL; L_AUTO_FREE_VAR(char *, passphrase) = NULL;
@@ -935,12 +934,31 @@ int eap_tls_common_settings_check(struct l_settings *settings,snprintf (setting_key,sizeof (setting_key),"%sCACert" , prefix); ca_cert =l_settings_get_string (settings,"Security" , setting_key);if (ca_cert) { - cacerts =eap_tls_load_ca_cert (settings, ca_cert); +struct l_queue *cacerts = +eap_tls_load_ca_cert (settings, ca_cert);if (!cacerts) {l_error ("Failed to load %s" , ca_cert);return -EIO ; } + +l_queue_destroy (cacerts, + (l_queue_destroy_func_t ) l_cert_free); + } + +/* +* Require CACert if ServerDomainMask is present. If the server +* certificate is not being checked against any trusted certificates +* there's no point validating its contents and we wouldn't even +* receive the subject DN from ell, because it may be freely made up. +*/ +snprintf (setting_key,sizeof (setting_key),"%sServerDomainMask" , + prefix); + domain_mask_str =l_settings_get_value (settings,"Security" , + setting_key); +if (domain_mask_str && !ca_cert) { +l_error ("%s was set but no CA Certificates given" , setting_key); +return -EINVAL ; } snprintf(client_cert_setting, sizeof(client_cert_setting),
@@ -1132,26 +1150,8 @@ int eap_tls_common_settings_check(struct l_settings *settings, goto done; } -/* -* Require CACert if ServerDomainMask is present. If the server -* certificate is not being checked against any trusted certificates -* there's no point validating its contents and we wouldn't even -* receive the subject DN from ell, because it may be freely made up. -*/ -snprintf (setting_key,sizeof (setting_key),"%sServerDomainMask" , - prefix); - domain_mask_str =l_settings_get_value (settings,"Security" , - setting_key); -if (domain_mask_str && !cacerts) { -l_error ("%s was set but no CA Certificates given" , setting_key); - ret = -EINVAL ; - goto done; - } - ret =0 ; done: -l_queue_destroy (cacerts, - (l_queue_destroy_func_t ) l_cert_free);l_certchain_free (cert);l_key_free (priv_key);
Signature · 1 line
2.27.0
Hi Andrew,
Quoted 10 lines · Andrew Zaborowski
This allows .p12 files and other formats to be used. When a single file contains both the client certificates and the private key, it can be given as either EAP-{TLS,PEAP,TTLS}-ClientCert or -ClientKey. Also both settings can point to the same or different files and only the certificates will be loaded from one and only the key from the other (if different).
--- src/eap-tls-common.c | 302 +++++++++++++++++++++++++------------------ 1 file changed, 178 insertions(+), 124 deletions(-)
<snip>
Quoted 12 lines
src/eap-tls-common.c +3
-1@@ -1121,7 +1169,9 @@ bool eap_tls_common_settings_load(struct eap_state *eap,struct eap_tls_state *eap_tls;char setting_key[72 ];char *domain_mask_str; - L_AUTO_FREE_VAR(char *, value) = NULL; + L_AUTO_FREE_VAR(char *, ca_cert) = NULL; + L_AUTO_FREE_VAR(char *, client_cert) = NULL; + L_AUTO_FREE_VAR(char *, client_key) = NULL; L_AUTO_FREE_VAR(char *, passphrase) = NULL; eap_tls = l_new(struct eap_tls_state, 1);
src/eap-tls-common.c bool eap_tls_common_settings_load(struct eap_state *eap, · line 1186
Quoted 7 lines
src/eap-tls-common.c +4
-0@@ -1130,47 +1180,51 @@ bool eap_tls_common_settings_load(struct eap_state *eap, eap_tls->variant_ops = variant_ops; eap_tls->variant_data = variant_data; +snprintf (setting_key,sizeof (setting_key),"%sClientKeyPassphrase" , + prefix); + passphrase =l_settings_get_string (settings,"Security" , setting_key); +
So this reminds me that ClientKeyPassphrase, ClientKey and ClientCert are already only relevant to EAP-TLS. They probably don't even belong being checked here in eap_tls_common_settins_load, etc.
src/eap-tls-common.c bool eap_tls_common_settings_load(struct eap_state *eap, · line 1192
Quoted 11 lines
src/eap-tls-common.c +4
-5snprintf (setting_key,sizeof (setting_key),"%sCACert" , prefix); - value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - eap_tls->ca_cert =eap_tls_load_ca_cert (settings, value); -if (!eap_tls->ca_cert) { -l_error ("Could not load CACert %s" , value); + ca_cert =l_settings_get_string (settings,"Security" , setting_key); +if (ca_cert) { + eap_tls->ca_cert =eap_tls_load_ca_cert (settings, ca_cert); +if (!eap_tls->ca_cert) goto load_error;
Hmm, the P12 files don't contain the CA certchain? I thought the whole point of these was to have the private key + public key + CA certchain? Otherwise I see little point in these since you effectively need to specify the P12 file _and_ the CACert file?
Quoted 50 lines
src/eap-tls-common.c +18
-25- } } -l_free (value); -snprintf (setting_key,sizeof (setting_key),"%sClientCert" , prefix); - value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - eap_tls->client_cert =eap_tls_load_client_cert (settings, - value); -if (!eap_tls->client_cert) { -l_error ("Could not load ClientCert %s" , value); - goto load_error; - } - } - -l_free (value); - -snprintf (setting_key,sizeof (setting_key),"%sClientKeyPassphrase" , - prefix); - passphrase =l_settings_get_string (settings,"Security" , setting_key); + client_cert =l_settings_get_string (settings,"Security" , setting_key);snprintf (setting_key,sizeof (setting_key),"%sClientKey" , prefix); - value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - eap_tls->client_key =eap_tls_load_priv_key (settings, value, + client_key =l_settings_get_string (settings,"Security" , setting_key); + +if (client_cert &&is_embedded (client_cert)) + eap_tls->client_cert =eap_tls_load_embedded_cert (settings, + client_cert); +else if (client_cert) { +l_pem_load_container_file (client_cert, passphrase, + &eap_tls->client_cert, + client_key ?NULL : + &eap_tls->client_key,NULL ); + } + +if (client_key &&is_embedded (client_key)) + eap_tls->client_key =eap_tls_load_embedded_priv_key (settings, + client_key, passphrase,NULL ); -if (!eap_tls->client_key) { -l_error ("Could not load ClientKey %s" , value); - goto load_error; - } +else if (client_key) { + l_pem_load_container_file(client_key, passphrase,
src/eap-tls-common.c bool eap_tls_common_settings_load(struct eap_state *eap, · line 1227
Quoted 10 lines
src/eap-tls-common.c +8
-0+ client_cert ?NULL : + &eap_tls->client_cert, + &eap_tls->client_key, NULL); } +if ((client_cert && !eap_tls->client_cert) || + (client_key && !eap_tls->client_key) || + !eap_tls->client_cert != !eap_tls->client_key) + goto load_error; +
So assuming that the CACert is also part of the P12, I'd think eap_tls_load_settings should work something like:
password = l_settings_get(.., "ClientPassphrase"); container = l_settings_get(.., "ClientKey");
if (client_key_is_container) {
// load client_key, client_cert, ca_cert
// load ServerDomainMask
return;
}
return eap_tls_common_settings_load()
src/eap-tls-common.c bool eap_tls_common_settings_load(struct eap_state *eap, · line 1230
Quoted 4 lines
src/eap-tls-common.c +0
-0snprintf (setting_key,sizeof (setting_key),"%sServerDomainMask" , prefix); domain_mask_str = l_settings_get_string(settings, "Security",
Regards,
-Denis
Hi Denis,
Quoted 29 lines · Denis Kenzior
Quoted 10 lines · Andrew Zaborowski
This allows .p12 files and other formats to be used. When a single file contains both the client certificates and the private key, it can be given as either EAP-{TLS,PEAP,TTLS}-ClientCert or -ClientKey. Also both settings can point to the same or different files and only the certificates will be loaded from one and only the key from the other (if different).
--- src/eap-tls-common.c | 302 +++++++++++++++++++++++++------------------ 1 file changed, 178 insertions(+), 124 deletions(-)<snip>
Quoted 15 lines
src/eap-tls-common.c +3
-1@@ -1121,7 +1169,9 @@ bool eap_tls_common_settings_load(struct eap_state *eap,struct eap_tls_state *eap_tls;char setting_key[72 ];char *domain_mask_str; - L_AUTO_FREE_VAR(char *, value) = NULL; + L_AUTO_FREE_VAR(char *, ca_cert) = NULL; + L_AUTO_FREE_VAR(char *, client_cert) = NULL; + L_AUTO_FREE_VAR(char *, client_key) = NULL; L_AUTO_FREE_VAR(char *, passphrase) = NULL; eap_tls = l_new(struct eap_tls_state, 1);@@ -1130,47 +1180,51 @@ bool eap_tls_common_settings_load(struct eap_state *eap, eap_tls->variant_ops = variant_ops; eap_tls->variant_data = variant_data;
Quoted 8 lines
src/eap-tls-common.c bool eap_tls_common_settings_load(struct eap_state *eap, · line 1186
Quoted 4 lines
src/eap-tls-common.c +4
-0+snprintf (setting_key,sizeof (setting_key),"%sClientKeyPassphrase" , + prefix); + passphrase =l_settings_get_string (settings,"Security" , setting_key); +So this reminds me that ClientKeyPassphrase, ClientKey and ClientCert are already only relevant to EAP-TLS. They probably don't even belong being checked here in
eap_tls_common_settins_load, etc.
Even if you deprecate EAP-PEAP-ClientCert you'll probably want to keep compatibility for some time.
Quoted 13 lines
src/eap-tls-common.c bool eap_tls_common_settings_load(struct eap_state *eap, · line 1192
Quoted 12 lines
src/eap-tls-common.c +4
-5snprintf (setting_key,sizeof (setting_key),"%sCACert" , prefix); - value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - eap_tls->ca_cert =eap_tls_load_ca_cert (settings, value); -if (!eap_tls->ca_cert) { -l_error ("Could not load CACert %s" , value); + ca_cert =l_settings_get_string (settings,"Security" , setting_key); +if (ca_cert) { + eap_tls->ca_cert =eap_tls_load_ca_cert (settings, ca_cert); +if (!eap_tls->ca_cert) goto load_error;
Quoted 4 lines
Hmm, the P12 files don't contain the CA certchain? I thought the whole point of these was to have the private key + public key + CA certchain? Otherwise I see little point in these since you effectively need to specify the P12 file _and_ the CACert file?
Putting the trusted CA certs in the same file (whether .p12, .pfx or PEM) is not a usual use case and if it exists I'd guess you have to use some PKCS#9 attributes to identify those certificates within the file? NM and wpa_s don't have logic for identifying those labels AFAIK.
You can have just your key or just your certchain or individual trusted CA certs in .p12 files without the other parts.
Quoted 68 lines
Quoted 51 lines
src/eap-tls-common.c +18
-25- } } -l_free (value); -snprintf (setting_key,sizeof (setting_key),"%sClientCert" , prefix); - value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - eap_tls->client_cert =eap_tls_load_client_cert (settings, - value); -if (!eap_tls->client_cert) { -l_error ("Could not load ClientCert %s" , value); - goto load_error; - } - } - -l_free (value); - -snprintf (setting_key,sizeof (setting_key),"%sClientKeyPassphrase" , - prefix); - passphrase =l_settings_get_string (settings,"Security" , setting_key); + client_cert =l_settings_get_string (settings,"Security" , setting_key);snprintf (setting_key,sizeof (setting_key),"%sClientKey" , prefix); - value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - eap_tls->client_key =eap_tls_load_priv_key (settings, value, + client_key =l_settings_get_string (settings,"Security" , setting_key); + +if (client_cert &&is_embedded (client_cert)) + eap_tls->client_cert =eap_tls_load_embedded_cert (settings, + client_cert); +else if (client_cert) { +l_pem_load_container_file (client_cert, passphrase, + &eap_tls->client_cert, + client_key ?NULL : + &eap_tls->client_key,NULL ); + } + +if (client_key &&is_embedded (client_key)) + eap_tls->client_key =eap_tls_load_embedded_priv_key (settings, + client_key, passphrase,NULL ); -if (!eap_tls->client_key) { -l_error ("Could not load ClientKey %s" , value); - goto load_error; - } +else if (client_key) { + l_pem_load_container_file(client_key, passphrase,src/eap-tls-common.c bool eap_tls_common_settings_load(struct eap_state *eap, · line 1227
Quoted 10 lines
src/eap-tls-common.c +8
-0+ client_cert ?NULL : + &eap_tls->client_cert, + &eap_tls->client_key, NULL); } +if ((client_cert && !eap_tls->client_cert) || + (client_key && !eap_tls->client_key) || + !eap_tls->client_cert != !eap_tls->client_key) + goto load_error; +So assuming that the CACert is also part of the P12, I'd think
eap_tls_load_settingsshould work something like:password =
l_settings_get(.., "ClientPassphrase"); container =l_settings_get(.., "ClientKey");
Quoted 7 lines
if (client_key_is_container) { // load client_key, client_cert, ca_cert // load ServerDomainMask return; }return
eap_tls_common_settings_load()
What's client_key_is_container though? If it's something set by the user I fear we're making things more complicated for the users than even wpa_s is. Also for ourselves by adding inconsistency between the tls-based methods.
The "container" naming I used in the ell patch was about all these certificate and/or key formats though. Note that if we use special settings here depending on what format we have, we're forcing the users of this (be it IT admins) to understand more about these files. And for me in the NM iwd-backend it may be directly impossible to convert those EAP settings if I have to detect what is stored inside the file since I can't decrypt it.
Best regards
Hi Andrew,
Quoted 7 lines
Quoted 3 lines
So this reminds me that ClientKeyPassphrase, ClientKey and ClientCert are already only relevant to EAP-TLS. They probably don't even belong being checked here in
eap_tls_common_settins_load, etc.Even if you deprecate EAP-PEAP-ClientCert you'll probably want to keep compatibility for some time.
Deprecate? It was never supposed to be supported. See 'man iwd.network.5'. These options are only for TLS. The use o EAP-PEAP/TTLS-ClientCert is just an artifact of how this was implemented originally.
Quoted 18 lines
Quoted 13 lines
src/eap-tls-common.c bool eap_tls_common_settings_load(struct eap_state *eap, · line 1192
Quoted 12 lines
snprintf(setting_key, sizeof(setting_key), "%sCACert", prefix);src/eap-tls-common.c +4
-5- value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - eap_tls->ca_cert =eap_tls_load_ca_cert (settings, value); -if (!eap_tls->ca_cert) { -l_error ("Could not load CACert %s" , value); + ca_cert =l_settings_get_string (settings,"Security" , setting_key); +if (ca_cert) { + eap_tls->ca_cert =eap_tls_load_ca_cert (settings, ca_cert); +if (!eap_tls->ca_cert) goto load_error;Quoted 4 lines
Hmm, the P12 files don't contain the CA certchain? I thought the whole point of these was to have the private key + public key + CA certchain? Otherwise I see little point in these since you effectively need to specify the P12 file _and_ the CACert file?
Quoted 5 lines
Putting the trusted CA certs in the same file (whether .p12, .pfx or PEM) is not a usual use case and if it exists I'd guess you have to use some PKCS#9 attributes to identify those certificates within the file? NM and
wpa_sdon't have logic for identifying those labels AFAIK.
I actually really wonder about the utility of these p12 files. We already have a bit of an issue with iwd not being allowed to access user home directories (by systemd for example). Which is why I'd like to move to the embedded format as much as possible. With PEMs we at least have the ability to embed all certs into the settings file easily.
Quoted 4 lines
You can have just your key or just your certchain or individual trusted CA certs in .p12 files without the other parts.
I'm pretty sure CA certs can be included in the p12 file for use on Android for example. Maybe we should look into how this is done?
Quoted 74 lines
Quoted 74 lines
Quoted 51 lines
src/eap-tls-common.c +18
-25- } } -l_free (value); -snprintf (setting_key,sizeof (setting_key),"%sClientCert" , prefix); - value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - eap_tls->client_cert =eap_tls_load_client_cert (settings, - value); -if (!eap_tls->client_cert) { -l_error ("Could not load ClientCert %s" , value); - goto load_error; - } - } - -l_free (value); - -snprintf (setting_key,sizeof (setting_key),"%sClientKeyPassphrase" , - prefix); - passphrase =l_settings_get_string (settings,"Security" , setting_key); + client_cert =l_settings_get_string (settings,"Security" , setting_key);snprintf (setting_key,sizeof (setting_key),"%sClientKey" , prefix); - value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - eap_tls->client_key =eap_tls_load_priv_key (settings, value, + client_key =l_settings_get_string (settings,"Security" , setting_key); + +if (client_cert &&is_embedded (client_cert)) + eap_tls->client_cert =eap_tls_load_embedded_cert (settings, + client_cert); +else if (client_cert) { +l_pem_load_container_file (client_cert, passphrase, + &eap_tls->client_cert, + client_key ?NULL : + &eap_tls->client_key,NULL ); + } + +if (client_key &&is_embedded (client_key)) + eap_tls->client_key =eap_tls_load_embedded_priv_key (settings, + client_key, passphrase,NULL ); -if (!eap_tls->client_key) { -l_error ("Could not load ClientKey %s" , value); - goto load_error; - } +else if (client_key) { + l_pem_load_container_file(client_key, passphrase,src/eap-tls-common.c bool eap_tls_common_settings_load(struct eap_state *eap, · line 1227
Quoted 10 lines
src/eap-tls-common.c +8
-0+ client_cert ?NULL : + &eap_tls->client_cert, + &eap_tls->client_key, NULL); } +if ((client_cert && !eap_tls->client_cert) || + (client_key && !eap_tls->client_key) || + !eap_tls->client_cert != !eap_tls->client_key) + goto load_error; +So assuming that the CACert is also part of the P12, I'd think
eap_tls_load_settingsshould work something like:password =
l_settings_get(.., "ClientPassphrase"); container =l_settings_get(.., "ClientKey");if (client_key_is_container) { // load client_key, client_cert, ca_cert // load ServerDomainMask return; }
Quoted 6 lines
Quoted 1 line
return
eap_tls_common_settings_load()What's
client_key_is_containerthough? If it's something set by the user I fear we're making things more complicated for the users than evenwpa_sis. Also for ourselves by adding inconsistency between the tls-based methods.
What inconsistency? As I pointed out earlier, ClientKey and ClientCert are TLS only.
client_key_is_container would basically indicate whether the file was a p12 or not. If the p12 does not contain ca_certs, then this could be written as:
password = ...
container = ...
if (client_key_is_p12) {
// load client_key, client_cert
goto done;
}// Load client key, client_cert the usual way
done:
return eap_tls_common_settings_load();
where common_settings_load only cares about the CACerts and ServerDomainMask.
Quoted 5 lines
The "container" naming I used in the ell patch was about all these certificate and/or key formats though. Note that if we use special settings here depending on what format we have, we're forcing the users of this (be it IT admins) to understand more about these files.
??
Quoted 4 lines
And for me in the NM iwd-backend it may be directly impossible to convert those EAP settings if I have to detect what is stored inside the file since I can't decrypt it.
The P12 file contains a public certificate and a (possibly encrypted) private key. You're not getting to the encrypted private key without the user password... But this is the same as if we had a PEM with an encrypted private key. So I don't see a problem...?
Or are you talking about the P12 file itself? Do we event want to support encrypted P12 files?
Note that P12 file might have an import key that is different than the ClientKeyPassword. So how are you handling that? Is the user providing two passwords somehow?
Regards,
-Denis
[resend attempt]
Quoted 10 lines · Denis Kenzior
Quoted 7 lines
Quoted 3 lines
So this reminds me that ClientKeyPassphrase, ClientKey and ClientCert are already only relevant to EAP-TLS. They probably don't even belong being checked here in
eap_tls_common_settins_load, etc.Even if you deprecate EAP-PEAP-ClientCert you'll probably want to keep compatibility for some time.
Deprecate? It was never supposed to be supported. See 'man iwd.network.5'. These options are only for TLS.
True, I didn't realize it was not in man iwd.network.5'.
Quoted 2 lines
The use o EAP-PEAP/TTLS-ClientCert is just an
artifact of how this was implemented originally.
I remember they were separate initially actually, and Tim made this big push to unify them.
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
src/eap-tls-common.c bool eap_tls_common_settings_load(struct eap_state *eap, · line 1192
Quoted 13 lines
snprintf(setting_key, sizeof(setting_key), "%sCACert", prefix);src/eap-tls-common.c +4
-5- value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - eap_tls->ca_cert =eap_tls_load_ca_cert (settings, value); -if (!eap_tls->ca_cert) { -l_error ("Could not load CACert %s" , value); + ca_cert =l_settings_get_string (settings,"Security" , setting_key); +if (ca_cert) { + eap_tls->ca_cert =eap_tls_load_ca_cert (settings, ca_cert); +if (!eap_tls->ca_cert) goto load_error;Hmm, the P12 files don't contain the CA certchain? I thought the whole point of these was to have the private key + public key + CA certchain? Otherwise I see little point in these since you effectively need to specify the P12 file _and_ the CACert file?
Quoted 7 lines
Quoted 5 lines
Putting the trusted CA certs in the same file (whether .p12, .pfx or PEM) is not a usual use case and if it exists I'd guess you have to use some PKCS#9 attributes to identify those certificates within the file? NM and
wpa_sdon't have logic for identifying those labels AFAIK.I actually really wonder about the utility of these p12 files.
The utility is the same as of the PEM format. However for me personally it's about supporting the popular formats (I think we're sitll missing one certificate format)
Quoted 5 lines
We already have
a bit of an issue with iwd not being allowed to access user home directories (by systemd for example). Which is why I'd like to move to the embedded format as much as possible. With PEMs we at least have the ability to embed all certs into the settings file easily.
Right, I'm not suggesting it shouldn't be used..
Quoted 8 lines
Quoted 5 lines
You can have just your key or just your certchain or individual trusted CA certs in .p12 files without the other parts.
I'm pretty sure CA certs can be included in the p12 file for use on Android for example. Maybe we should look into how this is done?
We probably should eventually.
Quoted 77 lines
Quoted 77 lines
Quoted 76 lines
Quoted 52 lines
src/eap-tls-common.c +18
-25- } } -l_free (value); -snprintf (setting_key,sizeof (setting_key),"%sClientCert" , prefix); - value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - eap_tls->client_cert =eap_tls_load_client_cert (settings, - value); -if (!eap_tls->client_cert) { -l_error ("Could not load ClientCert %s" , value); - goto load_error; - } - } - -l_free (value); - -snprintf (setting_key,sizeof (setting_key),"%sClientKeyPassphrase" , - prefix); - passphrase =l_settings_get_string (settings,"Security" , setting_key); + client_cert =l_settings_get_string (settings,"Security" , setting_key);snprintf (setting_key,sizeof (setting_key),"%sClientKey" , prefix); - value =l_settings_get_string (settings,"Security" , setting_key); -if (value) { - eap_tls->client_key =eap_tls_load_priv_key (settings, value, + client_key =l_settings_get_string (settings,"Security" , setting_key); + +if (client_cert &&is_embedded (client_cert)) + eap_tls->client_cert =eap_tls_load_embedded_cert (settings, + client_cert); +else if (client_cert) { +l_pem_load_container_file (client_cert, passphrase, + &eap_tls->client_cert, + client_key ?NULL : + &eap_tls->client_key,NULL ); + } + +if (client_key &&is_embedded (client_key)) + eap_tls->client_key =eap_tls_load_embedded_priv_key (settings, + client_key, passphrase,NULL ); -if (!eap_tls->client_key) { -l_error ("Could not load ClientKey %s" , value); - goto load_error; - } +else if (client_key) { + l_pem_load_container_file(client_key, passphrase,src/eap-tls-common.c bool eap_tls_common_settings_load(struct eap_state *eap, · line 1227
Quoted 10 lines
src/eap-tls-common.c +8
-0+ client_cert ?NULL : + &eap_tls->client_cert, + &eap_tls->client_key, NULL); } +if ((client_cert && !eap_tls->client_cert) || + (client_key && !eap_tls->client_key) || + !eap_tls->client_cert != !eap_tls->client_key) + goto load_error; +So assuming that the CACert is also part of the P12, I'd think
eap_tls_load_settingsshould work something like:password =
l_settings_get(.., "ClientPassphrase"); container =l_settings_get(.., "ClientKey");if (client_key_is_container) { // load client_key, client_cert, ca_cert // load ServerDomainMask return; }return
eap_tls_common_settings_load()
Quoted 7 lines
Quoted 4 lines
What's
client_key_is_containerthough? If it's something set by the user I fear we're making things more complicated for the users than evenwpa_sis. Also for ourselves by adding inconsistency between the tls-based methods.What inconsistency? As I pointed out earlier, ClientKey and ClientCert are TLS only.
Right.
Quoted 3 lines
client_key_is_containerwould basically indicate whether the file was a p12 or not. If the p12 does not containca_certs, then this could be written as:
Is it sepcified by the user though? As I said I think that's an unneeded complication for all parties.
Quoted 24 lines
password = ...
container = ...if (client_key_is_p12) { // load client_key, client_cert goto done; }// Load client key,
client_certthe usual waydone:
return eap_tls_common_settings_load();where
common_settings_loadonly cares about the CACerts and ServerDomainMask.Quoted 5 lines
The "container" naming I used in the ell patch was about all these certificate and/or key formats though. Note that if we use special settings here depending on what format we have, we're forcing the users of this (be it IT admins) to understand more about these files.
??
Quoted 8 lines
Quoted 4 lines
And for me in the NM iwd-backend it may be directly impossible to convert those EAP settings if I have to detect what is stored inside the file since I can't decrypt it.
The P12 file contains a public certificate and a (possibly encrypted) private key. You're not getting to the encrypted private key without the user password... But this is the same as if we had a PEM with an encrypted private key. So I don't see a problem...?
With PEM we know the types of objects we have in it, while with PKCS#12 we don't until we decrypt the file. *
In any case I'm still not sure what you're suggesting and how that is an improvement over autodetecting the format.
Quoted 3 lines
Or are you talking about the P12 file itself? Do we event want to support encrypted P12 files?
We only support encrypted PKCS#12 structs, I haven't seen unencrypted ones.
Quoted 4 lines
Note that P12 file might have an import key that is different than the ClientKeyPassword. So how are you handling that? Is the user providing two passwords somehow?
I'm handling the format that I know is in use or supported by NM, so far. I think that's what we normally want IWD.
What the spec says is that you can have an authentication password different from the encryption password, or you can use public keys for either the authentication or encryption, but I haven't seen files using any of those features. I haven't seen software that can produce them, or NM / wpa_s support for that (neither multiple passwords nor public key authentication or encryption). We can look into that once we have a use case.
Best regards
* Specifically you don't always know what is inside a PKCS#12 container depending on how it's structured. With openssl you know when a private key is present because it would not encrypt the Shrouded PKCS8 Key Bag type, and it would encrypt everything else as one opaque safe bag type.
Hi Andrew,
Quoted 1 line · Andrew Zaborowski
[resend attempt]
yeah, massive gmail outage seems to have affected me yesterday. So anything sent to me over the last few days had a good chance of being lost.
Quoted 6 lines
Quoted 2 lines
The use o EAP-PEAP/TTLS-ClientCert is just an
artifact of how this was implemented originally.I remember they were separate initially actually, and Tim made this big push to unify them.
The unification didn't really change the behavior. For whatever reason PEAP/TTLS supported ClientCert, etc from the beginning. In fact, if you look at our unit tests and autotests, they still have artifacts like EAP-TTLS-ClientCert settings.
Quoted 6 lines
Quoted 2 lines
I actually really wonder about the utility of these p12 files.
The utility is the same as of the PEM format. However for me personally it's about supporting the popular formats (I think we're sitll missing one certificate format)
Sure, I get that. But I have to wonder if spending massive amounts of time supporting something that is ultimately a dead end is a worthwhile exercise.
And I take it isn't possible for NM to convert these P12 files into something more sensible like a PEM + encrypted private key PEM on the fly?
Quoted 7 lines
Quoted 3 lines
client_key_is_containerwould basically indicate whether the file was a p12 or not. If the p12 does not containca_certs, then this could be written as:Is it sepcified by the user though? As I said I think that's an unneeded complication for all parties.
What is specified by the user? If ClientKey has a P12 format and you get both the private key and certificate out of it, then you're done.
I don't want users to produce files like:
EAP-TLS-ClientKey=/some/path/file.p12
EAP-TLS-ClientCert=/some/path/file.p12
EAP-TLS-CACert=/some/path/file.p12
It should be just
EAP-TLS-Certificates=/some/path/file.p12
Quoted 6 lines
Quoted 3 lines
Or are you talking about the P12 file itself? Do we event want to support encrypted P12 files?
We only support encrypted PKCS#12 structs, I haven't seen unencrypted ones.
Ugh, another reason why openssl needs to be killed with fire. That just makes no sense for a container format in the context of connecting to WiFi.
Quoted 8 lines
Quoted 4 lines
Note that P12 file might have an import key that is different than the ClientKeyPassword. So how are you handling that? Is the user providing two passwords somehow?
I'm handling the format that I know is in use or supported by NM, so far. I think that's what we normally want IWD.
Quoted 7 lines
What the spec says is that you can have an authentication password different from the encryption password, or you can use public keys for either the authentication or encryption, but I haven't seen files using any of those features. I haven't seen software that can produce them, or NM /
wpa_ssupport for that (neither multiple passwords nor public key authentication or encryption). We can look into that once we have a use case.
FYI, the P12 files produced to access our VPN are like this. The import key is (by default) the FSID of the path where the certificate is and the passphrase for the private key is something else entirely.
But in general, I really don't want us to be making the same mistakes as NM/wpa_s. So if there are multiple passwords, we probably should support that.
Quoted 9 lines
Best regards
* Specifically you don't always know what is inside a PKCS#12 container depending on how it's structured. With openssl you know when a private key is present because it would not encrypt the Shrouded PKCS8 Key Bag type, and it would encrypt everything else as one opaque safe bag type.
Can openssl be abused to encrypt with an empty password or something? That way we can still decode the public certchain and have the original encrypted private key..
It really sounds to me like .p12 is an awful choice for our use...
Regards,
-Denis
Quoted 9 lines · Denis Kenzior
Quoted 5 lines · Andrew Zaborowski
Quoted 1 line
I actually really wonder about the utility of these p12 files.
The utility is the same as of the PEM format. However for me personally it's about supporting the popular formats (I think we're sitll missing one certificate format)
Sure, I get that. But I have to wonder if spending massive amounts of time supporting something that is ultimately a dead end is a worthwhile exercise.
Why is it different than .pem, .crt, .key, .p7b, etc.?
Quoted 3 lines
And I take it isn't possible for NM to convert these P12 files into something more sensible like a PEM + encrypted private key PEM on the fly?
Without the password, no. I still don't see the reason to force IWD's clients and/or users to do this when we can have ell seemlessly autodetect the formats and clients like IWD (or https implementations) can forget about it, I'm not sure why we're having this conversation.
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines
client_key_is_containerwould basically indicate whether the file was a p12 or not. If the p12 does not containca_certs, then this could be written as:Is it sepcified by the user though? As I said I think that's an unneeded complication for all parties.
What is specified by the user?
client_key_is_container, does it come from a boolean setting? Or do you want ell to have a function that reads the file and detects the format, separate from the function that loads the file?
Quoted 2 lines
If ClientKey has a P12 format and you get both
the private key and certificate out of it, then you're done.
That's exactly what calling l_pem_load_container_file() does, so the clients don't have to worry about the 10 different file types.
Quoted 9 lines
I don't want users to produce files like:
EAP-TLS-ClientKey=/some/path/file.p12
EAP-TLS-ClientCert=/some/path/file.p12
EAP-TLS-CACert=/some/path/file.p12It should be just
EAP-TLS-Certificates=/some/path/file.p12
I looked around a little for an indication that a .p12 file is ever used to store the user keypair (for client authentication) *and* the trusted CA set (for server authentication) but I can't find it, I don't believe this exists. I also believe if some implementer wanted to support this -- it would be only for EAP, not other .p12 use cases (like https, .apk signing, etc.), so they'd go all the way and create a new format to store the full EAP configuration (Identity etc.) and certificates + keys in one file rather than use .p12. If you've seen something like this please re-check the details, I think you're talking about something different than .p12.
So you can't do either of the above, it's going to be something like:
Quoted 30 lines
EAP-TLS-ClientCert=/some/path/file1.p12
EAP-TLS-CACert=/some/path/file2.p12Quoted 6 lines
Quoted 3 lines
Or are you talking about the P12 file itself? Do we event want to support encrypted P12 files?
We only support encrypted PKCS#12 structs, I haven't seen unencrypted ones.
Ugh, another reason why openssl needs to be killed with fire. That just makes no sense for a container format in the context of connecting to WiFi.
Quoted 8 lines
Quoted 4 lines
Note that P12 file might have an import key that is different than the ClientKeyPassword. So how are you handling that? Is the user providing two passwords somehow?
I'm handling the format that I know is in use or supported by NM, so far. I think that's what we normally want IWD.
Quoted 7 lines
What the spec says is that you can have an authentication password different from the encryption password, or you can use public keys for either the authentication or encryption, but I haven't seen files using any of those features. I haven't seen software that can produce them, or NM /
wpa_ssupport for that (neither multiple passwords nor public key authentication or encryption). We can look into that once we have a use case.
Quoted 3 lines
FYI, the P12 files produced to access our VPN are like this. The import key is (by default) the FSID of the path where the certificate is and the passphrase for the private key is something else entirely.
I'm looking at some scripts and that's not the case, I don't know if you mean the same scripts, let me reply privately.
Quoted 14 lines
But in general, I really don't want us to be making the same mistakes as NM/wpa_s. So if there are multiple passwords, we probably should support that.
Quoted 9 lines
Best regards
* Specifically you don't always know what is inside a PKCS#12 container depending on how it's structured. With openssl you know when a private key is present because it would not encrypt the Shrouded PKCS8 Key Bag type, and it would encrypt everything else as one opaque safe bag type.
Quoted 3 lines
Can openssl be abused to encrypt with an empty password or something? That way we can still decode the public certchain and have the original encrypted private key..
It can encrypt with an empty password, yes, but I don't see what you can use this for.
Quoted 2 lines
It really sounds to me like .p12 is an awful choice for our use...
It's like the other formats each with its quirks.
Best regards
Hi Andrew,
Quoted 4 lines · Andrew Zaborowski
Quoted 3 lines · Denis Kenzior
Quoted 2 lines · Andrew Zaborowski
Quoted 1 line
I actually really wonder about the utility of these p12 files.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
The utility is the same as of the PEM format. However for me personally it's about supporting the popular formats (I think we're sitll missing one certificate format)
Sure, I get that. But I have to wonder if spending massive amounts of time supporting something that is ultimately a dead end is a worthwhile exercise.
Why is it different than .pem, .crt, .key, .p7b, etc.?
The difference is that this format can't be embedded into our settings file easily.
Don't get me wrong, I'm all for supporting all these file formats. But as I
mentioned previously, we're already getting bitten by people putting certs into their home directory and having systemd deny iwd permissions to read them. Something that you can't troubleshoot without reading logs and knowing where to look.
The fix is to have the user modify systemd default permissions for iwd to allow it to read user home directories (which it probably shouldn't), or forcing the user to put the files 'somewhere' accessible. Either is terrible user experience...
So I think it would be unfortunate if NM was forced into doing the same as above on a larger scale. Especially when multiple potentially sensitive files are involved which should be removed along with the network profile. This is why I consider non-embeddable file types a dead end. We either need to figure out how to embed them or do something else.
Quoted 6 lines
Quoted 4 lines
And I take it isn't possible for NM to convert these P12 files into something more sensible like a PEM + encrypted private key PEM on the fly?
Without the password, no. I still don't see the reason to force IWD's
Okay, that's what I thought.
Quoted 3 lines
clients and/or users to do this when we can have ell seemlessly autodetect the formats and clients like IWD (or https implementations) can forget about it, I'm not sure why we're having this conversation.
No, no. We're on the same page here with regard to auto-detection. At least I don't think we disagree here...
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
client_key_is_containerwould basically indicate whether the file was a p12 or not. If the p12 does not containca_certs, then this could be written as:Is it sepcified by the user though? As I said I think that's an unneeded complication for all parties.
Quoted 5 lines
Quoted 1 line
What is specified by the user?
client_key_is_container, does it come from a boolean setting? Or do you want ell to have a function that reads the file and detects the format, separate from the function that loads the file?
No boolean setting. The file type would be auto detected as you propose upon loading.
Quoted 14 lines
Quoted 3 lines
If ClientKey has a P12 format and you get both
the private key and certificate out of it, then you're done.That's exactly what calling
l_pem_load_container_file()does, so the clients don't have to worry about the 10 different file types.Quoted 7 lines
I don't want users to produce files like:
EAP-TLS-ClientKey=/some/path/file.p12
EAP-TLS-ClientCert=/some/path/file.p12
EAP-TLS-CACert=/some/path/file.p12
Quoted 6 lines
Quoted 2 lines
It should be just
EAP-TLS-Certificates=/some/path/file.p12I looked around a little for an indication that a .p12 file is ever used to store the user keypair (for client authentication) *and* the trusted CA set (for server authentication) but I can't find it, I
Here's one:
http://cubicspot.blogspot.com/2013/04/setting-up-wpa2-enterprise-aes-with.html
Certainly it would make sense to include the CA cert if you're already uploading a P12 container file with a user cert + user key. Many orgs have went away from running their own CA and use a public CA instead. So that might explain why this is not that common. Anyhow, this isn't that important. If the CA is not included in the vast majority of cases, then it isn't included.
Quoted 3 lines
don't believe this exists. I also believe if some implementer wanted to support this -- it would be only for EAP, not other .p12 use cases (like https, .apk signing, etc.), so they'd go all the way and create
VPN comes to mind. But then do we really care about other use cases just yet?
Quoted 2 lines
a new format to store the full EAP configuration (Identity etc.) and certificates + keys in one file rather than use .p12. If you've seen
Which is what Apple did with their .mobileconfig format. And that's exactly what our settings file with embedded certs is...
Quoted 7 lines
something like this please re-check the details, I think you're talking about something different than .p12.
So you can't do either of the above, it's going to be something like:
Quoted 2 lines
EAP-TLS-ClientCert=/some/path/file1.p12
EAP-TLS-CACert=/some/path/file2.p12
'Can't' might be a strong word. 'Might not be able to' is probably more accurate. But anyway, if the p12 is only including user key / user cert, then thats what we have to work with.
Regards,
-Denis
Hi Denis,
Quoted 16 lines · Denis Kenzior
Quoted 1 line · Andrew Zaborowski
Why is it different than .pem, .crt, .key, .p7b, etc.?
The difference is that this format can't be embedded into our settings file easily.
Don't get me wrong, I'm all for supporting all these file formats. But as I
mentioned previously, we're already getting bitten by people putting certs into their home directory and having systemd deny iwd permissions to read them. Something that you can't troubleshoot without reading logs and knowing where to look.The fix is to have the user modify systemd default permissions for iwd to allow it to read user home directories (which it probably shouldn't), or forcing the user to put the files 'somewhere' accessible. Either is terrible user experience...
Quoted 5 lines
So I think it would be unfortunate if NM was forced into doing the same as above on a larger scale. Especially when multiple potentially sensitive files are involved which should be removed along with the network profile. This is why I consider non-embeddable file types a dead end. We either need to figure out how to embed them or do something else.
Right, but a couple of things to consider:
NM and wpa_s also usually run as root and they're allowed to read those files from wherever the user has placed them. When you create a connection via nm-connection editor, the EAP settings are sent to NM over DBus but the public crypto files are only sent as file paths. I don't know how much effort it is for the distribution people to allow NM/wpa_s to access those files but assuming that IWD is treated the same way it should have no problem.
Secondly, NM could still convert the file to a "BEGIN PKCS12"-type PEM file and embed it. openssl doesn't seem to support creating exactly this format, but I didn't invent it ;) Cisco access points apparently want this format from the user. I'm not considering doing this right now because making copies of the user keys whether encrypted or not, needs extra work proving that it's safe, maybe issuing warnings in the logs etc. Also we'd need to be sure that deleting and modifying IWD network configs from the same NM UIs works 100% bulletproof.
Also we can't tell somebody that we don't allow them to use their standalone .p12 file (or .cer which is also binary) fbecause those files can't be embedded, it's a different use case.
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
And I take it isn't possible for NM to convert these P12 files into something more sensible like a PEM + encrypted private key PEM on the fly?
Without the password, no. I still don't see the reason to force IWD's
(Actually except for the "BEGIN PKCS12" format I mention above)
Quoted 6 lines
Quoted 3 lines
I looked around a little for an indication that a .p12 file is ever used to store the user keypair (for client authentication) *and* the trusted CA set (for server authentication) but I can't find it, I
Here's one:
http://cubicspot.blogspot.com/2013/04/setting-up-wpa2-enterprise-aes-with.html
Okay, so what seems to be happening is that Android can import certificates and keys from .p12 files into its credentials storage, the article that this post linked was about Android 2.2 but it still works on my Android 9 device. The device asks me for the decryption password, whether I want it for VPN and wlan, and a user-friendly name for the bundle. The ell test .p12 files contain the leaf certificate, the intermediate CA and the root (self-signed) CA, and they private key. Android imports the 3 certs and one key as a bundle under the name I gave. Then, when I set up a new EAP-TLS connection I can select one bundle for the trusted CA certificate and one for the user certificate + key, and they can be the same bundle but they can be different too.
So this is smart because often a .p12 file will contain the full cert-chain from the leaf user cert to root CA.cert, and often the root CA is the same for user authentication and for server authentication, and then you need just one .p12 file. But often this is not the case (because the certchain can be shorter or can contain no CAs at all, or because there are different roots for users and for the server) and they also support this situation becuase you can specify different files. In our code we're specifically not checking that the user certchain can be verified with the CA certs because they can be different, I think we made this change after someone complained.
So I think we should also allow a .p12 file to be specified as a EAP-TLS-CACerts (I haven't worked on this) and then we should use the last, not the first certificate from that file. Note that openssl doesn't support creating pkcs12 files where the certificates don't form a valid certchain, so you can't have multiple root CAs and you can't have a user cert + a CA for server authentication unless it's also the root of the user certchain.
Quoted 5 lines
Quoted 2 lines
a new format to store the full EAP configuration (Identity etc.) and certificates + keys in one file rather than use .p12. If you've seen
Which is what Apple did with their .mobileconfig format. And that's exactly what our settings file with embedded certs is...
True.
Best regards
Hi Andrew,
Quoted 27 lines · Andrew Zaborowski
Hi Denis,
Quoted 16 lines · Denis Kenzior
Quoted 1 line · Andrew Zaborowski
Why is it different than .pem, .crt, .key, .p7b, etc.?
The difference is that this format can't be embedded into our settings file easily.
Don't get me wrong, I'm all for supporting all these file formats. But as I
mentioned previously, we're already getting bitten by people putting certs into their home directory and having systemd deny iwd permissions to read them. Something that you can't troubleshoot without reading logs and knowing where to look.The fix is to have the user modify systemd default permissions for iwd to allow it to read user home directories (which it probably shouldn't), or forcing the user to put the files 'somewhere' accessible. Either is terrible user experience...
Quoted 5 lines
So I think it would be unfortunate if NM was forced into doing the same as above on a larger scale. Especially when multiple potentially sensitive files are involved which should be removed along with the network profile. This is why I consider non-embeddable file types a dead end. We either need to figure out how to embed them or do something else.
Right, but a couple of things to consider:
Quoted 7 lines
NM and
wpa_salso usually run as root and they're allowed to read those files from wherever the user has placed them. When you create a connection via nm-connection editor, the EAP settings are sent to NM over DBus but the public crypto files are only sent as file paths. I don't know how much effort it is for the distribution people to allow NM/wpa_s to access those files but assuming that IWD is treated the same way it should have no problem.
Yes, we can do this. And people have resorted to doing just that. But, really, the question is whether we _should_. Having iwd access files outside of its play area is a security risk. The less we have access to, the better. So from that perspective, what you suggest here is something I'd want to avoid.
Quoted 9 lines
Secondly, NM could still convert the file to a "BEGIN PKCS12"-type PEM file and embed it. openssl doesn't seem to support creating exactly this format, but I didn't invent it ;) Cisco access points apparently want this format from the user. I'm not considering doing this right now because making copies of the user keys whether encrypted or not, needs extra work proving that it's safe, maybe issuing warnings in the logs etc. Also we'd need to be sure that deleting and modifying IWD network configs from the same NM UIs works 100% bulletproof.
That sounds like an idea we should pursue...
Quoted 5 lines
Also we can't tell somebody that we don't allow them to use their standalone .p12 file (or .cer which is also binary) fbecause those files can't be embedded, it's a different use case.
We can certainly support .p12 files the way we support non-embedded PEMs today. I'm just not in favor of having NM use non-embedded files and forcing iwd to have worldwide read permissions.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
I looked around a little for an indication that a .p12 file is ever used to store the user keypair (for client authentication) *and* the trusted CA set (for server authentication) but I can't find it, I
Here's one:
http://cubicspot.blogspot.com/2013/04/setting-up-wpa2-enterprise-aes-with.html
Quoted 12 lines
Okay, so what seems to be happening is that Android can import certificates and keys from .p12 files into its credentials storage, the article that this post linked was about Android 2.2 but it still works on my Android 9 device. The device asks me for the decryption password, whether I want it for VPN and wlan, and a user-friendly name for the bundle. The ell test .p12 files contain the leaf certificate, the intermediate CA and the root (self-signed) CA, and they private key. Android imports the 3 certs and one key as a bundle under the name I gave. Then, when I set up a new EAP-TLS connection I can select one bundle for the trusted CA certificate and one for the user certificate + key, and they can be the same bundle but they can be different too.
So looks like Android got something right :)
Quoted 5 lines
So this is smart because often a .p12 file will contain the full cert-chain from the leaf user cert to root CA.cert, and often the root CA is the same for user authentication and for server authentication, and then you need just one .p12 file. But often this is not the case
Exactly. But for a self-signed CA, which is what you'd typically use this for, I would expect that the root CA to be included.
Quoted 2 lines
(because the certchain can be shorter or can contain no CAs at all, or because there are different roots for users and for the server) and
Yes, this is possible. I wonder why anyone would come up with such a setup in practice.
Quoted 4 lines
they also support this situation becuase you can specify different files. In our code we're specifically not checking that the user certchain can be verified with the CA certs because they can be different, I think we made this change after someone complained.
Yes, I recall something like this. My memory is fuzzy. I seem to recall you originally had a place holder for this but never implemented it. So we took it out.
Quoted 4 lines
So I think we should also allow a .p12 file to be specified as a EAP-TLS-CACerts (I haven't worked on this) and then we should use the last, not the first certificate from that file. Note that openssl
Yep, sounds reasonable.
Quoted 4 lines
doesn't support creating pkcs12 files where the certificates don't form a valid certchain, so you can't have multiple root CAs and you can't have a user cert + a CA for server authentication unless it's also the root of the user certchain.
I think that sort of makes sense (see above.) So, maybe we should just assume this setup and use the root CA provided as part of the .p12 file unless over-ridden by a separate CACert entry. But these details can be left until later...
Regards,
-Denis