I'm developing a Bitbucket API wrapper in JavaScript. I'm trying to write tests for the method which adds an SSH key. My naive attempt at creating a believable SSH key was unsuccessful. Here's how I generated a dummy key:
- start with "ssh-rsa "
- append the Base64-encoded representation of a 279 character string of random characters
- append " "
- append a 16 character string of random characters
- append "@"
- append a 16 character string of random characters
- append ".com"
Bitbucket returns 400 Bad Request when I POST an SSH key generated in this manner. Fortunately I have access to Bitbucket's source code, so I've been able to dig a little deeper. Bitbucket validates SSH keys by running them through ssh-keygen
.
I don't understand how SSH keys are generated, so I might be asking a silly question. Is it possible to generate an SSH key convincing enough to fool ssh-keygen
? Here's the output:
$ ssh-keygen -l -f ~/Desktop/dummy_rsa.pub
buffer_get_string_ret: bad string length 1903654498
key_from_blob: can't read key type
key_read: key_from_blob cXd2YnRzZXpha3Rld2V4YmdieWdoeWl2aXpla3hkaHBodnlteHl2ZHl0bnloYmRyYWZrdnVxaWR3cHBydnFmZWFkaHp0aGRwYml6ZXVxY3ZlZ3NiZ29lanl0cG9vZmlnZ2dyZmJ3aWxsdXJhb2puYWRjY3F0YW5rcGV3Z3dkc3lxd2tkb3d6emFzbXpubXJ1eGN2bm53a3l6bmRjenV1dnplbnFtZ3Z5bm96ZGZhandwcG9mcHVoaWFkZ25ud3VkdnB0enV6Zm51bWVxanhzanlwa2ZodGxpd2xld2pnY3dhbmJ6aXVyamp6c29rbm54dHp2enJmeWhnY2ZrcWlqemFscGNnbWJsY3lpcmRtYXFkbHB6c3l0 duvrnzsladfrmccr@xqrbenpfryhoklgw.com
failed
/Users/dc/Desktop/dummy_rsa.pub is not a public key file.
To be clear, I don't need to generate a "valid" SSH key, I just need to be able to test various API endpoints. Also, since the tests run in a browser, I can't shell out to generate a key.