Removed the bundled radar-radius. Added the original as submodule

This commit is contained in:
Jakob A. Dam 2015-04-10 09:14:21 +02:00 committed by Jakob Aarøe Dam
parent 3a2dff8fcd
commit 5dcb64b8b6
16 changed files with 52 additions and 1085 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "radar-radius"]
path = radar-radius
url = https://github.com/jakobadam/radar-radius

View file

@ -5,16 +5,38 @@ VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "CICRadarR", "CICRadarR.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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Debug|Any CPU.ActiveCfg = Debug|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Debug|Mixed Platforms.Build.0 = Debug|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Debug|x86.ActiveCfg = Debug|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Debug|x86.Build.0 = Debug|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Release|Any CPU.ActiveCfg = Release|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Release|Mixed Platforms.ActiveCfg = Release|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Release|Mixed Platforms.Build.0 = Release|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Release|x86.ActiveCfg = Release|x86
{04C6C533-9FEA-41B2-B554-A166C7C7FE32}.Release|x86.Build.0 = Release|x86
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Debug|x86.ActiveCfg = Debug|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Release|Any CPU.Build.0 = Release|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{3AB08A4E-C4FA-4571-A5D4-32BBA807C31D}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -7,7 +7,7 @@ Imports System.Security.Cryptography
Imports System.Text
Imports System
Imports System.Net.Mail
Imports RADAR
Public Class CICRadarR
@ -15,7 +15,9 @@ Public Class CICRadarR
Public Shared ADField As String = ""
Public Shared ADMailField As String = ""
Public Shared EnableOTP As Boolean
' TODO: What this?
' Shared key: used for challange encryption
' TODO: Fix
Public Shared encCode As String = "gewsyy#sjs2!"
Private Shared DEBUG As Boolean
@ -163,8 +165,6 @@ Public Class CICRadarR
End Sub
Public Shared Function GenerateCode() As String
Dim dummy As Integer = 0
Dim ordRand As New System.Random()

View file

@ -77,12 +77,10 @@
<Import Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="Conversion.vb" />
<Compile Include="exceptions\MissingRadiusSecret.vb" />
<Compile Include="exceptions\MissingUser.vb" />
<Compile Include="handlers\CitrixHandler.vb" />
<Compile Include="handlers\RDSHandler.vb" />
<Compile Include="VendorSpefic.vb" />
<Compile Include="Crypto.vb" />
<Compile Include="IniFileVb.vb" />
<Compile Include="Log.vb" />
@ -107,16 +105,12 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="NASAuthList.vb" />
<Compile Include="ProjectInstaller.Designer.vb">
<DependentUpon>ProjectInstaller.vb</DependentUpon>
</Compile>
<Compile Include="ProjectInstaller.vb">
<SubType>Component</SubType>
</Compile>
<Compile Include="RADIUSAttributes.vb" />
<Compile Include="RADIUSPacket.vb" />
<Compile Include="RADIUSServer.vb" />
<Compile Include="SmsClass.vb" />
<Compile Include="TestService.Designer.vb">
<DependentUpon>TestService.vb</DependentUpon>
@ -124,7 +118,6 @@
<Compile Include="TestService.vb">
<SubType>Form</SubType>
</Compile>
<Compile Include="UDPServer.vb" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="CICRadarR.resx">
@ -155,6 +148,12 @@
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\radar-radius\RADAR\RADAR.vbproj">
<Project>{3ab08a4e-c4fa-4571-a5d4-32bba807c31d}</Project>
<Name>RADAR</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View file

@ -1,17 +0,0 @@
Public Class NASAuthList
Inherits System.Collections.Generic.Dictionary(Of String, String)
Public Sub AddSharedSecret(ByVal nasIP As String, ByVal secret As String)
If MyBase.ContainsKey(nasIP) Then
MyBase.Item(nasIP) = secret
Else
MyBase.Add(nasIP, secret)
End If
End Sub
Public Function GetSharedSecret(ByVal nasIP As String) As String
Dim res As String = ""
MyBase.TryGetValue(nasIP, res)
Return res
End Function
End Class

View file

