Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Masterminds/sprig
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.1.0
Choose a base ref
...
head repository: Masterminds/sprig
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.2.0
Choose a head ref

Commits on Nov 3, 2019

  1. Refactoring

    kochurovro committed Nov 3, 2019
    Copy the full SHA
    8044caa View commit details
  2. Copy the full SHA
    1530b0f View commit details

Commits on Nov 6, 2019

  1. Function added

    Added description of randInt function
    anotherpopoua authored Nov 6, 2019
    Copy the full SHA
    dabaee5 View commit details
  2. Merge pull request #1 from anotherpopoua/master

    Function added
    kochurovro authored Nov 6, 2019
    Copy the full SHA
    7011e89 View commit details

Commits on Nov 7, 2019

  1. rand.Seed was added

    kochurovro committed Nov 7, 2019
    Copy the full SHA
    73d60f5 View commit details

Commits on Nov 8, 2019

  1. Copy the full SHA
    ba2545c View commit details

Commits on Jan 4, 2020

  1. Copy the full SHA
    c28666b View commit details

Commits on Apr 23, 2020

  1. add a bcrypt function

    robbiet480 committed Apr 23, 2020
    Copy the full SHA
    c0f6270 View commit details

Commits on May 25, 2020

  1. Fix htmlDateInZone example

    spawnia authored May 25, 2020
    Copy the full SHA
    5fbe6e4 View commit details

Commits on May 26, 2020

  1. Merge pull request #249 from spawnia/patch-1

    Fix htmlDateInZone example
    mattfarina authored May 26, 2020
    Copy the full SHA
    4241ae8 View commit details

Commits on Jun 30, 2020

  1. Add dig for dicts

    Adds a pipeline-compatible `dig` function - traverses a list of keys to
    return a value, or a default if no value provided.
    
    Future work, if required: allow `dig` to walk into lists with numeric
    indexes.
    
    Closes #227
    nyarly committed Jun 30, 2020
    Copy the full SHA
    c8449d4 View commit details
  2. Documenting dig

    nyarly committed Jun 30, 2020
    Copy the full SHA
    4bb6f1c View commit details

Commits on Aug 4, 2020

  1. Add support for regex.QuoteMeta string conversion

    Rachel Heaton committed Aug 4, 2020
    Copy the full SHA
    464a584 View commit details

Commits on Aug 5, 2020

  1. Add regexQuoteMeta to function map

    Rachel Heaton committed Aug 5, 2020
    Copy the full SHA
    1c12b85 View commit details

Commits on Oct 14, 2020

  1. Copy the full SHA
    b23121c View commit details

