Blame src/tests/t_proxy.py

Packit fd8b60
from k5test import *
Packit fd8b60
Packit fd8b60
# Skip this test if we're missing proxy functionality or parts of the proxy.
Packit fd8b60
if runenv.tls_impl == 'no':
Packit fd8b60
    skip_rest('HTTP proxy tests', 'TLS build support not enabled')
Packit fd8b60
try:
Packit fd8b60
    import kdcproxy
Packit fd8b60
except:
Packit fd8b60
    skip_rest('HTTP proxy tests', 'Python kdcproxy module not found')
Packit fd8b60
Packit fd8b60
# Construct a krb5.conf fragment configuring the client to use a local proxy
Packit fd8b60
# server.
Packit fd8b60
proxysubjectpem = os.path.join(srctop, 'tests', 'dejagnu', 'proxy-certs',
Packit fd8b60
                               'proxy-subject.pem')
Packit fd8b60
proxysanpem = os.path.join(srctop, 'tests', 'dejagnu', 'proxy-certs',
Packit fd8b60
                           'proxy-san.pem')
Packit fd8b60
proxyidealpem = os.path.join(srctop, 'tests', 'dejagnu', 'proxy-certs',
Packit fd8b60
                             'proxy-ideal.pem')
Packit fd8b60
proxywrongpem = os.path.join(srctop, 'tests', 'dejagnu', 'proxy-certs',
Packit fd8b60
                             'proxy-no-match.pem')
Packit fd8b60
proxybadpem = os.path.join(srctop, 'tests', 'dejagnu', 'proxy-certs',
Packit fd8b60
                           'proxy-badsig.pem')
Packit fd8b60
proxyca = os.path.join(srctop, 'tests', 'dejagnu', 'proxy-certs', 'ca.pem')
Packit fd8b60
proxyurl = 'https://localhost:$port5/KdcProxy'
Packit fd8b60
proxyurlupcase = 'https://LocalHost:$port5/KdcProxy'
Packit fd8b60
proxyurl4 = 'https://127.0.0.1:$port5/KdcProxy'
Packit fd8b60
proxyurl6 = 'https://[::1]:$port5/KdcProxy'
Packit fd8b60
Packit fd8b60
unanchored_krb5_conf = {'realms': {'$realm': {
Packit fd8b60
                        'kdc': proxyurl,
Packit fd8b60
                        'kpasswd_server': proxyurl}}}
Packit fd8b60
anchored_name_krb5_conf = {'realms': {'$realm': {
Packit fd8b60
                           'kdc': proxyurl,
Packit fd8b60
                           'kpasswd_server': proxyurl,
Packit fd8b60
                           'http_anchors': 'FILE:%s' % proxyca}}}
Packit fd8b60
anchored_upcasename_krb5_conf = {'realms': {'$realm': {
Packit fd8b60
                                 'kdc': proxyurlupcase,
Packit fd8b60
                                 'kpasswd_server': proxyurlupcase,
Packit fd8b60
                                 'http_anchors': 'FILE:%s' % proxyca}}}
Packit fd8b60
anchored_kadmin_krb5_conf = {'realms': {'$realm': {
Packit fd8b60
                             'kdc': proxyurl,
Packit fd8b60
                             'admin_server': proxyurl,
Packit fd8b60
                             'http_anchors': 'FILE:%s' % proxyca}}}
Packit fd8b60
anchored_ipv4_krb5_conf = {'realms': {'$realm': {
Packit fd8b60
                           'kdc': proxyurl4,
Packit fd8b60
                           'kpasswd_server': proxyurl4,
Packit fd8b60
                           'http_anchors': 'FILE:%s' % proxyca}}}
Packit fd8b60
kpasswd_input = (password('user') + '\n' + password('user') + '\n' +
Packit fd8b60
                 password('user') + '\n')
