mirror of
https://github.com/langgenius/dify-plugin-daemon.git
synced 2026-07-23 18:25:36 -04:00
9a1da25d59
* feat: Enhance plugin signing with authorized category verification - Added support for an `authorized_category` flag in the signature command to validate the category before signing. - Updated the `Sign` function to accept a verification parameter, allowing for category-based signing. - Enhanced error handling for invalid categories during the signing process. - Updated tests to cover new verification scenarios and ensure proper functionality with the authorized category. * fix * fix * test * test: Add unit test for plugin verification without verification field - Introduced a new test case to verify the behavior of plugins that lack a verification field. - Updated the signature_test.go file to include the test, ensuring proper functionality of the signing process. - Removed the outdated verifier_test.go file and associated test data to streamline the codebase.
39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
package signer
|
|
|
|
import (
|
|
"github.com/langgenius/dify-plugin-daemon/internal/core/license/private_key"
|
|
"github.com/langgenius/dify-plugin-daemon/internal/utils/encryption"
|
|
"github.com/langgenius/dify-plugin-daemon/pkg/plugin_packager/decoder"
|
|
"github.com/langgenius/dify-plugin-daemon/pkg/plugin_packager/signer/withkey"
|
|
)
|
|
|
|
/*
|
|
DifyPlugin is a file type that represents a plugin, it's designed to based on zip file format.
|
|
When signing a plugin, we use RSA-4096 to create a signature for the plugin and write the signature
|
|
into comment field of the zip file.
|
|
*/
|
|
|
|
// SignPlugin is a function that signs a plugin
|
|
// It takes a plugin as a stream of bytes and signs it with RSA-4096 with a bundled private key
|
|
func SignPlugin(plugin []byte, verification *decoder.Verification) ([]byte, error) {
|
|
// load private key
|
|
privateKey, err := encryption.LoadPrivateKey(private_key.PRIVATE_KEY)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return withkey.SignPluginWithPrivateKey(plugin, verification, privateKey)
|
|
}
|
|
|
|
// TraditionalSignPlugin, only used for testing
|
|
// WARNING: This function is deprecated, use SignPlugin instead
|
|
func TraditionalSignPlugin(plugin []byte) ([]byte, error) {
|
|
// load private key
|
|
privateKey, err := encryption.LoadPrivateKey(private_key.PRIVATE_KEY)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return withkey.TraditionalSignPlugin(plugin, privateKey)
|
|
}
|