@ -1,312 +0,0 @@
Imports Microsoft.VisualBasic.Conversion
Imports CICRadarR.Conversion
Public Class RADIUSAttributes
Inherits List(Of RADIUSAttribute)
Friend Function LoadAttributes(ByRef data() As Byte) As Boolean
Dim offset As Integer = 20
Dim attr As RADIUSAttribute
Dim result As Boolean = True
Do While offset < data.Length And result
If offset + 1 > data.Length Then result = False
If result Then
If data(offset + 1) < 3 Then result = False
End If
If result Then
If offset + data(offset + 1) > data.Length Then result = False
End If
If result Then
attr = New RADIUSAttribute(data, offset)
Me.Add(attr)
offset += data(offset + 1)
End If
Loop
Return result
End Function
Public ReadOnly Property Length() As Integer
Get
Dim result As Integer = 0
For Each attr In Me
result += attr.Length
Next
Return result
End Get
End Property
Friend ReadOnly Property Bytes() As Byte()
Get
Dim result() As Byte = {}
Dim offset As Integer = 0
Array.Resize(result, Me.Length)
For Each attr In Me
Array.Copy(attr.Bytes, 0, result, offset, attr.Length)
offset += attr.Length
Next
Return result
End Get
End Property
' fixed function so it return correct value (CI)
Public Function AttributeExists(ByVal type As RadiusAttributeType) As Boolean
Dim attr As RADIUSAttribute
Dim result As Boolean = False
For Each attr In Me
result = (attr.Type = type)
If result = True Then
Return True
End If
Next
Return False
End Function
Public Function GetFirstAttribute(ByVal type As RadiusAttributeType) As RADIUSAttribute
Dim atr As RADIUSAttribute
For Each atr In Me
If atr.Type = type Then Return atr
Next
Return Nothing
End Function
Public Function GetAllAttributes(ByVal type As RadiusAttributeType) As RADIUSAttributes
Dim ret As New RADIUSAttributes
Dim atr As RADIUSAttribute
For Each atr In Me
If atr.Type = type Then ret.Add(atr)
Next
Return ret
End Function
'Public Function GetAllVSAs() As RADIUSAttributes
' Dim ret As New RADIUSAttributes
' Dim atr As RADIUSAttribute
' For Each atr In Me
' If atr.Type = RadiusAttributeType.VendorSpecific Then ret.Add(atr)
' Next
' Return ret
'End Function
'Public Function GetAllCiscoAVPairs() As RADIUSAttributes
' Dim ret As New RADIUSAttributes
' Dim atr As RADIUSAttribute
' For Each atr In Me
' If atr.GetCiscoAVPair IsNot Nothing Then ret.Add(atr)
' Next
' Return ret
'End Function
'Public Function GetFirstCiscoAVPair(ByVal type As CiscoAVPairType) As CiscoAVPair
' Dim atr As RADIUSAttribute
' Dim avpair As CiscoAVPair
' For Each atr In Me
' If atr.Type = RadiusAttributeType.VendorSpecific Then
' avpair = atr.GetCiscoAVPair
' If avpair IsNot Nothing Then
' If avpair.VendorType = type Then Return avpair
' End If
' End If
' Next
' Return Nothing
'End Function
'Public Function GetFirstCiscoAVPair(ByVal name As String) As CiscoAVPair
' Dim atr As RADIUSAttribute
' Dim avpair As CiscoAVPair
' For Each atr In Me
' If atr.Type = RadiusAttributeType.VendorSpecific Then
' avpair = atr.GetCiscoAVPair
' If avpair IsNot Nothing Then
' If avpair.VendorName = name Then Return avpair
' End If
' End If
' Next
' Return Nothing
'End Function
End Class
Public Class RADIUSAttribute
Private mType As Byte
Private mLength As Byte
Private mValue() As Byte = {0}
Friend Sub New(ByRef data() As Byte, ByVal offset As Integer)
mLength = data(offset + 1)
Array.Resize(mValue, mLength - 2)
Array.Copy(data, offset + 2, mValue, 0, mLength - 2)
mType = data(offset)
End Sub
Public Sub New(ByVal type As RadiusAttributeType, ByVal data() As Byte)
CommonNew(type, data)
End Sub
Public Sub New(ByVal type As RadiusAttributeType, ByVal data As String)
Dim newdata() As Byte = ConvertToBytes(data)
CommonNew(type, newdata)
End Sub
Public Sub New(ByVal type As RadiusAttributeType, ByVal data As Long)
Dim newdata() As Byte = {data \ 16777216, _
(data Mod 16777216) \ 65536, _
(data Mod 65536) \ 256, _
(data Mod 256)}
CommonNew(type, newdata)
End Sub
Private Sub CommonNew(ByVal type As Byte, ByRef data() As Byte)
If data.Length > 253 Then
mType = 0
mLength = 3
Else
mType = type
Array.Resize(mValue, data.Length)
Array.Copy(data, 0, mValue, 0, data.Length)
mLength = mValue.Length + 2
End If
End Sub
Public ReadOnly Property Length() As Byte
Get
Return mLength
End Get
End Property
Public ReadOnly Property Type() As RadiusAttributeType
Get
Return mType
End Get
End Property
Friend ReadOnly Property Bytes() As Byte()
Get
Dim result() As Byte = {}
Array.Resize(result, mLength)
Array.Copy(mValue, 0, result, 2, mLength - 2)
result(0) = mType
result(1) = mLength
Return result
End Get
End Property
Public ReadOnly Property Value() As Byte()
Get
Return mValue
End Get
End Property
Public Overrides Function ToString() As String
Return ConvertToString(mValue)
End Function
Public Function GetLong() As Long
If mLength <> 6 Then Return 0
Return mValue(0) * 16777216 + _
mValue(1) * 65536 + _
mValue(2) * 256 + _
mValue(3)
End Function
Public Function GetIPAddress() As String
If mLength <> 6 Then Return "0.0.0.0"
Return mValue(0) & "." & mValue(1) & "." & mValue(2) & "." & mValue(3)
End Function
Public Function GetHex() As String
Dim i As Integer
Dim result As String = ""
Dim k As String
For i = 0 To mLength - 3
k = Hex(mValue(i))
If k.Length = 1 Then k = "0" & k
result = result & k & " "
Next
Return result
End Function
Public Function GetTrimHex() As String
Return Replace(GetHex, " ", "")
End Function
Public Function GetVendorSpecific() As VendorSpecificAttribute
Return New VendorSpecificAttribute(mValue)
End Function
'Public Function GetCiscoAVPair() As CiscoAVPair
' Return New CiscoAVPair(mValue)
'End Function
'Public Function GetVendorSpecific() As CiscoAVPair
' Return New CiscoAVPair(mValue)
'End Function
'Public Function CiscoAVPairTypeLookahead() As CiscoAVPairType
' If mLength < 8 Then Return CiscoAVPairType.Invalid
' If mValue(3) <> 9 Then Return CiscoAVPairType.Invalid
' If mValue(2) <> 0 Then Return CiscoAVPairType.Invalid
' If mValue(1) <> 0 Then Return CiscoAVPairType.Invalid
' If mValue(0) <> 0 Then Return CiscoAVPairType.Invalid
' Return mValue(4)
'End Function
End Class
Public Enum RadiusAttributeType As Byte
Invalid = 0
UserName = 1
UserPassword = 2
CHAPPassword = 3
NASIPAddress = 4
NASPort = 5
ServiceType = 6
FramedProtocol = 7
FramedIPAddress = 8
FramedIPNetmask = 9
FramedRouting = 10
FilterId = 11
FramedMTU = 12
FramedCompression = 13
LoginIPHost = 14
LoginService = 15
LoginTCPPort = 16
ReplyMessage = 18
CallbackNumber = 19
CallbackId = 20
FramedRoute = 22
FramedIPXNetwork = 23
State = 24
[Class] = 25
VendorSpecific = 26
SessionTimeout = 27
IdleTimeout = 28
TerminationAction = 29
CalledStationId = 30
CallingStationId = 31
NASIdentifier = 32
ProxyState = 33
LoginLATService = 34
LoginLATNode = 35
LoginLATGroup = 36
FramedAppleTalkLink = 37
FramedAppleTalkNetwork = 38
FramedAppleTalkZone = 39
AcctStatusType = 40
AcctDelayTime = 41
AcctInputOctets = 42
AcctOutputOctets = 43
AcctSessionId = 44
AcctAuthentic = 45
AcctSessionTime = 46
AcctInputPackets = 47
AcctOutputPackets = 48
AcctTerminateCause = 49
AcctMultiSessionId = 50
AcctLinkCount = 51
CHAPChallenge = 60
NASPortType = 61
PortLimit = 62
LoginLATPort = 63
MessageAuthenticator = 80
End Enum

