Skip to content

Commit

Permalink
Bugfixes and improvements
Browse files Browse the repository at this point in the history
- Improved encryption of authentication data by a detection method and automatic data conversion if necessary.
- Removed a forgotten debug line during the update testing process
- Removing a dependency in the creation of the MSI file
  • Loading branch information
gawindx committed Feb 8, 2021
1 parent c139251 commit 2a9fc77
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 39 deletions.
4 changes: 2 additions & 2 deletions WinNUT_V2/Setup/Setup.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,7 @@
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"Exclude" = "11:TRUE"
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
Expand Down Expand Up @@ -2597,7 +2597,7 @@
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"Exclude" = "11:TRUE"
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
Expand Down
18 changes: 9 additions & 9 deletions WinNUT_V2/WinNUT_GUI/CryptData.vb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ Public NotInheritable Class CryptData
Return hash
End Function

Public Function EncryptData(
ByVal plaintext As String) As String
Public Function EncryptData(ByVal plaintext As String) As String

' Convert the plaintext string to a byte array.
Dim plaintextBytes() As Byte =
Expand All @@ -45,8 +44,7 @@ Public NotInheritable Class CryptData
Return Convert.ToBase64String(ms.ToArray)
End Function

Public Function DecryptData(
ByVal encryptedtext As String) As String
Public Function DecryptData(ByVal encryptedtext As String) As String

' Convert the encrypted text string to a byte array.
Dim encryptedBytes() As Byte = Convert.FromBase64String(encryptedtext)
Expand All @@ -55,8 +53,7 @@ Public NotInheritable Class CryptData
Dim ms As New System.IO.MemoryStream
' Create the decoder to write to the stream.
Dim decStream As New CryptoStream(ms,
TripleDes.CreateDecryptor(),
System.Security.Cryptography.CryptoStreamMode.Write)
TripleDes.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write)

' Use the crypto stream to write the byte array to the stream.
decStream.Write(encryptedBytes, 0, encryptedBytes.Length)
Expand All @@ -65,14 +62,17 @@ Public NotInheritable Class CryptData
' Convert the plaintext stream to a string.
Return System.Text.Encoding.Unicode.GetString(ms.ToArray)
End Function
Public Function IsCryptedtData(
ByVal encryptedtext As String) As Boolean
Public Function IsCryptedtData(ByVal encryptedtext As String) As Boolean

Try
' Convert the encrypted text string to a byte array.
Dim encryptedBytes() As Byte = Convert.FromBase64String(encryptedtext)

Return True
If encryptedtext = EncryptData(DecryptData(encryptedtext)) Then
Return True
Else
Return True
End If
Catch
Return False
End Try
Expand Down
8 changes: 4 additions & 4 deletions WinNUT_V2/WinNUT_GUI/Pref_Gui.vb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
WinNUT_Params.Arr_Reg_Key.Item("Port") = CInt(Tb_Port.Text)
WinNUT_Params.Arr_Reg_Key.Item("UPSName") = Tb_UPS_Name.Text
WinNUT_Params.Arr_Reg_Key.Item("Delay") = CInt(Tb_Delay_Com.Text)
WinNUT_Params.Arr_Reg_Key.Item("enc_NutLogin") = Tb_Login_Nut.Text
WinNUT_Params.Arr_Reg_Key.Item("enc_NutPassword") = Tb_Pwd_Nut.Text
WinNUT_Params.Arr_Reg_Key.Item("NutLogin") = Tb_Login_Nut.Text
WinNUT_Params.Arr_Reg_Key.Item("NutPassword") = Tb_Pwd_Nut.Text
WinNUT_Params.Arr_Reg_Key.Item("AutoReconnect") = Cb_Reconnect.Checked
WinNUT_Params.Arr_Reg_Key.Item("MinInputVoltage") = CInt(Tb_InV_Min.Text)
WinNUT_Params.Arr_Reg_Key.Item("MaxInputVoltage") = CInt(Tb_InV_Max.Text)
Expand Down Expand Up @@ -95,8 +95,8 @@
Tb_Port.Text = CStr(WinNUT_Params.Arr_Reg_Key.Item("Port"))
Tb_UPS_Name.Text = CStr(WinNUT_Params.Arr_Reg_Key.Item("UPSName"))
Tb_Delay_Com.Text = CStr(WinNUT_Params.Arr_Reg_Key.Item("Delay"))
Tb_Login_Nut.Text = WinNUT_Params.Arr_Reg_Key.Item("enc_NutLogin")
Tb_Pwd_Nut.Text = WinNUT_Params.Arr_Reg_Key.Item("enc_NutPassword")
Tb_Login_Nut.Text = WinNUT_Params.Arr_Reg_Key.Item("NutLogin")
Tb_Pwd_Nut.Text = WinNUT_Params.Arr_Reg_Key.Item("NutPassword")
Cb_Reconnect.Checked = WinNUT_Params.Arr_Reg_Key.Item("AutoReconnect")
Tb_InV_Min.Text = CStr(WinNUT_Params.Arr_Reg_Key.Item("MinInputVoltage"))
Tb_InV_Max.Text = CStr(WinNUT_Params.Arr_Reg_Key.Item("MaxInputVoltage"))
Expand Down
3 changes: 1 addition & 2 deletions WinNUT_V2/WinNUT_GUI/Update_Gui.vb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@
If e.Result.Length <> 0 Then
Dim JSONReleases = Newtonsoft.Json.JsonConvert.DeserializeObject(e.Result)
Dim HighestVersion As String = Nothing
'Dim ActualVersion As Version = Version.Parse(WinNUT_Globals.ProgramVersion)
Dim ActualVersion As Version = Version.Parse("2.0.0.0")
Dim ActualVersion As Version = Version.Parse(WinNUT_Globals.ProgramVersion)
Dim sPattern As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("[Vv](\d+\.\d+\.\d+\.?\d+?).*$")
For Each JSONRelease In JSONReleases
Dim PreRelease = Convert.ToBoolean(JSONRelease("prerelease").ToString)
Expand Down
12 changes: 6 additions & 6 deletions WinNUT_V2/WinNUT_GUI/WinNUT.vb
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ Public Class WinNUT
UPS_Network.NutPort = WinNUT_Params.Arr_Reg_Key.Item("Port")
UPS_Network.NutUPS = WinNUT_Params.Arr_Reg_Key.Item("UPSName")
UPS_Network.NutDelay = WinNUT_Params.Arr_Reg_Key.Item("Delay")
UPS_Network.NutLogin = WinNUT_Params.Arr_Reg_Key.Item("enc_NutLogin")
UPS_Network.NutPassword = WinNUT_Params.Arr_Reg_Key.Item("enc_NutPassword")
UPS_Network.NutLogin = WinNUT_Params.Arr_Reg_Key.Item("NutLogin")
UPS_Network.NutPassword = WinNUT_Params.Arr_Reg_Key.Item("NutPassword")
UPS_Network.AutoReconnect = WinNUT_Params.Arr_Reg_Key.Item("AutoReconnect")
UPS_Network.Battery_Limit = WinNUT_Params.Arr_Reg_Key.Item("ShutdownLimitBatteryCharge")
UPS_Network.Backup_Limit = WinNUT_Params.Arr_Reg_Key.Item("ShutdownLimitUPSRemainTime")
Expand Down Expand Up @@ -707,13 +707,13 @@ Public Class WinNUT
NeedReconnect = True
UPS_Network.NutDelay = WinNUT_Params.Arr_Reg_Key.Item("Delay")
End If
If UPS_Network.NutLogin <> WinNUT_Params.Arr_Reg_Key.Item("enc_NutLogin") Then
If UPS_Network.NutLogin <> WinNUT_Params.Arr_Reg_Key.Item("NutLogin") Then
NeedReconnect = True
UPS_Network.NutLogin = WinNUT_Params.Arr_Reg_Key.Item("enc_NutLogin")
UPS_Network.NutLogin = WinNUT_Params.Arr_Reg_Key.Item("NutLogin")
End If
If UPS_Network.NutPassword <> WinNUT_Params.Arr_Reg_Key.Item("enc_NutPassword") Then
If UPS_Network.NutPassword <> WinNUT_Params.Arr_Reg_Key.Item("NutPassword") Then
NeedReconnect = True
UPS_Network.NutPassword = WinNUT_Params.Arr_Reg_Key.Item("enc_NutPassword")
UPS_Network.NutPassword = WinNUT_Params.Arr_Reg_Key.Item("NutPassword")
End If
If UPS_Network.UPS_Follow_FSD <> WinNUT_Params.Arr_Reg_Key.Item("Follow_FSD") Then
UPS_Network.UPS_Follow_FSD = WinNUT_Params.Arr_Reg_Key.Item("Follow_FSD")
Expand Down
34 changes: 18 additions & 16 deletions WinNUT_V2/WinNUT_GUI/WinNUT_Params.vb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
.Add("Port", 3493)
.Add("UPSName", "UPSName")
.Add("Delay", 5000)
.Add("enc_NutLogin", Cryptor.EncryptData(""))
.Add("enc_NutPassword", Cryptor.EncryptData(""))
.Add("NutLogin", Cryptor.EncryptData(""))
.Add("NutPassword", Cryptor.EncryptData(""))
.Add("AutoReconnect", vbFalse)
End With
With Arr_Reg_Calibration
Expand Down Expand Up @@ -116,15 +116,20 @@
'Verify if non encoded Login/Password Exist
'if not, create it
Dim WinnutConnRegPath = WinNUT_Params.RegBranch & "WinNUT\Connexion"
If Not (My.Computer.Registry.GetValue(WinnutConnRegPath, "NutLogin", Nothing) Is Nothing) Then
Dim OldLogin = My.Computer.Registry.GetValue(WinnutConnRegPath, "NutLogin", "")
My.Computer.Registry.SetValue(WinnutConnRegPath, "enc_NutLogin", Cryptor.EncryptData(OldLogin))
My.Computer.Registry.CurrentUser.OpenSubKey("SOFTWARE\WinNUT\Connexion", True).DeleteValue("NutLogin", False)
Dim LoginValue = My.Computer.Registry.GetValue(WinnutConnRegPath, "NutLogin", Nothing)
Dim PasswordValue = My.Computer.Registry.GetValue(WinnutConnRegPath, "NutPassword", Nothing)
If (LoginValue Is Nothing) Or Not (Cryptor.IsCryptedtData(LoginValue)) Then
My.Computer.Registry.SetValue(WinnutConnRegPath, "NutLogin", Cryptor.EncryptData(LoginValue))
'Dim OldLogin = My.Computer.Registry.GetValue(WinnutConnRegPath, "NutLogin", "")
'My.Computer.Registry.SetValue(WinnutConnRegPath, "enc_NutLogin", Cryptor.EncryptData(OldLogin))
'My.Computer.Registry.CurrentUser.OpenSubKey("SOFTWARE\WinNUT\Connexion", True).DeleteValue("NutLogin", False)
End If
If Not (My.Computer.Registry.GetValue(WinnutConnRegPath, "NutPassword", Nothing) Is Nothing) Then
Dim OldPassword = My.Computer.Registry.GetValue(WinnutConnRegPath, "NutPassword", "")
My.Computer.Registry.SetValue(WinnutConnRegPath, "enc_NutPassword", Cryptor.EncryptData(OldPassword))
My.Computer.Registry.CurrentUser.OpenSubKey("SOFTWARE\WinNUT\Connexion", True).DeleteValue("NutPassword", False)

