|
5 | 5 | let(:public_key) { private_key.public_key } |
6 | 6 | let(:params) { private_key.params } |
7 | 7 | let(:message) { "hello, world!" } |
| 8 | + let(:cert_key) { SSHData::PrivateKey::DSA.generate.public_key } |
8 | 9 |
|
9 | 10 | let(:openssh_key) { SSHData::PrivateKey.parse(fixture("rsa_leaf_for_rsa_ca")) } |
10 | 11 |
|
|
28 | 29 | }.not_to raise_error |
29 | 30 | end |
30 | 31 |
|
31 | | - it "can sign messages" do |
32 | | - expect(subject.public_key.verify(message, subject.sign(message))).to eq(true) |
| 32 | + [ |
| 33 | + nil, |
| 34 | + SSHData::PublicKey::ALGO_RSA, |
| 35 | + SSHData::PublicKey::ALGO_RSA_SHA2_256, |
| 36 | + SSHData::PublicKey::ALGO_RSA_SHA2_512 |
| 37 | + ].each do |signature_algo| |
| 38 | + it "can sign messages with #{signature_algo}" do |
| 39 | + sig = subject.sign(message, algo: signature_algo) |
| 40 | + expect(subject.public_key.verify(message, sig)).to eq(true) |
| 41 | + |
| 42 | + algo, _ = SSHData::Encoding.decode_signature(sig) |
| 43 | + expect(algo).to eq(signature_algo || SSHData::PublicKey::ALGO_RSA) |
| 44 | + end |
| 45 | + |
| 46 | + it "can issue a certificate with a #{signature_algo} signature" do |
| 47 | + cert = subject.issue_certificate( |
| 48 | + public_key: cert_key, |
| 49 | + key_id: "some ident", |
| 50 | + signature_algo: signature_algo |
| 51 | + ) |
| 52 | + |
| 53 | + algo, _ = SSHData::Encoding.decode_signature(cert.signature) |
| 54 | + |
| 55 | + expect(algo).to eq(signature_algo || SSHData::PublicKey::ALGO_RSA) |
| 56 | + expect(cert.verify).to be(true) |
| 57 | + end |
33 | 58 | end |
34 | 59 |
|
35 | | - it "can sign messages with ALGO_RSA" do |
36 | | - sig = subject.sign(message, algo: SSHData::PublicKey::ALGO_RSA) |
37 | | - expect(subject.public_key.verify(message, sig)).to eq(true) |
38 | | - end |
39 | | - |
40 | | - it "can sign messages with ALGO_RSA_SHA2_256" do |
41 | | - sig = subject.sign(message, algo: SSHData::PublicKey::ALGO_RSA_SHA2_256) |
42 | | - expect(subject.public_key.verify(message, sig)).to eq(true) |
43 | | - end |
44 | | - |
45 | | - it "can sign messages with ALGO_RSA_SHA2_512" do |
46 | | - sig = subject.sign(message, algo: SSHData::PublicKey::ALGO_RSA_SHA2_512) |
47 | | - expect(subject.public_key.verify(message, sig)).to eq(true) |
| 60 | + it "raises when trying to sign with bad algo" do |
| 61 | + expect { |
| 62 | + subject.issue_certificate( |
| 63 | + public_key: cert_key, |
| 64 | + key_id: "some ident", |
| 65 | + signature_algo: SSHData::PublicKey::ALGO_DSA |
| 66 | + ) |
| 67 | + }.to raise_error(SSHData::AlgorithmError) |
48 | 68 | end |
49 | 69 |
|
50 | | - it "raises when trying to sign with bad algo" do |
| 70 | + it "raises when trying to issue a certificate with bad signature algo" do |
51 | 71 | expect { |
52 | 72 | subject.sign(message, algo: SSHData::PublicKey::ALGO_DSA) |
53 | 73 | }.to raise_error(SSHData::AlgorithmError) |
|
0 commit comments