Skip to content

Commit

Permalink
Bugfix and Security Update
Browse files Browse the repository at this point in the history
Fixed test dialogue.

Added code comments.

Implemented random secret generation for configuration saving.
  • Loading branch information
FPaul committed Dec 26, 2023
1 parent 2a55818 commit 5ae9f22
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 41 deletions.
2 changes: 1 addition & 1 deletion yealink_dialer/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<configuration>
<startup>

<supportedRuntime version="v2.0.50727" sku="Client"/></startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup>
</configuration>
2 changes: 1 addition & 1 deletion yealink_dialer/Form1.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions yealink_dialer/Form1.resx
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,21 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="CloseTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="CloseTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="CallDelay.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="CallDelay.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>129, 17</value>
</metadata>
<metadata name="Closer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="Closer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>231, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAEAgIAAAAEAIAAoCAEAFgAAACgAAACAAAAAAAEAAAEAIAAAAAAAAAABABILAAASCwAAAAAAAAAA
Expand Down
129 changes: 100 additions & 29 deletions yealink_dialer/Form1.vb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Imports System.Security.Cryptography
Imports System.IO
Imports System.Text

Imports System.Management
Public Class Form1
Inherits System.Windows.Forms.Form

Dim CFGSecret As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath() & "\data\secret.cfg")

Dim DIAL As String
Dim PHONEIP As String
Dim SIPACCOUNT As String
Expand All @@ -13,43 +16,57 @@ Public Class Form1
Dim CRDTA As String

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

'Load application settings.
Dim ConfigContent As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath() & "\data\config.ini")
RichTextBox2.Text = ConfigContent
CTime = RichTextBox2.Lines(1).Replace("closedelay=", "") - 1
CallDelay.Interval = RichTextBox2.Lines(3).Replace("dialdelay=", "") & "000"

Dim PhoneContent As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath() & "\data\phone.cfg")

Dim rd As New RijndaelManaged
Dim rijndaelIvLength As Integer = 16
Dim md5 As New MD5CryptoServiceProvider
Dim key() As Byte = md5.ComputeHash(Encoding.UTF8.GetBytes("duSK(57&5fHPskg8%$/3jalskg90DGNA51"))
md5.Clear()
Dim encdata() As Byte = Convert.FromBase64String(PhoneContent)
Dim ms As New MemoryStream(encdata)
Dim iv(15) As Byte
ms.Read(iv, 0, rijndaelIvLength)
rd.IV = iv
rd.Key = key
Dim cs As New CryptoStream(ms, rd.CreateDecryptor, CryptoStreamMode.Read)
Dim data(ms.Length - rijndaelIvLength) As Byte
Dim i As Integer = cs.Read(data, 0, data.Length)
CRDTA = System.Text.Encoding.UTF8.GetString(data, 0, i)
cs.Close()
rd.Clear()

RichTextBox1.Text = CRDTA
'Load phone configuration file and decrypt it.
Try
Dim PhoneContent As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath() & "\data\phone.cfg")

Dim rd As New RijndaelManaged
Dim rijndaelIvLength As Integer = 16
Dim md5 As New MD5CryptoServiceProvider
Dim key() As Byte = md5.ComputeHash(Encoding.UTF8.GetBytes(CFGSecret))
md5.Clear()
Dim encdata() As Byte = Convert.FromBase64String(PhoneContent)
Dim ms As New MemoryStream(encdata)
Dim iv(15) As Byte
ms.Read(iv, 0, rijndaelIvLength)
rd.IV = iv
rd.Key = key
Dim cs As New CryptoStream(ms, rd.CreateDecryptor, CryptoStreamMode.Read)
Dim data(ms.Length - rijndaelIvLength) As Byte
Dim i As Integer = cs.Read(data, 0, data.Length)
CRDTA = System.Text.Encoding.UTF8.GetString(data, 0, i)
cs.Close()
rd.Clear()
RichTextBox1.Text = CRDTA

Catch ex As Exception

Finally
End Try

'Configure parameters
PHONEIP = RichTextBox1.Lines(0).Replace("PHONEIP=", "")
SIPACCOUNT = RichTextBox1.Lines(1).Replace("SIPACCOUNT=", "")
USERNAME = RichTextBox1.Lines(2).Replace("USERNAME=", "")
PASSWORD = RichTextBox1.Lines(3).Replace("PASSWORD=", "")



'Grab command line args and sanitize them.
Try
DIAL = My.Application.CommandLineArgs(0).Replace("tel:", "")
DIAL = DIAL.Replace("/", "")
DIAL = DIAL.Replace("-", "")
Label1.Text = "Calling: " & DIAL

'Start timers depending on config file.
If RichTextBox2.Lines(0).Replace("autoclose=", "") = "true" Then CloseTimer.Start()
If RichTextBox2.Lines(2).Replace("autodial=", "") = "true" Then CallDelay.Start()
Catch
Expand All @@ -64,11 +81,27 @@ Public Class Form1
End Sub

Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
'This button serves 2 functions, depending on the mode.

If Button1.Text = "Save" Then

'If application was not launched by a callto link, this saves the configuration with encryption.

'Generate new random crypto password and save it.

CFGSecret = RandomString(250, 256)
Using writer As New System.IO.StreamWriter(Application.StartupPath() & "\data\secret.cfg")
For Each line In "A"
writer.Write(CFGSecret)
Next
End Using


