snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 1s
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 1s
This commit is contained in:
212
server/channels/app/plugin_signature_test.go
Normal file
212
server/channels/app/plugin_signature_test.go
Normal file
@@ -0,0 +1,212 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/storetest/mocks"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils/fileutils"
|
||||
)
|
||||
|
||||
func TestPluginPublicKeys(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
th := SetupWithStoreMock(t)
|
||||
|
||||
mockStore := th.App.Srv().Store().(*mocks.Store)
|
||||
mockUserStore := mocks.UserStore{}
|
||||
mockUserStore.On("Count", mock.Anything).Return(int64(10), nil)
|
||||
mockPostStore := mocks.PostStore{}
|
||||
mockPostStore.On("GetMaxPostSize").Return(model.PostMessageMaxBytesV2, nil)
|
||||
mockSystemStore := mocks.SystemStore{}
|
||||
mockSystemStore.On("GetByName", "UpgradedFromTE").Return(&model.System{Name: "UpgradedFromTE", Value: "false"}, nil)
|
||||
mockSystemStore.On("GetByName", "InstallationDate").Return(&model.System{Name: "InstallationDate", Value: "10"}, nil)
|
||||
mockSystemStore.On("GetByName", "FirstServerRunTimestamp").Return(&model.System{Name: "FirstServerRunTimestamp", Value: "10"}, nil)
|
||||
|
||||
mockStore.On("User").Return(&mockUserStore)
|
||||
mockStore.On("Post").Return(&mockPostStore)
|
||||
mockStore.On("System").Return(&mockSystemStore)
|
||||
mockStore.On("GetDBSchemaVersion").Return(1, nil)
|
||||
|
||||
path, _ := fileutils.FindDir("tests")
|
||||
publicKeyFilename := "test-public-key.plugin.gpg"
|
||||
publicKey, err := os.ReadFile(filepath.Join(path, publicKeyFilename))
|
||||
require.NoError(t, err)
|
||||
fileReader, err := os.Open(filepath.Join(path, publicKeyFilename))
|
||||
require.NoError(t, err)
|
||||
defer fileReader.Close()
|
||||
appErr := th.App.AddPublicKey(publicKeyFilename, fileReader)
|
||||
require.Nil(t, appErr)
|
||||
file, appErr := th.App.GetPublicKey(publicKeyFilename)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, publicKey, file)
|
||||
_, appErr = th.App.GetPublicKey("wrong file name")
|
||||
require.NotNil(t, appErr)
|
||||
_, appErr = th.App.GetPublicKey("wrong-file-name.plugin.gpg")
|
||||
require.NotNil(t, appErr)
|
||||
|
||||
appErr = th.App.DeletePublicKey("wrong file name")
|
||||
require.Nil(t, appErr)
|
||||
appErr = th.App.DeletePublicKey("wrong-file-name.plugin.gpg")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
appErr = th.App.DeletePublicKey(publicKeyFilename)
|
||||
require.Nil(t, appErr)
|
||||
_, appErr = th.App.GetPublicKey(publicKeyFilename)
|
||||
require.NotNil(t, appErr)
|
||||
}
|
||||
|
||||
func TestVerifySignature(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
path, _ := fileutils.FindDir("tests")
|
||||
pluginFilename := "testplugin.tar.gz"
|
||||
signatureFilename := "testplugin.tar.gz.sig"
|
||||
armoredSignatureFilename := "testplugin.tar.gz.asc"
|
||||
publicKeyFilename := "development-public-key.gpg"
|
||||
armoredPublicKeyFilename := "development-public-key.asc"
|
||||
t.Run("verify armored signature and armored public key", func(t *testing.T) {
|
||||
publicKeyFileReader, err := os.Open(filepath.Join(path, armoredPublicKeyFilename))
|
||||
require.NoError(t, err)
|
||||
defer publicKeyFileReader.Close()
|
||||
pluginFileReader, err := os.Open(filepath.Join(path, pluginFilename))
|
||||
require.NoError(t, err)
|
||||
defer pluginFileReader.Close()
|
||||
signatureFileReader, err := os.Open(filepath.Join(path, armoredSignatureFilename))
|
||||
require.NoError(t, err)
|
||||
defer signatureFileReader.Close()
|
||||
require.NoError(t, verifySignature(publicKeyFileReader, pluginFileReader, signatureFileReader))
|
||||
})
|
||||
t.Run("verify non armored signature and armored public key", func(t *testing.T) {
|
||||
publicKeyFileReader, err := os.Open(filepath.Join(path, armoredPublicKeyFilename))
|
||||
require.NoError(t, err)
|
||||
defer publicKeyFileReader.Close()
|
||||
pluginFileReader, err := os.Open(filepath.Join(path, pluginFilename))
|
||||
require.NoError(t, err)
|
||||
defer pluginFileReader.Close()
|
||||
signatureFileReader, err := os.Open(filepath.Join(path, signatureFilename))
|
||||
require.NoError(t, err)
|
||||
defer signatureFileReader.Close()
|
||||
require.NoError(t, verifySignature(publicKeyFileReader, pluginFileReader, signatureFileReader))
|
||||
})
|
||||
t.Run("verify armored signature and non armored public key", func(t *testing.T) {
|
||||
publicKeyFileReader, err := os.Open(filepath.Join(path, publicKeyFilename))
|
||||
require.NoError(t, err)
|
||||
defer publicKeyFileReader.Close()
|
||||
pluginFileReader, err := os.Open(filepath.Join(path, pluginFilename))
|
||||
require.NoError(t, err)
|
||||
defer pluginFileReader.Close()
|
||||
armoredSignatureFileReader, err := os.Open(filepath.Join(path, armoredSignatureFilename))
|
||||
require.NoError(t, err)
|
||||
defer armoredSignatureFileReader.Close()
|
||||
require.NoError(t, verifySignature(publicKeyFileReader, pluginFileReader, armoredSignatureFileReader))
|
||||
})
|
||||
t.Run("verify non armored signature and non armored public key", func(t *testing.T) {
|
||||
publicKeyFileReader, err := os.Open(filepath.Join(path, publicKeyFilename))
|
||||
require.NoError(t, err)
|
||||
defer publicKeyFileReader.Close()
|
||||
pluginFileReader, err := os.Open(filepath.Join(path, pluginFilename))
|
||||
require.NoError(t, err)
|
||||
defer pluginFileReader.Close()
|
||||
signatureFileReader, err := os.Open(filepath.Join(path, signatureFilename))
|
||||
require.NoError(t, err)
|
||||
defer signatureFileReader.Close()
|
||||
require.NoError(t, verifySignature(publicKeyFileReader, pluginFileReader, signatureFileReader))
|
||||
})
|
||||
}
|
||||
|
||||
func TestVerifySignatureMFIPluginPublicKey(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
path, _ := fileutils.FindDir("tests")
|
||||
pluginFilename := "testplugin-mfi.tar.gz"
|
||||
signatureFilename := "testplugin-mfi.tar.gz.sig"
|
||||
armoredSignatureFilename := "testplugin-mfi.tar.gz.asc"
|
||||
|
||||
t.Run("verify armored signature against the MFI public key", func(t *testing.T) {
|
||||
pluginFileReader, err := os.Open(filepath.Join(path, pluginFilename))
|
||||
require.NoError(t, err)
|
||||
defer pluginFileReader.Close()
|
||||
signatureFileReader, err := os.Open(filepath.Join(path, armoredSignatureFilename))
|
||||
require.NoError(t, err)
|
||||
defer signatureFileReader.Close()
|
||||
require.NoError(t, verifySignature(bytes.NewReader(mfiPluginPublicKey), pluginFileReader, signatureFileReader))
|
||||
})
|
||||
|
||||
t.Run("verify non-armored signature against the MFI public key", func(t *testing.T) {
|
||||
pluginFileReader, err := os.Open(filepath.Join(path, pluginFilename))
|
||||
require.NoError(t, err)
|
||||
defer pluginFileReader.Close()
|
||||
signatureFileReader, err := os.Open(filepath.Join(path, signatureFilename))
|
||||
require.NoError(t, err)
|
||||
defer signatureFileReader.Close()
|
||||
require.NoError(t, verifySignature(bytes.NewReader(mfiPluginPublicKey), pluginFileReader, signatureFileReader))
|
||||
})
|
||||
}
|
||||
|
||||
// TestVerifyPluginMFIFeatureFlag covers the feature-flagged path in
|
||||
// verifyPlugin: gating by EnableMFIPluginSignaturePublicKey, reader
|
||||
// rewinding between the hard-coded Mattermost and MFI key attempts, and
|
||||
// falling back to admin-configured keys when the flag is off.
|
||||
func TestVerifyPluginMFIFeatureFlag(t *testing.T) {
|
||||
mainHelper.Parallel(t)
|
||||
path, _ := fileutils.FindDir("tests")
|
||||
logger := mlog.CreateConsoleTestLogger(t)
|
||||
|
||||
openPluginAndSignature := func(t *testing.T, pluginFilename, signatureFilename string) (*os.File, *os.File) {
|
||||
t.Helper()
|
||||
pluginFile, err := os.Open(filepath.Join(path, pluginFilename))
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { pluginFile.Close() })
|
||||
signatureFile, err := os.Open(filepath.Join(path, signatureFilename))
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { signatureFile.Close() })
|
||||
return pluginFile, signatureFile
|
||||
}
|
||||
|
||||
t.Run("verifies against the MFI key when the flag is enabled", func(t *testing.T) {
|
||||
th := SetupConfig(t, func(cfg *model.Config) {
|
||||
cfg.FeatureFlags.EnableMFIPluginSignaturePublicKey = true
|
||||
})
|
||||
|
||||
pluginFile, signatureFile := openPluginAndSignature(t, "testplugin-mfi.tar.gz", "testplugin-mfi.tar.gz.asc")
|
||||
require.Nil(t, th.App.ch.verifyPlugin(logger, pluginFile, signatureFile))
|
||||
})
|
||||
|
||||
t.Run("fails against the MFI key when the flag is disabled and no admin key matches", func(t *testing.T) {
|
||||
th := SetupConfig(t, func(cfg *model.Config) {
|
||||
cfg.FeatureFlags.EnableMFIPluginSignaturePublicKey = false
|
||||
})
|
||||
|
||||
pluginFile, signatureFile := openPluginAndSignature(t, "testplugin-mfi.tar.gz", "testplugin-mfi.tar.gz.asc")
|
||||
require.NotNil(t, th.App.ch.verifyPlugin(logger, pluginFile, signatureFile))
|
||||
})
|
||||
|
||||
t.Run("fails when the flag is enabled but the signature matches neither hard-coded key", func(t *testing.T) {
|
||||
th := SetupConfig(t, func(cfg *model.Config) {
|
||||
cfg.FeatureFlags.EnableMFIPluginSignaturePublicKey = true
|
||||
})
|
||||
|
||||
pluginFile, signatureFile := openPluginAndSignature(t, "testplugin.tar.gz", "testplugin.tar.gz.asc")
|
||||
require.NotNil(t, th.App.ch.verifyPlugin(logger, pluginFile, signatureFile))
|
||||
})
|
||||
|
||||
t.Run("falls back to an admin-configured key when the flag is disabled", func(t *testing.T) {
|
||||
th := SetupConfig(t, func(cfg *model.Config) {
|
||||
cfg.FeatureFlags.EnableMFIPluginSignaturePublicKey = false
|
||||
})
|
||||
|
||||
appErr := th.App.AddPublicKey("mfi-admin-key.asc", bytes.NewReader(mfiPluginPublicKey))
|
||||
require.Nil(t, appErr)
|
||||
|
||||
pluginFile, signatureFile := openPluginAndSignature(t, "testplugin-mfi.tar.gz", "testplugin-mfi.tar.gz.asc")
|
||||
require.Nil(t, th.App.ch.verifyPlugin(logger, pluginFile, signatureFile))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user