def __init__(self, tools_dir, keycfg): try: if keycfg == "": keycfg = os.path.join(tools_dir, "key_config.xml") print ("INFO: --keys option not given. ") print ("INFO: Continuing with default configuration file: " + keycfg) config_file = os.path.join(tools_dir, "ssd_bin.cfg") # temporary directories tdir = tempfile.mkdtemp() self.TEMP_F_DIR = tdir # temporary files self.IV_BIN_FNAME = os.path.join(tdir, "iv.bin") self.IEK_BIN_FNAME = os.path.join(tdir, "iek.bin") self.SSD_MD_TO_SIGN_FNAME = os.path.join(tdir, "to_sign.xml") self.config_p.readfp(open(config_file)) # Information in the config file is needed for generating the MD self.parse_config_file() if self.IEK_ENC_ALGO == "RSA-2048": self.dvc_key_fn = key_config_parser.get_rsa_pub_dvc_key(keycfg) self.dvc_key_id = key_config_parser.get_rsa_dvc_key_id_buf(keycfg) elif self.IEK_ENC_ALGO == "AES-128": self.dvc_key_fn = key_config_parser.get_aes_dvc_key(keycfg) self.dvc_key_id = key_config_parser.get_aes_dvc_key_id_buf(keycfg) else: print ("Error: Unsupported IEK_ENC_ALGO from config") exit(1) self.oem_key_fn = key_config_parser.get_rsa_pri_oem_key(keycfg) self.oem_key_id = key_config_parser.get_rsa_oem_key_id_buf(keycfg) if self.dvc_key_fn == "" or self.dvc_key_id == "" or self.oem_key_fn == "" or self.oem_key_id == "": print ("Error: Key config not correct") exit(1) # Remove previous temporary directory if True == os.path.exists(tdir) and True == os.path.isdir(tdir): shutil.rmtree(tdir) # Create temp directory for storing all temp files os.makedirs(tdir) # Initialization for encrypting&signing self.init_enc() self.init_sign("", "") except: print "Failed during init" exc_type, exc_value, exc_traceback = sys.exc_info() print "*** print_tb:" traceback.print_tb(exc_traceback, limit=1, file=sys.stdout) print "*** print_exception:" traceback.print_exception(exc_type, exc_value, exc_traceback, limit=2, file=sys.stdout) sys.exit(2)
def __init__(self, tools_dir, keycfg): try: if keycfg == "": keycfg = os.path.join(tools_dir, "key_config.xml") print("INFO: --keys option not given. ") print("INFO: Continuing with default configuration file: " + keycfg) config_file = os.path.join(tools_dir, "ssd_bin.cfg") # temporary directories tdir = tempfile.mkdtemp() self.TEMP_F_DIR = tdir # temporary files self.IV_BIN_FNAME = os.path.join(tdir, "iv.bin") self.IEK_BIN_FNAME = os.path.join(tdir, "iek.bin") self.SSD_MD_TO_SIGN_FNAME = os.path.join(tdir, "to_sign.xml") self.config_p.readfp(open(config_file)) # Information in the config file is needed for generating the MD self.parse_config_file() if (self.IEK_ENC_ALGO == "RSA-2048"): self.dvc_key_fn = key_config_parser.get_rsa_pub_dvc_key(keycfg) self.dvc_key_id = key_config_parser.get_rsa_dvc_key_id_buf( keycfg) elif (self.IEK_ENC_ALGO == "AES-128"): self.dvc_key_fn = key_config_parser.get_aes_dvc_key(keycfg) self.dvc_key_id = key_config_parser.get_aes_dvc_key_id_buf( keycfg) else: print("Error: Unsupported IEK_ENC_ALGO from config") exit(1) self.oem_key_fn = key_config_parser.get_rsa_pri_oem_key(keycfg) self.oem_key_id = key_config_parser.get_rsa_oem_key_id_buf(keycfg) if (self.dvc_key_fn == '' or self.dvc_key_id == '' or self.oem_key_fn == '' or self.oem_key_id == ''): print("Error: Key config not correct") exit(1) # Remove previous temporary directory if True == os.path.exists(tdir) and True == os.path.isdir(tdir): shutil.rmtree(tdir) # Create temp directory for storing all temp files os.makedirs(tdir) # Initialization for encrypting&signing self.init_enc() self.init_sign('', '') except: print "Failed during init" exc_type, exc_value, exc_traceback = sys.exc_info() print "*** print_tb:" traceback.print_tb(exc_traceback, limit=1, file=sys.stdout) print "*** print_exception:" traceback.print_exception(exc_type, exc_value, exc_traceback, limit=2, file=sys.stdout) sys.exit(2)