View file

@ -1,253 +0,0 @@
Imports System.Net
Imports System.Security.Cryptography
Imports CICRadarR.Conversion
Public Class RADIUSPacket
Private mCode As RadiusPacketCode
Private mIdentifier As Byte
Private mAuthenticator() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Private mAttributes As New RADIUSAttributes
Private mEndPoint As IPEndPoint
Private mIsValid As Boolean
Private mServer As RADIUSServer
Friend Sub New(ByRef data() As Byte, ByVal endPoint As IPEndPoint, ByRef server As RADIUSServer)
'Check validity ...
mIsValid = mAttributes.LoadAttributes(data)
If mIsValid Then
mCode = data(0)
mIdentifier = data(1)
Array.Copy(data, 4, mAuthenticator, 0, 16)
mEndPoint = endPoint
mServer = server
End If
End Sub
Public Sub New(ByVal code As RadiusPacketCode, ByVal identifier As Byte, ByVal attributes As RADIUSAttributes, ByVal endPoint As IPEndPoint)
mCode = code
mIdentifier = identifier
If attributes Is Nothing Then
mAttributes = New RADIUSAttributes
Else
mAttributes = attributes
End If
If endPoint Is Nothing Then
mIsValid = False
Else
mEndPoint = endPoint
mIsValid = True
End If
End Sub
Public ReadOnly Property IsValid() As Boolean
Get
Return mIsValid
End Get
End Property
Public ReadOnly Property Code() As RadiusPacketCode
Get
Return mCode
End Get
End Property
Public ReadOnly Property Identifier() As Byte
Get
Return mIdentifier
End Get
End Property
Public ReadOnly Property Attributes() As RADIUSAttributes
Get
Return mAttributes
End Get
End Property
Public ReadOnly Property Authenticator() As Byte()
Get
Return mAuthenticator
End Get
End Property
Public ReadOnly Property EndPoint() As IPEndPoint
Get
Return mEndPoint
End Get
End Property
''' <summary>
''' Returns the username supplied in an Access Request. Returns
''' Nothing if a User-Name attribute is missing or the packet is not an
''' Access Request.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property UserName() As String
Get
If mCode <> RadiusPacketCode.AccessRequest Then Return Nothing
If mAttributes.GetFirstAttribute(RadiusAttributeType.UserName) Is Nothing Then Return Nothing
Return mAttributes.GetFirstAttribute(RadiusAttributeType.UserName).ToString
End Get
End Property
''' <summary>
''' Returns the password supplied in an Access Request. Returns
''' Nothing is a User-Password attribute is missing or the packet is not
''' an Access Request.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property UserPassword() As String
Get
If mCode <> RadiusPacketCode.AccessRequest Then Return Nothing
If mAttributes.GetFirstAttribute(RadiusAttributeType.UserPassword) Is Nothing Then Return Nothing
Dim secret As String = mServer.NASList.GetSharedSecret(mEndPoint.Address.ToString)
If secret = "" Then Return Nothing
Dim userpass As Byte() = mAttributes.GetFirstAttribute(RadiusAttributeType.UserPassword).Value
If userpass.Length Mod 16 > 0 Then Return Nothing
Dim hasher As MD5 = MD5.Create
Dim decoded As Byte() = {}
Array.Resize(decoded, userpass.Length)
Dim temp As Byte() = {}
Array.Resize(temp, secret.Length + 16)
Dim segment As Byte() = {}
Array.Resize(segment, 16)
ConvertToBytes(secret).CopyTo(temp, 0)
Dim i As Integer
For i = 0 To userpass.Length \ 16 - 1
If i = 0 Then
mAuthenticator.CopyTo(temp, secret.Length)
Else
Array.Copy(userpass, (i - 1) * 16, temp, secret.Length, 16)
End If
Array.Copy(userpass, i * 16, segment, 0, 16)
Array.Copy(XorBytes(hasher.ComputeHash(temp), segment), 0, decoded, i * 16, 16)
Next
hasher = Nothing
Return ConvertToString(decoded).Trim(Chr(0))
End Get
End Property
Friend Function Bytes() As Byte()
Dim mLength = 20 + mAttributes.Length
Dim result() As Byte = {}
Array.Resize(result, mLength)
result(0) = mCode
result(1) = mIdentifier
result(2) = mLength \ 256
result(3) = mLength Mod 256
mAuthenticator.CopyTo(result, 4)
If mLength > 20 Then mAttributes.Bytes.CopyTo(result, 20)
Return result
End Function
''' <summary>
''' Deprecated. User the UserName and UserPassword properties instead.
''' </summary>
''' <param name="authList"></param>
''' <param name="nasList"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Function AuthenticateAccessRequest(ByRef authList As NASAuthList, ByRef nasList As NASAuthList) As Boolean
If authList Is Nothing Then Return False
If nasList Is Nothing Then Return False
If Not mIsValid Then Return False
If mCode <> RadiusPacketCode.AccessRequest Then Return True
Dim secret As String = nasList.GetSharedSecret(mEndPoint.Address.ToString)
If secret = "" Then Return False
Dim username As RADIUSAttribute = mAttributes.GetFirstAttribute(RadiusAttributeType.UserName)
If username Is Nothing Then Return False
Dim userpass As RADIUSAttribute = mAttributes.GetFirstAttribute(RadiusAttributeType.UserPassword)
If userpass Is Nothing Then Return False
Dim password As String = authList.GetSharedSecret(username.ToString)
If password = "" Then Return False
Dim passlen As Integer = password.Length \ 16
If password.Length Mod 16 > 0 Then
passlen += 1
password = password & StrDup(16 - (password.Length Mod 16), Chr(0))
End If
Dim hasher As MD5 = MD5.Create
Dim expect() As Byte = {}
Array.Resize(expect, passlen * 16)
Dim temp() As Byte = {}
Array.Resize(temp, secret.Length + 16)
ConvertToBytes(secret).CopyTo(temp, 0)
Dim i As Integer
For i = 0 To passlen - 1
If i = 0 Then
mAuthenticator.CopyTo(temp, secret.Length)
Else
Array.Copy(expect, (i - 1) * 16, temp, secret.Length, 16)
End If
Array.Copy(XorBytes(hasher.ComputeHash(temp), ConvertToBytes(password.Substring(i * 16, 16))), 0, expect, i * 16, 16)
Next
hasher = Nothing
Return (ConvertToString(expect) = userpass.ToString)
End Function
''' <summary>
''' Accept the access request.
''' </summary>
''' <remarks></remarks>
Public Sub AcceptAccessRequest()
AcceptAccessRequest(Nothing)
End Sub
''' <summary>
''' Accept the access request and include the specified attributes in the RADIUS response.
''' </summary>
''' <param name="attributes">The RADIUS attributes to include with the response.</param>
''' <remarks></remarks>
Public Sub AcceptAccessRequest(ByVal attributes As RADIUSAttributes)
If mCode <> RadiusPacketCode.AccessRequest Then Exit Sub
mServer.SendAsResponse(New RADIUSPacket(RadiusPacketCode.AccessAccept, mIdentifier, attributes, mEndPoint), mAuthenticator)
End Sub
''' <summary>
''' Reject the access request.
''' </summary>
''' <remarks></remarks>
Public Sub RejectAccessRequest()
If mCode <> RadiusPacketCode.AccessRequest Then Exit Sub
mServer.SendAsResponse(New RADIUSPacket(RadiusPacketCode.AccessReject, mIdentifier, Nothing, mEndPoint), mAuthenticator)
End Sub
Public Sub SendAccessChallenge(ByVal attributes As RADIUSAttributes)
mServer.SendAsResponse(New RADIUSPacket(RadiusPacketCode.AccessChallenge, mIdentifier, attributes, mEndPoint), mAuthenticator)
End Sub
Private Function XorBytes(ByVal oper1() As Byte, ByVal oper2() As Byte) As Byte()
Dim res() As Byte = {}
If oper1.Length <> oper2.Length Then Return res
Dim i As Integer
Array.Resize(res, oper1.Length)
For i = 0 To oper1.Length - 1
res(i) = oper1(i) Xor oper2(i)
Next
Return res
End Function
End Class
Public Enum RadiusPacketCode As Byte
AccessRequest = 1
AccessAccept = 2
AccessReject = 3
AccountingRequest = 4
AccountingResponse = 5
AccessChallenge = 11
StatusServer = 12
StatusClient = 13
Reserved = 255
End Enum

View file

@ -1,161 +0,0 @@
Imports System.Net
Imports CICRadarR.Conversion
Public Class RADIUSServer
Private mSocket As UDPServer
Private mSecrets As NASAuthList
Private mLastAuthenticator() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Public Delegate Sub RADIUSHandler(ByVal packet As RADIUSPacket)
Private HandlePacket As RADIUSHandler
Public Sub New(ByVal portNumber As Integer, ByVal onRADIUSPacket As RADIUSHandler, ByRef secrets As NASAuthList)
mSocket = New UDPServer(portNumber, AddressOf SocketData)
HandlePacket = onRADIUSPacket
mSecrets = secrets
End Sub
Public Sub New(ByVal ipAddress As String, ByVal portNumber As Integer, ByVal onRADIUSPacket As RADIUSHandler, ByRef secrets As NASAuthList)
mSocket = New UDPServer(ipAddress, portNumber, AddressOf SocketData)
HandlePacket = onRADIUSPacket
mSecrets = secrets
End Sub
Friend ReadOnly Property NASList() As NASAuthList
Get
Return mSecrets
End Get
End Property
Public Sub SendAsRequest(ByVal packet As RADIUSPacket)
If packet Is Nothing Then Exit Sub
If Not packet.IsValid Then Exit Sub
Dim data() As Byte = packet.Bytes
Dim hasher As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create
Dim hash() As Byte = {}
Dim secret As String = mSecrets.GetSharedSecret(packet.EndPoint.Address.ToString)
Array.Resize(hash, data.Length + secret.Length)
data.CopyTo(hash, 0)
ConvertToBytes(secret).CopyTo(hash, data.Length)
hash = hasher.ComputeHash(hash)
hash.CopyTo(data, 4)
hash.CopyTo(mLastAuthenticator, 0)
mSocket.Send(data, packet.EndPoint)
End Sub
Public Sub SendAsResponse(ByVal packet As RADIUSPacket, ByVal requestAuth() As Byte)
Try
If packet Is Nothing Then
Exit Sub
End If
If Not packet.IsValid Then
Exit Sub
End If
If requestAuth Is Nothing Then
Exit Sub
End If
If requestAuth.Length <> 16 Then
Exit Sub
End If
Dim data() As Byte = packet.Bytes
Dim hasher As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create
Dim hash() As Byte = {}
Dim secret As String = mSecrets.GetSharedSecret(packet.EndPoint.Address.ToString)
If secret = Nothing Then
Throw New MissingRadiusSecret(packet.EndPoint.Address.ToString)
End If
Array.Resize(hash, data.Length + secret.Length)
data.CopyTo(hash, 0)
ConvertToBytes(secret).CopyTo(hash, data.Length)
Array.Copy(requestAuth, 0, hash, 4, 16)
hash = hasher.ComputeHash(hash)
hash.CopyTo(data, 4)
mSocket.Send(data, packet.EndPoint)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Private Sub SocketData(ByRef data() As Byte, ByRef ep As IPEndPoint)
'Verify validity ...
If data.Length < 20 Then
Exit Sub
End If
Dim len As Integer = data(2) * 256 + data(3)
If data.Length <> len Then
Exit Sub
End If
Dim code As RadiusPacketCode = data(0)
Dim auth As Boolean
If code = RadiusPacketCode.AccessRequest Or code = RadiusPacketCode.AccountingRequest Then
auth = AuthenticateRequest(data, mSecrets.GetSharedSecret(ep.Address.ToString))
Else
auth = AuthenticateResponse(data, mSecrets.GetSharedSecret(ep.Address.ToString))
End If
If Not auth Then
Exit Sub
End If
Dim packet As New RADIUSPacket(data, ep, Me)
HandlePacket(packet)
End Sub
Private Function AuthenticateRequest(ByRef dataBytes() As Byte, ByVal secret As String) As Boolean
If dataBytes Is Nothing Then Return False
If dataBytes(0) = RadiusPacketCode.AccessRequest Then Return True
If secret Is Nothing Then Return False
Dim res As Boolean = True
Dim i As Integer
Dim hasher As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create
Dim expectedHash() As Byte = {}
Array.Resize(Of Byte)(expectedHash, dataBytes.Length + secret.Length)
dataBytes.CopyTo(expectedHash, 0)
ConvertToBytes(secret).CopyTo(expectedHash, dataBytes.Length)
For i = 4 To 19 : expectedHash(i) = 0 : Next ' Setting authenticator to zero...
expectedHash = hasher.ComputeHash(expectedHash)
' Compare ...
i = 4 : Do While res And i <= 19 : If dataBytes(i) <> expectedHash(i - 4) Then : res = False : End If : i += 1 : Loop
Return res
End Function
Private Function AuthenticateResponse(ByRef dataBytes() As Byte, ByVal secret As String) As Boolean
If secret Is Nothing Then Return False
If secret = "" Then Return False
Dim res As Boolean = True
Dim i As Integer
Dim hasher As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create
Dim expectedHash() As Byte = {}
Array.Resize(Of Byte)(expectedHash, dataBytes.Length + secret.Length)
dataBytes.CopyTo(expectedHash, 0)
ConvertToBytes(secret).CopyTo(expectedHash, dataBytes.Length)
For i = 4 To 19 : expectedHash(i) = mLastAuthenticator(i - 4) : Next ' Setting authenticator to zero...
expectedHash = hasher.ComputeHash(expectedHash)
' Compare ...
i = 4 : Do While res And i <= 19 : If dataBytes(i) <> expectedHash(i - 4) Then : res = False : End If : i += 1 : Loop
Return res
End Function
End Class

