473,385 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Python & SSL

Hello All,

I have been trying to make an https client with python, but it seems
that, to do this, one needs to have the socket module compiled with ssl.
This is not the default. So I have a couple of questions.

1. Where do I specify to compile socket with ssl? I found no
obvious option in configure or setup.py or several other
files I checked.
2. Is there a way to do this without re-compiling all of python?

Also, I have done numerous combinations of searches with ssl, https, &
python as terms, but I haven't found a page outlining the steps to make
a certificate and key that python understands. Has anyone been
successful at this? Did you use openssl? I want to make sure I am doing
this part correctly.

Thanks in advance for any help.

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
May 2 '06 #1
9 2750
James Stroud wrote:
I have been trying to make an https client with python


You probably don't want to use the standard library for HTTPS; here's a
quote from the socket module docs about SSL:

Warning: This does not do any certificate verification!

I'd recommend M2Crypto instead:
http://wiki.osafoundation.org/bin/vi...ts/MeTooCrypto
--
Benji York
May 2 '06 #2
Benji York wrote:
James Stroud wrote:
I have been trying to make an https client with python

You probably don't want to use the standard library for HTTPS; here's a
quote from the socket module docs about SSL:

Warning: This does not do any certificate verification!

I'd recommend M2Crypto instead:
http://wiki.osafoundation.org/bin/vi...ts/MeTooCrypto
--
Benji York


Thank you, I will give M2Crypto a try.

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
May 2 '06 #3
James Stroud <js*****@ucla.edu> writes:
I have been trying to make an https client with python, but it seems
What exactly do you mean by "make an https client"?

that, to do this, one needs to have the socket module compiled with ssl.
This is not the default. So I have a couple of questions.

1. Where do I specify to compile socket with ssl? I found no
obvious option in configure or setup.py or several other
files I checked.
What OS are you on?

2. Is there a way to do this without re-compiling all of python?
Are you sure it's NOT compiled in? But, if it's not compiled, it's
not compiled.

Also, I have done numerous combinations of searches with ssl, https, &
python as terms, but I haven't found a page outlining the steps to make
a certificate and key that python understands. Has anyone been
successful at this? Did you use openssl? I want to make sure I am doing
this part correctly.


Since you say "make a certificate", and mention "https client", it
sounds like you want to authenticate yourself to an HTTP server using
an SSL certificate? If so, I don't believe the issue Benji raised is
relevant (that issue is relevant for fetching HTTPS URLs rather than
authenticating yourself to a server using an SSL certificate, I
think).

urllib claims to have support for this in the form of the key_file and
cert_file arguments to Urlopener constructor (UNTESTED):

import urllib
opener = urllib.URLopener(key_file="/path/to/my_key_file",
cert_file="/path/to/my_cert_file")
response = opener.open(url)
I can't claim to know that it actually works, though...
John

May 3 '06 #4
John J. Lee wrote:
James Stroud <js*****@ucla.edu> writes:

I have been trying to make an https client with python, but it seems

What exactly do you mean by "make an https client"?


Something that can communicate with an https server. Fetch web pages,
send POST and GET information securely.
that, to do this, one needs to have the socket module compiled with ssl.
This is not the default. So I have a couple of questions.

1. Where do I specify to compile socket with ssl? I found no
obvious option in configure or setup.py or several other
files I checked.

What OS are you on?


Linux FC 4 with my self-compiled versions of just about everything.
2. Is there a way to do this without re-compiling all of python?

Are you sure it's NOT compiled in? But, if it's not compiled, it's
not compiled.


Its not compiled by default. I think I read this somewhere. I was
thinking of compiling just the socket module rather than installing over
my old version.
Also, I have done numerous combinations of searches with ssl, https, &
python as terms, but I haven't found a page outlining the steps to make
a certificate and key that python understands. Has anyone been
successful at this? Did you use openssl? I want to make sure I am doing
this part correctly.

Since you say "make a certificate", and mention "https client", it
sounds like you want to authenticate yourself to an HTTP server using
an SSL certificate? If so, I don't believe the issue Benji raised is
relevant (that issue is relevant for fetching HTTPS URLs rather than
authenticating yourself to a server using an SSL certificate, I
think).

urllib claims to have support for this in the form of the key_file and
cert_file arguments to Urlopener constructor (UNTESTED):

import urllib
opener = urllib.URLopener(key_file="/path/to/my_key_file",
cert_file="/path/to/my_cert_file")
response = opener.open(url)


At this point, authenticating is not an issue, though it would be nice
to know how to do. Mainly, I want to establish a secure connection for
2-way communication via https.

At any rate, I was able to make M2Crypto do what I wanted last night, so
I think I'll bypass the standard library route for now.

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
May 3 '06 #5
Benji York <be***@benjiyork.com> writes:
James Stroud wrote:
I have been trying to make an https client with python


You probably don't want to use the standard library for HTTPS; here's a
quote from the socket module docs about SSL:

Warning: This does not do any certificate verification!

[...]

Of course, remembering that the first thing to ask in response to "is
it secure?" is "against what?", for lots of purposes it just doesn't
matter that it ignores certificates.
John

May 3 '06 #6
John J. Lee enlightened us with:
Of course, remembering that the first thing to ask in response to
"is it secure?" is "against what?", for lots of purposes it just
doesn't matter that it ignores certificates.


I'm curious. Can you give me an example? AFAIK you need to know who
you're talking to before transmitting sensitive information, otherwise
you could be talking to anybody - and that's just what you wanted to
prevent with the encryption, right?

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
May 3 '06 #7
Sybren Stuvel wrote:
I'm curious. Can you give me an example? AFAIK you need to know who
you're talking to before transmitting sensitive information, otherwise
you could be talking to anybody - and that's just what you wanted to
prevent with the encryption, right?


