diff --git a/internal/web/actions/default/clusters/grants/create.go b/internal/web/actions/default/clusters/grants/create.go index 54d7e29d..5725fcc8 100644 --- a/internal/web/actions/default/clusters/grants/create.go +++ b/internal/web/actions/default/clusters/grants/create.go @@ -6,6 +6,7 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" + "golang.org/x/crypto/ssh" ) type CreateAction struct { @@ -50,6 +51,18 @@ func (this *CreateAction) RunPost(params struct { if len(params.PrivateKey) == 0 { this.FailField("privateKey", "请输入RSA私钥") } + + // 验证私钥 + var err error + if len(params.Passphrase) > 0 { + _, err = ssh.ParsePrivateKeyWithPassphrase([]byte(params.PrivateKey), []byte(params.Passphrase)) + } else { + _, err = ssh.ParsePrivateKey([]byte(params.PrivateKey)) + } + if err != nil { + this.Fail("私钥验证失败,请检查格式:" + err.Error()) + return + } default: this.Fail("请选择正确的认证方式") } diff --git a/internal/web/actions/default/clusters/grants/createPopup.go b/internal/web/actions/default/clusters/grants/createPopup.go index 49d8f171..cefa7aba 100644 --- a/internal/web/actions/default/clusters/grants/createPopup.go +++ b/internal/web/actions/default/clusters/grants/createPopup.go @@ -7,6 +7,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" + "golang.org/x/crypto/ssh" ) type CreatePopupAction struct { @@ -51,6 +52,18 @@ func (this *CreatePopupAction) RunPost(params struct { if len(params.PrivateKey) == 0 { this.FailField("privateKey", "请输入RSA私钥") } + + // 验证私钥 + var err error + if len(params.Passphrase) > 0 { + _, err = ssh.ParsePrivateKeyWithPassphrase([]byte(params.PrivateKey), []byte(params.Passphrase)) + } else { + _, err = ssh.ParsePrivateKey([]byte(params.PrivateKey)) + } + if err != nil { + this.Fail("私钥验证失败,请检查格式:" + err.Error()) + return + } default: this.Fail("请选择正确的认证方式") } diff --git a/internal/web/actions/default/clusters/grants/update.go b/internal/web/actions/default/clusters/grants/update.go index 00eb4b4b..15abdd01 100644 --- a/internal/web/actions/default/clusters/grants/update.go +++ b/internal/web/actions/default/clusters/grants/update.go @@ -7,6 +7,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" + "golang.org/x/crypto/ssh" ) type UpdateAction struct { @@ -83,6 +84,18 @@ func (this *UpdateAction) RunPost(params struct { if len(params.PrivateKey) == 0 { this.FailField("privateKey", "请输入RSA私钥") } + + // 验证私钥 + var err error + if len(params.Passphrase) > 0 { + _, err = ssh.ParsePrivateKeyWithPassphrase([]byte(params.PrivateKey), []byte(params.Passphrase)) + } else { + _, err = ssh.ParsePrivateKey([]byte(params.PrivateKey)) + } + if err != nil { + this.Fail("私钥验证失败,请检查格式:" + err.Error()) + return + } default: this.Fail("请选择正确的认证方式") } diff --git a/internal/web/actions/default/clusters/grants/updatePopup.go b/internal/web/actions/default/clusters/grants/updatePopup.go index 184757ae..763553e2 100644 --- a/internal/web/actions/default/clusters/grants/updatePopup.go +++ b/internal/web/actions/default/clusters/grants/updatePopup.go @@ -7,6 +7,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" + "golang.org/x/crypto/ssh" ) type UpdatePopupAction struct { @@ -83,6 +84,18 @@ func (this *UpdatePopupAction) RunPost(params struct { if len(params.PrivateKey) == 0 { this.FailField("privateKey", "请输入RSA私钥") } + + // 验证私钥 + var err error + if len(params.Passphrase) > 0 { + _, err = ssh.ParsePrivateKeyWithPassphrase([]byte(params.PrivateKey), []byte(params.Passphrase)) + } else { + _, err = ssh.ParsePrivateKey([]byte(params.PrivateKey)) + } + if err != nil { + this.Fail("私钥验证失败,请检查格式:" + err.Error()) + return + } default: this.Fail("请选择正确的认证方式") }