Repository navigation
Preserve connectivity across staggered Iroh upgrades #8196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,749
−201
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a94ceb0
test: cover Tailscale and Iroh upgrade compatibility
3ee987a
test: cover live Mac migration switching
416d02d
test: cover migration failure precedence and legacy expiry
64f37b5
test: strengthen legacy pairing privacy coverage
6c17c35
test: cover concurrent route migration
913b91c
fix: preserve Iroh and Tailscale upgrade compatibility
2aad5d7
fix: restore Bonsplit fork availability API
1ecd0d4
build(ios): lock Iroh in workspace resolution
c171bc3
test: cover reconnect migration review gaps
f8914fc
test: cover reconnect snapshot ownership
f16568c
fix: make reconnect migration authoritative and linear
3847206
Merge remote-tracking branch 'origin/main' into feat-tailscale-iroh-m…
9d7c8b3
test: cover final reconnect authority races
f7f7141
fix: revalidate reconnect migration authority
84fc14f
refactor: centralize legacy pairing codec
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...ges/Shared/CMUXMobileCore/Sources/CMUXMobileCore/CmxLegacyPrivateNetworkPairingCode.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import Foundation | ||
|
|
||
| /// Encodes the full-key v1 pairing payload required by released iOS clients | ||
| /// that predate the compact ticket and bare-route grammars. | ||
| public struct CmxLegacyPrivateNetworkPairingCode: Sendable { | ||
| /// The compatibility payload is non-authorizing, so its synthetic expiry | ||
| /// only prevents historical decoders from rejecting a displayed code. | ||
| private static let compatibilityExpiry = Date(timeIntervalSince1970: 4_102_444_800) | ||
|
|
||
| /// Creates the stateless compatibility encoder. | ||
| public init() {} | ||
|
|
||
| /// Returns a tokenless Tailscale-only v1 pairing URL, or `nil` when the | ||
| /// ticket has no Tailscale route to disclose. | ||
| public func encode(_ ticket: CmxAttachTicket) throws -> URL? { | ||
| let tailscaleRoutes = ticket.routes.filter { $0.kind == .tailscale } | ||
| guard !tailscaleRoutes.isEmpty else { return nil } | ||
|
|
||
| let legacyTicket = try CmxAttachTicket( | ||
| version: ticket.version, | ||
| workspaceID: ticket.workspaceID, | ||
| terminalID: ticket.terminalID, | ||
| macDeviceID: ticket.macDeviceID, | ||
| macDisplayName: ticket.macDisplayName, | ||
| macUserEmail: nil, | ||
| macUserID: ticket.macUserID, | ||
| macPairingCompatibilityVersion: ticket.macPairingCompatibilityVersion, | ||
| macAppVersion: ticket.macAppVersion, | ||
| macAppBuild: ticket.macAppBuild, | ||
| routes: tailscaleRoutes, | ||
| expiresAt: Self.compatibilityExpiry, | ||
| authToken: nil | ||
| ) | ||
| let encoder = JSONEncoder() | ||
| encoder.dateEncodingStrategy = .iso8601 | ||
| let payload = base64URLEncode(try encoder.encode(legacyTicket)) | ||
| return URL( | ||
| string: "\(CmxPairingURLScheme.current)://attach?v=\(legacyTicket.version)&payload=\(payload)" | ||
| ) | ||
| } | ||
|
|
||
| private func base64URLEncode(_ data: Data) -> String { | ||
| data.base64EncodedString() | ||
| .replacingOccurrences(of: "+", with: "-") | ||
| .replacingOccurrences(of: "/", with: "_") | ||
| .replacingOccurrences(of: "=", with: "") | ||
| } | ||
| } |
95 changes: 95 additions & 0 deletions
95
...ed/CMUXMobileCore/Tests/CMUXMobileCoreTests/CmxLegacyPrivateNetworkPairingCodeTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import Foundation | ||
| import Testing | ||
| @testable import CMUXMobileCore | ||
|
|
||
| @Suite struct CmxLegacyPrivateNetworkPairingCodeTests { | ||
| @Test func encodesTokenlessTailscaleOnlyFullKeyPayload() throws { | ||
| let tailscale = try CmxAttachRoute( | ||
| id: "tailscale", | ||
| kind: .tailscale, | ||
| endpoint: .hostPort(host: "100.64.0.5", port: 58_465), | ||
| priority: 10 | ||
| ) | ||
| let iroh = try CmxAttachRoute( | ||
| id: "iroh", | ||
| kind: .iroh, | ||
| endpoint: .peer( | ||
| identity: CmxIrohPeerIdentity( | ||
| endpointID: String(repeating: "a", count: 64) | ||
| ), | ||
| pathHints: [] | ||
| ), | ||
| priority: 0 | ||
| ) | ||
| let sourceExpiry = Date(timeIntervalSince1970: 1_800_000_000) | ||
| let ticket = try CmxAttachTicket( | ||
| version: CmxAttachTicket.currentVersion, | ||
| workspaceID: "", | ||
| terminalID: nil, | ||
| macDeviceID: "mac-1", | ||
| macDisplayName: "Mac", | ||
| macUserEmail: "private@example.com", | ||
| macUserID: "opaque-user-id", | ||
| macPairingCompatibilityVersion: 1, | ||
| macAppVersion: "1.0", | ||
| macAppBuild: "100", | ||
| routes: [iroh, tailscale], | ||
| expiresAt: sourceExpiry, | ||
| authToken: "secret" | ||
| ) | ||
|
|
||
| let encodedURL = try CmxLegacyPrivateNetworkPairingCode().encode(ticket) | ||
| let url = try #require(encodedURL) | ||
| let components = try #require(URLComponents(url: url, resolvingAgainstBaseURL: false)) | ||
| let encoded = try #require( | ||
| components.queryItems?.first(where: { $0.name == "payload" })?.value | ||
| ) | ||
| let data = try #require(Self.decodeBase64URL(encoded)) | ||
| let decoder = JSONDecoder() | ||
| decoder.dateDecodingStrategy = .iso8601 | ||
| let decoded = try decoder.decode(CmxAttachTicket.self, from: data) | ||
|
|
||
| #expect(decoded.routes == [tailscale]) | ||
| #expect(decoded.authToken == nil) | ||
| #expect(decoded.macUserEmail == nil) | ||
| #expect(decoded.macUserID == "opaque-user-id") | ||
| #expect(try #require(decoded.expiresAt) > sourceExpiry.addingTimeInterval(365 * 24 * 60 * 60)) | ||
| } | ||
|
|
||
| @Test func returnsNilWithoutTailscaleRoute() throws { | ||
| let ticket = try CmxAttachTicket( | ||
| version: CmxAttachTicket.currentVersion, | ||
| workspaceID: "", | ||
| terminalID: nil, | ||
| macDeviceID: "mac-1", | ||
| macDisplayName: "Mac", | ||
| macUserEmail: nil, | ||
| macUserID: "opaque-user-id", | ||
| routes: [ | ||
| try CmxAttachRoute( | ||
| id: "iroh", | ||
| kind: .iroh, | ||
| endpoint: .peer( | ||
| identity: CmxIrohPeerIdentity( | ||
| endpointID: String(repeating: "b", count: 64) | ||
| ), | ||
| pathHints: [] | ||
| ), | ||
| priority: 0 | ||
| ), | ||
| ], | ||
| expiresAt: nil, | ||
| authToken: nil | ||
| ) | ||
|
|
||
| #expect(try CmxLegacyPrivateNetworkPairingCode().encode(ticket) == nil) | ||
| } | ||
|
|
||
| private static func decodeBase64URL(_ value: String) -> Data? { | ||
| var normalized = value | ||
| .replacingOccurrences(of: "-", with: "+") | ||
| .replacingOccurrences(of: "_", with: "/") | ||
| normalized += String(repeating: "=", count: (4 - normalized.count % 4) % 4) | ||
| return Data(base64Encoded: normalized) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.