View file

@ -1,57 +0,0 @@
Imports System.Net
Imports System.Net.Sockets
Friend Class UDPServer
Private mSocket As UdpClient
Private mAsyncResult As IAsyncResult
Friend Delegate Sub UDPPacketHandler(ByRef data() As Byte, ByRef endPoint As IPEndPoint)
Private HandlePacket As UDPPacketHandler
Friend Sub New(ByVal portNumber As Integer, ByVal onDataArrived As UDPPacketHandler)
mSocket = New UdpClient(portNumber)
HandlePacket = onDataArrived
commonNew()
End Sub
Friend Sub New(ByVal ipAddress As String, ByVal portNumber As Integer, ByVal onDataArrived As UDPPacketHandler)
Dim ep As New IPEndPoint(System.Net.IPAddress.Parse(ipAddress), portNumber)
mSocket = New UdpClient(ep)
HandlePacket = onDataArrived
commonNew()
End Sub
Private Sub commonNew()
mAsyncResult = mSocket.BeginReceive(New AsyncCallback(AddressOf DataReceived), Nothing)
End Sub
Private Sub DataReceived(ByVal ar As IAsyncResult)
Dim ep As New IPEndPoint(0, 0)
Dim ef As Boolean = False
Dim data() As Byte = {}
Try
data = mSocket.EndReceive(mAsyncResult, ep)
Catch ex As System.Net.Sockets.SocketException
If ex.SocketErrorCode = 10054 Then ' Client killed connection
ef = False
Else
ef = True
End If
End Try
If Not ef Then
mAsyncResult = mSocket.BeginReceive(New AsyncCallback(AddressOf DataReceived), Nothing)
HandlePacket(data, ep)
End If
End Sub
Friend Sub Send(ByRef data() As Byte, ByRef endPoint As IPEndPoint)
mSocket.Send(data, data.Length, endPoint)
End Sub
End Class