Packit fd8b60
Packit fd8b60
def start_proxy(realm, keycertpem):
Packit fd8b60
    proxy_conf_path = os.path.join(realm.testdir, 'kdcproxy.conf')
Packit fd8b60
    proxy_exec_path = os.path.join(srctop, 'util', 'wsgiref-kdcproxy.py')
Packit fd8b60
    conf = open(proxy_conf_path, 'w')
Packit fd8b60
    conf.write('[%s]\n' % realm.realm)
Packit fd8b60
    conf.write('kerberos = kerberos://localhost:%d\n' % realm.portbase)
Packit fd8b60
    conf.write('kpasswd = kpasswd://localhost:%d\n' % (realm.portbase + 2))
Packit fd8b60
    conf.close()
Packit fd8b60
    realm.env['KDCPROXY_CONFIG'] = proxy_conf_path
Packit fd8b60
    cmd = [sys.executable, proxy_exec_path, str(realm.server_port()),
Packit fd8b60
           keycertpem]
Packit fd8b60
    return realm.start_server(cmd, sentinel='proxy server ready')
Packit fd8b60
Packit fd8b60
# Fail: untrusted issuer and hostname doesn't match.
Packit fd8b60
mark('untrusted issuer, hostname mismatch')
Packit fd8b60
output("running pass 1: issuer not trusted and hostname doesn't match\n")
Packit fd8b60
realm = K5Realm(krb5_conf=unanchored_krb5_conf, get_creds=False,
Packit fd8b60
                create_host=False)
Packit fd8b60
proxy = start_proxy(realm, proxywrongpem)
Packit fd8b60
realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
Packit fd8b60
stop_daemon(proxy)
Packit fd8b60
realm.stop()
Packit fd8b60
Packit fd8b60
# Fail: untrusted issuer, host name matches subject.
Packit fd8b60
mark('untrusted issuer, hostname subject match')
Packit fd8b60
output("running pass 2: subject matches, issuer not trusted\n")
Packit fd8b60
realm = K5Realm(krb5_conf=unanchored_krb5_conf, get_creds=False,
Packit fd8b60
                create_host=False)
Packit fd8b60
proxy = start_proxy(realm, proxysubjectpem)
Packit fd8b60
realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
Packit fd8b60
stop_daemon(proxy)
Packit fd8b60
realm.stop()
Packit fd8b60
Packit fd8b60
# Fail: untrusted issuer, host name matches subjectAltName.
Packit fd8b60
mark('untrusted issuer, hostname SAN match')
Packit fd8b60
output("running pass 3: subjectAltName matches, issuer not trusted\n")
Packit fd8b60
realm = K5Realm(krb5_conf=unanchored_krb5_conf, get_creds=False,
Packit fd8b60
                create_host=False)
Packit fd8b60
proxy = start_proxy(realm, proxysanpem)
Packit fd8b60
realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
Packit fd8b60
stop_daemon(proxy)
Packit fd8b60
realm.stop()
Packit fd8b60
Packit fd8b60
# Fail: untrusted issuer, certificate signature is bad.
Packit fd8b60
mark('untrusted issuer, bad signature')
Packit fd8b60
output("running pass 4: subject matches, issuer not trusted\n")
Packit fd8b60
realm = K5Realm(krb5_conf=unanchored_krb5_conf, get_creds=False,
Packit fd8b60
                create_host=False)
Packit fd8b60
proxy = start_proxy(realm, proxybadpem)
Packit fd8b60
realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
Packit fd8b60
stop_daemon(proxy)
Packit fd8b60
realm.stop()
Packit fd8b60
Packit fd8b60
# Fail: trusted issuer but hostname doesn't match.
Packit fd8b60
mark('trusted issuer, hostname mismatch')
Packit fd8b60
output("running pass 5: issuer trusted but hostname doesn't match\n")
Packit fd8b60
realm = K5Realm(krb5_conf=anchored_name_krb5_conf, get_creds=False,
Packit fd8b60
                create_host=False)
