Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions SecretManagement.Chromium.Extension/Public/Find-Chromium.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ function Find-Chromium {
function getProfileNames ($UserDataFolderPath) {
try {
$localStatePath = Join-Path -Resolve $UserDataFolderPath 'Local State' -ErrorAction stop
} catch {
}
catch {
Write-Warning "$UserDataFolderPath exists but has no Local State file."
}
[String[]]$ProfileNames = (Get-Content -Raw $localStatePath | ConvertFrom-Json).profile.info_cache.psobject.properties.name
[String[]]$ProfileNames = (Get-Content -Raw $localStatePath | ConvertFrom-Json -AsHashtable)["profile"].info_cache.Keys
if (-not $ProfileNames) { Write-Warning 'Local State file exists but no profile information was found' }
return $ProfileNames
}
Expand Down Expand Up @@ -75,7 +76,8 @@ function Find-Chromium {
} | Write-Output
Write-Verbose "SecretManagement.Chromium: Discovery FOUND $PresetItem profile at $($Presets[$PresetItem])"
}
} catch {
}
catch {
Write-Verbose "SecretManagement.Chromium: Discovery NOT FOUND $PresetItem profile at $($Presets[$PresetItem])"
}
}
Expand Down
21 changes: 13 additions & 8 deletions SecretManagement.Chromium.Extension/Public/Test-SecretVault.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using namespace 'System.Security.Cryptography'
function Test-SecretVault {
[CmdletBinding()]
param (
[Parameter(ValueFromPipelineByPropertyName,Mandatory)]
[Parameter(ValueFromPipelineByPropertyName, Mandatory)]
[string]$VaultName,

[Parameter(ValueFromPipelineByPropertyName)]
Expand All @@ -24,7 +24,8 @@ function Test-SecretVault {
$candidateStatePath = Join-Path $AdditionalParameters.DataPath '../../Local State' -Resolve -ErrorAction stop
Write-Verbose "Autodetected Local State file at $candidateStatePath"
$AdditionalParameters.StatePath = $candidateStatePath
} catch {
}
catch {
throw "Vault ${VaultName}: You must specify the StatePath parameter as a path to your Chromium Database. Hint for Chrome: `$env:LOCALAPPDATA\Google\Chrome\User Data\Local State"
}
}
Expand All @@ -33,7 +34,8 @@ function Test-SecretVault {
$tempDBFile = Join-Path ([io.path]::GetTempPath()) "ChromeVault-$PID-$VaultName.dbcache"
if ((Test-Path $tempDBFile) -and $dbFile.LastWriteTime -eq (Get-Item $tempDBFile).LastWriteTime -and $dbFile.Length -eq (Get-Item $tempDBFile).Length) {
Write-Debug "${VaultName}: Temp DB $tempDBFile is still a valid cache"
} else {
}
else {
#Make a copy because Chromium locks the DB file at the SQLite level and this will freeze the module trying to open it
Write-Debug "${VaultName}: Source DB has been updated, copying to $tempDBFile"
$tempDB = Copy-Item -ErrorAction Stop -Path $dbFile -Destination $tempDBFile -PassThru
Expand All @@ -52,15 +54,17 @@ function Test-SecretVault {
Remove-Item $tempDBFile
}
$SCRIPT:__VAULT[$VaultName] = $db
} catch {
}
catch {
throw
} finally {
}
finally {
$db.close()
}

#Extract the local state encryption key if present
if ($AdditionalParameters.StatePath) {
$localStateInfo = Get-Content -Raw $AdditionalParameters.StatePath | ConvertFrom-Json
$localStateInfo = Get-Content -Raw $AdditionalParameters.StatePath | ConvertFrom-Json -AsHashtable
if ($localStateInfo) {
$encryptedkey = [convert]::FromBase64String($localStateInfo.os_crypt.encrypted_key)
}
Expand All @@ -69,9 +73,10 @@ function Test-SecretVault {
if ($PSVersionTable.PSVersion -lt '7.0.0') {
throw [NotSupportedException]'Chromium v80 or later AES-encrypted passwords were detected, currently we cannot decrypt these with Windows Powershell or PS6. Please use Powershell 7'
}
$masterKey = [ProtectedData]::Unprotect(($encryptedkey | Select-Object -Skip 5), $null, 'CurrentUser')
$masterKey = [ProtectedData]::Unprotect(($encryptedkey | Select-Object -Skip 5), $null, 'CurrentUser')
$SCRIPT:__VAULT["$VaultName-Key"] = [AesGcm]::new($masterKey)
} else { Write-Warning 'Could not get key for new-style encyption. Will try with older Style' }
}
else { Write-Warning 'Could not get key for new-style encyption. Will try with older Style' }
}

return $true
Expand Down