import securexgboost as xgb import os from sklearn.datasets import dump_svmlight_file username = "******" HOME_DIR = os.path.dirname(os.path.realpath(__file__)) + "/../../" sym_key_file = HOME_DIR + "demo/data/key_zeros.txt" pub_key_file = HOME_DIR + "demo/data/userkeys/private_user_1.pem" cert_file = HOME_DIR + "demo/data/usercrts/{0}.crt".format(username) temp_name = HOME_DIR + "demo/data/temp_file.txt" temp_enc_name = HOME_DIR + "demo/data/temp_file.txt.enc" print("Init user parameters") xgb.init_user(username, sym_key_file, pub_key_file, cert_file) print("Creating enclave") enclave = xgb.Enclave(HOME_DIR + "build/enclave/xgboost_enclave.signed") # Remote Attestation print("Remote attestation") # Note: Simulation mode does not support attestation # pass in `verify=False` to attest() enclave.attest(verify=False) print("Send private key to enclave") enclave.add_key()
import securexgboost as xgb import os DIR = os.path.dirname(os.path.realpath(__file__)) HOME_DIR = DIR + "/../../../" SYM_KEY_FILE = DIR + "/../../data/key_zeros.txt" PRIVATE_KEY_FILE = HOME_DIR + "config/user1.pem" CERT_FILE = HOME_DIR + "config/user1.crt" username = "******" xgb.init_user(username, SYM_KEY_FILE, PRIVATE_KEY_FILE, CERT_FILE) print("Creating enclave") enclave = xgb.Enclave(HOME_DIR + "build/enclave/xgboost_enclave.signed") # Remote Attestation print("Remote attestation") # Note: Simulation mode does not support attestation # pass in `verify=False` to attest() enclave.attest() print("Send private key to enclave") enclave.add_key() rabit_args = { "DMLC_NUM_WORKER": os.environ.get("DMLC_NUM_WORKER"), "DMLC_NUM_SERVER": os.environ.get("DMLC_NUM_SERVER"), "DMLC_TRACKER_URI": os.environ.get("DMLC_TRACKER_URI"), "DMLC_TRACKER_PORT": os.environ.get("DMLC_TRACKER_PORT"), "DMLC_ROLE": os.environ.get("DMLC_ROLE"), "DMLC_NODE_HOST": os.environ.get("DMLC_NODE_HOST")
log_verbosity=0) # Remote Attestation print("Remote attestation") # Note: Simulation mode does not support attestation # pass in `verify=False` to attest() enclave.attest() username1 = "user1" train_enc_1 = HOME_DIR + "demo/python/multiclient-distributed/data/u1_train.enc" KEY_FILE_1 = HOME_DIR + "demo/python/multiclient-distributed/data/key1.txt" PRIVATE_KEY_FILE_1 = HOME_DIR + "config/user1.pem" CERT_FILE_1 = HOME_DIR + "config/user1.crt" xgb.init_user(username1, KEY_FILE_1, PRIVATE_KEY_FILE_1, CERT_FILE_1) print("Send private key to enclave") enclave.add_key() username2 = "user2" train_enc_2 = HOME_DIR + "demo/python/multiclient-distributed/data/u2_train.enc" test_enc_2 = HOME_DIR + "demo/python/multiclient-distributed/data/u2_test.enc" KEY_FILE_2 = HOME_DIR + "demo/python/multiclient-distributed/data/key2.txt" PRIVATE_KEY_FILE_2 = HOME_DIR + "config/user2.pem" CERT_FILE_2 = HOME_DIR + "config/user2.crt" xgb.init_user(username2, KEY_FILE_2, PRIVATE_KEY_FILE_2, CERT_FILE_2) print("Send private key to enclave") enclave.add_key()
def run(channel_addr, sym_key_file, priv_key_file, cert_file): xgb.init_user(username, sym_key_file, priv_key_file, cert_file) # Remote attestation print("Remote attestation") enclave_reference = xgb.Enclave(addr=channel_addr) # Note: Simulation mode does not support attestation # pass in `verify=False` to attest() enclave_reference.attest() print("Report successfully verified") print("Send private key to enclave") enclave_reference.add_key() print("Creating training matrix") dtrain = xgb.DMatrix({username: HOME_DIR + "demo/python/remote-control/data/train.enc"}) if not dtrain: print("Error creating dtrain") return print("dtrain: " + dtrain.handle.value.decode("utf-8")) print("Creating test matrix") dtest = xgb.DMatrix({username: HOME_DIR + "demo/python/remote-control/data/test.enc"}) if not dtest: print("Error creating dtest") return print("dtest: " + dtest.handle.value.decode("utf-8")) print("Beginning Training") # Set training parameters params = { "tree_method": "hist", "n_gpus": "0", "objective": "binary:logistic", "min_child_weight": "1", "gamma": "0.1", "max_depth": "3", "verbosity": "0" } # Train and evaluate num_rounds = 5 print("Training...") booster = xgb.train(params, dtrain, num_rounds) print("booster: " + booster.handle.value.decode("utf-8")) booster.save_model(HOME_DIR + "demo/python/remote-control/client/modelfile.model") # Get encrypted predictions print("\nModel Predictions: ") predictions, num_preds = booster.predict(dtest, decrypt=False) # Decrypt predictions print(booster.decrypt_predictions(predictions, num_preds)) # Get fscores of model print("\nModel Feature Importance: ") print(booster.get_fscore())