Packit fd8b60
proxy = start_proxy(realm, proxywrongpem)
Packit fd8b60
realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
Packit fd8b60
stop_daemon(proxy)
Packit fd8b60
realm.stop()
Packit fd8b60
Packit fd8b60
# Succeed: trusted issuer and host name matches subject.
Packit fd8b60
mark('trusted issuer, hostname subject match')
Packit fd8b60
output("running pass 6: issuer trusted, subject matches\n")
Packit fd8b60
realm = K5Realm(krb5_conf=anchored_name_krb5_conf, start_kadmind=True,
Packit fd8b60
                get_creds=False)
Packit fd8b60
proxy = start_proxy(realm, proxysubjectpem)
Packit fd8b60
realm.kinit(realm.user_princ, password=password('user'))
Packit fd8b60
realm.run([kvno, realm.host_princ])
Packit fd8b60
realm.run([kpasswd, realm.user_princ], input=kpasswd_input)
Packit fd8b60
stop_daemon(proxy)
Packit fd8b60
realm.stop()
Packit fd8b60
Packit fd8b60
# Succeed: trusted issuer and host name matches subjectAltName.
Packit fd8b60
mark('trusted issuer, hostname SAN match')
Packit fd8b60
output("running pass 7: issuer trusted, subjectAltName matches\n")
Packit fd8b60
realm = K5Realm(krb5_conf=anchored_name_krb5_conf, start_kadmind=True,
Packit fd8b60
                get_creds=False)
Packit fd8b60
proxy = start_proxy(realm, proxysanpem)
Packit fd8b60
realm.kinit(realm.user_princ, password=password('user'))
Packit fd8b60
realm.run([kvno, realm.host_princ])
Packit fd8b60
realm.run([kpasswd, realm.user_princ], input=kpasswd_input)
Packit fd8b60
stop_daemon(proxy)
Packit fd8b60
realm.stop()
Packit fd8b60
Packit fd8b60
# Fail: certificate signature is bad.
Packit fd8b60
mark('bad signature')
Packit fd8b60
output("running pass 8: issuer trusted and subjectAltName matches, sig bad\n")
Packit fd8b60
realm = K5Realm(krb5_conf=anchored_name_krb5_conf,
Packit fd8b60
                get_creds=False,
Packit fd8b60
		                create_host=False)
Packit fd8b60
proxy = start_proxy(realm, proxybadpem)
Packit fd8b60
realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
Packit fd8b60
stop_daemon(proxy)
Packit fd8b60
realm.stop()
Packit fd8b60
Packit fd8b60
# Fail: trusted issuer but IP doesn't match.
Packit fd8b60
mark('trusted issuer, IP mismatch')
Packit fd8b60
output("running pass 9: issuer trusted but no name matches IP\n")
Packit fd8b60
realm = K5Realm(krb5_conf=anchored_ipv4_krb5_conf, get_creds=False,
Packit fd8b60
                create_host=False)
Packit fd8b60
proxy = start_proxy(realm, proxywrongpem)
Packit fd8b60
realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
Packit fd8b60
stop_daemon(proxy)
Packit fd8b60
realm.stop()
Packit fd8b60
Packit fd8b60
# Fail: trusted issuer, but subject does not match.
Packit fd8b60
mark('trusted issuer, IP mismatch (hostname in subject)')
Packit fd8b60
output("running pass 10: issuer trusted, but subject does not match IP\n")
Packit fd8b60
realm = K5Realm(krb5_conf=anchored_ipv4_krb5_conf, get_creds=False,
Packit fd8b60
                create_host=False)
