Add tests for client certificate support.

This commit is contained in:
Aldo Cortesi 2013-01-20 22:39:28 +13:00
parent 294bca139c
commit 25cb9471f0
8 changed files with 101 additions and 35 deletions

View File

@ -29,14 +29,12 @@ class ProxyError(Exception):
return "ProxyError(%s, %s)"%(self.code, self.msg)
class Log(controller.Msg):
def __init__(self, msg):
controller.Msg.__init__(self)
self.msg = msg
class ProxyConfig:
def __init__(self, certfile = None, cacert = None, clientcerts = None, no_upstream_cert=False, body_size_limit = None, reverse_proxy=None, transparent_proxy=None, certdir = None, authenticator=None):
assert not (reverse_proxy and transparent_proxy)

3
test/data/clientcert/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
client.crt
client.key
client.req

View File

@ -1,32 +1,42 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQC+6rG6A/BGD0dI+mh2FZIqQZn82z/pGs4f3pyxbHb+ROxjjQOr
fDCw2jc11XDxK7CXpDQAnkO6au/sQ5t50vSZ+PGhFD+t558VV2ausB5OYZsR7RRx
gl1jsxWdde3EHGjxSK+aXRgFpVrZzPLSy6dl8tMoqUMWIBi0u1WTbmyYjwIDAQAB
AoGBAKyqhmK9/Sjf2JDgKGnjyHX/Ls3JXVvtqk6Yfw7YEiaVH1ZJyu/lOgQ414YQ
rDzyTpxXHdERUh/fZ24/FvZvHFgy5gWEQjQPpprIxvqCLKJhX73L2+TnXmfYDApb
J7V/JfnTeOaK9LTpHsofB98A1s9DWX/ccOgKTtZIYMjYpdoBAkEA9hLvtixbO2A2
ZgDcA9ftVX2WwdpRH+mYXl1G60Fem5nlO3Rl3FDoafRvSQNZiqyOlObvKbbYh/S2
L7ihEMMNYQJBAMaeLnAc9jO/z4ApTqSBGUpM9b7ul16aSgq56saUI0VULIZcXeo3
3BwdL2fEOOnzjNy6NpH2BW63h/+2t7lV++8CQQDK+S+1Sr0uKtx0Iv1YRkHEJMW3
vQbxldNS8wnOf6s0GisVcZubsTkkPLWWuiaf1ln9xMc9106gRmAI2PgyRVHBAk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X70+7R8VtPUPsB
WF5GftpZNzzhKaO9xoJsdPalA5zG/ArbkJokw6Djey1SMaCl7hcc7vy+hZrzNmTe
CVRIq4g0L1CnzvmCaN0Sc3IM2YsO1ur0HoWNOm2ls7Y8sSpoicuAeIQizFJzyeEm
jENQYoYfSwy70UzR7PQRK48+o9Ndk8cA8wunRwIDAQABMA0GCSqGSIb3DQEBBQUA
A4GBAMF+bvgrGUpaMGgE8/NfVWLpYD62cl9+5Tq5l52UZ5LC1NZLcQxtHzRJe1Vs
YYxNRRSe9C2UKq6/t8wA40nXAlBwQl2LbfgJn3M8+jFUb89QCvHptcfZhDd63My4
eA8L5ciHfbEu6YuG1Oh+iJZ4+yXegiJtMr4pBYC4EvMwmi/N
-----END CERTIFICATE-----

View File

@ -0,0 +1,5 @@
[ ssl_client ]
basicConstraints = CA:FALSE
nsCertType = client
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = clientAuth

View File

