Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter -UUID to Get-KeePassEntry #187

Open
tim-krehan opened this issue Dec 4, 2020 · 5 comments
Open

Add parameter -UUID to Get-KeePassEntry #187

tim-krehan opened this issue Dec 4, 2020 · 5 comments
Assignees

Comments

@tim-krehan
Copy link

Hi,

ist it possible, to add the Parameter -UUID To the Get-KeePassEntry function?
I tried a little coding myself, but got lost along the way.

Should I make a pull request with the changes i made until now?
Basically I only added the parameter to the list of params in the Get-KeePassEntry function with datatype [GUID] and assigned it to $params.UUID in the process block as byte array.

if($UUID){ $params.UUID = $UUID.ToByteArray() }

Greetings,
Tim

@tim-krehan
Copy link
Author

I think #155 would also be profiting from this, as the enduser could resolve the reference by himself.

@jkdba jkdba self-assigned this Dec 4, 2020
@jkdba
Copy link
Member

jkdba commented Dec 4, 2020

Interesting where would you be getting the UUID value to be passing to this new parameter?

@tim-krehan
Copy link
Author

From at least one other command execution before.
The uuid is stored as following in the corresponding field of the returned PSObject:
{REF:P@I:<<UUID>>}
Source: keepass

You can take the bit after the colon and put that in the new execution of the CMDlet, like following:

$entry = Get-KeePassEntry -MasterKey $key -KeePassGrouPath "Path/to/Group" -Title "Pass" -WithCredential
$entry.credential.GetNetworkCredential().Password

PS> {REF:P@I:2DED41BE10F50747A27641F095ADF1E8}

That uuid is fictitious, but should fit with the context.

@jkdba
Copy link
Member

jkdba commented Dec 4, 2020

Ok so I do expose the Uuid on entry return in the native type of [KeePassLib.PwUuid]

$x = Get-KeePassEntry  -blah -blah;
$x.Uuid 

The underlying call in Get-KeePassEntry: Get-KPEntry Supports a -UUID Parameter for this type of look up the only caveat is it must be the keepass type [KeePassLib.PwUuid]

This should not be an issue if you are retrieving the Uuid from the library and its already in the type [KeePassLib.PwUuid] . If you attempt to go from GUID to [KeePassLib.PwUuid] things get a little more complicated. The byte array produced by GUID.ToByteArray will not produce the same UUID when utilizing the PwUuid New Constructor [KeePassLib.PwUuid]::new($byteArray). Here is an SO question looking to perform this conversion. I suspect poking around KeePassLib source code will be necessary to understand the conversion process (and the Import/Export to xml might be a good place to look).

If the goal is to go from GUID to PwUuid and we are unable to figure out the conversion a work around would be to compare the values as strings: $PwUuid.ToHexString() -eq $GUID.ToString() -replace '-' and in the true since of a workaround its not great.

If the goal is to look up an Uuid of type KeePassLib.PwUuid the change to code should be relatively easy.
Add Parameter to Get-KeePassEntry -UUID of type KeePassLib.PwUuid. Then as you mention pass to the underlying call's parameter Get-KPEntry -KeePassUuid $UUID aka if($UUID){ $params.KeePassUuid= $UUID) }.

@tim-krehan
Copy link
Author

Yeah, the reason I came up with this, was that I had a few of these relations in my database. If you get on of these entries, the resulting string (or securestring) in the corresponding field will contain one of those REF:P@I:UUID kind of strings.
So you can break that down in its single components like that:

{REF:P@I:<<UUID>>}
into:

{
  REF:
  P <-- this field should contain the value of password in the referenced entry
  @
  I <-- this means that the following string will contain the UUID of the referenced entry
  :
  <UUID> <-- the uuid of the referenced entry in ... [string] format. bummer.
}

So there must be a way to convert the String we are getting back here in the [KeePassLib.PwUuid] type.

One thing I tried allready was the following:

$guidbytes = [guid]::new("<<UUID>>").ToByteArray()
$uuidBytes = $keePassEntry.Uuid.UuidBytes
Compare-Object -ReferenceObject $guidbytes -differenceObject $uuidBytes

PS> $true
So at least the underlying bytes are equal.
Maybe we can use that as common attribute?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants