diff --git a/CICRadarR/CICRadarR.suo b/RDSFactor/CICRadarR.suo similarity index 100% rename from CICRadarR/CICRadarR.suo rename to RDSFactor/CICRadarR.suo diff --git a/CICRadarR/Conversion.vb b/RDSFactor/Conversion.vb similarity index 100% rename from CICRadarR/Conversion.vb rename to RDSFactor/Conversion.vb diff --git a/CICRadarR/Crypto.vb b/RDSFactor/Crypto.vb similarity index 100% rename from CICRadarR/Crypto.vb rename to RDSFactor/Crypto.vb diff --git a/CICRadarR/IniFileVb.vb b/RDSFactor/IniFileVb.vb similarity index 100% rename from CICRadarR/IniFileVb.vb rename to RDSFactor/IniFileVb.vb diff --git a/CICRadarR/Log.vb b/RDSFactor/Log.vb similarity index 100% rename from CICRadarR/Log.vb rename to RDSFactor/Log.vb diff --git a/CICRadarR/My Project/Application.Designer.vb b/RDSFactor/My Project/Application.Designer.vb similarity index 100% rename from CICRadarR/My Project/Application.Designer.vb rename to RDSFactor/My Project/Application.Designer.vb diff --git a/CICRadarR/My Project/Application.myapp b/RDSFactor/My Project/Application.myapp similarity index 100% rename from CICRadarR/My Project/Application.myapp rename to RDSFactor/My Project/Application.myapp diff --git a/CICRadarR/My Project/AssemblyInfo.vb b/RDSFactor/My Project/AssemblyInfo.vb similarity index 100% rename from CICRadarR/My Project/AssemblyInfo.vb rename to RDSFactor/My Project/AssemblyInfo.vb diff --git a/CICRadarR/My Project/Resources.Designer.vb b/RDSFactor/My Project/Resources.Designer.vb similarity index 100% rename from CICRadarR/My Project/Resources.Designer.vb rename to RDSFactor/My Project/Resources.Designer.vb diff --git a/CICRadarR/My Project/Resources.resx b/RDSFactor/My Project/Resources.resx similarity index 100% rename from CICRadarR/My Project/Resources.resx rename to RDSFactor/My Project/Resources.resx diff --git a/CICRadarR/My Project/Settings.Designer.vb b/RDSFactor/My Project/Settings.Designer.vb similarity index 100% rename from CICRadarR/My Project/Settings.Designer.vb rename to RDSFactor/My Project/Settings.Designer.vb diff --git a/CICRadarR/My Project/Settings.settings b/RDSFactor/My Project/Settings.settings similarity index 100% rename from CICRadarR/My Project/Settings.settings rename to RDSFactor/My Project/Settings.settings diff --git a/CICRadarR/My Project/app.manifest b/RDSFactor/My Project/app.manifest similarity index 100% rename from CICRadarR/My Project/app.manifest rename to RDSFactor/My Project/app.manifest diff --git a/CICRadarR/ProjectInstaller.Designer.vb b/RDSFactor/ProjectInstaller.Designer.vb similarity index 100% rename from CICRadarR/ProjectInstaller.Designer.vb rename to RDSFactor/ProjectInstaller.Designer.vb diff --git a/CICRadarR/ProjectInstaller.resx b/RDSFactor/ProjectInstaller.resx similarity index 100% rename from CICRadarR/ProjectInstaller.resx rename to RDSFactor/ProjectInstaller.resx diff --git a/CICRadarR/ProjectInstaller.vb b/RDSFactor/ProjectInstaller.vb similarity index 100% rename from CICRadarR/ProjectInstaller.vb rename to RDSFactor/ProjectInstaller.vb diff --git a/CICRadarR/CICRadarR.Designer.vb b/RDSFactor/RDSFactor.Designer.vb similarity index 94% rename from CICRadarR/CICRadarR.Designer.vb rename to RDSFactor/RDSFactor.Designer.vb index aab6d8f..d64313d 100644 --- a/CICRadarR/CICRadarR.Designer.vb +++ b/RDSFactor/RDSFactor.Designer.vb @@ -1,68 +1,68 @@ -Imports System.ServiceProcess - - _ -Partial Class CICRadarR - Inherits System.ServiceProcess.ServiceBase - - 'UserService overrides dispose to clean up the component list. - _ - Protected Overrides Sub Dispose(ByVal disposing As Boolean) - Try - If disposing AndAlso components IsNot Nothing Then - components.Dispose() - End If - Finally - MyBase.Dispose(disposing) - End Try - End Sub - - ' The main entry point for the process - _ - _ - Shared Sub Main(ByVal args() As String) - Dim ServicesToRun() As System.ServiceProcess.ServiceBase - - ' More than one NT Service may run within the same process. To add - ' another service to this process, change the following line to - ' create a second service object. For example, - ' - ' ServicesToRun = New System.ServiceProcess.ServiceBase () {New Service1, New MySecondUserService} - ' - Dim server = New CICRadarR() - - If Environment.UserInteractive Then - server.OnStart(args) - Console.WriteLine("Type any character to exit") - Console.Read() - server.OnStop() - Else - ServicesToRun = New System.ServiceProcess.ServiceBase() {server} - System.ServiceProcess.ServiceBase.Run(ServicesToRun) - End If - End Sub - - 'Required by the Component Designer - Private components As System.ComponentModel.IContainer - - ' NOTE: The following procedure is required by the Component Designer - ' It can be modified using the Component Designer. - ' Do not modify it using the code editor. - _ - Private Sub InitializeComponent() - Me.TimerCleanUpHash = New System.Timers.Timer() - CType(Me.TimerCleanUpHash, System.ComponentModel.ISupportInitialize).BeginInit() - ' - 'TimerCleanUpHash - ' - Me.TimerCleanUpHash.Enabled = True - Me.TimerCleanUpHash.Interval = 60000.0R - ' - 'CICRadarR - ' - Me.ServiceName = "Service1" - CType(Me.TimerCleanUpHash, System.ComponentModel.ISupportInitialize).EndInit() - - End Sub - Friend WithEvents TimerCleanUpHash As System.Timers.Timer - -End Class +Imports System.ServiceProcess + + _ +Partial Class RDSFactor + Inherits System.ServiceProcess.ServiceBase + + 'UserService overrides dispose to clean up the component list. + _ + Protected Overrides Sub Dispose(ByVal disposing As Boolean) + Try + If disposing AndAlso components IsNot Nothing Then + components.Dispose() + End If + Finally + MyBase.Dispose(disposing) + End Try + End Sub + + ' The main entry point for the process + _ + _ + Shared Sub Main(ByVal args() As String) + Dim ServicesToRun() As System.ServiceProcess.ServiceBase + + ' More than one NT Service may run within the same process. To add + ' another service to this process, change the following line to + ' create a second service object. For example, + ' + ' ServicesToRun = New System.ServiceProcess.ServiceBase () {New Service1, New MySecondUserService} + ' + Dim server = New RDSFactor() + + If Environment.UserInteractive Then + server.OnStart(args) + Console.WriteLine("Type any character to exit") + Console.Read() + server.OnStop() + Else + ServicesToRun = New System.ServiceProcess.ServiceBase() {server} + System.ServiceProcess.ServiceBase.Run(ServicesToRun) + End If + End Sub + + 'Required by the Component Designer + Private components As System.ComponentModel.IContainer + + ' NOTE: The following procedure is required by the Component Designer + ' It can be modified using the Component Designer. + ' Do not modify it using the code editor. + _ + Private Sub InitializeComponent() + Me.TimerCleanUpHash = New System.Timers.Timer() + CType(Me.TimerCleanUpHash, System.ComponentModel.ISupportInitialize).BeginInit() + ' + 'TimerCleanUpHash + ' + Me.TimerCleanUpHash.Enabled = True + Me.TimerCleanUpHash.Interval = 60000.0R + ' + 'CICRadarR + ' + Me.ServiceName = "Service1" + CType(Me.TimerCleanUpHash, System.ComponentModel.ISupportInitialize).EndInit() + + End Sub + Friend WithEvents TimerCleanUpHash As System.Timers.Timer + +End Class diff --git a/CICRadarR/CICRadarR.resx b/RDSFactor/RDSFactor.resx similarity index 97% rename from CICRadarR/CICRadarR.resx rename to RDSFactor/RDSFactor.resx index ed70530..734d56d 100644 --- a/CICRadarR/CICRadarR.resx +++ b/RDSFactor/RDSFactor.resx @@ -1,126 +1,126 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 17, 17 - - - False - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + False + \ No newline at end of file diff --git a/CICRadarR/CICRadarR.sln b/RDSFactor/RDSFactor.sln similarity index 95% rename from CICRadarR/CICRadarR.sln rename to RDSFactor/RDSFactor.sln index c5c3255..c7ee0fb 100644 --- a/CICRadarR/CICRadarR.sln +++ b/RDSFactor/RDSFactor.sln @@ -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 diff --git a/CICRadarR/CICRadarR.vb b/RDSFactor/RDSFactor.vb similarity index 97% rename from CICRadarR/CICRadarR.vb rename to RDSFactor/RDSFactor.vb index 704b211..e3d3884 100644 --- a/CICRadarR/CICRadarR.vb +++ b/RDSFactor/RDSFactor.vb @@ -1,377 +1,377 @@ -Imports System.DirectoryServices -Imports System.IO -Imports System.Reflection -Imports CICRadarR.SMS -Imports CICRadarR.LogFile -Imports System.Security.Cryptography -Imports System.Text -Imports System -Imports System.Net.Mail -Imports RADAR - -Public Class CICRadarR - - Public Shared LDAPDomain As String = "" - Public Shared ADField As String = "" - Public Shared ADMailField As String = "" - Public Shared EnableOTP As Boolean - - ' Shared key: used for challange encryption - ' TODO: Fix - Public Shared encCode As String = "gewsyy#sjs2!" - - Private Shared DEBUG As Boolean - - Private Shared UserAccessLog As New LogWriter - Private Shared Log As New LogWriter - - Private secrets As NASAuthList - Private radius1812 As RADIUSServer - Private radius1645 As RADIUSServer - Private userHash As New Hashtable - Private packetHash As New Hashtable - Private clientHash As New Hashtable - - Public Shared NetBiosDomain As String = "" - - Private Shared Provider As String = "" - - - Private Shared ModemType As String = "" - Private Shared ComPort As String = "" - Private Shared SmsC As String = "" - Private Shared MailServer As String = "" - Private Shared SenderEmail As String = "" - - Private TSGW As String = "" - Private TSGWSessionIdHash As New Hashtable - Private TSGWSessionIdTimeStampHash As New Hashtable - Private TSGWLaunchIdTimeStampHash As New Hashtable - Private TSGWFirstLoginHash As New Hashtable ' Ensure that only one sms is send even if radius need to re-authenticate. - Private TSGWFirstLoginTimeStampHash As New Hashtable ' Ensure that only one sms is send even if radius need to re-authenticate. - - Public Shared SessionTimeOut As Integer = 30 ' in minutes - Public Shared LaunchTimeOut As Integer = 30 ' in seconds - Public Shared EnableSMS As Boolean = False - Public Shared EnableEmail As Boolean = False - - Protected Overrides Sub OnStart(ByVal args() As String) - - Log.filePath = ApplicationPath() & "\log.txt" - UserAccessLog.filePath = ApplicationPath() & "\UserAccessLog.txt" - - Log.WriteLog("---------------------------------------------------------------------------------------------------") - ServerLog("Starting Service") - ServerLog("Loading Configuration...") - Call loadConfiguration() - ServerLog("Starting Radius listner ports...") - Call StartUpServer() - End Sub - - Public Sub OnstartTest() - Log.filePath = ApplicationPath() & "\log.txt" - UserAccessLog.filePath = ApplicationPath() & "\UserAccessLog.txt" - - ServerLog("---------------------------------------------------------------------------------------------------") - ServerLog("Starting Service") - ServerLog("Loading Configuration...") - Call loadConfiguration() - ServerLog("Starting Radius listner ports...") - Call StartUpServer() - End Sub - - Protected Overrides Sub OnStop() - ServerLog("Stopping Radius listner ports...") - - End Sub - - Public Sub OnStopTest() - ServerLog("Stopping Radius listner ports...") - End Sub - - Public Sub StartUpServer() - - ' First, let's load a list of RADIUS shared secrets - ' in a NASAuthList object (a glorified Dictionary, basically) - secrets = New NASAuthList - ' Populate from DB, I suppose ... - - For Each cl As DictionaryEntry In clientHash - ServerLog("Adding Shared Secret to Radius Server") - secrets.AddSharedSecret(cl.Key, cl.Value) - Next - ' Then, we just create a RADIUS server ... - Try - radius1812 = New RADIUSServer(1812, AddressOf ProcessPacket1812, secrets) - ServerLog("Starting Radius Server on Port 1812...OK") - Catch - ServerLog("Starting Radius Server on Port 1812...FAILED") - End Try - - Try - radius1645 = New RADIUSServer(1645, AddressOf ProcessPacket1645, secrets) - ServerLog("Starting Radius Server on Port 1645...OK") - Catch - ServerLog("Starting Radius Server on Port 1645...FAILED") - End Try - - End Sub - - - ' Every valid RADIUS request generated by the server(s) we created earlier - ' will fire up the callback procedure. Invalid requests are dropped, per RFC. - Private Sub ProcessPacket1812(ByVal packet As RADIUSPacket) - 'Console.WriteLine("packet " & Now) - ProcessPacket(radius1812, packet) - End Sub - - Private Sub ProcessPacket1645(ByVal packet As RADIUSPacket) - ProcessPacket(radius1645, packet) - End Sub - - Public Shared Sub AccessLog(ByVal message) - If DEBUG = True Then - UserAccessLog.WriteLog(Now & ": DEBUG: " & message) - - ' Also write to the console if not a service - If Environment.UserInteractive Then - Console.WriteLine(Now & ": DEBUG: " & message) - End If - End If - End Sub - - Public Shared Sub ServerLog(ByVal message) - Log.WriteLog(Now & ":" & message) - ' Also write to the console if not a service - If Environment.UserInteractive Then - Console.WriteLine(Now & message) - End If - End Sub - - Private Sub ProcessPacket(ByVal server As RADIUSServer, ByVal packet As RADIUSPacket) - If Not packet.IsValid Then - Console.WriteLine("Packet is not valid. Discarding.") - Exit Sub - End If - - Dim handler - If TSGW = "1" Then - handler = New RDSHandler(packet) - Else - handler = New CitrixHandler(packet) - End If - - handler.ProcessRequest() - End Sub - - Public Shared Function GenerateCode() As String - Dim dummy As Integer = 0 - - Dim ordRand As New System.Random() - Dim temp As New System.Collections.ArrayList() - While temp.Count < 6 - dummy = ordRand.[Next](1, 9) - If Not temp.Contains(dummy) Then - temp.Add(dummy) - End If - End While - Dim strVar As String = temp(0).ToString() + temp(1).ToString() + temp(2).ToString() + temp(3).ToString() + temp(4).ToString() + temp(5).ToString() - Return strVar - - End Function - - Public Sub loadConfiguration() - Dim ConfOk As Boolean = True - Dim RConfig As New IniFile - Try - RConfig.Load(ApplicationPath() & "\CICRadarR.ini") - DEBUG = RConfig.GetKeyValue("CICRadarR", "Debug") - NetBiosDomain = RConfig.GetKeyValue("CICRadarR", "NetBiosDomain") - If NetBiosDomain.Length = 0 Then - ServerLog("ERROR: NetBiosDomain can not be empty") - ConfOk = False - End If - LDAPDomain = RConfig.GetKeyValue("CICRadarR", "LDAPDomain") - If LDAPDomain.Length = 0 Then - ServerLog("ERROR: LDAPDomain can not be empty") - ConfOk = False - End If - - TSGW = RConfig.GetKeyValue("CICRadarR", "TSGW") - - EnableOTP = RConfig.GetKeyValue("CICRadarR", "EnableOTP") - - If EnableOTP = True Then - If RConfig.GetKeyValue("CICRadarR", "EnableEmail") = "1" Then - EnableEmail = True - SenderEmail = RConfig.GetKeyValue("CICRadarR", "SenderEmail") - MailServer = RConfig.GetKeyValue("CICRadarR", "MailServer") - ADMailField = RConfig.GetKeyValue("CICRadarR", "ADMailField") - End If - - ADField = RConfig.GetKeyValue("CICRadarR", "ADField") - If ADField.Length = 0 Then - ServerLog("ERROR: ADField can not be empty") - ConfOk = False - End If - - If RConfig.GetKeyValue("CICRadarR", "EnableSMS") = "1" Then - EnableSMS = True - ModemType = RConfig.GetKeyValue("CICRadarR", "USELOCALMODEM") - Select Case ModemType - Case "0" - Provider = RConfig.GetKeyValue("CICRadarR", "Provider") - If Provider.Length = 0 Then - ServerLog("ERROR: Provider can not be empty") - ConfOk = False - End If - Case "1" - ComPort = RConfig.GetKeyValue("CICRadarR", "COMPORT") - If ComPort.Length = 0 Then - ServerLog("ERROR: ComPort can not be empty") - ConfOk = False - End If - SmsC = RConfig.GetKeyValue("CICRadarR", "SMSC") - If SmsC.Length = 0 Then - ServerLog("ERROR: SMSC can not be empty. See http://smsclist.com/downloads/default.txt for valid values") - ConfOk = False - End If - Case Else - ServerLog("ERROR: USELOCALMODEM contain invalid configuration. Correct value are 1 or 0") - ConfOk = False - End Select - End If - - End If - - Dim ClientList As String = "" - ClientList = RConfig.GetKeyValue("CICRadarR", "ClientList") - - Dim ClientArray() As String - ClientArray = Split(ClientList, ",") - - For i As Integer = 0 To ClientArray.Length - 1 - ServerLog("Loading Shared Secret for Client: " & ClientArray(i)) - clientHash.Add(ClientArray(i), EncDec.Decrypt(RConfig.GetKeyValue("Clients", ClientArray(i)), encCode)) - Next - - If ConfOk = True Then - ServerLog("Loading Configuration...OK") - Else - ServerLog("Loading Configuration...FAILED") - End If - Catch - ServerLog("ERROR: Missing CICRadarR.ini from startup path or CICRadarR.ini contains invalid configuration") - ServerLog("Loading Configuration...FAILED") - End - End Try - End Sub - - Public Function ApplicationPath() As String - Return Path.GetDirectoryName([Assembly].GetExecutingAssembly().Location) - End Function - - Public Shared Function SendSMS(ByVal number As String, ByVal passcode As String) As String - - ' test if using online sms provider or local modem - If ModemType = 1 Then ' local modem - Dim modem As New SmsClass(ComPort) - modem.Opens() - modem.sendSms(number, passcode, SmsC) - modem.Closes() - modem = Nothing - Return "Ok" - Else - - - Dim baseurl As String = Provider.Split("?")(0) - Dim client As New System.Net.WebClient() - ' Add a user agent header in case the requested URI contains a query. - - client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR1.0.3705;)") - - Dim parameters As String = Provider.Split("?")(1) - Dim pary As String() = parameters.Split("&") - - For i As Integer = 0 To pary.Length - 1 - If pary(i).IndexOf("***TEXTMESSAGE***") > 0 Then - Dim qpar As String() = pary(i).Split("=") - client.QueryString.Add(qpar(0), passcode) - ElseIf pary(i).IndexOf("***NUMBER***") > 0 Then - Dim qpar As String() = pary(i).Split("=") - client.QueryString.Add(qpar(0), number) - Else - - Dim qpar As String() = pary(i).Split("=") - client.QueryString.Add(qpar(0), qpar(1)) - End If - Next - - - Dim data As Stream = client.OpenRead(baseurl) - Dim reader As New StreamReader(data) - Dim s As String = reader.ReadToEnd() - data.Close() - reader.Close() - Return (s) - End If - - End Function - - Public Shared Function SendEmail(email As String, passcode As String) As String - - - Dim mail As New MailMessage() - mail.To.Add(email) - mail.From = New MailAddress(SenderEmail) - mail.Subject = "Token: " & passcode - mail.Body = "Subject contains the token code to login to you site" - mail.IsBodyHtml = False - Dim smtp As New SmtpClient(MailServer) - - - Try - smtp.Send(mail) - If DEBUG = True Then - AccessLog(Now & ": Mail send to: " & email) - End If - Return "SEND" - Catch e As InvalidCastException - - If DEBUG = True Then - AccessLog(Now & " : Debug: " & e.Message) - AccessLog(Now & " : Unable to send mail to: " & email & " ## Check that MAILSERVER and SENDEREMAIL are configured correctly in smscode.conf. Also check that your Webinterface server is allowed to relay through the mail server specified") - End If - Return "FAILED" - End Try - - - - End Function - - Private Sub TimerCleanUpHash_Elapsed(sender As System.Object, e As System.Timers.ElapsedEventArgs) Handles TimerCleanUpHash.Elapsed - ' Clean Session and Launch hash for TSGW - Try - Dim Item As DictionaryEntry - For Each Item In TSGWSessionIdTimeStampHash - Dim hTime As DateTime = DirectCast(Item.Value, DateTime) - Dim tValid = DateDiff(DateInterval.Minute, hTime, Now) - If tValid >= SessionTimeOut Then - TSGWSessionIdTimeStampHash.Remove(Item.Key) - If TSGWSessionIdHash.Contains(Item.Key) Then - TSGWSessionIdHash.Remove(Item.Key) - End If - End If - Next - - For Each Item In TSGWLaunchIdTimeStampHash - Dim hTime As DateTime = DirectCast(Item.Value, DateTime) - Dim tValid = DateDiff(DateInterval.Second, hTime, Now) - If tValid >= LaunchTimeOut Then - TSGWLaunchIdTimeStampHash.Remove(Item.Key) - End If - Next - Catch - End Try - End Sub -End Class +Imports System.DirectoryServices +Imports System.IO +Imports System.Reflection +Imports CICRadarR.SMS +Imports CICRadarR.LogFile +Imports System.Security.Cryptography +Imports System.Text +Imports System +Imports System.Net.Mail +Imports RADAR + +Public Class RDSFactor + + Public Shared LDAPDomain As String = "" + Public Shared ADField As String = "" + Public Shared ADMailField As String = "" + Public Shared EnableOTP As Boolean + + ' Shared key: used for challange encryption + ' TODO: Fix + Public Shared encCode As String = "gewsyy#sjs2!" + + Private Shared DEBUG As Boolean + + Private Shared UserAccessLog As New LogWriter + Private Shared Log As New LogWriter + + Private secrets As NASAuthList + Private radius1812 As RADIUSServer + Private radius1645 As RADIUSServer + Private userHash As New Hashtable + Private packetHash As New Hashtable + Private clientHash As New Hashtable + + Public Shared NetBiosDomain As String = "" + + Private Shared Provider As String = "" + + + Private Shared ModemType As String = "" + Private Shared ComPort As String = "" + Private Shared SmsC As String = "" + Private Shared MailServer As String = "" + Private Shared SenderEmail As String = "" + + Private TSGW As String = "" + Private TSGWSessionIdHash As New Hashtable + Private TSGWSessionIdTimeStampHash As New Hashtable + Private TSGWLaunchIdTimeStampHash As New Hashtable + Private TSGWFirstLoginHash As New Hashtable ' Ensure that only one sms is send even if radius need to re-authenticate. + Private TSGWFirstLoginTimeStampHash As New Hashtable ' Ensure that only one sms is send even if radius need to re-authenticate. + + Public Shared SessionTimeOut As Integer = 30 ' in minutes + Public Shared LaunchTimeOut As Integer = 30 ' in seconds + Public Shared EnableSMS As Boolean = False + Public Shared EnableEmail As Boolean = False + + Protected Overrides Sub OnStart(ByVal args() As String) + + Log.filePath = ApplicationPath() & "\log.txt" + UserAccessLog.filePath = ApplicationPath() & "\UserAccessLog.txt" + + Log.WriteLog("---------------------------------------------------------------------------------------------------") + ServerLog("Starting Service") + ServerLog("Loading Configuration...") + Call loadConfiguration() + ServerLog("Starting Radius listner ports...") + Call StartUpServer() + End Sub + + Public Sub OnstartTest() + Log.filePath = ApplicationPath() & "\log.txt" + UserAccessLog.filePath = ApplicationPath() & "\UserAccessLog.txt" + + ServerLog("---------------------------------------------------------------------------------------------------") + ServerLog("Starting Service") + ServerLog("Loading Configuration...") + Call loadConfiguration() + ServerLog("Starting Radius listner ports...") + Call StartUpServer() + End Sub + + Protected Overrides Sub OnStop() + ServerLog("Stopping Radius listner ports...") + + End Sub + + Public Sub OnStopTest() + ServerLog("Stopping Radius listner ports...") + End Sub + + Public Sub StartUpServer() + + ' First, let's load a list of RADIUS shared secrets + ' in a NASAuthList object (a glorified Dictionary, basically) + secrets = New NASAuthList + ' Populate from DB, I suppose ... + + For Each cl As DictionaryEntry In clientHash + ServerLog("Adding Shared Secret to Radius Server") + secrets.AddSharedSecret(cl.Key, cl.Value) + Next + ' Then, we just create a RADIUS server ... + Try + radius1812 = New RADIUSServer(1812, AddressOf ProcessPacket1812, secrets) + ServerLog("Starting Radius Server on Port 1812...OK") + Catch + ServerLog("Starting Radius Server on Port 1812...FAILED") + End Try + + Try + radius1645 = New RADIUSServer(1645, AddressOf ProcessPacket1645, secrets) + ServerLog("Starting Radius Server on Port 1645...OK") + Catch + ServerLog("Starting Radius Server on Port 1645...FAILED") + End Try + + End Sub + + + ' Every valid RADIUS request generated by the server(s) we created earlier + ' will fire up the callback procedure. Invalid requests are dropped, per RFC. + Private Sub ProcessPacket1812(ByVal packet As RADIUSPacket) + 'Console.WriteLine("packet " & Now) + ProcessPacket(radius1812, packet) + End Sub + + Private Sub ProcessPacket1645(ByVal packet As RADIUSPacket) + ProcessPacket(radius1645, packet) + End Sub + + Public Shared Sub AccessLog(ByVal message) + If DEBUG = True Then + UserAccessLog.WriteLog(Now & ": DEBUG: " & message) + + ' Also write to the console if not a service + If Environment.UserInteractive Then + Console.WriteLine(Now & ": DEBUG: " & message) + End If + End If + End Sub + + Public Shared Sub ServerLog(ByVal message) + Log.WriteLog(Now & ":" & message) + ' Also write to the console if not a service + If Environment.UserInteractive Then + Console.WriteLine(Now & message) + End If + End Sub + + Private Sub ProcessPacket(ByVal server As RADIUSServer, ByVal packet As RADIUSPacket) + If Not packet.IsValid Then + Console.WriteLine("Packet is not valid. Discarding.") + Exit Sub + End If + + Dim handler + If TSGW = "1" Then + handler = New RDSHandler(packet) + Else + handler = New CitrixHandler(packet) + End If + + handler.ProcessRequest() + End Sub + + Public Shared Function GenerateCode() As String + Dim dummy As Integer = 0 + + Dim ordRand As New System.Random() + Dim temp As New System.Collections.ArrayList() + While temp.Count < 6 + dummy = ordRand.[Next](1, 9) + If Not temp.Contains(dummy) Then + temp.Add(dummy) + End If + End While + Dim strVar As String = temp(0).ToString() + temp(1).ToString() + temp(2).ToString() + temp(3).ToString() + temp(4).ToString() + temp(5).ToString() + Return strVar + + End Function + + Public Sub loadConfiguration() + Dim ConfOk As Boolean = True + Dim RConfig As New IniFile + Try + RConfig.Load(ApplicationPath() & "\CICRadarR.ini") + DEBUG = RConfig.GetKeyValue("CICRadarR", "Debug") + NetBiosDomain = RConfig.GetKeyValue("CICRadarR", "NetBiosDomain") + If NetBiosDomain.Length = 0 Then + ServerLog("ERROR: NetBiosDomain can not be empty") + ConfOk = False + End If + LDAPDomain = RConfig.GetKeyValue("CICRadarR", "LDAPDomain") + If LDAPDomain.Length = 0 Then + ServerLog("ERROR: LDAPDomain can not be empty") + ConfOk = False + End If + + TSGW = RConfig.GetKeyValue("CICRadarR", "TSGW") + + EnableOTP = RConfig.GetKeyValue("CICRadarR", "EnableOTP") + + If EnableOTP = True Then + If RConfig.GetKeyValue("CICRadarR", "EnableEmail") = "1" Then + EnableEmail = True + SenderEmail = RConfig.GetKeyValue("CICRadarR", "SenderEmail") + MailServer = RConfig.GetKeyValue("CICRadarR", "MailServer") + ADMailField = RConfig.GetKeyValue("CICRadarR", "ADMailField") + End If + + ADField = RConfig.GetKeyValue("CICRadarR", "ADField") + If ADField.Length = 0 Then + ServerLog("ERROR: ADField can not be empty") + ConfOk = False + End If + + If RConfig.GetKeyValue("CICRadarR", "EnableSMS") = "1" Then + EnableSMS = True + ModemType = RConfig.GetKeyValue("CICRadarR", "USELOCALMODEM") + Select Case ModemType + Case "0" + Provider = RConfig.GetKeyValue("CICRadarR", "Provider") + If Provider.Length = 0 Then + ServerLog("ERROR: Provider can not be empty") + ConfOk = False + End If + Case "1" + ComPort = RConfig.GetKeyValue("CICRadarR", "COMPORT") + If ComPort.Length = 0 Then + ServerLog("ERROR: ComPort can not be empty") + ConfOk = False + End If + SmsC = RConfig.GetKeyValue("CICRadarR", "SMSC") + If SmsC.Length = 0 Then + ServerLog("ERROR: SMSC can not be empty. See http://smsclist.com/downloads/default.txt for valid values") + ConfOk = False + End If + Case Else + ServerLog("ERROR: USELOCALMODEM contain invalid configuration. Correct value are 1 or 0") + ConfOk = False + End Select + End If + + End If + + Dim ClientList As String = "" + ClientList = RConfig.GetKeyValue("CICRadarR", "ClientList") + + Dim ClientArray() As String + ClientArray = Split(ClientList, ",") + + For i As Integer = 0 To ClientArray.Length - 1 + ServerLog("Loading Shared Secret for Client: " & ClientArray(i)) + clientHash.Add(ClientArray(i), EncDec.Decrypt(RConfig.GetKeyValue("Clients", ClientArray(i)), encCode)) + Next + + If ConfOk = True Then + ServerLog("Loading Configuration...OK") + Else + ServerLog("Loading Configuration...FAILED") + End If + Catch + ServerLog("ERROR: Missing CICRadarR.ini from startup path or CICRadarR.ini contains invalid configuration") + ServerLog("Loading Configuration...FAILED") + End + End Try + End Sub + + Public Function ApplicationPath() As String + Return Path.GetDirectoryName([Assembly].GetExecutingAssembly().Location) + End Function + + Public Shared Function SendSMS(ByVal number As String, ByVal passcode As String) As String + + ' test if using online sms provider or local modem + If ModemType = 1 Then ' local modem + Dim modem As New SmsClass(ComPort) + modem.Opens() + modem.sendSms(number, passcode, SmsC) + modem.Closes() + modem = Nothing + Return "Ok" + Else + + + Dim baseurl As String = Provider.Split("?")(0) + Dim client As New System.Net.WebClient() + ' Add a user agent header in case the requested URI contains a query. + + client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR1.0.3705;)") + + Dim parameters As String = Provider.Split("?")(1) + Dim pary As String() = parameters.Split("&") + + For i As Integer = 0 To pary.Length - 1 + If pary(i).IndexOf("***TEXTMESSAGE***") > 0 Then + Dim qpar As String() = pary(i).Split("=") + client.QueryString.Add(qpar(0), passcode) + ElseIf pary(i).IndexOf("***NUMBER***") > 0 Then + Dim qpar As String() = pary(i).Split("=") + client.QueryString.Add(qpar(0), number) + Else + + Dim qpar As String() = pary(i).Split("=") + client.QueryString.Add(qpar(0), qpar(1)) + End If + Next + + + Dim data As Stream = client.OpenRead(baseurl) + Dim reader As New StreamReader(data) + Dim s As String = reader.ReadToEnd() + data.Close() + reader.Close() + Return (s) + End If + + End Function + + Public Shared Function SendEmail(email As String, passcode As String) As String + + + Dim mail As New MailMessage() + mail.To.Add(email) + mail.From = New MailAddress(SenderEmail) + mail.Subject = "Token: " & passcode + mail.Body = "Subject contains the token code to login to you site" + mail.IsBodyHtml = False + Dim smtp As New SmtpClient(MailServer) + + + Try + smtp.Send(mail) + If DEBUG = True Then + AccessLog(Now & ": Mail send to: " & email) + End If + Return "SEND" + Catch e As InvalidCastException + + If DEBUG = True Then + AccessLog(Now & " : Debug: " & e.Message) + AccessLog(Now & " : Unable to send mail to: " & email & " ## Check that MAILSERVER and SENDEREMAIL are configured correctly in smscode.conf. Also check that your Webinterface server is allowed to relay through the mail server specified") + End If + Return "FAILED" + End Try + + + + End Function + + Private Sub TimerCleanUpHash_Elapsed(sender As System.Object, e As System.Timers.ElapsedEventArgs) Handles TimerCleanUpHash.Elapsed + ' Clean Session and Launch hash for TSGW + Try + Dim Item As DictionaryEntry + For Each Item In TSGWSessionIdTimeStampHash + Dim hTime As DateTime = DirectCast(Item.Value, DateTime) + Dim tValid = DateDiff(DateInterval.Minute, hTime, Now) + If tValid >= SessionTimeOut Then + TSGWSessionIdTimeStampHash.Remove(Item.Key) + If TSGWSessionIdHash.Contains(Item.Key) Then + TSGWSessionIdHash.Remove(Item.Key) + End If + End If + Next + + For Each Item In TSGWLaunchIdTimeStampHash + Dim hTime As DateTime = DirectCast(Item.Value, DateTime) + Dim tValid = DateDiff(DateInterval.Second, hTime, Now) + If tValid >= LaunchTimeOut Then + TSGWLaunchIdTimeStampHash.Remove(Item.Key) + End If + Next + Catch + End Try + End Sub +End Class diff --git a/CICRadarR/CICRadarR.vbproj b/RDSFactor/RDSFactor.vbproj similarity index 94% rename from CICRadarR/CICRadarR.vbproj rename to RDSFactor/RDSFactor.vbproj index 397dd34..25ccc49 100644 --- a/CICRadarR/CICRadarR.vbproj +++ b/RDSFactor/RDSFactor.vbproj @@ -1,165 +1,165 @@ - - - - Debug - x86 - - - - - {04C6C533-9FEA-41B2-B554-A166C7C7FE32} - Exe - Sub Main - CICRadarR - CICRadarR - 512 - Console - v4.0 - Client - - - x86 - true - full - true - true - bin\Debug\ - CICRadarR.xml - 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 - - - x86 - pdbonly - false - true - true - bin\Release\ - CICRadarR.xml - 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 - - - On - - - Binary - - - Off - - - On - - - My Project\app.manifest - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - True - Application.myapp - - - Component - - - CICRadarR.vb - - - - True - True - Resources.resx - - - True - Settings.settings - True - - - ProjectInstaller.vb - - - Component - - - - TestService.vb - - - Form - - - - - CICRadarR.vb - - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources - Designer - - - ProjectInstaller.vb - - - TestService.vb - - - - - - MyApplicationCodeGenerator - Application.Designer.vb - - - SettingsSingleFileGenerator - My - Settings.Designer.vb - - - - - {3ab08a4e-c4fa-4571-a5d4-32bba807c31d} - RADAR - - - - + + + + Debug + x86 + + + + + {04C6C533-9FEA-41B2-B554-A166C7C7FE32} + Exe + Sub Main + CICRadarR + CICRadarR + 512 + Console + v4.0 + Client + + + x86 + true + full + true + true + bin\Debug\ + CICRadarR.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + x86 + pdbonly + false + true + true + bin\Release\ + CICRadarR.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + On + + + Binary + + + Off + + + On + + + My Project\app.manifest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + Application.myapp + + + Component + + + RDSFactor.vb + + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ProjectInstaller.vb + + + Component + + + + TestService.vb + + + Form + + + + + RDSFactor.vb + + + VbMyResourcesResXFileCodeGenerator + Resources.Designer.vb + My.Resources + Designer + + + ProjectInstaller.vb + + + TestService.vb + + + + + + MyApplicationCodeGenerator + Application.Designer.vb + + + SettingsSingleFileGenerator + My + Settings.Designer.vb + + + + + {3ab08a4e-c4fa-4571-a5d4-32bba807c31d} + RADAR + + + + \ No newline at end of file diff --git a/CICRadarR/CICRadarR.vbproj.user b/RDSFactor/RDSFactor.vbproj.user similarity index 98% rename from CICRadarR/CICRadarR.vbproj.user rename to RDSFactor/RDSFactor.vbproj.user index 695b5c7..ace9a86 100644 --- a/CICRadarR/CICRadarR.vbproj.user +++ b/RDSFactor/RDSFactor.vbproj.user @@ -1,3 +1,3 @@ - - + + \ No newline at end of file diff --git a/CICRadarR/SmsClass.vb b/RDSFactor/SmsClass.vb similarity index 100% rename from CICRadarR/SmsClass.vb rename to RDSFactor/SmsClass.vb diff --git a/CICRadarR/TestService.Designer.vb b/RDSFactor/TestService.Designer.vb similarity index 100% rename from CICRadarR/TestService.Designer.vb rename to RDSFactor/TestService.Designer.vb diff --git a/CICRadarR/TestService.resx b/RDSFactor/TestService.resx similarity index 100% rename from CICRadarR/TestService.resx rename to RDSFactor/TestService.resx diff --git a/CICRadarR/TestService.vb b/RDSFactor/TestService.vb similarity index 94% rename from CICRadarR/TestService.vb rename to RDSFactor/TestService.vb index cc00252..4f2f786 100644 --- a/CICRadarR/TestService.vb +++ b/RDSFactor/TestService.vb @@ -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() diff --git a/CICRadarR/VSA.vb b/RDSFactor/VSA.vb similarity index 100% rename from CICRadarR/VSA.vb rename to RDSFactor/VSA.vb diff --git a/CICRadarR/bin/Debug/CICRadarR.InstallLog b/RDSFactor/bin/Debug/CICRadarR.InstallLog similarity index 100% rename from CICRadarR/bin/Debug/CICRadarR.InstallLog rename to RDSFactor/bin/Debug/CICRadarR.InstallLog diff --git a/CICRadarR/bin/Debug/CICRadarR.ini b/RDSFactor/bin/Debug/CICRadarR.ini similarity index 100% rename from CICRadarR/bin/Debug/CICRadarR.ini rename to RDSFactor/bin/Debug/CICRadarR.ini diff --git a/CICRadarR/bin/Debug/InstallUtil.InstallLog b/RDSFactor/bin/Debug/InstallUtil.InstallLog similarity index 100% rename from CICRadarR/bin/Debug/InstallUtil.InstallLog rename to RDSFactor/bin/Debug/InstallUtil.InstallLog diff --git a/CICRadarR/bin/Release/CICRadarR.exe b/RDSFactor/bin/Release/CICRadarR.exe similarity index 100% rename from CICRadarR/bin/Release/CICRadarR.exe rename to RDSFactor/bin/Release/CICRadarR.exe diff --git a/CICRadarR/bin/Release/CICRadarR.pdb b/RDSFactor/bin/Release/CICRadarR.pdb similarity index 100% rename from CICRadarR/bin/Release/CICRadarR.pdb rename to RDSFactor/bin/Release/CICRadarR.pdb diff --git a/CICRadarR/bin/Release/CICRadarR.vshost.exe b/RDSFactor/bin/Release/CICRadarR.vshost.exe similarity index 100% rename from CICRadarR/bin/Release/CICRadarR.vshost.exe rename to RDSFactor/bin/Release/CICRadarR.vshost.exe diff --git a/CICRadarR/bin/Release/CICRadarR.vshost.exe.manifest b/RDSFactor/bin/Release/CICRadarR.vshost.exe.manifest similarity index 100% rename from CICRadarR/bin/Release/CICRadarR.vshost.exe.manifest rename to RDSFactor/bin/Release/CICRadarR.vshost.exe.manifest diff --git a/CICRadarR/bin/Release/CICRadarR.xml b/RDSFactor/bin/Release/CICRadarR.xml similarity index 100% rename from CICRadarR/bin/Release/CICRadarR.xml rename to RDSFactor/bin/Release/CICRadarR.xml diff --git a/CICRadarR/exceptions/MissingRadiusSecret.vb b/RDSFactor/exceptions/MissingRadiusSecret.vb similarity index 100% rename from CICRadarR/exceptions/MissingRadiusSecret.vb rename to RDSFactor/exceptions/MissingRadiusSecret.vb diff --git a/CICRadarR/exceptions/MissingUser.vb b/RDSFactor/exceptions/MissingUser.vb similarity index 100% rename from CICRadarR/exceptions/MissingUser.vb rename to RDSFactor/exceptions/MissingUser.vb diff --git a/CICRadarR/handlers/CitrixHandler.vb b/RDSFactor/handlers/CitrixHandler.vb similarity index 78% rename from CICRadarR/handlers/CitrixHandler.vb rename to RDSFactor/handlers/CitrixHandler.vb index ff34dc6..c0e8c4d 100644 --- a/CICRadarR/handlers/CitrixHandler.vb +++ b/RDSFactor/handlers/CitrixHandler.vb @@ -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 diff --git a/CICRadarR/handlers/RDSHandler.vb b/RDSFactor/handlers/RDSHandler.vb similarity index 81% rename from CICRadarR/handlers/RDSHandler.vb rename to RDSFactor/handlers/RDSHandler.vb index 625b48f..9e3c0de 100644 --- a/CICRadarR/handlers/RDSHandler.vb +++ b/RDSFactor/handlers/RDSHandler.vb @@ -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 diff --git a/CICRadarR/random.vb b/RDSFactor/random.vb similarity index 100% rename from CICRadarR/random.vb rename to RDSFactor/random.vb