Skip to content

Instantly share code, notes, and snippets.

@bkreider
Last active December 18, 2015 02:18
Show Gist options
  • Save bkreider/5709899 to your computer and use it in GitHub Desktop.
Save bkreider/5709899 to your computer and use it in GitHub Desktop.
Boto (2.9.2) cert issues with us-west-1. This compares two cacerts: the one included in the Requests library and the one included in Boto. Note: The SSL code is pulled from Boto's source code.
import ssl
import boto
import socket
GOOD_CERT="/opt/anaconda/lib/python2.7/site-packages/requests/cacert.pem"
BAD_CERT="/opt/anaconda/lib/python2.7/site-packages/boto/cacerts/cacerts.txt"
HOST="ec2.us-west-1.amazonaws.com"
PORT=443
def connect(host, port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host,port))
return sock
def ssl_wrap(sock, cert):
s = ssl.wrap_socket(sock, keyfile=None, certfile=None, cert_reqs=ssl.CERT_REQUIRED, ca_certs=cert)
return s
def main():
tests = [
("Good Cert", GOOD_CERT),
("Bad Cert", BAD_CERT)
]
print ("=============================\n"
"Boto Version: %s\n"
"=============================\n" % boto.__version__)
for test in tests:
print
print "Testing %s:%s" % test
print "=================="
print "Connecting socket"
sock = connect(HOST, PORT)
print "Wrapping with SSL"
try:
wrapped_sock = ssl_wrap(sock, test[1])
print "Cert info: %s" % (wrapped_sock.getpeercert(),)
except ssl.SSLError, e:
print "FAILED: %s" % (str(e),)
print "\n\n"
if __name__ == "__main__":
main()
@jtriley
Copy link

jtriley commented Jul 2, 2013

@asmeurer I think that error comes from the cert paths not existing. You probably need to update the script to point to the right cacert.pem and cacerts.txt locations. It looks like your anaconda install is in $HOME.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment