@@ -85,18 +85,6 @@ export async function remoteServerCertExists(connection: IBMi, legacy = false) {
85
85
return list . includes ( pfxPath ) ;
86
86
}
87
87
88
- export async function remoteClientCertExists ( connection : IBMi ) {
89
- const crtPath = getRemoteClientCertPath ( connection ) ;
90
-
91
- const dirList = await connection . sendCommand ( {
92
- command : `ls -p ${ crtPath } `
93
- } ) ;
94
-
95
- const list = dirList . stdout . split ( `\n` ) ;
96
-
97
- return list . includes ( crtPath ) ;
98
- }
99
-
100
88
/**
101
89
* Generate all certifcates on the server
102
90
*/
@@ -115,9 +103,9 @@ export async function setup(connection: IBMi) {
115
103
const commands = [
116
104
`openssl genrsa -out debug_service.key 2048` ,
117
105
`openssl req -new -key debug_service.key -out debug_service.csr -subj '/CN=${ host } '` ,
118
- `openssl x509 -req -in debug_service.csr -signkey debug_service.key -out debug_service.crt -days 1095 -sha256 -sha256 - req -extfile <(printf "${ extFileContent } ")` ,
106
+ `openssl x509 -req -in debug_service.csr -signkey debug_service.key -out debug_service.crt -days 1095 -sha256 -req -extfile <(printf "${ extFileContent } ")` ,
119
107
`openssl pkcs12 -export -out debug_service.pfx -inkey debug_service.key -in debug_service.crt -password pass:${ host } ` ,
120
- `rm debug_service.key debug_service.csr` ,
108
+ `rm debug_service.key debug_service.csr debug_service.crt ` ,
121
109
`chmod 444 debug_service.pfx`
122
110
] ;
123
111
@@ -141,11 +129,19 @@ export async function setup(connection: IBMi) {
141
129
}
142
130
}
143
131
144
- export function downloadClientCert ( connection : IBMi ) {
145
- const remotePath = getRemoteClientCertPath ( connection ) ;
132
+ export async function downloadClientCert ( connection : IBMi ) {
146
133
const localPath = getLocalCertPath ( connection ) ;
147
134
148
- return connection . downloadFile ( localPath , remotePath ) ;
135
+ const result = await connection . sendCommand ( {
136
+ command : `openssl s_client -connect localhost:${ connection . config ?. debugPort } -showcerts < /dev/null 2> /dev/null | openssl x509 -outform PEM` ,
137
+ directory : getRemoteCertDirectory ( connection )
138
+ } ) ;
139
+
140
+ if ( result . code && result . code > 0 ) {
141
+ throw new Error ( `Failed to download client certificate.` ) ;
142
+ }
143
+
144
+ await fs . writeFile ( localPath , result . stdout , { encoding : `utf8` } ) ;
149
145
}
150
146
151
147
export function getLocalCertPath ( connection : IBMi ) {
0 commit comments