Skip to content

Commit

Permalink
CERT-27347 | objectFormat p12 support added
Browse files Browse the repository at this point in the history
  • Loading branch information
Gopal Mariyappan committed Sep 8, 2022
1 parent 965a6b9 commit cb6036d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dev_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ metadata:
spec:
provider: appviewx
parameters:
objectFormat: pem # pem, pfx, jks
objectFormat: pem # pem, pfx, p12, jks
objectEncoding: utf-8 # utf-8, hex, base64
objects: |
- commonName: cert-default-leaf-casetting-default-ca-casetting-default-selfsigned.appviewx.com
Expand Down
9 changes: 6 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func parseParameters(parametersStr string) (Parameters, error) {
err = yaml.Unmarshal([]byte(secretsYaml), &m1)
if err != nil {
fmt.Println("Error in Unmarshalling Yaml to map : ", err)
return Parameters{}, fmt.Errorf("Error in parseParameters : Error in Unmarshalling Yaml to map : %w", err)
return Parameters{},
fmt.Errorf("Error in parseParameters : Error in Unmarshalling Yaml to map : %w", err)
}

c, err := json.Marshal(m1)
Expand Down Expand Up @@ -132,11 +133,13 @@ func (c *Config) validate() error {
c.Parameters.ObjectFormat = util.OBJECT_FORMAT_PEM
} else if strings.ToLower(c.Parameters.ObjectFormat) != util.OBJECT_FORMAT_PEM &&
strings.ToLower(c.Parameters.ObjectFormat) != util.OBJECT_FORMAT_PFX &&
strings.ToLower(c.Parameters.ObjectFormat) != util.OBJECT_FORMAT_P12 &&
strings.ToLower(c.Parameters.ObjectFormat) != util.OBJECT_FORMAT_JKS {

return fmt.Errorf("%s : is not a valid ObjectFormat only %s,%s,%s are supported",
return fmt.Errorf("%s : is not a valid ObjectFormat only %s,%s,%s,%s are supported",
c.Parameters.ObjectFormat,
util.OBJECT_FORMAT_PEM, util.OBJECT_FORMAT_PFX, util.OBJECT_FORMAT_JKS)
util.OBJECT_FORMAT_PEM, util.OBJECT_FORMAT_PFX,
util.OBJECT_FORMAT_P12, util.OBJECT_FORMAT_JKS)
}

if len(c.Parameters.ObjectEncoding) == 0 {
Expand Down
21 changes: 21 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,27 @@ func getMountFilesAndObjectVersions(
files, objectVersions = appendToFilesAndObjectVersions(cfg.FilePermission, []byte(password), "password", files, objectVersions)
}

return

case util.OBJECT_FORMAT_P12:
l.Info("objectFormat p12")

for _, currentSecretContent := range secretContents {
pfxContent, password, err := format.GetPfxContentForSecret(currentSecretContent, l)
if err != nil {
l.Error(fmt.Sprintf("Error in getMountFilesAndObjectVersions while format.GetPfxContentForSecret : %v", err))
return nil, nil, fmt.Errorf("error in getMountFilesAndObjectVersions while format.GetPfxContentForSecret : %w", err)
}
encodedContent, err := util.Encode(pfxContent, encodingFormat, l)
if err != nil {
l.Error(fmt.Sprintf("Error in getMountFilesAndObjectVersions while util.Encode : %v", err))
return nil, nil, fmt.Errorf("error in getMountFilesAndObjectVersions while util.Encode : %w", err)
}

files, objectVersions = appendToFilesAndObjectVersions(cfg.FilePermission, encodedContent, "tls.p12", files, objectVersions)
files, objectVersions = appendToFilesAndObjectVersions(cfg.FilePermission, []byte(password), "password", files, objectVersions)
}

return
case util.OBJECT_FORMAT_JKS:
l.Info("objectFormat jks")
Expand Down
1 change: 1 addition & 0 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
const (
OBJECT_FORMAT_PEM = "pem"
OBJECT_FORMAT_PFX = "pfx"
OBJECT_FORMAT_P12 = "p12"
OBJECT_FORMAT_JKS = "jks"

OBJECT_ENCODING_UTF_8 = "utf-8"
Expand Down

0 comments on commit cb6036d

Please sign in to comment.