feat: handle key encrypted looking at headers too
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user