Skip to content

Commit 3855f1c

Browse files
committed
Improve SK-EC tests.
1 parent be8023c commit 3855f1c

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

spec/public_key/skecdsa_spec.rb

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
describe SSHData::PublicKey::SKECDSA do
44
let(:openssh_key) { SSHData::PublicKey.parse_openssh(fixture("skecdsa_leaf_for_rsa_ca.pub")) }
5+
let(:ec_p384_publickey) { OpenSSL::PKey::EC.new('secp384r1').tap { |k|
6+
k.generate_key
7+
k.private_key = nil
8+
}
9+
}
510

611
it "can parse openssh-generate keys" do
712
expect { openssh_key }.not_to raise_error
@@ -11,12 +16,27 @@
1116
expect(openssh_key.rfc4253).to eq(fixture("skecdsa_leaf_for_rsa_ca.pub", binary: true))
1217
end
1318

14-
it "blows up if the curve doesn't match the key type" do
15-
# outer layer claims to be p384, but curve and public key are p256
16-
malformed = [SSHData::PublicKey::ALGO_ECDSA384, Base64.strict_encode64([
17-
SSHData::Encoding.encode_string(SSHData::PublicKey::ALGO_ECDSA384),
19+
it "blows up if the inner key identifier is not a security key" do
20+
# outer layer claims to be SK-ECDSA256, but inner key is plain ECDSA256
21+
malformed = [SSHData::PublicKey::ALGO_SKECDSA256, Base64.strict_encode64([
22+
SSHData::Encoding.encode_string(SSHData::PublicKey::ALGO_ECDSA256),
1823
SSHData::Encoding.encode_string(openssh_key.curve),
1924
SSHData::Encoding.encode_string(openssh_key.public_key_bytes),
25+
SSHData::Encoding.encode_string('ssh:'),
26+
].join)].join(" ")
27+
28+
expect {
29+
SSHData::PublicKey.parse_openssh(malformed)
30+
}.to raise_error(SSHData::DecodeError)
31+
end
32+
33+
it "blows up if the inner key identifier has a mismatched curve" do
34+
# outer layer claims to be SK-ECDSA256, but inner key is SK-ECDSA256 with a P384 curve
35+
malformed = [SSHData::PublicKey::ALGO_SKECDSA256, Base64.strict_encode64([
36+
SSHData::Encoding.encode_string(SSHData::PublicKey::ALGO_SKECDSA256),
37+
SSHData::Encoding.encode_string('nistp384'),
38+
SSHData::Encoding.encode_string(ec_p384_publickey.to_der),
39+
SSHData::Encoding.encode_string('ssh:'),
2040
].join)].join(" ")
2141

2242
expect {

0 commit comments

Comments
 (0)