Skip to content

Commit eeefbbb

Browse files
committed
Cleanup and renaming
Signed-off-by: Seb Julliand <[email protected]>
1 parent 46fafa1 commit eeefbbb

File tree

4 files changed

+45
-51
lines changed

4 files changed

+45
-51
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -937,13 +937,13 @@
937937
},
938938
{
939939
"command": "code-for-ibmi.debug.setup.remote",
940-
"title": "Setup Remote Certificates",
940+
"title": "Setup Service Certificate",
941941
"category": "IBM i Debug",
942942
"enablement": "code-for-ibmi:connected && code-for-ibmi:debugManaged != true"
943943
},
944944
{
945945
"command": "code-for-ibmi.debug.setup.local",
946-
"title": "Import Local Certificate",
946+
"title": "Import Client Certificate",
947947
"category": "IBM i Debug",
948948
"enablement": "code-for-ibmi:connected && code-for-ibmi:debugManaged != true"
949949
},

src/api/debug/certificates.ts

+22-26
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import path from "path";
2-
import {promises as fs} from "fs";
3-
import * as os from "os";
4-
import IBMi from "../IBMi";
51
import * as dns from 'dns';
6-
import {window} from "vscode";
2+
import { promises as fs } from "fs";
3+
import * as os from "os";
4+
import path from "path";
5+
import { window } from "vscode";
76
import { ConnectionConfiguration } from "../Configuration";
7+
import IBMi from "../IBMi";
88

9-
const serverCertName = `debug_service.pfx`;
10-
const clientCertName = `debug_service.crt`;
9+
const SERVER_CERTIFICATE = `debug_service.pfx`;
10+
const CLIENT_CERTIFICATE = `debug_service.crt`;
1111

1212
export const LEGACY_CERT_DIRECTORY = `/QIBM/ProdData/IBMiDebugService/bin/certs`;
1313
export const DEFAULT_CERT_DIRECTORY = `/QIBM/UserData/IBMiDebugService/certs`;
1414

15-
export function getRemoteCertDirectory(connection: IBMi) {
15+
export function getRemoteCertificateDirectory(connection: IBMi) {
1616
return connection.config?.debugCertDirectory!;
1717
}
1818

@@ -61,20 +61,16 @@ async function getExtFileContent(host: string, connection: IBMi) {
6161
return extFileContent;
6262
}
6363

64-
function getLegacyCertPath() {
65-
return path.posix.join(LEGACY_CERT_DIRECTORY, serverCertName);
66-
}
67-
68-
export function getRemoteServerCertPath(connection: IBMi) {
69-
return path.posix.join(getRemoteCertDirectory(connection), serverCertName);
64+
function getLegacyCertificatePath() {
65+
return path.posix.join(LEGACY_CERT_DIRECTORY, SERVER_CERTIFICATE);
7066
}
7167

72-
export function getRemoteClientCertPath(connection: IBMi) {
73-
return path.posix.join(getRemoteCertDirectory(connection), clientCertName);
68+
export function getRemoteServerCertificatePath(connection: IBMi) {
69+
return path.posix.join(getRemoteCertificateDirectory(connection), SERVER_CERTIFICATE);
7470
}
7571

76-
export async function remoteServerCertExists(connection: IBMi, legacy = false) {
77-
const pfxPath = legacy ? getLegacyCertPath() : getRemoteServerCertPath(connection);
72+
export async function remoteServerCertificateExists(connection: IBMi, legacy = false) {
73+
const pfxPath = legacy ? getLegacyCertificatePath() : getRemoteServerCertificatePath(connection);
7874

7975
const dirList = await connection.sendCommand({
8076
command: `ls -p ${pfxPath}`
@@ -109,14 +105,14 @@ export async function setup(connection: IBMi) {
109105
`chmod 444 debug_service.pfx`
110106
];
111107

112-
const directory = getRemoteCertDirectory(connection);
108+
const directory = getRemoteCertificateDirectory(connection);
113109

114110
const mkdirResult = await connection.sendCommand({
115111
command: `mkdir -p ${directory}`
116112
});
117113

118114
if (mkdirResult.code && mkdirResult.code > 0) {
119-
throw new Error(`Failed to create certificate directory: ${directory}`);
115+
throw new Error(`Failed to create server certificate directory: ${directory}`);
120116
}
121117

122118
const creationResults = await connection.sendCommand({
@@ -125,7 +121,7 @@ export async function setup(connection: IBMi) {
125121
});
126122

127123
if (creationResults.code && creationResults.code > 0) {
128-
throw new Error(`Failed to create certificates.`);
124+
throw new Error(`Failed to create server certificate.`);
129125
}
130126
}
131127

@@ -134,7 +130,7 @@ export async function downloadClientCert(connection: IBMi) {
134130

135131
const result = await connection.sendCommand({
136132
command: `openssl s_client -connect localhost:${connection.config?.debugPort} -showcerts < /dev/null 2> /dev/null | openssl x509 -outform PEM`,
137-
directory: getRemoteCertDirectory(connection)
133+
directory: getRemoteCertificateDirectory(connection)
138134
});
139135

140136
if (result.code && result.code > 0) {
@@ -146,7 +142,7 @@ export async function downloadClientCert(connection: IBMi) {
146142

147143
export function getLocalCertPath(connection: IBMi) {
148144
const host = connection.currentHost;
149-
return path.join(os.homedir(), `${host}_${clientCertName}`);
145+
return path.join(os.homedir(), `${host}_${CLIENT_CERTIFICATE}`);
150146
}
151147

152148
export async function localClientCertExists(connection: IBMi) {
@@ -162,8 +158,8 @@ export async function localClientCertExists(connection: IBMi) {
162158
export async function legacyCertificateChecks(connection: IBMi, existingDebugService: string|undefined) {
163159
// We need to migrate away from using the old legacy directory to a new one if
164160
// the user has the old directory configured but isn't running the server
165-
const usingLegacyCertPath = (getRemoteCertDirectory(connection) === LEGACY_CERT_DIRECTORY);
166-
const certsExistAtConfig = await remoteServerCertExists(connection);
161+
const usingLegacyCertPath = (getRemoteCertificateDirectory(connection) === LEGACY_CERT_DIRECTORY);
162+
const certsExistAtConfig = await remoteServerCertificateExists(connection);
167163

168164
let changeCertDirConfig: string|undefined;
169165

@@ -198,7 +194,7 @@ export async function legacyCertificateChecks(connection: IBMi, existingDebugSer
198194
if (!certsExistAtConfig) {
199195
// The server is running but the certs don't exist in the new path, let's
200196
// check if they exist at the legacy path and switch back to that
201-
const legacyCertsExist = await remoteServerCertExists(connection, true);
197+
const legacyCertsExist = await remoteServerCertificateExists(connection, true);
202198
if (legacyCertsExist) {
203199
changeCertDirConfig = LEGACY_CERT_DIRECTORY;
204200
}

src/api/debug/index.ts

+20-22
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { ExtensionContext, Uri } from "vscode";
22
import Instance from "../Instance";
33

4-
import * as vscode from 'vscode';
54
import path from "path";
5+
import * as vscode from 'vscode';
66

7-
import * as certificates from "./certificates";
8-
import * as server from "./server";
97
import { copyFileSync } from "fs";
108
import { instance } from "../../instantiate";
11-
import { getEnvConfig } from "../local/env";
129
import { ILELibrarySettings } from "../CompileTools";
10+
import { getEnvConfig } from "../local/env";
11+
import * as certificates from "./certificates";
12+
import * as server from "./server";
1313

1414
const debugExtensionId = `IBM.ibmidebug`;
1515

@@ -60,7 +60,7 @@ export async function initialize(context: ExtensionContext) {
6060

6161
if (config.debugIsSecure && !isManaged()) {
6262
if (!await certificates.localClientCertExists(connection)) {
63-
vscode.window.showInformationMessage(`Debug Service Certificates`, {
63+
vscode.window.showInformationMessage(`Debug Service Certificate`, {
6464
modal: true,
6565
detail: `Debug client certificate is not setup.`
6666
},
@@ -102,7 +102,7 @@ export async function initialize(context: ExtensionContext) {
102102
detail: `The IBM i Debug extension is not installed. It can be installed from the Marketplace.`,
103103
modal: true
104104
}, `Go to Marketplace`).then(result => {
105-
if (result === `Go to Marketplace`) {
105+
if (result) {
106106
vscode.commands.executeCommand('code-for-ibmi.debug.extension');
107107
}
108108
});
@@ -230,8 +230,7 @@ export async function initialize(context: ExtensionContext) {
230230
const ptfInstalled = debugPTFInstalled();
231231

232232
if (ptfInstalled) {
233-
const remoteCertExists = await certificates.remoteServerCertExists(connection);
234-
let remoteCertsAreNew = false;
233+
const remoteCertExists = await certificates.remoteServerCertificateExists(connection);
235234
let remoteCertsOk = false;
236235

237236
if (remoteCertExists) {
@@ -243,8 +242,8 @@ export async function initialize(context: ExtensionContext) {
243242
const doSetup = await vscode.window.showInformationMessage(`Debug setup`, {
244243
modal: true,
245244
detail: `${remoteCertExists
246-
? `Debug certificates already exist on this system! This will download the client certificates to enable secure debugging.`
247-
: `Debug certificates are not setup on the system. This will generate the certificates and download them to your device.`
245+
? `Debug service certificate already exist on this system! This will download the client certificate to enable secure debugging.`
246+
: `Debug service certificate is not setup on the system. This will generate the server certificate and download the client certificate to your device.`
248247
} Continue with setup?`
249248
}, `Continue`);
250249

@@ -253,9 +252,8 @@ export async function initialize(context: ExtensionContext) {
253252
// If the remote certs don't exist, generate them
254253
if (!remoteCertExists) {
255254
await certificates.setup(connection);
256-
vscode.window.showInformationMessage(`Certificates successfully generated on server.`);
255+
vscode.window.showInformationMessage(`Certificate successfully generated on server.`);
257256
remoteCertsOk = true;
258-
remoteCertsAreNew = true;
259257
}
260258
} catch (e: any) {
261259
vscode.window.showErrorMessage(e.message || e);
@@ -286,34 +284,34 @@ export async function initialize(context: ExtensionContext) {
286284

287285
try {
288286
const existingDebugService = await server.getRunningJob(connection.config?.debugPort || "8005", instance.getContent()!);
289-
const remoteCertExists = await certificates.remoteServerCertExists(connection);
287+
const remoteCertExists = await certificates.remoteServerCertificateExists(connection);
290288

291289
// If the client certificate exists on the server, download it
292290
if (remoteCertExists) {
293291
if (existingDebugService) {
294292
await certificates.downloadClientCert(connection);
295293
localCertsOk = true;
296-
vscode.window.showInformationMessage(`Debug certificate downloaded from the server.`);
294+
vscode.window.showInformationMessage(`Debug client certificate downloaded from the server.`);
297295
} else {
298296
vscode.window.showInformationMessage(`Cannot fetch client certificate because the Debug Service is not running.`, `Startup Service`).then(result => {
299-
if (result === `Startup Service`) {
297+
if (result) {
300298
vscode.commands.executeCommand(`code-for-ibmi.debug.start`);
301299
}
302300
});
303301
}
304-
305302
} else {
306303
const doImport = await vscode.window.showInformationMessage(`Debug setup`, {
307304
modal: true,
308-
detail: `The server certificate is not setup on the server. Would you like to import a certificate from your device?`
305+
detail: `The debug service certificate is not setup on the server. Would you like to import a server certificate from your device?`
309306
}, `Yes`, `No`);
310307

311308
if (doImport === `Yes`) {
312309
const selectedFile = await vscode.window.showOpenDialog({
313310
canSelectFiles: true,
314311
canSelectFolders: false,
315312
canSelectMany: false,
316-
title: `Select debug client certificate`
313+
title: `Select debug service certificate`,
314+
filters: { "PFX certificate": ["pfx"] }
317315
});
318316

319317
if (selectedFile && selectedFile.length === 1) {
@@ -328,7 +326,7 @@ export async function initialize(context: ExtensionContext) {
328326
}
329327
} else {
330328
vscode.window.showInformationMessage(`Import of debug client certificate skipped as not required in current mode.`, `Open configuration`).then(result => {
331-
if (result === `Open configuration`) {
329+
if (result) {
332330
vscode.commands.executeCommand(`code-for-ibmi.showAdditionalSettings`, undefined, `Debugger`);
333331
}
334332
});
@@ -348,7 +346,7 @@ export async function initialize(context: ExtensionContext) {
348346
if (connection) {
349347
const ptfInstalled = debugPTFInstalled();
350348
if (ptfInstalled) {
351-
const remoteExists = await certificates.remoteServerCertExists(connection);
349+
const remoteExists = await certificates.remoteServerCertificateExists(connection);
352350
if (remoteExists) {
353351
vscode.window.withProgress({ location: vscode.ProgressLocation.Notification }, async (progress) => {
354352

@@ -429,7 +427,7 @@ export async function initialize(context: ExtensionContext) {
429427

430428
await certificates.legacyCertificateChecks(connection, existingDebugService);
431429

432-
const remoteCertsExist = await certificates.remoteServerCertExists(connection);
430+
const remoteCertsExist = await certificates.remoteServerCertificateExists(connection);
433431

434432
if (remoteCertsExist) {
435433
vscode.commands.executeCommand(`setContext`, remoteCertContext, true);
@@ -449,7 +447,7 @@ export async function initialize(context: ExtensionContext) {
449447
`Looks like you have the debug PTF but don't have it configured.`
450448
} Do you want to see the Walkthrough to set it up?`, `Take me there`);
451449

452-
if (openTut === `Take me there`) {
450+
if (openTut) {
453451
vscode.commands.executeCommand(`workbench.action.openWalkthrough`, `halcyontechltd.vscode-ibmi-walkthroughs#code-ibmi-debug`);
454452
}
455453
}

src/api/debug/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export async function startup(connection: IBMi) {
2525

2626
const password = encryptResult.stdout;
2727

28-
const keystorePath = certificates.getRemoteServerCertPath(connection);
28+
const keystorePath = certificates.getRemoteServerCertificatePath(connection);
2929

3030
connection.sendCommand({
3131
command: `${MY_JAVA_HOME} DEBUG_SERVICE_KEYSTORE_PASSWORD="${password}" DEBUG_SERVICE_KEYSTORE_FILE="${keystorePath}" /QOpenSys/usr/bin/nohup "${path.posix.join(serverDirectory, `startDebugService.sh`)}"`

0 commit comments

Comments
 (0)