Commit Graph

24 Commits

Author SHA1 Message Date
Jamil
4d84e1f12e chore(connlib): Add external ID to FFI, return fd in on_set_interface_config (#1945)
(Supersedes #1944)

* Fixes https://github.com/firezone/product/issues/649
* Passes `dns_fallback_strategy` over FFI (these are hardcoded for now)
* Incorporates @conectado 's #1944 and cleans up a few places `fd` was
still passed

Draft for now until I can test it more tomorrow

---------

Co-authored-by: conectado <gabrielalejandro7@gmail.com>
2023-08-25 15:44:08 -07:00
Roopesh Chander
e1ac496545 apple: macOS app: Some bugfixes (#1937)
Fixes the following issues with the macOS app:

 1. Every alternate launch of the app caused the tunnel to go down
2. When signing out and signing back in, resources were not getting
updated
3. While the tunnel is up, when we quit the app and restart the app, the
tunnel was brought down
2023-08-22 15:25:16 +00:00
Jamil
54e1a79a50 fix(ios): portal connectivity and tunnel setup (#1927)
This PR fixes issues with the iOS client connecting to the portal and
setting up the tunnel.

- portal IPv6 unique-local prefix typo
- Use `rustls-webpki-roots` instead of `rustls-native-roots` for tokio
tungstenite since the latter [only supports macOS, Linux, and
Windows](https://github.com/rustls/rustls-native-certs) while the former
seems to work on all platforms(?)
- Remove Multipath TCP entitlement for iOS since it's not relevant for
us.

@conectado After this is merged, we _almost_ have a working tunnel on
iOS. I believe the error we're hitting now is the 4-byte address family
header that we need to add and strip from each packet written to / read
from the tunnel. See below log for sample output when attempting to
connect to the `HTTPbin` resource:

```
dev.firezone.firezone.network-extension	packet-tunnel	debug	16:10:13.401705-0700	FirezoneNetworkExtensioniOS	Adapter state changed to: tunnelReady
dev.firezone.firezone.network-extension	packet-tunnel	debug	16:10:13.401731-0700	FirezoneNetworkExtensioniOS	Beginning path monitoring
com.apple.network	path	default	16:10:13.402211-0700	FirezoneNetworkExtensioniOS	nw_path_evaluator_start [1ACDE975-615B-4557-BF7C-678F3594452E <NULL> generic, multipath service: 1, attribution: developer]
	path: satisfied (Path is satisfied), interface: en0[802.11], scoped, ipv4, ipv6, dns
com.apple.network	path	info	16:10:13.402235-0700	FirezoneNetworkExtensioniOS	nw_path_evaluator_call_update_handler [1ACDE975-615B-4557-BF7C-678F3594452E] scheduling update
com.apple.network	path	info	16:10:13.402261-0700	FirezoneNetworkExtensioniOS	nw_path_evaluator_call_update_handler_block_invoke [1ACDE975-615B-4557-BF7C-678F3594452E] delivering update
com.apple.network		debug	16:10:13.402286-0700	FirezoneNetworkExtensioniOS	nw_path_copy_interface_with_generation Cache miss for interface for index 3 (generation 4574)
com.apple.network		debug	16:10:13.402312-0700	FirezoneNetworkExtensioniOS	nw_path_copy_interface_with_generation Cache miss for interface for index 31 (generation 141)
dev.firezone.firezone.network-extension	packet-tunnel	debug	16:10:13.402363-0700	FirezoneNetworkExtensioniOS	Suppressing calls to disableSomeRoamingForBrokenMobileSemantics() and bumpSockets()
dev.firezone.firezone	connlib	debug	16:10:14.368105-0700	FirezoneNetworkExtensioniOS	Reading from iface 76 bytes
dev.firezone.firezone	connlib	debug	16:10:15.369018-0700	FirezoneNetworkExtensioniOS	Reading from iface 76 bytes
dev.firezone.firezone	connlib	debug	16:10:16.095618-0700	FirezoneNetworkExtensioniOS	Reading from iface 76 bytes
dev.firezone.firezone	connlib	debug	16:10:16.370908-0700	FirezoneNetworkExtensioniOS	Reading from iface 76 bytes
dev.firezone.firezone	connlib	debug	16:10:17.372035-0700	FirezoneNetworkExtensioniOS	Reading from iface 76 bytes
dev.firezone.firezone	connlib	debug	16:10:18.373423-0700	FirezoneNetworkExtensioniOS	Reading from iface 76 bytes
dev.firezone.firezone	connlib	debug	16:10:20.402863-0700	FirezoneNetworkExtensioniOS	Reading from iface 76 bytes
dev.firezone.firezone	connlib	debug	16:10:24.381581-0700	FirezoneNetworkExtensioniOS	Reading from iface 76 bytes
dev.firezone.firezone	connlib	debug	16:10:32.374566-0700	FirezoneNetworkExtensioniOS	Reading from iface 76 bytes
dev.firezone.firezone	connlib	debug	16:10:38.137437-0700	FirezoneNetworkExtensioniOS	Text("{\"ref\":null,\"topic\":\"phoenix\",\"event\":\"phx_reply\",\"payload\":{\"status\":\"ok\",\"response\":{}}}")
dev.firezone.firezone	connlib	debug	16:10:38.137757-0700	FirezoneNetworkExtensioniOS	Phoenix status message
dev.firezone.firezone	connlib	debug	16:10:48.376339-0700	FirezoneNetworkExtensioniOS	Reading from iface 76 bytes
dev.firezone.firezone	connlib	debug	16:11:08.148369-0700	FirezoneNetworkExtensioniOS	Text("{\"ref\":null,\"topic\":\"phoenix\",\"event\":\"phx_reply\",\"payload\":{\"status\":\"ok\",\"response\":{}}}")
dev.firezone.firezone	connlib	debug	16:11:08.148654-0700	FirezoneNetworkExtensioniOS	Phoenix status message
```
2023-08-21 20:48:30 -07:00
Gabi
8c6d487e89 swift: update app capabilities to enable UDP binding (#1925)
cc @jamilbk

---------

Signed-off-by: Jamil <jamilbk@users.noreply.github.com>
Co-authored-by: Jamil <jamilbk@users.noreply.github.com>
2023-08-18 13:27:19 -07:00
Jamil
b8cb59beb2 Use tunnelOverheadBytes to properly set tunnel interface MTU (#1924)
Apple provides a mechanism to calculate a smarter MTU for the tunnel
interface that is created.

This will be automatically adjusted depending on the MTU of the
underlying physical device.
2023-08-18 05:14:04 +00:00
Jamil
2adeb4836c Revert "Apple: Add support for magic links" (#1913)
Reverts firezone/firezone#1909

As discussed [in this
thread](https://firezonehq.slack.com/archives/C04HRQTFY0Z/p1691797780786319),
I didn't catch that this PR would introduce a potential token-stealing
vulnerability into the application.

Magic link auth flow will be fixed in #1912
2023-08-16 21:11:20 -07:00
Jamil
f59ed16dca Add note re: debugging network extension in ios sim (#1895)
https://developer.apple.com/forums/thread/101663

🙃 

I'll leave the build in CI enabled for now, but wanted to note this in
docs.
2023-08-15 08:00:33 +00:00
Roopesh Chander
6ed762d5b4 Apple: Add support for magic links (#1909)
Addresses #1899.

Tested only with PortalMock. Works with Safari. Not tested yet with
non-Safari browsers as default in macOS (if required, will address that
separately).

`client_csrf_token` is always passed. It's verified only if the sign in
happens with the external open-app-with-URL scenario. It's not checked
if the user logs in inside of the `ASWebAuthenticationSession` webpage
itself.
2023-08-14 20:06:01 +00:00
Jamil
1fb196d2e3 Fix SettingsView for iOS (#1897)
Just a quick fix to get the buttons working for iOS so we can test the
packet tunnel. Could still be improved.
2023-08-14 05:12:56 +00:00
Jamil
80e17b2270 fix: load SSO cookies in ASWebAuthenticationSession (#1898) 2023-08-13 04:24:28 +00:00
Jamil
e9c0729b98 Use public Logger from FirezoneKit (#1888)
Enables the NetworkExtension to use the Logger helpers so that its
bundle id is used for the logging subsystem
2023-08-11 13:33:29 -05:00
Jamil
d0a472b8c1 Build for iphonesimulator (#1890)
Fixes the iphonesimulator build.
2023-08-11 13:33:04 -05:00
Roopesh Chander
fbd2329e9d apple: Separate auth URL and control plane URL (#1887)
Auth base URL and Control Plane URL are configurable in a new
Server.xcconfig (so that we can have Server_Dev.xcconfig,
Server_Staging.xcconfig, and Server_Prod.xcconfig and switch between
them by copying / symbolic linking).

App's Settings View takes in Team ID instead of a URL. App forms auth
URL from Auth base URL from Server.xcconfig and the Team ID in settings.
Tunnel passes control plane URL from Server.xcconfig to connlib.

~~Marked as draft because this PR depends on #1881.~~ #1881 has been
merged.
2023-08-11 11:08:40 -05:00
Jamil
3a79f4c0aa apple: refactor portal_url to be opaque (#1881)
* Remove JWT to be an opaque token and update variable names accordingly
* Use new `actor_name` param from the portal instead of user info from
old JWT
* Log attempted portal URL from connlib
* Remove account slug/id from portal_url before sending to connlib

@roop The token from the portal is a Phoenix.Token, not a valid JWT, so
this was causing a JWTDecodeError. Discussed with @AndrewDryga and
concluded this should be an opaque token. Expiry and other invalid token
scenarios will be bubbled up from connlib via an `onError` callback (or
perhaps a dedicated `onTokenInvalid` callback). For now connlib doesn't
handle this specifically.
2023-08-11 06:17:44 -05:00
Jamil
9b538e92d4 apple: Tunnel stack (#1876)
This PR adds the remaining bits of the Apple tunnel stack for macOS and
iOS devices.

- [x] Find file descriptor corresponding to NE-managed tunnel interface
- [ ] Testing

---------

Signed-off-by: Jamil <jamilbk@users.noreply.github.com>
Co-authored-by: conectado <gabrielalejandro7@gmail.com>
2023-08-10 12:40:46 -05:00
Jamil
9b2ab98f7e apple: Remove dest param and redirect with client_platform (#1869)
Matches what's being set in #1868
2023-08-08 10:32:36 +00:00
Roopesh Chander
e591b92ec9 apple: Set network settings using data from connlib (#1846)
This PR sets the network settings, split-DNS, and macOS UI resources
using the data from connlib callbacks.

This should enable connlib to be developed / tested in Apple platforms
(Caveat: There's no UI to see resources in iOS yet).

Some assumptions being made are:
- It's ok to call disconnect() before onTunnelReady(), but after
connect()
- CIDR addresses don't include enclosing quotes (they currently include
the quotes, like: `"8.8.4.4/32"`)
- CIDR addresses in routes always end with “/n”
- Connlib calls can be made from a queue (non-main thread)

---------

Co-authored-by: Jamil <jamilbk@users.noreply.github.com>
2023-08-07 06:50:05 +00:00
Francesca Lovebloom
9d4df04501 connlib: Simpler FFI (#1823)
As per discussion from the client sync,
- this removes `TunnelAddresses` in favor of simply passing the IPv4 and
IPv6 addresses as two separate strings.
- this changes `onDisconnect`'s semantics to be called _after_
disconnect instead of before.

Additionally, as per earlier discussion, errors are now passed as
strings. These errors already weren't intended to be actionable on the
client side, so the ability to handle them programmatically is
unnecessary. When internationalization is added down the road, we'll
likely replace these with error codes for looking up localized strings;
until then, this design improves diagnostics and reduces complexity.

Closes #1796
Closes #1822
2023-07-29 23:47:39 +00:00
Jamil
f968c8cefc Update Apple client with changes from demoable build (#1809)
Brings in the changes from the Demoable build so I can start getting
feedback from users on.

---------

Co-authored-by: Roopesh Chander <roop@roopc.net>
2023-07-24 19:59:40 +00:00
Jamil
30ccb43ebb apple: Add icons in prep for App Store distribution (#1808)
Adds icons to Apple for app distribution for TestFlight testing.

@pratikvelani -- can these also be used for Android or do we need a
different format? I can add you to our Figma team if you need to slice
the assets directly.
2023-07-20 18:22:10 +00:00
dependabot[bot]
fe77897da6 Bump rack from 2.2.4 to 2.2.7 in /swift/apple/PortalMock (#1782)
Bumps [rack](https://github.com/rack/rack) from 2.2.4 to 2.2.7.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/rack/rack/releases">rack's
releases</a>.</em></p>
<blockquote>
<h2>v2.2.7</h2>
<h2>What's Changed</h2>
<ul>
<li>Correct the year number in the changelog by <a
href="https://github.com/kimulab"><code>@​kimulab</code></a> in <a
href="https://redirect.github.com/rack/rack/pull/2015">rack/rack#2015</a></li>
<li>Support underscore in host names for Rack 2.2 (Fixes <a
href="https://redirect.github.com/rack/rack/issues/2070">#2070</a>) by
<a href="https://github.com/jeremyevans"><code>@​jeremyevans</code></a>
in <a
href="https://redirect.github.com/rack/rack/pull/2071">rack/rack#2071</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/kimulab"><code>@​kimulab</code></a> made
their first contribution in <a
href="https://redirect.github.com/rack/rack/pull/2015">rack/rack#2015</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/rack/rack/compare/v2.2.6.4...v2.2.7">https://github.com/rack/rack/compare/v2.2.6.4...v2.2.7</a></p>
<h2>v2.2.6.4</h2>
<p>No release notes provided.</p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/rack/rack/blob/main/CHANGELOG.md">rack's
changelog</a>.</em></p>
<blockquote>
<h1>Changelog</h1>
<p>All notable changes to this project will be documented in this file.
For info on how to format all future additions to this file please
reference <a href="https://keepachangelog.com/en/1.0.0/">Keep A
Changelog</a>.</p>
<h2>Unreleased</h2>
<h3>SPEC Changes</h3>
<ul>
<li><code>rack.input</code> is now optional. (<a
href="https://redirect.github.com/rack/rack/pull/1997">#1997</a>, [<a
href="https://github.com/ioquatix"><code>@​ioquatix</code></a>])</li>
</ul>
<h3>Changed</h3>
<ul>
<li><code>rack.input</code> is now optional, and if missing, will raise
an error. Use this to fail on multipart parsing a request without an
input body. (<a
href="https://redirect.github.com/rack/rack/pull/2018">#2018</a>, [<a
href="https://github.com/ioquatix"><code>@​ioquatix</code></a>])</li>
<li>Introduce <code>module Rack::BadRequest</code> which is included in
multipart and query parser errors. (<a
href="https://redirect.github.com/rack/rack/pull/2019">#2019</a>, [<a
href="https://github.com/ioquatix"><code>@​ioquatix</code></a>])</li>
<li>MIME type for JavaScript files (<code>.js</code>) changed from
<code>application/javascript</code> to <code>text/javascript</code> (<a
href="1bd0f1597d"><code>1bd0f15</code></a>)</li>
<li>Add <code>.mjs</code> MIME type (<a
href="https://redirect.github.com/rack/rack/pull/2057">#2057</a>, [<a
href="https://github.com/axilleas"><code>@​axilleas</code></a>])</li>
<li>Update MIME types associated to <code>.ttf</code>,
<code>.woff</code>, <code>.woff2</code> and <code>.otf</code> extensions
to use mondern <code>font/*</code> types. (<a
href="https://redirect.github.com/rack/rack/pull/2065">#2065</a>, [<a
href="https://github.com/davidstosik"><code>@​davidstosik</code></a>])</li>
</ul>
<h2>[3.0.8] - 2023-06-14</h2>
<ul>
<li>Fix some unused variable verbose warnings. (<a
href="https://redirect.github.com/rack/rack/pull/2084">#2084</a>, [<a
href="https://github.com/jeremyevans"><code>@​jeremyevans</code></a>],
<a
href="https://github.com/skipkayhil"><code>@​skipkayhil</code></a>)</li>
</ul>
<h2>[3.0.7] - 2023-03-16</h2>
<ul>
<li>Make query parameters without <code>=</code> have <code>nil</code>
values. (<a
href="https://redirect.github.com/rack/rack/pull/2059">#2059</a>, [<a
href="https://github.com/jeremyevans"><code>@​jeremyevans</code></a>])</li>
</ul>
<h2>[3.0.6.1] - 2023-03-13</h2>
<ul>
<li>[CVE-2023-27539] Avoid ReDoS in header parsing</li>
</ul>
<h2>[3.0.6] - 2023-03-13</h2>
<ul>
<li>Add <code>QueryParser#missing_value</code> for handling missing
values + tests. (<a
href="https://redirect.github.com/rack/rack/pull/2052">#2052</a>, [<a
href="https://github.com/ioquatix"><code>@​ioquatix</code></a>])</li>
</ul>
<h2>[3.0.5] - 2023-03-13</h2>
<ul>
<li>Split form/query parsing into two steps. (<a
href="https://redirect.github.com/rack/rack/pull/2038">#2038</a>, <a
href="https://github.com/matthewd"><code>@​matthewd</code></a>)</li>
</ul>
<h2>[3.0.4.2] - 2023-03-02</h2>
<ul>
<li>[CVE-2023-27530] Introduce multipart_total_part_limit to limit total
parts</li>
</ul>
<h2>[3.0.4.1] - 2023-01-17</h2>
<ul>
<li>[CVE-2022-44571] Fix ReDoS vulnerability in multipart parser</li>
<li>[CVE-2022-44570] Fix ReDoS in Rack::Utils.get_byte_ranges</li>
<li>[CVE-2022-44572] Forbid control characters in attributes (also
ReDoS)</li>
</ul>
<h2>[3.0.4] - 2023-01-17</h2>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="983b6e3b29"><code>983b6e3</code></a>
Bump patch version.</li>
<li><a
href="e5a30bf548"><code>e5a30bf</code></a>
Support underscore in host names for Rack 2.2 (Fixes <a
href="https://redirect.github.com/rack/rack/issues/2070">#2070</a>) (<a
href="https://redirect.github.com/rack/rack/issues/2071">#2071</a>)</li>
<li><a
href="70185aa15a"><code>70185aa</code></a>
Merge branch '2-2-sec' into 2-2-stable</li>
<li><a
href="27addc7f1a"><code>27addc7</code></a>
bump version</li>
<li><a
href="ee7919ea04"><code>ee7919e</code></a>
Avoid ReDoS problem</li>
<li><a
href="6f79642d90"><code>6f79642</code></a>
Merge branch '2-2-sec' into 2-2-stable</li>
<li><a
href="d6b5b2bab8"><code>d6b5b2b</code></a>
bump version</li>
<li><a
href="9aac3757fe"><code>9aac375</code></a>
Limit all multipart parts, not just files</li>
<li><a
href="cd4c9f0e4b"><code>cd4c9f0</code></a>
Correct the year in the changelog (<a
href="https://redirect.github.com/rack/rack/issues/2015">#2015</a>)</li>
<li><a
href="2606ac5d5d"><code>2606ac5</code></a>
bumping version</li>
<li>Additional commits viewable in <a
href="https://github.com/rack/rack/compare/2.2.4...v2.2.7">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=rack&package-manager=bundler&previous-version=2.2.4&new-version=2.2.7)](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)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/firezone/firezone/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-13 19:48:28 +00:00
Roopesh Chander
9ad557f568 Integrate connlib build into apple build (#1759)
This PR improves the build process for the macOS / iOS apps by building
connlib as part of the macOS / iOS app build.

Fixes firezone/product#625.

This is how the build would work after this PR:
- `build-rust.sh` creates `libconnlib.a` for the appropriate target
triples only. lipo is not used. When creating macOS debug builds, it’s
built only for the native architecture.
- The network extension targets in the Xcode project set a library
search path as the cargo target dir, so that the Xcode build for a
target triple can pickup the appropriate `libconnlib.a` at link time.

Swift code reorganizations:
  - connlib’s Adapter has moved to the main app
- connlib’s CallbackHandler’s logic has moved to Adapter, which is set
as CallbackHandler’s delegate. The CallbackHandler serves as an
interface to receive callbacks from the FFI. In case we need to change
the FFI, CallbackHandler should change as well, so it remains in the
connlib directory. In case of changes to the Rust FFI, as part of the
Rust FFI change PR, we can modify the CallbackHandler class and leave
the delegate unchanged, so that the app can continue to be built without
errors.
- `Connlib.xcodeproject` and build scripts for building
`Connlib.xcframework` are removed
- Connlib headers and Swift files are copied to
`FirezoneNetworkExtension/Connlib` as part of the build process, and
used from there.

Rust build changes:
- The rust target dir remains the same, but it’s ~~passed explicitly as
`--target-dir`~~ used to set `CARGO_TARGET_DIR`, so that the same target
dir can be used to populate Xcode’s library search paths
- The `build.rs` for connlib-apple had lots of code to build Swift code
as part of the Rust build. This PR reverts it to the previous simple
version. With this PR, building connlib-apple (i.e. running
`build-rust.sh`) only builds the Rust code.
- ~~We set `cargo:rerun-if-env-changed=CONNLIB_MOCK`.~~ We don't set
this because it's not required.
- The Rust CI job for building connlib-apple is removed. It's built when
the macOS / iOS apps are built in swift.yml. This means that with this
PR, connlib-apple is tested only when `rust/connlib/**` changes, not
when `rust/**` changes. Is that ok?

Other changes not directly related to the build process change but part
of this PR:
  - There’s a cleanup script: `./cleanup.sh`
  - Fixed a typo in `swift-pass-checks.yml`: “paths-ginore”
2023-07-13 05:23:24 +00:00
Roopesh Chander
c9c13e1e11 Bring in apple client into monorepo (#1737)
This PR brings in the apple client into the monorepo.

---------

Co-authored-by: Jamil <jamilbk@users.noreply.github.com>
2023-07-07 10:37:24 -07:00
Jamil
d35208bf17 Stub out client app directories in monorepo structure (#1716)
Stubs out the client app dirs and basic CI workflow for the client apps
in preparation to move them into this repository.

After this is merged @roop @pratikvelani you should be able to add the
client repos here.
2023-06-29 20:16:29 +00:00