File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 834834 data , total_read = SSHData ::Encoding . decode_openssh_signature ( signature_appended , offset = prefix . bytesize )
835835 expect ( total_read ) . to eq ( signature . bytesize )
836836 end
837+
838+ it "fails if the signature does not begin with wrong magic prefix" do
839+ wrong_magic = signature . gsub ( /^SSHSIG/ , "NOGOOD" )
840+ expect { SSHData ::Encoding . decode_openssh_signature ( wrong_magic ) } . to raise_error ( SSHData ::DecodeError )
841+ end
842+
843+ it "fails if the signature is shorter than magic prefix" do
844+ short_sig = "OHHI"
845+ expect { SSHData ::Encoding . decode_openssh_signature ( short_sig ) } . to raise_error ( SSHData ::DecodeError )
846+ end
847+
848+ it "fails if the signature has magic but no decodable signature" do
849+ bad_sig = "SSHSIGOHNO"
850+ expect { SSHData ::Encoding . decode_openssh_signature ( bad_sig ) } . to raise_error ( SSHData ::DecodeError )
851+ end
852+
853+ it "fails if the signature is corrupt" do
854+ # 6 for the magic prefix
855+ # 4 for the signature version (int32)
856+ # The next 4 will be the length-prefixed the public key.
857+ # Corrupt the key by setting the length to something bogus and maintain the rest of the key.
858+ start = 6 + 4
859+ finish = start + 4
860+ bad_sig = signature . dup
861+ bad_sig [ start ...finish ] = "\xFF \xFF \xFF \xFF " . force_encoding ( 'BINARY' )
862+ expect ( bad_sig . length ) . to eq ( signature . length )
863+ expect { SSHData ::Encoding . decode_openssh_signature ( bad_sig ) } . to raise_error ( SSHData ::DecodeError )
864+ end
865+
866+ it "fails if the signature is too short" do
867+ # Hack a byte off at the end.
868+ bad_sig = signature . byteslice ( ( ..-2 ) )
869+ expect { SSHData ::Encoding . decode_openssh_signature ( bad_sig ) } . to raise_error ( SSHData ::DecodeError )
870+ end
837871 end
838872end
You can’t perform that action at this time.
0 commit comments