Skip to content

Commit

Permalink
Merge pull request #1923 from codefori/feature/sep_support
Browse files Browse the repository at this point in the history
SEP support
  • Loading branch information
worksofliam authored Apr 3, 2024
2 parents 236d0eb + 38a8243 commit 5754257
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 99 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 @@ -1749,6 +1755,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 @@ -1785,6 +1796,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 @@ -2047,7 +2066,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 @@ -2236,7 +2259,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 @@ -2438,8 +2461,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
15 changes: 10 additions & 5 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,9 +102,9 @@ 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}`,
`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 All @@ -127,9 +131,10 @@ export async function setup(connection: IBMi) {

export async function downloadClientCert(connection: IBMi) {
const localPath = getLocalCertPath(connection);
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 5754257

Please sign in to comment.