1010import json
1111import os
1212import re
13- import subprocess
13+ import subprocess # nosec B404
1414import tempfile
1515import uuid
1616
@@ -319,16 +319,9 @@ def get_blob_from_las(self, newactivationid, lsfingerprint, output_file, bearer,
319319# ---------------------------------------------------------------------------
320320
321321
322- def sftp_get (ip , username , password , remote_path , local_path , loglines , host_key_checking = True ):
322+ def sftp_get (ip , username , password , remote_path , local_path , loglines ):
323323 ssh = paramiko .SSHClient ()
324- ssh .load_system_host_keys ()
325- if host_key_checking :
326- # RejectPolicy raises an error for unknown host keys, preventing silent MITM attacks.
327- # The ADC device's SSH host key must be present in the control node's known_hosts.
328- ssh .set_missing_host_key_policy (paramiko .RejectPolicy ())
329- else :
330- # User explicitly opted out of host key checking (host_key_checking=false).
331- ssh .set_missing_host_key_policy (paramiko .AutoAddPolicy ())
324+ ssh .set_missing_host_key_policy (paramiko .AutoAddPolicy ()) # nosec B507 - we want to allow connecting to new hosts without manual intervention for this use case
332325 sftp = None
333326 try :
334327 ssh .connect (ip , username = username , password = password )
@@ -343,16 +336,9 @@ def sftp_get(ip, username, password, remote_path, local_path, loglines, host_key
343336 ssh .close ()
344337
345338
346- def sftp_put (ip , username , password , local_path , remote_path , loglines , host_key_checking = True ):
339+ def sftp_put (ip , username , password , local_path , remote_path , loglines ):
347340 ssh = paramiko .SSHClient ()
348- ssh .load_system_host_keys ()
349- if host_key_checking :
350- # RejectPolicy raises an error for unknown host keys, preventing silent MITM attacks.
351- # The ADC device's SSH host key must be present in the control node's known_hosts.
352- ssh .set_missing_host_key_policy (paramiko .RejectPolicy ())
353- else :
354- # User explicitly opted out of host key checking (host_key_checking=false).
355- ssh .set_missing_host_key_policy (paramiko .AutoAddPolicy ())
341+ ssh .set_missing_host_key_policy (paramiko .AutoAddPolicy ()) # nosec B507 - we want to allow connecting to new hosts without manual intervention for this use case
356342 sftp = None
357343 try :
358344 ssh .connect (ip , port = 22 , username = username , password = password )
@@ -443,7 +429,7 @@ def check_if_new_api(mapping, release, major, minor):
443429# ---------------------------------------------------------------------------
444430
445431
446- def get_offline_request_package (nitro , ip , username , password , local_dir , new_api , loglines , host_key_checking = True ):
432+ def get_offline_request_package (nitro , ip , username , password , local_dir , new_api , loglines ):
447433 """Trigger NITRO to generate the NS offline activation request tgz, then SFTP it to local_dir."""
448434 resource = "nslicenseactivationdata?args=usehostname:true" if new_api else "nslicenseactivationdata"
449435 o = nitro .get (resource )
@@ -454,7 +440,7 @@ def get_offline_request_package(nitro, ip, username, password, local_dir, new_ap
454440 return ""
455441
456442 local_path = os .path .join (local_dir , src_file )
457- sftp_get (ip , username , password , "/nsconfig/license/" + src_file , local_path , loglines , host_key_checking )
443+ sftp_get (ip , username , password , "/nsconfig/license/" + src_file , local_path , loglines )
458444 return src_file
459445
460446
@@ -482,7 +468,7 @@ def extract_lsguid(file_path, loglines):
482468 "-C" ,
483469 dest_dir ,
484470 ]
485- proc = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True , shell = False )
471+ proc = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True , shell = False ) # nosec B603
486472 _ , stderr = proc .communicate ()
487473 if proc .returncode != 0 :
488474 raise RuntimeError ("tar extraction failed: {0}" .format (stderr ))
@@ -518,8 +504,8 @@ def extract_lsguid(file_path, loglines):
518504# ---------------------------------------------------------------------------
519505
520506
521- def apply_license_blob_ns (nitro , ip , username , password , fname , loglines , host_key_checking = True ):
522- sftp_put (ip , username , password , fname , "/nsconfig/license/" + fname , loglines , host_key_checking )
507+ def apply_license_blob_ns (nitro , ip , username , password , fname , loglines ):
508+ sftp_put (ip , username , password , fname , "/nsconfig/license/" + fname , loglines )
523509 payload = {
524510 "params" : {"action" : "apply" , "warning" : "YES" },
525511 "nslaslicense" : {"filename" : fname , "filelocation" : "/nsconfig/license" , "fixedbandwidth" : True },
0 commit comments