Commits on Nov 30, 2020

  1. Add network.md to index.md (#240)

    The network.md documentation was added in
    ac14fb2
    but was never added to index.md.
    kristinnardal2 authored Nov 30, 2020
    Copy the full SHA
    27bd2d6 View commit details
  2. Copy the full SHA
    0a555ee View commit details
  3. Add randBytes

    Adds the randBytes function to cryptographically generate a
    base64-encoded string of random bytes of a given length.
    
    Resolves #252.
    MikaelSmith committed Nov 30, 2020
    Copy the full SHA
    f0c2324 View commit details

Commits on Dec 2, 2020

  1. Copy the full SHA
    26b8e63 View commit details
  2. Copy the full SHA
    4d8ae00 View commit details
  3. Update docs/math.md

    Co-authored-by: Daniel <daniel.hoherd@gmail.com>
    mattfarina and danielhoherd authored Dec 2, 2020
    Copy the full SHA
    771d021 View commit details
  4. Copy the full SHA
    74297d0 View commit details
  5. Fixing bad merge conflict resolution

    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina authored Dec 2, 2020
    Copy the full SHA
    44a11a1 View commit details
  6. Merge pull request #211 from kochurovro/add--randInt

    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina authored Dec 2, 2020
    Copy the full SHA
    ce41f42 View commit details
  7. Merge pull request #223 from mholt/master

    Add fromJson and mustFromJson funcs
    mattfarina authored Dec 2, 2020
    Copy the full SHA
    1bbf15f View commit details
  8. Merge pull request #242 from robbiet480/bcrypt

    Add a bcrypt function
    mattfarina authored Dec 2, 2020
    Copy the full SHA
    ed89b5b View commit details
  9. Merge pull request #253 from MikaelSmith/randBytes

    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina authored Dec 2, 2020
    Copy the full SHA
    0111002 View commit details
  10. Copy the full SHA
    66c1bf4 View commit details
  11. Copy the full SHA
    eaeb5ac View commit details
  12. Merge pull request #254 from nyarly/dig-into-dict

    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina authored Dec 2, 2020
    Copy the full SHA
    ef25c39 View commit details
  13. Merge pull request #257 from rheaton/master

    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina authored Dec 2, 2020
    Copy the full SHA
    37818c4 View commit details

Commits on Dec 3, 2020

  1. Copy the full SHA
    a60fe27 View commit details
  2. support non-RSA keys when _parsing_ certificates

    Malte Isberner committed Dec 3, 2020
    Copy the full SHA
    f06c8f7 View commit details
  3. wip

    Malte Isberner committed Dec 3, 2020
    Copy the full SHA
    441c154 View commit details
  4. Merge pull request #261 from zugl/master

    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina authored Dec 3, 2020
    Copy the full SHA
    18b20c1 View commit details
  5. Merge pull request #268 from phuslu/allany

    add all/any for evaluating multiple conditions
    mattfarina authored Dec 3, 2020
    Copy the full SHA
    a81d0aa View commit details

Commits on Dec 4, 2020

  1. Add chunk function to split array into smaller

    Karel Bilek committed Dec 4, 2020
    Copy the full SHA
    e3ce235 View commit details
  2. Copy the full SHA
    8c1c917 View commit details

Commits on Dec 6, 2020

  1. wip

    Malte Isberner committed Dec 6, 2020
    Copy the full SHA
    a02fca0 View commit details
  2. add unit tests

    Malte Isberner committed Dec 6, 2020
    Copy the full SHA
    2c7065f View commit details
  3. rename internal

    Malte Isberner committed Dec 6, 2020
    Copy the full SHA
    4d85df5 View commit details
  4. Copy the full SHA
    0209fbb View commit details
  5. remove ed25519

    Malte Isberner committed Dec 6, 2020
    Copy the full SHA
    ac19f30 View commit details

Commits on Dec 7, 2020

  1. Merge pull request #181 from andrewmostello/master

    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina authored Dec 7, 2020
    Copy the full SHA
    be8a535 View commit details

Commits on Dec 10, 2020

  1. Merge pull request #265 from karelbilek/master

    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina authored Dec 10, 2020
    Copy the full SHA
    364146e View commit details

Commits on Dec 11, 2020

  1. Merge pull request #270 from misberner/mi/non-rsa-private-keys

    Extend certificate functions to handle non-RSA keys + add support for ed25519 keys
    mattfarina authored Dec 11, 2020
    Copy the full SHA
    39e4d5d View commit details
  2. Copy the full SHA
    cbe818b View commit details
  3. Merge pull request #272 from mattfarina/bump-versions

    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina authored Dec 11, 2020
    Copy the full SHA
    868e751 View commit details
  4. Updating mergo to 0.3.11

    mergo had made a breaking change in 0.3.9. This was undone in 0.3.10
    with a new path forward for internal reworking via a new implementation.
    0.3.10 and 0.3.11 no longer break sprig functionality. This is tested.
    More information at https://github.com/imdario/mergo/releases/tag/v0.3.10
    mattfarina committed Dec 11, 2020
    Copy the full SHA
    98a0e53 View commit details
  5. Merge pull request #273 from mattfarina/update-mergo.11

    Updating mergo to 0.3.11
    mattfarina authored Dec 11, 2020
    Copy the full SHA
    8b073ef View commit details
Showing with 1,193 additions and 97 deletions.
  1. +1 −1 .github/workflows/test.yaml
  2. +30 −0 CHANGELOG.md
  3. +184 −40 crypto.go
  4. +126 −6 crypto_test.go
  5. +41 −0 defaults.go
  6. +57 −0 defaults_test.go
  7. +26 −0 dict.go
  8. +15 −0 dict_test.go
  9. +93 −3 docs/crypto.md
  10. +1 −1 docs/date.md
  11. +45 −0 docs/defaults.md
  12. +34 −0 docs/dicts.md
  13. +6 −5 docs/index.md
  14. +10 −0 docs/lists.md
  15. +9 −4 docs/math.md
  16. +85 −0 docs/mathf.md
  17. +81 −10 docs/paths.md
  18. +1 −1 docs/reflection.md
  19. +11 −0 docs/strings.md
  20. +44 −1 functions.go
  21. +28 −0 functions_linux_test.go
  22. +8 −2 functions_test.go
  23. +28 −0 functions_windows_test.go
  24. +3 −2 go.mod
  25. +10 −16 go.sum
  26. +45 −0 list.go
  27. +26 −0 list_test.go
  28. +1 −1 network.go
  29. +31 −0 numeric.go
  30. +102 −2 numeric_test.go
  31. +4 −0 regex.go
  32. +5 −0 regex_test.go
  33. +2 −2 strings_test.go
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.12.x, 1.13.x, 1.14.x]
go-version: [1.13.x, 1.14.x, 1.15.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# Changelog

## Release 3.2.0 (2020-12-14)

### Added

- #211: Added randInt function (thanks @kochurovro)
- #223: Added fromJson and mustFromJson functions (thanks @mholt)
- #242: Added a bcrypt function (thanks @robbiet480)
- #253: Added randBytes function (thanks @MikaelSmith)
- #254: Added dig function for dicts (thanks @nyarly)
- #257: Added regexQuoteMeta for quoting regex metadata (thanks @rheaton)
- #261: Added filepath functions osBase, osDir, osExt, osClean, osIsAbs (thanks @zugl)
- #268: Added and and all functions for testing conditions (thanks @phuslu)
- #181: Added float64 arithmetic addf, add1f, subf, divf, mulf, maxf, and minf
(thanks @andrewmostello)
- #265: Added chunk function to split array into smaller arrays (thanks @karelbilek)
- #270: Extend certificate functions to handle non-RSA keys + add support for
ed25519 keys (thanks @misberner)

### Changed

- Removed testing and support for Go 1.12. ed25519 support requires Go 1.13 or newer
- Using semver 3.1.1 and mergo 0.3.11

### Fixed

- #249: Fix htmlDateInZone example (thanks @spawnia)

NOTE: The dependency github.com/imdario/mergo reverted the breaking change in
0.3.9 via 0.3.10 release.

## Release 3.1.0 (2020-04-16)

NOTE: The dependency github.com/imdario/mergo made a behavior change in 0.3.9
224 changes: 184 additions & 40 deletions crypto.go
Original file line number Diff line number Diff line change
@@ -2,10 +2,12 @@ package sprig

import (
"bytes"
"crypto"
"crypto/aes"
"crypto/cipher"
"crypto/dsa"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/elliptic"
"crypto/hmac"
"crypto/rand"
@@ -30,7 +32,7 @@ import (
"strings"

"github.com/google/uuid"
"golang.org/x/crypto/bcrypt"
bcrypt_lib "golang.org/x/crypto/bcrypt"
"golang.org/x/crypto/scrypt"
)

@@ -49,15 +51,28 @@ func adler32sum(input string) string {
return fmt.Sprintf("%d", hash)
}

func bcrypt(input string) string {
hash, err := bcrypt_lib.GenerateFromPassword([]byte(input), bcrypt_lib.DefaultCost)
if err != nil {
return fmt.Sprintf("failed to encrypt string with bcrypt: %s", err)
}

return string(hash)
}

func htpasswd(username string, password string) string {
if strings.Contains(username, ":") {
return fmt.Sprintf("invalid username: %s", username)
}
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
if err != nil {
return fmt.Sprintf("failed to create htpasswd: %s", err)
return fmt.Sprintf("%s:%s", username, bcrypt(password))
}

func randBytes(count int) (string, error) {
buf := make([]byte, count)
if _, err := rand.Read(buf); err != nil {
return "", err
}
return fmt.Sprintf("%s:%s", username, hash)
return base64.StdEncoding.EncodeToString(buf), nil
}

// uuidv4 provides a safe and secure UUID v4 implementation
@@ -147,6 +162,8 @@ func generatePrivateKey(typ string) string {
case "ecdsa":
// again, good enough for government work
priv, err = ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
case "ed25519":
_, priv, err = ed25519.GenerateKey(rand.Reader)
default:
return "Unknown type " + typ
}
@@ -179,7 +196,73 @@ func pemBlockForKey(priv interface{}) *pem.Block {
b, _ := x509.MarshalECPrivateKey(k)
return &pem.Block{Type: "EC PRIVATE KEY", Bytes: b}
default:
return nil
// attempt PKCS#8 format for all other keys
b, err := x509.MarshalPKCS8PrivateKey(k)
if err != nil {
return nil
}
return &pem.Block{Type: "PRIVATE KEY", Bytes: b}
}
}

func parsePrivateKeyPEM(pemBlock string) (crypto.PrivateKey, error) {
block, _ := pem.Decode([]byte(pemBlock))
if block == nil {
return nil, errors.New("no PEM data in input")
}

if block.Type == "PRIVATE KEY" {
priv, err := x509.ParsePKCS8PrivateKey(block.Bytes)
if err != nil {
return nil, fmt.Errorf("decoding PEM as PKCS#8: %s", err)
}
return priv, nil
} else if !strings.HasSuffix(block.Type, " PRIVATE KEY") {
return nil, fmt.Errorf("no private key data in PEM block of type %s", block.Type)
}

switch block.Type[:len(block.Type)-12] { // strip " PRIVATE KEY"
case "RSA":
priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
return nil, fmt.Errorf("parsing RSA private key from PEM: %s", err)
}
return priv, nil
case "EC":
priv, err := x509.ParseECPrivateKey(block.Bytes)
if err != nil {
return nil, fmt.Errorf("parsing EC private key from PEM: %s", err)
}
return priv, nil
case "DSA":
var k DSAKeyFormat
_, err := asn1.Unmarshal(block.Bytes, &k)
if err != nil {
return nil, fmt.Errorf("parsing DSA private key from PEM: %s", err)
}
priv := &dsa.PrivateKey{
PublicKey: dsa.PublicKey{
Parameters: dsa.Parameters{
P: k.P, Q: k.Q, G: k.G,
},
Y: k.Y,
},
X: k.X,
}
return priv, nil
default:
return nil, fmt.Errorf("invalid private key type %s", block.Type)
}
}

func getPublicKey(priv crypto.PrivateKey) (crypto.PublicKey, error) {
switch k := priv.(type) {
case interface{ Public() crypto.PublicKey }:
return k.Public(), nil
case *dsa.PrivateKey:
return &k.PublicKey, nil
default:
return nil, fmt.Errorf("unable to get public key for type %T", priv)
}
}

@@ -213,14 +296,10 @@ func buildCustomCertificate(b64cert string, b64key string) (certificate, error)
)
}

