web.py, SSL and paths

972 views
Skip to first unread message

boubou_cs

unread,
Jul 28, 2010, 8:35:40 AM7/28/10
to web.py
hello,

I would like to use the ssl with integrated webpy server. So I
followed the following tutorial : http://webpy.org/cookbook/ssl

import web

from web.wsgiserver import CherryPyWSGIServer

CherryPyWSGIServer.ssl_certificate = "path/to/ssl_certificate"
CherryPyWSGIServer.ssl_private_key = "path/to/ssl_private_key"

urls = ("/.*", "hello")
app = web.application(urls, globals())

class hello:
def GET(self):
return 'Hello, world!'

if __name__ == "__main__":
app.run()

I do not know exactly where are the paths of the certificate and
private key :

path/to/ssl_certificate
path/to/ssl_private_key

I created an SSL certificate using the following commands:

sudo apt-get install openssl
cd /etc/ssl
sudo openssl genrsa -out server.key 1024
sudo openssl req -new -key server.key -out server.csr
sudo openssl x509 -req -days 365 -in server.csr -signkey server.key -
out server.crt

Then I assumed that the paths were as follows: /etc/ssl/certs and /etc/
ssl/private.

When I start the server with the command "python code.py" I have the
following error :

http://0.0.0.0:8080/
Traceback (most recent call last):
File "code.py", line 80, in <module>
app.run()
File "/usr/local/lib/python2.6/dist-packages/web/application.py",
line 316, in run
return wsgi.runwsgi(self.wsgifunc(*middleware))
File "/usr/local/lib/python2.6/dist-packages/web/wsgi.py", line 54,
in runwsgi
return httpserver.runsimple(func, validip(listget(sys.argv, 1,
'')))
File "/usr/local/lib/python2.6/dist-packages/web/httpserver.py",
line 146, in runsimple
server.start()
File "/usr/local/lib/python2.6/dist-packages/web/wsgiserver/
__init__.py", line 1588, in start
self.bind(af, socktype, proto)
File "/usr/local/lib/python2.6/dist-packages/web/wsgiserver/
__init__.py", line 1628, in bind
ctx.use_privatekey_file(self.ssl_private_key)
OpenSSL.SSL.Error: [('PEM routines', 'PEM_read_bio', 'no start line'),
('SSL routines', 'SSL_CTX_use_PrivateKey_file', 'PEM lib')]

One of you can tell me if my approach is correct?

jason pepas

unread,
Jul 28, 2010, 10:29:59 AM7/28/10
to web.py
On Jul 28, 7:35 am, boubou_cs <vincin...@gmail.com> wrote:
> hello,
>
> I do not know exactly where are the paths of the certificate and
> private key :
>
>         path/to/ssl_certificate
>         path/to/ssl_private_key
>
> I created an SSL certificate using the following commands:
>
> sudo apt-get install openssl
> cd /etc/ssl
> sudo openssl genrsa -out server.key 1024
> sudo openssl req -new -key server.key -out server.csr
> sudo openssl x509 -req -days 365 -in server.csr -signkey server.key -
> out server.crt
>
> Then I assumed that the paths were as follows: /etc/ssl/certs and /etc/
> ssl/private.

try this:

cd /etc/ssl
find .

-jason

boubou_cs

unread,
Jul 29, 2010, 11:13:08 AM7/29/10
to web.py
Thanks for the help. I found the solution.

First i make a self-signed certificate:

openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out
server.crt
cp server.key myserver.key
cp server.crt myserver.crt

Then, in code.py:

from web.wsgiserver import CherryPyWSGIServer # SSL

CherryPyWSGIServer.ssl_certificate = "/etc/ssl/myserver.crt"
CherryPyWSGIServer.ssl_private_key = "/etc/ssl/myserver.key"

Then if i go to http://127.0.0.1:8080/:

The client sent a plain HTTP request, but this server only speaks
HTTPS on this port.

So https://127.0.0.1:8080 and i have my "hello" !

"It's alive !" ;)


boubou_cs

unread,
Jul 31, 2010, 5:29:39 AM7/31/10
to web.py
Can someone explain how to make some requests in https and not others
with the server by default?
Is it possible to make referrals to the http requests are redirected
to the https with the server by default?

Thank you in advance
Reply all
Reply to author
Forward
0 new messages