1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
package ipmi
import (
"context"
"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(ctx context.Context) (response *GetSessionChallengeResponse, err error) {
username := padBytes(c.Username, 16, 0x00)
request := &GetSessionChallengeRequest{
AuthType: c.session.authType,
Username: array16(username),
}
response = &GetSessionChallengeResponse{}
err = c.Exchange(ctx, request, response)
if err != nil {
return
}
c.session.v15.sessionID = response.TemporarySessionID
c.session.v15.challenge = response.Challenge
return
}
|