-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Description
I am not sure if it is a bug or intended behavior change.
A PKCS8 (RFC5208) formatted private key is no longer supported from OTP-23 release. In OTP-23 or newer version, calling ssh_file:host_key(Algorithm, Options) with a ssh_host_rsa_key file in PKCS8 format will return {error,key_decode_failed}. This will cause SSH daemon fail to start.
To reproduce
Use attached archive ssh-pkcs8.zip which contains private key in PKCS8 format. The header and footer of the PKCS8 syntax is the following:
-----BEGIN PRIVATE KEY-----
-----END PRIVATE KEY-----
Unzip the archive and ssh-pkcs8 folder will be in the current working directory. Start an Erlang shell in OTP-23 or newer version.
Erlang/OTP 23 [erts-11.2.2.13] [source-6d894d27ce] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]
Eshell V11.2.2.13 (abort with ^G)
1> Algorithm = 'ssh-rsa'.
'ssh-rsa'
2> Options = [{system_dir,"./ssh-pkcs8"}].
[{system_dir,"./ssh-pkcs8"}]
3> ssh_file:host_key(Algorithm, Options).
{error,key_decode_failed}
Affected versions
OTP-23 and newer version is affected.
Expected behavior
In OTP-22, calling ssh_file:host_key(Algorithm, Options) with the exact same ssh_host_rsa_key file in PKCS8 format given above will return {ok, #'RSAPrivateKey'{}}.
Additional context
I find out the changed behavior was introduced in this commit where asn1_type/1 function is added to ssh_file.erl module.
A patch that could solve the issue:
--- i/lib/ssh/src/ssh_file.erl
+++ w/lib/ssh/src/ssh_file.erl
@@ -738,6 +738,7 @@ asn1_type(<<"RSA PUBLIC">>) -> 'RSAPublicKey';
asn1_type(<<"DSA PRIVATE">>) -> 'DSAPrivateKey';
asn1_type(<<"EC PRIVATE">>) -> 'ECPrivateKey';
asn1_type(<<"OPENSSH PRIVATE">>) -> 'openssh-key-v1';
+asn1_type(<<"PRIVATE">>) -> 'PrivateKeyInfo';
asn1_type(_) -> undefined.
%%%================================================================