2022-05-23 16:26:27 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
|
|
|
"errors"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/client"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
|
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
2024-05-16 09:11:57 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/server/ctrlmessage"
|
2024-11-07 14:32:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
|
|
|
frostfscrypto "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto"
|
2022-05-23 16:26:27 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2023-11-07 14:35:09 +00:00
|
|
|
const (
|
|
|
|
irFlagNameVUB = "vub"
|
|
|
|
)
|
|
|
|
|
2022-10-17 15:37:15 +00:00
|
|
|
func initControlFlags(cmd *cobra.Command) {
|
|
|
|
ff := cmd.Flags()
|
2022-11-29 10:22:17 +00:00
|
|
|
ff.StringP(commonflags.WalletPath, commonflags.WalletPathShorthand, commonflags.WalletPathDefault, commonflags.WalletPathUsage)
|
|
|
|
ff.StringP(commonflags.Account, commonflags.AccountShorthand, commonflags.AccountDefault, commonflags.AccountUsage)
|
2022-10-17 15:37:15 +00:00
|
|
|
ff.String(controlRPC, controlRPCDefault, controlRPCUsage)
|
|
|
|
ff.DurationP(commonflags.Timeout, commonflags.TimeoutShorthand, commonflags.TimeoutDefault, commonflags.TimeoutUsage)
|
|
|
|
}
|
|
|
|
|
2023-11-07 14:35:09 +00:00
|
|
|
func initControlIRFlags(cmd *cobra.Command) {
|
|
|
|
initControlFlags(cmd)
|
|
|
|
|
|
|
|
ff := cmd.Flags()
|
|
|
|
ff.Uint32(irFlagNameVUB, 0, "Valid until block value for notary transaction")
|
|
|
|
}
|
|
|
|
|
2024-05-16 09:11:57 +00:00
|
|
|
func signRequest(cmd *cobra.Command, pk *ecdsa.PrivateKey, req ctrlmessage.SignedMessage) {
|
|
|
|
err := ctrlmessage.Sign(pk, req)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "could not sign request: %w", err)
|
2022-05-23 16:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func verifyResponse(cmd *cobra.Command,
|
|
|
|
sigControl interface {
|
|
|
|
GetKey() []byte
|
|
|
|
GetSign() []byte
|
|
|
|
},
|
|
|
|
body interface {
|
2024-08-19 15:28:53 +00:00
|
|
|
MarshalProtobuf([]byte) []byte
|
2022-05-23 16:26:27 +00:00
|
|
|
},
|
|
|
|
) {
|
|
|
|
if sigControl == nil {
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "", errors.New("missing response signature"))
|
2022-05-23 16:26:27 +00:00
|
|
|
}
|
|
|
|
|
2023-06-26 13:18:39 +00:00
|
|
|
// TODO(@cthulhu-rider): #468 use Signature message from FrostFS API to avoid conversion
|
2022-05-23 16:26:27 +00:00
|
|
|
var sigV2 refs.Signature
|
|
|
|
sigV2.SetScheme(refs.ECDSA_SHA512)
|
|
|
|
sigV2.SetKey(sigControl.GetKey())
|
|
|
|
sigV2.SetSign(sigControl.GetSign())
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
var sig frostfscrypto.Signature
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "can't read signature: %w", sig.ReadFromV2(sigV2))
|
2022-05-23 16:26:27 +00:00
|
|
|
|
2024-08-19 15:28:53 +00:00
|
|
|
if !sig.Verify(body.MarshalProtobuf(nil)) {
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "", errors.New("invalid response signature"))
|
2022-05-23 16:26:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getClient(cmd *cobra.Command, pk *ecdsa.PrivateKey) *client.Client {
|
2022-05-24 08:38:45 +00:00
|
|
|
return internalclient.GetSDKClientByFlag(cmd, pk, controlRPC)
|
2022-05-23 16:26:27 +00:00
|
|
|
}
|