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 AES-encrypted DER-encoded private keys #577

Closed
P-E-Meunier opened this issue Oct 10, 2017 · 3 comments
Closed

Support AES-encrypted DER-encoded private keys #577

P-E-Meunier opened this issue Oct 10, 2017 · 3 comments

Comments

@P-E-Meunier
Copy link
Contributor

The thrussh-keys crate tries to parse as many different key formats as possible.

The encoding of older key formats (inherited from SSLeay) is AES-encrypted, and the plaintext is sometimes padded with zeros.

This causes the read_all method in your der::nested function to fail. I am doing the following, which seems to work in many cases: parse the ASN.1 encoding of the key manually to find out its length, truncate the buffer, and parse.

@briansmith
Copy link
Owner

Please post an example key. Note that by definition of DER, there can't be any extra zero padding bytes, because every value is uniquely encoded using the shortest possible encoding.

@P-E-Meunier
Copy link
Contributor Author

So, thanks for mentioning that.
Turns out it's just my misunderstanding of how rust-crypto works with padding. I'm posting the key anyway, in case you want to handle such keys in *ring*.

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,CF6186291E818C7D6AFE285DB6C482CA

exLdQJljgJvpLamD1DIFMxM3do/f2OzeNth3nYB7ZW0wq2fq5DzoE57PjsZ+rf8q
4GZNN3x5k7pJldo18eqOengCCxwTqhHNEYzrO0AHnEYdHODHgq9TP+RlaCtdwlKX
L0Jca1c8VjYOdHVWkTTFe56VSk5+aqi0EEZ8QD1yM9DxyhsKUpKw4MMLdJlxPihu
IwMDEBTF2FZU8vIdApJql4XM/T/NXF9Y9/ts6TVEsqE/Zj8+jM/kpZs+Lo3P5jz9
2QTzvf633WuiJCmke6JK/JCsQ4NLOVlaiUXGY6sHloHTIC4vsQ79CQ3Gz6Eg2UH5
hdSA55w8As5hItVOcUMNjQRGH2/Iok+MnxP4GpuPKmA931bilqSimjYp5bHN0lC9
rA7C4kPeBw/kRXJAapM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q3pZY0Q5gJrjo3kCxwECb
oK/MxkH6+gaZlhSaliqm0xip5j4DQ2MO/MocGxaI/C0iFrmYW59yIHgSOkQhRtsr
UdCCfSC0P34ABAX/cCI0XxfeAroSaRM6ow8NSxe0wkOAqvZ7EzokvgT2u/qwRdb7
-----END RSA PRIVATE KEY-----

Also, I'm renaming the issue. Feel free to close if inappropriate, and sorry for the noise.

@P-E-Meunier P-E-Meunier changed the title from_der fails when the DER is padded with zeros Support AES-encrypted DER-encoded private keys Oct 10, 2017
@P-E-Meunier
Copy link
Contributor Author

Alright, thrussh-keys now does this fine using #582.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants