Android的蓝牙连接安全不安全

Android的蓝牙连接安全不安全

本文介绍了Android的蓝牙连接安全不安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在玩弄为Android 2.2(API级别8上,HTC Desire)蓝牙API,并一个应用程序连接到嵌入式蓝牙设备的使用:

  device.createRfcommSocketToServiceRecord(DEV_UUID);
 

这产生预期,但是精简我想避免用户交互连接过程中,当配对感动到API级别10(HTC Desire采用的CyanogenMod 7)的配对请求,所以我可以使用:

  device.createInsecureRfcommSocketToServiceRecord(DEV_UUID);
 

在这个测试也按预期工作(连接不提示用户配对),但是当我尝试使用2.2作为前下创建API级别10安全RfcommSocket我得到一个连接被拒绝的例外......

  java.io.IOException异常:连接被拒绝
    在android.bluetooth.BluetoothSocket.connectNative(本机方法)
    在android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:204)
 

据我可以告诉这应该仍然工作以同样的方式,提示用户对?

编辑:

只需再次尝试使用下面的code和结果是相同的(工作不安全而不是安全的),我会尽量让我的手股票2.3设备上进行测试的。

 尝试{
            方法M = dev.getClass()实现getMethod(createInsecureRfcommSocketToServiceRecord,新的等级[] {} UUID.class)。
            的BluetoothSocket BS =(的BluetoothSocket)m.invoke(DEV,devUUID);
            Log.d(TEST,方法调用);
            bs.connect();
            Log.d(TEST,连接到插座);
            bs.close();
            Log.d(TEST,关闭套接字);
        }
 

解决方案

尽管找我的应用程序类似的问题的解决方案,我发现这个博客从code.google.com

这将帮助所有那些谁仍然在寻找对SO

这个问题的解决方案

http://mobisocial.stanford.edu /新闻/ 2011/03 /蓝牙反射和遗留-NFC / (链接不工作了)

该解决方案变得非常简单了。只包含InsecureBluetooth.java在您的项目,并更改BluetoothChatService.java 2行。

  TMP = InsecureBluetooth.listenUsingRfcommWithServiceRecord(mAdapter,姓名,MY_UUID,真正的);
 

  TMP = InsecureBluetooth.createRfcommSocketToServiceRecord(设备,MY_UUID,真正的);
 

完蛋了!

I have been playing around with the bluetooth API for Android 2.2 (API level 8, HTC Desire) and had an app connecting to an embedded Bluetooth device using:

device.createRfcommSocketToServiceRecord(DEV_UUID);

This generated a pairing request as expected, however to streamline the connection process I wanted to avoid the user interaction when pairing so moved to API level 10 (HTC Desire with CyanogenMod 7) so I could use:

 device.createInsecureRfcommSocketToServiceRecord(DEV_UUID);

When testing this also works as expected (connecting without prompting the user to pair), however when I try to create the secure RfcommSocket under API level 10 as before with 2.2 I get a connection refused exception...

 java.io.IOException: Connection refused
    at android.bluetooth.BluetoothSocket.connectNative(Native Method)
    at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:204)

As far as I can tell this should still work in the same way, prompting the user to pair?

EDIT:

Just tried again using the following code and the outcome is the same (working for insecure but not for secure), I will try and get my hands on a stock 2.3 device to test on.

        try {
            Method m = dev.getClass().getMethod("createInsecureRfcommSocketToServiceRecord", new Class[] { UUID.class } );
            BluetoothSocket bs = (BluetoothSocket)m.invoke(dev, devUUID);
            Log.d("TEST", "Method Invoked");
            bs.connect();
            Log.d("TEST", "Connected to socket");
            bs.close();
            Log.d("TEST", "Closed Socket");
        }
解决方案

While looking for the solution of similar problem in my app, I have found this blog from code.google.com

It will help all those who are still looking for this problem solution on SO

http://mobisocial.stanford.edu/news/2011/03/bluetooth-reflection-and-legacy-nfc/ (link not working anymore)

The solution has become very simple now. Just include InsecureBluetooth.java in your project and change 2 lines in BluetoothChatService.java.

tmp = InsecureBluetooth.listenUsingRfcommWithServiceRecord(mAdapter, NAME, MY_UUID, true);

and

tmp   = InsecureBluetooth.createRfcommSocketToServiceRecord(device, MY_UUID, true);

Thats it !

这篇关于Android的蓝牙连接安全不安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 04:45