decodedKey, _ := pem.Decode(key)
if decodedKey == nil {
return crt, errors.New("unable to decode key")
}
_, err = x509.ParsePKCS1PrivateKey(decodedKey.Bytes)
_, err = parsePrivateKeyPEM(string(key))
if err != nil {
return crt, fmt.Errorf(
"error parsing prive key: decodedKey.Bytes: %s",
"error parsing private key: %s",
err,
)
}
@@ -234,6 +313,31 @@ func buildCustomCertificate(b64cert string, b64key string) (certificate, error)
func generateCertificateAuthority(
cn string,
daysValid int,
) (certificate, error) {
priv, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
return certificate{}, fmt.Errorf("error generating rsa key: %s", err)
}

return generateCertificateAuthorityWithKeyInternal(cn, daysValid, priv)
}

func generateCertificateAuthorityWithPEMKey(
cn string,
daysValid int,
privPEM string,
) (certificate, error) {
priv, err := parsePrivateKeyPEM(privPEM)
if err != nil {
return certificate{}, fmt.Errorf("parsing private key: %s", err)
}
return generateCertificateAuthorityWithKeyInternal(cn, daysValid, priv)
}

func generateCertificateAuthorityWithKeyInternal(
cn string,
daysValid int,
priv crypto.PrivateKey,
) (certificate, error) {
ca := certificate{}

@@ -247,11 +351,6 @@ func generateCertificateAuthority(
x509.KeyUsageCertSign
template.IsCA = true

priv, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
return ca, fmt.Errorf("error generating rsa key: %s", err)
}

ca.Cert, ca.Key, err = getCertAndKey(template, priv, template, priv)

return ca, err
@@ -263,16 +362,39 @@ func generateSelfSignedCertificate(
alternateDNS []interface{},
daysValid int,
) (certificate, error) {
cert := certificate{}
priv, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
return certificate{}, fmt.Errorf("error generating rsa key: %s", err)
}
return generateSelfSignedCertificateWithKeyInternal(cn, ips, alternateDNS, daysValid, priv)
}

