2018-08-07 09:43:33

by Libor Peltan

[permalink] [raw]
Subject: bt "server" how to configure requiring passkey from connecting clients

Hello,
I'm preparing a bluetooth "access point" using BlueZ 5.47, so that for exam=
ple mobile phones can connect to it, and further use PAN profile (which is =
not part of this question). So far it works well, just using the JustWorks =
pairing method.

I'd like to secure this a little bit, not allowing anyone to pair, rather t=
o request passkey (let's say hardcoded string) before accepting pairing req=
uested by a client mobile phone.

After searching through documentation and much googling, I don't see any hi=
nts how to achieve this.

I found some information about pairing agents in BlueZ5, both in bluetoothc=
tl and custom (programming them seems complicated but viable and I cannot u=
se simple-agent since I don't have python on my machine), but all the useca=
ses seem to target on BlueZ being the client, who initiates pairing, and th=
e agent takes care of inputting passkey required by the other side - which =
is the opposite of what I need.

How to configure BlueZ5 to require passkey from any incomming pairing reque=
sts?

Thanks very much for your answers!

Libor


2018-08-14 13:15:02

by Libor Peltan

[permalink] [raw]
Subject: RE: bt "server" how to configure requiring passkey from connecting clients

VGhhbmsgeW91IGZvciB0aGUgYW5zd2VyIGFnYWluLg0KDQpJJ20gcmVnaXN0ZXJpbmcgdGhlIGFn
ZW50IHdpdGg6DQogICAgZGJ1c19jb25uZWN0aW9uX3RyeV9yZWdpc3Rlcl9vYmplY3RfcGF0aChh
Z2VudF9jb25uLCAiL2J0cGFuZF9hZ2VudCIsICZhZ2VudF90YWJsZSwgTlVMTCwgJmVycik7DQoN
CiAgICAib3JnLmJsdWV6IiAiL29yZy9ibHVleiIgIm9yZy5ibHVlei5BZ2VudE1hbmFnZXIxIiAi
UmVnaXN0ZXJBZ2VudCIgIm8iICIvYnRwYW5kX2FnZW50IiAicyIgIk5vSW5wdXROb091dHB1dCIN
Cg0KICAgICJvcmcuYmx1ZXoiICIvb3JnL2JsdWV6IiAib3JnLmJsdWV6LkFnZW50TWFuYWdlcjEi
ICJSZXF1ZXN0RGVmYXVsdEFnZW50IiAibyIgIi9idHBhbmRfYWdlbnQiDQoNClRoaXMgZ29lcyB3
aXRob3V0IGFueSBlcn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bSB0byBzaW1w
bHkgd29yay4uLg0KDQpZb3Ugd2lsbCBhbHNvIG5lZWQgdG8gcmVnaXN0ZXIgdGhlIGFnZW50LCBh
bmQgbWFrZSBzdXJlIGl0J3MgdGhlIGRlZmF1bHQgb25lICh5b3UnbGwgcHJvYmFibHkgd2FudCB0
byBkaXNhYmxlIHdoYXRldmVyIG90aGVyIG9uZSB5b3UgaGF2ZSBydW5uaW5nKS4NCg0KWW91IHdv
dWxkIHByb2JhYmx5IG9ubHkgZXZlciBnZXQgQXV0aG9yaXplU2VydmljZSBpZiB0aGUgZGV2aWNl
IGlzIGFscmVhZHkgcGFpcmVkLiBZb3Ugd291bGQgbmVlZCB0byB1bnBhaXIgaXQsIGFuZCBvbmNl
IHBhaXJlZCwgbWFyayBpdCBhcyB0cnVzdGVkIHNvIHRoYXQgQXV0aG9yaXplU2VydmljZSBpcyBu
b3QgY2FsbGVkIGFuZCB0aGUgc2VydmljZSBpcyBhdXRob3Jpc2VkIHdpdGhvdXQgYW55IGZ1cnRo
ZXIgcHJvbXB0cyAob3IgY2hlY2sgdGhhdCB0aGUgZGV2aWNlIGlzIHBhaXJlZCBpbiB5b3VyIEF1
dGhvcml6ZVNlcnZpY2UgaW1wbGVtZW50YXRpb24pLg0KDQpIVEgNCg0K

2018-08-14 12:25:44

by Bastien Nocera

[permalink] [raw]
Subject: Re: bt "server" how to configure requiring passkey from connecting clients

On Tue, 2018-08-14 at 12:14 +0000, Libor Peltan wrote:
> Thanks Bastien for your brief, but leading answer.
>
> Still, I feel like I'm missing something :(
>
> I've read the links carefully. The "CHIP-bluetooth-speaker" uses
> bluez-tools' bt-agent with parameters set so that it's using
> NoInputNoOutput capabilitiy, but requiring Passkey at the same time.
> This is exactly what I want!
>
> No having bluez-tools in my setup, I tried to make my own programmed
> agent behave similarly, i.e. according to your hint, implement the
> RequestPasskey method in my agent. However, this method is never
> called! When pairing a phone, BlueZ only calls the AuthorizeService
> method of my agent.
>
> How can I force BlueZ to call the RequestPasskey method of my agent?
>
> I tried to analyze how bluez-tools do it, but I haven't find anything
> in their code. They seem to simply work...

You will also need to register the agent, and make sure it's the
default one (you'll probably want to disable whatever other one you
have running).

You would probably only ever get AuthorizeService if the device is
already paired. You would need to unpair it, and once paired, mark it
as trusted so that AuthorizeService is not called and the service is
authorised without any further prompts (or check that the device is
paired in your AuthorizeService implementation).

HTH

2018-08-14 12:14:28

by Libor Peltan

[permalink] [raw]
Subject: RE: bt "server" how to configure requiring passkey from connecting clients

VGhhbmtzIEJhc3RpZW4gZm9yIHlvdXIgYnJpZWYsIGJ1dCBsZWFkaW5nIGFuc3dlci4NCg0KU3Rp
bGwsIEkgZmVlbCBsaWtlIEknbSBtaXNzaW5nIHNvbWV0aGluZyA6KA0KDQpJJ3ZlIHJlYWQgdGhl
IGxpbmtzIGNhcmVmdWxseS4gVGhlICJDSElQLWJsdWV0b290aC1zcGVha2VyIiB1c2VzIGJsdWV6
LXRvb2xzJyBidC1hZ2VudCB3aXRoIHBhcmFtZXRlcnMgc2V0IHNvIHRoYXQgaXQncyB1c2luZyBO
b0lucHV0Tm9PdXRwdXQgY2FwYWJpbGl0aXksIGJ1dCByZXF1aXJpbmcgUGFzc2tleSBhdCB0aGUg
c2FtZSB0aW1lLiBUaGlzIGlzIGV4YWN0bHkgd2hhdCBJIHdhbnQhDQoNCk5vIGhhdmluZyBibHVl
ei10b29scyBpbiBteSBzZXR1cCwgSSB0cmllZCB0byBtYWtlIG15IG93biBwcm9ncmFtbWVkIGFn
ZW50IGJlaGF2ZSBzaW1pbGFybHksIGkuZS4gYWNjb3JkaW5nIHRvIHlvdXIgaGludCwgaW1wbGVt
ZW50IHRoZSBSZXF1ZXN0UGFzc2tleSBtZXRob2QgaW4gbXkgYWdlbnQuIEhvd2V2ZXIsIHRoaXMg
bWV0aG9kIGlzIG5ldmVyIGNhbGxlZCEgV2hlbiBwYWlyaW5nIGEgcGhvbmUsIEJsdWVaIG9ubHkg
Y2FsbHMgdGhlIEF1dGhvcml6Z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HV0IGNhcGFiaWxpdHks
IGFuZCBpbXBsZW1lbnQgdGhlIFJlcXVlc3RQYXNza2V5IGZ1bmN0aW9uIHNvIHRoYXQgeW91IGNh
biBwcm92aWRlIHRoZSBwYXNza2V5IHRvIGJlIHVzZWQuDQoNCkNoZWVycw0K

2018-08-08 15:14:52

by Bastien Nocera

[permalink] [raw]
Subject: Re: bt "server" how to configure requiring passkey from connecting clients

On Wed, 2018-08-08 at 14:31 +0000, Libor Peltan wrote:
> Hi Bastien,
> Thanks much for your answer.
>
> Even if programmed my own pairing agent, I can't see how I could
> achieve having fixed PIN for incomming requests.
>
> When I register my agent, I can choose one of following capability
> options [accorging to BlueZ Agent API]:
> - NoInputNoOutput, DisplayYesNo, KeyboardOnly: I can just
> programatically decide based on the client's BD address if I accept
> the pairing or not
> - DisplayOnly, KeyboardDisplay: at the time of pairing, the agent
> receives already the PIN, and can just decide if it's accepted. But
> this PIN is not entered by the mobile phone (client) user, it's just
> fabriqued (randomly?) somewhere inside the pairing process. Actually,
> the mobile phone user is queried with the same PIN and can only
> accept it too.
>
> All in all, my agent is never asked to return the PIN.
>
> The agents built-in in bluetoothctl or the bluez-tools you pointed
> to, behave rouhly the same.
>
> Am I missing something, some other usecase of pairing agent?
>
> It seems weird to me that for old version of BlueZ (4?), I have found
> something like 'bluetooth-agent 1234' command instantly doing what I
> need... But I don't know exactly.

This, up to line 100:
https://github.com/hadess/CHIP-bluetooth-speaker/blob/master/setup.sh#L73
is the example of a script that creates a fixed PIN, for all clients,
with bluez-tools' bt-agent running as a service. Ideally, you would
start this after some sort of physical interaction with your device, or
have an "uncommon" pincode (a password of sorts, eg. not 0000 or 1111),
otherwise your neighbours will be able to pair with your device.

If you want to use a fixed pin code in your agent, you'd need to use
the NoInputNoOutput capability, and implement the RequestPasskey
function so that you can provide the passkey to be used.

Cheers

2018-08-08 14:31:30

by Libor Peltan

[permalink] [raw]
Subject: RE: bt "server" how to configure requiring passkey from connecting clients

SGkgQmFzdGllbiwNClRo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bXBsZS1hZ2VudCBQeXRob24gc2NyaXB0IGluIHRoZSBibHVleiBzb3VyY2VzIGlz
IHByb2JhYmx5IGEgZ29vZCBzdGFydC4NCg0KQ2hlZXJzDQo=

2018-08-08 12:41:13

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: bt "server" how to configure requiring passkey from connecting clients

Hi,

On Wed, Aug 8, 2018 at 3:19 PM, Bastien Nocera <[email protected]> wrote:
> On Tue, 2018-08-07 at 09:43 +0000, Libor Peltan wrote:
>> Hello,
>> I'm preparing a bluetooth "access point" using BlueZ 5.47, so that
>> for example mobile phones can connect to it, and further use PAN
>> profile (which is not part of this question). So far it works well,
>> just using the JustWorks pairing method.
>>
>> I'd like to secure this a little bit, not allowing anyone to pair,
>> rather to request passkey (let's say hardcoded string) before
>> accepting pairing requested by a client mobile phone.
>>
>> After searching through documentation and much googling, I don't see
>> any hints how to achieve this.
>>
>> I found some information about pairing agents in BlueZ5, both in
>> bluetoothctl and custom (programming them seems complicated but
>> viable and I cannot use simple-agent since I don't have python on my
>> machine), but all the usecases seem to target on BlueZ being the
>> client, who initiates pairing, and the agent takes care of inputting
>> passkey required by the other side - which is the opposite of what I
>> need.
>>
>> How to configure BlueZ5 to require passkey from any incomming pairing
>> requests?
>>
>> Thanks very much for your answers!
>
> You need a pairing agent to do this sort of thing, and bluez itself
> doesn't ship any such tools for headless use. Your best bet is using
> the "bluez-tools" repo:
> https://github.com/khvzak/bluez-tools
>
> I've used them successfully on headless devices. In your case, you
> could have the pairing agent (bt-agent) be started for X seconds after
> a button press for example.
>
> If you want something more complicated, you'll need to implement your
> own agent, the test/simple-agent Python script in the bluez sources is
> probably a good start.

I was wondering about this while hacking the AlwaysPairable option, we
could perhaps add a third option there for hardcoding a pincode that
way it would not be limited to just works since that does not offer
main in the middle protection. Obviously if the system does have an
agent then it should stick to AlwaysPairable = false.

--
Luiz Augusto von Dentz

2018-08-08 12:19:25

by Bastien Nocera

[permalink] [raw]
Subject: Re: bt "server" how to configure requiring passkey from connecting clients

On Tue, 2018-08-07 at 09:43 +0000, Libor Peltan wrote:
> Hello,
> I'm preparing a bluetooth "access point" using BlueZ 5.47, so that
> for example mobile phones can connect to it, and further use PAN
> profile (which is not part of this question). So far it works well,
> just using the JustWorks pairing method.
>
> I'd like to secure this a little bit, not allowing anyone to pair,
> rather to request passkey (let's say hardcoded string) before
> accepting pairing requested by a client mobile phone.
>
> After searching through documentation and much googling, I don't see
> any hints how to achieve this.
>
> I found some information about pairing agents in BlueZ5, both in
> bluetoothctl and custom (programming them seems complicated but
> viable and I cannot use simple-agent since I don't have python on my
> machine), but all the usecases seem to target on BlueZ being the
> client, who initiates pairing, and the agent takes care of inputting
> passkey required by the other side - which is the opposite of what I
> need.
>
> How to configure BlueZ5 to require passkey from any incomming pairing
> requests?
>
> Thanks very much for your answers!

You need a pairing agent to do this sort of thing, and bluez itself
doesn't ship any such tools for headless use. Your best bet is using
the "bluez-tools" repo:
https://github.com/khvzak/bluez-tools

I've used them successfully on headless devices. In your case, you
could have the pairing agent (bt-agent) be started for X seconds after
a button press for example.

If you want something more complicated, you'll need to implement your
own agent, the test/simple-agent Python script in the bluez sources is
probably a good start.

Cheers