func parsePemBlock()

in internal/loader/configuration_setting_loader.go [834:866]


func parsePemBlock(pemBlock []*pem.Block) ([]byte, []byte, error) {
	// PEM block encoded form contains the headers
	//    -----BEGIN Type-----
	//    Headers
	//    base64-encoded Bytes
	//    -----END Type-----
	// Setting headers to nil to ensure no headers included in the encoded block
	var pemKeyData, pemCertData []byte
	for _, block := range pemBlock {

		block.Headers = make(map[string]string)
		if block.Type == "CERTIFICATE" {
			pemCertData = append(pemCertData, pem.EncodeToMemory(block)...)
		} else {
			key, err := parsePrivateKey(block.Bytes)
			if err != nil {
				return nil, nil, err
			}
			// pkcs1 RSA private key PEM file is specific for RSA keys. RSA is not used exclusively inside X509
			// and SSL/TLS, a more generic key format is available in the form of PKCS#8 that identifies the type
			// of private key and contains the relevant data.
			// Converting to pkcs8 private key as ToPEM uses pkcs1
			// The driver determines the key type from the pkcs8 form of the key and marshals appropriately
			block.Bytes, err = x509.MarshalPKCS8PrivateKey(key)
			if err != nil {
				return nil, nil, err
			}
			pemKeyData = append(pemKeyData, pem.EncodeToMemory(block)...)
		}
	}

	return pemKeyData, pemCertData, nil
}