secure

package
v0.0.0-...-fee78ac Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EncryptMethodAes = "aes"
	EncryptMethodRsa = "rsa"
	EncryptMethodSm4 = "sm4"
)
View Source
const (
	NotForward = iota
	AutoForward
	ManualForward
)

Variables

View Source
var (
	Crypter *crypto.RSACrypto
)

Functions

func AddSkipBodyEncryptRoutes

func AddSkipBodyEncryptRoutes(routes ...string)

func BodyDecrypt

func BodyDecrypt(body []byte, keys ...string) ([]byte, error)

func BuildBody

func BuildBody(agentInfo meta.AgentInfoInterface, param interface{}) (encryptedBody interface{}, Key, Iv []byte, err error)

func BuildBodyAndHeader

func BuildBodyAndHeader(agentInfo meta.AgentInfoInterface, uri string, param interface{}) (encryptedBody interface{}, header map[string]string, err error)

func BuildHeader

func BuildHeader(agentInfo meta.AgentInfoInterface, uri string, isForword bool, keys ...[]byte) map[string]string

func BuildHeaderForForward

func BuildHeaderForForward(agentInfo meta.AgentInfoInterface, uri string, keys ...[]byte) map[string]string

func CheckPasswordInSqlite

func CheckPasswordInSqlite() error

CheckPasswordInSqlite will try connecting ob using password stored in sqlite.

func Decrypt

func Decrypt(value string) (res string, err error)

func DecryptPwdInObConfigMap

func DecryptPwdInObConfigMap(configs map[string]sqlite.ObConfig) (err error)

func DecryptPwdInObConfigs

func DecryptPwdInObConfigs(configs []sqlite.ObConfig) (err error)

func DeleteToken

func DeleteToken(agent meta.AgentInfoInterface) (err error)

func Dump

func Dump() error

Dump will dump private key into sqlite.

func Encrypt

func Encrypt(value string) (res string, err error)

func EncryptBodyWithAes

func EncryptBodyWithAes(body interface{}) (encryptedBody interface{}, key []byte, iv []byte, err error)

func EncryptBodyWithRsa

func EncryptBodyWithRsa(agentInfo meta.AgentInfoInterface, body interface{}) (encryptedBody interface{}, err error)

func EncryptBodyWithSm4

func EncryptBodyWithSm4(body interface{}) (encryptedBody interface{}, key []byte, iv []byte, err error)

func EncryptForAgent

func EncryptForAgent(value string, agent meta.AgentInfoInterface) (res string, err error)

func EncryptPwdInObConfigMap

func EncryptPwdInObConfigMap(configs map[string]sqlite.ObConfig) (pwd string, err error)

func EncryptPwdInObConfigMapForOther

func EncryptPwdInObConfigMapForOther(configs map[string]sqlite.ObConfig, otherAgent meta.AgentInfoInterface) (err error)

func EncryptPwdInObConfigs

func EncryptPwdInObConfigs(configs []sqlite.ObConfig) (err error)

func EncryptPwdInObConfigsForOther

func EncryptPwdInObConfigsForOther(configs []sqlite.ObConfig, otherAgent meta.AgentInfoInterface) (err error)

func EncryptToOther

func EncryptToOther(raw []byte, other meta.AgentInfoInterface) (string, error)

EncryptToOther will encrypt data using other agent's public key.

func GetAgentPublicKey

func GetAgentPublicKey(agent meta.AgentInfoInterface) string

GetAgentPublicKey will get public key of specific agent.

func GetSecret

func GetSecret(ctx context.Context) *meta.AgentSecret

func GetSkipBodyEncryptRoutes

func GetSkipBodyEncryptRoutes() []string

func Init

func Init() (err error)

Init will initialize secure module.

func LoadPassword

func LoadPassword(password *string) error

LoadPassword will load password from environment variable or sqlite.

func New

func New() (err error)

New will generate new RSA crypto.

func NewToken

func NewToken(targetAgent meta.AgentInfoInterface) (string, error)

NewToken generates a token for the agent to join/scale-out an existing cluster

func Public

func Public() string

Public will return thecurrent public key.

func RepackageHeaderForAutoForward

func RepackageHeaderForAutoForward(header *HttpHeader, agentInfo meta.AgentInfoInterface) (headers map[string]string, err error)

func RestoreKey

func RestoreKey() error

