#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os import subprocess import gssapi import sys import socket curr_path = os.getcwd() os.environ["KRB5_CONFIG"] = curr_path + "/client/krb5.conf" os.environ["KRB5CCNAME"] = "/tmp/krb5cc_cli_1000" os.environ["KRB5_KTNAME"] = curr_path + "/client/cli.keytab" os.environ["KRB5_TRACE"] = "/tmp/client.log" principal = "cli@TEST.COM" res = subprocess.call(["kinit", "-kt", "client/cli.keytab", principal]) subprocess.call(["klist"]) name = gssapi.Name(principal) server_token = None port = 12345 s = socket.socket() host = "127.0.0.1" s.connect((host, port)) rev = s.recv(1024) print(rev) cname = name.canonicalize(gssapi.MechType.kerberos) print(cname) client_ctx = gssapi.SecurityContext(name=cname, usage="initiate") while not client_ctx.complete: client_token = client_ctx.step(server_token)