-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce601ef
commit 33e3a16
Showing
5 changed files
with
53 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
@@ -1,28 +1,55 @@ | ||
import { promises as fs } from 'fs'; | ||
import * as path from 'path'; | ||
import { exec } from 'child_process'; | ||
import { promisify } from 'util'; | ||
|
||
export const SYSTEM_ROOT = process.env['SystemRoot'] || 'C:\\Windows'; | ||
|
||
const serviceFile = 'gksvc.exe'; | ||
const keyProvFile = 'gkcng.dll'; | ||
const certProvFile = 'gkcertsvc.dll'; | ||
const utilFile = 'gkutils.exe'; | ||
const allFiles = [serviceFile, keyProvFile, certProvFile, utilFile]; | ||
|
||
const execAsync = promisify(exec); | ||
|
||
export async function installGoodKey(distDir: string, systemDir: string) { | ||
for (const file of allFiles) { | ||
const srcPath = path.join(distDir, file); | ||
const destPath = path.join(systemDir, file); | ||
await fs.copyFile(srcPath, destPath); | ||
} | ||
try { | ||
|
||
for (const file of allFiles) { | ||
const srcPath = path.join(distDir, file); | ||
const destPath = path.join(systemDir, file); | ||
await fs.copyFile(srcPath, destPath); | ||
} | ||
|
||
// Register DLLs | ||
await exec(`regsvr32.exe /s "${path.join(systemDir, keyProvFile)}"`); | ||
await exec(`regsvr32.exe /s "${path.join(systemDir, certProvFile)}"`); | ||
// Register DLLs | ||
await execAsync(`regsvr32.exe /s "${path.join(systemDir, keyProvFile)}"`); | ||
await execAsync(`regsvr32.exe /s "${path.join(systemDir, certProvFile)}"`); | ||
|
||
// Install service | ||
await exec(`sc create gksvc binPath= "${path.join(systemDir, serviceFile)}" start= auto`); | ||
// Install service | ||
await execAsync(`sc create gksvc binPath= "${path.join(systemDir, serviceFile)}" start= auto`); | ||
|
||
// Get User status using gkutils | ||
const { stdout } = await exec(`${path.join(systemDir, utilFile)} auth status`); | ||
console.log(stdout); | ||
// Get User status using `gkutils auth status` and log it | ||
const { stdout } = await execAsync(`${path.join(systemDir, utilFile)} auth status`); | ||
console.log(stdout); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
const message = 'stdout' in error && error.stdout ? error.stdout.toString() : error.message; | ||
throw new Error(`Installation of GoodKey failed: ${message}`); | ||
} | ||
throw error; | ||
} | ||
} | ||
|
||
export async function registerUser(token: string, organizationId: string) { | ||
try { | ||
const { stdout } = await execAsync(`${path.join(SYSTEM_ROOT, 'System32', utilFile)} auth register -t ${token} -o ${organizationId}`); | ||
console.log(stdout); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
const message = 'stdout' in error && error.stdout ? error.stdout.toString() : error.message; | ||
throw new Error(`Registration of user failed: ${message}`); | ||
} | ||
throw error; | ||
} | ||
} |