Sha256: e00c320d5198f3ca1f3652581d7d8bfaec49eef01753f6147f1c1936f94665b2

Contents?: true

Size: 1.19 KB

Versions: 149

Compression:

Stored size: 1.19 KB

Contents

require 'openssl'
require 'base64'

module Travis
  module Tools
    module SSLKey
      extend self

      def generate_rsa(size = 2048)
        OpenSSL::PKey::RSA.generate(size)
      end

      def public_rsa_key(string)
        @to_rsa ||= OpenSSL::PKey::RSA.new(string)
      rescue OpenSSL::PKey::RSAError
        public_key = string.gsub('RSA PUBLIC KEY', 'PUBLIC KEY')
        @to_rsa = OpenSSL::PKey::RSA.new(public_key)
      end

      def has_passphrase?(key)
        OpenSSL::PKey::RSA.new(key, key)
        false
      rescue OpenSSL::PKey::RSAError
        true
      end

      def remove_passphrase(key, passphrase)
        OpenSSL::PKey::RSA.new(key, passphrase).to_s
      rescue OpenSSL::PKey::RSAError
        false
      end

      def rsa_ssh(key)
        ['ssh-rsa ', "\0\0\0\assh-rsa#{sized_bytes(key.e)}#{sized_bytes(key.n)}"].pack('a*m').gsub("\n", '')
      end

      def sized_bytes(value)
        bytes = to_byte_array(value.to_i)
        [bytes.size, *bytes].pack('NC*')
      end

      def to_byte_array(num, *significant)
        return significant if num.between?(-1, 0) and significant[0][7] == num[7]
        to_byte_array(*num.divmod(256)) + significant
      end
    end
  end
end

Version data entries

149 entries across 149 versions & 3 rubygems

Version Path
travis-1.8.4.travis.777.4 lib/travis/tools/ssl_key.rb
travis-1.8.4.travis.775.4 lib/travis/tools/ssl_key.rb
travis-1.8.3.travis.773.4 lib/travis/tools/ssl_key.rb
travis-async-listener-1.8.3 lib/travis/tools/ssl_key.rb
travis-1.8.3.travis.745.4 lib/travis/tools/ssl_key.rb
travis-1.8.3.travis.726.4.pre.debug lib/travis/tools/ssl_key.rb
travis-1.8.3.travis.724.4 lib/travis/tools/ssl_key.rb
travis-1.8.2 lib/travis/tools/ssl_key.rb
travis-1.8.2.travis.722.4 lib/travis/tools/ssl_key.rb
travis-1.8.2.travis.719.4 lib/travis/tools/ssl_key.rb
travis-1.8.1 lib/travis/tools/ssl_key.rb
travis-1.8.1.travis.717.4 lib/travis/tools/ssl_key.rb
travis-1.8.1.travis.713.4 lib/travis/tools/ssl_key.rb
travis-1.8.1.travis.705.5 lib/travis/tools/ssl_key.rb
travis-1.8.1.travis.704.5 lib/travis/tools/ssl_key.rb
travis-1.8.1.travis.699.5 lib/travis/tools/ssl_key.rb
travis-1.8.1.travis.697.5 lib/travis/tools/ssl_key.rb
travis-1.8.1.travis.696.5 lib/travis/tools/ssl_key.rb
travis-1.8.1.travis.693.5 lib/travis/tools/ssl_key.rb
travis-1.8.1.travis.692.5 lib/travis/tools/ssl_key.rb