rename PublicKey and Certificate `parse` methods `parse_openssh`

This commit is contained in:
Ben Toews 2019-02-11 12:06:20 -07:00
Родитель 27ba7d8e09
Коммит f2a8716b15
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E9C423BE17EFEE70
9 изменённых файлов: 30 добавлений и 30 удалений

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

@ -14,11 +14,11 @@ gem install ssh_data
require "ssh_data"
key_data = File.read("~/.ssh/id_rsa.pub")
key = SSHData::PublicKey.parse(key_data)
key = SSHData::PublicKey.parse_openssh(key_data)
#=> <SSHData::PublicKey::RSA>
cert_data = = File.read("~/.ssh/id_rsa-cert.pub")
cert = SSHData::Certificate.parse(cert_data)
cert = SSHData::Certificate.parse_openssh(cert_data)
#=> <SSHData::PublicKey::Certificate>
cert.key_id

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

@ -25,7 +25,7 @@ module SSHData
# (Default false)
#
# Returns a Certificate instance.
def self.parse(cert, unsafe_no_verify: false)
def self.parse_openssh(cert, unsafe_no_verify: false)
algo, raw, _ = SSHData.key_parts(cert)
parsed = parse_rfc4253(raw, unsafe_no_verify: unsafe_no_verify)

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

@ -15,7 +15,7 @@ module SSHData
# and optional comment.
#
# Returns a PublicKey::Base subclass instance.
def self.parse(key)
def self.parse_openssh(key)
algo, raw, _ = SSHData.key_parts(key)
parsed = parse_rfc4253(raw)

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

@ -1,28 +1,28 @@
require_relative "./spec_helper"
describe SSHData::Certificate do
let(:rsa_cert) { described_class.parse(fixture("rsa_leaf_for_rsa_ca-cert.pub")) }
let(:dsa_cert) { described_class.parse(fixture("dsa_leaf_for_rsa_ca-cert.pub")) }
let(:ecdsa_cert) { described_class.parse(fixture("ecdsa_leaf_for_rsa_ca-cert.pub")) }
let(:ed25519_cert) { described_class.parse(fixture("ed25519_leaf_for_rsa_ca-cert.pub")) }
let(:rsa_cert) { described_class.parse_openssh(fixture("rsa_leaf_for_rsa_ca-cert.pub")) }
let(:dsa_cert) { described_class.parse_openssh(fixture("dsa_leaf_for_rsa_ca-cert.pub")) }
let(:ecdsa_cert) { described_class.parse_openssh(fixture("ecdsa_leaf_for_rsa_ca-cert.pub")) }
let(:ed25519_cert) { described_class.parse_openssh(fixture("ed25519_leaf_for_rsa_ca-cert.pub")) }
let(:rsa_ca_cert) { described_class.parse(fixture("rsa_leaf_for_rsa_ca-cert.pub")) }
let(:dsa_ca_cert) { described_class.parse(fixture("rsa_leaf_for_dsa_ca-cert.pub")) }
let(:ecdsa_ca_cert) { described_class.parse(fixture("rsa_leaf_for_ecdsa_ca-cert.pub")) }
let(:ed25519_ca_cert) { described_class.parse(fixture("rsa_leaf_for_ed25519_ca-cert.pub")) }
let(:rsa_ca_cert) { described_class.parse_openssh(fixture("rsa_leaf_for_rsa_ca-cert.pub")) }
let(:dsa_ca_cert) { described_class.parse_openssh(fixture("rsa_leaf_for_dsa_ca-cert.pub")) }
let(:ecdsa_ca_cert) { described_class.parse_openssh(fixture("rsa_leaf_for_ecdsa_ca-cert.pub")) }
let(:ed25519_ca_cert) { described_class.parse_openssh(fixture("rsa_leaf_for_ed25519_ca-cert.pub")) }
let(:min_time) { Time.at(0) }
let(:max_time) { Time.at((2**64)-1) }
it "raises on invalid signatures" do
expect {
described_class.parse(fixture("bad_signature-cert.pub"))
described_class.parse_openssh(fixture("bad_signature-cert.pub"))
}.to raise_error(SSHData::VerifyError)
end
it "doesn't validate signatures if provided unsafe_no_verify flag" do
expect {
described_class.parse(fixture("bad_signature-cert.pub"),
described_class.parse_openssh(fixture("bad_signature-cert.pub"),
unsafe_no_verify: true
)
}.not_to raise_error
@ -36,7 +36,7 @@ describe SSHData::Certificate do
cert = [algo, b64, comment].join(" ")
expect {
described_class.parse(cert, unsafe_no_verify: true)
described_class.parse_openssh(cert, unsafe_no_verify: true)
}.to raise_error(SSHData::DecodeError)
end
@ -45,7 +45,7 @@ describe SSHData::Certificate do
cert = [SSHData::Certificate::ALGO_ED25519, b64, comment].join(" ")
expect {
described_class.parse(cert, unsafe_no_verify: true)
described_class.parse_openssh(cert, unsafe_no_verify: true)
}.to raise_error(SSHData::DecodeError)
end
@ -54,7 +54,7 @@ describe SSHData::Certificate do
cert = [type, b64].join(" ")
expect {
described_class.parse(cert, unsafe_no_verify: true)
described_class.parse_openssh(cert, unsafe_no_verify: true)
}.not_to raise_error
end

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

@ -11,7 +11,7 @@ describe SSHData::PublicKey::DSA do
let(:ssh_sig) { described_class.ssh_signature(openssl_sig) }
let(:sig) { SSHData::Encoding.encode_signature(SSHData::PublicKey::ALGO_DSA, ssh_sig) }
let(:openssh_key) { SSHData::PublicKey.parse(fixture("dsa_leaf_for_rsa_ca.pub")) }
let(:openssh_key) { SSHData::PublicKey.parse_openssh(fixture("dsa_leaf_for_rsa_ca.pub")) }
subject do
described_class.new(
@ -92,7 +92,7 @@ describe SSHData::PublicKey::DSA do
it "can verify certificate signatures" do
expect {
SSHData::Certificate.parse(fixture("rsa_leaf_for_dsa_ca-cert.pub"),
SSHData::Certificate.parse_openssh(fixture("rsa_leaf_for_dsa_ca-cert.pub"),
unsafe_no_verify: false
)
}.not_to raise_error

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

@ -1,7 +1,7 @@
require_relative "../spec_helper"
describe SSHData::PublicKey::ECDSA do
let(:openssh_key) { SSHData::PublicKey.parse(fixture("ecdsa_leaf_for_rsa_ca.pub")) }
let(:openssh_key) { SSHData::PublicKey.parse_openssh(fixture("ecdsa_leaf_for_rsa_ca.pub")) }
it "can parse openssh-generate keys" do
expect { openssh_key }.not_to raise_error
@ -13,7 +13,7 @@ describe SSHData::PublicKey::ECDSA do
it "can verify certificate signatures" do
expect {
SSHData::Certificate.parse(fixture("rsa_leaf_for_ecdsa_ca-cert.pub"),
SSHData::Certificate.parse_openssh(fixture("rsa_leaf_for_ecdsa_ca-cert.pub"),
unsafe_no_verify: false
)
}.not_to raise_error
@ -29,7 +29,7 @@ describe SSHData::PublicKey::ECDSA do
].join)].join(" ")
expect {
SSHData::PublicKey.parse(malformed)
SSHData::PublicKey.parse_openssh(malformed)
}.to raise_error(SSHData::DecodeError)
end
@ -107,7 +107,7 @@ describe SSHData::PublicKey::ECDSA do
].join)].join(" ")
expect {
SSHData::PublicKey.parse(malformed)
SSHData::PublicKey.parse_openssh(malformed)
}.to raise_error(SSHData::DecodeError)
end
end

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