'Encrypt config with generated string.

Dim rd As New RijndaelManaged
Dim md5 As New MD5CryptoServiceProvider
Dim key() As Byte = md5.ComputeHash(Encoding.UTF8.GetBytes("duSK(57&5fHPskg8%$/3jalskg90DGNA51"))
Dim key() As Byte = md5.ComputeHash(Encoding.UTF8.GetBytes(CFGSecret))
md5.Clear()
rd.Key = key
rd.GenerateIV()
Expand All @@ -84,12 +117,17 @@ Public Class Form1
cs.Close()
rd.Clear()

'Save encrypted data.
Using writer As New System.IO.StreamWriter(Application.StartupPath() & "\data\phone.cfg")
For Each line In "A"
writer.Write(CRDTA)
Next
End Using

Else

'If launched with callto link, this button instead is the CALL button and initiates the call once pressed.

CloseTimer.Stop()
WebBrowser1.Navigate("http://" & USERNAME & ":" & PASSWORD & "@" & PHONEIP & "/servlet?key=number=" & DIAL & "&outgoing_uri=" & SIPACCOUNT & "")
Closer.Start()
Expand All @@ -98,6 +136,7 @@ Public Class Form1
End If
End Sub

'Autoclose after delay, if autoclose is enabled.
Private Sub CloseTimer_Tick(sender As Object, e As EventArgs) Handles CloseTimer.Tick
If CTime > 0 Then
CTime = CTime - 1
Expand All @@ -106,23 +145,55 @@ Public Class Form1
End If
End Sub

'Execute call after delay, if autocall is enabled.
Private Sub CallDelay_Tick(sender As Object, e As EventArgs) Handles CallDelay.Tick
WebBrowser1.Navigate("http://" & USERNAME & ":" & PASSWORD & "@" & PHONEIP & "/servlet?key=number=" & DIAL & "&outgoing_uri=" & SIPACCOUNT & "")
CallDelay.Stop()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
MsgBox("Initiate test call?" & vbNewLine & "(Calls 01234567890)", MsgBoxStyle.YesNo)
PHONEIP = RichTextBox1.Lines(0).Replace("PHONEIP=", "")
SIPACCOUNT = RichTextBox1.Lines(1).Replace("SIPACCOUNT=", "")
USERNAME = RichTextBox1.Lines(2).Replace("USERNAME=", "")
PASSWORD = RichTextBox1.Lines(3).Replace("PASSWORD=", "")

WebBrowser1.Navigate("http://" & USERNAME & ":" & PASSWORD & "@" & PHONEIP & "/servlet?key=number=" & DIAL & "&outgoing_uri=" & SIPACCOUNT & "")
'Test Call Button

Dim Buttons As MessageBoxButtons = MessageBoxButtons.YesNo
Dim Result As DialogResult
Result = MessageBox.Show("Initiate test call?" & vbNewLine & "(Calls 01234567890)", "Test call?", Buttons, MessageBoxIcon.Information)

If Result = DialogResult.Yes Then
PHONEIP = RichTextBox1.Lines(0).Replace("PHONEIP=", "")
SIPACCOUNT = RichTextBox1.Lines(1).Replace("SIPACCOUNT=", "")
USERNAME = RichTextBox1.Lines(2).Replace("USERNAME=", "")
PASSWORD = RichTextBox1.Lines(3).Replace("PASSWORD=", "")

WebBrowser1.Navigate("http://" & USERNAME & ":" & PASSWORD & "@" & PHONEIP & "/servlet?key=number=" & DIAL & "&outgoing_uri=" & SIPACCOUNT & "")

End If
End Sub

Private Sub Closer_Tick(sender As Object, e As EventArgs) Handles Closer.Tick
Close()
End Sub

'This function generated the random string to use for encrypting the config file.
Function RandomString(minCharacters As Integer, maxCharacters As Integer)
Dim s As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789=?!&+-#.$§"
Static r As New Random
Dim chactersInString As Integer = r.Next(minCharacters, maxCharacters)
Dim sb As New StringBuilder
For i As Integer = 1 To chactersInString
Dim idx As Integer = r.Next(0, s.Length)
sb.Append(s.Substring(idx, 1))
Next
Return sb.ToString()
End Function

'Generate uinque computer ID for encryption (currently unused)
Public Shared Function GetComputerID() As Long
Dim objMOS As New ManagementObjectSearcher("Select * From Win32_Processor")
Dim computerinfo As String = My.Computer.Name
For Each objMO As Management.ManagementObject In objMOS.Get
computerinfo &= objMO("ProcessorID")
Next
Return computerinfo.GetHashCode
End Function
End Class
2 changes: 1 addition & 1 deletion yealink_dialer/My Project/Resources.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion yealink_dialer/My Project/Settings.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions yealink_dialer/yealink_dialer.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
<AssemblyName>YDialer</AssemblyName>
<FileAlignment>512</FileAlignment>
<MyType>WindowsForms</MyType>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -25,6 +26,7 @@
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>YDialer.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -35,6 +37,7 @@
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>YDialer.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<OptionExplicit>On</OptionExplicit>
Expand All @@ -56,6 +59,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Management" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -88,6 +92,7 @@
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="My Project\Resources.Designer.vb">
<AutoGen>True</AutoGen>
Expand Down

0 comments on commit 5ae9f22

Please sign in to comment.