diff --git a/comp/src/gb.net.smtp/.src/Main.module b/comp/src/gb.net.smtp/.src/Main.module index be8a7b665..44bad0024 100644 --- a/comp/src/gb.net.smtp/.src/Main.module +++ b/comp/src/gb.net.smtp/.src/Main.module @@ -18,9 +18,27 @@ Public Sub Main() ' hClient.Add(File.Load("~/TexteDehorsilpleut.odt"), "application/vnd.oasis.opendocument.text", "Dehors il pleut.odt") ' hClient.Add(File.Load("~/balloon.png"), "image/png", "balloon.png") ' hClient.Send - + Dim hMsg As New SmtpClient + ' Dim sChallenge As String + ' Dim sKey As String + ' Dim sCommand As String + ' Dim sResult As String + ' + ' sChallenge = "'abc'" + ' sKey = "benoit" + ' + ' sCommand = "echo -n " & Shell$(sChallenge) & " | openssl md5 -hmac " & Shell$(sKey) + ' Shell sCommand To sResult + ' Print sResult + ' + ' sCommand = "openssl md5 -hmac " & Shell$(sKey) & " << EOF\n'abc'" + ' Shell sCommand To sResult + ' Print sResult + ' + ' Return + hMsg.Debug = True hMsg.To.Add("benoit@minisini.fr") hMsg.Subject = "Test mail headers 5" diff --git a/comp/src/gb.net.smtp/.src/SmtpClient.class b/comp/src/gb.net.smtp/.src/SmtpClient.class index 1332bdcf8..2357e8aea 100644 --- a/comp/src/gb.net.smtp/.src/SmtpClient.class +++ b/comp/src/gb.net.smtp/.src/SmtpClient.class @@ -309,21 +309,55 @@ Catch End Private Sub Authenticate() - - Dim sData As String - + + Dim sChallenge64, sChallenge, sKey, sCommand, sResponse, sDigestHex As String + If Not $sUser Then Return - - sData = $hSession.Send("AUTH PLAIN") - If $hSession.LastCode <> "334" Then Error.Raise("Unsupported authentication method") - - sData = $hSession.Send(Base64$($sUser & Chr$(0) & $sUser & Chr$(0) & $sPassword), True) - If $hSession.LastCode <> "235" Then Error.Raise("Authentication failed") - + + ' AUTH LOGIN + $hSession.Send("AUTH LOGIN") + If $hSession.LastCode = "334" Then + $hSession.Send(Base64$($sUser)) + If $hSession.LastCode = "334" Then + $hSession.Send(Base64$($sPassword)) + If $hSession.LastCode = "235" Then Return + Endif + Endif + + ' AUTH PLAIN + $hSession.Send("AUTH PLAIN") + If $hSession.LastCode <> "334" Then + $hSession.Send("AUTH PLAIN " & Base64$($sUser & Chr$(0) & $sUser & Chr$(0) & $sPassword), True) + Else + $hSession.Send(Base64$($sUser & Chr$(0) & $sUser & Chr$(0) & $sPassword), True) + Endif + If $hSession.LastCode = "235" Then Return + + ' CRAM-MD5 + $hSession.Send("AUTH CRAM-MD5") + 'If $hSession.LastCode = "334" Then Print "LastAnswer = "; $hSession.LastAnswer + + sChallenge64 = Split($hSession.LastAnswer, " ")[1] + sChallenge = UnBase64(sChallenge64) + sKey = $sPassword + + 'sCommand = "echo -n " & Shell$(sChallenge) & " | openssl md5 -hmac " & Shell$(sKey) + sCommand = "openssl md5 -hmac " & Shell$(sKey) & " << EOF\n" & sChallenge + Shell sCommand To sDigestHex + + sDigestHex = Trim(Split(sDigestHex, "=")[1]) + sResponse = Base64($sUser & sDigestHex) + + $hSession.Send(sResponse) + If $hSession.LastCode = "235" Then Return + + ' Nothing worked? + Error.Raise("Authentication failed") + Catch - + Error.Raise("Unable to authenticate: " & Error.Text) - + End Private Sub SendRecipients()