@ -0,0 +1,42 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAvePcOuHOLzXSNGmunF+adQIsFIVx5F40WmvtLPiuV2mrcJyY
lMvluOk36Yf39jIUlAqP5y2JvzoPI3BAEZHFt4taIe3LrDddolsyzcAWcyQD9ow1
eTfuF7wIMgi0TY27Azvu602CGZWdlteGiKanaEOn6nsoDZEIxCK4TnaNFFDQSXRq
/9+1X5AsHmaaaUJd+uGhWOfBLuXEDuURGHtnD4TKMpKupS0BX6X5J9QXKNiMQe0B
8T8o196+1gl/wsYyTzESUV1YWe5kAEsqAWZvmLee5+16DIV/CUVk4OS9Ny/fCZY1
wxvCnUankHNTJtcgNPZ9s1c1MD1NIKrI3NekdwIDAQABAoIBAEKESAgEQ0J8Wvbr
MjQqtSNZsHE70YqKiVJHThybvA54wIpBAJ3W0tC0OVa/v1dpcZXuITx80iy/PMBQ
ONEuvBCwatFJyDe6aT1PLvut1u9cZVr/AFhHBEsiHcjRDb/A7wqR+v5H91PY+gv1
0XWa0zeNw4s6uuw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nSQ/
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
MIICYDCCAckCAQEwDQYJKoZIhvcNAQEFBQAwKDESMBAGA1UEAxMJbWl0bXByb3h5
MRIwEAYDVQQKEwltaXRtcHJveHkwHhcNMTMwMTIwMDg0OTM5WhcNMTUxMDE3MDg0
OTM5WjBFMQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UE
ChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQEAvePcOuHOLzXSNGmunF+adQIsFIVx5F40WmvtLPiuV2mrcJyY
lMvluOk36Yf39jIUlAqP5y2JvzoPI3BAEZHFt4taIe3LrDddolsyzcAWcyQD9ow1
eTfuF7wIMgi0TY27Azvu602CGZWdlteGiKanaEOn6nsoDZEIxCK4TnaNFFDQSXRq
/9+1X5AsHmaaaUJd+uGhWOfBLuXEDuURGHtnD4TKMpKupS0BX6X5J9QXKNiMQe0B
8T8o196+1gl/wsYyTzESUV1YWe5kAEsqAWZvmLee5+16DIV/CUVk4OS9Ny/fCZY1
wxvCnUankHNTJtcgNPZ9s1c1MD1NIKrI3NekdwIDAQABMA0GCSqGSIb3DQEBBQUA
A4GBAM9i0K4Sffaofi/k9QT7GJKWqmQKQVJoueC8ZZvkHRbUoOexIPnKduCzgreZ
M+QCteZHXT0UEMjscm5MuiF+/32sVGsF1aCPWc1esggpuLkhWtxjJtA9d1PE4xjt
z3+hyF+/tAkSVwVtj2WouczBY9HULP2uR1G19DwOJwIaup1Q
-----END CERTIFICATE-----

8
test/data/clientcert/make Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
openssl genrsa -out client.key 2048
openssl req -key client.key -new -out client.req
openssl x509 -req -days 365 -in client.req -signkey client.key -out client.crt -extfile client.cnf -extensions ssl_client
openssl x509 -req -days 1000 -in client.req -CA ~/.mitmproxy/mitmproxy-ca.pem -CAkey ~/.mitmproxy/mitmproxy-ca.pem -set_serial 00001 -out client.crt -extensions ssl_client
cat client.key client.crt > 127.0.0.1.pem
openssl x509 -text -noout -in 127.0.0.1.pem

View File

@ -71,9 +71,10 @@ class TestHTTP(tutils.HTTPProxTest, SanityMixin):
class TestHTTPS(tutils.HTTPProxTest, SanityMixin):
ssl = True
# FIXME: Instrument pathod to actually test that client cert is being sent
# correctly.
clientcerts = True
def test_clientcert(self):
f = self.pathod("304")
assert self.last_log()["request"]["clientcert"]["keyinfo"]
class TestReverse(tutils.ReverseProxTest, SanityMixin):

View File

@ -116,9 +116,8 @@ class ProxTestBase:
"""
return self.server.urlbase
def log(self):
pthread = self.proxy
return pthread.tmaster.log
def last_log(self):
return self.server.last_log()
class HTTPProxTest(ProxTestBase):