Notify if shared RADIUS secret is missing

This commit is contained in:
Jakob A. Dam 2015-04-08 09:59:37 +02:00 committed by Jakob Aarøe Dam
parent dccef64f40
commit 4a1e1471f6
6 changed files with 22 additions and 6 deletions

View file

@ -78,7 +78,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Conversion.vb" />
<Compile Include="exceptions\MissingUserException.vb" />
<Compile Include="exceptions\MissingRadiusSecret.vb" />
<Compile Include="exceptions\MissingUser.vb" />
<Compile Include="handlers\RDSHandler.vb" />
<Compile Include="VendorSpefic.vb" />
<Compile Include="Crypto.vb" />

View file

@ -67,6 +67,11 @@ Public Class RADIUSServer
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)

View file

@ -0,0 +1,9 @@
Public Class MissingRadiusSecret
Inherits Exception
Public Sub New(ByVal ip As String)
MyBase.New("No shared secret for ip: " & ip & ". This MUST be inserted in the config file.")
End Sub
End Class

View file

@ -0,0 +1,3 @@
Public Class MissingUser
Inherits Exception
End Class

View file

@ -1,3 +0,0 @@
Public Class MissingUserException
Inherits Exception
End Class

View file

@ -122,6 +122,7 @@ Public Class RDSHandler
Accept()
End If
Catch ex As Exception
Console.WriteLine("Authentication failed. Sending reject.")
mPacket.RejectAccessRequest()
End Try
End Sub
@ -179,6 +180,7 @@ Public Class RDSHandler
Dim password As String = mPacket.UserPassword
Dim ldapDomain As String = CICRadarR.LDAPDomain
Console.WriteLine("Authenticating: LDAPPAth: " & "LDAP://" & ldapDomain & ", Username: " & packetUsername)
Dim dirEntry As New DirectoryEntry("LDAP://" & ldapDomain, packetUsername, password)
Dim obj As Object = dirEntry.NativeObject
@ -196,12 +198,11 @@ Public Class RDSHandler
search.PropertiesToLoad.Add(CICRadarR.ADMailField)
End If
Console.WriteLine("Authenticating: LDAPPAth: " & "LDAP://" & ldapDomain & ", Username: " & packetUsername)
Dim result = search.FindOne()
If IsDBNull(result) Then
Console.WriteLine("Failed to authenticate with Active Directory")
Throw New MissingUserException
Throw New MissingUser
End If
Return result