Chromium Code Reviews| Index: chromeos_network.cc |
| diff --git a/chromeos_network.cc b/chromeos_network.cc |
| index 915f37345aa34607b683c4150298e573cc7f3752..c48c6df08696368adc637f52f9b1e8d34f4abaea 100644 |
| --- a/chromeos_network.cc |
| +++ b/chromeos_network.cc |
| @@ -12,6 +12,7 @@ |
| #include "marshal.glibmarshal.h" // NOLINT |
| #include "base/scoped_ptr.h" |
| +#include "base/scoped_vector.h" |
| #include "base/string_util.h" |
| #include "base/values.h" |
| #include "chromeos/dbus/dbus.h" // NOLINT |
| @@ -106,6 +107,22 @@ static const char* kFirmwareRevisionProperty = "Cellular.FirmwareRevision"; |
| static const char* kHardwareRevisionProperty = "Cellular.HardwareRevision"; |
| static const char* kLastDeviceUpdateProperty = "Cellular.LastDeviceUpdate"; |
| static const char* kPRLVersionProperty = "Cellular.PRLVersion"; // (INT16) |
| +static const char* kCertpathSettingsPrefix = "SETTINGS:"; |
| + |
| +// Connman EAP service properties |
| +static const char* kEAPIdentityProperty = "EAP.Identity"; |
| +static const char* kEAPEAPProperty = "EAP.EAP"; |
| +static const char* kEAPInnerEAPProperty = "EAP.InnerEAP"; |
| +static const char* kEAPAnonymousIdentityProperty = "EAP.AnonymousIdentity"; |
| +static const char* kEAPClientCertProperty = "EAP.ClientCert"; |
|
Jason Glasgow
2011/01/31 13:33:29
Is this the path to the cert?
|
| +static const char* kEAPCertIDProperty = "EAP.CertID"; |
| +static const char* kEAPPrivateKeyProperty = "EAP.PrivateKey"; |
| +static const char* kEAPPrivateKeyPasswordProperty = "EAP.PrivateKeyPassword"; |
| +static const char* kEAPKeyIDProperty = "EAP.KeyID"; |
| +static const char* kEAPCACertProperty = "EAP.CACert"; |
| +static const char* kEAPCACertIDProperty = "EAP.CACertID"; |
| +static const char* kEAPPINProperty = "EAP.PIN"; |
| +static const char* kEAPPasswordProperty = "EAP.Password"; |
| // Connman monitored properties |
| static const char* kMonitorPropertyChanged = "PropertyChanged"; |
| @@ -623,14 +640,9 @@ void ParseServiceProperties(const glib::ScopedHashTable& properties, |
| // Identity |
| default_string = ""; |
| - properties.Retrieve(kIdentityProperty, &default_string); |
| + properties.Retrieve(kEAPIdentityProperty, &default_string); |
| info->identity = NewStringCopy(default_string); |
| - // Certificate path |
| - default_string = ""; |
| - properties.Retrieve(kCertPathProperty, &default_string); |
| - info->cert_path = NewStringCopy(default_string); |
| - |
| // Strength |
| uint8 default_uint8 = 0; |
| properties.Retrieve(kSignalStrengthProperty, &default_uint8); |
| @@ -708,6 +720,60 @@ void ParseServiceProperties(const glib::ScopedHashTable& properties, |
| info->carrier_info = NULL; |
| } |
| + // EAP type |
| + default_string = ""; |
| + properties.Retrieve(kEAPEAPProperty, &default_string); |
| + info->eap = NewStringCopy(default_string); |
| + // Inner EAP type |
| + default_string = ""; |
| + properties.Retrieve(kEAPInnerEAPProperty, &default_string); |
| + info->inner_eap = NewStringCopy(default_string); |
| + // Anonymous identity |
| + default_string = ""; |
| + properties.Retrieve(kEAPAnonymousIdentityProperty, &default_string); |
| + info->anonymous_identity = NewStringCopy(default_string); |
| + // Client certificate |
| + default_string = ""; |
| + properties.Retrieve(kEAPClientCertProperty, &default_string); |
| + info->client_cert = NewStringCopy(default_string); |
| + // Certificate ID |
| + default_string = ""; |
| + properties.Retrieve(kEAPCertIDProperty, &default_string); |
| + info->cert_id = NewStringCopy(default_string); |
| + // Private key |
| + default_string = ""; |
| + properties.Retrieve(kEAPPrivateKeyProperty, &default_string); |
| + info->private_key = NewStringCopy(default_string); |
| + // Private key password |
| + default_string = ""; |
| + properties.Retrieve(kEAPPrivateKeyPasswordProperty, &default_string); |
| + info->private_key_passwd = NewStringCopy(default_string); |
| + // Private key ID |
| + default_string = ""; |
| + properties.Retrieve(kEAPKeyIDProperty, &default_string); |
| + info->key_id = NewStringCopy(default_string); |
| + // CA certificate |
| + default_string = ""; |
| + properties.Retrieve(kEAPCACertProperty, &default_string); |
| + info->ca_cert = NewStringCopy(default_string); |
| + // CA certificate ID |
| + default_string = ""; |
| + properties.Retrieve(kEAPCACertIDProperty, &default_string); |
| + info->ca_cert_id = NewStringCopy(default_string); |
| + // PKCS#11 PIN |
| + default_string = ""; |
| + properties.Retrieve(kEAPPINProperty, &default_string); |
| + info->pin = NewStringCopy(default_string); |
| + // EAP Password |
| + default_string = ""; |
| + properties.Retrieve(kEAPPasswordProperty, &default_string); |
| + info->password = NewStringCopy(default_string); |
| + |
| + // Certificate path (backwards compat only) |
|
Jason Glasgow
2011/01/31 13:33:29
Would it help to say // DEPRECATED so it is easy t
|
| + default_string = ""; |
| + properties.Retrieve(kCertPathProperty, &default_string); |
| + info->cert_path = NewStringCopy(default_string); |
| + |
| // Device Info (initialize to NULL) |
| info->device_info = NULL; |
| } |
| @@ -1491,6 +1557,27 @@ bool ChromeOSActivateCellularModem(const char* service_path, |
| return true; |
| } |
| +class ScopedPtrGStrFreeV { |
| + public: |
| + inline void operator()(char** x) const { |
| + g_strfreev(x); |
| + } |
| +}; |
| + |
| +static const char *map_oldprop_to_newprop(const char *oldprop) |
| +{ |
| + if (strcmp(oldprop, "key_id") == 0) |
| + return kEAPKeyIDProperty; |
| + if (strcmp(oldprop, "cert_id") == 0) |
| + return kEAPCertIDProperty; |
| + if (strcmp(oldprop, "pin") == 0) |
| + return kEAPPINProperty; |
| + |
| + return NULL; |
| +} |
| + |
| + |
| + |
| extern "C" |
| bool ChromeOSConfigureWifiService(const char* ssid, |
| ConnectionSecurity security, |
| @@ -1528,10 +1615,32 @@ bool ChromeOSConfigureWifiService(const char* ssid, |
| &value_security); |
| ::g_hash_table_insert(properties, ::g_strdup(kPassphraseProperty), |
| &value_passphrase); |
| - ::g_hash_table_insert(properties, ::g_strdup(kIdentityProperty), |
| + ::g_hash_table_insert(properties, ::g_strdup(kEAPIdentityProperty), |
| &value_identity); |
| - ::g_hash_table_insert(properties, ::g_strdup(kCertPathProperty), |
| - &value_cert_path); |
| + |
| + // Backwards-compatibility for "CertPath=SETTINGS:key_id=1,cert_id=2,..." |
| + ScopedVector<glib::Value> values; |
| + scoped_ptr_malloc<char *, ScopedPtrGStrFreeV> settings; |
| + if (::g_str_has_prefix(certpath, kCertpathSettingsPrefix)) { |
| + char **settingsp; |
| + settings.reset(::g_strsplit_set( |
| + certpath + strlen(kCertpathSettingsPrefix), ",=", 0)); |
| + for (settingsp = settings.get(); *settingsp != NULL; settingsp += 2) { |
| + const char *key = map_oldprop_to_newprop(*settingsp); |
| + if (key == NULL) |
| + continue; // TODO(njw): log something? |
|
Jason Glasgow
2011/01/31 13:33:29
Not really a TODO, since the code is already DEPRE
|
| + glib::Value *value = new glib::Value(*(settingsp + 1)); |
| + values.push_back(value); |
| + ::g_hash_table_insert(properties, ::g_strdup(key), value); |
| + } |
| + // Presume EAP-TLS if we're here |
| + glib::Value *value = new glib::Value("TLS"); |
| + values.push_back(value); |
| + ::g_hash_table_insert(properties, ::g_strdup(kEAPEAPProperty), value); |
| + } else { |
| + ::g_hash_table_insert(properties, ::g_strdup(kCertPathProperty), |
|
Jason Glasgow
2011/01/31 13:33:29
Is this not kEAPClientCertProperty? Compare with
|
| + &value_cert_path); |
| + } |
| glib::ScopedError error; |
| @@ -1602,20 +1711,68 @@ bool ChromeOSConnectToNetworkWithCertInfo(const char* service_path, |
| // Set certificate path if non-null. |
| if (certpath) { |
| - glib::Value value_certpath(certpath); |
| - glib::ScopedError error; |
| - if (!::dbus_g_proxy_call(service_proxy.gproxy(), |
| - kSetPropertyFunction, |
| - &Resetter(&error).lvalue(), |
| - G_TYPE_STRING, |
| - kCertPathProperty, |
| - G_TYPE_VALUE, |
| - &value_certpath, |
| - G_TYPE_INVALID, |
| - G_TYPE_INVALID)) { |
| - LOG(WARNING) << "ConnectToNetwork failed on set certpath: " |
| - << (error->message ? error->message : "Unknown Error."); |
| - return false; |
| + // Backwards-compatibility for "CertPath=SETTINGS:key_id=1,cert_id=2,..." |
| + if (::g_str_has_prefix(certpath, kCertpathSettingsPrefix)) { |
| + glib::ScopedError error; |
| + char **settingsp; |
| + char **settings = ::g_strsplit_set( |
|
Jason Glasgow
2011/01/31 13:33:29
Can you use scoped_ptr_malloc<> here?
|
| + certpath + strlen(kCertpathSettingsPrefix), ",=", 0); |
| + for (settingsp = settings; *settingsp != NULL; settingsp += 2) { |
| + const char *key = map_oldprop_to_newprop(*settingsp); |
| + if (key == NULL) { |
| + LOG(WARNING) << "ConnectToNetwork, unknown key '" << key |
| + << "' from certpath "; |
| + continue; |
| + } |
| + glib::Value value(*(settingsp + 1)); |
| + if (!::dbus_g_proxy_call(service_proxy.gproxy(), |
| + kSetPropertyFunction, |
| + &Resetter(&error).lvalue(), |
| + G_TYPE_STRING, |
| + key, |
| + G_TYPE_VALUE, |
| + &value, |
| + G_TYPE_INVALID, |
| + G_TYPE_INVALID)) { |
| + LOG(WARNING) << "ConnectToNetwork failed on set '" << key |
| + << "' (from certpath): " |
| + << (error->message ? error->message : "Unknown Error."); |
| + return false; |
|
Jason Glasgow
2011/01/31 13:33:29
You will leak settings here unless you use the sco
|
| + } |
| + } |
| + ::g_strfreev(settings); |
| + // Presume EAP-TLS if we're here |
| + glib::Value value("TLS"); |
| + if (!::dbus_g_proxy_call(service_proxy.gproxy(), |
| + kSetPropertyFunction, |
| + &Resetter(&error).lvalue(), |
| + G_TYPE_STRING, |
| + kEAPEAPProperty, |
| + G_TYPE_VALUE, |
| + &value, |
| + G_TYPE_INVALID, |
| + G_TYPE_INVALID)) { |
| + LOG(WARNING) << "ConnectToNetwork failed on set EAP type'" |
| + << "' (from certpath): " |
| + << (error->message ? error->message : "Unknown Error."); |
| + return false; |
| + } |
| + } else { |
| + glib::Value value_certpath(certpath); |
| + glib::ScopedError error; |
| + if (!::dbus_g_proxy_call(service_proxy.gproxy(), |
| + kSetPropertyFunction, |
| + &Resetter(&error).lvalue(), |
| + G_TYPE_STRING, |
| + kEAPClientCertProperty, |
|
Jason Glasgow
2011/01/31 13:33:29
See line 1641.
|
| + G_TYPE_VALUE, |
| + &value_certpath, |
| + G_TYPE_INVALID, |
| + G_TYPE_INVALID)) { |
| + LOG(WARNING) << "ConnectToNetwork failed on set certpath: " |
| + << (error->message ? error->message : "Unknown Error."); |
| + return false; |
| + } |
| } |
| } |