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

Commit 89c6ea5d authored by Charlie Boutier's avatar Charlie Boutier Committed by Automerger Merge Worker
Browse files

Merge "[Pandora] - Implement refined Security.proto" am: 3b92f765 am: 80c79587

parents 115f008d 80c79587
Loading
Loading
Loading
Loading
+12 −8
Original line number Original line Diff line number Diff line
@@ -7,7 +7,8 @@ from pandora_experimental.gatt_grpc import GATT
from pandora_experimental.gatt_pb2 import GattServiceParams, GattCharacteristicParams
from pandora_experimental.gatt_pb2 import GattServiceParams, GattCharacteristicParams
from pandora_experimental.host_grpc import Host
from pandora_experimental.host_grpc import Host
from pandora_experimental.host_pb2 import ConnectabilityMode, DataTypes, DiscoverabilityMode, OwnAddressType
from pandora_experimental.host_pb2 import ConnectabilityMode, DataTypes, DiscoverabilityMode, OwnAddressType
from pandora_experimental.security_grpc import Security
from pandora_experimental.security_grpc import Security, SecurityStorage
from pandora_experimental.security_pb2 import LESecurityLevel




class GAPProxy(ProfileProxy):
class GAPProxy(ProfileProxy):
@@ -17,6 +18,7 @@ class GAPProxy(ProfileProxy):
        self.gatt = GATT(channel)
        self.gatt = GATT(channel)
        self.host = Host(channel)
        self.host = Host(channel)
        self.security = Security(channel)
        self.security = Security(channel)
        self.security_storage = SecurityStorage(channel)


        self.connection = None
        self.connection = None
        self.pairing_events = None
        self.pairing_events = None
@@ -132,9 +134,9 @@ class GAPProxy(ProfileProxy):
            # we also begin pairing here if we are not already paired on LE
            # we also begin pairing here if we are not already paired on LE
            if self.counter == 0:
            if self.counter == 0:
                self.counter += 1
                self.counter += 1
                self.security.DeletePairing(address=pts_addr)
                self.security_storage.DeleteBond(public=pts_addr)
                self.connection = self.host.ConnectLE(public=pts_addr).connection
                self.connection = self.host.ConnectLE(public=pts_addr).connection
                self.security.Pair(connection=self.host.GetLEConnection(address=pts_addr).connection)
                self.security.Secure(connection=self.connection, le=LESecurityLevel.LE_LEVEL3)
                return "OK"
                return "OK"


        if test == "GAP/SEC/AUT/BV-21-C" and self.connection is not None:
        if test == "GAP/SEC/AUT/BV-21-C" and self.connection is not None:
@@ -158,7 +160,7 @@ class GAPProxy(ProfileProxy):


        self.connection = self.host.ConnectLE(public=address).connection
        self.connection = self.host.ConnectLE(public=address).connection
        if test in {"GAP/BOND/BON/BV-04-C"}:
        if test in {"GAP/BOND/BON/BV-04-C"}:
            self.security.Pair(connection=self.connection)
            self.security.Secure(connection=self.connection, le=LESecurityLevel.LE_LEVEL3)


        return "OK"
        return "OK"


@@ -559,9 +561,10 @@ class GAPProxy(ProfileProxy):
            return "OK"
            return "OK"


        if test not in {"GAP/SEC/AUT/BV-21-C"}:
        if test not in {"GAP/SEC/AUT/BV-21-C"}:
            self.security.DeletePairing(address=pts_addr)
            self.security_storage.DeleteBond(public=pts_addr)


        self.security.Pair(connection=self.host.GetLEConnection(address=pts_addr).connection)
        connection = self.host.GetLEConnection(address=pts_addr).connection
        self.security.Secure(connection=connection, le=LESecurityLevel.LE_LEVEL3)


        return "OK"
        return "OK"


@@ -704,7 +707,8 @@ class GAPProxy(ProfileProxy):
        """
        """


        # No idea how we can bond in non-bondable mode, but this passes the tests...
        # No idea how we can bond in non-bondable mode, but this passes the tests...
        self.security.Pair(connection=self.host.GetLEConnection(address=pts_addr).connection,)
        connection = self.host.GetLEConnection(address=pts_addr).connection
        self.security.Secure(connection=connection, le=LESecurityLevel.LE_LEVEL3)


        return "OK"
        return "OK"