template, err := getBaseCertTemplate(cn, ips, alternateDNS, daysValid)
func generateSelfSignedCertificateWithPEMKey(
cn string,
ips []interface{},
alternateDNS []interface{},
daysValid int,
privPEM string,
) (certificate, error) {
priv, err := parsePrivateKeyPEM(privPEM)
if err != nil {
return cert, err
return certificate{}, fmt.Errorf("parsing private key: %s", err)
}
return generateSelfSignedCertificateWithKeyInternal(cn, ips, alternateDNS, daysValid, priv)
}

priv, err := rsa.GenerateKey(rand.Reader, 2048)
func generateSelfSignedCertificateWithKeyInternal(
cn string,
ips []interface{},
alternateDNS []interface{},
daysValid int,
priv crypto.PrivateKey,
) (certificate, error) {
cert := certificate{}

template, err := getBaseCertTemplate(cn, ips, alternateDNS, daysValid)
if err != nil {
return cert, fmt.Errorf("error generating rsa key: %s", err)
return cert, err
}

cert.Cert, cert.Key, err = getCertAndKey(template, priv, template, priv)
@@ -286,6 +408,36 @@ func generateSignedCertificate(
alternateDNS []interface{},
daysValid int,
ca certificate,
) (certificate, error) {
priv, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
return certificate{}, fmt.Errorf("error generating rsa key: %s", err)
}
return generateSignedCertificateWithKeyInternal(cn, ips, alternateDNS, daysValid, ca, priv)
}

