maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   [Request/Idea] enable "secure device" lock based on wifi network (https://talk.maemo.org/showthread.php?t=71814)

dave1010 2011-04-04 21:01

[Request/Idea] enable "secure device" lock based on wifi network
 
Update: laasonen has made a program to do this! See this thread for details.

When I'm at home or work then there's not much point in having the lock code on my N900 but it's useful when I'm out. What would be great is if the "secure device" lock screen was disabled on certain wifi networks.

I can lock the device immediately (with phone-control --unlock) and I can run scripts depending on network connections (with dbus-scripts) but if I put the 2 together then my N900 locks/unlocks immediately.

Can any one point me in the right direction? I'd be appy with a command line dbus hack but a nice gui app would be even better.

jedi 2011-04-04 21:27

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
I like this idea. Sorry - I can't help but I'd like to see how this progresses :)

godofwar424 2011-04-04 21:47

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
Have you tried out using dbus-monitor to see what the signal is to Lock the device?

That would give you the dbus commands needed and then you could possibly find a way to add that command to a script which activates based on your connection name?

laasonen 2011-04-04 22:26

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
Wrote simple script which unlocks the device when you click the power button when it's connected to the wlan you specified :)
Code:

#!/bin/sh
homeESSID="Home_1" #Set up your ESSID

while true; do
        cat /dev/input/pwrbutton | echo "Waiting.."
        echo "Trying to open.."
        if [ `iwconfig wlan0 | grep ESSID | awk -F'"' '{print $2}'` = $homeESSID ];        then
                if [ `cat /sys/class/backlight/acx565akm/brightness` = "0" ]; then
                        sleep 1
                        dbus-send --system --type=method_call --dest=com.nokia.mce /com/nokia/mce/request com.nokia.mce.request.req_tklock_mode_change string:"unlocked"
                        dbus-send --system --type=method_call --dest=com.nokia.system_ui /com/nokia/system_ui/request com.nokia.system_ui.request.devlock_close string:"com.nokia.mce" string:"/com/nokia/mce/request" string:"com.nokia.mce.request" string:"devlock_callback" uint32:'0'
                        echo "..opened";
                else
                        echo "..not locked!";
                fi
        else
                echo "..not in home network!";
        fi
done

You need to run it as root, because user can't read /dev/input/pwrbutton
Comment the first dbus-send, if you miss the slider.

EDIT: Now it checks if the screen is unlocked already.

laasonen 2011-04-05 13:29

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
I was trying to add a smarter way to detect the lock, but I can't figure out why it says that device is locked even thought it's not?
Code:

Nokia-N900:~# dbus-send --system --type=method_call --dest="com.nokia.mce" --print-reply "/com/nokia/mce/request" com.nokia.mce.request.get_devicelock_mode
method return sender=:1.9 -> dest=:1.218 reply_serial=2
  string "locked"
Nokia-N900:~#

Keyboard and screen lock detecting seems to work:
Code:

Nokia-N900:~# dbus-send --system --type=method_call --dest="com.nokia.mce" --print-reply "/com/nokia/mce/request" com.nokia.mce.request.get_tklock_mode
method return sender=:1.9 -> dest=:1.241 reply_serial=2
  string "unlocked"
Nokia-N900:~#

EDIT: It seems to work now :/

Better one:
Code:

#!/bin/sh
homeESSID="Home_1" #Set up your ESSID

while true; do
        cat /dev/input/pwrbutton | echo "Waiting.."
        echo "Trying to open.."
        if [ `iwconfig wlan0 | grep ESSID | awk -F'"' '{print $2}'` = $homeESSID ];        then #Correct wlan?
                echo "..opening.."
                dbus-send --system --type=method_call --dest="com.nokia.mce" --print-reply "/com/nokia/mce/request" com.nokia.mce.request.get_devicelock_mode | grep unlocked > /dev/null
                devicelock=$?
                dbus-send --system --type=method_call --dest="com.nokia.mce" --print-reply "/com/nokia/mce/request" com.nokia.mce.request.get_tklock_mode | grep unlocked > /dev/null
                tklock=$?
                echo $devicelock
                echo $tklock
                if [ $devicelock = 1 || $tklock = 1 ]; then #Need sleep?
                        sleep 1
                fi
                if [ $devicelock = 1 ]; then #Device lock?
                        dbus-send --system --type=method_call --dest=com.nokia.system_ui /com/nokia/system_ui/request com.nokia.system_ui.request.devlock_close string:"com.nokia.mce" string:"/com/nokia/mce/request" string:"com.nokia.mce.request" string:"devlock_callback" uint32:'0'
                fi
                if [ $tklock = 1 ]; then #Device lock?
                        dbus-send --system --type=method_call --dest=com.nokia.mce /com/nokia/mce/request com.nokia.mce.request.req_tklock_mode_change string:"unlocked"
                fi
                echo "..opened!"
        else
                echo "..not in home network!"
        fi
done

After couple unlocks the power button stops opening the menu :/ I'll make better one with python :D

laasonen 2011-04-05 22:38

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
Python version :) It is starting to be pretty decent, I'll upload it extras-devel later this week when I have time.

dave1010 2011-04-06 06:56

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
That's brilliant, thanks laasonen! Giving it a go now. I'm happy with editing a Python script but if it's going into extras then it'd be nice to have a GUI to edit the SSIDs.

I love the Maemo community.

laasonen 2011-04-06 07:26

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
Quote:

Originally Posted by dave1010 (Post 982840)
That's brilliant, thanks laasonen! Giving it a go now. I'm happy with editing a Python script but if it's going into extras then it'd be nice to have a GUI to edit the SSIDs.

I love the Maemo community.

I was thinking of adding gconf-support and settings applet.

laasonen 2011-04-08 16:04

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
Any ideas for name?

hawaii 2011-04-08 16:47

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
WireLock? SSIDSecure? WiLock? Wi-Lo?

Alfred 2011-04-08 16:54

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
What about "wifiunlock" or "wlanunlock" or smth that hasn't even with wifi to doб like "homeunlock"?

EDIT:

Quote:

Originally Posted by hawaii (Post 984257)
WireLock? SSIDSecure? WiLock? Wi-Lo?

Actually Wi-Lo sounds really cool=)

laasonen 2011-04-08 23:16

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
Decided to use my friend's idea ConnLock.

I haven't uploaded it to extras-devel, because I want to fix couple things first, but here is .deb:
http://hosted.laasonen.net/connlock_0.1.0-1_all.deb

There is something really strange about osso-systemui. Power button menu randomly stops working. I first thought it was just my shell script which was directly reading pwrbutton, but it's now happening with my python/dbus version :( Is it just me? Any suggestions?

http://hosted.laasonen.net/attachment-KVS8SV.png
http://hosted.laasonen.net/attachment-QKJ5SV.png

Pillum 2011-04-08 23:31

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
why REMOVED?

laasonen 2011-04-08 23:38

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
Quote:

Originally Posted by Pillum (Post 984397)
why REMOVED?

Added it again, but there is a problem with osso-systemui (read my last post).

jstokes 2011-04-09 20:15

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
Quote:

Originally Posted by laasonen (Post 984393)
There is something really strange about osso-systemui. Power button menu randomly stops working. I first thought it was just my shell script which was directly reading pwrbutton, but it's now happening with my python/dbus version :( Is it just me? Any suggestions?

Excuse me if I'm misunderstanding anything, but instead of watching to see if the power button is pressed and then calling the SystemUI D-Bus method that unlocks the device, why not just disable locking when a selected network is connected to and then re-enable it when the device disconnects?

You can turn off the autolock by changing the value of GConf key /system/osso/dsm/locks/devicelock_autolock_enabled

hawaii 2011-04-09 20:27

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
^^

Easily done using /etc/network/if-up.d/ and watching iwconfig for the associating SSID.

laasonen 2011-04-09 20:49

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
Quote:

Originally Posted by jstokes (Post 984717)
Excuse me if I'm misunderstanding anything, but instead of watching to see if the power button is pressed and then calling the SystemUI D-Bus method that unlocks the device..

The python version is using dbus, but the idea is the same:
Code:

self.bus.add_signal_receiver(self.unlock, path='/com/nokia/mce/signal', dbus_interface='com.nokia.mce.signal', signal_name='tklock_mode_ind')
Quote:

Originally Posted by jstokes (Post 984717)
...why not just disable locking when a selected network is connected to and then re-enable it when the device disconnects?

You can turn off the autolock by changing the value of GConf key /system/osso/dsm/locks/devicelock_autolock_enabled

Tried it and at least this doesn't open it, when it's already locked:
Code:

gconftool -s -t bool /system/osso/dsm/locks/devicelock_autolock_enabled false
So if you you lock your device when you are at work for example and then you go home, it will ask the password when you open it.

I have been testing the dbus devlock_close call more.

If I lock the device with dbus like this:
Code:

dbus-send --system --type=method_call --dest=com.nokia.system_ui /com/nokia/system_ui/request com.nokia.system_ui.request.devlock_open string:"com.nokia.mce" string:"/com/nokia/mce/request" string:"com.nokia.mce.request" string:"devlock_callback" uint32:'3'
And then unlock it like this:
Code:

dbus-send --system --type=method_call --dest=com.nokia.system_ui /com/nokia/system_ui/request com.nokia.system_ui.request.devlock_close string:"com.nokia.mce" string:"/com/nokia/mce/request" string:"com.nokia.mce.request" string:"devlock_callback" uint32:'0'
Everything works great, but when I lock it with the power button menu and then use dbus to unlock, the power button menu stops working, until I use dbus to lock it again and then open it with password. Could someone confirm this?

jstokes 2011-04-09 21:06

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
Quote:

Originally Posted by laasonen (Post 984734)
Could someone confirm this?

I can't confirm this as I have no N900, but you can enable D-Bus eavesdropping and see if anything different happens when locking from the menu

auouymous 2011-04-10 05:30

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
Code:

dbus-send --system --type=method_call --dest=com.nokia.mce /com/nokia/mce/request com.nokia.mce.request.devlock_callback int32:2
That will make MCE tell SystemUI to close the keypad on n8x0 and should do the same on n900, might have to change the 2 to a 0 though. You will still need to toggle the gconf value to keep the keypad from opening when the timeout expires.

laasonen 2011-04-10 06:04

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
Quote:

Originally Posted by auouymous (Post 984870)
Code:

dbus-send --system --type=method_call --dest=com.nokia.mce /com/nokia/mce/request com.nokia.mce.request.devlock_callback int32:2
That will make MCE tell SystemUI to close the keypad on n8x0 and should do the same on n900, might have to change the 2 to a 0 though. You will still need to toggle the gconf value to keep the keypad from opening when the timeout expires.

Works, thanks a lot :)

laasonen 2011-04-10 11:35

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
Here is 0.2.0 :) I'm now going to upload it to extras-testing.
http://hosted.laasonen.net/connlock_0.2.0-1_armel.deb

Alfred 2011-04-10 11:53

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
will try it out

laasonen 2011-04-10 12:23

Re: [Request/Idea] enable "secure device" lock based on wifi network
 
Created new thread.


All times are GMT. The time now is 05:31.

vBulletin® Version 3.8.8