mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-09-13 14:29:09 +00:00
Add Metadata Decryption
This commit is contained in:
parent
b0f75af26a
commit
2197d9e0f7
2 changed files with 141 additions and 0 deletions
41
api/metadata.go
Normal file
41
api/metadata.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ProtonMail/gopenpgp/v3/crypto"
|
||||
)
|
||||
|
||||
// ResourceMetadataTypePasswordAndDescription
|
||||
type ResourceMetadataTypePasswordAndDescription struct {
|
||||
ObjectType string `json:"object_type"`
|
||||
ResourceTypeID string `json:"resource_type_id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
URIs []string `json:"uris,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) DecryptMetadata(metadataKey *crypto.Key, armoredCiphertext string) (string, error) {
|
||||
// TODO Get SessionKey from Cache
|
||||
var sessionKey *crypto.SessionKey = nil
|
||||
|
||||
if sessionKey != nil {
|
||||
message, err := c.DecryptMessageWithSessionKey(sessionKey, armoredCiphertext)
|
||||
// If Decrypt was successfull
|
||||
if err == nil {
|
||||
return message, nil
|
||||
}
|
||||
// if this failed, fall through
|
||||
}
|
||||
|
||||
metadata, newSessionKey, err := c.DecryptMessageWithPrivateKeyAndReturnSessionKey(metadataKey, armoredCiphertext)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Decrypting Metadata: %w", err)
|
||||
}
|
||||
|
||||
// TODO Save newSessionKey to cache
|
||||
_ = newSessionKey
|
||||
|
||||
return metadata, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue