mirror of
https://github.com/jakobadam/RDSFactor.git
synced 2025-07-23 10:05:55 +02:00
Merge a7d447029e
into a69e94fac0
This commit is contained in:
commit
1ff32e4345
3 changed files with 21 additions and 21 deletions
|
@ -253,7 +253,7 @@ Public Class RDSFactor
|
||||||
mail.To.Add(email)
|
mail.To.Add(email)
|
||||||
mail.From = New MailAddress(SenderEmail)
|
mail.From = New MailAddress(SenderEmail)
|
||||||
mail.Subject = "Token: " & passcode
|
mail.Subject = "Token: " & passcode
|
||||||
mail.Body = "Subject contains the token code to login to you site"
|
mail.Body = "Subject contains the token code to login to the site"
|
||||||
mail.IsBodyHtml = False
|
mail.IsBodyHtml = False
|
||||||
Dim smtp As New SmtpClient(MailServer)
|
Dim smtp As New SmtpClient(MailServer)
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ Public Class RDSFactor
|
||||||
Try
|
Try
|
||||||
smtp.Send(mail)
|
smtp.Send(mail)
|
||||||
If DEBUG = True Then
|
If DEBUG = True Then
|
||||||
LogDebug(Now & ": Mail send to: " & email)
|
LogDebug(Now & ": Mail sent to: " & email)
|
||||||
End If
|
End If
|
||||||
Return "SEND"
|
Return "SEND"
|
||||||
Catch e As InvalidCastException
|
Catch e As InvalidCastException
|
||||||
|
|
|
@ -10,7 +10,7 @@ Public Class RDSHandler
|
||||||
|
|
||||||
Private Shared userSessions As New Hashtable
|
Private Shared userSessions As New Hashtable
|
||||||
Private Shared sessionTimestamps As New Hashtable
|
Private Shared sessionTimestamps As New Hashtable
|
||||||
Private Shared encryptedChallangeResults As New Hashtable
|
Private Shared encryptedChallengeResults As New Hashtable
|
||||||
Private Shared userLaunchTimestamps As New Hashtable
|
Private Shared userLaunchTimestamps As New Hashtable
|
||||||
|
|
||||||
Private mPacket As RADIUSPacket
|
Private mPacket As RADIUSPacket
|
||||||
|
@ -149,7 +149,7 @@ Public Class RDSHandler
|
||||||
Dim attributes As New RADIUSAttributes
|
Dim attributes As New RADIUSAttributes
|
||||||
|
|
||||||
If sessionId = Nothing Or launchTimestamp = Nothing Then
|
If sessionId = Nothing Or launchTimestamp = Nothing Then
|
||||||
RDSFactor.LogDebug(mPacket, "User's has no launch window. User must re-authenticate")
|
RDSFactor.LogDebug(mPacket, "User has no launch window. User must re-authenticate")
|
||||||
mPacket.RejectAccessRequest()
|
mPacket.RejectAccessRequest()
|
||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
|
@ -175,7 +175,7 @@ Public Class RDSHandler
|
||||||
Public Sub ProcessAccessRequest()
|
Public Sub ProcessAccessRequest()
|
||||||
Dim hasState = mPacket.Attributes.AttributeExists(RadiusAttributeType.State)
|
Dim hasState = mPacket.Attributes.AttributeExists(RadiusAttributeType.State)
|
||||||
If hasState Then
|
If hasState Then
|
||||||
' An Access-Request with a state is pr. definition a challange response.
|
' An Access-Request with a state is pr. definition a challenge response.
|
||||||
ProcessChallengeResponse()
|
ProcessChallengeResponse()
|
||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
|
@ -212,48 +212,48 @@ Public Class RDSHandler
|
||||||
Private Sub ProcessChallengeResponse()
|
Private Sub ProcessChallengeResponse()
|
||||||
Dim authToken = mPacket.Attributes.GetFirstAttribute(RadiusAttributeType.State).ToString
|
Dim authToken = mPacket.Attributes.GetFirstAttribute(RadiusAttributeType.State).ToString
|
||||||
If Not authToken = authTokens(mUsername) Then
|
If Not authToken = authTokens(mUsername) Then
|
||||||
Throw New Exception("User is trying to respond to challange without valid auth token")
|
Throw New Exception("User is trying to respond to challenge without valid auth token")
|
||||||
End If
|
End If
|
||||||
|
|
||||||
' When the packet is an Challange-Response the password attr. contains the encrypted result
|
' When the packet is an Challenge-Response the password attr. contains the encrypted result
|
||||||
Dim userEncryptedResult = mPassword
|
Dim userEncryptedResult = mPassword
|
||||||
Dim localEncryptedResult = encryptedChallangeResults(mUsername)
|
Dim localEncryptedResult = encryptedChallengeResults(mUsername)
|
||||||
|
|
||||||
If localEncryptedResult = userEncryptedResult Then
|
If localEncryptedResult = userEncryptedResult Then
|
||||||
RDSFactor.LogDebug(mPacket, "ChallengeResponse Success")
|
RDSFactor.LogDebug(mPacket, "ChallengeResponse Success")
|
||||||
encryptedChallangeResults.Remove(mUsername)
|
encryptedChallengeResults.Remove(mUsername)
|
||||||
authTokens.Remove(mUsername)
|
authTokens.Remove(mUsername)
|
||||||
Accept()
|
Accept()
|
||||||
Else
|
Else
|
||||||
RDSFactor.LogDebug(mPacket, "Wrong challange code!")
|
RDSFactor.LogDebug(mPacket, "Wrong challenge code!")
|
||||||
mPacket.RejectAccessRequest()
|
mPacket.RejectAccessRequest()
|
||||||
End If
|
End If
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Sub TwoFactorChallenge(ldapResult As SearchResult)
|
Private Sub TwoFactorChallenge(ldapResult As SearchResult)
|
||||||
Dim challangeCode = RDSFactor.GenerateCode
|
Dim challengeCode = RDSFactor.GenerateCode
|
||||||
Dim authToken = System.Guid.NewGuid.ToString
|
Dim authToken = System.Guid.NewGuid.ToString
|
||||||
Dim clientIP = mPacket.EndPoint.Address.ToString
|
Dim clientIP = mPacket.EndPoint.Address.ToString
|
||||||
Dim sharedSecret = RDSFactor.secrets(clientIP)
|
Dim sharedSecret = RDSFactor.secrets(clientIP)
|
||||||
|
|
||||||
RDSFactor.LogDebug(mPacket, "Access Challange Code: " & challangeCode)
|
RDSFactor.LogDebug(mPacket, "Access Challenge Code: " & challengeCode)
|
||||||
|
|
||||||
If sharedSecret = Nothing Then
|
If sharedSecret = Nothing Then
|
||||||
Throw New Exception("No shared secret for client:" & clientIP)
|
Throw New Exception("No shared secret for client:" & clientIP)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
authTokens(mUsername) = authToken
|
authTokens(mUsername) = authToken
|
||||||
Dim encryptedChallangeResult = Crypto.SHA256(mUsername & challangeCode & sharedSecret)
|
Dim encryptedChallengeResult = Crypto.SHA256(mUsername & challengeCode & sharedSecret)
|
||||||
encryptedChallangeResults(mUsername) = encryptedChallangeResult
|
encryptedChallengeResults(mUsername) = encryptedChallengeResult
|
||||||
|
|
||||||
If mUseSMSFactor Then
|
If mUseSMSFactor Then
|
||||||
Dim mobile = LdapGetNumber(ldapResult)
|
Dim mobile = LdapGetNumber(ldapResult)
|
||||||
RDSFactor.SendSMS(mobile, challangeCode)
|
RDSFactor.SendSMS(mobile, challengeCode)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
If mUseEmailFactor Then
|
If mUseEmailFactor Then
|
||||||
Dim email = LdapGetEmail(ldapResult)
|
Dim email = LdapGetEmail(ldapResult)
|
||||||
RDSFactor.SendEmail(email, challangeCode)
|
RDSFactor.SendEmail(email, challengeCode)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Dim attributes As New RADIUSAttributes
|
Dim attributes As New RADIUSAttributes
|
||||||
|
@ -333,7 +333,7 @@ Public Class RDSHandler
|
||||||
userSessions.Remove(username)
|
userSessions.Remove(username)
|
||||||
sessionTimestamps.Remove(username)
|
sessionTimestamps.Remove(username)
|
||||||
userLaunchTimestamps.Remove(username)
|
userLaunchTimestamps.Remove(username)
|
||||||
encryptedChallangeResults.Remove(username)
|
encryptedChallengeResults.Remove(username)
|
||||||
authTokens.Remove(username)
|
authTokens.Remove(username)
|
||||||
End If
|
End If
|
||||||
Next
|
Next
|
||||||
|
|
|
@ -45,8 +45,8 @@ public partial class SMSToken : System.Web.UI.Page
|
||||||
|
|
||||||
atts.Add(state);
|
atts.Add(state);
|
||||||
|
|
||||||
String encryptedChallangeResult = Crypto.SHA256(username + SmsToken.Text + radiusSecret);
|
String encryptedChallengeResult = Crypto.SHA256(username + SmsToken.Text + radiusSecret);
|
||||||
RADIUSPacket response = client.Authenticate(username, encryptedChallangeResult, atts);
|
RADIUSPacket response = client.Authenticate(username, encryptedChallengeResult, atts);
|
||||||
|
|
||||||
onRadiusResponse(response);
|
onRadiusResponse(response);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public partial class SMSToken : System.Web.UI.Page
|
||||||
|
|
||||||
void onRadiusResponse(RADIUSPacket response) {
|
void onRadiusResponse(RADIUSPacket response) {
|
||||||
if (response.Code == RadiusPacketCode.AccessChallenge) {
|
if (response.Code == RadiusPacketCode.AccessChallenge) {
|
||||||
onRadiusChallange(response);
|
onRadiusChallenge(response);
|
||||||
}
|
}
|
||||||
else if (response.Code == RadiusPacketCode.AccessAccept) {
|
else if (response.Code == RadiusPacketCode.AccessAccept) {
|
||||||
onRadiusAccept(response);
|
onRadiusAccept(response);
|
||||||
|
@ -84,7 +84,7 @@ public partial class SMSToken : System.Web.UI.Page
|
||||||
logoff();
|
logoff();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onRadiusChallange(RADIUSPacket response){
|
void onRadiusChallenge(RADIUSPacket response){
|
||||||
RADIUSAttribute state = response.Attributes.GetFirstAttribute(RadiusAttributeType.State);
|
RADIUSAttribute state = response.Attributes.GetFirstAttribute(RadiusAttributeType.State);
|
||||||
Session["State"] = state;
|
Session["State"] = state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue