I'm aware that Android 2.3 has the methods: createInsecureRfcommSocket() and createInsecureRfcommSocketToServiceRecord(). I've been searching for a way to exchange data between devices, both using my application, without the need for pairing/bonding and user confimation. Will these methods allow me to, say, connect to a brand new device never before paired, and exchange data without prompting the user in any way?
Thanks. I was unable to find a specific answer to this question elsewhere.
The pairing process will still happen, except that if Devices are 2.1 and above, then the user will not be prompted for confirmation or for entering passkey during the pairing process. This is called using the "just works" model for pairing.
Related
Can I pair smartphone over Bluetooth without a need to confirm this in user interface, accept to pair this devices. I use android studio. I don't need to exchange data over them, I need just pairing without any action. And then safely pair with smartphone over Bluetooth without any user's action?
Yes and no, but you shouldn't anyway.
The only way to do this in Android is by using the BLUETOOTH_PRIVILEGED permission, which, as you can see, is only granted to apps in /system/priv-app/ or apps signed by the platform key of the device.
So unless you have root and can move your app to /system/priv-app/, you can't do what you want. Even if you can do this, however, don't. It's not a good user experience when someone installs an app, only for it to move itself to the system partition and start pairing without any notification.
We are designing a small hardware device (call it the "puck") that communicates over BLE, and an app for Android & iOS to talk to it. We have an app (written in C#/Xamarin) that is connecting to the puck and they are connecting and sending data back and forth.
According to this web site, when the Bluetooth connection is first made, the two devices "pair" which just means they exchange security information.
Question 1: Am I correct in my understanding that the exchange of security information takes place automatically, there's nothing I have to do in my code to cause it to happen?
Question 2: Am I guaranteed that the communication (after the initial exchange of security information, including keys) will be encrypted?
Question 3a: On an Android device, how can I query the connection to find out what security features were agreed upon by the two BLE devices?
Question 3b: Same as 3a but on an iOS device
The puck has no display to speak of (a couple of LEDs and a button) so can't display a PIN for bonding. The plan is to have the user initiate bonding in the mobile app, sending some command over the BLE connection; in response the puck will flash its lights in some pattern and wait for the user to press the button. If the button is pressed within some timeout, bonding should take place.
Question 4: What are the "best practices" for bonding, in order to keep the BLE connection as secure as possible?
1) BLE Security is a complicated thing, and if you are no expert at this, it is best to ensure that the stack on which you build the application is doing this for you. On Android (and also on iOS, I suppose) the built-in stack will do the pairing for you as soon as you have started it, but on your custom built "puck" you will have to ensure this for yourself - or implement a Bluetooth stack that does this correctly (recommended).
2) If implementation is correct, encryption is ensured, yes.
3) I can't tell you this in detail, but when you initiate pairing, there should be a response from the Bluetooth stack; maybe in the return parameters, you can find this information (but I don't know that, and it strongly depends on the API you are using).
4) If the puck has no display and no input possibility except from a button (that can be seen as a Yes/No option, where "Yes" is pressing the button and "No" is not pressing it), your possibilities for pairing are very limited. Expressed as I/O capabilities, this is defined as "NoInputNoOutput" (see CoreSpec v4.2, Vol.3, Part H, chap. 2.3.2), and thus it will always result in an unauthenticated connection (see table 7 in CoreSpec v4.2, Vol.3, Part C, chap. 5.2.2.6). This does not mean that the connection is not encrypted (in fact it is), but you have no protection against Man-in-the-Middle attacks.
Checking if a button is pressed on the puck may be an additional safety measure, but note that an attacker can fake the "Button pressed" message if s/he wants to pair with your app.
I am developing an application which connects devices over bluetooth and exchanges messages. It works fine for paired devices, but I would also like it to automatically pair devices that are not paired. Like for example it could store and use the same PIN for pairing requests, I just dont know how to manage this request programatically in my applciation, how to automatically set and send the PIN when you get a pairing request and how to initiate such a request with the predefined PIN code.
Any snippets or thoughts would be highly appreciated! :)
EDIT:
I know its risky, I am developing this app for emergency situations only where no other means but bluetooth is available. Also is there maybe a way of premature pairing with devices without even connecting to them? Like lets say there is a list of MAC Addresses of those devices and I can use them to generate a bond with that devices so that they appear paired on my device?
You can't do this. To do what you want to do would create a huge security risk. Think about it, my device just comes anywhere in bluetooth range of yours and now I can send you anything I want without you knowing? You can't really do this and I highly recommend not trying to subvert it.
Reflecting the setPin method allowed me to send the pin automatically to the other device. I had to implement it in a broadcast receiver that is listening for pairing requests. Although I cant get rid of the dialog it just stucks there on the screen and I dont know how to close it (programatically) and continue the bonding procedure since this dialog is called from inside connect() which is a blocking method. I am not giving up on it yet though :)
With Bluetooth version 2.1 and above there is a method of pairing called the 'just works' association model. This is the lowest security method of pairing and has no protection against man-in-the-middle attacks.
However, this will provide a secure, encrypted link without the need to exchange pin numbers or verify device ID.
The API on different platforms may differ but the underlying HCI messages require that you indicate that your device (or one of the devices) has the following IO capabilities:
No Keyboard, No Display.
As you might have guessed, this is a mode for very
simple devices that use Bluetooth, such as a speaker or headphones.
If you can find the API to configure that, then the 'just works' association mode of Secure Simple Pairing will be used for pairing.
The next step is to store the link keys e.g. bonding. Many devices e.g. mobile phones, will still create a dialogue box to the user to ask if they want to 'remember this device', as user authorisation is specified by the BT specifications... but that's another problem.
I was reading this
http://developer.android.com/guide/topics/wireless/bluetooth.html#QueryingPairedDevices
which is allot of help on how to pair,connect to a bluetooth device.
I have a situation where I have several BT devices that are in Non-Discover mode always. I know the MAC and the PIN of these devices. IS there a way in Android Dev to manually add devices to the PAIRED list so i can just use the connect as a client.
I understand this maual is written allot for V3. i think i will need to do this on 2.0 ; 2.1- has anybody done this before?
Basically these devices I want to connect to are power saving modules I used pre built BT modules to monitor daylight, another one humidity, etc.. every 3hrs or when interrupted and runs of a single battery for months. So turning off divcory on server saves immense power and prevents other people trying to connect and waste battery.
Not sure what you mean by "manually": Do you mean "manually" as in GUI/user interaction, or "manually" as "I do it in my own application code"?
Some suggestions though:
If you can make your BT devices discoverable at all, you could do it this way:
Make your BT device discoverable
Let Android search for and find the device and then initiate a connection
Android will ask for the PIN for pairing with the device; enter the PIN.
Once pairing was successful, Android stores the pairing information for future use, so that you can
Make your BT device invisible again.
From then on your app should be able to connect to the BT device at any time without further pairing operations.
If the said is not an option for you, maybe you want to go another way:
In current Android versions there are different API routines implemented which are neither documented nor exposed in the normal SDK. A hack kind of solution may be to use some of these "hidden" ("#hide"...) APIs, either via reflection or via modification of your SDK installation.
But be aware that this is always a hack and it may work on a specific device with a specific version of Android and is likely to break your app on another device and/or any other Android version.
Having said that, here comes some reference:
Example of how to access "hidden" bluetooth API.
Then, have a look at the source code for android.bluetooth.BluetoothDevice, e.g. here.
In there, public boolean createBond(){...} may do what you want.
In this past I've played with connecting two Android devices and every time they've required the user to input a pin to connect. I've even implemented the old "android-bluetooth" Google code project that attempted to inject the pin for a user-free connection without success after Android 1.5.
My question is, does the new 2.3.3 APIs allow for two Android devices to connect without user intervention? Not including NFC, is there anyway to allow phones to interact without authorization? Thanks.
Bluetooth version 2.1 and above has a new pairing mechanism called - Secure Simple Pairing (SSP), it allows for few different methods to pair , and it is different from the legacy pairing (which was the PIN entry mechanism).
The new Secure simple pairing mechanism does not depend on user entered PIN, instead it has a generated 6 digit pass key.
One of the SSP mechanism allows for pairing without any intervention from the user. This method is called "Just-works" association model, the createInsecureRfcommSocket() API uses this method.
The other API createRfcommSocket() will use the other mechanism - passkey entry or user confirmation where the 6 digit passkey comes into play.
The new pairing will get used only when both devices are bluetooth 2.1 and above
I have a detailed description of the new pairing mechanism here