Encryption has multiple meanings. In the general sense, it encompasses all
of cryptography and the information security properties crypto provides.
This meaning is rather imprecise and you run into problems using it to
answer questions like yours. I won't encryption this way again in this
post.

In a more specific/technical sense, encryption protects the privacy of
transmitted information, preventing third-party eavesdropping. It makes no
guarantees who's on the other end of your encrypted pipe. Block cipher
modes (CBC-DES, CTR-Rijndael/AES, etc) and asymmetric cipher modes
(RSA-OAEP) are examples.

Integrity guarantees that the data sent is the same as the data received.

Authentication verifies the party on the other end of your pipe. This is
the primary purpose of SSL certs, authenticating web sites to browsers (you
get data encryption too, but that's somewhat less important). Note that it
doesn't verify the party's identity or trustworthiness, only that they know
a particular secret. The assumption is that if the certificate system is
setup correctly, possession of that secret makes them trustworthy (or
rather, you can trust the site because their secret proves that a cert
authority somewhere trusts them in some fashion). Trustworthy for what is
never defined.

If that sounds convoluted or illogical, it is. "Ten Risk of PKI" is a good
intro to why this chain of trust isn't all it's cracked up to be. It's
good reading to understand exactly what you benefits you get from an SSL
connection.

http://www.schneier.com/paper-pki.html

So in a long-winded way, I've answered your question. The short and sweet
of it is, yes, SSL is meant to prevent you from "talking to anybody". In
that it succeeds* -- but only so far as making sure the site you're talking
to paid some money to one of the dozens of cert authorities for a minimal
background check. You've gone from "anybody" to "anybody with a couple
hundred bucks and spare time to blow".

*at least, until the end user completely ignores the warning dialogs and
accepts whatever invalid cert he's presented with.

Of course if you control the server and serve a small clientele who already
trust you, you can have clients import your own cert so they really can be
sure who they're talking to -- as long as your master key remains secret.
Watch out for hackers and disgruntled employees.

The moral of this story is: computer security is an ugly, complex business.

May 3 '06 #8
Edward Elliott enlightened us with:
Encryption has multiple meanings. In the general sense, it
encompasses all of cryptography and the information security
properties crypto provides.
And if you already know who'll get the message, it's secure. I get it
:)

Thanks for the nice read ;-)
Of course if you control the server and serve a small clientele who
already trust you, you can have clients import your own cert so they
really can be sure who they're talking to -- as long as your master
key remains secret.
I'm used to using it like that. My own graduation project uses SSL to
thoroughly check the identity of both parties, without a web of trust.
The moral of this story is: computer security is an ugly, complex
business.


Yup.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
May 4 '06 #9
Sybren Stuvel <sy*******@YOURthirdtower.com.imagination> writes:
John J. Lee enlightened us with:
Of course, remembering that the first thing to ask in response to
"is it secure?" is "against what?", for lots of purposes it just
doesn't matter that it ignores certificates.


I'm curious. Can you give me an example? AFAIK you need to know who
you're talking to before transmitting sensitive information, otherwise
you could be talking to anybody - and that's just what you wanted to
prevent with the encryption, right?


If Edward hadn't answered I would have said something along the lines
of what he said too, but more than that I just had in mind situations
where, when fetching a web page, the risk (probability and
consequences) of a man-in-the-middle attack doesn't feature much
higher than the risk of getting hit by a piece of debris from outer
space that day. Surprisingly often, it so happens that the people
setting up the web site used https, even though as a user of the site
I don't really care about the encryption or authentication.

That doesn't mean proper certificate handling wouldn't be good to have
(it would), just that installing m2crypto and finding the right docs
isn't necessarily worth the bother.

BTW, I assume the reason the OP (I forgot who that was) didn't have
https support compiled in was just that they didn't have OpenSSL
installed when they typed ./configure (since the Python build process
on unix uses autoconf). Either that or they installed a system
package to get Python (e.g. an .rpm) and the SSL support is is a
separate package (seems unlikely).
John

May 4 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: james blair | last post by:
Hi I have a search page & the reults for the search are fetched from the database. I want that on the results page only first 25 results are shown & a link "next 25 results" be shown.Same for the...
2
by: . | last post by:
Hi, how can I build python modules on windows? I tried to build numarray using Microsoft Visual C++ 2003 Toolkit, but got the following error: --- error: Python was built with version 7.1 of...
3
by: John Nagle | last post by:
Here's a URL from a link on the home page of a major company. <a href="/adsk/servlet/index?siteID=123112&amp;id=1860142">About Us</a> Yes, that "&amp;" is in the source text of the page. This is, in...
8
by: js | last post by:
Hi list. If I'm not mistaken, in python, there's no standard library to convert html entities, like &amp; or &gt; into their applicable characters. htmlentitydefs provides maps that helps this...
0
by: OldManRiver | last post by:
All, I downloaded the OpenEMM (Linux & Windows) to install. The Windows version uses Python as the Installer and the programmer for this installer made some bad assumptions about the...
4
by: Jive Dadson | last post by:
Hey folks. I know approximately zero about web clients. There's a simple task I want to do. (I think it's probably simple.) And I figure a Python script ought to be just the ticket. Various...
3
by: bsagert | last post by:
Some web feeds use decimal character entities that seem to confuse Python (or me). For example, the string "doesn't" may be coded as "doesn’t" which should produce a right leaning apostrophe....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.