| 137 | ) |
| 138 | |
| 139 | func (io *IO) auth(key string, secret string, expire string) bool { |
| 140 | if unixTime, err := strconv.ParseInt(expire, 16, 64); err != nil || time.Now().Unix() > unixTime { |
| 141 | if EngineConfig.LogLang == "zh" { |
| 142 | log.Error("鉴权失败,时间戳过期了", zap.String("expire", expire)) |
| 143 | } else { |
| 144 | log.Error("auth failed expired", zap.String("expire", expire)) |
| 145 | } |
| 146 | return false |
| 147 | } |
| 148 | if len(secret) != 32 { |
| 149 | if EngineConfig.LogLang == "zh" { |
| 150 | log.Error("鉴权失败,密文应该是32位长度", zap.String("secret", secret)) |
| 151 | } else { |
| 152 | log.Error("auth failed secret length must be 32", zap.String("secret", secret)) |
| 153 | } |
| 154 | return false |
| 155 | } |
| 156 | trueSecret := md5.Sum([]byte(key + io.Stream.Path + expire)) |
| 157 | for i := 0; i < 16; i++ { |
| 158 | hex, err := strconv.ParseInt(secret[i<<1:(i<<1)+2], 16, 16) |
| 159 | if trueSecret[i] != byte(hex) || err != nil { |
| 160 | if EngineConfig.LogLang == "zh" { |
| 161 | log.Error("鉴权失败,密文不匹配", zap.String("secret", secret)) |
| 162 | } else { |
| 163 | log.Error("auth failed invalid secret ", zap.String("secret", secret)) |
| 164 | } |
| 165 | return false |
| 166 | } |
| 167 | } |
| 168 | return true |
| 169 | } |
| 170 | |
| 171 | // receive 用于接收发布或者订阅 |
| 172 | func (io *IO) receive(streamPath string, specific common.IIO) error { |