Documentation ¶
Overview ¶
Copyright 2023 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 IBM Corp. Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Variables
- func CreateCert(csrPath, caCertPath, caKeyPath string, expiryDays int) (string, error)
- func CreateSigningCert(privateKey, cacert, cakey, csrData, csrPemData string, expiryDays int) (string, error)
- func CreateTempFile(data string) (string, error)
- func CryptoDecryptBasic(privKey []byte) func(string) E.Either[error, []byte]
- func CryptoEncryptBasic(cert []byte) func([]byte) E.Either[error, string]
- func CryptoPrivateKey() E.Either[error, []byte]
- func CryptoRandomPassword(count int) func() E.Either[error, []byte]
- func CryptoSignDigest(privKey []byte) func([]byte) E.Either[error, []byte]
- func CryptoSymmetricDecrypt(srcText string) func([]byte) E.Either[error, []byte]
- func CryptoSymmetricEncrypt(srcPlainBytes []byte) func([]byte) E.Either[error, string]
- func DecryptBasic(asymmDecrypt func(string) E.Either[error, []byte], ...) func(string) E.Either[error, []byte]
- func EncodeToBase64(input string) string
- func EncryptBasic(genPwd func() E.Either[error, []byte], ...) func([]byte) E.Either[error, string]
- func EncryptContract(password string, section map[string]interface{}) (string, error)
- func EncryptFinalStr(encryptedPassword, encryptedContract string) string
- func EncryptPassword(password, cert string) (string, error)
- func GenFinalSignedContract(workload, env, workloadEnvSig string) (string, error)
- func KeyValueInjector(contract map[string]interface{}, key, value string) (string, error)
- func MapToYaml(m map[string]interface{}) (string, error)
- func OpenSSL(args ...string) func([]byte) E.Either[error, common.CommandOutput]
- func OpenSSLDecryptBasic(privKey []byte) func(string) E.Either[error, []byte]
- func OpenSSLEncryptBasic(cert []byte) func([]byte) E.Either[error, string]
- func OpenSSLPrivateKey() E.Either[error, []byte]
- func OpenSSLRandomPassword(count int) func() E.Either[error, []byte]
- func OpenSSLSymmetricDecrypt(token string) func([]byte) E.Either[error, []byte]
- func OpenSSLVerifyDigest(pubKey []byte) func([]byte) func([]byte) O.Option[error]
- func OpensslCheck() error
- func RandomPasswordGenerator() (string, error)
- func SignContract(encryptedWorkload, encryptedEnv, privateKey string) (string, error)
- func SignatureTest(privateKey func() E.Either[error, []byte], ...) func(t *testing.T)
- func SimpleExecCommand(name string, stdinInput string, args ...string) (string, error)
- type Decryption
- type Encryption
- type OpenSSLVersion
- type SplitToken
Constants ¶
This section is empty.
Variables ¶
var ( // PrivToRsaKey decodes a pkcs file into a private key PrivToRsaKey = F.Flow2( pemDecodeE, E.Chain(parsePrivateKeyE), ) // CryptoCertFingerprint computes the fingerprint of a certificate using the crypto library CryptoCertFingerprint = F.Flow5( pemDecodeE, E.Chain(parseCertificateE), E.Map[error](rawFromCertificate), E.Map[error](sha256.Sum256), E.Map[error](shaToBytes), ) // CryptoPrivKeyFingerprint computes the fingerprint of a private key using the crypto library CryptoPrivKeyFingerprint = F.Flow7( pemDecodeE, E.Chain(parsePrivateKeyE), E.Map[error](privToPub), E.Map[error](pubToAny), E.Chain(marshalPKIXPublicKeyE), E.Map[error](sha256.Sum256), E.Map[error](shaToBytes), ) // CryptoVerifyDigest verifies the signature of the input data against a signature CryptoVerifyDigest = F.Flow2( pubToRsaKey, E.Fold(errorValidator, verifyPKCS1v15), ) // CryptoPublicKey extracts the public key from a private key CryptoPublicKey = F.Flow6( pemDecodeE, E.Chain(parsePrivateKeyE), E.Map[error](privToPub), E.Map[error](pubToAny), E.Chain(marshalPKIXPublicKeyE), E.Map[error](func(data []byte) []byte { return pem.EncodeToMemory( &pem.Block{ Type: "PUBLIC KEY", Bytes: data, }, ) }), ) )
var ( // name of the environment variable carrying the openSSL binary KeyEnvOpenSSL = "OPENSSL_BIN" // OpenSSLSignDigest signs the sha256 digest using a private key OpenSSLSignDigest = handle(signDigest) OpenSSLAsymmetricEncryptPub = handle(asymmetricEncryptPub) OpenSSLAsymmetricEncryptCert = handle(asymmetricEncryptCert) OpenSSLAsymmetricDecrypt = handle(asymmetricDecrypt) OpenSSLSymmetricEncrypt = handle(symmetricEncrypt) // OpenSSLPublicKey gets the public key from a private key OpenSSLPublicKey = F.Flow2( OpenSSL("rsa", "-pubout"), mapStdout, ) // CertSerial gets the serial number from a certificate CertSerial = F.Flow2( OpenSSL("x509", "-serial", "-noout"), mapStdout, ) // OpenSSLCertFingerprint gets the fingerprint of a certificate OpenSSLCertFingerprint = F.Flow4( OpenSSL("x509", "--outform", "DER"), mapStdout, E.Chain(OpenSSL("sha256", "--binary")), mapStdout, ) // gets the fingerprint of the private key OpenSSLPrivKeyFingerprint = F.Flow4( OpenSSL("rsa", "-pubout", "-outform", "DER"), mapStdout, E.Chain(OpenSSL("sha256", "--binary")), mapStdout, ) )
var CryptoAsymmetricDecrypt = cryptoAsymmetricDecrypt(PrivToRsaKey)
CryptoAsymmetricDecrypt decrypts a piece of text using a private key
var CryptoAsymmetricEncryptCert = cryptoAsymmetricEncrypt(certToRsaKey)
CryptoAsymmetricEncryptCert encrypts a piece of text using a certificate
var CryptoAsymmetricEncryptPub = cryptoAsymmetricEncrypt(pubToRsaKey)
// CryptoAsymmetricEncryptPub encrypts a piece of text using a public key
Functions ¶
func CreateCert ¶ added in v0.5.0
func CreateSigningCert ¶ added in v0.5.0
func CreateSigningCert(privateKey, cacert, cakey, csrData, csrPemData string, expiryDays int) (string, error)
CreateSigningCert - function to generate Signing Certificate
func CreateTempFile ¶ added in v0.5.0
CreateTempFile - Function to create temp file
func CryptoDecryptBasic ¶ added in v0.1.6
OpenSSLDecryptBasic implements basic decryption using golang crypto libraries given the private key
func CryptoEncryptBasic ¶
CryptoEncryptBasic implements basic encryption using golang crypto libraries given the certificate
func CryptoPrivateKey ¶
CryptoPrivateKey generates a private key
func CryptoRandomPassword ¶
CryptoRandomPassword creates a random password of given length using characters from the base64 alphabet only
func CryptoSignDigest ¶
CryptoSignDigest generates a signature across the sha256
func CryptoSymmetricDecrypt ¶ added in v0.1.6
CryptoSymmetricDecrypt encrypts a set of bytes using a password
func CryptoSymmetricEncrypt ¶
CryptoSymmetricEncrypt encrypts a set of bytes using a password
func DecryptBasic ¶
func EncodeToBase64 ¶ added in v0.5.0
EncodeToBase64 - function to encode string as base64
func EncryptBasic ¶
func EncryptBasic( genPwd func() E.Either[error, []byte], asymmEncrypt func([]byte) E.Either[error, string], symmEncrypt func([]byte) func([]byte) E.Either[error, string], ) func([]byte) E.Either[error, string]
EncryptBasic implements the basic encryption operations
func EncryptContract ¶ added in v0.5.0
EncryptContract - function to encrypt contract
func EncryptFinalStr ¶ added in v0.5.0
EncryptFinalStr - function to get final encrypted section
func EncryptPassword ¶ added in v0.5.0
EncryptPassword - function to encrypt password
func GenFinalSignedContract ¶ added in v0.5.0
GenFinalSignedContract - function to generate the final contract
func KeyValueInjector ¶ added in v0.5.0
KeyValueInjector - function to inject key value pair in YAML
func OpenSSLDecryptBasic ¶
OpenSSLDecryptBasic implements basic decryption using openSSL given the private key
func OpenSSLEncryptBasic ¶
OpenSSLEncryptBasic implements basic encryption using openSSL given the certificate
func OpenSSLPrivateKey ¶
OpenSSLPrivateKey generates a private key
func OpenSSLRandomPassword ¶
OpenSSLRandomPassword creates a random password of given length using characters from the base64 alphabet only
func OpenSSLSymmetricDecrypt ¶ added in v0.1.6
func OpenSSLVerifyDigest ¶
OpenSSLVerifyDigest verifies the signature of the input data against a signature
func OpensslCheck ¶ added in v0.5.0
func OpensslCheck() error
OpensslCheck - function to check if openssl exists
func RandomPasswordGenerator ¶ added in v0.5.0
RandomPasswordGenerator - function to generate random password
func SignContract ¶ added in v0.5.0
SignContract - function to sign encrypted contract
func SignatureTest ¶
Types ¶
type Decryption ¶ added in v0.1.6
type Decryption struct { // DecryptBasic implements basic decryption given the private key DecryptBasic func(privKey []byte) func(string) E.Either[error, []byte] }
Decryption captures the crypto functions required to implement the source providers
func DefaultDecryption ¶ added in v0.1.6
func DefaultDecryption() Decryption
// DefaultDecryption detects the decryption environment
type Encryption ¶
type Encryption struct { // EncryptBasic implements basic encryption given the certificate EncryptBasic func([]byte) func([]byte) E.Either[error, string] // CertFingerprint computes the fingerprint of a certificate CertFingerprint func([]byte) E.Either[error, []byte] // PrivKeyFingerprint computes the fingerprint of a private key PrivKeyFingerprint func([]byte) E.Either[error, []byte] // PrivKey computes a new private key PrivKey func() E.Either[error, []byte] // PubKey computes a public key from a private key PubKey func([]byte) E.Either[error, []byte] // SignDigest computes the sha256 signature using a private key SignDigest func([]byte) func([]byte) E.Either[error, []byte] }
Encryption captures the crypto functions required to implement the source providers
func DefaultEncryption ¶
func DefaultEncryption() Encryption
DefaultEncryption detects the encryption environment
type OpenSSLVersion ¶
OpenSSLVersion represents the openSSL version, including the path to the binary