提问者:小点点

Android蓝牙和笔记本电脑蓝牙设备之间是否有可能建立不安全的连接?


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

我创建了一个Android应用程序(客户端),它尝试连接运行java应用程序(服务器)的笔记本电脑蓝牙设备。

我担心的是,是否可以使用蓝牙插座连接不安全地连接两个设备(无需 PIN 身份验证)?

如果可能,请向我建议解决方案。

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

提前致谢!!!


共2个答案

匿名用户

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

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

我的服务器是用java的。在 java 中,将某些参数添加到 URL。使身份验证=假;授权=假;加密=假;打开此 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 + ".\n\nUpdate your server address from 00:00:00:00:00:00 to the correct address on line 37 in the java code";
            msg = msg +  ".\n\nCheck that the SPP UUID: " + MY_UUID.toString() + " exists on server.\n\n";
        }
        // AlertBox("Fatal Error", msg);      
    }

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

在客户端的“地址”字段中提供服务器蓝牙MAC地址。

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

但是此代码依赖于设备...

某些设备能够非常有效地进行通信。像联想笔记本电脑,用于 Java 服务器的 PC 的外部蓝牙设备和 Android 设备戴尔会场 7,索尼,LG 手机为客户端。经过测试并正常工作。

但是在戴尔笔记本电脑,Micromaxx,xolo移动中,它不起作用。我不知道为什么它不起作用,如果有人知道,请给出解决方案。

匿名用户

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