Packit fd8b60
proxy = start_proxy(realm, proxysubjectpem)
Packit fd8b60
realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
Packit fd8b60
stop_daemon(proxy)
Packit fd8b60
realm.stop()
Packit fd8b60
Packit fd8b60
# Succeed: trusted issuer and host name matches subjectAltName.
Packit fd8b60
mark('trusted issuer, IP SAN match')
Packit fd8b60
output("running pass 11: issuer trusted, subjectAltName matches IP\n")
Packit fd8b60
realm = K5Realm(krb5_conf=anchored_ipv4_krb5_conf, start_kadmind=True,
Packit fd8b60
                get_creds=False)
Packit fd8b60
proxy = start_proxy(realm, proxysanpem)
Packit fd8b60
realm.kinit(realm.user_princ, password=password('user'))
Packit fd8b60
realm.run([kvno, realm.host_princ])
Packit fd8b60
realm.run([kpasswd, realm.user_princ], input=kpasswd_input)
Packit fd8b60
stop_daemon(proxy)
Packit fd8b60
realm.stop()
Packit fd8b60
Packit fd8b60
# Fail: certificate signature is bad.
Packit fd8b60
mark('bad signature (IP hostname)')
Packit fd8b60
output("running pass 12: issuer trusted, names don't match, signature bad\n")
Packit fd8b60
realm = K5Realm(krb5_conf=anchored_ipv4_krb5_conf, get_creds=False,
Packit fd8b60
                create_host=False)
Packit fd8b60
proxy = start_proxy(realm, proxybadpem)
Packit fd8b60
realm.kinit(realm.user_princ, password=password('user'), expected_code=1)
Packit fd8b60
stop_daemon(proxy)
Packit fd8b60
realm.stop()
Packit fd8b60
Packit fd8b60
# Succeed: trusted issuer and host name matches subject, using kadmin
Packit fd8b60
# configuration to find kpasswdd.
Packit fd8b60
mark('trusted issuer, hostname subject match (kadmin)')
Packit fd8b60
output("running pass 13: issuer trusted, subject matches\n")
Packit fd8b60
realm = K5Realm(krb5_conf=anchored_kadmin_krb5_conf, start_kadmind=True,
Packit fd8b60
                get_creds=False, create_host=False)
Packit fd8b60
proxy = start_proxy(realm, proxysubjectpem)
Packit fd8b60
realm.run([kpasswd, realm.user_princ], input=kpasswd_input)
Packit fd8b60
stop_daemon(proxy)
Packit fd8b60
realm.stop()
Packit fd8b60
Packit fd8b60
# Succeed: trusted issuer and host name matches subjectAltName, using
Packit fd8b60
# kadmin configuration to find kpasswdd.
Packit fd8b60
mark('trusted issuer, hostname SAN match (kadmin)')
Packit fd8b60
output("running pass 14: issuer trusted, subjectAltName matches\n")
Packit fd8b60
realm = K5Realm(krb5_conf=anchored_kadmin_krb5_conf, start_kadmind=True,
Packit fd8b60
                get_creds=False, create_host=False)
Packit fd8b60
proxy = start_proxy(realm, proxysanpem)
Packit fd8b60
realm.run([kpasswd, realm.user_princ], input=kpasswd_input)
Packit fd8b60
stop_daemon(proxy)
Packit fd8b60
realm.stop()
Packit fd8b60
Packit fd8b60
# Succeed: trusted issuer and host name matches subjectAltName (give or take
Packit fd8b60
# case).
Packit fd8b60
mark('trusted issuer, hostname SAN case-insensitive match')
Packit fd8b60
output("running pass 15: issuer trusted, subjectAltName case-insensitive\n")
Packit fd8b60
realm = K5Realm(krb5_conf=anchored_upcasename_krb5_conf, start_kadmind=True,
Packit fd8b60
                get_creds=False, create_host=False)
Packit fd8b60
proxy = start_proxy(realm, proxysanpem)
Packit fd8b60
realm.run([kpasswd, realm.user_princ], input=kpasswd_input)
Packit fd8b60
stop_daemon(proxy)
Packit fd8b60
realm.stop()
Packit fd8b60
Packit fd8b60
success('MS-KKDCP proxy')