Compare commits

..

No commits in common. "91df259a870250024d21d964b0af3f31d0c0f07e" and "d5f79a943fdec24806089c99fd3136199e6fb8b4" have entirely different histories.

5 changed files with 31 additions and 307 deletions

View file

@ -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)

View file

@ -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
}

View file

@ -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"
}
}
}
}
}
}`),
}

View file

@ -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)
}
}
}

View file

@ -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,6 +54,8 @@ 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)
@ -69,15 +68,6 @@ func GetResourceMetadata(ctx context.Context, c *api.Client, resource api.Resour
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)
}
tmp = string(schema)
}
err = json.Unmarshal([]byte(tmp), &schemaDefinition)
if err != nil {
return "", fmt.Errorf("Workaround Unmarshal Json Schema: %w", err)
@ -90,7 +80,7 @@ func GetResourceMetadata(ctx context.Context, c *api.Client, resource api.Resour
comp := jsonschema.NewCompiler()
err = comp.AddResource("metadata.json", bytes.NewReader(schemaDefinition.Resource))
err = comp.AddResource("metadata.json", bytes.NewReader(schemaDefinition.Secret))
if err != nil {
return "", fmt.Errorf("Adding Json Schema: %w", err)
}
@ -104,6 +94,7 @@ func GetResourceMetadata(ctx context.Context, c *api.Client, resource api.Resour
if err != nil {
return "", fmt.Errorf("Validating Secret Data: %w", err)
}
*/
return decMetadata, nil
}