Commit Graph

275 Commits

Author SHA1 Message Date
Lorenzo Blasa
165a989cc6 Use setProcessState
Summary:
`setProcessState` does some adjusting to PATH. This was only ever done for Electron.

This change moves that functionality to FlipperServerImpl which is the one what orchestrates. By doing this, flipper server also benefits from getting these adjustments.

Reviewed By: antonk52

Differential Revision: D46836659

fbshipit-source-id: f98291d320cf9b7f3808223af8745c068b1318ce
2023-06-19 04:05:07 -07:00
Lorenzo Blasa
8f70cf14a4 Kill server after 30 seconds
Summary: Bring timeout from 15min to 30seconds.

Reviewed By: passy

Differential Revision: D46726959

fbshipit-source-id: cae1fdd4668fc5237ad0f187385f3a63a51c4797
2023-06-14 09:59:21 -07:00
Lukas Kurucz
279a9e6b52 fix: prefixed plugin package name (#4811)
Summary:
When distributing plugin over Marketplace. Currently there is an issue with downloading a plugin to `tmp` folder if the plugin `packageName` starts with `company-prefix/flipper-plugin-name`. It would throw `ENONET` error while trying to stream the response data into `tmp` folder.

## Changelog

- add support for prefixed plugin package names (`shopify/flipper-plugin-name`,...)

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

Test Plan: - Try install a plugin from Marketplace which has `/` in the plugin `package.json` `name`.

Reviewed By: lblasa

Differential Revision: D46679195

Pulled By: passy

fbshipit-source-id: f330896dae9da7cbe101b1c6d7ed07667fb7ae0a
2023-06-13 03:53:18 -07:00
Lorenzo Blasa
0db4e99aff Track bootstrap diagnostics
Summary:
^

In addition to logging to the console bootstrap performance metrics, track these events to scuba as well.

Reviewed By: aigoncharov

Differential Revision: D46648876

fbshipit-source-id: 191704c13158884bb8cfbca614a23f2a64f1fd93
2023-06-13 02:45:57 -07:00
Lorenzo Blasa
146a5cf666 Move server started analytics
Summary: This is a better place as it takes place once the server starts listening.

Reviewed By: passy

Differential Revision: D46558350

fbshipit-source-id: f586defecc8e16d8f0b285615803662d8b6b75fb
2023-06-08 11:03:44 -07:00
Lorenzo Blasa
bd809853e7 Fixes an issue with client queries and rsocket
Summary: This is necessary as we map from the protocol medium to our internal medium representation.

Reviewed By: mweststrate

Differential Revision: D46557431

fbshipit-source-id: 617307cd860e1c7e230be2441c06417c44af580e
2023-06-08 07:24:32 -07:00
Lorenzo Blasa
85f5c6f893 Close server if no clients are connected
Summary: If after 15min there are no connected clients, close flipper server.

Reviewed By: antonk52

Differential Revision: D46519563

fbshipit-source-id: c3396ed8987be8ca7075c644734793e4ebceba18
2023-06-07 10:46:15 -07:00
Lorenzo Blasa
7dc978c3d3 Remove processDevices logs
Summary: These are no longer that useful and can be quite verbose, remove.

Reviewed By: antonk52

Differential Revision: D46516093

fbshipit-source-id: e6c3a546d379ca20ff8757fdc3feaa11bf0788a0
2023-06-07 06:59:31 -07:00
Lorenzo Blasa
98f376ec69 Use auth token when connecting to existing server from Electron
Summary:
All clients need to provide an authentication token before connecting. Electron app is no different.

This change adds the authentication token whether we are connecting over UDS or TCP.

Before this change, if Flipper server was already running, launching the Electron app would look similar to this:

{F1016961594}

Reviewed By: antonk52

Differential Revision: D46418758

fbshipit-source-id: f00ffe675df78403d5921250e3e9ed9331a55bde
2023-06-05 05:26:10 -07:00
Lorenzo Blasa
90240f4186 Move auth token to the default directory for crypto related files
Summary:
Used to be stored in the static directory as it was meant to be used by connecting clients.

This is still the case, except that there may be different clients with different static directories all trying to connect to the same server.

Instead, store the authentication token with the other crypto files, in the user's home directory.

By doing this, all clients, as long as they have access to the local filesystem, can use it.

Reviewed By: mweststrate

Differential Revision: D46418639

fbshipit-source-id: 181e98346d86ad7b3fc1d0005aca3350deb6df32
2023-06-05 05:26:10 -07:00
Lorenzo Blasa
80c201b10f Add localhost as a valid host
Summary: ^

Reviewed By: passy

Differential Revision: D46393661

fbshipit-source-id: eeaa0971a747d6435a10c3eb27969bb452cd73a7
2023-06-02 09:35:32 -07:00
Andrey Goncharov
e8e1a32e48 Back out "Update adbkit and logcat to maintained librarys"
Summary:
Original commit changeset: 2a23c0eaa12f

Original Phabricator Diff: D45569652

The new lib causes weird log parsing https://fb.workplace.com/groups/flippersupport/permalink/1629943924152926/

Reviewed By: LukeDefeo, passy

Differential Revision: D46390961

fbshipit-source-id: 7c9d0ca7fff2d9cb1ac1a309710f2348233a3471
2023-06-02 08:10:47 -07:00
Lorenzo Blasa
828d56f617 Kill PortForwardingApp on exit
Summary:
I noticed we were not killing the PortForwardingApp on exit.

This is not ideal.

So, use an exit hook to kill the app.

Reviewed By: passy

Differential Revision: D46392855

fbshipit-source-id: e2b75f76c9dfab0ff46df3ad2c94a1a523154b2a
2023-06-02 07:55:56 -07:00
Lorenzo Blasa
2f9e633fad Medium refactoring
Summary:
Simplifies medium usage. Clients report this value as an integer. Internally, we transform this integer as type (a set of valid strings).

Instead of transform this value in different places, do it once when the client query is received.

Reviewed By: antonk52

Differential Revision: D46358024

fbshipit-source-id: ecd2b6c6ccbe7c38787a89d4e2f81930c7b91864
2023-06-02 03:59:15 -07:00
Andrey Goncharov
94cb8935b2 Fix adb connection
Summary: On my mac localhost resolves to an IP6 address by the new adb lib. This should fix it.

Reviewed By: LukeDefeo

Differential Revision: D46314612

fbshipit-source-id: 3771efd2c6b79fe9ae9851ce4aac35bcede28847
2023-05-31 09:25:55 -07:00
Andrey Goncharov
1d595862b5 Fix e2e test
Summary: This time for real

Reviewed By: elboman

Differential Revision: D46279935

fbshipit-source-id: a639a6abafa7267ef4539c183323a5c96674e202
2023-05-30 09:47:19 -07:00
Andrey Goncharov
53a5939d68 Add one more fallback for the adb path
Summary: It seems that adb path has changed on the jest-e2e side. That might case the flipper e2e test failure. With this fallback we have granular control of the path.

Reviewed By: antonk52

Differential Revision: D46278512

fbshipit-source-id: 97310459de54eeb003eefb3a3ff06af8b13bebae
2023-05-30 09:47:19 -07:00
Lorenzo Blasa
27909e8296 Track CSR processing
Summary:
Need to answer:

- Certificate exchange success rate, fails and errors a day per OS and device type.

Reviewed By: antonk52

Differential Revision: D46221301

fbshipit-source-id: 03c6993aa15f56fdf98a7abd57d00b2af0e9ce1a
2023-05-26 08:02:12 -07:00
Lorenzo Blasa
f25591580c Track insecure connection attempts
Summary: Same as previous diff but for plain socket.

Reviewed By: antonk52

Differential Revision: D46220933

fbshipit-source-id: 235ca860891b8514dd0d743d32fe85f15a2cdd7e
2023-05-26 08:02:12 -07:00
Lorenzo Blasa
135d3e3aa8 Track secure connection attempts
Summary: Same as previous diff but for TLS attempts.

Reviewed By: antonk52

Differential Revision: D46220897

fbshipit-source-id: 9495c39edffbdebe0ba21ec7320b63bad8759dde
2023-05-26 08:02:12 -07:00
Lorenzo Blasa
8065313949 Track app connections
Summary:
Need to answer:

- How many app connections a day/week?
- How many connections a day/week per app?
- How many connections a day/week per os?
- How many connections a day/week over WWW exchange?
- How many connections a day/week over FS exchange?
- How many connections over a device?
- How many connections over a simulator?

Reviewed By: antonk52

Differential Revision: D46220581

fbshipit-source-id: 6783f49b59cba91cd04625044314973d98cef301
2023-05-26 08:02:12 -07:00
Lorenzo Blasa
e7806d5be7 Track server start
Summary:
Need to answer:

- How many starts a day over time

Reviewed By: antonk52

Differential Revision: D46219995

fbshipit-source-id: bffaeadf684a2d34c6e145784c5a86dbaf5f532a
2023-05-26 08:02:12 -07:00
Lorenzo Blasa
29510f66c8 Track proxy errors
Summary:
Need to answer:
- Proxy errors rate over time

Reviewed By: antonk52

Differential Revision: D46219927

fbshipit-source-id: 1ad8cc60303ed3aa34828b9ff87009ff7754a146
2023-05-26 08:02:12 -07:00
Lorenzo Blasa
6936cb34ac Track socket already in use
Summary:
Some times the socket can already be in use by an existing process. Track it as to quantify how likely this is found in production. May remove later.

Need to answer:
- Socket already in use rate over time

Reviewed By: antonk52

Differential Revision: D46219768

fbshipit-source-id: 27da82cddb707f729a1d43079e84c221bb544a82
2023-05-26 08:02:12 -07:00
Lorenzo Blasa
694f6f284e Define a tracker interface and replace auth token tracking
Summary:
Define the tracker interface and replace the existing authentication token verification tracking.

Subsequent diffs will add analytics for remaining connectivity areas.

Need to answer:
- No tokens rate over time
- Unable to verify tokens rate over time

Reviewed By: antonk52

Differential Revision: D46219661

fbshipit-source-id: dfc41cae664bc1ef211d312990120111fca3808b
2023-05-26 08:02:12 -07:00
Lorenzo Blasa
4704c177ec Check if server is already listening
Summary:
Right now, this simply avoids trying to create a server instance if one appears to be already running.

In a future change, we may decide to kill the existing instance and replace it with a new one.

But, in this case, running this as is will be useful as it will provide the connection URL with the auth token.

Also remove flipper server dependency from finding installation. In this case, we don't need it and can use `os.getPlatform()` instead.

Reviewed By: antonk52

Differential Revision: D46144843

fbshipit-source-id: 2922843b916d37e0126e43ae65a622f87a6920ec
2023-05-24 06:50:05 -07:00
Andrey Goncharov
d078a89e83 Skip token verification if a special env variable is passed
Summary: Recently , we started verifying a special token for every websocket connection. It made e2e tests fail. We are going to use this bypass flag in jest e2e envs.

Reviewed By: lblasa

Differential Revision: D46025343

fbshipit-source-id: c2e6e0b561286fb8b571565243a45cdfb56a54a9
2023-05-19 10:19:10 -07:00
Andrey Goncharov
898e9c3b07 Update adbkit and logcat to maintained librarys
Summary:
We were using an old unmaintained/abandonned library for communicating with adb server https://github.com/openstf/adbkit

This was giving me issues i couldnt figure out when running flipper server.

There is a popular fork written in typescript here https://github.com/DeviceFarmer/adbkit but it uses blue bird for promises.

There is a fork of the fork here which i have chosen to use which is the same api as above but with es6 promises, https://github.com/UrielCh/adbkit.

Both forks have a slightly different api to the original. In the original library there was a single client and any command directed at a particular device had a serial as the first argument

In the new libraries you create a DeviceClient where the serial is baked in and you don't need to supply this argument every time

allow-large-files

Reviewed By: lblasa

Differential Revision: D45569652

fbshipit-source-id: 2a23c0eaa12feaebdccadb3d343e087c0d5708d5
2023-05-18 09:56:41 -07:00
Lorenzo Blasa
7386608a53 Track token validation
Summary: ^

Reviewed By: antonk52

Differential Revision: D45864358

fbshipit-source-id: c043555c5dd3050503115a22982162ec16aba40f
2023-05-16 04:32:47 -07:00
Lorenzo Blasa
c6d5eb3334 Flipper as PWA
Summary:
^

Reference: https://docs.google.com/document/d/1flQJUzTe4AuQz3QCpvbloQycenHsu7ZxbKScov7K7ao

Reviewed By: passy

Differential Revision: D45693382

fbshipit-source-id: 5a2e6c213a7e7e2cf9cd5f3033cff3e5291a2a92
2023-05-16 04:32:47 -07:00
Lorenzo Blasa
a96caacb2b EnvironmentInfo as argument to start server
Summary:
Clean initialisation by passing down the environment info to start server.

(Also rename dir to path as that's the name used in other places)

Reviewed By: passy

Differential Revision: D45731751

fbshipit-source-id: a60fdd49c567fc312d1f8da72db3a46a0828c140
2023-05-11 04:10:16 -07:00
Lorenzo Blasa
fdd1a9e887 Use different location for token depending on build type
Summary:
For Electron builds, use the same directory as certificates and keys.

For headless builds, then use the static directory.

Reviewed By: antonk52

Differential Revision: D45728515

fbshipit-source-id: 55a3b143a9289fed23e57cbf6b701a5e48d27332
2023-05-10 04:35:17 -07:00
Lorenzo Blasa
b94f6b6152 Set the right environment info for headless builds
Summary: The isHeadlessBuild flag was not properly set.

Reviewed By: antonk52

Differential Revision: D45728435

fbshipit-source-id: 3616c4358114d4f3d96372766dabf48b27b44333
2023-05-10 04:35:17 -07:00
Lorenzo Blasa
238f40f55d Mandate auth token to connect over TCP
Summary:
Until now, launching flipper-server with TCP would accept any incoming connection as long as it comes from the same origin (localhost) using web socket host origin verification.

This is not entirely secure as origin can be spoofed with tools like curl.

Our team created a security review and a proposal was written:
https://docs.google.com/document/d/16iXypCQibPiner061SoaQUFUY9tLVAEpkKfV_hUXI7c/

Effectively, Flipper can generate a token which is then used by the client to authenticate.

This diff contains the changes required to generate, obtain, and validate authentication tokens from clients connecting to flipper over TCP connections.

The token itself is a JWT token. JWT was chosen because it is a simple industry standard which offers three features which can immediately benefit us:

- Expiration handling. No need for Flipper to store this information anywhere.
- Payload. Payload can be used to push any data we deem relevant i.e. unix username.
- Signing. Signed and verified using the same server key pair which is already in place for certificate exchange.

Additionally, the token is stored in the Flipper static folder. This ensures that the browser and PWA clients have access to it.

Reviewed By: mweststrate

Differential Revision: D45179654

fbshipit-source-id: 6761bcb24f4ba30b67d1511cde8fe875158d78af
2023-05-05 07:52:13 -07:00
Andrey Goncharov
7609a4cb38 Downgrade log severity for log listener start failures
Reviewed By: mweststrate

Differential Revision: D44333037

fbshipit-source-id: 87f5bec31cb7bf38306f0d48c891ad84d8c0121f
2023-03-23 05:27:52 -07:00
Andrey Goncharov
a4fcd68c19 Downgrade adb-logcat unexpected shutdown event from error to warning
Reviewed By: mweststrate

Differential Revision: D44089920

fbshipit-source-id: 6d258e507e80b2c9f2ac08f743cdb9fe49b702f2
2023-03-15 06:33:11 -07:00
Pascal Hartig
043f5296d0 Demote active iOS device error
Summary: The error is non-fatal as it's already handled and it's not actionable by the Flipper team.

Reviewed By: lawrencelomax

Differential Revision: D44054514

fbshipit-source-id: c54c7e935374a1c97e54a5da4daaa3f26b236023
2023-03-14 05:16:52 -07:00
Andrey Goncharov
3d70020f40 Downgrade user error to warning
Summary: We can't do much if a phone is not setup properly

Reviewed By: lblasa

Differential Revision: D43980508

fbshipit-source-id: 5baf82ae36030b81c7cc90bcf6a5de2af9304fb3
2023-03-10 08:32:24 -08:00
Pascal Hartig
cfcad76e74 Demote Xcode select error to warning
Summary: This is firing regularly when people have a broken local setup.

Reviewed By: lawrencelomax

Differential Revision: D43834469

fbshipit-source-id: 1fbc2cf52f93046984e9846f8aed931106542b03
2023-03-06 04:54:36 -08:00
Andrey Goncharov
39b14fc428 Track socket usage during file download
Summary: Should help to investigate further issues like https://fb.workplace.com/groups/flippersupport/permalink/1577911229356196/

Reviewed By: passy

Differential Revision: D43692927

fbshipit-source-id: 723b051f748946c89ece85fb6c11c40705196fe4
2023-03-01 05:26:00 -08:00
Andrey Goncharov
618f58b390 Verbose logging for iOS cert exchange
Summary: Helps debugging cert exchange problems.

Reviewed By: lawrencelomax

Differential Revision: D43495107

fbshipit-source-id: 499c08ec6ab15a351d74673f0a5edf9abe5af1b1
2023-02-22 04:42:34 -08:00
dependabot[bot]
df5ddf01a6 Bump js-base64 from 3.7.4 to 3.7.5 in /desktop (#4519)
Summary:
Bumps [js-base64](https://github.com/dankogai/js-base64) from 3.7.4 to 3.7.5.
<details>
<summary>Commits</summary>
<ul>
<li><a href="7e790b799e"><code>7e790b7</code></a> version 3.7.5</li>
<li><a href="f729053682"><code>f729053</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/dankogai/js-base64/issues/167">https://github.com/facebook/flipper/issues/167</a> from ctomacheski/main</li>
<li><a href="a9a994f367"><code>a9a994f</code></a> improve performance by stop using the mapFn param on Uint8Array.from constructor</li>
<li>See full diff in <a href="https://github.com/dankogai/js-base64/compare/3.7.4...3.7.5">compare view</a></li>
</ul>
</details>
<br />

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=js-base64&package-manager=npm_and_yarn&previous-version=3.7.4&new-version=3.7.5)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

 ---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `dependabot rebase` will rebase this PR
- `dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `dependabot merge` will merge this PR after your CI passes on it
- `dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `dependabot cancel merge` will cancel a previously requested merge and block automerging
- `dependabot reopen` will reopen this PR if it is closed
- `dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

</details>

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

Reviewed By: mweststrate

Differential Revision: D43305193

Pulled By: ivanmisuno

fbshipit-source-id: e10eb134c079951e325c1f4d627eb1e60510c12d
2023-02-16 06:33:32 -08:00
Michel Weststrate
6196204a7b Plugin download failure is not an error
Summary: Plugin download failure is typical a transient error, no need to trigger monitoring for that

Reviewed By: ivanmisuno

Differential Revision: D43118116

fbshipit-source-id: 0cd0f87f0ed6123adcba28139308ecea92b1b508
2023-02-10 02:22:50 -08:00
kongxiaojun
e2867a74a7 Fixed a bug where the screenshot of some Android phones was unavailable (#4366)
Summary:
The 'screenrecord' command is not in some Android phones e.g OPPO. So 'screenrecord' command can't be used as a basis for determining whether or not you can take a screenshot. Replace it with 'screencap' command  to determine whether you can take a screenshot.

## Changelog

Fixed a bug where the screenshot of some Android phones was unavailable

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

Test Plan: It passed the test on my Mac and OPPO phone Reno2.

Reviewed By: ivanmisuno

Differential Revision: D42918902

Pulled By: passy

fbshipit-source-id: c1f02f075817d90e0d447f466a1168b6ec932e4e
2023-02-02 08:17:33 -08:00
Pascal Hartig
18b6ce6f24 Dep bump
Summary: Combining a bunch of individual tasks for dep upgrades into one diff.

Reviewed By: ivanmisuno

Differential Revision: D42706074

fbshipit-source-id: 054b2545ad1295699f47f4c6eb5065b7b9a1d6a0
2023-01-25 04:35:09 -08:00
Ranesh Saha
7a28ed1fe5 Pipe through --updater/--no-updater flag for flipper.exe (#4277)
Summary:
In our organization, Flipper is distributed in a version controlled way. As a result, we do not want users to manually update or receive prompts to update when a new version is available. There is already a `--updater` flag in the command line arguments for flipper.exe, but it isn't piped through. This change pipes it through and disables all update related UI when `--no-updater` is passed in.
## Changelog

Support --updater and --no-updater options for flipper.exe

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

Test Plan: Ran `yarn build --win` in flipper/desktop, and launched flipper.exe from flipper/dist/win-unpacked with the `--updater`, `--no-updater` and no flags and ensured the proper behavior was observed (update UI shows by default or when `--updater` is specified, and doesn't show when `--no-updater` is specified).

Reviewed By: passy

Differential Revision: D41298321

Pulled By: mweststrate

fbshipit-source-id: 5ddfede2700954f0fdd6a111b20d0836fab25565
2022-11-15 03:23:55 -08:00
Michel Weststrate
7626453f55 Fall back to memory password storage if keytar is not available
Summary:
Not in all environments keytar is available, but still it will be useful to be able to login to intern with Flipper, even for temporarily sessions. This solution falls back to in memory storage.

Note that the underlying assuption is that multiple different users are not connected to the same Flipper server, as this would share their session!

https://fb.workplace.com/groups/flippersupport/permalink/1498550730625580/

Reviewed By: passy

Differential Revision: D41218132

fbshipit-source-id: 6e518d742df639bfbdc9a36ed1fa56ecb363a0b0
2022-11-11 08:28:25 -08:00
Andrey Goncharov
7e9166137c Add verbose logging for Android cert exchange
Reviewed By: lblasa

Differential Revision: D40981864

fbshipit-source-id: f99f517c5abdce839a441c21d50ce8488b249313
2022-11-04 08:23:44 -07:00
Andrey Goncharov
2c767e1920 Make the universal export work on the older Android devices
Summary: On older Android devices (API 24) `-printf ` is not available

Reviewed By: lblasa

Differential Revision: D40980640

fbshipit-source-id: d1a1bcadc496deaf3d514c1e45b2e0104a937b18
2022-11-04 08:23:44 -07:00
Lorenzo Blasa
587f428cf8 Allow plugins to use css
Summary:
Flipper plugins fail when importing css from third-party dependencies. This diff tries to fix that.

Effectively, the plugin can import the css and export it when is bundled.

When we load the plugin, we check if there's a css file for it. If there's one, we return it and try to use it.

Reviewed By: aigoncharov

Differential Revision: D40758178

fbshipit-source-id: e53afffcc481504905d5eeb1aea1f9114ee2a86b
2022-10-27 22:50:30 -07:00