Documentation
¶
Index ¶
- Constants
- Variables
- func Any2RsaPublicKey(data any) (*rsa.PublicKey, error)
- func ArrayContains[T comparable](s []T, e T) bool
- func ByteArray2File(file *os.File, bytes []byte) error
- func ByteArray2ReponseWriter(file http.ResponseWriter, bytes []byte) error
- func Bytea2b64(ba []byte) string
- func Bytes2sha256(bytes []byte) []byte
- func CaptureOutput(f func()) (stderr string, stdout string)
- func CondDebug(msg ...string)
- func CondDebugSet(val bool)
- func CondDebugStatus() bool
- func CondDebugln(msg ...string)
- func CreateRSAKeyPair(bitSize int) (*rsa.PrivateKey, *rsa.PublicKey, error)
- func CreateRSAKeyPair2File(outfileName string, bitSize int) error
- func CurrentFunctionName() string
- func Debug(msg ...string)
- func DebugRsaPublicKey(pubKey *rsa.PublicKey)
- func Debugln(msg ...string)
- func ErrorExit(errorCode uint8, msg ...string)
- func ExecCmd(cmd string, args ...string) error
- func ExecNoOutputCmd(cmd string) error
- func ExecOutputCmd(cmd string) ([]byte, error)
- func ExecutableReachableByPath(cmd ...string) error
- func ExitIfError(err error, exitcode uint8, msg string)
- func FatalGetEnvValue(key string) string
- func FilenameWithoutSuffix(filename string) string
- func Format(format DestinationFormat, body interface{}) (string, error)
- func GetCertAttributesCnOu(headers map[string][]string) (string, string, error)
- func GetEnvValue(key string) (string, error)
- func GetEnvValueOrDefaultBool(key string, defaultValue bool) bool
- func GetEnvValueOrDefaultInt(key string, defaultValue int) int
- func GetEnvValueOrDefaultString(key string, defaultValue string) string
- func IsDirectory(filename string) bool
- func IsExecutableCmd(cmd string) error
- func IsExistingFile(filename string) bool
- func IsPlainFile(filename string) bool
- func LoadPrivateKey(filename string) (*rsa.PrivateKey, error)
- func LoadRsaPublicKey(filename string) (*rsa.PublicKey, error)
- func LogErr(msg string)
- func LogInfo(msg string)
- func LogInit(tag string)
- func LogStringInit(tag string)
- func LogWarn(msg string)
- func Pem2CSR(bytes []byte) (*x509.CertificateRequest, error)
- func Pem2RsaPrivateKey(der []byte) (*rsa.PrivateKey, error)
- func Pem2RsaPublicKey(der []byte) (*rsa.PublicKey, error)
- func PsqlGetUser(constr string) (string, error)
- func PsqlListTablesInCurrentDatabase(dbPool *pgxpool.Pool) ([]string, error)
- func PsqlVerifyTablePermissions(dbPool *pgxpool.Pool, user string, perms PsqlTablePermission, tables ...string) error
- func RsaPrivateKey2Sha256Digest(prvKey *rsa.PrivateKey) (string, error)
- func RsaPublicKey2Sha256Digest(pubKey *rsa.PublicKey) (string, error)
- func Sign115ByteArray(key *rsa.PrivateKey, digest []byte) ([]byte, error)
- func Sign115ByteArray2Base64(key *rsa.PrivateKey, digest []byte) (string, error)
- func SignPSSByteArray(key *rsa.PrivateKey, digest []byte) ([]byte, error)
- func SignPSSByteArray2Base64(key *rsa.PrivateKey, digest []byte) (string, error)
- func Str2sha256(str string) []byte
- func String2md5(str string) string
- func ValidIPv4Address(ipv4 string) error
- func Verify115Base64String(key *rsa.PublicKey, b64 string, msg string) error
- func Verify115ByteArray(key *rsa.PublicKey, digest []byte, msg []byte) error
- func VerifyPSSBase64String(key *rsa.PublicKey, b64 string, msg string) error
- func VerifyPSSByteArray(key *rsa.PublicKey, digest []byte, msg []byte) error
- func WriteRsaPrivateKey(file *os.File, privKey *rsa.PrivateKey) error
- func WriteRsaPublicKey(file *os.File, pubKey *rsa.PublicKey) error
- type DestinationFormat
- type PsqlTablePermission
Constants ¶
const Debugerrorce_app_version = "3.9.1"
const RSA2048 = 2048
const RSA4096 = 4096
Variables ¶
var OutputWriter io.Writer = os.Stderr
OutputWriter defines the default output channel. It can be changed if required.
Functions ¶
func Any2RsaPublicKey ¶
TODO: support for at least the additional algorithm Ed25519 https://golang.google.cn/pkg/crypto/x509/#PublicKeyAlgorithm Any2RsaPublicKey is required to read public keys from *x509.CertificateRequest
func ArrayContains ¶
func ArrayContains[T comparable](s []T, e T) bool
func ByteArray2File ¶
ByteArray2File writes a byte array into a file. If required it does so in multiple steps. If all succeeds then nil is returned, otherwise an error.
func ByteArray2ReponseWriter ¶
func ByteArray2ReponseWriter(file http.ResponseWriter, bytes []byte) error
ByteArray2ReponseWriter writes a byte array into a file. If required it does so in multiple steps. If all succeeds then nil is returned, otherwise an error.
func Bytea2b64 ¶
create the sha256 sum of str, don't treat it as hex but as binary and take the base64 of it
func Bytes2sha256 ¶
Bytes2sha256 (ex: Sha256bytes2bytes) converts a byte sequence into a SHA-256-based digest of it. The output for this application is the same on the commadn line with: curl -q localhost:8888 | jq -c .Data | tr -d '\n' | shasum -a256 The added newline must be removed. Alternatively, gnu-sed can be used instad of tr: gsed -Ez 's/\n$//' The complete JSON return structure only consists of US-ASCII characters. So potential different escaping for special characters do not have to be considered.
func CaptureOutput ¶
CaptureOutput get a function as its argument. It executes the function and returns the output (stderr and stdout) created by this function. While capturing this output, this output is not written to default stdout or stderr.
func CondDebug ¶
func CondDebug(msg ...string)
CondDebug outputs if debug is set without an added newline at the EOL.
func CondDebugStatus ¶
func CondDebugStatus() bool
CondDebugStatus allows to check if debug is turned on/off.
func CondDebugln ¶
func CondDebugln(msg ...string)
CondDebugln is the implementation of a global debug function. If it was turned on using CondDebugSet(true), then the string is shown to stderr. Else, no output is created.
func CreateRSAKeyPair ¶
CreateRSAKeyPair creates an RSA bitsize-bit key-pair. This function makes only partly sense, as the private key always contains the public key.
func CreateRSAKeyPair2File ¶
CreateRSAKeyPair2File checks if the 2 required files do not exist and can be created sucessfully. Then, it transfers control to createKeyPairError2.
func CurrentFunctionName ¶
func CurrentFunctionName() string
CurrentFunctionName returns the name of the current function being executed.
func DebugRsaPublicKey ¶
func Debugln ¶
func Debugln(msg ...string)
Debugln outputs a message with adding a newline at the EOL
func ErrorExit ¶
ErrorExit exits the application with the specified error code. The output is written to the assigned output writer, by default stderr.
func ExecCmd ¶
ExecCmd is a helper to execute an external application. If the exit status of this command is non-zero, then an error is returned, else nil. Deprecated: ExecCmd is deprecated. Replaced by ExecNoOutputCmd.
func ExecNoOutputCmd ¶
ExecNoOutputCmd calls a command but does not expect handle output except for the return code of the app.
func ExecOutputCmd ¶
func ExecutableReachableByPath ¶
ExecutableReachableByPath checks for all given input if the input is executable and can be found by the current setting of the PATH variable.
func ExitIfError ¶
ExitIfError exists using ErrorExit if the supplied err is not nil. In such a case, the error message of err will be added to the message.
func FatalGetEnvValue ¶
FatalGetEnvValue does the same as getEnvValue, but exits with an error
func FilenameWithoutSuffix ¶
func GetCertAttributesCnOu ¶ added in v3.9.0
func GetEnvValue ¶
GetEnvValue retrieves a value from the ENV if exists, otherwise returns an error
func GetEnvValueOrDefaultBool ¶
GetEnvValueOrDefaultBool returns the ENV boolean value for the given key or the default one
func GetEnvValueOrDefaultInt ¶
GetEnvValueOrDefaultInt returns the ENV int value for the given key or the default one if none could be found or if there is an error parsing the string to an int
func GetEnvValueOrDefaultString ¶
GetEnvValueOrDefaultString returns the ENV string value for the given key or the default one
func IsDirectory ¶
func IsExecutableCmd ¶
IsExecutableCmd is a predicate checking if the given parameter represents an executable file. It returns nil in the positive case. Otherwise, an error is returned.
func IsExistingFile ¶
isExistingFile predicate that sometimes can make the code easier (if we do not are about the error value)
func IsPlainFile ¶
isPlainFile is a predicate returning true if the supplied argument is an existing, plain file (no directory, device-file,...)
func LoadPrivateKey ¶
func LoadPrivateKey(filename string) (*rsa.PrivateKey, error)
LoadPrivateKey load a PEM-encoded RSA private key from a file
func LoadRsaPublicKey ¶
LoadPublicKey load a PEM-encoded RSA public key from a file
func LogErr ¶
func LogErr(msg string)
LogErr creates a message preprended with ERROR to syslog and stderr, but tries to continue execution.
func LogStringInit ¶
func LogStringInit(tag string)
LogStringInit does not use syslog (for dockerised environments. Instead, it writes all messages to stderr) This is suited for dockerised environments.
func LogWarn ¶
func LogWarn(msg string)
LogWarn creates a syslog and STDERR message labeled with WARNING.
func Pem2RsaPrivateKey ¶
func Pem2RsaPrivateKey(der []byte) (*rsa.PrivateKey, error)
Pem2RsaPrivateKey load a PEM-encoded RSA private key from a buffer. The function does not try to read multiple keys from the byte array. Only the first PEM block is processed.
func Pem2RsaPublicKey ¶
Pem2RsaPublicKey load a PEM-encoded RSA public key from a buffer. The function does not try to read multiple keys from the byte array. Only the first PEM block is processed.
func PsqlGetUser ¶
PsqlGetUser returns the user name from a postgresql connection string.
func PsqlListTablesInCurrentDatabase ¶
PsqlListTablesInCurrentDatabase delivers all existing tables in the current database
func PsqlVerifyTablePermissions ¶
func PsqlVerifyTablePermissions(dbPool *pgxpool.Pool, user string, perms PsqlTablePermission, tables ...string) error
/ foreach export function PsqlVerifyTablePermissions @Summary check for existence of table and permissions for the specified DB user @Description PostgreSQL-specific code @Produce error | nil @Success nil "no error ⤳ tables existing in the database, user existing, user has required permissions" @Failure error "USAGE_ERROR: wrong arguments to function" @Failure error "DBMS_ERROR: DBMS returned an error" @Failure error "TABLE_ERROR: permissions not existing for a table"
func RsaPrivateKey2Sha256Digest ¶
func RsaPrivateKey2Sha256Digest(prvKey *rsa.PrivateKey) (string, error)
func Sign115ByteArray ¶
func Sign115ByteArray(key *rsa.PrivateKey, digest []byte) ([]byte, error)
Sign115ByteArray returns a signature for the given digest or returns an error
func Sign115ByteArray2Base64 ¶
func Sign115ByteArray2Base64(key *rsa.PrivateKey, digest []byte) (string, error)
Sign115ByteArray2Base64 signs a byte array by calling SignByteArray but returns the signature as a base64-encoded string.
func SignPSSByteArray ¶
func SignPSSByteArray(key *rsa.PrivateKey, digest []byte) ([]byte, error)
SignPSSByteArray returns a signature for the given digest or returns an error
func SignPSSByteArray2Base64 ¶
func SignPSSByteArray2Base64(key *rsa.PrivateKey, digest []byte) (string, error)
SignPSSByteArray2Base64 returns the signature as a base64-encoded string.
func Str2sha256 ¶
func String2md5 ¶
func ValidIPv4Address ¶
func Verify115Base64String ¶
Verify115Base64String accepts a base64 encoded string as the signature. It decodes the signature and calls VerifyByteArray.
func Verify115ByteArray ¶
Verify115ByteArray verifies a digital signature (digest). If no error is returned, then the verification was successful. Furthermore, it recalculates the digest of the message. It should result in the same digest as the digitally signed one.
func VerifyPSSBase64String ¶
VerifyPSSBase64String accepts a base64 encoded string as the signature. It decodes the signature and calls VerifyByteArray.
func VerifyPSSByteArray ¶
VerifyPSSByteArray verifies a digital signature (digest). If no error is returned, then the verification was successful. Furthermore, it recalculates the digest of the message. It should result in the same digest as the digitally signed one.
func WriteRsaPrivateKey ¶
func WriteRsaPrivateKey(file *os.File, privKey *rsa.PrivateKey) error
WriteRsaPrivateKey converts the key to PEM format and writes them to a file.
Types ¶
type DestinationFormat ¶
type DestinationFormat int
const ( FormatText DestinationFormat = iota FormatJSON FormatPrettyJson )
type PsqlTablePermission ¶
type PsqlTablePermission string
const ( SELECT PsqlTablePermission = "r" INSERT PsqlTablePermission = "a" UPDATE PsqlTablePermission = "w" DELETE PsqlTablePermission = "d" TRUNCATE PsqlTablePermission = "D" TRIGGER PsqlTablePermission = "t" REFERENCES PsqlTablePermission = "x" ALL_PERMS PsqlTablePermission = "arwdDxt" )