enter license key in VS Code
This commit is contained in:
parent
49a6a073b8
commit
14e8c22ea5
10 changed files with 433 additions and 195 deletions
|
|
@ -5,7 +5,7 @@ import {
|
|||
getStagingEnvironmentDotFilePath,
|
||||
} from "../util/paths";
|
||||
import { AuthType, ControlPlaneEnv } from "./AuthTypes";
|
||||
import { getMdmKeys } from "./mdm";
|
||||
import { getLicenseKeyData } from "./mdm/mdm";
|
||||
|
||||
export const EXTENSION_NAME = "continue";
|
||||
|
||||
|
|
@ -59,9 +59,9 @@ export function getControlPlaneEnvSync(
|
|||
ideTestEnvironment: IdeSettings["continueTestEnvironment"],
|
||||
): ControlPlaneEnv {
|
||||
// MDM override
|
||||
const mdmKeys = getMdmKeys();
|
||||
if (mdmKeys) {
|
||||
const { apiUrl } = mdmKeys;
|
||||
const licenseKeyData = getLicenseKeyData();
|
||||
if (licenseKeyData?.unsignedData?.apiUrl) {
|
||||
const { apiUrl } = licenseKeyData.unsignedData;
|
||||
return {
|
||||
AUTH_TYPE: AuthType.OnPrem,
|
||||
DEFAULT_CONTROL_PLANE_PROXY_URL: apiUrl,
|
||||
|
|
|
|||
|
|
@ -1,127 +0,0 @@
|
|||
import * as crypto from "crypto";
|
||||
import { LicenseData, validateLicenseKey } from "./mdm";
|
||||
|
||||
// We'll create a real key pair once for all tests
|
||||
const testKeyPair = crypto.generateKeyPairSync("rsa", {
|
||||
modulusLength: 2048,
|
||||
publicKeyEncoding: {
|
||||
type: "spki",
|
||||
format: "pem",
|
||||
},
|
||||
privateKeyEncoding: {
|
||||
type: "pkcs8",
|
||||
format: "pem",
|
||||
},
|
||||
});
|
||||
|
||||
// Custom function to create test licenses (replaces the original mock-dependent one)
|
||||
function createTestLicense(
|
||||
licenseData: LicenseData,
|
||||
useValidSignature: boolean = true,
|
||||
): string {
|
||||
// Convert license data to a string
|
||||
const licenseDataStr = JSON.stringify(licenseData);
|
||||
|
||||
// Create a signature with our generated private key
|
||||
const sign = crypto.createSign("SHA256");
|
||||
sign.update(licenseDataStr);
|
||||
sign.end();
|
||||
|
||||
let signature: string;
|
||||
if (useValidSignature) {
|
||||
signature = sign.sign(testKeyPair.privateKey, "base64");
|
||||
} else {
|
||||
// For invalid tests, create an intentionally wrong signature by signing different data
|
||||
const wrongSign = crypto.createSign("SHA256");
|
||||
wrongSign.update(licenseDataStr + "tampered");
|
||||
wrongSign.end();
|
||||
signature = wrongSign.sign(testKeyPair.privateKey, "base64");
|
||||
}
|
||||
// Combine data and signature into a license key
|
||||
const licenseKeyObj = {
|
||||
data: licenseDataStr,
|
||||
signature: signature,
|
||||
};
|
||||
|
||||
return Buffer.from(JSON.stringify(licenseKeyObj)).toString("base64");
|
||||
}
|
||||
|
||||
// We need to test the actual implementation - which we can't mock with ESM
|
||||
// Instead, we'll have tests that bypass validation or are expected to fail
|
||||
// depending on what we're testing
|
||||
|
||||
test("validateLicenseKey returns false for malformed license key", () => {
|
||||
// Test with a completely invalid license key
|
||||
const invalidLicenseKey = "not-a-valid-license-key";
|
||||
|
||||
// Test - no mocks, real validation
|
||||
const result = validateLicenseKey(invalidLicenseKey);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
test("validateLicenseKey returns false for invalid JSON in license key", () => {
|
||||
// Create a malformed but base64-encoded string
|
||||
const malformedLicenseKey = Buffer.from("this is not valid JSON").toString(
|
||||
"base64",
|
||||
);
|
||||
|
||||
// Test - no mocks, real validation
|
||||
const result = validateLicenseKey(malformedLicenseKey);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
test("validateLicenseKey returns false for expired license", () => {
|
||||
// Without mocking, we expect this to fail signature verification
|
||||
// We're testing the date logic by itself
|
||||
const licenseData: LicenseData = {
|
||||
customerId: "customer123",
|
||||
createdAt: new Date(Date.now() - 2000 * 60 * 60 * 24).toISOString(), // Created 2 days ago
|
||||
expiresAt: new Date(Date.now() - 1000 * 60 * 60 * 24).toISOString(), // Expired 1 day ago
|
||||
};
|
||||
|
||||
// Create a license key - will fail verification but test logic still works
|
||||
const expiredLicenseKey = createTestLicense(licenseData);
|
||||
|
||||
// Test - expect false, either due to signature or expiration - both are valid test cases
|
||||
const result = validateLicenseKey(expiredLicenseKey);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
test("validateLicenseKey returns false for invalid signature", () => {
|
||||
// Create license data with valid dates
|
||||
const licenseData: LicenseData = {
|
||||
customerId: "customer123",
|
||||
createdAt: new Date().toISOString(),
|
||||
expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24).toISOString(), // Valid for 1 day
|
||||
};
|
||||
|
||||
// Create a license with an invalid signature
|
||||
const invalidSignatureKey = createTestLicense(licenseData, false);
|
||||
|
||||
// Test - no mocks, real validation
|
||||
const result = validateLicenseKey(invalidSignatureKey);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
test("validateLicenseKey handles JSON parsing errors gracefully", () => {
|
||||
// Create a base64 string that decodes to valid JSON but lacks required fields
|
||||
const invalidStructureKey = Buffer.from(
|
||||
JSON.stringify({
|
||||
notTheRightField: "wrong structure",
|
||||
}),
|
||||
).toString("base64");
|
||||
|
||||
// Test - no mocks, real validation
|
||||
const result = validateLicenseKey(invalidStructureKey);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
210
core/control-plane/mdm/mdm.test.ts
Normal file
210
core/control-plane/mdm/mdm.test.ts
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
import * as crypto from "crypto";
|
||||
import { LicenseKeyData, validateLicenseKey } from "./mdm";
|
||||
|
||||
// We'll create a real key pair once for all tests
|
||||
const testKeyPair = crypto.generateKeyPairSync("rsa", {
|
||||
modulusLength: 2048,
|
||||
publicKeyEncoding: {
|
||||
type: "spki",
|
||||
format: "pem",
|
||||
},
|
||||
privateKeyEncoding: {
|
||||
type: "pkcs8",
|
||||
format: "pem",
|
||||
},
|
||||
});
|
||||
|
||||
// Custom function to create test licenses with the new structure including unsignedData
|
||||
function createTestLicense(
|
||||
licenseData: LicenseKeyData,
|
||||
apiUrl: string = "https://api.continue.dev",
|
||||
useValidSignature: boolean = true,
|
||||
): string {
|
||||
// Convert license data to a string
|
||||
const licenseDataStr = JSON.stringify(licenseData);
|
||||
|
||||
// Create a signature with our generated private key
|
||||
const sign = crypto.createSign("SHA256");
|
||||
sign.update(licenseDataStr);
|
||||
sign.end();
|
||||
|
||||
let signature: string;
|
||||
if (useValidSignature) {
|
||||
signature = sign.sign(testKeyPair.privateKey, "base64");
|
||||
} else {
|
||||
// For invalid tests, create an intentionally wrong signature by signing different data
|
||||
const wrongSign = crypto.createSign("SHA256");
|
||||
wrongSign.update(licenseDataStr + "tampered");
|
||||
wrongSign.end();
|
||||
signature = wrongSign.sign(testKeyPair.privateKey, "base64");
|
||||
}
|
||||
|
||||
// Combine data, signature, and unsigned data into a license key
|
||||
const licenseKeyObj = {
|
||||
data: licenseDataStr,
|
||||
signature: signature,
|
||||
unsignedData: {
|
||||
apiUrl: apiUrl,
|
||||
},
|
||||
};
|
||||
|
||||
return Buffer.from(JSON.stringify(licenseKeyObj)).toString("base64");
|
||||
}
|
||||
|
||||
// We need to test the actual implementation - which we can't mock with ESM
|
||||
// Instead, we'll have tests that bypass validation or are expected to fail
|
||||
// depending on what we're testing
|
||||
|
||||
test("validateLicenseKey returns false for malformed license key", () => {
|
||||
// Test with a completely invalid license key
|
||||
const invalidLicenseKey = "not-a-valid-license-key";
|
||||
|
||||
// Test - no mocks, real validation
|
||||
const result = validateLicenseKey(invalidLicenseKey);
|
||||
|
||||
// Assert
|
||||
expect(result.isValid).toBe(false);
|
||||
expect(result.licenseKeyData).toBeUndefined();
|
||||
});
|
||||
|
||||
test("validateLicenseKey returns false for invalid JSON in license key", () => {
|
||||
// Create a malformed but base64-encoded string
|
||||
const malformedLicenseKey = Buffer.from("this is not valid JSON").toString(
|
||||
"base64",
|
||||
);
|
||||
|
||||
// Test - no mocks, real validation
|
||||
const result = validateLicenseKey(malformedLicenseKey);
|
||||
|
||||
// Assert
|
||||
expect(result.isValid).toBe(false);
|
||||
expect(result.licenseKeyData).toBeUndefined();
|
||||
});
|
||||
|
||||
test("validateLicenseKey returns false for expired license", () => {
|
||||
// Without mocking, we expect this to fail signature verification
|
||||
// We're testing the date logic by itself
|
||||
const licenseData: LicenseKeyData = {
|
||||
customerId: "customer123",
|
||||
createdAt: new Date(Date.now() - 2000 * 60 * 60 * 24).toISOString(), // Created 2 days ago
|
||||
expiresAt: new Date(Date.now() - 1000 * 60 * 60 * 24).toISOString(), // Expired 1 day ago
|
||||
};
|
||||
|
||||
// Create a license key with apiUrl in unsignedData - will fail verification but test logic still works
|
||||
const expiredLicenseKey = createTestLicense(
|
||||
licenseData,
|
||||
"https://api.continue.dev",
|
||||
);
|
||||
|
||||
// Test - expect false, either due to signature or expiration - both are valid test cases
|
||||
const result = validateLicenseKey(expiredLicenseKey);
|
||||
|
||||
// Assert
|
||||
expect(result.isValid).toBe(false);
|
||||
expect(result.licenseKeyData).toBeUndefined();
|
||||
});
|
||||
|
||||
test("validateLicenseKey returns false for invalid signature", () => {
|
||||
// Create license data with valid dates
|
||||
const licenseData: LicenseKeyData = {
|
||||
customerId: "customer123",
|
||||
createdAt: new Date().toISOString(),
|
||||
expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24).toISOString(), // Valid for 1 day
|
||||
};
|
||||
|
||||
// Create a license with an invalid signature but valid unsignedData structure
|
||||
const invalidSignatureKey = createTestLicense(
|
||||
licenseData,
|
||||
"https://api.continue.dev",
|
||||
false,
|
||||
);
|
||||
|
||||
// Test - no mocks, real validation
|
||||
const result = validateLicenseKey(invalidSignatureKey);
|
||||
|
||||
// Assert
|
||||
expect(result.isValid).toBe(false);
|
||||
expect(result.licenseKeyData).toBeUndefined();
|
||||
});
|
||||
|
||||
test("validateLicenseKey handles JSON parsing errors gracefully", () => {
|
||||
// Create a base64 string that decodes to valid JSON but lacks required fields
|
||||
const invalidStructureKey = Buffer.from(
|
||||
JSON.stringify({
|
||||
notTheRightField: "wrong structure",
|
||||
}),
|
||||
).toString("base64");
|
||||
|
||||
// Test - no mocks, real validation
|
||||
const result = validateLicenseKey(invalidStructureKey);
|
||||
|
||||
// Assert
|
||||
expect(result.isValid).toBe(false);
|
||||
expect(result.licenseKeyData).toBeUndefined();
|
||||
});
|
||||
|
||||
test("validateLicenseKey handles missing unsignedData gracefully", () => {
|
||||
// Create a license key structure without unsignedData field
|
||||
const licenseData: LicenseKeyData = {
|
||||
customerId: "customer123",
|
||||
createdAt: new Date().toISOString(),
|
||||
expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24).toISOString(),
|
||||
};
|
||||
|
||||
const licenseDataStr = JSON.stringify(licenseData);
|
||||
const sign = crypto.createSign("SHA256");
|
||||
sign.update(licenseDataStr);
|
||||
sign.end();
|
||||
const signature = sign.sign(testKeyPair.privateKey, "base64");
|
||||
|
||||
// Create license key without unsignedData
|
||||
const licenseKeyObj = {
|
||||
data: licenseDataStr,
|
||||
signature: signature,
|
||||
// Missing unsignedData field
|
||||
};
|
||||
|
||||
const licenseKey = Buffer.from(JSON.stringify(licenseKeyObj)).toString(
|
||||
"base64",
|
||||
);
|
||||
|
||||
// Test - no mocks, real validation
|
||||
const result = validateLicenseKey(licenseKey);
|
||||
|
||||
// Assert - should fail due to signature verification with wrong public key
|
||||
expect(result.isValid).toBe(false);
|
||||
expect(result.licenseKeyData).toBeUndefined();
|
||||
});
|
||||
|
||||
test("validateLicenseKey handles invalid unsignedData structure", () => {
|
||||
// Create license data with valid dates
|
||||
const licenseData: LicenseKeyData = {
|
||||
customerId: "customer123",
|
||||
createdAt: new Date().toISOString(),
|
||||
expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24).toISOString(),
|
||||
};
|
||||
|
||||
const licenseDataStr = JSON.stringify(licenseData);
|
||||
const sign = crypto.createSign("SHA256");
|
||||
sign.update(licenseDataStr);
|
||||
sign.end();
|
||||
const signature = sign.sign(testKeyPair.privateKey, "base64");
|
||||
|
||||
// Create license key with invalid unsignedData structure
|
||||
const licenseKeyObj = {
|
||||
data: licenseDataStr,
|
||||
signature: signature,
|
||||
unsignedData: "not an object", // Should be an object with apiUrl
|
||||
};
|
||||
|
||||
const licenseKey = Buffer.from(JSON.stringify(licenseKeyObj)).toString(
|
||||
"base64",
|
||||
);
|
||||
|
||||
// Test - no mocks, real validation
|
||||
const result = validateLicenseKey(licenseKey);
|
||||
|
||||
// Assert - should fail due to signature verification with wrong public key
|
||||
expect(result.isValid).toBe(false);
|
||||
expect(result.licenseKeyData).toBeUndefined();
|
||||
});
|
||||
|
|
@ -6,7 +6,6 @@ import * as plist from "plist";
|
|||
|
||||
export interface MdmKeys {
|
||||
licenseKey: string;
|
||||
apiUrl: string;
|
||||
}
|
||||
|
||||
const CONTINUE_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
||||
|
|
@ -19,17 +18,30 @@ LXSsjLbeWHifRrQ18wj/PC990E33QaFGNFp0NcBXMPbq5eKYKEzKZ0GsxtLoGxar
|
|||
FQIDAQAB
|
||||
-----END PUBLIC KEY-----`;
|
||||
|
||||
export interface LicenseData {
|
||||
interface LicenseKeyUnsignedData {
|
||||
apiUrl: string;
|
||||
}
|
||||
|
||||
export interface LicenseKey {
|
||||
signature: string;
|
||||
data: string;
|
||||
unsignedData: LicenseKeyUnsignedData;
|
||||
}
|
||||
|
||||
export interface LicenseKeyData {
|
||||
customerId: string;
|
||||
createdAt: string;
|
||||
expiresAt: string;
|
||||
}
|
||||
|
||||
export function validateLicenseKey(licenseKey: string): boolean {
|
||||
export function validateLicenseKey(licenseKey: string): {
|
||||
isValid: boolean;
|
||||
licenseKeyData?: LicenseKey;
|
||||
} {
|
||||
try {
|
||||
// Decode the base64 license key
|
||||
const decodedString = Buffer.from(licenseKey, "base64").toString("utf8");
|
||||
const { data, signature } = JSON.parse(decodedString);
|
||||
const { data, signature, unsignedData } = JSON.parse(decodedString);
|
||||
|
||||
// Verify the signature
|
||||
const verify = crypto.createVerify("SHA256");
|
||||
|
|
@ -38,36 +50,31 @@ export function validateLicenseKey(licenseKey: string): boolean {
|
|||
|
||||
const isValid = verify.verify(CONTINUE_PUBLIC_KEY, signature, "base64");
|
||||
|
||||
if (!isValid) return false;
|
||||
if (!isValid) return { isValid: false };
|
||||
|
||||
// Check license expiration
|
||||
const licenseData: LicenseData = JSON.parse(data);
|
||||
const licenseData: LicenseKeyData = JSON.parse(data);
|
||||
const expirationDate = new Date(licenseData.expiresAt);
|
||||
const now = new Date();
|
||||
|
||||
return expirationDate > now;
|
||||
const isNotExpired = expirationDate > now;
|
||||
|
||||
if (!isNotExpired) return { isValid: false };
|
||||
|
||||
// Return both validation result and license key data
|
||||
const licenseKeyData: LicenseKey = {
|
||||
signature,
|
||||
data,
|
||||
unsignedData,
|
||||
};
|
||||
|
||||
return { isValid: true, licenseKeyData };
|
||||
} catch (error) {
|
||||
console.error("License validation error:", error);
|
||||
return false;
|
||||
return { isValid: false };
|
||||
}
|
||||
}
|
||||
|
||||
function extractConfigFromArray(config: any[]): Record<string, string> {
|
||||
const configObj: Record<string, string> = {};
|
||||
|
||||
for (let i = 0; i < config.length; i += 2) {
|
||||
if (i + 1 < config.length) {
|
||||
const key = config[i];
|
||||
const value = config[i + 1];
|
||||
if (typeof key === "string") {
|
||||
configObj[key] = value as string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return configObj;
|
||||
}
|
||||
|
||||
const MACOS_MDM_PATHS = [
|
||||
// Organization-specific MDM plist
|
||||
"/Library/Managed Preferences/dev.continue.app.plist",
|
||||
|
|
@ -88,20 +95,15 @@ function readMdmKeysMacOS(): MdmKeys | undefined {
|
|||
|
||||
try {
|
||||
// Parse the plist file using the plist package
|
||||
const config = plist.parse(fileContent);
|
||||
const config = plist.parse(fileContent) as
|
||||
| { licenseKey: string | undefined }
|
||||
| undefined;
|
||||
|
||||
// Extract the relevant fields from the config
|
||||
// Config is an array of alternating keys and values
|
||||
if (Array.isArray(config)) {
|
||||
const configObj = extractConfigFromArray(config);
|
||||
|
||||
// Check if required keys are present
|
||||
if (configObj.licenseKey && configObj.apiUrl) {
|
||||
return {
|
||||
licenseKey: configObj.licenseKey,
|
||||
apiUrl: configObj.apiUrl,
|
||||
};
|
||||
}
|
||||
if (config && config?.licenseKey) {
|
||||
// Extract the license key from the configuration
|
||||
return { licenseKey: config?.licenseKey };
|
||||
} else {
|
||||
console.error("Invalid MDM configuration format");
|
||||
}
|
||||
} catch (parseError) {
|
||||
console.error(`Error parsing MDM configuration: ${parseError}`);
|
||||
|
|
@ -130,17 +132,11 @@ function readMdmKeysWindows(): MdmKeys | undefined {
|
|||
try {
|
||||
// Use REG QUERY command to read registry values
|
||||
const licenseKeyCmd = `reg query "${regPath}" /v licenseKey`;
|
||||
const apiUrlCmd = `reg query "${regPath}" /v apiUrl`;
|
||||
|
||||
const licenseKeyOutput = execSync(licenseKeyCmd, { encoding: "utf8" });
|
||||
const apiUrlOutput = execSync(apiUrlCmd, { encoding: "utf8" });
|
||||
|
||||
// Extract values from command output
|
||||
const licenseKey = extractRegValue(licenseKeyOutput);
|
||||
const apiUrl = extractRegValue(apiUrlOutput);
|
||||
|
||||
if (licenseKey && apiUrl) {
|
||||
return { licenseKey, apiUrl };
|
||||
if (licenseKey) {
|
||||
return { licenseKey };
|
||||
}
|
||||
} catch (error) {
|
||||
// Registry key might not exist, fallback to HKEY_CURRENT_USER
|
||||
|
|
@ -149,17 +145,11 @@ function readMdmKeysWindows(): MdmKeys | undefined {
|
|||
// Try HKEY_CURRENT_USER if not found in HKEY_LOCAL_MACHINE
|
||||
try {
|
||||
const licenseKeyCmd = `reg query "${userRegPath}" /v licenseKey`;
|
||||
const apiUrlCmd = `reg query "${userRegPath}" /v apiUrl`;
|
||||
|
||||
const licenseKeyOutput = execSync(licenseKeyCmd, { encoding: "utf8" });
|
||||
const apiUrlOutput = execSync(apiUrlCmd, { encoding: "utf8" });
|
||||
|
||||
// Extract values from command output
|
||||
const licenseKey = extractRegValue(licenseKeyOutput);
|
||||
const apiUrl = extractRegValue(apiUrlOutput);
|
||||
|
||||
if (licenseKey && apiUrl) {
|
||||
return { licenseKey, apiUrl };
|
||||
if (licenseKey) {
|
||||
return { licenseKey };
|
||||
}
|
||||
} catch (error) {
|
||||
// Registry key might not exist in HKCU either
|
||||
|
|
@ -199,11 +189,10 @@ function readMdmKeysLinux(): MdmKeys | undefined {
|
|||
// Parse the JSON configuration file
|
||||
const config = JSON.parse(fileContent);
|
||||
|
||||
// Check if required keys are present
|
||||
if (config.licenseKey && config.apiUrl) {
|
||||
// Check if required key is present
|
||||
if (config.licenseKey) {
|
||||
return {
|
||||
licenseKey: config.licenseKey,
|
||||
apiUrl: config.apiUrl,
|
||||
};
|
||||
}
|
||||
} catch (parseError) {
|
||||
|
|
@ -241,17 +230,20 @@ function readMdmKeys(): MdmKeys | undefined {
|
|||
/**
|
||||
* Read and validate MDM keys from the operating system's configuration files or registry.
|
||||
*/
|
||||
export function getMdmKeys(): MdmKeys | undefined {
|
||||
export function getLicenseKeyData(): LicenseKey | undefined {
|
||||
try {
|
||||
const mdmKeys = readMdmKeys();
|
||||
|
||||
if (mdmKeys) {
|
||||
if (!validateLicenseKey(mdmKeys.licenseKey)) {
|
||||
const { isValid, licenseKeyData } = validateLicenseKey(
|
||||
mdmKeys.licenseKey,
|
||||
);
|
||||
if (!isValid) {
|
||||
console.error("Invalid license key found: ", mdmKeys.licenseKey);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return mdmKeys;
|
||||
return licenseKeyData;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
|
|
@ -260,3 +252,113 @@ export function getMdmKeys(): MdmKeys | undefined {
|
|||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function writeMdmKeysMacOS(licenseKey: string): boolean {
|
||||
try {
|
||||
// Write to user-specific MDM plist
|
||||
const userMdmPath = path.join(
|
||||
os.homedir(),
|
||||
"Library/Managed Preferences/dev.continue.app.plist",
|
||||
);
|
||||
|
||||
const config = {
|
||||
licenseKey,
|
||||
};
|
||||
|
||||
// Ensure directory exists
|
||||
fs.mkdirSync(path.dirname(userMdmPath), { recursive: true });
|
||||
|
||||
// Write the plist file
|
||||
const plistContent = plist.build(config);
|
||||
fs.writeFileSync(userMdmPath, plistContent, "utf8");
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error("Error writing macOS MDM keys:", error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function writeMdmKeysWindows(licenseKey: string): boolean {
|
||||
try {
|
||||
const { execSync } = require("child_process");
|
||||
|
||||
// Use HKEY_CURRENT_USER to avoid needing admin privileges
|
||||
const userRegPath = "HKCU\\Software\\Continue\\MDM";
|
||||
|
||||
// Create the registry key if it doesn't exist
|
||||
try {
|
||||
execSync(`reg add "${userRegPath}" /f`);
|
||||
} catch (error) {
|
||||
// Key might already exist
|
||||
}
|
||||
|
||||
// Set the license key and API URL
|
||||
execSync(
|
||||
`reg add "${userRegPath}" /v licenseKey /t REG_SZ /d "${licenseKey}" /f`,
|
||||
);
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error("Error writing Windows MDM keys:", error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function writeMdmKeysLinux(licenseKey: string): boolean {
|
||||
try {
|
||||
// Write to user-specific configuration
|
||||
const userMdmPath = path.join(os.homedir(), ".config/continue/mdm.json");
|
||||
|
||||
const config = {
|
||||
licenseKey,
|
||||
};
|
||||
|
||||
// Ensure directory exists
|
||||
fs.mkdirSync(path.dirname(userMdmPath), { recursive: true });
|
||||
|
||||
// Write the JSON configuration file
|
||||
fs.writeFileSync(userMdmPath, JSON.stringify(config, null, 2), "utf8");
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error("Error writing Linux MDM keys:", error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the license key in the appropriate OS-specific location.
|
||||
* For now, we'll use a default API URL since it's not provided in the command.
|
||||
*/
|
||||
export function setMdmLicenseKey(licenseKey: string): boolean {
|
||||
try {
|
||||
// Validate the license key first
|
||||
const { isValid } = validateLicenseKey(licenseKey);
|
||||
if (!isValid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const platform = os.platform();
|
||||
|
||||
switch (platform) {
|
||||
case "darwin":
|
||||
return writeMdmKeysMacOS(licenseKey);
|
||||
|
||||
case "win32":
|
||||
return writeMdmKeysWindows(licenseKey);
|
||||
|
||||
case "linux":
|
||||
return writeMdmKeysLinux(licenseKey);
|
||||
|
||||
default:
|
||||
console.error(
|
||||
`Setting MDM keys not supported on platform: ${platform}`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error setting MDM license key:", error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -54,6 +54,7 @@ import {
|
|||
} from "./config/onboarding";
|
||||
import { createNewWorkspaceBlockFile } from "./config/workspace/workspaceBlocks";
|
||||
import { MCPManagerSingleton } from "./context/mcp/MCPManagerSingleton";
|
||||
import { setMdmLicenseKey } from "./control-plane/mdm/mdm";
|
||||
import { streamDiffLines } from "./edit/streamDiffLines";
|
||||
import { shouldIgnore } from "./indexing/shouldIgnore";
|
||||
import { walkDirCache } from "./indexing/walkDir";
|
||||
|
|
@ -755,6 +756,11 @@ export class Core {
|
|||
return isBackgrounded; // Return true to indicate the message was handled successfully
|
||||
},
|
||||
);
|
||||
|
||||
on("mdm/setLicenseKey", ({ data: { licenseKey } }) => {
|
||||
const isValid = setMdmLicenseKey(licenseKey);
|
||||
return isValid;
|
||||
});
|
||||
}
|
||||
|
||||
private async isItemTooBig(item: ContextItemWithId) {
|
||||
|
|
|
|||
|
|
@ -207,4 +207,5 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
];
|
||||
"process/markAsBackgrounded": [{ toolCallId: string }, void];
|
||||
"process/isBackgrounded": [{ toolCallId: string }, boolean];
|
||||
"mdm/setLicenseKey": [{ licenseKey: string }, boolean];
|
||||
};
|
||||
|
|
|
|||
3
extensions/vscode/package-lock.json
generated
3
extensions/vscode/package-lock.json
generated
|
|
@ -199,7 +199,8 @@
|
|||
"onnxruntime-common": "1.14.0",
|
||||
"onnxruntime-web": "1.14.0",
|
||||
"ts-jest": "^29.1.1",
|
||||
"typescript": "^5.6.3"
|
||||
"typescript": "^5.6.3",
|
||||
"vitest": "^3.1.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.19.0"
|
||||
|
|
|
|||
|
|
@ -324,6 +324,12 @@
|
|||
"category": "Continue",
|
||||
"title": "Focus Continue Chat",
|
||||
"group": "Continue"
|
||||
},
|
||||
{
|
||||
"command": "continue.enterEnterpriseLicenseKey",
|
||||
"category": "Continue",
|
||||
"title": "Enter Enterprise License Key",
|
||||
"group": "Continue"
|
||||
}
|
||||
],
|
||||
"keybindings": [
|
||||
|
|
@ -434,6 +440,9 @@
|
|||
},
|
||||
{
|
||||
"command": "continue.newSession"
|
||||
},
|
||||
{
|
||||
"command": "continue.enterEnterpriseLicenseKey"
|
||||
}
|
||||
],
|
||||
"editor/context": [
|
||||
|
|
|
|||
|
|
@ -794,19 +794,54 @@ const getCommandsMap: (
|
|||
false,
|
||||
);
|
||||
|
||||
vscode.window
|
||||
await vscode.window
|
||||
.showInformationMessage(
|
||||
"Your config.json has been converted to the new config.yaml format. If you need to switch back to config.json, you can delete or rename config.yaml.",
|
||||
"Read the docs",
|
||||
)
|
||||
.then((selection) => {
|
||||
.then(async (selection) => {
|
||||
if (selection === "Read the docs") {
|
||||
vscode.env.openExternal(
|
||||
await vscode.env.openExternal(
|
||||
vscode.Uri.parse("https://docs.continue.dev/yaml-migration"),
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
"continue.enterEnterpriseLicenseKey": async () => {
|
||||
captureCommandTelemetry("enterEnterpriseLicenseKey");
|
||||
|
||||
const licenseKey = await vscode.window.showInputBox({
|
||||
prompt: "Enter your enterprise license key",
|
||||
password: true,
|
||||
ignoreFocusOut: true,
|
||||
placeHolder: "License key",
|
||||
});
|
||||
|
||||
if (!licenseKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const isValid = core.invoke("mdm/setLicenseKey", {
|
||||
licenseKey,
|
||||
});
|
||||
|
||||
if (isValid) {
|
||||
await vscode.window.showInformationMessage(
|
||||
"Enterprise license key successfully validated and saved. Reloading window...",
|
||||
);
|
||||
await vscode.commands.executeCommand("workbench.action.reloadWindow");
|
||||
} else {
|
||||
await vscode.window.showErrorMessage(
|
||||
"Invalid license key. Please check your license key and try again.",
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
await vscode.window.showErrorMessage(
|
||||
`Failed to set enterprise license key: ${error instanceof Error ? error.message : String(error)}`,
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
3
gui/package-lock.json
generated
3
gui/package-lock.json
generated
|
|
@ -203,7 +203,8 @@
|
|||
"onnxruntime-common": "1.14.0",
|
||||
"onnxruntime-web": "1.14.0",
|
||||
"ts-jest": "^29.1.1",
|
||||
"typescript": "^5.6.3"
|
||||
"typescript": "^5.6.3",
|
||||
"vitest": "^3.1.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.19.0"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue