securitymdl

package
v2.0.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SEC_ENCKey     = "encKey"
	SEC_UserKey    = "userKey"
	SEC_FieldQuery = "fieldQuery"
	SEC_SECURITY   = "security"
)
View Source
const (
	// SharedPrefix prefix represents the file is sharable i.e encryption key does not include (fdbSec.fieldQuery)
	SharedPrefix = "ss_"
	EmptySTR     = ""
)

Variables

View Source
var IV = ""

IV set IV for dev mode

Functions

func AESDecrypt

func AESDecrypt(encodedData, key []byte) ([]byte, error)

AESDecrypt Decrypts given cipher text

func AESEncrypt

func AESEncrypt(plainText, key []byte) ([]byte, error)

AESEncrypt Encrypts given text

func CheckDataForFieldQuery

func CheckDataForFieldQuery(fileName string, data *gjson.Result) (bool, error)

CheckDataForFieldQuery checks for result of field query in data.

If no query is provided OR Not shared file, the result will be false, nil

Else will check for query result. If result is empty, error will be thrown.

Check only if security is enabled for the database.

fileName must not be empty and data must not be nil

func CheckPasswordSalt

func CheckPasswordSalt(hashedPassword, password string) bool

CheckPasswordSalt - compares hashed password with its possible plaintext equivalent. Returns true on match, or an false on mismatch.

func CreateSecurityKey

func CreateSecurityKey(keyLength int) (string, error)

CreateSecurityKey generates random string of given length

func GenSecKey

func GenSecKey(fileName string, data *gjson.Result) (string, error)

func GenSecKeyBytes

func GenSecKeyBytes(fileName string, data *gjson.Result) ([]byte, error)

GenSecKey generates the security key for FDB.

If fileName has prefix "ss_" then key is generated by 1. Global encryption key (fdbSec.encKey) 2. UserDefinedKey (fdbSec.userDefinedKey) 3. fileName

else result by firing (fdbSec.fieldQuery) on data is also included in generation. If rusult is empty, expect an error.

Order for key: data.Get(fdbSec.fieldQuery).String() + fdbSec.encKey + fdbSec.userDefinedKey + fileName(only)

func GetHash

func GetHash(plaintext string) (string, error)

GetHash - returns Hash Check sum of given plaintext

func GetHashAndSalt

func GetHashAndSalt(plaintext, salt string) (string, error)

GetHashAndSalt - returns Hash Check sum of given plaintext+ salt combination

func PaddingDataUsingpkcs7

func PaddingDataUsingpkcs7(buf []byte, size int) ([]byte, error)

PaddingDataUsingpkcs7 - This methods is copy from https://github.com/mergermarket/go-pkcs7

func SaltPassword

func SaltPassword(password string) (string, error)

SaltPassword Salt using bcrypt creates saltedString of given string,it generates new saltedString each time for the same input

func SetIV

func SetIV(initializationVector string)

SetIV will set initializationVector

func SetSecurityConfig

func SetSecurityConfig(secKey []byte, initializationVector string)

SetSecurityConfig will set security key and initializationVector

func SetSecurityKey

func SetSecurityKey(secKey []byte)

SetSecurityKey will set Security key

func SetSecurityKeyGeneratorFunc

func SetSecurityKeyGeneratorFunc(genratorFunc SecurityKeyGeneratorFunc)

SetSecurityKeyGeneratorFunc - sets default security Key

func UnpaddingDataUsingpkcs7

func UnpaddingDataUsingpkcs7(padded []byte, size int) ([]byte, error)

UnpaddingDataUsingpkcs7 - his methods is copy from https://github.com/mergermarket/go-pkcs7

Types

type FDBSecOptions

type FDBSecOptions struct {
	EncKey         string // the global encryption key used in the project. This key will be applicable in all cases.
	UserDefinedKey string // the user defined key in the project. This key will be applicable in all cases.
	FieldQuery     string // query to get dynamic field. Ex. Each student data can be encrypted with studentID. Applicable only for the shared bucket.
}

FDBSecOptions provide options to be set for fdb security. All fields are compulsorry. On applying options, we will get error if any field is empty. Only these options are exposed as actual

func GetFDBSecOptions

func GetFDBSecOptions() FDBSecOptions

GetFDBSecOptions returns the copy of fdb options set by Apply() method.

func NewFDBOptions

func NewFDBOptions() *FDBSecOptions

func (*FDBSecOptions) Apply

func (fo *FDBSecOptions) Apply() error

Apply sets the internal security variable.

Returns error if options fail while validations and if Apply() is already called.

func (*FDBSecOptions) Validate

func (fs *FDBSecOptions) Validate() error

Validate checks options for empty fields.

type FDBSecParams

type FDBSecParams struct {
	EnableSecurity    bool
	EnableCompression bool
}

FDBSecParams provide options for the FDB security for the FDB CRUD operations.

type SecurityKeyGeneratorFunc

type SecurityKeyGeneratorFunc func(string) ([]byte, error)

SecurityKeyGeneratorFunc - header definition

func GetSecurityKeyGeneratorFunc

func GetSecurityKeyGeneratorFunc() SecurityKeyGeneratorFunc

GetSecurityKeyGeneratorFunc - returns security Key

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL