-
Notifications
You must be signed in to change notification settings - Fork 187
/
openssl.go
46 lines (36 loc) · 873 Bytes
/
openssl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//go:build e2e
// +build e2e
package openssl
import (
"fmt"
"os"
"os/exec"
"strings"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
// ParsePKCS12 parses PKCS#12 pfx data and returns pem with private key
// and certificate
func ParsePKCS12(pfxData, password string) (string, error) {
tmpFile, err := os.CreateTemp("", "")
Expect(err).To(BeNil())
_, err = tmpFile.Write([]byte(pfxData))
Expect(err).To(BeNil())
defer os.Remove(tmpFile.Name())
args := append([]string{
"pkcs12",
"-nodes",
"-passin",
fmt.Sprintf("pass:%s", password),
"-in",
tmpFile.Name(),
})
out, err := openssl(args)
return out, err
}
func openssl(args []string) (string, error) {
By(fmt.Sprintf("openssl %s", strings.Join(args, " ")))
cmd := exec.Command("openssl", args...)
stdoutStderr, err := cmd.CombinedOutput()
return string(stdoutStderr), err
}