[Twisted-Python] Twisted HTTP client with certificate ?

Drew Smathers drew.smathers at gmail.com
Sun Mar 9 11:47:09 EDT 2008


On Sun, Mar 9, 2008 at 11:10 AM, Roland Hedberg
<roland.hedberg at adm.umu.se> wrote:
> Hi!
>
>  It seems like the HTTP client in Twisted handles HTTPS and easily as
>  HTTP connections.
>
>  But, I can not find any place where I can specify a client certificate
>  to use in the HTTPS connection.
>
>  Is there something I have overlooked or is there another solution I can
>   use, because I need to have certificates on both the server and the
>  client side.
>
>  -- Roland
>

You need to pass a ContextFactory which provides the client certificate:

  reactor.connectSSL(host, port, factory, contextFactory)

web.client.getPage, for example, takes a contextFactory as a keyword argument.
One way to create the context factory, with the key and certificate
stored in files:

   clientCtxFactory = ssl.DefaultOpenSSLContextFactory(keyPath, certPath)

-- 
\\\\\/\"/\\\\\\\\\\\
\\\\/ // //\/\\\\\\\
\\\/  \\// /\ \/\\\\
\\/ /\/ / /\/ /\ \\\
\/ / /\/ /\  /\\\ \\
/ /\\\  /\\\ \\\\\/\
\/\\\\\/\\\\\/\\\\\\
               d.p.s




More information about the Twisted-Python mailing list