View file

@ -1,142 +0,0 @@

Imports CICRadarR.Conversion
Public Class VendorSpecificAttribute
Private mVendorType As VendorSpecificType
Private mVendorName As String
Private mVendorValue As String
Public ReadOnly Property VendorType() As VendorSpecificType
Get
Return mVendorType
End Get
End Property
Public ReadOnly Property VendorName() As String
Get
Return mVendorName
End Get
End Property
Public ReadOnly Property VendorValue() As String
Get
Return mVendorValue
End Get
End Property
Public Function GetTimeStamp() As DateTime
Return ConvertToDateTime(mVendorValue)
End Function
Friend Sub New(ByRef value() As Byte)
mVendorType = VendorSpecificType.Invalid
mVendorName = ""
mVendorValue = ""
If value.Length < 6 Then
Exit Sub
End If
If value.Length <> value(5) + 4 Then
Exit Sub
End If
mVendorType = value(4)
If mVendorType = 47 Then
mVendorName = "generic"
mVendorValue = "TSGateway"
Else
mVendorName = "generic"
Dim v() As Byte = {}
Array.Resize(v, value.Length - 6)
Array.Copy(value, 6, v, 0, v.Length)
mVendorValue = ConvertToString(v)
End If
End Sub
Public Sub New(ByVal type As VendorSpecificType, ByVal value As String)
mVendorType = type
If type = VendorSpecificType.Invalid Then
mVendorName = ""
mVendorValue = ""
ElseIf type = VendorSpecificType.Generic Then
mVendorName = "generic"
mVendorValue = value
End If
End Sub
Public Sub New(ByVal name As String, ByVal value As String)
mVendorType = VendorSpecificType.Generic
mVendorName = name
mVendorValue = value
End Sub
Public Function ToBytes(data As String) As Byte()
Dim newdata() As Byte = ConvertToBytes(data)
Return newdata
End Function
Public Sub GetRADIUSAttribute(ByRef attributes As RADIUSAttributes)
If attributes Is Nothing Then Exit Sub
If mVendorType = VendorSpecificType.Invalid Then
Exit Sub
End If
Dim data() As Byte = {}
Dim len As Byte = 6
Dim lvt As Byte = mVendorType
' If lvt = CiscoAVPairType.IVR_In Or lvt = CiscoAVPairType.IVR_Out Then lvt = 1
If VendorName = "generic" Then
len += VendorValue.Length
Array.Resize(data, len)
ConvertToBytes(VendorValue).CopyTo(data, 6)
Else
len += VendorName.Length + 1 + VendorValue.Length
Array.Resize(data, len)
ConvertToBytes(VendorName & "=" & VendorValue).CopyTo(data, 6)
End If
data(4) = lvt
data(5) = len - 4
data(0) = 0
data(1) = 0
data(2) = 0
data(3) = 9
Dim attr As New RADIUSAttribute(RadiusAttributeType.VendorSpecific, data)
attributes.Add(attr)
End Sub
Public Sub SetRADIUSAttribute(ByRef attributes As RADIUSAttributes)
If mVendorType = VendorSpecificType.Invalid Then Exit Sub
Dim data() As Byte = {}
Dim len As Byte = 6
Dim lvt As Byte = mVendorType
len += VendorValue.Length
Array.Resize(data, len)
ConvertToBytes(VendorValue).CopyTo(data, 6)
data(4) = lvt
data(5) = len - 4
data(0) = 0
data(1) = 0
data(2) = 2 ' Generic value 666. Not sure if this confilct with other vendor, but RFC does not list existing vendor id's
data(3) = 154
Dim attr As New RADIUSAttribute(RadiusAttributeType.VendorSpecific, data)
attributes.Add(attr)
End Sub
End Class
Public Enum VendorSpecificType As Byte
Invalid = 0
Generic = 1
End Enum

