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

Support for traditional OpenSSL and PKCS8 RSA private key serialization #1503

Merged
merged 10 commits into from
Mar 1, 2015

Conversation

reaperhulk
Copy link
Member

This temporarily uses the backend to do it until the alternate approach is ready. DSA/ECDSA and public key support will follow if this is deemed worthy.


:param enctype: :class:`~cryptography.hazmat.primitives.serialization.EncryptionTypes`

:param bytes password: The password for encryption.
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, needing both params makes me think this should be a class, there's no reason to have a password param if you're doing NoEncryption

@jenkins-cryptography
Copy link

Test FAILed.
Refer to this link for build results: https://jenkins.cryptography.io/job/cryptography-pr-experimental/2592/

@alex
Copy link
Member

alex commented Nov 29, 2014

test failure relevant (use of unicode syntax in test_serialization.py)

On Sat Nov 29 2014 at 4:01:37 PM jenkins-cryptography <
notifications@github.com> wrote:

Test FAILed.
Refer to this link for build results:
https://jenkins.cryptography.io/job/cryptography-pr-experimental/2592/


Reply to this email directly or view it on GitHub
#1503 (comment).

@jenkins-cryptography
Copy link

Test PASSed.
Refer to this link for build results: https://jenkins.cryptography.io/job/cryptography-pr-experimental/2593/

@alex
Copy link
Member

alex commented Nov 30, 2014

I think we can do it simpler than that, just rename the interface, add a compatibility name, and be happy. That's the same thign we did with CMACContext -> MACContext.

@reaperhulk
Copy link
Member Author

Done

@jenkins-cryptography
Copy link

Test PASSed.
Refer to this link for build results: https://jenkins.cryptography.io/job/cryptography-pr-experimental/2595/

@jenkins-cryptography
Copy link

Test PASSed.
Refer to this link for build results: https://jenkins.cryptography.io/job/cryptography-pr-experimental/2596/

@jenkins-cryptography
Copy link

Test PASSed.
Refer to this link for build results: https://jenkins.cryptography.io/job/cryptography-pr-experimental/2597/

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 4806702 on reaperhulk:serialize-some-keys into 745e512 on pyca:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 4806702 on reaperhulk:serialize-some-keys into 745e512 on pyca:master.

class EncryptionTypes(Enum):
BestAvailable = "Best available to the backend"
AES256CBC = "256-bit AES in CBC mode"
TripleDESCBC = "Triple DES EDE in CBC mode"
Copy link
Member

Choose a reason for hiding this comment

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

These are a bit mis-leading; using the same value between PKCS8 and PKCS1 gets you totally different things, since they use differnt KDFs. I also think we should switch to using classes, instead of enums, so we vaoid issues like NoEncryption requiring you to pass an empty password

Copy link
Member Author

Choose a reason for hiding this comment

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

So we'd need to define an interface and 4 classes (for now) that conform to it?

@six.add_metaclass(abc.ABCMeta)
class KeySerializationEncryption(object):
    pass

@utils.register_interface(KeySerializationEncryption)
class BestAvailable(object):
    def __init__(self, password):
        self.password = password

@utils.register_interface(KeySerializationEncryption)
class AES256CBC(object):
    def __init__(self, password):
        self.password = password

@utils.register_interface(KeySerializationEncryption)
class TripleDESCBC(object):
    def __init__(self, password):
        self.password = password

@utils.register_interface(KeySerializationEncryption)
class NoEncryption(object):
    pass

Which would make calls to serialize look like:

key.dump_pem(PKCS8(AES256CBC("password"))
key.dump_pem(PKCS1(NoEncryption()))

Copy link
Member Author

Choose a reason for hiding this comment

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

(The interface would be so we can easily test to see if the passed object is permissible)

@jenkins-cryptography
Copy link

Test FAILed.
Refer to this link for build results: https://jenkins.cryptography.io/job/cryptography-pr-experimental/2606/

@alex
Copy link
Member

alex commented Dec 6, 2014

Tests are very red :-)

@reaperhulk
Copy link
Member Author

Holiday commit!

On Dec 6, 2014, at 5:58 PM, Alex Gaynor notifications@github.com wrote:

Tests are very red :-)


Reply to this email directly or view it on GitHub.

@jenkins-cryptography
Copy link

Test PASSed.
Refer to this link for build results: https://jenkins.cryptography.io/job/cryptography-pr-experimental/2608/


:param enctype: :class:`~cryptography.hazmat.primitives.asymmetric.serialization.KeySerializationEncryption`

.. class:: TraditionalOpenSSL(enctype)
Copy link
Member

Choose a reason for hiding this comment

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

Now that all the serializers just have their own encryption, should we just move this "up the stack" as it were, and onto the dump_pem method?

@alex
Copy link
Member

alex commented Feb 28, 2015

There's still a few outstanding comments here, but progress!

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 20456e9 on reaperhulk:serialize-some-keys into 3639423 on pyca:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 20456e9 on reaperhulk:serialize-some-keys into 3639423 on pyca:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 20456e9 on reaperhulk:serialize-some-keys into 3639423 on pyca:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 20456e9 on reaperhulk:serialize-some-keys into 3639423 on pyca:master.

.. method:: as_bytes(encoding, format, encryption_algorithm)

Allows serialization of the key to bytes. Encoding (PEM or DER), format
(TraditionalOpenSSL or PKCS8) and encryption algorithm (such as
Copy link
Member

Choose a reason for hiding this comment

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

Can we linkify PEM, DER, TraditionalOpenSSL, and PKCS8

@alex
Copy link
Member

alex commented Feb 28, 2015

Besides these two comments, this is ready as far as I'm concerned. Since it's pretty large and introducing a new API I'd like one person to double check me though :-)

@reaperhulk reaperhulk mentioned this pull request Feb 28, 2015
3 tasks
:class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateNumbers`
instance.

.. method:: as_bytes(encoding, format, encryption_algorithm)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why private_numbers but not private_bytes? This seems inconsistent.

Would private_as_numbers / private_as_bytes make sense?

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 223a8f0 on reaperhulk:serialize-some-keys into 3639423 on pyca:master.

@alex
Copy link
Member

alex commented Mar 1, 2015

I'm happy with this. Unless I hear otherwise I'll merge in the morning.

@reaperhulk reaperhulk mentioned this pull request Mar 1, 2015
@public
Copy link
Member

public commented Mar 1, 2015

Can someone explain why we are deprecating the WithNumbers names instead of 1) Using the existing class name or 2) Making a seperate set of interfaces for Serialization?

@alex
Copy link
Member

alex commented Mar 1, 2015

Because both Numbers and PEM/DER are Serialization, and if you can do one
you can do the other.

On Sun, Mar 1, 2015 at 7:44 AM, Alex Stapleton notifications@github.com
wrote:

Can someone explain why we are deprecating the WithNumbers names instead
of 1) Using the existing class name or 2) Making a seperate set of
interfaces for Serialization?


Reply to this email directly or view it on GitHub
#1503 (comment).

"I disapprove of what you say, but I will defend to the death your right to
say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero
GPG Key fingerprint: 125F 5C67 DFE9 4084

@public
Copy link
Member

public commented Mar 1, 2015

Until we commit to depending on pyasn1 that doesnt quite seem accurate to me, not that I have much of a problem with that idea :)

In any case I don't think "WithSerialization" is particularly a more descriptive class name than "WithNumbers". Would seem preferable to avoid deprecating yet another thing. Am I missing something?

@alex
Copy link
Member

alex commented Mar 1, 2015

@public I do find WithSerialization more accurate describes what we're doing with this interface, and I don't think many people actually type this class name, so it's not super disruptive.

Are you -1 on this, or are you ok with me merging?

public added a commit that referenced this pull request Mar 1, 2015
Support for traditional OpenSSL and PKCS8 RSA private key serialization
@public public merged commit 6bb9624 into pyca:master Mar 1, 2015
@reaperhulk reaperhulk deleted the serialize-some-keys branch March 1, 2015 17:38
@reaperhulk
Copy link
Member Author

While this has been merged I should note that we do have a hard dependency on pyasn1.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

7 participants