If (PasswordValue Is Nothing) Or Not (Cryptor.IsCryptedtData(PasswordValue)) Then
My.Computer.Registry.SetValue(WinnutConnRegPath, "NutPassword", Cryptor.EncryptData(PasswordValue))
'Dim OldPassword = My.Computer.Registry.GetValue(WinnutConnRegPath, "NutPassword", "")
'My.Computer.Registry.SetValue(WinnutConnRegPath, "enc_NutPassword", Cryptor.EncryptData(OldPassword))
'My.Computer.Registry.CurrentUser.OpenSubKey("SOFTWARE\WinNUT\Connexion", True).DeleteValue("NutPassword", False)
End If

'Read Data from registry
Expand All @@ -135,14 +140,11 @@
My.Computer.Registry.CurrentUser.CreateSubKey(RegPath)
My.Computer.Registry.SetValue(WinNUT_Params.RegBranch & RegPath, RegValue.Key, RegValue.Value)
End If
If (RegValue.Key.StartsWith("enc")) Then
If (RegValue.Key = "NutLogin" Or RegValue.Key = "NutPassword") Then
Dim WinReg = My.Computer.Registry.GetValue(WinNUT_Params.RegBranch & RegPath, RegValue.Key, RegValue.Value)
Dim Result = Cryptor.IsCryptedtData(WinReg)
Dim Res = String.IsNullOrEmpty(WinReg)
If String.IsNullOrEmpty(WinReg) And Not (Cryptor.IsCryptedtData(WinReg)) Then
If String.IsNullOrEmpty(WinReg) Or Not (Cryptor.IsCryptedtData(WinReg)) Then
WinReg = Cryptor.EncryptData("")
End If

WinNUT_Params.Arr_Reg_Key.Item(RegValue.Key) = Cryptor.DecryptData(WinReg)
Else
WinNUT_Params.Arr_Reg_Key.Item(RegValue.Key) = My.Computer.Registry.GetValue(WinNUT_Params.RegBranch & RegPath, RegValue.Key, RegValue.Value)
Expand All @@ -162,7 +164,7 @@
My.Computer.Registry.CurrentUser.CreateSubKey(RegPath)
My.Computer.Registry.SetValue(WinNUT_Params.RegBranch & RegPath, RegValue.Key, RegValue.Value)
Else
If (RegValue.Key.StartsWith("enc")) Then
If (RegValue.Key = "NutLogin" Or RegValue.Key = "NutPassword") Then
My.Computer.Registry.SetValue(WinNUT_Params.RegBranch & RegPath, RegValue.Key, Cryptor.EncryptData(WinNUT_Params.Arr_Reg_Key.Item(RegValue.Key)))
Else
My.Computer.Registry.SetValue(WinNUT_Params.RegBranch & RegPath, RegValue.Key, WinNUT_Params.Arr_Reg_Key.Item(RegValue.Key))
Expand Down

0 comments on commit 2a9fc77

Please sign in to comment.