View file

@ -1,23 +1,19 @@
[CICRadarR]
USELOCALMODEM=0
ClientList=192.168.121.162
SenderEmail=noreply2@isager.dk
SMSC=+4540390999
Debug=1
ADField=telephoneNumber
COMPORT=com1
NetBiosDomain=isager
ClientList=10.10.10.47,192.168.1.139,192.168.1.101,192.168.1.61,192.168.1.44
LDAPDomain=isager.lan
EnableOTP=0
Provider=https://www.cpsms.dk/sms/?username=myuser&password=mypassword&recipient=***NUMBER***&message=***TEXTMESSAGE***&from=CPSMS
EnableOTP=1
TSGW=1
EnableSMS=1
EnableEmail=1
Debug=1
MailServer=192.168.1.25
SenderEmail=noreply@isager.dk
NetBiosDomain=windows-2012-r2
TSGW=1
LDAPDomain=windows-2012-r2.example.com
EnableEmail=0
USELOCALMODEM=0
ADField=telephoneNumber
EnableSMS=1
COMPORT=com1
ADMailfield=mail
[Clients]
10.10.10.47=iirseiKUQCWnjfg1ZLhF+w==
192.168.1.101=eXA0YJxFrgfaDtOFApCifbPtJYrEL0RjpDzymPKlw6c=
192.168.1.61=p2fyLMddDfH8aLYwMyDbhQ1l3MY9hAJxx6DyiUOhjXw=
192.168.1.139=eXA0YJxFrgfaDtOFApCifbPtJYrEL0RjpDzymPKlw6c=
192.168.1.44=eXA0YJxFrgfaDtOFApCifbPtJYrEL0RjpDzymPKlw6c=
192.168.121.162=eXA0YJxFrgfaDtOFApCifbPtJYrEL0RjpDzymPKlw6c=

