bin/ssltransportagentgemtest.rb
# for testing, use:
#
# swaks -tls -a plain -s mail.example.com:2000 -t coco@example.com -f mjwelchphd@gmail.com
# Username: coco@czarmail.com
# Password: my-password
#
# NOTE: replace mail.example.com:2000 with your test server domain or ip
#
# swaks will send AUTH PLAIN AGNvY29AY3phcm1haWwuY29tAG15LXBhc3N3b3Jk
# for its authorization request. The code AGNvY...3b3Jk is base64.
#
#   AGNvY29AY3phcm1haWwuY29tAG15LXBhc3N3b3Jk decoded => ["coco@czarmail.com", "my-password"]
#   "my-password" hashed => {CRYPT}IwYH/ZXeR8vUM
#
# The 'validate_plain' method will decode it into username/password and yield(username)
# to the caller's block, which looks up the {CRYPT} hash for username. In the test
# code, then {CRYPT} hash is simply returned always for testing. The method checks the
# given password against the hash, and if it matches, it returns true; else false.
#
# "AGNvY29AY3phcm1haWwuY29tAG15LXBhc3N3b3Jk".validate_plain { "{CRYPT}IwYH/ZXeR8vUM" } => "coco@czarmail.com", true


replace mail.example.com:2000 with your test server domain or ip

swaks will send AUTH PLAIN AGNvY29AY3phcm1haWwuY29tAG15LXBhc3N3b3Jk
for its authorization request. The code AGNvY...3b3Jk is base64.



The 'validate_plain' method will decode it into username/password and yield(username)
to the caller's block, which looks up the {CRYPT} hash for username. In the test
code, then {CRYPT} hash is simply returned always for testing. The method checks the
given password against the hash, and if it matches, it returns true; else false.


replace mail . example . com : 2000 with your test server domain or ip swaks will send AUTH PLAIN AGNvY29AY3phcm1haWwuY29tAG15LXBhc3N3b3Jk for its authorization request . The code AGNvY ... 3b3Jk is base64 . The ' validate_plain ' method will decode it into username / password and yield ( username ) to the caller ' s block which looks up the { CRYPT } hash for username . In the test code then { CRYPT } hash is simply returned always for testing . The method checks the given password against the hash and if it matches it returns true ; else false .
def auth(value)
    auth_type, auth_encoded = value.split
    case auth_type.upcase
    when "PLAIN"
      username, ok = auth_encoded.validate_plain do |username|
        "{CRYPT}IwYH/ZXeR8vUM" 
      end
      if ok
        send_text("235 2.0.0 Authentication succeeded")
        @mail[:authenticated] = username
      else
        send_text("530 5.7.8 Authentication failed")
      end
    else
      send_text("504 5.7.4 authentication mechanism not supported")
    end
  end
def auth ( value ) auth_type , auth_encoded = value . split case auth_type . upcase when "PLAIN" username , ok = auth_encoded . validate_plain do | username | "{CRYPT}IwYH/ZXeR8vUM" end if ok send_text ( "235 2.0.0 Authentication succeeded" ) @mail [ :authenticated ] = username else send_text ( "530 5.7.8 Authentication failed" ) end else send_text ( "504 5.7.4 authentication mechanism not supported" ) end end
for testing, use:
swaks -tls -a plain -s mail.example.com:2000 -t coco@example.com -f mjwelchphd@gmail.com
Username: coco@czarmail.com
Password: my-password
for testing use : swaks - tls - a plain - s mail . example . com : 2000 - t coco@example . com - f mjwelchphd@gmail . com Username : coco@czarmail . com Password : my - password
# auth_encoded contains both username and password # get the password hash from the database # for testing
value
<not_specific>