RestoreKey will restore key from sqlite.

func SendDeleteRequest

func SendDeleteRequest(agentInfo meta.AgentInfoInterface, uri string, param interface{}, ret interface{}) error

SendDeleteRequest will send http delete request to the agent. If ret is not nil, it should be a pointer.

func SendDeleteRequestAndReturnResponse

func SendDeleteRequestAndReturnResponse(agentInfo meta.AgentInfoInterface, uri string, param interface{}, ret interface{}) (*resty.Response, error)

SendDeleteRequestAndReturnResponse will return http response and error. If ret is not nil, it should be a pointer.

func SendGetRequest

func SendGetRequest(agentInfo meta.AgentInfoInterface, uri string, param interface{}, ret interface{}) error

SendGetRequest will send http get request to the agent. If ret is not nil, it should be a pointer.

func SendGetRequestAndReturnResponse

func SendGetRequestAndReturnResponse(agentInfo meta.AgentInfoInterface, uri string, param interface{}, ret interface{}) (*resty.Response, error)

SendGetRequestAndReturnResponse will return http response and error. If ret is not nil, it should be a pointer.

func SendPatchRequest

func SendPatchRequest(agentInfo meta.AgentInfoInterface, uri string, param interface{}, ret interface{}) error

SendPatchRequest will send http patch request to the agent. If ret is not nil, it should be a pointer.

func SendPatchRequestAndReturnResponse

func SendPatchRequestAndReturnResponse(agentInfo meta.AgentInfoInterface, uri string, param interface{}, ret interface{}) (*resty.Response, error)

SendPatchRequestAndReturnResponse will return http response and error. If ret is not nil, it should be a pointer.

func SendPostRequest

func SendPostRequest(agentInfo meta.AgentInfoInterface, uri string, param interface{}, ret interface{}) error

SendPostRequest will send http post request to the agent. If ret is not nil, it should be a pointer.

func SendPostRequestAndReturnResponse

func SendPostRequestAndReturnResponse(agentInfo meta.AgentInfoInterface, uri string, param interface{}, ret interface{}) (*resty.Response, error)

SendPostRequestAndReturnResponse will return http response and error. If ret is not nil, it should be a pointer.

func SendPutRequest

func SendPutRequest(agentInfo meta.AgentInfoInterface, uri string, param interface{}, ret interface{}) error

SendPutRequest will send http put request to the agent. If ret is not nil, it should be a pointer.

func SendPutRequestAndReturnResponse

func SendPutRequestAndReturnResponse(agentInfo meta.AgentInfoInterface, uri string, param interface{}, ret interface{}) (*resty.Response, error)

SendPutRequestAndReturnResponse will return http response and error. If ret is not nil, it should be a pointer.

func SendRequestAndReturnResponse

func SendRequestAndReturnResponse(agentInfo meta.AgentInfoInterface, uri string, method string, param interface{}, ret interface{}) (*resty.Response, error)

func TryDecrypt

func TryDecrypt(value string) string

func TryEncrypt

func TryEncrypt(value string) string

func UpdateObPassword

func UpdateObPassword(password string) (err error)

UpdateObPassword recieve a encrypted password

func UpdateObPasswordInTransaction

func UpdateObPasswordInTransaction(tx *gorm.DB, password string) (err error)

UpdateObPasswordInTransaction recieve a encrypted password

func VerifyAuth

func VerifyAuth(pwd string, ts string, curTs int64) error

func VerifyOceanbasePassword

func VerifyOceanbasePassword(password string) error

func VerifyToken

func VerifyToken(token string) error

func VerifyTokenByAgentInfo

func VerifyTokenByAgentInfo(token string, agentInfo meta.AgentInfo) error

Types

type AgentAuth

type AgentAuth struct {
	Password string
	Ts       int64
}

type GetPasswordResp

type GetPasswordResp struct {
	Password string `json:"password"`
}

type HttpHeader

type HttpHeader struct {
	Auth         string
	Ts           string
	Token        string
	Uri          string
	Keys         []byte
	ForwardType  int
	ForwardAgent meta.AgentInfo
}

func DecryptHeader

func DecryptHeader(ciphertext string) (HttpHeader, error)

type SecureConfig

type SecureConfig struct {
	AuthExpiredDuration time.Duration
}

Jump to

Keyboard shortcuts

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