@ -8,7 +8,7 @@ describe SSHData::PublicKey::ED25519 do
let(:raw_sig) { signing_key.sign(msg) }
let(:sig) { SSHData::Encoding.encode_signature(SSHData::PublicKey::ALGO_ED25519, raw_sig) }
let(:openssh_key) { SSHData::PublicKey.parse(fixture("ed25519_leaf_for_rsa_ca.pub")) }
let(:openssh_key) { SSHData::PublicKey.parse_openssh(fixture("ed25519_leaf_for_rsa_ca.pub")) }
subject do
described_class.new(
@ -59,7 +59,7 @@ describe SSHData::PublicKey::ED25519 do
it "can verify certificate signatures" do
expect {
SSHData::Certificate.parse(fixture("rsa_leaf_for_ed25519_ca-cert.pub"),
SSHData::Certificate.parse_openssh(fixture("rsa_leaf_for_ed25519_ca-cert.pub"),
unsafe_no_verify: false
)
}.not_to raise_error
@ -72,7 +72,7 @@ describe SSHData::PublicKey::ED25519 do
begin
expect {
SSHData::Certificate.parse(fixture("rsa_leaf_for_ed25519_ca-cert.pub"),
SSHData::Certificate.parse_openssh(fixture("rsa_leaf_for_ed25519_ca-cert.pub"),
unsafe_no_verify: false
)
}.to raise_error(SSHData::VerifyError)

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

@ -10,7 +10,7 @@ describe SSHData::PublicKey::RSA do
let(:raw_sig) { private_key.sign(digest, msg) }
let(:sig) { SSHData::Encoding.encode_signature(SSHData::PublicKey::ALGO_RSA, raw_sig) }
let(:openssh_key) { SSHData::PublicKey.parse(fixture("rsa_leaf_for_rsa_ca.pub")) }
let(:openssh_key) { SSHData::PublicKey.parse_openssh(fixture("rsa_leaf_for_rsa_ca.pub")) }
subject do
described_class.new(
@ -65,7 +65,7 @@ describe SSHData::PublicKey::RSA do
it "can verify certificate signatures" do
expect {
SSHData::Certificate.parse(fixture("rsa_leaf_for_rsa_ca-cert.pub"),
SSHData::Certificate.parse_openssh(fixture("rsa_leaf_for_rsa_ca-cert.pub"),
unsafe_no_verify: false
)
}.not_to raise_error

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

@ -5,11 +5,11 @@ describe SSHData::PublicKey do
name = File.basename(path)
it "generates a MD5 fingerprint matching ssh-keygen for #{name}" do
expect(described_class.parse(fixture(name)).fingerprint(md5: true)).to eq(ssh_keygen_fingerprint(name, :md5))
expect(described_class.parse_openssh(fixture(name)).fingerprint(md5: true)).to eq(ssh_keygen_fingerprint(name, :md5))
end
it "generates a SHA256 fingerprint matching ssh-keygen for #{name}" do
expect(described_class.parse(fixture(name)).fingerprint).to eq(ssh_keygen_fingerprint(name, :sha256))
expect(described_class.parse_openssh(fixture(name)).fingerprint).to eq(ssh_keygen_fingerprint(name, :sha256))
end
end
end