Use variables for string replacements on cert_util

This commit is contained in:
Calvin Leung Huang 2017-05-02 14:11:57 -04:00
parent ff4cf41ebb
commit 2b7a66e23b

View file

@ -188,17 +188,20 @@ func fetchCertBySerial(req *logical.Request, prefix, serial string) (*logical.St
var err error var err error
var certEntry *logical.StorageEntry var certEntry *logical.StorageEntry
hyphenSerial := strings.Replace(strings.ToLower(serial), ":", "-", -1)
colonSerial := strings.Replace(strings.ToLower(serial), "-", ":", -1)
switch { switch {
// Revoked goes first as otherwise ca/crl get hardcoded paths which fail if // Revoked goes first as otherwise ca/crl get hardcoded paths which fail if
// we actually want revocation info // we actually want revocation info
case strings.HasPrefix(prefix, "revoked/"): case strings.HasPrefix(prefix, "revoked/"):
path = "revoked/" + strings.Replace(strings.ToLower(serial), ":", "-", -1) path = "revoked/" + hyphenSerial
case serial == "ca": case serial == "ca":
path = "ca" path = "ca"
case serial == "crl": case serial == "crl":
path = "crl" path = "crl"
default: default:
path = "certs/" + strings.Replace(strings.ToLower(serial), ":", "-", -1) path = "certs/" + hyphenSerial
} }
certEntry, err = req.Storage.Get(path) certEntry, err = req.Storage.Get(path)
@ -223,9 +226,9 @@ func fetchCertBySerial(req *logical.Request, prefix, serial string) (*logical.St
// If we get here we need to check for old-style paths using colons // If we get here we need to check for old-style paths using colons
switch { switch {
case strings.HasPrefix(prefix, "revoked/"): case strings.HasPrefix(prefix, "revoked/"):
path = "revoked/" + strings.Replace(strings.ToLower(serial), "-", ":", -1) path = "revoked/" + colonSerial
default: default:
path = "certs/" + strings.Replace(strings.ToLower(serial), "-", ":", -1) path = "certs/" + colonSerial
} }
certEntry, err = req.Storage.Get(path) certEntry, err = req.Storage.Get(path)