deviceAuth

package
v0.6.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2023 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package device 设备登录权限认证及对应clientID,userName的处理

Index

Constants

View Source
const (
	ProductIdLen = 11
	HmacSha256   = "hmacsha256"
	HmacSha1     = "hmacsha1"
)

Variables

This section is empty.

Functions

func AccessAuth

func AccessAuth(in AuthInfo) error

系统topic及物模型topic都是

第一个表示大的功能(如$thing,$ota)
第二个表示上行还是下行
中间为自定义字段
以产品id/设备名结尾

func GenSecretDeviceInfo added in v0.3.0

func GenSecretDeviceInfo(hmacType string, productID string, deviceName string, deviceSecret string) (
	clientID, userName, password string)

func GetInt64ProductID

func GetInt64ProductID(id string) int64

func GetStrProductID

func GetStrProductID(id int64) string

先将 10进制 转为 62进制 然后 因为字符串类型的产品id有11个字节,不够的需要在前面补0

Types

type AuthInfo

type AuthInfo struct {
	Username string            //用户名
	Topic    string            //主题
	ClientID string            //clientID
	Access   devices.Direction //操作
	Ip       string            //访问的ip地址
}

type LoginDevice

type LoginDevice struct {
	ProductID  string //产品id
	DeviceName string //设备名称
	SdkAppID   int64  //appid 直接填 12010126
	ConnID     string //随机6字节字符串 帮助查bug
	Expiry     int64  //过期时间 unix时间戳
}

func GetClientIDInfo

func GetClientIDInfo(ClientID string) (*LoginDevice, error)

func GetLoginDevice

func GetLoginDevice(userName string) (*LoginDevice, error)

type PwdInfo

type PwdInfo struct {
	HmacHandle func(data string, secret []byte) string
	// contains filtered or unexported fields
}

username 字段的格式为: ${productId}${deviceName};${sdkappid};${connid};${expiry} 注意:${} 表示变量,并非特定的拼接符号。

password 字段格式为: ${token};hmac 签名方法 其中 hmac 签名方法字段填写第三步用到的摘要算法,可选的值有 hmacsha256 和 hmacsha1。

func NewPwdInfo

func NewPwdInfo(signature string, signMethod string) (*PwdInfo, error)

func NewPwdInfoWithPwd added in v0.5.1

func NewPwdInfoWithPwd(password string) (*PwdInfo, error)

func (*PwdInfo) CmpPwd

func (p *PwdInfo) CmpPwd(signature, secret string) error

比较设备秘钥是否正确 @param secret 设备秘钥

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL