diff --git a/internal/notifier/factory.go b/internal/notifier/factory.go index ce66a64ac..e07a344f7 100644 --- a/internal/notifier/factory.go +++ b/internal/notifier/factory.go @@ -82,7 +82,7 @@ func (f Factory) Notifier(provider string) (Interface, error) { case v1beta1.LarkProvider: n, err = NewLark(f.URL) case v1beta1.Matrix: - n, err = NewMatrix(f.URL, f.Token, f.Channel) + n, err = NewMatrix(f.URL, f.Token, f.Channel, f.CertPool) case v1beta1.OpsgenieProvider: n, err = NewOpsgenie(f.URL, f.ProxyURL, f.CertPool, f.Token) case v1beta1.AlertManagerProvider: diff --git a/internal/notifier/matrix.go b/internal/notifier/matrix.go index 8eb0da24c..d68ad7079 100644 --- a/internal/notifier/matrix.go +++ b/internal/notifier/matrix.go @@ -2,6 +2,7 @@ package notifier import ( "crypto/sha1" + "crypto/x509" "encoding/json" "fmt" "net/http" @@ -13,9 +14,10 @@ import ( ) type Matrix struct { - Token string - URL string - RoomId string + Token string + URL string + RoomId string + CertPool *x509.CertPool } type MatrixPayload struct { @@ -23,16 +25,17 @@ type MatrixPayload struct { MsgType string `json:"msgtype"` } -func NewMatrix(serverURL, token, roomId string) (*Matrix, error) { +func NewMatrix(serverURL, token, roomId string, certPool *x509.CertPool) (*Matrix, error) { _, err := url.ParseRequestURI(serverURL) if err != nil { return nil, fmt.Errorf("invalid Matrix homeserver URL %s", serverURL) } return &Matrix{ - URL: serverURL, - RoomId: roomId, - Token: token, + URL: serverURL, + RoomId: roomId, + Token: token, + CertPool: certPool, }, nil } @@ -61,7 +64,7 @@ func (m *Matrix) Post(event events.Event) error { MsgType: "m.text", } - err = postMessage(fullURL, "", nil, payload, func(request *retryablehttp.Request) { + err = postMessage(fullURL, "", m.CertPool, payload, func(request *retryablehttp.Request) { request.Method = http.MethodPut request.Header.Add("Authorization", "Bearer "+m.Token) }) diff --git a/tests/fuzz/matrix_fuzzer.go b/tests/fuzz/matrix_fuzzer.go index e4a57861c..8e9f1f581 100644 --- a/tests/fuzz/matrix_fuzzer.go +++ b/tests/fuzz/matrix_fuzzer.go @@ -42,7 +42,7 @@ func FuzzMatrix(data []byte) int { return 0 } - matrix, err := NewMatrix(ts.URL, "", token) + matrix, err := NewMatrix(ts.URL, "", token, nil) if err != nil { return 0 }