[WIP]: Move to pure python code for parsing PEMs.

OMFG. Not final.

Implements:

* the core "PEM" parser logic
* PEM decryption
* Handling of the ASN.1 DER for ECDSA Private Keys

Not done:

* Parsing of a bunch of other key types
* non-md5 based PBES

Some notes:

* I don't understand the error handling around ASN.1 well enough yet, which
  makes me pretty uncomfortable given the sensitivity of this stuff.
* PyASN.1's API is kind of miserable, but it does appear to be complete
* There's some not-great error handling in (at least) the EC number loading in
  the OpenSSL backend
* Bits vs. Bytes for key_size is the worst :-(
* If we're comitted to doing this, it's going to be a decent sized project.
  We'll have to keep the old key loading logic around and port one key type at
  a time.
* I don't know if I read the RFC closely enough :-( There's all kinds of random
  notes in various places, and I assume if I ignore any one of those the
  security of the system is screwed.



FEEDBACK PLEASE!!! :-)
I don't think `six.bytes2int` exists, there's `six.byte2int` (singular!),
but that's basically just `chr`.

On Sat, Oct 11, 2014 at 8:20 AM, Terry Chia <notifications@github.com>
wrote:

> In cryptography/hazmat/primitives/serialization.py:
>
> > +                namedValues=namedval.NamedValues(
> > +                    ("ecPrivkeyVer1", 1),
> > +                )
> > +            ),
> > +        ),
> > +        namedtype.NamedType("privateKey", univ.OctetString()),
> > +        namedtype.OptionalNamedType("parameters", _ECParameters().subtype(
> > +            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0),
> > +        )),
> > +        namedtype.OptionalNamedType("publicKey", univ.BitString().subtype(
> > +            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1),
> > +        )),
> > +    )
> > +
> > +
> > +def bytes_to_int(b):
>
> Unless I'm misunderstanding the purpose of this method, can't we just use
> six.bytes2int()?
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/pyca/cryptography/pull/1390/files#r18742113>.
>



-- 
"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