forked from cossacklabs/acra
-
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.
Transparent decryption with metadata replacing (cossacklabs#515)
* extend client session with map interface to store session related data * save session in ctx * save query encryption settings to client session * make public function of encoding binary data to hex wrap encoding functions with wrapper that do nothing with valid strings * extend GetData method for BoundValue with error returning to handle possible errors * save client session in ctx after accepting connection user struct instead of interface for QueryDataItem to avoid extra nil checks with reflection * remove redundant interface method with per column subscribing that weren't used by any component and just produce unused code and complicate reading * extend PgSQLDataEncoderProcessor, make responsible for all data encoding/decoding operations over interesting data for decryption/detokenization received from database * update encoding encrypted data in PostgresqlDBDataCoder extend encryptor, now find ColumnEncryptionSettings for queries from Parse Packet with placeholders and save it in ClientSession to use it in ParameterDescription packet followed by Parse packet (and also for Bind packet but there we already have query to re-parse it) * parse ParameterDescription + RowDescription packets, update OID values according to ColumnEncryptionSetting change value encoding flow for encrypted integers Remove encoding/decoding logic from Column struct, use only from PostgresqlEncoderDecoder and BoundValue encodings * refactor ColumnData: - don't use DecodedData struct - store raw data on protocol handler level - encode/decode data in OnColumn handler on higher level * log keystore's folder used on startup * use logger related to context instead of global in handleBindPacket function * store data about used placeholders and related ColumnEncryptionSetting in SQL queries to encrypt bound values * handle text format for binds too fix parameter description updates * validate token type in encryption_config * fix saving placeholder's data and add unit tests * move pgsql data encoder from pseudonymization to decryptor/postgresql package * convert comparable data to bytes due to receiving as bytes from db drivers * use separate setting field for data type tampering * separate PgDataEncodeDecodeProcessor into two separate processors fix unit/integration tests * encapsulate long logical check into separate function into common package decryptor/base
- Loading branch information
Showing
74 changed files
with
3,774 additions
and
886 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package common | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestClientSession_Data(t *testing.T) { | ||
session, err := NewClientSession(context.TODO(), nil, nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
type testcase struct { | ||
key string | ||
data interface{} | ||
} | ||
testcases := []testcase{ | ||
{`binary key`, []byte(`binary data`)}, | ||
{`string key`, `string value`}, | ||
{`int key`, 123}, | ||
{`struct key`, testcase{`123`, `123`}}, | ||
} | ||
overwriteValue := `some value that will overwrite existing value` | ||
for _, tcase := range testcases { | ||
if session.HasData(tcase.key) { | ||
t.Fatal("session should not have value of not used key") | ||
} | ||
value, ok := session.GetData(tcase.key) | ||
if ok { | ||
t.Fatal("session should not have value of not used key") | ||
} | ||
if value != nil { | ||
t.Fatal("session should return nil for not existing keys") | ||
} | ||
session.SetData(tcase.key, tcase.data) | ||
if !session.HasData(tcase.key) { | ||
t.Fatal("session hasn't value of existing key") | ||
} | ||
value, ok = session.GetData(tcase.key) | ||
if !ok { | ||
t.Fatal("session hasn't value of of existing key") | ||
} | ||
if !reflect.DeepEqual(tcase.data, value) { | ||
t.Fatal("session returned another value") | ||
} | ||
|
||
// overwrite value and check that it successfully overwritten | ||
session.SetData(tcase.key, overwriteValue) | ||
if !session.HasData(tcase.key) { | ||
t.Fatal("session hasn't value of existing key") | ||
} | ||
value, ok = session.GetData(tcase.key) | ||
if !ok { | ||
t.Fatal("session hasn't value of of existing key") | ||
} | ||
if !reflect.DeepEqual(overwriteValue, value) { | ||
t.Fatal("session returned another value") | ||
} | ||
|
||
session.DeleteData(tcase.key) | ||
if session.HasData(tcase.key) { | ||
t.Fatal("session should not have value of not used key") | ||
} | ||
value, ok = session.GetData(tcase.key) | ||
if ok { | ||
t.Fatal("session should not have value of not used key") | ||
} | ||
if value != nil { | ||
t.Fatal("session should return nil for not existing keys") | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
# Install grpc dependencies | ||
``` | ||
# from https://github.com/grpc/grpc-go | ||
go get -u github.com/golang/protobuf/{proto,protoc-gen-go} | ||
go get -u google.golang.org/grpc | ||
# from https://developers.google.com/protocol-buffers/docs/gotutorial | ||
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest | ||
``` | ||
To recompile proto file run from root of acra repository: | ||
``` | ||
protoc --go_out=plugins=grpc:. cmd/acra-translator/grpc_api/api.proto | ||
make build_protobuf | ||
``` |
This file was deleted.
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
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,40 @@ | ||
package base | ||
|
||
import ( | ||
"context" | ||
"net" | ||
) | ||
|
||
// ClientSession is a connection between the client and the database, mediated by AcraServer. | ||
type ClientSession interface { | ||
Context() context.Context | ||
ClientConnection() net.Conn | ||
DatabaseConnection() net.Conn | ||
|
||
PreparedStatementRegistry() PreparedStatementRegistry | ||
SetPreparedStatementRegistry(registry PreparedStatementRegistry) | ||
|
||
ProtocolState() interface{} | ||
SetProtocolState(state interface{}) | ||
GetData(string) (interface{}, bool) | ||
SetData(string, interface{}) | ||
DeleteData(string) | ||
HasData(string) bool | ||
} | ||
|
||
type sessionContextKey struct{} | ||
|
||
// SetClientSessionToContext return context with saved ClientSession | ||
func SetClientSessionToContext(ctx context.Context, session ClientSession) context.Context { | ||
return context.WithValue(ctx, sessionContextKey{}, session) | ||
} | ||
|
||
// ClientSessionFromContext return saved ClientSession from context or nil | ||
func ClientSessionFromContext(ctx context.Context) ClientSession { | ||
value := ctx.Value(sessionContextKey{}) | ||
session, ok := value.(ClientSession) | ||
if ok { | ||
return session | ||
} | ||
return nil | ||
} |
Oops, something went wrong.