安卓蓝牙与笔记本蓝牙设备之间是否存在不安全连接?



我正在尝试通过蓝牙插座连接android设备与笔记本电脑或台式机。

我已经创建了一个android应用程序(客户端),它试图连接笔记本电脑蓝牙设备,其中java应用程序(服务器)正在运行。

我担心的是,是否有可能使用蓝牙插座连接不安全地连接这两个设备(没有pin认证)?

如果可能,请给我一个解决方案。

如果没有,是否有任何方法以编程方式自动配对两个设备?

提前感谢!!

通过参考java蓝牙api,我得到了两个Android和笔记本电脑蓝牙设备之间不安全连接的解决方案。

我已经使用了SPP客户端服务器机制。

我的服务器是java。在java中,为URL添加某些参数。Make authentication= false;授权= false;加密= false;打开此URL接受连接。

//Create a UUID for SPP
    UUID uuid=new UUID("0f2b61c18be240e6ab90e735818da0a7", false);
    System.out.println("n"+uuid.toString());
    //Create the servicve url
    String url="btspp://localhost:"+uuid.toString()+";"+"name=remoteNotifier;authenticate=false;authorize=false;encrypt=false";
    //open server url
    StreamConnectionNotifier streamConnNotifier = (StreamConnectionNotifier)Connector.open(url);

    //Create a UUID for SPP
    UUID uuid=new UUID("0f2b61c18be240e6ab90e735818da0a7", false);
    System.out.println("n"+uuid.toString());
    //Create the servicve url
    String url="btspp://localhost:"+uuid.toString()+";"+"name=remoteNotifier;authenticate=false;authorize=false;encrypt=false";
    //open server url
    StreamConnectionNotifier streamConnNotifier = (StreamConnectionNotifier)Connector.open(url);

现在客户端:Android API 10以上包含不安全连接方法。"createInsecureRfcommSocketToServiceRecord (UUID)"所以使用这种方法进行连接。它不会弹出配对请求,并尝试连接Java服务器已经运行的远程蓝牙设备。

代码:

// Set up a pointer to the remote node using it's address.
    BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
    // Two things are needed to make a connection:
    // A MAC address, which we got above.
    // A Service ID or UUID.  In this case we are using the
    // UUID for SPP.
    try {
        //          btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
        btSocket = device.createInsecureRfcommSocketToServiceRecord(MY_UUID);
    } catch (IOException e) {
        AlertBox("Fatal Error", "In onResume() and socket create failed: " + e.getMessage() + ".");
    }
    // Discovery is resource intensive.  Make sure it isn't going on
    // when you attempt to connect and pass your message.
    mBluetoothAdapter.cancelDiscovery();
    // Establish the connection.  This will block until it connects.
    try {
        btSocket.connect();
        out.append("n...Connection established and data link opened...");
    } catch (IOException e) {
        try {
            btSocket.close();
            e.printStackTrace();
        } catch (IOException e2) {
            e2.printStackTrace();
            AlertBox("Fatal Error", "In onResume() and unable to close socket during connection failure" + e2.getMessage() + ".");
        }
    }
    // Create a data stream so we can talk to server.
    out.append("n...Sending message to server...");
    try {
        outStream = btSocket.getOutputStream();
    } catch (IOException e) {
        AlertBox("Fatal Error", "In onResume() and output stream creation failed:" + e.getMessage() + ".");
    }
    //      Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.android_logo);
    //      byte[] msgBuffer = getBytesFromBitmap(bitmap);
    String message = "Hello from Android.n";
    byte[] msgBuffer = message.getBytes();
    try {
        outStream.write(msgBuffer);
    } catch (IOException e) {
        String msg = "In onResume() and an exception occurred during write: " + e.getMessage();
        if (address.equals("00:00:00:00:00:00")) {
            msg = msg + ".nnUpdate your server address from 00:00:00:00:00:00 to the correct address on line 37 in the java code";
            msg = msg +  ".nnCheck that the SPP UUID: " + MY_UUID.toString() + " exists on server.nn";
        }
        // AlertBox("Fatal Error", msg);      
    }

我只提供了所需的代码。对于连接,两个设备的UUID应该相同。

在客户端"address"字段提供服务器蓝牙MAC地址。

我们能够与远程蓝牙设备进行不安全的通信(无需配对)。

但是这段代码是设备相关的…

某些设备能够非常有效地通信。如联想笔记本电脑,外接蓝牙设备的PC为Java服务器和Android设备DELL venue 7,索尼、LG手机为客户端。已测试,工作正常

但在戴尔笔记本电脑、Micromaxx、xolo手机上,它不起作用。我不知道为什么不工作,如果有人知道,请给出解决方案。

对于蓝牙2.1及以上的设备,安全性是强制性的。如果你只是想避免密码输入/显示,你可以将笔记本电脑和安卓设备的安全要求设置为"不需要MITM保护"。这样,设备将自动配对,但链接将容易受到中间人攻击。

相关内容

最新更新