Skip to content

Commit

Permalink
Bring over minor changes from the signed branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallwp committed Aug 11, 2022
1 parent 54d2730 commit 6fb88b8
Show file tree
Hide file tree
Showing 20 changed files with 37 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.codeFormatting.autoCorrectAliases": true,
"powershell.pester.useLegacyCodeLens": false,

// Helps ensure Set-AuthenticodeSignature doesn't overwrite the last line of code.
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true
}
4 changes: 2 additions & 2 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 William Marshall
Copyright (c) 2022 Industrial Info Resources, Inc.
Copyright (c) 2021 Shannon Brooks
Copyright (c) 2020 Gaston Paquette

Expand All @@ -20,4 +20,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'Remove-Secret',
'Set-Secret',
'Test-SecretVault',
'Unlock-SecretVault'
'Unlock-SecretVault',
'Unregister-SecretVault'
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
EncodingOfSecrets = 'utf8'
MaximumObjectDepth = 2
ResyncCacheIfOlderThan = New-TimeSpan -Hours 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ enum BitwardenOrganizationUserStatus {
Invited = 0
Accepted = 1
Confirmed = 2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class BitwardenPasswordHistory {
$this.LastUsedDate = $JsonObject.LastUsedDate
$this.Password = ConvertTo-SecureString -String $JsonObject.Password -AsPlainText -Force
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ function ConvertTo-HashTable
$InputObject
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ function Get-FullSecret {
}

return $Result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function Invoke-BitwardenCLI {
process {
$ps = New-Object System.Diagnostics.Process
$ps.StartInfo.Filename = $BitwardenCLI

$args | ForEach-Object {
Write-Verbose "Argument: $_"
$ps.StartInfo.ArgumentList.Add($_)
Expand Down Expand Up @@ -132,7 +132,7 @@ function Invoke-BitwardenCLI {
$Result = $ps.StandardOutput.ReadToEnd()
$BWError = $ps.StandardError.ReadToEnd()
$ps.WaitForExit()

if ($BWError) {
switch -Wildcard ($BWError) {
'Not found.' {
Expand All @@ -157,7 +157,7 @@ $($errparse | Format-Table ID, Name | Out-String )
}

# As passing exit codes to the parent process does not seem to be working, we pass $true and $false instead.
if ( $ps.StartInfo.ArgumentList.Contains('--quiet') ) {
if ( $ps.StartInfo.ArgumentList.Contains('--quiet') ) {
if($ps.ExitCode -eq 0) { return $true } else { return $false }
}

Expand Down Expand Up @@ -256,7 +256,7 @@ $BitwardenCLIArgumentCompleter = {
return $__CommandAutoComplete[ $ArgumentsArray[-1] ].Split(' ') |
Where-Object { $_ -like "$WordToComplete*" }
}

# if it doesn't have a key then we just want to pause for user input
# so we return an empty string. this pauses auto-complete until the
# user provides input.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ function Merge-Defaults {
}

return $AdditionalParameters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ function New-Secret {
}

return $Secret
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ function Sync-BitwardenVault {
# And update the cache.
Get-Date -Format "o" | Out-File -FilePath $CacheLocation -NoNewline
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function Test-KeysInHashtable {
Param(
# Hashtable object to search
[hashtable]$Hashtable,
# List of keys
# List of keys
[string[]]$Keys,
# If specified, test will fail if any of the keys are missing.
[switch]$MatchAll
Expand All @@ -15,7 +15,7 @@ function Test-KeysInHashtable {
if($Hashtable.ContainsKey($prop)) { $ContainsKey = $true }
else { $ContainsKey = $false; break }
}
elseif($Hashtable.ContainsKey($prop)) { $ContainsKey = $true; break }
elseif($Hashtable.ContainsKey($prop)) { $ContainsKey = $true; break }
}
return $ContainsKey
}
}
2 changes: 1 addition & 1 deletion SecretManagement.BitWarden.Extension/public/Get-Secret.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function Get-Secret {
switch ( $Result.type ) {
"SecureNote" {
$ObjType = ($Result.notes | Select-String -Pattern "(?<=PowerShellObjectRepresentation: )[^\n]*").Matches | Select-Object -First 1 -ExpandProperty Groups | Select-Object -First 1 -ExpandProperty Values
if( !$ObjType ) {
if( !$ObjType ) {
return $Result.notes
}
elseif( $ObjType -ieq "CliXml" ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function Get-SecretInfo {
[Alias('Vault')][string] $VaultName,
[hashtable] $AdditionalParameters
)

# Enable Verbose Mode inside this script if passed from the wrapper.
if($AdditionalParameters.ContainsKey('Verbose') -and ($AdditionalParameters['Verbose'] -eq $true)) {$script:VerbosePreference = 'Continue'}
$AdditionalParameters = Merge-Defaults $AdditionalParameters
Expand All @@ -30,8 +30,8 @@ function Get-SecretInfo {
if ( $vaultSecretInfo.type -eq [BitwardenItemType]::Login ) {
$type = [Microsoft.PowerShell.SecretManagement.SecretType]::PSCredential
}
else {
$type = [Microsoft.PowerShell.SecretManagement.SecretType]::SecureString
else {
$type = [Microsoft.PowerShell.SecretManagement.SecretType]::SecureString
}

$hashtable = [ordered]@{}
Expand All @@ -46,4 +46,4 @@ function Get-SecretInfo {
$hashtable
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ function Remove-Secret {
}

Invoke-BitwardenCLI @CmdParams
}
}
14 changes: 7 additions & 7 deletions SecretManagement.BitWarden.Extension/public/Set-Secret.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Set-Secret
}
{ "String","SecureString" -contains $Secret.GetType().Name } {
$Field = Read-Host -Prompt "Is this $($Secret.GetType().Name) a UserName, Password, TOTP, URIs, or SecureNote?"

if( $Field -iin "UserName","Password","TOTP","URIs" ) {
$OldSecret = New-Secret -Name $Name -SecretType Login
} elseif( $Field -ieq "SecureNote" ) {
Expand Down Expand Up @@ -75,7 +75,7 @@ function Set-Secret
{ ConvertFrom-SecureString $Secret.UserName -AsPlainText } else { [string]$Secret.UserName }
}
if($Secret.Password -or $IsNewItem) {
$OldSecret.login.password = if($Secret.Password -is [SecureString])
$OldSecret.login.password = if($Secret.Password -is [SecureString])
{ ConvertFrom-SecureString $Secret.Password -AsPlainText } else { [string]$Secret.Password }
}
if($Secret.uris) { $OldSecret.login.uris = @([string]$Secret.uris) } elseif($IsNewItem) { $OldSecret.login.uris = @() }
Expand Down Expand Up @@ -108,14 +108,14 @@ function Set-Secret
}

# If this is a new item, clear out all the default values.
if($IsNewItem) {
($OldSecret.login | Get-Member -MemberType NoteProperty).Name | Where-Object { $_ -ine $Field } | ForEach-Object {
if($IsNewItem) {
($OldSecret.login | Get-Member -MemberType NoteProperty).Name | Where-Object { $_ -ine $Field } | ForEach-Object {
if($_ -ine "URIs") { $OldSecret.login.$_ = $null } else { $OldSecret.logon.uris = $() }
}
}
break
}
default {
default {
$ex = New-Object System.Management.Automation.PSInvalidCastException "Casting data of $($Secret.GetType().Name) type to a Bitwarden Login is not supported."
Write-Error -Exception $ex -Category InvalidType -ErrorId "InvalidCast" -ErrorAction Stop
break
Expand Down Expand Up @@ -176,7 +176,7 @@ function Set-Secret
}
break
}
default {
default {
$ex = New-Object System.Management.Automation.PSInvalidCastException "Casting data of $($Secret.GetType().Name) type to a Bitwarden Card is not supported."
Write-Error -Exception $ex -Category InvalidType -ErrorId "InvalidCast" -ErrorAction Stop
break
Expand All @@ -202,7 +202,7 @@ function Set-Secret
}
break
}
default {
default {
$ex = New-Object System.Management.Automation.PSInvalidCastException "Casting data of $($Secret.GetType().Name) type to a Bitwarden Identity is not supported."
Write-Error -Exception $ex -Category InvalidType -ErrorId "InvalidCast" -ErrorAction Stop
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ function Test-SecretVault {
Sync-BitwardenVault -Force
return $true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ function Unlock-SecretVault {
}

Write-Verbose $env:BW_SESSION
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ function Unregister-SecretVault
# Removes the bitwarden-ext directory and all contents from the computer.
$BitwardenExtDir = $IsWindows ? "$env:LocalAppData\Microsoft\PowerShell\secretmanagement\bitwarden-ext" : "$HOME/.secretmanagement/bitwarden-ext"
Remove-Item -Path $BitwardenExtDir -Recurse
}
}

0 comments on commit 6fb88b8

Please sign in to comment.