Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8994957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:32:26+00:00 2026-06-15T23:32:26+00:00

In Python, ssl.wrap_socket can read certificates from files, ssl.wrap_socket require the certificate as a

  • 0

In Python, ssl.wrap_socket can read certificates from files, ssl.wrap_socket require the certificate as a file path.

How can I start an SSL connection using a certificate read from string variables?

My host environment does not allow write to files, and tempfile module is not functional
I’m using Python 2.7.
I store the certificate inside MySQL and read as a string.

Edit:
I gave up, this is basically require implement ssl by pure python code, this is beyond my current knowledge.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:32:28+00:00Added an answer on June 15, 2026 at 11:32 pm

    Looking at the source, ssl.wrap_socket calls directly into the native code (openssl) function SSL_CTX_use_cert_chain_file which requires a path to a file, so what you are trying to do is not possible.

    For reference:

    In ssl/init.py we see:

    def wrap_socket(sock, keyfile=None, certfile=None,
                    server_side=False, cert_reqs=CERT_NONE,
                    ssl_version=PROTOCOL_SSLv23, ca_certs=None,
                    do_handshake_on_connect=True):
    
        return SSLSocket(sock, keyfile=keyfile, certfile=certfile,
                       server_side=server_side, cert_reqs=cert_reqs,
                       ssl_version=ssl_version, ca_certs=ca_certs,
                       do_handshake_on_connect=do_handshake_on_connect)
    

    Points us to the SSLSocket constructor (which is in the same file) and we see the following happen:

    self._sslobj = _ssl2.sslwrap(self._sock, server_side,
                                         keyfile, certfile,
                                         cert_reqs, ssl_version, ca_certs)
    

    _ssl2 is implemented in C (_ssl2.c)

    Looking at the sslwrap function, we see it’s creating a new object:

        return (PyObject *) newPySSLObject(Sock, key_file, cert_file,
                                           server_side, verification_mode,
                                           protocol, cacerts_file);
    

    Looking at the constructor for that object, we eventually see:

                ret = SSL_CTX_use_certificate_chain_file(self->ctx,
                                                         cert_file);
    

    That function is defined in openssl, so now we need to switch to that codebase.

    In ssl/ssl_rsa.c we eventually find in the function:

    BIO_read_filename(in,file) 
    

    If you dig far enough into the BIO code (part of openssl) you’ll eventually come to a normal fopen():

    fp=fopen(ptr,p);
    

    So it looks like as it’s currently written. It must be in a file openable by C’s fopen().

    Also, since python’s ssl library so quickly jumps into C, I don’t see a immediately obvious place to monkeypatch in a workaround either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a secure SSL connection to a server using python and M2Crypto. See
My app must read an SSL url from a third party. How do I
The Problem: Python's ssl module is not complaining about a certificate, although the issuing
I tried using the ssl module in Python 2.6 but I was told that
Does cyclone (python) support HTTPS connections and SSL? If so, can you please provide
I am trying to build Python from source and need to include the SSL
Can anybody suggest any python * ssl rsa library * , which has a
Ok, I am trying to verify data from PKCS7 envelop using Python. I have
I'm using Python's ssl library with an encrypted keyfile. However every time I wrap
I have a Python script adapted from Downloading MMS emails sent to Gmail using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.