Skip to content

Commit

Permalink
Merge branch 'master' into feature/debugStatus
Browse files Browse the repository at this point in the history
Signed-off-by: Seb Julliand <[email protected]>
  • Loading branch information
sebjulliand committed Apr 4, 2024
2 parents a0f1007 + 8dc66ba commit 17d37ca
Show file tree
Hide file tree
Showing 15 changed files with 408 additions and 148 deletions.
41 changes: 32 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,14 @@
"default": "8005",
"description": "Port to connect to IBM i Debug Service."
},
"debugSepPort": {
"type": "string",
"default": "8008",
"description": "Port to connect to IBM i Debug Service for SEP."
},
"debugIsSecure": {
"type": "boolean",
"default": false,
"default": true,
"description": "Used to determine if the client should connect securely or not."
},
"debugUpdateProductionFiles": {
Expand Down Expand Up @@ -956,16 +961,17 @@
"enablement": "code-for-ibmi:connected && code-for-ibmi:debugManaged != true"
},
{
"command": "code-for-ibmi.debug.activeEditor",
"title": "Start Debugging Active Source",
"command": "code-for-ibmi.debug.batch",
"title": "Debug as Batch",
"category": "IBM i",
"icon": "$(debug-alt)",
"enablement": "code-for-ibmi:connected"
},
{
"command": "code-for-ibmi.debug.program",
"title": "Debug Program",
"command": "code-for-ibmi.debug.sep",
"title": "Set Service Entry Point",
"category": "IBM i",
"icon": "$(debug-alt)",
"enablement": "code-for-ibmi:connected"
},
{
Expand Down Expand Up @@ -1754,6 +1760,11 @@
{
"id": "code-for-ibmi.openMember",
"label": "Open"
},
{
"id": "code-for-ibmi.debug.group",
"label": "Start Debugging",
"icon": "$(debug-start)"
}
],
"menus": {
Expand Down Expand Up @@ -1790,6 +1801,14 @@
"when": "viewItem == member"
}
],
"code-for-ibmi.debug.group": [
{
"command": "code-for-ibmi.debug.batch"
},
{
"command": "code-for-ibmi.debug.sep"
}
],
"commandPalette": [
{
"command": "code-for-ibmi.userLibraryList.enable",
Expand Down Expand Up @@ -2052,7 +2071,11 @@
"when": "never"
},
{
"command": "code-for-ibmi.debug.program",
"command": "code-for-ibmi.debug.batch",
"when": "never"
},
{
"command": "code-for-ibmi.debug.sep",
"when": "never"
},
{
Expand Down Expand Up @@ -2245,7 +2268,7 @@
],
"editor/title": [
{
"command": "code-for-ibmi.debug.activeEditor",
"submenu": "code-for-ibmi.debug.group",
"when": "code-for-ibmi:connected && !inDebugMode && editorLangId =~ /^rpgle$|^rpg$|^cobol$|^cl$/i",
"group": "navigation@1"
},
Expand Down Expand Up @@ -2447,8 +2470,8 @@
"group": "1_workspace@1"
},
{
"command": "code-for-ibmi.debug.program",
"when": "view == objectBrowser && !inDebugMode && viewItem =~ /^object.pgm.*/",
"submenu": "code-for-ibmi.debug.group",
"when": "view == objectBrowser && !inDebugMode && (viewItem =~ /^object.pgm.*/ || viewItem =~ /^object.srvpgm.*/)",
"group": "2_debug@1"
},
{
Expand Down
2 changes: 2 additions & 0 deletions src/api/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export namespace ConnectionConfiguration {
showDescInLibList: boolean;
debugCertDirectory: string;
debugPort: string;
debugSepPort: string;
debugIsSecure: boolean;
debugUpdateProductionFiles: boolean;
debugEnableDebugTracing: boolean;
Expand Down Expand Up @@ -137,6 +138,7 @@ export namespace ConnectionConfiguration {
showDescInLibList: (parameters.showDescInLibList === true),
debugCertDirectory: (parameters.debugCertDirectory || DEFAULT_CERT_DIRECTORY),
debugPort: (parameters.debugPort || "8005"),
debugSepPort: (parameters.debugSepPort || "8008"),
debugIsSecure: (parameters.debugIsSecure === true),
debugUpdateProductionFiles: (parameters.debugUpdateProductionFiles === true),
debugEnableDebugTracing: (parameters.debugEnableDebugTracing === true),
Expand Down
53 changes: 31 additions & 22 deletions src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,21 +484,28 @@ export default class IBMiContent {
return true;
});

const sanitized = Tools.sanitizeLibraryNames(newLibl);

const result = await this.ibmi.sendQsh({
command: [
`liblist -d ` + Tools.sanitizeLibraryNames(this.ibmi.defaultUserLibraries).join(` `),
...newLibl.map(lib => `liblist -a ` + Tools.sanitizeLibraryNames([lib]))
...sanitized.map(lib => `liblist -a ` + lib)
].join(`; `)
});

if (result.stderr) {
const lines = result.stderr.split(`\n`);

lines.forEach(line => {
const badLib = newLibl.find(lib => line.includes(`ibrary ${lib} `) || line.includes(`ibrary ${Tools.sanitizeLibraryNames([lib])} `));
const isNotFound = line.includes(`CPF2110`);
if (isNotFound) {
const libraryReference = sanitized.find(lib => line.includes(lib));

// If there is an error about the library, remove it
if (badLib) badLibs.push(badLib);
// If there is an error about the library, remove it
if (libraryReference) {
badLibs.push(libraryReference);
}
}
});
}

Expand Down Expand Up @@ -778,22 +785,24 @@ export default class IBMiContent {
}

async memberResolve(member: string, files: QsysPath[]): Promise<IBMiMember | undefined> {
const inAmerican = (s: string) => { return this.ibmi.sysNameInAmerican(s) };
const inLocal = (s: string) => { return this.ibmi.sysNameInLocal(s) };

// Escape names for shell
const pathList = this.ibmi.upperCaseName(
files
.map(file => {
const asp = file.asp || this.config.sourceASP;
if (asp && asp.length > 0) {
return [
Tools.qualifyPath(file.library, file.name, member, asp, true),
Tools.qualifyPath(file.library, file.name, member, undefined, true)
].join(` `);
} else {
return Tools.qualifyPath(file.library, file.name, member, undefined, true);
}
})
.join(` `)
);
const pathList = files
.map(file => {
const asp = file.asp || this.config.sourceASP;
if (asp && asp.length > 0) {
return [
Tools.qualifyPath(inAmerican(file.library), inAmerican(file.name), inAmerican(member), asp, true),
Tools.qualifyPath(inAmerican(file.library), inAmerican(file.name), inAmerican(member), undefined, true)
].join(` `);
} else {
return Tools.qualifyPath(inAmerican(file.library), inAmerican(file.name), inAmerican(member), undefined, true);
}
})
.join(` `)
.toUpperCase();

const command = `for f in ${pathList}; do if [ -f $f ]; then echo $f; break; fi; done`;
const result = await this.ibmi.sendCommand({
Expand All @@ -805,7 +814,7 @@ export default class IBMiContent {

if (firstMost) {
try {
const simplePath = Tools.unqualifyPath(firstMost);
const simplePath = inLocal(Tools.unqualifyPath(firstMost));

// This can error if the path format is wrong for some reason.
// Not that this would ever happen, but better to be safe than sorry
Expand All @@ -820,7 +829,7 @@ export default class IBMiContent {
}

async objectResolve(object: string, libraries: string[]): Promise<string | undefined> {
const command = `for f in ${libraries.map(lib => `/QSYS.LIB/${this.ibmi.upperCaseName(lib)}.LIB/${this.ibmi.upperCaseName(object)}.*`).join(` `)}; do if [ -f $f ] || [ -d $f ]; then echo $f; break; fi; done`;
const command = `for f in ${libraries.map(lib => `/QSYS.LIB/${this.ibmi.sysNameInAmerican(lib)}.LIB/${this.ibmi.sysNameInAmerican(object)}.*`).join(` `)}; do if [ -f $f ] || [ -d $f ]; then echo $f; break; fi; done`;

const result = await this.ibmi.sendCommand({
command,
Expand All @@ -830,7 +839,7 @@ export default class IBMiContent {
const firstMost = result.stdout;

if (firstMost) {
const lib = Tools.unqualifyPath(firstMost);
const lib = this.ibmi.sysNameInLocal(Tools.unqualifyPath(firstMost));

return lib.split('/')[1];
}
Expand Down
18 changes: 12 additions & 6 deletions src/api/debug/certificates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ function getLegacyCertificatePath() {
return path.posix.join(LEGACY_CERT_DIRECTORY, SERVER_CERTIFICATE);
}

function getPasswordForHost(connection: IBMi) {
return connection.currentHost;
}

export function getRemoteServerCertificatePath(connection: IBMi) {
return path.posix.join(getRemoteCertificateDirectory(connection), SERVER_CERTIFICATE);
}
Expand All @@ -85,8 +89,8 @@ export async function remoteServerCertificateExists(connection: IBMi, legacy = f
* Generate all certifcates on the server
*/
export async function setup(connection: IBMi) {
const host = connection.currentHost;
const extFileContent = await getExtFileContent(host, connection);
const pw = getPasswordForHost(connection);
const extFileContent = await getExtFileContent(pw, connection);

if (!connection.usingBash()) {
if (connection.remoteFeatures[`bash`]) {
Expand All @@ -98,10 +102,10 @@ export async function setup(connection: IBMi) {

const commands = [
`openssl genrsa -out debug_service.key 2048`,
`openssl req -new -key debug_service.key -out debug_service.csr -subj '/CN=${host}'`,
`openssl req -new -key debug_service.key -out debug_service.csr -subj '/CN=${pw}'`,
`openssl x509 -req -in debug_service.csr -signkey debug_service.key -out debug_service.crt -days 1095 -sha256 -req -extfile <(printf "${extFileContent}")`,
`openssl pkcs12 -export -out debug_service.pfx -inkey debug_service.key -in debug_service.crt -password pass:${host}`,
`rm debug_service.key debug_service.csr debug_service.crt`,
`openssl pkcs12 -export -out debug_service.pfx -inkey debug_service.key -in debug_service.crt -password pass:${pw}`,
`rm debug_service.key debug_service.csr debug_service.crt`,
`chmod 444 debug_service.pfx`
];

Expand Down Expand Up @@ -131,8 +135,10 @@ export async function downloadClientCert(connection: IBMi) {
}

export async function readRemoteCertificate(connection: IBMi) {
const keyPass = getPasswordForHost(connection);

const result = await connection.sendCommand({
command: `openssl s_client -connect localhost:${connection.config?.debugPort} -showcerts < /dev/null 2> /dev/null | openssl x509 -outform PEM`,
command: `openssl pkcs12 -in ${getRemoteServerCertificatePath(connection)} -passin pass:${keyPass} -info -nokeys -clcerts 2>/dev/null | openssl x509 -outform PEM`,
directory: getRemoteCertificateDirectory(connection)
});

Expand Down
Loading

0 comments on commit 17d37ca

Please sign in to comment.