21

I am changing a users laptop and they have saved their username and passowrd in the OpenVPN GUI. Naturally they don't know their password because they entered them a while back and click "save password". Is there anyway to recover these details so that I can migrate them to the new laptop without having to get the VPN account reset (which would be quite a lot more difficult that it should be!).

Both laptops are Windows 10.

I have copied the .ovpn, p12 and .key files over but the GUI still prompts for the username and password. There is no password text file inside the config directory (under OpenVPN under Program Files).

I've search the registry too but couldn't find the info there.

EDIT: To be clear I don't actually need to "recover" the password. If it is encrypted in a registry key for example, that is fine, I could export the key from the old laptop and import it on the new one. I need to find a way to copy the details from laptop1 to laptop2.

1
  • Since keywords are protected using system security services I doubt copy-pasting the encrypted record is going to work. Did it work in your case? Oct 21, 2021 at 7:40

5 Answers 5

19
+100

Per the OpenVPN GUI source code, saved passwords are stored in the registry under HKCU\Software\OpenVPN-GUI\configs.

30

The Powershell script in this link gets the password for me: OpenVPN Password Recovery

The registry names on my computer are a bit different; my version:

$keys = Get-ChildItem "HKCU:\Software\OpenVPN-GUI\configs"
$items = $keys | ForEach-Object {Get-ItemProperty $_.PsPath}

foreach ($item in $items)
{
  $encryptedbytes=$item.'auth-data'
  $entropy=$item.'entropy'
  $entropy=$entropy[0..(($entropy.Length)-2)]

  $decryptedbytes = [System.Security.Cryptography.ProtectedData]::Unprotect(
    $encryptedBytes, 
    $entropy, 
    [System.Security.Cryptography.DataProtectionScope]::CurrentUser)
 
  Write-Host ([System.Text.Encoding]::Unicode.GetString($decryptedbytes))
}

You may also need to execute Add-Type -AssemblyName System.Security in Powershell to make it work.

edit: on windows 10, OpenVPN v11.9, $encryptedbytes=$item.'key-data'

3
  • 6
    Worked for me changing 'key-data' to 'auth-data'
    – leonbloy
    Mar 20, 2020 at 23:10
  • @leonbloy / Alex has anyone seen my question here stackoverflow.com/q/70934162/365107 ? How do I get OpenVPN Username in the same way, I have also put what I tried as code there, can anyone assist in fixing the issue ?
    – Vicky Dev
    Feb 7, 2022 at 0:08
  • Thanks, @leonbloy, your comment helped with the answer provided by Alex. This answer should be the accepted one, in my opinion, because it more clearly solves the problem as stated by the OP. In my experience, simply copying the registry keys over did not work, probably because the entropy data for the encrypted password is not shared between different Windows installs. Sep 27, 2023 at 13:58
2

I have same problem after migrating from windows 10 with corporate openVPN config to windows 11 workplace. Scripts in this thread did not help me. And i made my own. May be this help someone else... Just replace registry path in Get-ItemPropertyValue with yours stored path and run this script in power shell window... Working in Windows 10x64, OpenVPN 2.4.9

$keyBinEncrupted = Get-ItemPropertyValue 'HKCU:\SOFTWARE\OpenVPN-GUI\configs\corpnet' 'key-data'
$entropyBin = Get-ItemPropertyValue 'HKCU:\SOFTWARE\OpenVPN-GUI\configs\corpnet' 'entropy'
$entropyBin = $entropyBin[0..(($entropyBin.Length)-2)]

$keyBinDecrupted = [System.Security.Cryptography.ProtectedData]::Unprotect(
    $keyBinEncrupted,
    $entropyBin,
    [System.Security.Cryptography.DataProtectionScope]::CurrentUser)

Write-Host ([System.Text.Encoding]::Unicode.GetString($keyBinDecrupted))
1
  • 1
    Hi. I got a error when executed your script but it worked after to add this line at the top: .. Add-Type -assembly System.Security .. I don't know why I needed it but it's just to help others. I'm on Windows 11
    – btafarelo
    Aug 18, 2023 at 9:27
1

My version is working on Windows 10/11 x64. It requires no Admin rights after executing following commands:

Set-ExecutionPolicy RemoteSigned
Add-Type -AssemblyName System.Security
#openvpn-password-recovery.ps1

$keys = Get-ChildItem "HKCU:\Software\OpenVPN-GUI\configs"
$items = $keys | ForEach-Object {Get-ItemProperty $_.PsPath}

foreach ($item in $items)
{

  Write-Host ($item.'PSChildName')
  $username=$encryptedbytes=$item.'username'
  Write-Host ([System.Text.Encoding]::Unicode.GetString($username))

  $encryptedbytes=$item.'auth-data'
  $entropy=$item.'entropy'
  $entropy=$entropy[0..(($entropy.Length)-2)]

  $decryptedbytes = [System.Security.Cryptography.ProtectedData]::Unprotect(
    $encryptedBytes, 
    $entropy, 
    [System.Security.Cryptography.DataProtectionScope]::CurrentUser)
 
  Write-Host ([System.Text.Encoding]::Unicode.GetString($decryptedbytes))
  Write-Host (' ')

}
0

Adding to the answer from Alex:

You can also easily extract the username as well if required by adding the following two lines:

$username=$encryptedbytes=$item.'username'
Write-Host ([System.Text.Encoding]::Unicode.GetString($username))

Also note that depending on your PowerShell config, you might need to run the following two commands first before the script can work (to allow scripts and enable the security types needed for the decryption process):

set-executionpolicy remotesigned 
Add-Type -AssemblyName System.Security

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .