diff --git a/api/encryption.go b/api/encryption.go index 2c393ee..c39eee3 100644 --- a/api/encryption.go +++ b/api/encryption.go @@ -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) diff --git a/api/metadata.go b/api/metadata.go index cc40425..f62464f 100644 --- a/api/metadata.go +++ b/api/metadata.go @@ -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 -} diff --git a/api/schema.go b/api/schema.go deleted file mode 100644 index b9fe6d4..0000000 --- a/api/schema.go +++ /dev/null @@ -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" - } - } - } - } - } -}`), -} diff --git a/api/schema_test.go b/api/schema_test.go deleted file mode 100644 index a9069e4..0000000 --- a/api/schema_test.go +++ /dev/null @@ -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) - } - } -} diff --git a/helper/metadata.go b/helper/metadata.go index e89cb78..eebb89e 100644 --- a/helper/metadata.go +++ b/helper/metadata.go @@ -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 }