Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEM format quickfix #54 #57

Merged

Conversation

lukpueh
Copy link
Member

@lukpueh lukpueh commented Sep 15, 2017

This quickfix changes the PEM format from PKSC8 to PKSC5 (TraditionalOpenSSL) in pyca_crypto's variant of create_rsa_encrypted_pem.
PKSC5 has the PEM headers expected by other PEM parsing functions, e.g. is_pem_private and extract_pem, which would break without this fix. The PR also updates the unittests.

However, we should consider a smarter solution as discussed in #54.

This quickfix changes the PEM format from PKSC8 to
PKSC5 (TraditionalOpenSSL) in pyca_crypto's variant of
`create_rsa_encrypted_pem`.
PKSC5 has the PEM headers expected by other PEM parsing functions,
e.g. `is_pem_private` and `extract_pem`.

See secure-systems-lab#54 for more details
Test the output of `create_rsa_encrypted_pem` in conjunction with
PEM parsing functions `extract_pem` and `is_private_pem`.
@@ -540,7 +540,7 @@ def create_rsa_encrypted_pem(private_key, passphrase):

encrypted_pem = \
private_key.private_bytes(encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.PKCS8,
format=serialization.PrivateFormat.TraditionalOpenSSL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring for this function should be updated, not only to mention the new PEM format but to correct it. The docstring incorrectly references PyCrypto and 3DES, etc. (this appears to be a copy+paste that wasn't edited).

# Test encrypted private pem
private_pem_encrypted = KEYS.create_rsa_encrypted_pem(private_pem, "pw")
private_pem_encrypted = KEYS.extract_pem(private_pem_encrypted,
private_pem=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that there are still many instances of this style of indentation in the codebase, but we should try to use the recently added indentation rules of the code style guidelines from now on.

Here is what the guidelines says about indentation for this particular case:

Make sure to indent the continued line appropriately; double-indentation (4 spaces) is prefered for line continuation, to distinguish it from functional indentation.

Correct me if I'm wrong, but this line should look as follows:

KEYS.extract_pem(private_pem_encrypted,
    private_pem=True)

@@ -737,9 +745,11 @@ def test_is_pem_private(self):
# Test for a valid PEM string.
private_pem = self.rsakey_dict['keyval']['private']
private_pem_ec = self.ecdsakey_dict['keyval']['private']
private_pem_encrypted = KEYS.create_rsa_encrypted_pem(private_pem, "pw")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe name it private_pem_encrypted_rsa to make it clear that it's an RSA PEM, similar to private_pem_ec?

is used to strengthen 'passphrase'.
Return a string in PEM format (TraditionalOpenSSL), where the
private part of the RSA key is encrypted using the best available
encryption for a given key’s backend. This is a curated encryption choice
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A non-ASCII character is used on this line, but these modules don't declare a source code encoding. Probably easiest not to remove it.

As @vladimir-v-diaz points out, comments and docstrings for
securesystemslib/pyca_crypto_keys.py's `create_rsa_encrypted_pem`
are outdated.
This commit updates docstring, comments and some indentation
guideline mismatches.
Following @vladimir-v-diaz's review suggestions, this commit
fixes some variable names and indentations in `test_keys.py`
@lukpueh lukpueh force-pushed the pem-format-quickfix branch from a6b9877 to 59f5876 Compare September 15, 2017 18:14
@lukpueh
Copy link
Member Author

lukpueh commented Sep 15, 2017

Oops, removed non-ascii character, fixed wrong variable, rebased and force-pushed. Should be fine now.

@vladimir-v-diaz vladimir-v-diaz merged commit 59f5876 into secure-systems-lab:master Sep 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants