aboutsummaryrefslogtreecommitdiff
path: root/3.2/mail.rb
diff options
context:
space:
mode:
Diffstat (limited to '3.2/mail.rb')
-rwxr-xr-x3.2/mail.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/3.2/mail.rb b/3.2/mail.rb
new file mode 100755
index 0000000..e8f9cdd
--- /dev/null
+++ b/3.2/mail.rb
@@ -0,0 +1,32 @@
+#!/usr/bin/env ruby
+
+require 'openssl'
+require 'securerandom'
+require 'sinatra'
+
+set :port, 4568
+
+Service = "Mail"
+ServicePassword = "{FvM<kgG}VpHxKJO;6Zo"
+
+def decrypt(ticket)
+ ticket = [ticket].pack("H*").unpack("C*").pack("c*")
+ cipher = OpenSSL::Cipher::AES.new(256, :CBC).decrypt
+ cipher.key = Digest::SHA2.digest(ServicePassword)
+ cipher.update(ticket) + cipher.final
+end
+
+post '/login' do
+ request.body.rewind
+ data = JSON.parse(request.body.read)
+ next "Invalid request\n" unless data.keys.sort == %w(ticket username)
+ un, ws, sn, ls, ts = decrypt(data["ticket"]).split(?\0)
+ ls = ls.to_i
+ ts = ts.to_i
+ next "Invalid ticket\n" unless sn == Service
+ next "Invalid ticket\n" unless un == data["username"]
+ next "Invalid ticket\n" unless ws == request.ip
+ next "Invalid ticket\n" unless Time.now.to_i >= ts
+ next "Ticket expired\n" unless Time.now.to_i < (ts + ls)
+ "Login okay! You have no mail.\n"
+end