Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions cmd/commandline/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,50 +196,6 @@ If no parameters are provided, an interactive mode will be started.`,
},
}

// NOTE: tester is deprecated, maybe, in several months, we will support this again
// pluginTestCommand = &cobra.Command{
// Use: "test [-i inputs] [-t timeout] package_path invoke_type invoke_action",
// Short: "",
// Long: "Test runs the given plugin package locally, and you can specify the inputs using json format, if not specified, will use default inputs\n" +
// "type: invoke type, available values: \n" +
// "[\n" +
// " tool, model, endpoint\n" +
// "]\n" +
// "action: invoke action, available values: \n" +
// "[\n" +
// " invoke_tool, validate_tool_credentials, \n" +
// " invoke_endpoint\n" +
// " invoke_llm, invoke_text_embedding, invoke_rerank, invoke_tts, invoke_speech2text, invoke_moderation, \n" +
// " validate_provider_credentials, validate_model_credentials, get_tts_model_voices, \n" +
// " get_text_embedding_num_tokens, get_ai_model_schemas, get_llm_num_tokens\n" +
// "]\n",
// Run: func(cmd *cobra.Command, args []string) {
// if len(args) < 3 {
// log.Error("invalid args, please specify package_path, invoke_type, invoke_action")
// return
// }
// // get package path
// package_path_str := args[0]
// // get invoke type
// invoke_type_str := args[1]
// // get invoke action
// invoke_action_str := args[2]
// // get inputs if specified
// inputs := map[string]any{}
// if cmd.Flag("inputs") != nil {
// inputs_str := cmd.Flag("inputs").Value.String()
// err := json.Unmarshal([]byte(inputs_str), &inputs)
// if err != nil {
// log.Error("failed to unmarshal inputs, inputs: %s, error: %v", inputs_str, err)
// return
// }
// }
// // parse flag
// timeout := ""
// if cmd.Flag("timeout") != nil {
// timeout = cmd.Flag("timeout").Value.String()
// }

)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/commandline/signature/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func TestVerifyPluginWithoutVerificationField(t *testing.T) {
t.Fatalf("Failed to create dummy plugin file: %v", err)
}

pluginPackageWithoutVerificationField, err := signer.TraditionalSignPlugin(dummyPlugin)
pluginPackageWithoutVerificationField, err := signer.SignPlugin(dummyPlugin, nil)
if err != nil {
t.Fatalf("Failed to sign plugin: %v", err)
}
Expand Down
1 change: 0 additions & 1 deletion internal/core/local_runtime/tester.go

This file was deleted.

105 changes: 0 additions & 105 deletions internal/core/plugin_manager/tester.go

This file was deleted.

1 change: 0 additions & 1 deletion internal/core/serverless_runtime/init.go

This file was deleted.

11 changes: 0 additions & 11 deletions pkg/plugin_packager/signer/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,3 @@ func SignPlugin(plugin []byte, verification *decoder.Verification) ([]byte, erro
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)
}
123 changes: 17 additions & 106 deletions pkg/plugin_packager/signer/withkey/sign_with_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"crypto/rsa"
"crypto/sha256"
"encoding/base64"
"errors"
"io"
"path"
"strconv"
Expand All @@ -30,10 +29,6 @@ func SignPluginWithPrivateKey(
return nil, err
}

if verification == nil {
return nil, errors.New("verification cannot be nil")
}

// create a new zip writer
zipBuffer := new(bytes.Buffer)
zipWriter := zip.NewWriter(zipBuffer)
Expand Down Expand Up @@ -74,116 +69,31 @@ func SignPluginWithPrivateKey(
return nil, err
}

// write the verification into data
// NOTE: .verification.dify.json is a special file that contains the verification information
// and it will be placed at the end of the zip file, checksum is calculated using it also
verificationBytes := parser.MarshalJsonBytes(verification)

// write verification into the zip file
fileWriter, err := zipWriter.Create(consts.VERIFICATION_FILE)
if err != nil {
return nil, err
}

if _, err := fileWriter.Write(verificationBytes); err != nil {
return nil, err
}

// hash the verification
hash := sha256.New()
hash.Write(verificationBytes)
hashed := hash.Sum(nil)

// write the hash into data
if _, err := data.Write(hashed); err != nil {
return nil, err
}

// get current time
ct := time.Now().Unix()

// convert time to bytes
timeString := strconv.FormatInt(ct, 10)

// write the time into data
data.Write([]byte(timeString))

// sign the data
signature, err := encryption.RSASign(privateKey, data.Bytes())
if err != nil {
return nil, err
}

// write the signature into the comment field of the zip file
comments := parser.MarshalJson(map[string]any{
"signature": base64.StdEncoding.EncodeToString(signature),
"time": ct,
})

// write signature
err = zipWriter.SetComment(comments)
if err != nil {
return nil, err
}

// close the zip writer
err = zipWriter.Close()
if err != nil {
return nil, err
}

return zipBuffer.Bytes(), nil
}

// Only used for testing
// WARNING: This function is deprecated, use SignPluginWithPrivateKey instead
func TraditionalSignPlugin(
plugin []byte,
privateKey *rsa.PrivateKey,
) ([]byte, error) {
decoder, err := decoder.NewZipPluginDecoder(plugin)
if err != nil {
return nil, err
}
if verification != nil {
// write the verification into data
// NOTE: .verification.dify.json is a special file that contains the verification information
// and it will be placed at the end of the zip file, checksum is calculated using it also
verificationBytes := parser.MarshalJsonBytes(verification)

// create a new zip writer
zipBuffer := new(bytes.Buffer)
zipWriter := zip.NewWriter(zipBuffer)

defer zipWriter.Close()
// store temporary hash
data := new(bytes.Buffer)
// read one by one
err = decoder.Walk(func(filename, dir string) error {
file, err := decoder.ReadFile(path.Join(dir, filename))
// write verification into the zip file
fileWriter, err := zipWriter.Create(consts.VERIFICATION_FILE)
if err != nil {
return err
return nil, err
}

// calculate sha256 hash of the file
if _, err := fileWriter.Write(verificationBytes); err != nil {
return nil, err
}

// hash the verification
hash := sha256.New()
hash.Write(file)
hash.Write(verificationBytes)
hashed := hash.Sum(nil)

// write the hash into data
data.Write(hashed)

// create a new file in the zip writer
fileWriter, err := zipWriter.Create(path.Join(dir, filename))
if err != nil {
return err
}

_, err = io.Copy(fileWriter, bytes.NewReader(file))
if err != nil {
return err
if _, err := data.Write(hashed); err != nil {
return nil, err
}

return nil
})

if err != nil {
return nil, err
}

// get current time
Expand Down Expand Up @@ -221,3 +131,4 @@ func TraditionalSignPlugin(

return zipBuffer.Bytes(), nil
}

Loading