Added load_ssh_public_key to load OpenSSH public keys (RSA support only)

As far as I can tell, there isn't currently a way to import OpenSSH (RFC 4253) formatted RSA public keys into an RSAPublicKey in cryptography. This commit adds that functionality.

Other Python cryptography libraries (notably PyCrypto) provide this sort of functionality and at least one library that I'd like to see ported to cryptography relies on that functionality.

This is my first-time contributing to cryptography. Your feedback would be very much appreciated! Thanks!
I agree that we shouldn't try to use pyasn.1 here, that was a mistake
earlier :-)

On Sat Dec 13 2014 at 9:47:15 AM Alex Stapleton <notifications@github.com>
wrote:

> In src/cryptography/hazmat/primitives/serialization.py
> <https://github.com/pyca/cryptography/pull/1517#discussion-diff-21789812>:
>
> > +def load_ssh_rsa_public_key(data, backend):
> > +    if not data.startswith(b'ssh-rsa '):
> > +        raise ValueError('SSH-formatted RSA keys must begin with ssh-rsa')
> > +
> > +    parts = data.split(b' ')
> > +    data = base64.b64decode(parts[1])
> > +
> > +    cert_data = []
> > +
> > +    while len(data) > 0:
> > +        str_len = struct.unpack('>I', data[0:4])[0]
> > +        cert_data.append(data[4:4 + str_len])
> > +        data = data[4 + str_len:]
> > +
> > +    e = _bytes_to_int(cert_data[1])
> > +    n = _bytes_to_int(cert_data[2])
>
> The actual encoding of the *value* is the same but they aren't stored in
> an ASN.1 sequence or anything so you are still going to end up having to
> tokenize stuff yourself. Using PyASN1 seems pretty unnatural for this.
>
> Since our handling of SSH is currently container entirely to this 1
> function I don't mind much if it's not particularly generic myself.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/pyca/cryptography/pull/1517/files#r21789812>.
>