[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!!! :-)
Where do we have that method? We have some code in "bn_to_int", but it only
does py3k, py2k goes via hex.

On Sat, Oct 11, 2014 at 2:12 AM, Alex Stapleton <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):
>
> Is this some fancy ASN.1 bytes to int thing? It doesn't look particularly
> special and we already have a utility method that does bytes to int.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/pyca/cryptography/pull/1390/files#r18740432>.
>



-- 
"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