Class: OpenSSL::PKey::DSA

Inherits:
Object
  • Object
show all
Defined in:
lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb

Overview

This class is originally defined in the OpenSSL module. As needed, methods have been added to it by the Net::SSH module for convenience in dealing with SSH functionality.

Instance Method Summary collapse

Instance Method Details

#ssh_do_sign(data) ⇒ Object

Signs the given data.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb', line 107

def ssh_do_sign(data)
  sig = sign( OpenSSL::Digest::DSS1.new, data)
  a1sig = OpenSSL::ASN1.decode( sig )

  sig_r = a1sig.value[0].value.to_s(2)
  sig_s = a1sig.value[1].value.to_s(2)

  if sig_r.length > 20 || sig_s.length > 20
    raise OpenSSL::PKey::DSAError, "bad sig size"
  end

  sig_r = "\0" * ( 20 - sig_r.length ) + sig_r if sig_r.length < 20
  sig_s = "\0" * ( 20 - sig_s.length ) + sig_s if sig_s.length < 20

  return sig_r + sig_s
end

#ssh_do_verify(sig, data) ⇒ Object

Verifies the given signature matches the given data.



96
97
98
99
100
101
102
103
104
# File 'lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb', line 96

def ssh_do_verify(sig, data)
  sig_r = sig[0,20].unpack("H*")[0].to_i(16)
  sig_s = sig[20,20].unpack("H*")[0].to_i(16)
  a1sig = OpenSSL::ASN1::Sequence([
     OpenSSL::ASN1::Integer(sig_r),
     OpenSSL::ASN1::Integer(sig_s)
  ])
  return verify(OpenSSL::Digest::DSS1.new, a1sig.to_der, data)
end

#ssh_typeObject

Returns “ssh-dss”, which is the description of this key type used by the SSH2 protocol.



85
86
87
# File 'lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb', line 85

def ssh_type
  "ssh-dss"
end

#to_blobObject

Converts the key to a blob, according to the SSH2 protocol.



90
91
92
93
# File 'lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb', line 90

def to_blob
  @blob ||= Net::SSH::Buffer.from(:string, ssh_type,
    :bignum, p, :bignum, q, :bignum, g, :bignum, pub_key).to_s
end