python / python/cpython

Support loading keys and certificates as variables (bytes) in particular in the load_cert_chain function

Open
#118,557 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Proposal:

In MutualTLS Authentication scenarios it's useful to maintain client credential (private_key) confidentiality by allowing loading of the credential from encrypted key archives for example PKCS12. Python Cryptography and other modules allow loading of private keys into memory and at present we need to write those sensitive files to disk temporarily in order to load them into our TLS Client context.

This appears to be the existing code https://github.com/python/cpython/blob/a9c304cf020e2fa3ae78fd88359dfc808c9dd639/Modules/_ssl.c#L3899


    if (keyfile && !PyUnicode_FSConverter(keyfile, &keyfile_bytes)) {
        if (PyErr_ExceptionMatches(PyExc_TypeError)) {
            PyErr_SetString(PyExc_TypeError,
                            "keyfile should be a valid filesystem path");
        }
        goto error;
    }

Has this already been discussed elsewhere?

There is one somewhat similar feature request relating to loading from PKCS11 tokens. This is not related.

Links to previous discussion of this feature:

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Modules/_ssl.c at the load_cert_chain implementation and the filesystem-path conversion shown in the issue. Review how the current function accepts key and certificate paths, then determine the API and test coverage needed for in-memory byte inputs. Done means credentials can be loaded from bytes without requiring temporary sensitive files.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
authentication, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.