-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from openfort-xyz/fix/migrate-sss-library
feat: new sss library
- Loading branch information
Showing
28 changed files
with
465 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
internal/adapters/encryption/deprecated_sss_reconstruction_strategy/strategy.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package depsssrec | ||
|
||
import ( | ||
"go.openfort.xyz/shield/internal/core/domain/errors" | ||
"go.openfort.xyz/shield/internal/core/ports/strategies" | ||
"go.openfort.xyz/shield/pkg/cypher" | ||
) | ||
|
||
const ( | ||
MaxReties = 5 | ||
) | ||
|
||
type SSSReconstructionStrategy struct{} | ||
|
||
func NewSSSReconstructionStrategy() strategies.ReconstructionStrategy { | ||
return &SSSReconstructionStrategy{} | ||
} | ||
|
||
func (s *SSSReconstructionStrategy) Split(data string) (storedPart string, projectPart string, err error) { | ||
for i := 0; i < MaxReties; i++ { | ||
storedPart, projectPart, err = cypher.SplitEncryptionKey(data) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
err = s.validateSplit(data, storedPart, projectPart) | ||
if err == nil { | ||
return | ||
} | ||
} | ||
|
||
return | ||
} | ||
|
||
func (s *SSSReconstructionStrategy) Reconstruct(storedPart string, projectPart string) (string, error) { | ||
return cypher.ReconstructEncryptionKey(storedPart, projectPart) | ||
} | ||
|
||
func (s *SSSReconstructionStrategy) validateSplit(data string, storedPart string, projectPart string) error { | ||
reconstructed, err := s.Reconstruct(storedPart, projectPart) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if data != reconstructed { | ||
return errors.ErrReconstructedKeyMismatch | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
internal/adapters/repositories/sql/migrations/20240712130440_shamir_migrations.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-- +goose Up | ||
CREATE TABLE IF NOT EXISTS shld_shamir_migrations ( | ||
id VARCHAR(36) PRIMARY KEY, | ||
project_id VARCHAR(36) NOT NULL, | ||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
success BOOLEAN NOT NULL DEFAULT FALSE | ||
); | ||
CREATE INDEX idx_project_id_success ON shld_shamir_migrations(project_id, success); | ||
DROP TABLE IF EXISTS shld_allowed_origins; | ||
-- +goose StatementBegin | ||
-- +goose StatementEnd | ||
|
||
-- +goose Down | ||
DROP INDEX idx_project_id_success ON shld_shamir_migrations; | ||
DROP TABLE IF EXISTS shld_shamir_migrations; | ||
CREATE TABLE IF NOT EXISTS shld_allowed_origins ( | ||
id VARCHAR(36) PRIMARY KEY, | ||
project_id VARCHAR(36) NOT NULL, | ||
origin VARCHAR(255) NOT NULL, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||
deleted_at TIMESTAMP DEFAULT NULL | ||
); | ||
ALTER TABLE shld_allowed_origins ADD CONSTRAINT fk_origin_project FOREIGN KEY (project_id) REFERENCES shld_projects(id) ON DELETE CASCADE; | ||
-- +goose StatementBegin | ||
-- +goose StatementEnd |
Oops, something went wrong.