Re: Retrieving 'secret' setting



On Wed, 2017-09-06 at 12:51 +0100, Colin Helliwell wrote:
On 06 September 2017 at 11:14 Thomas Haller <thaller redhat com>
wrote:

On Wed, 2017-09-06 at 10:20 +0100, colin helliwell ln-systems com
wrote:

I'm python-scripting to get a connection's gsm properties, and
want
to get
the password - which "c.for_each_setting_value(print_values,
None)"
seems to
not report (just "None").
What would be the technique to get it?
Thanks

Hi,

on D-Bus, secrets are exposed separately from regular properties of
the
connection.

GetSettings() vs GetSecrets() in
https://developer.gnome.org/NetworkManager/stable/gdbus-org.freedes
ktop.NetworkManager.Settings.Connection.html

Anyway, from libnm (and python gi) you would call

secrets = remote_connection.get_secrets('ethernet')


Great, got that. Now, don't suppose you could help me get to grips
with parsing the Glib.Variant....? ;)

You can get around the need for touching GVariant by passing what you
get from get_secrets() to NMConnection's replace_settings() call too. 
Then you get a nice NMConnection object, with only the secrets filled
in.  For example, pass a connection UUID as the argument to this:

#!/usr/bin/env python
import gi
gi.require_version('NM', '1.0')
from
gi.repository import GLib, NM
import sys

client = NM.Client.new(None)
c = client.get_connection_by_uuid(sys.argv[1])
wifi_secrets = c.get_secrets(NM.SETTING_WIRELESS_SECURITY_SETTING_NAME)
wifi_secrets_con = NM.SimpleConnection.new()
wifi_secrets_con.replace_settings(wifi_secrets)
wsec = wifi_secrets_con.get_setting_wireless_security()
print "%s" % wsec.get_psk()

Dan


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]