raise on encyrpted private key PEM type

This commit is contained in:
Ben Toews 2019-02-05 10:09:06 -07:00
Родитель bea481837f
Коммит 93d65847e1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E9C423BE17EFEE70
2 изменённых файлов: 43 добавлений и 4 удалений

Просмотреть файл

@ -1,9 +1,10 @@
module SSHData
module PrivateKey
OPENSSH_PEM_TYPE = "OPENSSH PRIVATE KEY"
RSA_PEM_TYPE = "RSA PRIVATE KEY"
DSA_PEM_TYPE = "DSA PRIVATE KEY"
ECDSA_PEM_TYPE = "EC PRIVATE KEY"
OPENSSH_PEM_TYPE = "OPENSSH PRIVATE KEY"
RSA_PEM_TYPE = "RSA PRIVATE KEY"
DSA_PEM_TYPE = "DSA PRIVATE KEY"
ECDSA_PEM_TYPE = "EC PRIVATE KEY"
ENCRYPTED_PEM_TYPE = "ENCRYPTED PRIVATE KEY"
# Parse an SSH private key.
#
@ -21,6 +22,8 @@ module SSHData
[DSA.from_openssl(OpenSSL::PKey::DSA.new(key))]
when ECDSA_PEM_TYPE
[ECDSA.from_openssl(OpenSSL::PKey::EC.new(key))]
when ENCRYPTED_PEM_TYPE
raise DecryptError, "cannot decode encrypted private keys"
else
raise AlgorithmError, "unknown PEM type: #{pem_type.inspect}"
end

Просмотреть файл

@ -33,4 +33,40 @@ describe SSHData::PrivateKey do
PEM
}.to raise_error(SSHData::AlgorithmError)
end
it "raises on encrypted PEM type" do
expect {
described_class.parse(<<-PEM.gsub(/^ /, ""))
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIE6TAbBgkqhkiG9w0BBQMwDgQIcWWgZeQYPTcCAggABIIEyLoa5b3ktcPmy4VB
hHkpHzVSEsKJPmQTUaQvUwIp6+hYZeuOk78EPehrYJ/QezwJRdyBoD51oOxqWCE2
fZ5Wf6Mi/9NIuPyqQccP2ouErcMAcDLaAx9C0Ot37yoG0S6hOZgaxqwnCdGYKHgS
7cYUv40kLOJmTOJlHJbatfXHocrHcHkCBJ1q8wApA1KVQI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