feat: handle key encrypted looking at headers too

This commit is contained in:
2023-04-15 20:42:33 +02:00
parent aa713af153
commit ee967277d4
2 changed files with 122 additions and 26 deletions

View File

@@ -36,7 +36,7 @@ func FromRSAKeyWithPassword(certFile, certKey, passwd string) (credentials.Trans
return nil, errors.New("rest is not empty")
}
if !strings.Contains(keyBlock.Type, "ENCRYPTED") {
if !strings.Contains(keyBlock.Type, "ENCRYPTED") && !isEncryptedOnHeaders(keyBlock.Headers) {
return nil, fmt.Errorf("certificate should has been encrypted with password")
}
@@ -57,6 +57,19 @@ func FromRSAKeyWithPassword(certFile, certKey, passwd string) (credentials.Trans
return credentials.NewServerTLSFromCert(&cert), nil
}
func isEncryptedOnHeaders(headers map[string]string) bool {
if len(headers) == 0 {
return false
}
for _, v := range headers {
if !strings.Contains(v, "ENCRYPTED") {
return true
}
}
return false
}
func decryptRSA(keyFile, password string) (string, error) {
cmd := exec.Command("openssl", "rsa", "-in", keyFile, "-passin", formatPass(password), "-text")
output_bts, err := cmd.Output()