mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-09-13 14:29:09 +00:00
Compare commits
No commits in common. "91df259a870250024d21d964b0af3f31d0c0f07e" and "d5f79a943fdec24806089c99fd3136199e6fb8b4" have entirely different histories.
91df259a87
...
d5f79a943f
5 changed files with 31 additions and 307 deletions
|
@ -33,19 +33,12 @@ func (c *Client) EncryptMessage(message string) (string, error) {
|
|||
}
|
||||
|
||||
// EncryptMessageWithPublicKey encrypts a message using the provided public key and then signes the message using the users private key
|
||||
//
|
||||
// Deprecated: EncryptMessageWithPublicKey is deprecated. Use EncryptMessageWithKey instead
|
||||
func (c *Client) EncryptMessageWithPublicKey(publickey, message string) (string, error) {
|
||||
publicKey, err := crypto.NewKeyFromArmored(publickey)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Get Public Key: %w", err)
|
||||
}
|
||||
|
||||
return c.EncryptMessageWithKey(publicKey, message)
|
||||
}
|
||||
|
||||
// EncryptMessageWithKey encrypts a message using the provided key and then signes the message using the users private key
|
||||
func (c *Client) EncryptMessageWithKey(publicKey *crypto.Key, message string) (string, error) {
|
||||
key, err := c.userPrivateKey.Copy()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Get Private Key Copy: %w", err)
|
||||
|
|
|
@ -68,14 +68,3 @@ func (c *Client) DecryptMetadata(metadataKey *crypto.Key, armoredCiphertext stri
|
|||
|
||||
return metadata, nil
|
||||
}
|
||||
|
||||
func (c *Client) EncryptMetadata(metadataKey *crypto.Key, data string) (string, error) {
|
||||
armoredCiphertext, err := c.EncryptMessageWithKey(metadataKey, data)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Encrypting Metadata: %w", err)
|
||||
}
|
||||
|
||||
// TODO save Session Key to cache
|
||||
|
||||
return armoredCiphertext, nil
|
||||
}
|
||||
|
|
231
api/schema.go
231
api/schema.go
|
@ -1,231 +0,0 @@
|
|||
package api
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// Fallback Schema, Only to be used if we encounter a Broken Server (v5.0), Not API Stable!
|
||||
var ResourceSchemas = map[string]json.RawMessage{
|
||||
"v5-default": json.RawMessage(`
|
||||
{
|
||||
"resource": {
|
||||
"type": "object",
|
||||
"required": ["name"],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"maxLength": 255
|
||||
},
|
||||
"username": {
|
||||
"type": "string",
|
||||
"maxLength": 255,
|
||||
"nullable": true
|
||||
},
|
||||
"uris": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"maxLength": 1024,
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"maxLength": 10000,
|
||||
"nullable": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"secret": {
|
||||
"type": "object",
|
||||
"required": ["password"],
|
||||
"properties": {
|
||||
"object_type": {
|
||||
"type": "string",
|
||||
"enum": ["PASSBOLT_SECRET_DATA"]
|
||||
},
|
||||
"password": {
|
||||
"type": "string",
|
||||
"maxLength": 4096,
|
||||
"nullable": true
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"maxLength": 10000,
|
||||
"nullable": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}`),
|
||||
"v5-password-string": json.RawMessage(`
|
||||
{
|
||||
"resource": {
|
||||
"type": "object",
|
||||
"required": ["name"],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"maxLength": 255
|
||||
},
|
||||
"username": {
|
||||
"type": "string",
|
||||
"maxLength": 255,
|
||||
"nullable": true
|
||||
},
|
||||
"uris": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"maxLength": 1024,
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"maxLength": 10000,
|
||||
"nullable": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"secret": {
|
||||
"type": "string",
|
||||
"maxLength": 4096
|
||||
}
|
||||
}`),
|
||||
"v5-default-with-totp": json.RawMessage(`
|
||||
{
|
||||
"resource": {
|
||||
"type": "object",
|
||||
"required": ["name"],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"maxLength": 255
|
||||
},
|
||||
"username": {
|
||||
"type": "string",
|
||||
"maxLength": 255,
|
||||
"nullable": true
|
||||
},
|
||||
"uris": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"maxLength": 1024,
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"maxLength": 10000,
|
||||
"nullable": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"secret": {
|
||||
"type": "object",
|
||||
"required": ["totp"],
|
||||
"properties": {
|
||||
"object_type": {
|
||||
"type": "string",
|
||||
"enum": ["PASSBOLT_SECRET_DATA"]
|
||||
},
|
||||
"password": {
|
||||
"type": "string",
|
||||
"maxLength": 4096,
|
||||
"nullable": true
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"maxLength": 10000,
|
||||
"nullable": true
|
||||
},
|
||||
"totp": {
|
||||
"type": "object",
|
||||
"required": ["secret_key", "digits", "algorithm"],
|
||||
"properties": {
|
||||
"algorithm": {
|
||||
"type": "string",
|
||||
"minLength": 4,
|
||||
"maxLength": 6
|
||||
},
|
||||
"secret_key": {
|
||||
"type": "string",
|
||||
"maxLength": 1024
|
||||
},
|
||||
"digits": {
|
||||
"type": "number",
|
||||
"minimum": 6,
|
||||
"maximum": 8
|
||||
},
|
||||
"period": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`),
|
||||
"v5-totp-standalone": json.RawMessage(`
|
||||
{
|
||||
"resource": {
|
||||
"type": "object",
|
||||
"required": ["name"],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"maxLength": 255
|
||||
},
|
||||
"username": {
|
||||
"type": "string",
|
||||
"maxLength": 255,
|
||||
"nullable": true
|
||||
},
|
||||
"uris": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"maxLength": 1024,
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"maxLength": 10000,
|
||||
"nullable": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"secret": {
|
||||
"type": "object",
|
||||
"required": ["totp"],
|
||||
"properties": {
|
||||
"object_type": {
|
||||
"type": "string",
|
||||
"enum": ["PASSBOLT_SECRET_DATA"]
|
||||
},
|
||||
"totp": {
|
||||
"type": "object",
|
||||
"required": ["secret_key", "digits", "algorithm"],
|
||||
"properties": {
|
||||
"algorithm": {
|
||||
"type": "string",
|
||||
"minLength": 4,
|
||||
"maxLength": 6
|
||||
},
|
||||
"secret_key": {
|
||||
"type": "string",
|
||||
"maxLength": 1024
|
||||
},
|
||||
"digits": {
|
||||
"type": "number",
|
||||
"minimum": 6,
|
||||
"maximum": 8
|
||||
},
|
||||
"period": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`),
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestResourceJsonSchema(t *testing.T) {
|
||||
for slug, schema := range ResourceSchemas {
|
||||
var schemaDefinition ResourceTypeSchema
|
||||
err := json.Unmarshal(schema, &schemaDefinition)
|
||||
if err != nil {
|
||||
t.Errorf("Error While Parsing Resource Schema %v: %v", slug, err)
|
||||
} else {
|
||||
t.Logf("Schema for type %v is ok", slug)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,14 +1,11 @@
|
|||
package helper
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/passbolt/go-passbolt/api"
|
||||
"github.com/santhosh-tekuri/jsonschema"
|
||||
)
|
||||
|
||||
func GetResourceMetadata(ctx context.Context, c *api.Client, resource api.Resource, rType api.ResourceType) (string, error) {
|
||||
|
@ -57,53 +54,47 @@ func GetResourceMetadata(ctx context.Context, c *api.Client, resource api.Resour
|
|||
if err != nil {
|
||||
return "", fmt.Errorf("Decrypt Metadata: %w", err)
|
||||
}
|
||||
/*
|
||||
|
||||
var schemaDefinition api.ResourceTypeSchema
|
||||
err = json.Unmarshal([]byte(rType.Definition), &schemaDefinition)
|
||||
if err != nil {
|
||||
// Workaround for inconsistant API Responses where sometime the Schema is embedded directly and sometimes it's escaped as a string
|
||||
if err.Error() == "json: cannot unmarshal string into Go value of type api.ResourceTypeSchema" {
|
||||
var tmp string
|
||||
err = json.Unmarshal([]byte(rType.Definition), &tmp)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Workaround Unmarshal Json Schema String: %w", err)
|
||||
}
|
||||
|
||||
if tmp == "[]" {
|
||||
// Use The Builtin Fallback Schemas in this Case
|
||||
schema, ok := api.ResourceSchemas[rType.Slug]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("Server Does not have the Required json Schema and there is no fallback available for type: %v", rType.Slug)
|
||||
var schemaDefinition api.ResourceTypeSchema
|
||||
err = json.Unmarshal([]byte(rType.Definition), &schemaDefinition)
|
||||
if err != nil {
|
||||
// Workaround for inconsistant API Responses where sometime the Schema is embedded directly and sometimes it's escaped as a string
|
||||
if err.Error() == "json: cannot unmarshal string into Go value of type api.ResourceTypeSchema" {
|
||||
var tmp string
|
||||
err = json.Unmarshal([]byte(rType.Definition), &tmp)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Workaround Unmarshal Json Schema String: %w", err)
|
||||
}
|
||||
tmp = string(schema)
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(tmp), &schemaDefinition)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Workaround Unmarshal Json Schema: %w", err)
|
||||
}
|
||||
err = json.Unmarshal([]byte(tmp), &schemaDefinition)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Workaround Unmarshal Json Schema: %w", err)
|
||||
}
|
||||
|
||||
} else {
|
||||
return "", fmt.Errorf("Unmarshal Json Schema: %w", err)
|
||||
} else {
|
||||
return "", fmt.Errorf("Unmarshal Json Schema: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
comp := jsonschema.NewCompiler()
|
||||
comp := jsonschema.NewCompiler()
|
||||
|
||||
err = comp.AddResource("metadata.json", bytes.NewReader(schemaDefinition.Resource))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Adding Json Schema: %w", err)
|
||||
}
|
||||
err = comp.AddResource("metadata.json", bytes.NewReader(schemaDefinition.Secret))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Adding Json Schema: %w", err)
|
||||
}
|
||||
|
||||
schema, err := comp.Compile("metadata.json")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Compiling Json Schema: %w", err)
|
||||
}
|
||||
schema, err := comp.Compile("metadata.json")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Compiling Json Schema: %w", err)
|
||||
}
|
||||
|
||||
err = schema.Validate(strings.NewReader(decMetadata))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Validating Secret Data: %w", err)
|
||||
}
|
||||
err = schema.Validate(strings.NewReader(decMetadata))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Validating Secret Data: %w", err)
|
||||
}
|
||||
*/
|
||||
|
||||
return decMetadata, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue