1 Star 0 Fork 0

叶海丰/ipmi-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cmd_get_session_challenge.go 1.84 KB
一键复制 编辑 原始数据 按行查看 历史
叶海丰 提交于 2024-08-02 08:43 . init
package ipmi
import "fmt"
// 22.16
type GetSessionChallengeRequest struct {
// Authentication Type for Challenge
// indicating what type of authentication type the console wants to use.
AuthType AuthType
// Sixteen-bytes. All 0s for null user name (User 1)
Username [16]byte
}
type GetSessionChallengeResponse struct {
TemporarySessionID uint32 // LS byte first
Challenge [16]byte
}
func (req *GetSessionChallengeRequest) Command() Command {
return CommandGetSessionChallenge
}
func (req *GetSessionChallengeRequest) Pack() []byte {
out := make([]byte, 17)
packUint8(uint8(req.AuthType), out, 0)
packBytes(req.Username[:], out, 1)
return out
}
func (res *GetSessionChallengeResponse) Unpack(msg []byte) error {
if len(msg) < 20 {
return ErrUnpackedDataTooShortWith(len(msg), 20)
}
res.TemporarySessionID, _, _ = unpackUint32L(msg, 0)
b, _, _ := unpackBytes(msg, 4, 16)
res.Challenge = array16(b)
return nil
}
func (*GetSessionChallengeResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{
0x81: "invalid user name",
0x82: "null user name (User 1) not enabled",
}
}
func (res *GetSessionChallengeResponse) Format() string {
return fmt.Sprintf("%v", res)
}
// The command selects which of the BMC-supported authentication types the Remote Console would like to use,
// and a username that selects which set of user information should be used for the session
func (c *Client) GetSessionChallenge() (response *GetSessionChallengeResponse, err error) {
username := padBytes(c.Username, 16, 0x00)
request := &GetSessionChallengeRequest{
AuthType: c.session.authType,
Username: array16(username),
}
response = &GetSessionChallengeResponse{}
err = c.Exchange(request, response)
if err != nil {
return
}
c.session.v15.sessionID = response.TemporarySessionID
c.session.v15.challenge = response.Challenge
return
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/rogax/ipmi-go.git
git@gitee.com:rogax/ipmi-go.git
rogax
ipmi-go
ipmi-go
86ae46cfb58e

搜索帮助

0d507c66 1850385 C8b1a773 1850385