Rename CICRadarR -> RDSFactor

This commit is contained in:
Jakob A. Dam 2015-04-10 09:43:25 +02:00 committed by Jakob Aarøe Dam
parent d296781847
commit a29384d872
40 changed files with 810 additions and 810 deletions

View file

@ -1,7 +1,7 @@
Imports System.ServiceProcess
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class CICRadarR
Partial Class RDSFactor
Inherits System.ServiceProcess.ServiceBase
'UserService overrides dispose to clean up the component list.
@ -28,7 +28,7 @@ Partial Class CICRadarR
'
' ServicesToRun = New System.ServiceProcess.ServiceBase () {New Service1, New MySecondUserService}
'
Dim server = New CICRadarR()
Dim server = New RDSFactor()
If Environment.UserInteractive Then
server.OnStart(args)

View file

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2013 for Windows Desktop
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "CICRadarR", "CICRadarR.vbproj", "{04C6C533-9FEA-41B2-B554-A166C7C7FE32}"
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "RDSFactor", "RDSFactor.vbproj", "{04C6C533-9FEA-41B2-B554-A166C7C7FE32}"
EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "RADAR", "..\radar-radius\RADAR\RADAR.vbproj", "{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}"
EndProject

View file

@ -9,7 +9,7 @@ Imports System
Imports System.Net.Mail
Imports RADAR
Public Class CICRadarR
Public Class RDSFactor
Public Shared LDAPDomain As String = ""
Public Shared ADField As String = ""

View file

@ -88,11 +88,11 @@
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
</Compile>
<Compile Include="CICRadarR.vb">
<Compile Include="RDSFactor.vb">
<SubType>Component</SubType>
</Compile>
<Compile Include="CICRadarR.Designer.vb">
<DependentUpon>CICRadarR.vb</DependentUpon>
<Compile Include="RDSFactor.Designer.vb">
<DependentUpon>RDSFactor.vb</DependentUpon>
</Compile>
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Resources.Designer.vb">
@ -120,8 +120,8 @@
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="CICRadarR.resx">
<DependentUpon>CICRadarR.vb</DependentUpon>
<EmbeddedResource Include="RDSFactor.resx">
<DependentUpon>RDSFactor.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="My Project\Resources.resx">
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>

View file

@ -2,7 +2,7 @@
Public Class TestService
Private Radius_Service As New CICRadarR
Private Radius_Service As New RDSFactor
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
btnStart.Enabled = False
Call Radius_Service.OnstartTest()

View file

@ -17,7 +17,7 @@ Public Class CitrixHandler
' and drop other requests silently ...
If packet.Code <> RadiusPacketCode.AccessRequest Then
CICRadarR.AccessLog("Not a valid radius packet.. Drop!")
RDSFactor.AccessLog("Not a valid radius packet.. Drop!")
Exit Sub
End If
@ -36,11 +36,11 @@ Public Class CitrixHandler
' will return Nothing.
If username Is Nothing Then
' Technically, this case is against RFC, so ... drop.
CICRadarR.AccessLog("Not a valid radius packet.. No username pressent.. Drop!")
RDSFactor.AccessLog("Not a valid radius packet.. No username pressent.. Drop!")
Exit Sub
End If
CICRadarR.AccessLog("Processing packet for user: " & username.ToString)
RDSFactor.AccessLog("Processing packet for user: " & username.ToString)
'If packetHash.ContainsKey(username.GetString & "_" & pass.GetString) Then
' Exit Sub
@ -49,27 +49,27 @@ Public Class CitrixHandler
Dim existState As Boolean = packet.Attributes.AttributeExists(RadiusAttributeType.State)
CICRadarR.AccessLog("Packet contains a state attribute? State=" & existState.ToString)
RDSFactor.AccessLog("Packet contains a state attribute? State=" & existState.ToString)
If existState = True Then ' Ok we have at packet with the State attribute set. Check if we can identify the authtentication packet.
Dim state As String = packet.Attributes.GetFirstAttribute(RadiusAttributeType.State).ToString
CICRadarR.AccessLog("Packet contains a state attribute State=" & state)
RDSFactor.AccessLog("Packet contains a state attribute State=" & state)
Dim UserDomain As String = ""
'lets see if user login using upd or UPN name
Dim sUserName As String = username.ToString
Dim sPassword As String = packet.UserPassword
CICRadarR.AccessLog("SMSToken supplied by user: " & sUserName)
RDSFactor.AccessLog("SMSToken supplied by user: " & sUserName)
sid = ""
If InStr(sUserName, "@") > 0 Then 'UPN
UserDomain = sUserName
Else 'UPD
'read domain from Hashtable
UserDomain = CICRadarR.NetBiosDomain & "\" & sUserName
UserDomain = RDSFactor.NetBiosDomain & "\" & sUserName
End If
sid = EncDec.Encrypt(UserDomain & "_" & packet.UserPassword, CICRadarR.encCode)
CICRadarR.AccessLog("Checking for userHash " & sid)
sid = EncDec.Encrypt(UserDomain & "_" & packet.UserPassword, RDSFactor.encCode)
RDSFactor.AccessLog("Checking for userHash " & sid)
If sid = state Then
packet.AcceptAccessRequest()
Else
@ -97,15 +97,15 @@ Public Class CitrixHandler
UserDomain = sUserName
Else 'UPD
'read domain from Hashtable
UserDomain = CICRadarR.NetBiosDomain & "\" & sUserName
UserDomain = RDSFactor.NetBiosDomain & "\" & sUserName
End If
CICRadarR.AccessLog("User " & UserDomain & " is trying to log in ...")
RDSFactor.AccessLog("User " & UserDomain & " is trying to log in ...")
Try
Dim dirEntry As New DirectoryEntry("LDAP://" & CICRadarR.LDAPDomain, UserDomain, sPassword)
Dim dirEntry As New DirectoryEntry("LDAP://" & RDSFactor.LDAPDomain, UserDomain, sPassword)
Dim obj As Object = dirEntry.NativeObject
Dim search As New DirectorySearcher(dirEntry)
@ -118,17 +118,17 @@ Public Class CitrixHandler
'Load the Properties we need from AD
search.PropertiesToLoad.Add("distinguishedName")
'search.PropertiesToLoad.Add("primaryTelexNumber")
If CICRadarR.EnableOTP = True Then
If CICRadarR.EnableEmail = True Then
search.PropertiesToLoad.Add(CICRadarR.ADMailField)
If RDSFactor.EnableOTP = True Then
If RDSFactor.EnableEmail = True Then
search.PropertiesToLoad.Add(RDSFactor.ADMailField)
End If
If CICRadarR.EnableSMS = True Then
search.PropertiesToLoad.Add(CICRadarR.ADField)
If RDSFactor.EnableSMS = True Then
search.PropertiesToLoad.Add(RDSFactor.ADField)
End If
End If
' Time to find out if user entered the correct username and pasword
CICRadarR.AccessLog("Trying to authenticate user agains Active Directory using te following parameters: " & "LDAPPAth: " & "LDAP://" & CICRadarR.LDAPDomain & ", Username: " & UserDomain & ", Password: " & sPassword)
RDSFactor.AccessLog("Trying to authenticate user agains Active Directory using te following parameters: " & "LDAPPAth: " & "LDAP://" & RDSFactor.LDAPDomain & ", Username: " & UserDomain & ", Password: " & sPassword)
Dim result As SearchResult = search.FindOne()
'Get the setting form AD. Yes we uses the field primaryTelexNumber, for who the f... still users telex. (I bet half the people reading this code don't even know what a telex is!)
@ -137,43 +137,43 @@ Public Class CitrixHandler
'Dim userLdap As String = "LDAP://" & LDAPPath & "/" & result.Properties("distinguishedName")(0)
'Dim userEntry As New DirectoryEntry(userLdap, UserDomain, sPassword)
If CICRadarR.EnableOTP = True Then
smsCode = CICRadarR.GenerateCode()
If RDSFactor.EnableOTP = True Then
smsCode = RDSFactor.GenerateCode()
' REMEMBER to put at check for empty phone string
If CICRadarR.EnableEmail = True Then
If RDSFactor.EnableEmail = True Then
Try
UserEmail = DirectCast(result.Properties(CICRadarR.ADMailField)(0), String)
UserEmail = DirectCast(result.Properties(RDSFactor.ADMailField)(0), String)
If UserEmail.Trim.Length = 0 Or InStr(UserEmail, "@") = 0 Then
success = False
CICRadarR.AccessLog("Unable to find correct email for user " & UserDomain)
RDSFactor.AccessLog("Unable to find correct email for user " & UserDomain)
Else
success = True
End If
Catch
CICRadarR.AccessLog("Unable to find correct email for user " & UserDomain)
RDSFactor.AccessLog("Unable to find correct email for user " & UserDomain)
success = False
End Try
End If
If CICRadarR.EnableSMS = True Then
If RDSFactor.EnableSMS = True Then
Try
mobile = DirectCast(result.Properties(CICRadarR.ADField)(0), String)
mobile = DirectCast(result.Properties(RDSFactor.ADField)(0), String)
mobile = Replace(mobile, "+", "")
If mobile.Trim.Length = 0 Then
success = False
CICRadarR.AccessLog("Unable to find correct phone number for user " & UserDomain)
RDSFactor.AccessLog("Unable to find correct phone number for user " & UserDomain)
Else
success = True
End If
Catch
CICRadarR.AccessLog("Unable to find correct phone number for user " & UserDomain)
RDSFactor.AccessLog("Unable to find correct phone number for user " & UserDomain)
success = False
End Try
End If
sid = EncDec.Encrypt(UserDomain & "_" & smsCode, CICRadarR.encCode) 'generate unique code
sid = EncDec.Encrypt(UserDomain & "_" & smsCode, RDSFactor.encCode) 'generate unique code
End If
' sid = UserDomain & "_" & smsCode
'userEntry.Properties("primaryTelexNumber").Value = aCode(0) & "/" & smsCode & "/" & aCode(2) & "/" & aCode(3)
@ -199,7 +199,7 @@ Public Class CitrixHandler
success = False
End If
Catch
CICRadarR.AccessLog("Failed to authenticate user agains Active Directory using the following parameters: " & "LDAPPAth: " & "LDAP://" & CICRadarR.LDAPDomain & ", Username: " & UserDomain & ", Password: " & sPassword)
RDSFactor.AccessLog("Failed to authenticate user agains Active Directory using the following parameters: " & "LDAPPAth: " & "LDAP://" & RDSFactor.LDAPDomain & ", Username: " & UserDomain & ", Password: " & sPassword)
success = False
End Try
@ -207,8 +207,8 @@ Public Class CitrixHandler
Dim attributes As New RADIUSAttributes
If success Then ' Yay! Someone guess the password ...
CICRadarR.AccessLog("User " & UserDomain & " authenticated agains Active Directory")
If CICRadarR.EnableOTP = True Then
RDSFactor.AccessLog("User " & UserDomain & " authenticated agains Active Directory")
If RDSFactor.EnableOTP = True Then
Dim attr As New RADIUSAttribute(RadiusAttributeType.ReplyMessage, "SMS Token")
attributes.Add(attr)
Dim state As New RADIUSAttribute(RadiusAttributeType.State, sid)
@ -219,22 +219,22 @@ Public Class CitrixHandler
packet.Identifier, attributes, _
packet.EndPoint), _
packet.Authenticator)
If CICRadarR.EnableSMS = True Then
CICRadarR.AccessLog("Sending access token: " & smsCode & " to phonenumber " & mobile)
Call CICRadarR.SendSMS(mobile, smsCode)
If RDSFactor.EnableSMS = True Then
RDSFactor.AccessLog("Sending access token: " & smsCode & " to phonenumber " & mobile)
Call RDSFactor.SendSMS(mobile, smsCode)
End If
If CICRadarR.EnableEmail = True Then
CICRadarR.AccessLog("Sending access token: " & smsCode & " to email " & UserEmail)
Call CICRadarR.SendEmail(UserEmail, smsCode)
If RDSFactor.EnableEmail = True Then
RDSFactor.AccessLog("Sending access token: " & smsCode & " to email " & UserEmail)
Call RDSFactor.SendEmail(UserEmail, smsCode)
End If
Else
CICRadarR.AccessLog("One time Password not enabled, so we let the user in")
RDSFactor.AccessLog("One time Password not enabled, so we let the user in")
packet.AcceptAccessRequest()
End If
' packetHash.Remove(username.GetString & "_" & pass.GetString)
Else ' Wrong username / password ...
CICRadarR.AccessLog("User " & UserDomain & " failed to authenticate against Active Directory")
RDSFactor.AccessLog("User " & UserDomain & " failed to authenticate against Active Directory")
Dim pk As New RADIUSPacket(RadiusPacketCode.AccessReject, packet.Identifier, Nothing, packet.EndPoint)
server.SendAsResponse(pk, packet.Authenticator)
' FYI ... if no additional attributes need to be added

