Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac7284e3 authored by Casper Bonde's avatar Casper Bonde Committed by Andre Eisenbach
Browse files

Add support for MITM for BluetoothSockets (2/4)



This change enables use of the option to enforce Man-in-the-middle protection
for the authentication process for the Sim Acces Profile.

Change-Id: I98244d5e822c25f3f8f51833f38c79e13bb60e63
Signed-off-by: default avatarCasper Bonde <c.bonde@samsung.com>
parent 448d426c
Loading
Loading
Loading
Loading
+6 −11
Original line number Diff line number Diff line
@@ -113,27 +113,22 @@ public class SapService extends ProfileService {
        for (int i = 0; i < CREATE_RETRY_TIME && !mInterrupted; i++) {
            initSocketOK = true;
            try {
                //
                // It is mandatory for MSE to support initiation of bonding and
                // encryption.
                //
                // TODO: Consider reusing the mServerSocket - it is intended
                // to be reused for multiple connections.
                //
                mServerSocket = mAdapter.
                        listenUsingRfcommOn(BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP);
                int channel = mServerSocket.getChannel();
                // It is mandatory for MSE to support initiation of bonding and encryption.
                // TODO: Consider reusing the mServerSocket - it is indented to be reused
                //       for multiple connections.
                mServerSocket = mAdapter.listenUsingRfcommOn(
                        BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP, true);
                if (mSdpHandle >= 0) {
                    SdpManager.getDefaultManager().removeSdpRecord(mSdpHandle);
                    if (VERBOSE) Log.d(TAG, "Removing SDP record");
                }
                mSdpHandle = SdpManager.getDefaultManager().createSapsRecord(SDP_SAP_SERVICE_NAME,
                        mServerSocket.getChannel(), SDP_SAP_VERSION);

            } catch (IOException e) {
                Log.e(TAG, "Error create RfcommServerSocket ", e);
                initSocketOK = false;
            }

            if (!initSocketOK) {
                // Need to break out of this loop if BT is being turned off.
                if (mAdapter == null) break;
+35 −0
Original line number Diff line number Diff line
package com.android.bluetooth.tests;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothUuid;
import android.test.AndroidTestCase;
import android.util.Log;

import java.io.IOException;

public class SecurityTest extends AndroidTestCase {
    static final String TAG = "SecurityTest";

    public void connectSapNoSec() {
        BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
        if(bt == null) {
            Log.e(TAG,"No Bluetooth Device!");
            assertTrue(false);
        }

        BluetoothTestUtils.enableBt(bt);
        BluetoothDevice serverDevice = bt.getRemoteDevice(ObexTest.SERVER_ADDRESS);
        try {
            serverDevice.createInsecureRfcommSocketToServiceRecord(BluetoothUuid.SAP.getUuid());
        } catch (IOException e) {
            Log.e(TAG, "Failed to create connection", e);
        }

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            Log.w(TAG, "Sleep interrupted", e);
        }
    }
}