github.com/Mrs4s/MiraiGo@v0.0.0-20240226124653-54bdd873e3fe/client/internal/auth/auth.go (about) 1 package auth 2 3 import ( 4 "encoding/hex" 5 "encoding/json" 6 "fmt" 7 8 "github.com/pkg/errors" 9 ) 10 11 //go:generate stringer -type=ProtocolType -linecomment 12 type ProtocolType int 13 14 const ( 15 Unset ProtocolType = iota 16 AndroidPhone // Android Phone 17 AndroidWatch // Android Watch 18 MacOS // MacOS 19 QiDian // 企点 20 IPad // iPad 21 AndroidPad // Android Pad 22 ) 23 24 var ( 25 AppVersions = map[ProtocolType]*AppVersion{ 26 AndroidPhone: { 27 ApkId: "com.tencent.mobileqq", 28 AppId: 537164840, 29 SubAppId: 537164840, 30 AppKey: "0S200MNJT807V3GE", 31 SortVersionName: "8.9.63.11390", 32 BuildTime: 1685069178, 33 ApkSign: []byte{0xA6, 0xB7, 0x45, 0xBF, 0x24, 0xA2, 0xC2, 0x77, 0x52, 0x77, 0x16, 0xF6, 0xF3, 0x6E, 0xB6, 0x8D}, 34 SdkVersion: "6.0.0.2546", 35 SSOVersion: 20, 36 MiscBitmap: 150470524, 37 SubSigmap: 0x10400, 38 MainSigMap: WLOGIN_A5 | WLOGIN_RESERVED | WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | 39 WLOGIN_LSKEY | WLOGIN_SKEY | WLOGIN_SIG64 | 1<<16 | WLOGIN_VKEY | WLOGIN_D2 | 40 WLOGIN_SID | WLOGIN_PSKEY | WLOGIN_AQSIG | WLOGIN_LHSIG | WLOGIN_PAYTOKEN, // 16724722 41 QUA: "V1_AND_SQ_8.9.63_4194_YYB_D", 42 Protocol: AndroidPhone, 43 }, 44 AndroidPad: { 45 ApkId: "com.tencent.mobileqq", 46 AppId: 537164888, 47 SubAppId: 537164888, 48 AppKey: "0S200MNJT807V3GE", 49 SortVersionName: "8.9.63.11390", 50 BuildTime: 1685069178, 51 ApkSign: []byte{0xA6, 0xB7, 0x45, 0xBF, 0x24, 0xA2, 0xC2, 0x77, 0x52, 0x77, 0x16, 0xF6, 0xF3, 0x6E, 0xB6, 0x8D}, 52 SdkVersion: "6.0.0.2546", 53 SSOVersion: 20, 54 MiscBitmap: 150470524, 55 SubSigmap: 0x10400, 56 MainSigMap: WLOGIN_A5 | WLOGIN_RESERVED | WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | 57 WLOGIN_LSKEY | WLOGIN_SKEY | WLOGIN_SIG64 | 1<<16 | WLOGIN_VKEY | WLOGIN_D2 | 58 WLOGIN_SID | WLOGIN_PSKEY | WLOGIN_AQSIG | WLOGIN_LHSIG | WLOGIN_PAYTOKEN, // 16724722 59 QUA: "V1_AND_SQ_8.9.63_4194_YYB_D", 60 Protocol: AndroidPad, 61 }, 62 AndroidWatch: { 63 ApkId: "com.tencent.qqlite", 64 AppId: 537065138, 65 SubAppId: 537065138, 66 SortVersionName: "2.0.8", 67 BuildTime: 1559564731, 68 ApkSign: []byte{0xA6, 0xB7, 0x45, 0xBF, 0x24, 0xA2, 0xC2, 0x77, 0x52, 0x77, 0x16, 0xF6, 0xF3, 0x6E, 0xB6, 0x8D}, 69 SdkVersion: "6.0.0.2365", 70 SSOVersion: 5, 71 MiscBitmap: 16252796, 72 SubSigmap: 0x10400, 73 MainSigMap: WLOGIN_A5 | WLOGIN_RESERVED | WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | 74 WLOGIN_LSKEY | WLOGIN_SKEY | WLOGIN_SIG64 | 1<<16 | WLOGIN_VKEY | WLOGIN_D2 | 75 WLOGIN_SID | WLOGIN_PSKEY | WLOGIN_AQSIG | WLOGIN_LHSIG | WLOGIN_PAYTOKEN, // 16724722 76 Protocol: AndroidWatch, 77 }, 78 IPad: { 79 ApkId: "com.tencent.minihd.qq", 80 AppId: 537151363, 81 SubAppId: 537151363, 82 SortVersionName: "8.9.33.614", 83 BuildTime: 1595836208, 84 ApkSign: []byte{170, 57, 120, 244, 31, 217, 111, 249, 145, 74, 102, 158, 24, 100, 116, 199}, 85 SdkVersion: "6.0.0.2433", 86 SSOVersion: 19, 87 MiscBitmap: 150470524, 88 SubSigmap: 66560, 89 MainSigMap: WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | WLOGIN_SKEY | WLOGIN_VKEY | WLOGIN_D2 | WLOGIN_SID | WLOGIN_PSKEY, // 1970400 90 Protocol: IPad, 91 }, 92 MacOS: { 93 ApkId: "com.tencent.minihd.qq", 94 AppId: 537128930, 95 SubAppId: 537128930, 96 SortVersionName: "5.8.9", 97 BuildTime: 1595836208, 98 ApkSign: []byte{170, 57, 120, 244, 31, 217, 111, 249, 145, 74, 102, 158, 24, 100, 116, 199}, 99 SdkVersion: "6.0.0.2433", 100 SSOVersion: 12, 101 MiscBitmap: 150470524, 102 SubSigmap: 66560, 103 MainSigMap: WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | WLOGIN_SKEY | WLOGIN_VKEY | WLOGIN_D2 | WLOGIN_SID | WLOGIN_PSKEY, // 1970400 104 Protocol: MacOS, 105 }, 106 QiDian: { 107 ApkId: "com.tencent.qidian", 108 AppId: 537096038, 109 SubAppId: 537036590, 110 SortVersionName: "5.0.0", 111 BuildTime: 1630062176, 112 ApkSign: []byte{160, 30, 236, 171, 133, 233, 227, 186, 43, 15, 106, 21, 140, 133, 92, 41}, 113 SdkVersion: "6.0.0.2484", 114 SSOVersion: 18, 115 MiscBitmap: 184024956, 116 SubSigmap: 66560, 117 MainSigMap: WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | WLOGIN_SKEY | WLOGIN_D2 | WLOGIN_PSKEY | WLOGIN_DA2, // 34869472 118 Protocol: QiDian, 119 }, 120 } 121 ) 122 123 // see oicq/wlogin_sdk/request/WtloginHelper.java class SigType 124 const ( 125 _ = 1 << iota 126 WLOGIN_A5 127 _ 128 _ 129 WLOGIN_RESERVED 130 WLOGIN_STWEB 131 WLOGIN_A2 132 WLOGIN_ST 133 _ 134 WLOGIN_LSKEY 135 _ 136 _ 137 WLOGIN_SKEY 138 WLOGIN_SIG64 139 WLOGIN_OPENKEY 140 WLOGIN_TOKEN 141 _ 142 WLOGIN_VKEY 143 WLOGIN_D2 144 WLOGIN_SID 145 WLOGIN_PSKEY 146 WLOGIN_AQSIG 147 WLOGIN_LHSIG 148 WLOGIN_PAYTOKEN 149 WLOGIN_PF 150 WLOGIN_DA2 151 WLOGIN_QRPUSH 152 WLOGIN_PT4Token 153 ) 154 155 type AppVersion struct { 156 ApkSign []byte 157 ApkId string 158 SortVersionName string 159 SdkVersion string 160 AppId uint32 161 SubAppId uint32 162 AppKey string 163 BuildTime uint32 164 SSOVersion uint32 165 MiscBitmap uint32 166 SubSigmap uint32 167 MainSigMap uint32 168 QUA string 169 Protocol ProtocolType 170 } 171 172 func (v *AppVersion) String() string { 173 return fmt.Sprintf("%s %s", v.Protocol.String(), v.SortVersionName) 174 } 175 176 func (v *AppVersion) UpdateFromJson(d []byte) error { 177 var f appVersionFile 178 if err := json.Unmarshal(d, &f); err != nil { 179 return errors.Wrap(err, "failed to unmarshal json message") 180 } 181 // 按 AppVersion 字段顺序赋值,以免遗漏 182 v.ApkSign, _ = hex.DecodeString(f.ApkSign) 183 v.ApkId = f.ApkId 184 v.SortVersionName = f.SortVersionName 185 v.SdkVersion = f.SdkVersion 186 v.AppId = f.AppId 187 v.SubAppId = f.SubAppId 188 v.AppKey = f.AppKey 189 v.BuildTime = f.BuildTime 190 v.SSOVersion = f.SSOVersion 191 v.MiscBitmap = f.MiscBitmap 192 v.SubSigmap = f.SubSigmap 193 v.MainSigMap = f.MainSigMap 194 v.QUA = f.QUA 195 v.Protocol = f.ProtocolType 196 return nil 197 } 198 199 func (i ProtocolType) Version() *AppVersion { 200 return AppVersions[i] 201 } 202 203 type SigInfo struct { 204 LoginBitmap uint64 205 TGT []byte 206 TGTKey []byte 207 208 SrmToken []byte // study room manager | 0x16a 209 T133 []byte 210 EncryptedA1 []byte 211 UserStKey []byte 212 UserStWebSig []byte 213 SKey []byte 214 SKeyExpiredTime int64 215 D2 []byte 216 D2Key []byte 217 DeviceToken []byte 218 219 PsKeyMap map[string][]byte 220 Pt4TokenMap map[string][]byte 221 222 // Others 223 OutPacketSessionID []byte 224 Dpwd []byte 225 226 // tlv cache 227 T104 []byte 228 T174 []byte 229 G []byte 230 T402 []byte 231 RandSeed []byte // t403 232 T547 []byte 233 // rollbackSig []byte 234 // t149 []byte 235 // t150 []byte 236 // t528 []byte 237 // t530 []byte 238 239 // sync info 240 SyncCookie []byte 241 PubAccountCookie []byte 242 Ksid []byte 243 // msgCtrlBuf []byte 244 } 245 246 type appVersionFile struct { 247 ApkId string `json:"apk_id"` 248 AppId uint32 `json:"app_id"` 249 SubAppId uint32 `json:"sub_app_id"` 250 AppKey string `json:"app_key"` 251 SortVersionName string `json:"sort_version_name"` 252 BuildTime uint32 `json:"build_time"` 253 ApkSign string `json:"apk_sign"` // hex encoded 254 SdkVersion string `json:"sdk_version"` 255 SSOVersion uint32 `json:"sso_version"` 256 MiscBitmap uint32 `json:"misc_bitmap"` 257 MainSigMap uint32 `json:"main_sig_map"` 258 SubSigmap uint32 `json:"sub_sig_map"` 259 QUA string `json:"qua"` 260 ProtocolType ProtocolType `json:"protocol_type"` 261 }