func generateSignedCertificateWithPEMKey(
cn string,
ips []interface{},
alternateDNS []interface{},
daysValid int,
ca certificate,
privPEM string,
) (certificate, error) {
priv, err := parsePrivateKeyPEM(privPEM)
if err != nil {
return certificate{}, fmt.Errorf("parsing private key: %s", err)
}
return generateSignedCertificateWithKeyInternal(cn, ips, alternateDNS, daysValid, ca, priv)
}

func generateSignedCertificateWithKeyInternal(
cn string,
ips []interface{},
alternateDNS []interface{},
daysValid int,
ca certificate,
priv crypto.PrivateKey,
) (certificate, error) {
cert := certificate{}

@@ -300,14 +452,10 @@ func generateSignedCertificate(
err,
)
}
decodedSignerKey, _ := pem.Decode([]byte(ca.Key))
if decodedSignerKey == nil {
return cert, errors.New("unable to decode key")
}
signerKey, err := x509.ParsePKCS1PrivateKey(decodedSignerKey.Bytes)
signerKey, err := parsePrivateKeyPEM(ca.Key)
if err != nil {
return cert, fmt.Errorf(
"error parsing prive key: decodedSignerKey.Bytes: %s",
"error parsing private key: %s",
err,
)
}
@@ -317,11 +465,6 @@ func generateSignedCertificate(
return cert, err
}

priv, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
return cert, fmt.Errorf("error generating rsa key: %s", err)
}

cert.Cert, cert.Key, err = getCertAndKey(
template,
priv,
@@ -334,15 +477,19 @@ func generateSignedCertificate(

func getCertAndKey(
template *x509.Certificate,
signeeKey *rsa.PrivateKey,
signeeKey crypto.PrivateKey,
parent *x509.Certificate,
signingKey *rsa.PrivateKey,
signingKey crypto.PrivateKey,
) (string, string, error) {
signeePubKey, err := getPublicKey(signeeKey)
if err != nil {
return "", "", fmt.Errorf("error retrieving public key from signee key: %s", err)
}
derBytes, err := x509.CreateCertificate(
rand.Reader,
template,
parent,
&signeeKey.PublicKey,
signeePubKey,
signingKey,
)
if err != nil {
@@ -360,10 +507,7 @@ func getCertAndKey(
keyBuffer := bytes.Buffer{}
if err := pem.Encode(
&keyBuffer,
&pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(signeeKey),
},
pemBlockForKey(signeeKey),
); err != nil {
return "", "", fmt.Errorf("error pem-encoding key: %s", err)
}
Loading