File: gss_server.rb

package info (click to toggle)
ruby-gssapi 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 216 kB
  • sloc: ruby: 770; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 802 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'gssapi'
require 'base64'
require 'socket'


host = 'example.org'
service  = 'host'
keytab = "#{ENV['HOME']}/.gssapi/krb5.keytab"  # this is optional, but probably required if not running as root

tcpsrv = TCPServer.new(host, 8082)

loop do
  Thread.start(tcpsrv.accept) do |s|
    print(s, "Accepted Connection\n")
    stok = s.gets.chomp
    print(s, "Received string#{stok}\n")
    srv = GSSAPI::Simple.new(host, service, keytab)
    srv.acquire_credentials
    otok = srv.accept_context(Base64.strict_decode64(stok.chomp))
    s.write("#{Base64.strict_encode64(otok)}\n")

    begin
      emsg = s.gets.chomp
      msg = srv.unwrap_message(Base64.strict_decode64(emsg.chomp))
      puts "Received: #{msg}"
    end while msg != 'exit'

    print(s, "Closing Socket\n")
    s.close
  end
end