@@ -53,11 +53,20 @@ def get_token(name, ca_url, ca_path="."):
53
53
root_crt = step_config_dir / "certs" / "root_ca.crt"
54
54
try :
55
55
token = subprocess .check_output (
56
- f"{ step_path } ca token { name } "
57
- f"--key { priv_json } --root { root_crt } "
58
- f"--password-file { pass_file } "
59
- f"--ca-url { ca_url } " ,
60
- shell = True ,
56
+ [
57
+ step_path ,
58
+ "ca" ,
59
+ "token" ,
60
+ name ,
61
+ "--key" ,
62
+ priv_json ,
63
+ "--root" ,
64
+ root_crt ,
65
+ "--password-file" ,
66
+ pass_file ,
67
+ "--ca-url" ,
68
+ ca_url ,
69
+ ]
61
70
)
62
71
except subprocess .CalledProcessError as exc :
63
72
logger .error ("Error code %s: %s" , exc .returncode , exc .output )
@@ -131,9 +140,21 @@ def certify(name, cert_path: Path, token_with_cert, ca_path: Path):
131
140
with open (f"{ cert_path } /root_ca.crt" , mode = "wb" ) as file :
132
141
file .write (root_certificate )
133
142
check_call (
134
- f"{ step_path } ca certificate { name } { cert_path } /{ name } .crt "
135
- f"{ cert_path } /{ name } .key --kty EC --curve P-384 -f --token { token } " ,
136
- shell = True ,
143
+ [
144
+ step_path ,
145
+ "ca" ,
146
+ "certificate" ,
147
+ name ,
148
+ f"{ cert_path } /{ name } .crt" ,
149
+ f"{ cert_path } /{ name } .key" ,
150
+ "--kty" ,
151
+ "EC" ,
152
+ "--curve" ,
153
+ "P-384" ,
154
+ "-f" ,
155
+ "--token" ,
156
+ token ,
157
+ ]
137
158
)
138
159
139
160
@@ -186,7 +207,7 @@ def run_ca(step_ca, pass_file, ca_json):
186
207
"""
187
208
if _check_kill_process ("step-ca" , confirmation = True ):
188
209
logger .info ("Up CA server" )
189
- check_call (f" { step_ca } --password-file { pass_file } { ca_json } " , shell = True )
210
+ check_call ([ step_ca , " --password-file" , pass_file , ca_json ] )
190
211
191
212
192
213
def _check_kill_process (pstring , confirmation = False ):
@@ -202,11 +223,22 @@ def _check_kill_process(pstring, confirmation=False):
202
223
"""
203
224
pids = []
204
225
proc = subprocess .Popen (
205
- f"ps ax | grep { pstring } | grep -v grep" ,
206
- shell = True ,
226
+ ["ps" , "ax" ],
227
+ stdout = subprocess .PIPE ,
228
+ )
229
+ grep_proc = subprocess .Popen (
230
+ ["grep" , pstring ],
231
+ stdin = proc .stdout ,
232
+ stdout = subprocess .PIPE ,
233
+ )
234
+ proc .stdout .close ()
235
+ grep_proc_2 = subprocess .Popen (
236
+ ["grep" , "-v" , "grep" ],
237
+ stdin = grep_proc .stdout ,
207
238
stdout = subprocess .PIPE ,
208
239
)
209
- text = proc .communicate ()[0 ].decode ("utf-8" )
240
+ grep_proc .stdout .close ()
241
+ text = grep_proc_2 .communicate ()[0 ].decode ("utf-8" )
210
242
211
243
for line in text .splitlines ():
212
244
fields = line .split ()
@@ -249,21 +281,38 @@ def _create_ca(ca_path: Path, ca_url: str, password: str):
249
281
shutil .rmtree (step_config_dir , ignore_errors = True )
250
282
name = ca_url .split (":" )[0 ]
251
283
check_call (
252
- f"{ step_path } ca init --name name --dns { name } "
253
- f"--address { ca_url } --provisioner prov "
254
- f"--password-file { pki_dir } /pass_file" ,
255
- shell = True ,
284
+ [
285
+ step_path ,
286
+ "ca" ,
287
+ "init" ,
288
+ "--name" ,
289
+ "name" ,
290
+ "--dns" ,
291
+ name ,
292
+ "--address" ,
293
+ ca_url ,
294
+ "--provisioner" ,
295
+ "prov" ,
296
+ "--password-file" ,
297
+ f"{ pki_dir } /pass_file" ,
298
+ ]
256
299
)
257
300
258
- check_call (f"{ step_path } ca provisioner remove prov --all" , shell = True )
301
+ check_call ([step_path , "ca" , "provisioner" , "remove" , "prov" , "--all" ])
302
+
259
303
check_call (
260
- f"{ step_path } crypto jwk create { step_config_dir } /certs/pub.json "
261
- f"{ step_config_dir } /secrets/priv.json --password-file={ pki_dir } /pass_file" ,
262
- shell = True ,
304
+ [
305
+ step_path ,
306
+ "crypto" ,
307
+ "jwk" ,
308
+ "create" ,
309
+ f"{ step_config_dir } /certs/pub.json" ,
310
+ f"{ step_config_dir } /secrets/priv.json" ,
311
+ f"--password-file={ pki_dir } /pass_file" ,
312
+ ]
263
313
)
264
314
check_call (
265
- f"{ step_path } ca provisioner add provisioner { step_config_dir } /certs/pub.json" ,
266
- shell = True ,
315
+ [step_path , "ca" , "provisioner" , "add" , "provisioner" , f"{ step_config_dir } /certs/pub.json" ]
267
316
)
268
317
269
318
0 commit comments