View file

@ -1,48 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel node will disable file and registry virtualization.
If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of all Windows versions that this application is designed to work with. Windows will automatically select the most compatible environment.-->
<!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
</application>
</compatibility>
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!-- <dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>-->
</asmv1:assembly>

View file

@ -1,66 +0,0 @@
<?xml version="1.0"?>
<doc>
<assembly>
<name>
CICRadarR
</name>
</assembly>
<members>
<member name="P:CICRadarR.My.Resources.Resources.ResourceManager">
<summary>
Returns the cached ResourceManager instance used by this class.
</summary>
</member><member name="P:CICRadarR.My.Resources.Resources.Culture">
<summary>
Overrides the current thread's CurrentUICulture property for all
resource lookups using this strongly typed resource class.
</summary>
</member><member name="T:CICRadarR.My.Resources.Resources">
<summary>
A strongly-typed resource class, for looking up localized strings, etc.
</summary>
</member><member name="P:CICRadarR.RADIUSPacket.UserName">
<summary>
Returns the username supplied in an Access Request. Returns
Nothing if a User-Name attribute is missing or the packet is not an
Access Request.
</summary>
<value></value>
<returns></returns>
<remarks></remarks>
</member><member name="P:CICRadarR.RADIUSPacket.UserPassword">
<summary>
Returns the password supplied in an Access Request. Returns
Nothing is a User-Password attribute is missing or the packet is not
an Access Request.
</summary>
<value></value>
<returns></returns>
<remarks></remarks>
</member><member name="M:CICRadarR.RADIUSPacket.AuthenticateAccessRequest(CICRadarR.NASAuthList@,CICRadarR.NASAuthList@)">
<summary>
Deprecated. User the UserName and UserPassword properties instead.
</summary>
<param name="authList"></param>
<param name="nasList"></param>
<returns></returns>
<remarks></remarks>
</member><member name="M:CICRadarR.RADIUSPacket.AcceptAccessRequest">
<summary>
Accept the access request.
</summary>
<remarks></remarks>
</member><member name="M:CICRadarR.RADIUSPacket.AcceptAccessRequest(CICRadarR.RADIUSAttributes)">
<summary>
Accept the access request and include the specified attributes in the RADIUS response.
</summary>
<param name="attributes">The RADIUS attributes to include with the response.</param>
<remarks></remarks>
</member><member name="M:CICRadarR.RADIUSPacket.RejectAccessRequest">
<summary>
Reject the access request.
</summary>
<remarks></remarks>
</member>
</members>
</doc>

View file

@ -1,4 +1,5 @@
Imports System.DirectoryServices
Imports RADAR
' TODO: I don't use this! It's a leftover, moved out of the way
' from the CICRadarR.vb

View file

@ -1,4 +1,5 @@
Imports System.DirectoryServices
Imports RADAR
Public Class RDSHandler
@ -227,7 +228,7 @@ Public Class RDSHandler
attributes.Add(attr)
attributes.Add(state)
mPacket.SendAccessChallenge(attributes)
mPacket.SendAccessChallange(attributes)
End Sub
Private Function Authenticate() As System.DirectoryServices.SearchResult

1
radar-radius Submodule

@ -0,0 +1 @@
Subproject commit 62c83c7d8c7c6245e9ab13d4c1435dbb5c1ccc11