def main()

in resources/code/my-first-enclave/cryptographic-attestation/client.py [0:0]


def main():

    args = parse_args()

    if args.prepare is True:
        kms = boto3.client("kms", region_name=REGION)
        arr = parse_input(args.values)
        rand_val = select_random_value(arr)
        base64_cipher_text = encrypt_string(rand_val, args.alias, kms)
        file = open("string.encrypted", "w")
        file.write(base64_cipher_text)
        file.close
        exit()
    elif args.submit is True:
        ciphertext = args.ciphertext.read()

        # Get EC2 instance metedata and prepare JSON to send to server
        credential = prepare_server_request(ciphertext)

        # Create a vsock socket object
        s = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)

        # Get CID from command line parameter
        cid = get_cid()

        # The port should match the server running in enclave
        port = 5000

        # Connect to the server
        s.connect((cid, port))

        # Send AWS credential to the server running in enclave
        s.send(str.encode(json.dumps(credential)))

        # receive data from the server
        r = s.recv(4096).decode()

        #parse response
        parsed = json.loads(r)

        #pretty print response
        print(json.dumps(parsed, indent=4, sort_keys=True))

        # close the connection
        s.close()
    else:
        print('valid arguments not given')
        exit()