decode the valid-principals field

This commit is contained in:
Ben Toews 2019-01-23 15:05:40 -07:00
Родитель 2035c4b805
Коммит 77e65398b5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E9C423BE17EFEE70
5 изменённых файлов: 44 добавлений и 12 удалений

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

@ -33,10 +33,10 @@ PLATFORMS
ruby
DEPENDENCIES
ed25519 (~> 1.2.4)
pry (~> 0.10.4)
rspec (~> 3.5.0)
rspec-mocks (~> 3.5.0)
ed25519 (~> 1.2)
pry (~> 0.10)
rspec (~> 3.5)
rspec-mocks (~> 3.5)
ssh_data!
BUNDLED WITH

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

@ -44,6 +44,7 @@ class SSHData::Certificate
data[:valid_after] = Time.at(data[:valid_after])
data[:valid_before] = Time.at(data[:valid_before])
data[:public_key] = SSHData::PublicKey.from_data(data.delete(:key_data))
data[:valid_principals], _ = SSHData::Encoding.decode_strings(data[:valid_principals])
# The signature key is encoded as a string, but we can parse it.
sk_raw = data.delete(:signature_key)

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

@ -212,6 +212,25 @@ module SSHData::Encoding
[string.bytesize, string].pack("L>A*")
end
# Read a series of strings out of the provided data.
#
# data - A binary String.
#
# Returns an Array including the Array of decoded Strings and the Integer
# number of bytes read.
def decode_strings(data)
total_read = 0
strs = []
while data.bytesize > total_read
str, read = decode_string(data, total_read)
strs << str
total_read += read
end
[strs, total_read]
end
# Read a multi-precision integer from the provided data.
#
# data - A binary String.

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

@ -65,7 +65,7 @@ describe SSHData::Certificate do
expect(rsa_cert.serial).to eq(123)
expect(rsa_cert.type).to eq(SSHData::Certificate::TYPE_USER)
expect(rsa_cert.key_id).to eq("my-ident")
expect(rsa_cert.valid_principals).to eq("\x00\x00\x00\x0Cmy-principal")
expect(rsa_cert.valid_principals).to eq(["my-principal"])
expect(rsa_cert.valid_after).to eq(min_time)
expect(rsa_cert.valid_before).to eq(max_time)
expect(rsa_cert.critical_options).to eq("\x00\x00\x00\x03foo\x00\x00\x00\x07\x00\x00\x00\x03bar")
@ -82,7 +82,7 @@ describe SSHData::Certificate do
expect(dsa_cert.serial).to eq(123)
expect(dsa_cert.type).to eq(SSHData::Certificate::TYPE_USER)
expect(dsa_cert.key_id).to eq("my-ident")
expect(dsa_cert.valid_principals).to eq("\x00\x00\x00\x0Cmy-principal")
expect(dsa_cert.valid_principals).to eq(["my-principal"])
expect(dsa_cert.valid_after).to eq(min_time)
expect(dsa_cert.valid_before).to eq(max_time)
expect(dsa_cert.critical_options).to eq("\x00\x00\x00\x03foo\x00\x00\x00\x07\x00\x00\x00\x03bar")
@ -99,7 +99,7 @@ describe SSHData::Certificate do
expect(ecdsa_cert.serial).to eq(123)
expect(ecdsa_cert.type).to eq(SSHData::Certificate::TYPE_USER)
expect(ecdsa_cert.key_id).to eq("my-ident")
expect(ecdsa_cert.valid_principals).to eq("\x00\x00\x00\x0Cmy-principal")
expect(ecdsa_cert.valid_principals).to eq(["my-principal"])
expect(ecdsa_cert.valid_after).to eq(min_time)
expect(ecdsa_cert.valid_before).to eq(max_time)
expect(ecdsa_cert.critical_options).to eq("\x00\x00\x00\x03foo\x00\x00\x00\x07\x00\x00\x00\x03bar")
@ -116,7 +116,7 @@ describe SSHData::Certificate do
expect(ed25519_cert.serial).to eq(123)
expect(ed25519_cert.type).to eq(SSHData::Certificate::TYPE_USER)
expect(ed25519_cert.key_id).to eq("my-ident")
expect(ed25519_cert.valid_principals).to eq("\x00\x00\x00\x0Cmy-principal")
expect(ed25519_cert.valid_principals).to eq(["my-principal"])
expect(ed25519_cert.valid_after).to eq(min_time)
expect(ed25519_cert.valid_before).to eq(max_time)
expect(ed25519_cert.critical_options).to eq("\x00\x00\x00\x03foo\x00\x00\x00\x07\x00\x00\x00\x03bar")
@ -133,7 +133,7 @@ describe SSHData::Certificate do
expect(rsa_ca_cert.serial).to eq(123)
expect(rsa_ca_cert.type).to eq(SSHData::Certificate::TYPE_USER)
expect(rsa_ca_cert.key_id).to eq("my-ident")
expect(rsa_ca_cert.valid_principals).to eq("\x00\x00\x00\x0Cmy-principal")
expect(rsa_ca_cert.valid_principals).to eq(["my-principal"])
expect(rsa_ca_cert.valid_after).to eq(min_time)
expect(rsa_ca_cert.valid_before).to eq(max_time)
expect(rsa_ca_cert.critical_options).to eq("\x00\x00\x00\x03foo\x00\x00\x00\x07\x00\x00\x00\x03bar")
@ -150,7 +150,7 @@ describe SSHData::Certificate do
expect(dsa_ca_cert.serial).to eq(123)
expect(dsa_ca_cert.type).to eq(SSHData::Certificate::TYPE_USER)
expect(dsa_ca_cert.key_id).to eq("my-ident")
expect(dsa_ca_cert.valid_principals).to eq("\x00\x00\x00\x0Cmy-principal")
expect(dsa_ca_cert.valid_principals).to eq(["my-principal"])
expect(dsa_ca_cert.valid_after).to eq(min_time)
expect(dsa_ca_cert.valid_before).to eq(max_time)
expect(dsa_ca_cert.critical_options).to eq("\x00\x00\x00\x03foo\x00\x00\x00\x07\x00\x00\x00\x03bar")
@ -167,7 +167,7 @@ describe SSHData::Certificate do
expect(ecdsa_ca_cert.serial).to eq(123)
expect(ecdsa_ca_cert.type).to eq(SSHData::Certificate::TYPE_USER)
expect(ecdsa_ca_cert.key_id).to eq("my-ident")
expect(ecdsa_ca_cert.valid_principals).to eq("\x00\x00\x00\x0Cmy-principal")
expect(ecdsa_ca_cert.valid_principals).to eq(["my-principal"])
expect(ecdsa_ca_cert.valid_after).to eq(min_time)
expect(ecdsa_ca_cert.valid_before).to eq(max_time)
expect(ecdsa_ca_cert.critical_options).to eq("\x00\x00\x00\x03foo\x00\x00\x00\x07\x00\x00\x00\x03bar")
@ -184,7 +184,7 @@ describe SSHData::Certificate do
expect(ed25519_ca_cert.serial).to eq(123)
expect(ed25519_ca_cert.type).to eq(SSHData::Certificate::TYPE_USER)
expect(ed25519_ca_cert.key_id).to eq("my-ident")
expect(ed25519_ca_cert.valid_principals).to eq("\x00\x00\x00\x0Cmy-principal")
expect(ed25519_ca_cert.valid_principals).to eq(["my-principal"])
expect(ed25519_ca_cert.valid_after).to eq(min_time)
expect(ed25519_ca_cert.valid_before).to eq(max_time)
expect(ed25519_ca_cert.critical_options).to eq("\x00\x00\x00\x03foo\x00\x00\x00\x07\x00\x00\x00\x03bar")

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

@ -17,6 +17,18 @@ describe SSHData::Encoding do
let(:ecdsa_ca_data) { described_class.decode_certificate(fixture("rsa_leaf_for_ecdsa_ca-cert.pub", binary: true)).first }
let(:ed25519_ca_data) { described_class.decode_certificate(fixture("rsa_leaf_for_ed25519_ca-cert.pub", binary: true)).first }
it "can decode a series of strings" do
strs = %w(one two three)
encoded = strs.map { |s| described_class.encode_string(s) }.join
decoded, read = described_class.decode_strings(encoded)
expect(decoded).to eq(strs)
expect(read).to eq(encoded.bytesize)
decoded, read = described_class.decode_strings("")
expect(decoded).to eq([])
expect(read).to eq(0)
end
it "can round trip a string" do
s1 = "foobar"
s2, read = described_class.decode_string(described_class.encode_string(s1))