-
Notifications
You must be signed in to change notification settings - Fork 0
feat: bind native entitlement to broker identity #641
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
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3cc4127
feat: bind native entitlement to broker identity
6ca5c80
fix: fail closed on malformed entitlement expiry
b5ff29c
fix: require broker identity for native activation
8bc02cf
test: bind native CLI activation fixture
3f0252e
fix(license): parse dash-prefixed broker identities
c091c25
fix(license): require native repository binding
24c57e0
fix(license): keep activation repository immutable
204fdaf
fix(license): validate native repository binding
3e836a6
fix(license): validate native activation identity
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
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
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
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
37 changes: 37 additions & 0 deletions
37
...ndiff-desktop/Tests/NeonDiffDesktopAppCoreTests/DesktopActivationLicenseClientTests.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,37 @@ | ||
| import Foundation | ||
| import Testing | ||
| @testable import NeonDiffDesktopAppCore | ||
| import NeonDiffDesktopCore | ||
|
|
||
| @Suite struct DesktopActivationLicenseClientTests { | ||
| @Test func bindsActivationToBrokerDeviceAndRepositoryWithoutArgvSecret() async throws { | ||
| let rawKey = "nd_live_keychain-desktop-fixture" | ||
| let cli = RecordingCLIExecutor(result: CLIRunResult( | ||
| exitCode: 0, | ||
| stdout: """ | ||
| {"command":"license activate","ok":true,"status":"active","source":"api", | ||
| "checkedAt":"2026-07-18T00:00:00.000Z", | ||
| "entitlement":{"status":"active","repoVisibilityScope":"private", | ||
| "privateRepoAllowed":true,"updateEntitlement":true}} | ||
| """, | ||
| stderr: "" | ||
| )) | ||
| let client = DesktopActivationLicenseClient( | ||
| cli: cli, | ||
| executablePath: "/fixture/neondiff", | ||
| configPath: "/fixture/config.json", | ||
| machineId: "broker-device-binding-123", | ||
| repository: "octo/private" | ||
| ) | ||
|
|
||
| _ = try await client.activate(key: ActivationKeyMaterial(rawKey)) | ||
|
|
||
| let call = try #require(cli.calls.first) | ||
| #expect(call.standardInput == Data(rawKey.utf8)) | ||
| #expect(call.arguments.contains("--license-machine-id")) | ||
| #expect(call.arguments.contains("broker-device-binding-123")) | ||
| #expect(call.arguments.contains("--repo")) | ||
| #expect(call.arguments.contains("octo/private")) | ||
| #expect(call.arguments.allSatisfy { !$0.contains(rawKey) }) | ||
| } | ||
| } |
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
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
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
60 changes: 60 additions & 0 deletions
60
services/license-api/src/github-broker/license-entitlement.ts
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,60 @@ | ||
| import type { EntitlementResolver } from "./service.js"; | ||
| import type { LicenseStore } from "../store.js"; | ||
|
|
||
| const MAX_ACTIVATION_KEY_LENGTH = 512; | ||
|
|
||
| /** | ||
| * Resolve a private-repository broker request against the production license | ||
| * store. The raw Activation Key is used only for this in-memory lookup and is | ||
| * never returned, logged, or persisted by the broker. | ||
| * | ||
| * Private coverage is deliberately narrower than license validity: the license | ||
| * must be active and unexpired, and its activation must already bind this exact | ||
| * authenticated broker device to the exact requested repository. | ||
| */ | ||
| export function createLicenseStoreEntitlementResolver( | ||
| store: LicenseStore, | ||
| now: () => Date = () => new Date() | ||
| ): EntitlementResolver { | ||
| return (context) => { | ||
| const activationKey = normalizeActivationKey(context.activationKey); | ||
| if (!activationKey) return { status: "none" }; | ||
|
|
||
| const license = store.getLicenseByKey(activationKey); | ||
| if (!license) return { status: "invalid" }; | ||
| if (license.status === "revoked") return { status: "revoked" }; | ||
| const expiresAt = license.expiresAt === undefined | ||
| ? undefined | ||
| : Date.parse(license.expiresAt); | ||
| if (license.status === "expired" | ||
| || (expiresAt !== undefined | ||
| && (!Number.isFinite(expiresAt) || expiresAt <= now().getTime()))) { | ||
| return { status: "expired" }; | ||
| } | ||
|
|
||
| const activation = store.getActivation(license.licenseKeyHash, context.deviceId); | ||
| if (!activation) return { status: "replay_conflict" }; | ||
|
|
||
| if ( | ||
| !license.privateRepoAllowed | ||
| || license.repoVisibilityScope === "public" | ||
| || !activation.repo | ||
| ) { | ||
| return { status: "active", coveredPrivateRepositories: [] }; | ||
| } | ||
|
|
||
| return { | ||
| status: "active", | ||
| coveredPrivateRepositories: context.privateRepositories.includes(activation.repo) | ||
| ? [activation.repo] | ||
|
100yenadmin marked this conversation as resolved.
100yenadmin marked this conversation as resolved.
|
||
| : [] | ||
|
100yenadmin marked this conversation as resolved.
|
||
| }; | ||
| }; | ||
| } | ||
|
|
||
| function normalizeActivationKey(value: string | undefined): string | undefined { | ||
| if (typeof value !== "string") return undefined; | ||
| const trimmed = value.trim(); | ||
| if (!trimmed || trimmed.length > MAX_ACTIVATION_KEY_LENGTH) return undefined; | ||
| return trimmed; | ||
| } | ||
Oops, something went wrong.
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.