@@ -887,7 +891,7 @@ class GAPProxy(ProfileProxy):
        if test != "GAP/SEC/SEM/BV-08-C":
        if test != "GAP/SEC/SEM/BV-08-C":
            # we already started in the Connect MMI
            # we already started in the Connect MMI
            self.pairing_events = self.security.OnPairing()
            self.pairing_events = self.security.OnPairing()
            self.security.Pair(connection=connection)
            self.security.Secure(connection=connection, le=LESecurityLevel.LE_LEVEL3)


        connection = self.host.GetConnection(address=pts_addr).connection
        connection = self.host.GetConnection(address=pts_addr).connection


+3 −2
Original line number Original line Diff line number Diff line
@@ -19,7 +19,7 @@ from mmi2grpc._proxy import ProfileProxy
from pandora_experimental.hfp_grpc import HFP
from pandora_experimental.hfp_grpc import HFP
from pandora_experimental.host_grpc import Host
from pandora_experimental.host_grpc import Host
from pandora_experimental.host_pb2 import ConnectabilityMode
from pandora_experimental.host_pb2 import ConnectabilityMode
from pandora_experimental.security_grpc import Security
from pandora_experimental.security_grpc import Security, SecurityStorage
from pandora_experimental.hfp_pb2 import AudioPath
from pandora_experimental.hfp_pb2 import AudioPath


import sys
import sys
@@ -43,6 +43,7 @@ class HFPProxy(ProfileProxy):
        self.hfp = HFP(channel)
        self.hfp = HFP(channel)
        self.host = Host(channel)
        self.host = Host(channel)
        self.security = Security(channel)
        self.security = Security(channel)
        self.security_storage = SecurityStorage(channel)
        self.rootcanal = rootcanal
        self.rootcanal = rootcanal
        self.modem = modem
        self.modem = modem


@@ -75,7 +76,7 @@ class HFPProxy(ProfileProxy):
        (IUT), then click Ok.
        (IUT), then click Ok.
        """
        """


        self.security.DeletePairing(address=pts_addr)
        self.security_storage.DeleteBond(public=pts_addr)
        return "OK"
        return "OK"


    @assert_description
    @assert_description
+5 −1
Original line number Original line Diff line number Diff line
import threading
import textwrap
import textwrap
import uuid
import uuid
import re
import re
@@ -7,6 +8,7 @@ from mmi2grpc._proxy import ProfileProxy


from pandora_experimental.host_grpc import Host
from pandora_experimental.host_grpc import Host
from pandora_experimental.security_grpc import Security
from pandora_experimental.security_grpc import Security
from pandora_experimental.security_pb2 import LESecurityLevel
from pandora_experimental.gatt_grpc import GATT
from pandora_experimental.gatt_grpc import GATT


BASE_UUID = uuid.UUID("00000000-0000-1000-8000-00805F9B34FB")
BASE_UUID = uuid.UUID("00000000-0000-1000-8000-00805F9B34FB")
@@ -39,7 +41,9 @@ class HOGPProxy(ProfileProxy):


        self.connection = self.host.ConnectLE(public=pts_addr).connection
        self.connection = self.host.ConnectLE(public=pts_addr).connection
        self.pairing_stream = self.security.OnPairing()
        self.pairing_stream = self.security.OnPairing()
        self.security.Pair(connection=self.connection)
        def secure():
            self.security.Secure(connection=self.connection, le=LESecurityLevel.LE_LEVEL3)
        threading.Thread(target=secure).start()


        return "OK"
        return "OK"


+6 −3
Original line number Original line Diff line number Diff line
@@ -15,13 +15,14 @@
from queue import Empty, Queue
from queue import Empty, Queue
from threading import Thread
from threading import Thread
import sys
import sys
import time
import asyncio


from mmi2grpc._helpers import assert_description, match_description
from mmi2grpc._helpers import assert_description, match_description
from mmi2grpc._proxy import ProfileProxy
from mmi2grpc._proxy import ProfileProxy
from mmi2grpc._streaming import StreamWrapper
from mmi2grpc._streaming import StreamWrapper


from pandora_experimental.security_grpc import Security
from pandora_experimental.security_grpc import Security
from pandora_experimental.security_pb2 import LESecurityLevel
from pandora_experimental.host_grpc import Host
from pandora_experimental.host_grpc import Host
from pandora_experimental.host_pb2 import ConnectabilityMode, OwnAddressType
from pandora_experimental.host_pb2 import ConnectabilityMode, OwnAddressType


@@ -54,8 +55,10 @@ class SMProxy(ProfileProxy):
        """
        """
        Please start pairing process.
        Please start pairing process.
        """
        """
        def secure():
            if self.connection:
            if self.connection:
            self.security.Pair(connection=self.connection)
                self.security.Secure(connection=self.connection, le=LESecurityLevel.LE_LEVEL3)
        Thread(target=secure).start()
        return "OK"
        return "OK"


    @assert_description
    @assert_description
+16 −23
Original line number Original line Diff line number Diff line
@@ -43,7 +43,6 @@ import com.google.protobuf.ByteString
import com.google.protobuf.Empty
import com.google.protobuf.Empty
import io.grpc.Status
import io.grpc.Status
import io.grpc.stub.StreamObserver
import io.grpc.stub.StreamObserver
import java.io.IOException
import java.time.Duration
import java.time.Duration
import java.util.UUID
import java.util.UUID
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineScope
@@ -62,12 +61,15 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import pandora.HostGrpc.HostImplBase
import pandora.HostGrpc.HostImplBase
import pandora.HostProto.*
import pandora.HostProto.*


@kotlinx.coroutines.ExperimentalCoroutinesApi
@kotlinx.coroutines.ExperimentalCoroutinesApi
class Host(private val context: Context, private val server: Server) : HostImplBase() {
class Host(
  private val context: Context,
  private val security: Security,
  private val server: Server
) : HostImplBase() {
  private val TAG = "PandoraHost"
  private val TAG = "PandoraHost"


  private val scope: CoroutineScope
  private val scope: CoroutineScope
@@ -194,7 +196,7 @@ class Host(private val context: Context, private val server: Server) : HostImplB
      .first()
      .first()
  }
  }


  private suspend fun waitBondIntent(bluetoothDevice: BluetoothDevice) {
  suspend fun waitBondIntent(bluetoothDevice: BluetoothDevice) {
    // We only wait for bonding to be completed since we only need the ACL connection to be
    // We only wait for bonding to be completed since we only need the ACL connection to be
    // established with the peer device (on Android state connected is sent when all profiles
    // established with the peer device (on Android state connected is sent when all profiles
    // have been connected).
    // have been connected).
@@ -229,7 +231,7 @@ class Host(private val context: Context, private val server: Server) : HostImplB
        throw Status.UNKNOWN.asException()
        throw Status.UNKNOWN.asException()
      }
      }


      if (request.manuallyConfirm) {
      if (security.manuallyConfirm) {
        waitBondIntent(bluetoothDevice)
        waitBondIntent(bluetoothDevice)
      } else {
      } else {
        acceptPairingAndAwaitBonded(bluetoothDevice)
        acceptPairingAndAwaitBonded(bluetoothDevice)
@@ -250,14 +252,6 @@ class Host(private val context: Context, private val server: Server) : HostImplB
      bluetoothAdapter.cancelDiscovery()
      bluetoothAdapter.cancelDiscovery()


      if (!bluetoothDevice.isConnected()) {
      if (!bluetoothDevice.isConnected()) {
        if (request.skipPairing) {
          // do an SDP request to trigger a temporary BREDR connection
          try {
            withTimeout(1500) { bluetoothDevice.createRfcommSocket(3).connect() }
          } catch (e: IOException) {
            // ignore
          }
        } else {
        if (bluetoothDevice.bondState == BOND_BONDED) {
        if (bluetoothDevice.bondState == BOND_BONDED) {
          // already bonded, just reconnect
          // already bonded, just reconnect
          bluetoothDevice.connect()
          bluetoothDevice.connect()
@@ -265,12 +259,11 @@ class Host(private val context: Context, private val server: Server) : HostImplB
        } else {
        } else {
          // need to bond
          // need to bond
          bluetoothDevice.createBond()
          bluetoothDevice.createBond()
            if (!request.manuallyConfirm) {
          if (!security.manuallyConfirm) {
            acceptPairingAndAwaitBonded(bluetoothDevice)
            acceptPairingAndAwaitBonded(bluetoothDevice)
          }
          }
        }
        }
      }
      }
      }


      ConnectResponse.newBuilder()
      ConnectResponse.newBuilder()
        .setConnection(bluetoothDevice.toConnection(TRANSPORT_BREDR))
        .setConnection(bluetoothDevice.toConnection(TRANSPORT_BREDR))
Loading