View file

@ -75,7 +75,7 @@ Public Class RDSHandler
' NOTE: Requests contain the session GUID in the password attribute
' of the packet.
Public Sub ProcessAppLaunchRequest()
CICRadarR.AccessLog("ProcessAppLaunchRequest")
RDSFactor.AccessLog("ProcessAppLaunchRequest")
' When the packet is an AppLaunchRequest the password attribute contains the session id!
Dim packetSessionId = mPassword
@ -83,15 +83,15 @@ Public Class RDSHandler
Dim sessionTimestamp = sessionTimestamps(mUsername)
If storedSessionId = Nothing Or sessionTimestamp = Nothing Then
CICRadarR.AccessLog("User has no session. MUST re-authenticate!")
RDSFactor.AccessLog("User has no session. MUST re-authenticate!")
mPacket.RejectAccessRequest()
Exit Sub
End If
If packetSessionId = storedSessionId Then
Dim minsSinceLastActivity = DateDiff(DateInterval.Minute, sessionTimestamp, Now)
If minsSinceLastActivity < CICRadarR.SessionTimeOut Then
CICRadarR.AccessLog("Opening window for: " & mUsername)
If minsSinceLastActivity < RDSFactor.SessionTimeOut Then
RDSFactor.AccessLog("Opening window for: " & mUsername)
' Pro-long session
sessionTimestamps(storedSessionId) = Now
' Open launch window
@ -99,12 +99,12 @@ Public Class RDSHandler
mPacket.AcceptAccessRequest()
Exit Sub
Else
CICRadarR.AccessLog("Session timed out -- User MUST re-authenticate")
RDSFactor.AccessLog("Session timed out -- User MUST re-authenticate")
userSessions.Remove(mUsername)
sessionTimestamps.Remove(mUsername)
End If
Else
CICRadarR.AccessLog("Stored session id didn't match packet session id!")
RDSFactor.AccessLog("Stored session id didn't match packet session id!")
End If
mPacket.RejectAccessRequest()
@ -122,14 +122,14 @@ Public Class RDSHandler
' TODO: Fix race-condition RD Web vs. Gateway. Don't start RDP client in RD Web
' before ensuring App Launch request was successful
Public Sub ProcessGatewayRequest()
CICRadarR.AccessLog("Gateway Request for user: " & mUsername)
RDSFactor.AccessLog("Gateway Request for user: " & mUsername)
Dim sessionId = userSessions(mUsername)
Dim launchTimestamp = userLaunchTimestamps(mUsername)
Dim attributes As New RADIUSAttributes
If sessionId = Nothing Or launchTimestamp = Nothing Then
CICRadarR.AccessLog("User's has no launch window. User must re-authenticate")
RDSFactor.AccessLog("User's has no launch window. User must re-authenticate")
mPacket.RejectAccessRequest()
Exit Sub
End If
@ -141,11 +141,11 @@ Public Class RDSHandler
End If
Dim secondsSinceLaunch = DateDiff(DateInterval.Second, launchTimestamp, Now)
If secondsSinceLaunch < CICRadarR.LaunchTimeOut Then
CICRadarR.AccessLog("Allowing access through gateway for user: " & mUsername & " -- closing window")
If secondsSinceLaunch < RDSFactor.LaunchTimeOut Then
RDSFactor.AccessLog("Allowing access through gateway for user: " & mUsername & " -- closing window")
mPacket.AcceptAccessRequest(attributes)
Else
CICRadarR.AccessLog("Launch window has closed!")
RDSFactor.AccessLog("Launch window has closed!")
End If
' close window
@ -160,24 +160,24 @@ Public Class RDSHandler
Exit Sub
End If
CICRadarR.AccessLog("ProcessAccessRequest")
RDSFactor.AccessLog("ProcessAccessRequest")
Try
Dim ldapResult = Authenticate()
If CICRadarR.EnableOTP Then
If RDSFactor.EnableOTP Then
TwoFactorChallenge()
Exit Sub
Else
Accept()
End If
Catch ex As Exception
CICRadarR.AccessLog("Authentication failed. Sending reject. Error: " & ex.Message)
RDSFactor.AccessLog("Authentication failed. Sending reject. Error: " & ex.Message)
mPacket.RejectAccessRequest()
End Try
End Sub
Private Sub Accept()
CICRadarR.AccessLog("Accept")
RDSFactor.AccessLog("Accept")
Dim sGUID As String = System.Guid.NewGuid.ToString()
userSessions(mUsername) = sGUID
sessionTimestamps(mUsername) = Now
@ -190,13 +190,13 @@ Public Class RDSHandler
End Sub
Private Sub ProcessChallengeResponse()
CICRadarR.AccessLog("ProcessChallengeResponse")
RDSFactor.AccessLog("ProcessChallengeResponse")
' When the packet is an Challange-Response the password attr. contains the token
Dim challangeCode = mPassword
Dim state = mPacket.Attributes.GetFirstAttribute(RadiusAttributeType.State)
Dim sid = EncDec.Encrypt(mUsername & "_" & challangeCode, CICRadarR.encCode)
Dim sid = EncDec.Encrypt(mUsername & "_" & challangeCode, RDSFactor.encCode)
If sid = state.ToString Then
Accept()
Else
@ -205,19 +205,19 @@ Public Class RDSHandler
End Sub
Private Sub TwoFactorChallenge()
Dim code = CICRadarR.GenerateCode
Dim sid = EncDec.Encrypt(mUsername & "_" & code, CICRadarR.encCode) 'generate unique code
CICRadarR.AccessLog("Access Challange Code: " & code)
Dim code = RDSFactor.GenerateCode
Dim sid = EncDec.Encrypt(mUsername & "_" & code, RDSFactor.encCode) 'generate unique code
RDSFactor.AccessLog("Access Challange Code: " & code)
userSidTokens(mUsername) = sid
tokenTimestamps(mUsername) = Now
If mUseSMSFactor Then
CICRadarR.AccessLog("TODO: Send SMS")
RDSFactor.AccessLog("TODO: Send SMS")
End If
If mUseEmailFactor Then
CICRadarR.AccessLog("TODO: Send Email")
RDSFactor.AccessLog("TODO: Send Email")
End If
Dim attributes As New RADIUSAttributes
@ -233,9 +233,9 @@ Public Class RDSHandler
Private Function Authenticate() As System.DirectoryServices.SearchResult
Dim password As String = mPacket.UserPassword
Dim ldapDomain As String = CICRadarR.LDAPDomain
Dim ldapDomain As String = RDSFactor.LDAPDomain
CICRadarR.AccessLog("Authenticating: LDAPPAth: " & "LDAP://" & ldapDomain & ", Username: " & mUsername)
RDSFactor.AccessLog("Authenticating: LDAPPAth: " & "LDAP://" & ldapDomain & ", Username: " & mUsername)
Dim dirEntry As New DirectoryEntry("LDAP://" & ldapDomain, mUsername, password)
Dim obj As Object = dirEntry.NativeObject
@ -248,15 +248,15 @@ Public Class RDSHandler
End If
search.PropertiesToLoad.Add("distinguishedName")
If CICRadarR.EnableOTP = True Then
search.PropertiesToLoad.Add(CICRadarR.ADField)
search.PropertiesToLoad.Add(CICRadarR.ADMailField)
If RDSFactor.EnableOTP = True Then
search.PropertiesToLoad.Add(RDSFactor.ADField)
search.PropertiesToLoad.Add(RDSFactor.ADMailField)
End If
Dim result = search.FindOne()
If IsDBNull(result) Then
CICRadarR.AccessLog("Failed to authenticate with Active Directory")
RDSFactor.AccessLog("Failed to authenticate with Active Directory")
Throw New MissingUser
End If
@ -264,19 +264,19 @@ Public Class RDSHandler
End Function
Private Function LdapGetNumber(result As SearchResult) As String
Dim mobile = result.Properties(CICRadarR.ADField)(0)
Dim mobile = result.Properties(RDSFactor.ADField)(0)
mobile = Replace(mobile, "+", "")
If mobile.Trim.Length = 0 Then
CICRadarR.AccessLog("Unable to find correct phone number for user " & mUsername)
RDSFactor.AccessLog("Unable to find correct phone number for user " & mUsername)
End If
Return mobile
End Function
Private Function LdapGetEmail(result As SearchResult) As String
Dim email = result.Properties(CICRadarR.ADMailField)(0)
Dim email = result.Properties(RDSFactor.ADMailField)(0)
If InStr(email, "@") = 0 Then
CICRadarR.AccessLog("Unable to find correct email for user " & mUsername)
RDSFactor.AccessLog("Unable to find correct email for user " & mUsername)
End If
Return email
End Function