diff options
| author | Casper Bonde <c.bonde@samsung.com> | 2015-05-08 14:32:24 +0200 |
|---|---|---|
| committer | Andre Eisenbach <eisenbach@google.com> | 2015-06-09 21:42:22 +0000 |
| commit | 3b3d1fea94318a4892fbd4353269749af417a81a (patch) | |
| tree | 35e44e3d5ad431e3327fcdc4b189653c77b027b8 /core/java | |
| parent | 6f024937c11bd9e1ad0aa2ab9ae05e14eae5063a (diff) | |
| download | frameworks_base-3b3d1fea94318a4892fbd4353269749af417a81a.zip frameworks_base-3b3d1fea94318a4892fbd4353269749af417a81a.tar.gz frameworks_base-3b3d1fea94318a4892fbd4353269749af417a81a.tar.bz2 | |
SAP: Make it possible to enforce a 16-digit pin code (4/5)
This change enable the posibility to enforce using a
16-digit pin or MITM for a RFCOMM or L2CAP connection.
This is needed for the SIM access profile.
Change-Id: I3205013f9e758c353381442a86845dab467780f8
Signed-off-by: Casper Bonde <c.bonde@samsung.com>
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/bluetooth/BluetoothAdapter.java | 17 | ||||
| -rw-r--r-- | core/java/android/bluetooth/BluetoothDevice.java | 11 | ||||
| -rw-r--r-- | core/java/android/bluetooth/BluetoothServerSocket.java | 6 | ||||
| -rw-r--r-- | core/java/android/bluetooth/BluetoothSocket.java | 14 |
4 files changed, 35 insertions, 13 deletions
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java index ab3f7bc..97afafa 100644 --- a/core/java/android/bluetooth/BluetoothAdapter.java +++ b/core/java/android/bluetooth/BluetoothAdapter.java @@ -1467,7 +1467,7 @@ public final class BluetoothAdapter { * @hide */ public BluetoothServerSocket listenUsingRfcommOn(int channel) throws IOException { - return listenUsingRfcommOn(channel, false); + return listenUsingRfcommOn(channel, false, false); } /** @@ -1482,14 +1482,17 @@ public final class BluetoothAdapter { * {@link SOCKET_CHANNEL_AUTO_STATIC_NO_SDP} as channel number. * @param channel RFCOMM channel to listen on * @param mitm enforce man-in-the-middle protection for authentication. + * @param min16DigitPin enforce a pin key length og minimum 16 digit for sec mode 2 connections. * @return a listening RFCOMM BluetoothServerSocket * @throws IOException on error, for example Bluetooth not available, or * insufficient permissions, or channel in use. * @hide */ - public BluetoothServerSocket listenUsingRfcommOn(int channel, boolean mitm) throws IOException { + public BluetoothServerSocket listenUsingRfcommOn(int channel, boolean mitm, + boolean min16DigitPin) + throws IOException { BluetoothServerSocket socket = new BluetoothServerSocket( - BluetoothSocket.TYPE_RFCOMM, true, true, channel, mitm); + BluetoothSocket.TYPE_RFCOMM, true, true, channel, mitm, min16DigitPin); int errno = socket.mSocket.bindListen(); if (channel == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { socket.setChannel(socket.mSocket.getPort()); @@ -1694,14 +1697,16 @@ public final class BluetoothAdapter { * {@link SOCKET_CHANNEL_AUTO_STATIC_NO_SDP} as port number. * @param port the PSM to listen on * @param mitm enforce man-in-the-middle protection for authentication. + * @param min16DigitPin enforce a pin key length og minimum 16 digit for sec mode 2 connections. * @return An L2CAP BluetoothServerSocket * @throws IOException On error, for example Bluetooth not available, or * insufficient permissions. * @hide */ - public BluetoothServerSocket listenUsingL2capOn(int port, boolean mitm) throws IOException { + public BluetoothServerSocket listenUsingL2capOn(int port, boolean mitm, boolean min16DigitPin) + throws IOException { BluetoothServerSocket socket = new BluetoothServerSocket( - BluetoothSocket.TYPE_L2CAP, true, true, port, mitm); + BluetoothSocket.TYPE_L2CAP, true, true, port, mitm, min16DigitPin); int errno = socket.mSocket.bindListen(); if(port == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { socket.setChannel(socket.mSocket.getPort()); @@ -1727,7 +1732,7 @@ public final class BluetoothAdapter { * @hide */ public BluetoothServerSocket listenUsingL2capOn(int port) throws IOException { - return listenUsingL2capOn(port, false); + return listenUsingL2capOn(port, false, false); } /** diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java index dcf06d8..c96fe71 100644 --- a/core/java/android/bluetooth/BluetoothDevice.java +++ b/core/java/android/bluetooth/BluetoothDevice.java @@ -531,6 +531,13 @@ public final class BluetoothDevice implements Parcelable { public static final int PAIRING_VARIANT_OOB_CONSENT = 6; /** + * The user will be prompted to enter a 16 digit pin or + * an app will enter a 16 digit pin for user. + * @hide + */ + public static final int PAIRING_VARIANT_PIN_16_DIGITS = 7; + + /** * Used as an extra field in {@link #ACTION_UUID} intents, * Contains the {@link android.os.ParcelUuid}s of the remote device which * is a parcelable version of {@link UUID}. @@ -1315,8 +1322,8 @@ public final class BluetoothDevice implements Parcelable { Log.e(TAG, "", e); } return false; - } - + } + /** * Create an RFCOMM {@link BluetoothSocket} ready to start a secure * outgoing connection to this remote device on given channel. diff --git a/core/java/android/bluetooth/BluetoothServerSocket.java b/core/java/android/bluetooth/BluetoothServerSocket.java index a80f55c..c15852d 100644 --- a/core/java/android/bluetooth/BluetoothServerSocket.java +++ b/core/java/android/bluetooth/BluetoothServerSocket.java @@ -98,14 +98,16 @@ public final class BluetoothServerSocket implements Closeable { * @param encrypt require the connection to be encrypted * @param port remote port * @param mitm enforce man-in-the-middle protection for authentication. + * @param min16DigitPin enforce a minimum length of 16 digits for a sec mode 2 connection * @throws IOException On error, for example Bluetooth not available, or * insufficient privileges */ /*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, int port, - boolean mitm) + boolean mitm, boolean min16DigitPin) throws IOException { mChannel = port; - mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port, null, mitm); + mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port, null, mitm, + min16DigitPin); if(port == BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { mSocket.setExcludeSdp(true); } diff --git a/core/java/android/bluetooth/BluetoothSocket.java b/core/java/android/bluetooth/BluetoothSocket.java index 6ca6976..6302521 100644 --- a/core/java/android/bluetooth/BluetoothSocket.java +++ b/core/java/android/bluetooth/BluetoothSocket.java @@ -107,6 +107,7 @@ public final class BluetoothSocket implements Closeable { /*package*/ static final int SEC_FLAG_AUTH = 1 << 1; /*package*/ static final int BTSOCK_FLAG_NO_SDP = 1 << 2; /*package*/ static final int SEC_FLAG_AUTH_MITM = 1 << 3; + /*package*/ static final int SEC_FLAG_AUTH_16_DIGIT = 1 << 4; private final int mType; /* one of TYPE_RFCOMM etc */ private BluetoothDevice mDevice; /* remote device */ @@ -118,6 +119,7 @@ public final class BluetoothSocket implements Closeable { private final ParcelUuid mUuid; private boolean mExcludeSdp = false; /* when true no SPP SDP record will be created */ private boolean mAuthMitm = false; /* when true Man-in-the-middle protection will be enabled*/ + private boolean mMin16DigitPin = false; /* Minimum 16 digit pin for sec mode 2 connections */ private ParcelFileDescriptor mPfd; private LocalSocket mSocket; private InputStream mSocketIS; @@ -160,7 +162,7 @@ public final class BluetoothSocket implements Closeable { */ /*package*/ BluetoothSocket(int type, int fd, boolean auth, boolean encrypt, BluetoothDevice device, int port, ParcelUuid uuid) throws IOException { - this(type, fd, auth, encrypt, device, port, uuid, false); + this(type, fd, auth, encrypt, device, port, uuid, false, false); } /** @@ -173,11 +175,13 @@ public final class BluetoothSocket implements Closeable { * @param port remote port * @param uuid SDP uuid * @param mitm enforce man-in-the-middle protection. + * @param min16DigitPin enforce a minimum length of 16 digits for a sec mode 2 connection * @throws IOException On error, for example Bluetooth not available, or * insufficient privileges */ /*package*/ BluetoothSocket(int type, int fd, boolean auth, boolean encrypt, - BluetoothDevice device, int port, ParcelUuid uuid, boolean mitm) throws IOException { + BluetoothDevice device, int port, ParcelUuid uuid, boolean mitm, boolean min16DigitPin) + throws IOException { if (VDBG) Log.d(TAG, "Creating new BluetoothSocket of type: " + type); if (type == BluetoothSocket.TYPE_RFCOMM && uuid == null && fd == -1 && port != BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) { @@ -191,6 +195,7 @@ public final class BluetoothSocket implements Closeable { mType = type; mAuth = auth; mAuthMitm = mitm; + mMin16DigitPin = min16DigitPin; mEncrypt = encrypt; mDevice = device; mPort = port; @@ -223,6 +228,7 @@ public final class BluetoothSocket implements Closeable { mServiceName = s.mServiceName; mExcludeSdp = s.mExcludeSdp; mAuthMitm = s.mAuthMitm; + mMin16DigitPin = s.mMin16DigitPin; } private BluetoothSocket acceptSocket(String RemoteAddr) throws IOException { BluetoothSocket as = new BluetoothSocket(this); @@ -254,7 +260,7 @@ public final class BluetoothSocket implements Closeable { */ private BluetoothSocket(int type, int fd, boolean auth, boolean encrypt, String address, int port) throws IOException { - this(type, fd, auth, encrypt, new BluetoothDevice(address), port, null, false); + this(type, fd, auth, encrypt, new BluetoothDevice(address), port, null, false, false); } /** @hide */ @@ -276,6 +282,8 @@ public final class BluetoothSocket implements Closeable { flags |= BTSOCK_FLAG_NO_SDP; if(mAuthMitm) flags |= SEC_FLAG_AUTH_MITM; + if(mMin16DigitPin) + flags |= SEC_FLAG_AUTH_16_DIGIT; return flags; } |
