Commit Graph

228 Commits

Author SHA1 Message Date
Lorenzo Blasa
216c926ca5 Remove dead code in connection context store
Summary:
^
It was used by rsocket.

Reviewed By: fabiomassimo

Differential Revision: D36246038

fbshipit-source-id: 8bdc77d9e1ecf22402436e0102b5522ed36aff27
2022-05-12 09:16:13 -07:00
Lorenzo Blasa
63dde6e5cf Exceptions
Summary:
Flipper doesn really use library specific exceptions throughout, and that's OK.

Introducing SSLException as a replacement for the existing Folly Async Socket SSL exception.

This exception originally thrown by rsocket. Because we had rsocket and websockets using the same code, websockets were creating and throwing this same exception.

With rsocket gone, we can fully replace the usage of that exception. This is also needed as to decouple Flipper from folly async components.

Reviewed By: fabiomassimo

Differential Revision: D36245624

fbshipit-source-id: f5c97c5efe063280ce95be130008dee7f4e5d788
2022-05-12 09:16:13 -07:00
Lorenzo Blasa
afcc695edf Scheduler
Summary: Introduce a 'Scheduler' interface which will allow to decouple from the existing used Folly scheduler.

Reviewed By: fabiomassimo

Differential Revision: D36245587

fbshipit-source-id: 2f28bc1612e37ae53060a134d1c8059231fbc8ad
2022-05-12 07:37:11 -07:00
Lorenzo Blasa
1beae3230b Remove OpenSSL file BIO operations
Summary:
^
Change necessary when OpenSSL is compiled without STDIO for file operations. Basically, don't use the BIO file API's. Instead use in-memory BIO and do file operations manually.

UPDATE:

The changes were good, but have been simplified and fixed. A fixed was needed as to read and write the file in binary mode. This has no effect in POSIX systems but it does on Windows and this change was made for Windows. It meant that the BIO was incorrectly written to disk thus corrupting its content.

Changelog: Remove OpenSSL file BIO operations

Reviewed By: jknoxville

Differential Revision: D36060992

fbshipit-source-id: 21b30582dd0b32c24b8ba001d6993034d92de1da
2022-05-09 05:27:21 -07:00
Lorenzo Blasa
3826f2c8ef Refactor endpoint verification prior to connection
Summary:
^

There's a similar issue/request for Android. So, this change moves the code out from the FlipperKit into Flipper as to be able to reuse it.

Reviewed By: aigoncharov

Differential Revision: D35961745

fbshipit-source-id: aa255db582a7852dc06c2feaba389d1dac3b0f67
2022-05-03 11:24:17 -07:00
Lorenzo Blasa
c72088a137 Execute third-party prepare before configureCMake
Summary:
^

:android:third-party task, on ocassions, gets parallelised with the :configureCMake task resulting in build errors.

:configureCMake depends on dependencies being in-place and patched.

Our current setup was achieving this via setting these tasks as dependencies of the preBuild task.

Unfortunately, this seems not be a bullet-proof solution.

This patch aims to improve this situation by ensuring the tasks are executed before :configureCMake. Whatever happens first.

Changelog: Execute :third-party:prepare before :configureCMake task on Android

Reviewed By: passy

Differential Revision: D36001637

fbshipit-source-id: 6c53b6852e40e354337c0ac940b5bbad4ef83078
2022-04-28 06:36:42 -07:00
Lorenzo Blasa
2bafe32f2a Process certificate signing request in the right event loop
Summary:
To ensure that no deadlocks take place, it is important that there are no re-entrant calls from within the callbacks or event handlers.

For the most part, this was already the case. Event and message handlers run critical sections into a Folly event scheduler.

The only exception was the sendExpectResponse used during the certificate exchange. Once the response was received, the non-secure socket was disconnected.
The solution was to put that operation in the Folly event scheduler as it should've been from the beginning.

changelog: Certificate signing request response to be processed on the right event loop.

Reviewed By: fabiomassimo

Differential Revision: D35548148

fbshipit-source-id: cea2476ad66137f376acda66cdbc27801c0c47e1
2022-04-12 02:30:02 -07:00
Lorenzo Blasa
30becc1ced Remove RSocket
Summary:
^
Changelog: Remove rsocket dependency for Android

Reviewed By: aigoncharov

Differential Revision: D34418565

fbshipit-source-id: d2bfd6cede3c85709e252a8205525aa4595b4791
2022-02-25 02:33:22 -08:00
Lorenzo Blasa
c4f80a826e Remove RSocket
Summary:
^
Changelog: Remove rsocket references from xplat

Reviewed By: aigoncharov

Differential Revision: D34418118

fbshipit-source-id: bd49b9da119e3a2a1ce396d14e0dca73e1b9c692
2022-02-24 23:56:22 -08:00
Lorenzo Blasa
5993a748ba C++ WebSocket
Summary:
^

Changes include:
- C++ WebSocket integration
- Explicit asio namespace usage as namespace asio = websocketpp::lib::asio; this way we don't care if boost::asio or just asio is used in the end.

Reviewed By: javache

Differential Revision: D34388770

fbshipit-source-id: d0b3ee8ac687751ab1b93d483729eb2baccb8687
2022-02-23 04:23:07 -08:00
Lorenzo Blasa
c2f3607d03 remove rsocket fallback for mobile clients
Summary:
^
Note: this is already a working case. The difference is that if we are unable to establish a socket connection, we will not attempt to create one using rsocket.

Changelog: Removes rsocket-fallback for mobile clients

Reviewed By: nikoant

Differential Revision: D33655430

fbshipit-source-id: cb6f752f2d1354ab46d011b1f19c89520e1e7dd3
2022-02-15 04:56:17 -08:00
Lorenzo Blasa
c8c40bca17 openssl from prefab (google) (#3429)
Summary:
Pull Request resolved: https://github.com/facebook/flipper/pull/3429

Instead of downloading/patching/building openssl, use the prefab package prepared by Google.

changelog: Consume openssl from maven (prefab)

Reviewed By: passy

Differential Revision: D34143349

fbshipit-source-id: 0ca92be6628b1b27a59b3e4ad8278cf8fef6d5d8
2022-02-11 02:59:45 -08:00
Lorenzo Blasa
b3cf7e1ad1 C++ WebSocket client for Flipper
Summary:
Introducing a Flipper WebSocket client implemented in C++.
The requirement came from Spark AR (Skylight) as they have a macOS/Linux/Windows clients.

For reviewers:

- This is an implementation of the existing FlipperSocket interface. Effectively, the only type that needs to be reviewed is WebSocketTLSClient.

- BaseClient defined a base class for WebSocketClient and WebSocketTLSClient.

- WebSocketClient is a simplified version of WebSocketTLSClient as there's no TLS configuration.

Reviewed By: mweststrate

Differential Revision: D34081943

fbshipit-source-id: 619a83f5a6783a21069d0f5111d139bb180f9e97
2022-02-10 05:25:56 -08:00
Lorenzo Blasa
37b87b7653 ConnectionContextStore to expose API to retrieve store items path
Summary:
^

This change allow callers to retrieve the path of different store items some of which are used for connection authentication.

Reviewed By: aigoncharov

Differential Revision: D34081942

fbshipit-source-id: c6b8d3590993de6c48a36266a5c16f2caf9f5a93
2022-02-09 06:31:14 -08:00
Lorenzo Blasa
c793549d84 Release client if exists before establishing a connection
Summary:
The problem seems to be exclusive to Android emulators.

Bringing the emulator ON from a warm state brings the app from is previous state before shutting down. At this point there may have been a Flipper connection.

Flipper tries to connect and does so successfully replacing the previously, now dead connection.

The problem is that replacing that connection triggers the reconnect cycle as Flipper thinks the connection is dead and hence the reconnect loop initiates.
Changelog: Release an existing client before attempting a secure connection

Reviewed By: passy

Differential Revision: D34080726

fbshipit-source-id: 8185adb492dd4d9255fcea5874ca2e5b7fee0c84
2022-02-08 12:40:39 -08:00
Lorenzo Blasa
fd3d4d4efb Catch receiver errors
Summary:
This change adds a safety net for receivers that may throw an exception on invocation.

Without this change, the exception is logged but not shown in Flipper.

Reviewed By: nikoant

Differential Revision: D34001224

fbshipit-source-id: ca07d3dd006b277e306ecbc1c033845929a83f4c
2022-02-04 07:05:44 -08:00
Andrey Goncharov
a474a0c2f2 Fallback to RSockets if cert exchange fails
Summary:
Changelog: Fallback to RSockets if cert exchange fails even if the connection was successful.

Currently, we fallback to RSockets only if the connected is rejected.
It turns out that WS server does not reject connection from our RSocket client. Instead, it rejects the messages.
As result, requestSignedCertFromFlipper fails, but it never triggers the change of protocol.
With this diff we start evaluating if we need to change our protocol for every socket error.

Reviewed By: lblasa

Differential Revision: D33890235

fbshipit-source-id: f79b5c6992f01f8a93e0793e180a5cbd4a105619
2022-01-31 08:56:22 -08:00
Lorenzo Blasa
76a9b3d3ae Remove sendLegacyCertificateRequest
Summary:
Legacy certificate request is most likely deadcode by now. Remove it.

Changelog: Remove legacy certificate request

Reviewed By: antonk52

Differential Revision: D33707396

fbshipit-source-id: 47a410204bcd2ed843b716461df105ebc48264a6
2022-01-21 07:29:20 -08:00
Lorenzo Blasa
7579b81b97 Add a bit of defence checks as to minimise exception likelihood when no medium is known
Summary:
^

Changelog: Minimises the probability of throwing an exception if no exchange medium is known

Reviewed By: passy

Differential Revision: D33620655

fbshipit-source-id: e03e7fed0607c376add218ee98dcd2bd0f8880f1
2022-01-17 09:57:47 -08:00
Lorenzo Blasa
f3b0c82f4d Remove custom url_encode in favour of folly uri encode
Summary:
^
There was an issue for some characters in newer android API versions. One option was to fix our implementation, which can be done by casting to char to unsigned int before using std::isalnum.

But, do not duplicate existing functionality, used a solid implementation instead.

Changelog: Fixes an issue whereas the url encoding was incorrect for UTF-8

Reviewed By: mweststrate

Differential Revision: D33405760

fbshipit-source-id: e1c0a4da3dceb27e923b26d0ebfac091febeceb3
2022-01-05 04:06:43 -08:00
Andres Suarez
79023ee190 Update copyright headers from Facebook to Meta
Reviewed By: bhamodi

Differential Revision: D33331422

fbshipit-source-id: 016e8dcc0c0c7f1fc353a348b54fda0d5e2ddc01
2021-12-27 14:31:45 -08:00
Andrey Goncharov
6a8135af38 Initiate cert exchange when medium changes
Summary:
Changelog: Initiate cert exchange when medium changes

Fixes the following bug:

1. Start an iOS app with WWW cert exchange
2. Get cert (and fake serial of a virtual device)
3. Close app
4. Restart Flipper
5. Switch app to FS_ACCESS cert exchange
6. Start app

Expected result:
App re-initializes cert exchange to get a new serial of a real device

Current result:
App tries to connect securely using the previous fake serial of a virtual device. Flipper does not recognize it and refuses the connection.

Reviewed By: lblasa

Differential Revision: D33163798

fbshipit-source-id: 67126a9b562f2cb7cfe6521a46abf38b2699fb2d
2021-12-17 03:54:55 -08:00
Lorenzo Blasa
6a4a867f74 Enable WebSockets for Android
Summary: This change effectively prioritises WebSocket over RSocket connections for Android.

Reviewed By: passy

Differential Revision: D32490095

fbshipit-source-id: 836438970f0668521ca6e7fab6c106e77f951652
2021-12-02 02:28:50 -08:00
Lorenzo Blasa
a935ab8a6c Android Web Socket (#2978)
Summary:
Pull Request resolved: https://github.com/facebook/flipper/pull/2978

Flipper Android WebSocket provider and socket implementation

Reviewed By: ldelgadoj

Differential Revision: D31683510

fbshipit-source-id: d553a7fdee9451da742e9ea3e6e5b6a2c9417579
2021-11-08 09:22:48 -08:00
Lorenzo Blasa
b60eaf5fe6 Move the serialiser to Flipper
Summary:
This change moves the existing serialiser from FlipperWebSocket to FlipperURLSerializer.

The serialiser can be shared with Android as it no longer has any iOS dependencies.

Reviewed By: fabiomassimo

Differential Revision: D31571272

fbshipit-source-id: 0769b384d4143d7404fcfcf993d49dc1b00eeffd
2021-10-15 02:34:35 -07:00
Lorenzo Blasa
5944002c4c Base64 encoding using OpenSSL
Summary: This change adds a function to base64 encode. It is used to encode the CSR which gets added to the connection url.

Reviewed By: passy

Differential Revision: D31570706

fbshipit-source-id: 8356550fe87ae3ac6aae8616744a9339cf69b511
2021-10-14 11:23:29 -07:00
Lorenzo Blasa
bce2cdc316 Reduce logging verbosity for flipper socket provider switches
Summary: Change that removes log verbosity around socket provider switching.

Reviewed By: jknoxville

Differential Revision: D31395115

fbshipit-source-id: aece2facdf16c517522488c21496ea6a0eb50936
2021-10-05 10:57:06 -07:00
Lorenzo Blasa
3dacf5a7c9 WebSocket as default socket provider
Summary:
This change makes WebSockets the default for Flipper on iOS.

Having said that, we are introducing some logic to deal with clients connecting to older Flipper Desktop versions.

The mobile client will first attempt to connect via WebSocket with the Desktop. This connection can either be secure or insecure. If that fails, it will attempt to connect via RSocket.

Connection failure logic:
The mobile client will attempt to connect up-to 3 times via a WebSocket. If it fails to connect, then the socket provider is switched to RSocket.

As before, the mobile client will attempt to connect up-to 3 times via a RSocket. If it fails to connect, then the socket provider is switched back to WebSocket.

Process repeats until a successful connection is established.

Some logs that can be seen from iOS:

   2021-09-15 14:31:51.193503+0100 Sample[92026:92107440] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed
   2021-09-15 14:31:51.878257+0100 Sample[92026:92107440] [connection] nw_socket_handle_socket_event [C1.1:1] Socket SO_ERROR [61: Connection refused]
   2021-09-15 14:31:52.553729+0100 Sample[92026:92107440] [connection] nw_socket_handle_socket_event [C1.2:1] Socket SO_ERROR [61: Connection refused]
   2021-09-15 14:31:52.899511+0100 Sample[92026:92107442] [connection] nw_connection_get_connected_socket [C1] Client called nw_connection_get_connected_socket on unconnected nw_connection
   2021-09-15 14:31:52.899664+0100 Sample[92026:92107442] TCP Conn 0x600001d384d0 Failed : error 0:61 [61]
   2021-09-15 14:31:57.120120+0100 Sample[92026:92107439] [connection] nw_socket_handle_socket_event [C2.1:1] Socket SO_ERROR [61: Connection refused]
   2021-09-15 14:31:57.141785+0100 Sample[92026:92107439] [connection] nw_socket_handle_socket_event [C2.2:1] Socket SO_ERROR [61: Connection refused]
   2021-09-15 14:31:57.151604+0100 Sample[92026:92107483] [connection] nw_connection_get_connected_socket [C2] Client called nw_connection_get_connected_socket on unconnected nw_connection
   2021-09-15 14:31:57.154312+0100 Sample[92026:92107483] TCP Conn 0x600001d7c0b0 Failed : error 0:61 [61]
   2021-09-15 14:31:59.206079+0100 Sample[92026:92107483] [connection] nw_socket_handle_socket_event [C3.1:1] Socket SO_ERROR [61: Connection refused]
   2021-09-15 14:31:59.236824+0100 Sample[92026:92107483] [connection] nw_socket_handle_socket_event [C3.2:1] Socket SO_ERROR [61: Connection refused]
   2021-09-15 14:31:59.251927+0100 Sample[92026:92107439] [connection] nw_connection_get_connected_socket [C3] Client called nw_connection_get_connected_socket on unconnected nw_connection
   2021-09-15 14:31:59.255963+0100 Sample[92026:92107439] TCP Conn 0x600001d1c210 Failed : error 0:61 [61]
   2021-09-15 14:32:01.291303+0100 Sample[92026:92107439] [connection] nw_socket_handle_socket_event [C4.1:1] Socket SO_ERROR [61: Connection refused]
   2021-09-15 14:32:01.312406+0100 Sample[92026:92107439] [connection] nw_socket_handle_socket_event [C4.2:1] Socket SO_ERROR [61: Connection refused]
   2021-09-15 14:32:01.323099+0100 Sample[92026:92107483] [connection] nw_connection_get_connected_socket [C4] Client called nw_connection_get_connected_socket on unconnected nw_connection
   2021-09-15 14:32:01.326028+0100 Sample[92026:92107483] TCP Conn 0x600001d7c0b0 Failed : error 0:61 [61]
   flipper: Failed to connect with the current socket provider
   flipper: Use legacy socket provider
   flipper: FlipperClient::onConnected

Reviewed By: passy

Differential Revision: D30900471

fbshipit-source-id: 7c242ad71306803b050d0174fc22696bb74fdba5
2021-09-23 05:22:23 -07:00
Lorenzo Blasa
10e97a7e98 Fixes an error with the handled flag for certificate exchange
Summary:
This change fixes a bug with the handled flag during the certificate exchange process.

Explanation:
handled was passed by reference as &handled
Once the function goes out of scope then the reference, well, it just becomes invalid (undefined behaviour)
In some cases, it appears as 'handled' because the reference is invalid and it happens to be 'true'.

Changelog: Fixed an issue where clients would randomly not connect to Flipper. Please update FlipperKit to 0.110.0 to apply the fix: https://fbflipper.com/docs/getting-started/react-native#using-the-latest-flipper-sdk

Reviewed By: mweststrate

Differential Revision: D31017592

fbshipit-source-id: c087a769fa23de1acfd3c198b4db4d6ccdb2be90
2021-09-17 08:23:18 -07:00
Lorenzo Blasa
1390bf4a33 Define alt ports for web socket connections
Summary:
The changes below add the notion of alternative ports to Flipper.

These alternative ports are meant to and will be used to connect via WebSocket instead of RSocket. The name does not suggest that as to make as generic as possible so that they can be reused for different purposes in the future.

Reviewed By: passy

Differential Revision: D30898874

fbshipit-source-id: 5eed8c61b41b502c859192aaac59c284b7b36228
2021-09-15 07:59:55 -07:00
Pascal Hartig
da9511a5bf Fix CI build for Android (#2836)
Summary:
I've been really sweating about this one. It looks like Google now removed NDK 21 as it's too old. However, we've been struggling with the upgrade because OpenSSL was built against an old version of the NDK/glibc/LLVM/some other stuff.

I've now managed to create an OpenSSL distribution for 1.1.1k (we had 1.1.0h before) that seems to build with this after some small modifications.

This seems to do the trick, but I wouldn't be shocked if we found some more incompatibilities further down the line.

Pull Request resolved: https://github.com/facebook/flipper/pull/2836

Test Plan:
- Locally: `./gradlew :tutorial:installDebug`. Builds, starts up. Cool.
- Public GitHub CI: Happy.
- Circle CI: Only triggers post-land. We'll see. But the setup is simple, so hopefully it should work there, too.
- Internal CI: Waiting for signal.

Reviewed By: fabiomassimo

Differential Revision: D30839209

Pulled By: passy

fbshipit-source-id: efe599f28cc0edfdf2149f905c3483555239edc0
2021-09-09 08:46:59 -07:00
Lorenzo Blasa
ef831f346d Socket provider
Summary:
Abstract the socket creation from FlipperConnectionManagerImpl. Instead, use FlipperSocketProvider.

There's a default provider which will always return RSocket sockets. This provider can be changed and thus can return other implementations.

Reviewed By: fabiomassimo

Differential Revision: D30396322

fbshipit-source-id: 0583865376809260b0240e5bd653d73f2fa514b1
2021-08-23 03:17:47 -07:00
Lorenzo Blasa
8e2a839f9d Clear event handler on deallocation
Summary:
It's just bad that we give a naked pointer of the connection manager to other instances. If the connection manager gets deallocated, the instances keeping a pointer to it are doomed to crash.

This change creates a wrapper on top of the pointer that can be freely shared. On deallocation, the shared wrapper gets invalidated.

Reviewed By: timur-valiev

Differential Revision: D30398466

fbshipit-source-id: 8f228e7fbaebc0ea28921409de071b58bbb69f1e
2021-08-19 04:42:45 -07:00
Lorenzo Blasa
a9c6351cf0 Define boundaries between FlipperConnectionManager and RSocket on the client side
Summary:
These changes abstract RSocket from FlipperConnectionManagerImpl.

This is achieved by defining FlipperSocket.

FlipperConnectionManagerImpl uses instances of FlipperSocket and RSocket is now contained within FlipperRSocket which implements FlipperSocket.

On the changes to follow, FlipperConnectionManagerImpl will no longer reference FlipperRSocket directly thus fully abstracting the socket implementation in use.

For reviewers:
- All of the RSocket code now lives in FlipperRSocket.
- Main changes are in FlipperConnectionManagerImpl. Lambdas are used to deal with events and message handling.
- There's some very minimal serialisation additions for payloads.

Reviewed By: jknoxville

Differential Revision: D30341076

fbshipit-source-id: 54bb4878967378490710c05f729cdd7f4cf08bb8
2021-08-17 05:27:34 -07:00
Lorenzo Blasa
43179a7ef4 ConnectionContext to expose client certificate in PKCS #12 format
Summary:
RSocket plays nicely with Folly and OpenSSL.

Flipper WebSocket-client uses SocketRocket which instead relies on Apple's NSInputStream and NSOutputStream types.

SSL options can be set to secure the communication in both.

Unfortunately, Apple APIs are a bit limited on the supported cryptographic formats it can accept as arguments.

SSL options require the client certificate to be set in PKCS #12 format, contrary to the existing PEM format used by RSocket.

This change adds a method to the ConnectionContext which converts and saves the client certificate in PKCS #12 format.

The method is always expected to succeed as it will only be called once a valid client certificate is available. An unlikely failure will raise an exception.

Reviewed By: fabiomassimo

Differential Revision: D30074334

fbshipit-source-id: 91a475d080569cc339b649c7302b1f28793c7de7
2021-08-04 06:34:18 -07:00
Aleksandr Sasha Sergeev
dbd52d1cfe Fix deadlock in FlipperClient
Summary:
This diff fixes deadlock that happens on mutex [FlipperClient::mutex_](https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/xplat/sonar/xplat/Flipper/FlipperClient.h?commit=9eba9f832dfb648788d4c0e6ae05712e30a59a21&lines=113).

Steps that cause a deadlock:
1. Mutex is locked at [FlipperClient.cpp:170](https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/xplat/sonar/xplat/Flipper/FlipperClient.cpp?commit=750ee132616cd3c470d8d091532a853e6b44f6d6&lines=170)
2. `FlipperConnectionImpl::call` executed at [FlipperClient.cpp:237](https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/xplat/sonar/xplat/Flipper/FlipperClient.cpp?commit=750ee132616cd3c470d8d091532a853e6b44f6d6&lines=237)
3. `FlipperConnectionImpl::call` eventually calls `FlipperClient::getPlugin()` (see fullstacktrace below) which is trying to lock the same [FlipperClient::mutex_](https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/xplat/sonar/xplat/Flipper/FlipperClient.h?commit=9eba9f832dfb648788d4c0e6ae05712e30a59a21&lines=113) as in step 1.

Full stacktrace: P420350989. Mutex is locked in frame #43 and attempted to be locked in frame #6.
More details: T92341964

Solution: unlock the mutex before calling `FlipperConnectionImpl::call` at [FlipperClient.cpp:237](https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/xplat/sonar/xplat/Flipper/FlipperClient.cpp?commit=750ee132616cd3c470d8d091532a853e6b44f6d6&lines=237)

Reviewed By: jknoxville

Differential Revision: D28918093

fbshipit-source-id: 06c7841740a70e117dc5f767f9d5852149974f7f
2021-06-07 11:20:51 -07:00
Pritesh Nandgaonkar
b0b49e1098 Handle CN greater than 64 character length
Summary:
This diff handles the case when the CN(subject Common) is greater than 64. CN in our case is an appId, which can be greater than 64 length. Have a look at this [issue](https://fb.workplace.com/groups/flippersupport/permalink/1142641402883183/). In this issue the appID was  `com.facebook.internal.focusrepresentativeapp.development.localDevelopment`

See this [discussion on stack](https://unix.stackexchange.com/questions/234324/openssl-self-signed-certificate-with-a-common-name-longer-than-64-bytes) overflow to understand about the limit of 64.

This diff checks the length first and then defaults the CN to be "com.flipper".

Reviewed By: jknoxville

Differential Revision: D28807389

fbshipit-source-id: ca01ccd5d31a51826df49f943414c42bf902be89
2021-06-02 03:51:57 -07:00
Andres Suarez
39172f6413 Apply clang-format
Reviewed By: igorsugak

Differential Revision: D28477074

fbshipit-source-id: f15dfc45b9fb30c661ebe2899cd882676d0fdf2a
2021-05-20 21:23:41 -07:00
Pritesh Nandgaonkar
62863c8fe5 Change the logic to check the cert exchange is needed or not
Summary:
It has been seen [here](https://fb.workplace.com/groups/flippersupport/permalink/1094276434386347/) that the user's app sandbox can be in a state where it might not have the device id information, but other app certificates. This causes the issue of "Timed out waiting for unknown device".

We get the deviceid from flipper into app's sandbox when cert exchange happens. So if we don't have the device id information, we can again redo the cert exchange to get the sandbox in a state where flipper connects. Thus I updated the logic of `hasRequiredFiles` which checks the required files for cert exchange.

Reviewed By: mweststrate

Differential Revision: D27265693

fbshipit-source-id: ccf311f4728837ee9385c95c38f94c9c93380feb
2021-03-24 13:13:05 -07:00
Andrew Gallagher
c70d97accf Add missing <sstream> includes to various sources
Summary: This gets exposed by using glog from tp2 for fbcode platform builds.

Reviewed By: aniketmathur

Differential Revision: D26515732

fbshipit-source-id: 7bb4b20a43702f9096bd6014278faffb5029712f
2021-02-21 08:48:52 -08:00
Andres Suarez
731e39445f Apply clang-format update fixes
Reviewed By: igorsugak

Differential Revision: D25861849

fbshipit-source-id: 840dc1061e557717c7f9ffcccbc09c24b96b78e0
2021-01-10 10:07:30 -08:00
John Knox
07212ec8e0 Fix memory leak
Summary:
Fixes https://github.com/facebook/flipper/issues/1561

Thanks to rdunlop for finding this!

Reviewed By: cekkaewnumchai

Differential Revision: D24923154

fbshipit-source-id: f4904730aecb9ecd7f391b5e1dcabc6a6db038cf
2020-11-17 03:59:59 -08:00
Michel Weststrate
ffbccf2331 Fixed more missing namespaces
Summary: See the previous diffs, we pollute the global namespace here and there. Found some more missing namespace wrappers. Tried to wrap `FlipperStep` as well, which passed tests but gave weird linking errors in Wilde, so reverted that part (the name is not very ambiguous anyway)

Reviewed By: cekkaewnumchai

Differential Revision: D24193109

fbshipit-source-id: 111c479e421fdb321e898f948586229f30a7d777
2020-10-13 03:06:38 -07:00
Marco Marinangeli
05f4c0f54f Fix ConnectionContextStore namespaces (#1581)
Summary:
It should fix this [issue](https://github.com/facebook/flipper/issues/1565)

I'm not a C++ expert. Any kind of comment or advice is very appreciated.

Pull Request resolved: https://github.com/facebook/flipper/pull/1581

Reviewed By: passy

Differential Revision: D24189366

Pulled By: mweststrate

fbshipit-source-id: cc93fe36036d557b63c9c1baa62ed9bcc14c08ab
2020-10-13 03:06:38 -07:00
Pritesh Nandgaonkar
3c3d76be60 Send flipperstate to cert downloader
Summary: Add flipperstate to the cert downloader.

Reviewed By: jknoxville

Differential Revision: D23172851

fbshipit-source-id: f0eb23ec709d656918831c2ee82a6ddb426596e5
2020-08-18 17:16:43 -07:00
Pritesh Nandgaonkar
f626925443 Upload/Download certs zip from Flipper
Summary:
This diff adds upload and download logic for certs. It makes changes on both Flipper Client and Desktop side. With this we enable cert exchange through WWW.

Next Diffs:

1) Add Flipper state in cert provider for more debug data
2) Tests

Reviewed By: jknoxville

Differential Revision: D23092706

fbshipit-source-id: e576253606b64b62848b70203db7e09a3bd77fd9
2020-08-17 06:51:52 -07:00
Pritesh Nandgaonkar
293de19c2b Add toggle in the settings for cert exchange medium
Summary:
This diff adds a toggle setting in wilde which will enable certificate exchange through www.
Right now it just sends the information about which medium to be used for cert exchange to Flipper JS and its client side. But its implementation is not done yet.

### Flow for Wilde

Whenever user changes the setting(or when user logs out) we set the state of exchange medium and accordingly set/reset authtoken. Note at no given point we remove already existing certificates.

### Context for OSS

With this diff we introduce another way to do certificate exchange. Before this diff, we did certificate exchange by accessing the file system of app. But it turns out it's not possible to do that in applications signed by enterprise certs. Thus with this diff one can write their FlipperKitCertificateProvider and fetch the certificate from WWW.

Reviewed By: jknoxville

Differential Revision: D22896320

fbshipit-source-id: 55aef7028a62e71ba9c02f9f79acaab41d09c0c6
2020-08-12 04:44:18 -07:00
Alex Dickson
0065ddedd7 Provide explicit failure reason when connection can't be established
Reviewed By: jknoxville

Differential Revision: D22999785

fbshipit-source-id: 301ec8230a89ee9dbc82d006fa6520d8bac80b3e
2020-08-10 04:31:12 -07:00
Michel Weststrate
b9c3d99f44 Stop connecting disabled background plugins
Summary:
Background for this diff: https://fb.quip.com/KqEfAlKYlgme

Some plugins don't respect that stuff (livefeed and graphql), but for others it seems to work fine.

This is just a PoC, there are some present bugs concerning the combination of selecting and bg plugins

Questions to investigate:

- [x] make sure that LiveFeed and GraphQL disconnect properly. There might be more plugins that need that
- [x] verifiy that we don't loose one of the original goals of background plugins, e.g. QPL collecting and sending data from device start. Does this still work as intended after this change?
- [x] how can we observe / measure improvements? Are dev builds more responsive after this? Is the layout inspector smoother for example because no QPL plugins are interweaved?
- [x] how is forward and backward compatibility?
   - If Flipper is updated, but device not: No change I think, as getBackgroundPlugins() will return an empty set, and background plugins are initiated as usual, so old behavior
  - If device is updated, but Flipper not, background plugins won't be started until they are selected. This is a degradation, but hopefully explainable.
- [x] Verify QPL buffer is not unbounded
- [x] Share architecutre changes with team

For Graphql updates: D20943455

Added runtime stats to monitor network traffic (sadly had to redo that since scuba couldn't handle the data format used at first, so probably will hold of landing this diff a week to make sure we can see some effects)

Follow up work:

[x] wait until we released the stat tracking before we release this, to be able to measure the effect?
[x] make sure graphql fix lands
[ ] use side effects abstraction
[ ] fix other background plugins (android only) or fix it in a generic way:

{F234394286}

Changelog: Background plugins will no longer receive a Flipper connection if they are disabled. This should significantly reduce the overall load of Flipper both on the device and desktop when unused plugins are disabled used, which could otherwise generate 10MB/s of network traffic certain scenarios. All plugins *should* be able to handle to this gracefully, but since this is quite a fundamental change, reach out to the Flipper team when in doubt!

Reviewed By: jknoxville

Differential Revision: D20942453

fbshipit-source-id: b699199cb95c1b3e4c36e026b6dfaee7d1652e1f
2020-04-27 09:46:13 -07:00
John Knox
eb1981f9f2 Don't log when insecure connection fails
Summary:
Context: https://fb.workplace.com/groups/flippersupport/permalink/803808233433170/

A similar change was done earlier with the secure connection route.
This does the same for the insecure route.

Reviewed By: mweststrate

Differential Revision: D21227196

fbshipit-source-id: 844cb674b5b16033977f451bbc3d8bbc69732273
2020-04-24 05:52:14 -07:00