|
2 | 2 |
|
3 | 3 | describe SSHData::PublicKey::SKECDSA do |
4 | 4 | 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 | + } |
5 | 10 |
|
6 | 11 | it "can parse openssh-generate keys" do |
7 | 12 | expect { openssh_key }.not_to raise_error |
|
11 | 16 | expect(openssh_key.rfc4253).to eq(fixture("skecdsa_leaf_for_rsa_ca.pub", binary: true)) |
12 | 17 | end |
13 | 18 |
|
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), |
18 | 23 | SSHData::Encoding.encode_string(openssh_key.curve), |
19 | 24 | 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:'), |
20 | 40 | ].join)].join(" ") |
21 | 41 |
|
22 | 42 | expect { |
|
0 commit comments