Keyexchange.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. // AUTOGENERATED FILE, DO NOT EDIT BY HAND
  2. #ifndef PB_KEYEXCHANGE_H
  3. #define PB_KEYEXCHANGE_H
  4. #include <memory>
  5. #include <vector>
  6. #include <PbCommon.h>
  7. #include <PbWriter.h>
  8. #include <PbReader.h>
  9. enum class Product : uint32_t {
  10. PRODUCT_CLIENT = 0,
  11. PRODUCT_LIBSPOTIFY = 1,
  12. PRODUCT_MOBILE = 2,
  13. PRODUCT_PARTNER = 3,
  14. PRODUCT_LIBSPOTIFY_EMBEDDED = 5
  15. };
  16. enum class Platform : uint32_t {
  17. PLATFORM_WIN32_X86 = 0,
  18. PLATFORM_OSX_X86 = 1,
  19. PLATFORM_LINUX_X86 = 2,
  20. PLATFORM_IPHONE_ARM = 3,
  21. PLATFORM_S60_ARM = 4,
  22. PLATFORM_OSX_PPC = 5,
  23. PLATFORM_ANDROID_ARM = 6,
  24. PLATFORM_WINDOWS_CE_ARM = 7,
  25. PLATFORM_LINUX_X86_64 = 8,
  26. PLATFORM_OSX_X86_64 = 9,
  27. PLATFORM_PALM_ARM = 10,
  28. PLATFORM_LINUX_SH = 11,
  29. PLATFORM_FREEBSD_X86 = 12,
  30. PLATFORM_FREEBSD_X86_64 = 13,
  31. PLATFORM_BLACKBERRY_ARM = 14,
  32. PLATFORM_SONOS = 15,
  33. PLATFORM_LINUX_MIPS = 16,
  34. PLATFORM_LINUX_ARM = 17,
  35. PLATFORM_LOGITECH_ARM = 18,
  36. PLATFORM_LINUX_BLACKFIN = 19,
  37. PLATFORM_WP7_ARM = 20,
  38. PLATFORM_ONKYO_ARM = 21,
  39. PLATFORM_QNXNTO_ARM = 22,
  40. PLATFORM_BCO_ARM = 23
  41. };
  42. enum class Cryptosuite : uint32_t {
  43. CRYPTO_SUITE_SHANNON = 0,
  44. CRYPTO_SUITE_RC4_SHA1_HMAC = 1
  45. };
  46. class LoginCryptoDiffieHellmanChallenge : public BaseProtobufMessage {
  47. private:
  48. public:
  49. LoginCryptoDiffieHellmanChallenge() {};
  50. std::vector<uint8_t> gs;
  51. bool decodeField(std::shared_ptr<PbReader> reader) {
  52. switch (reader->currentTag)
  53. {
  54. case 10:
  55. reader->decodeVector(gs);
  56. break;
  57. default:
  58. return false;
  59. }
  60. return true;
  61. }
  62. void encodeWithWriter(std::shared_ptr<PbWriter> writer) {
  63. writer->addVector(10, gs);
  64. }
  65. };
  66. class LoginCryptoChallengeUnion : public BaseProtobufMessage {
  67. private:
  68. public:
  69. LoginCryptoChallengeUnion() {};
  70. LoginCryptoDiffieHellmanChallenge diffie_hellman;
  71. bool decodeField(std::shared_ptr<PbReader> reader) {
  72. switch (reader->currentTag)
  73. {
  74. case 10:
  75. lastMessagePosition = reader->pos + reader->decodeVarInt<uint32_t>();
  76. diffie_hellman.parseWithReader(reader);
  77. reader->maxPosition = lastMessagePosition;
  78. break;
  79. default:
  80. return false;
  81. }
  82. return true;
  83. }
  84. void encodeWithWriter(std::shared_ptr<PbWriter> writer) {
  85. lastMessagePosition = writer->startMessage();
  86. diffie_hellman.encodeWithWriter(writer);
  87. writer->finishMessage(10, lastMessagePosition);
  88. }
  89. };
  90. class LoginCryptoDiffieHellmanHello : public BaseProtobufMessage {
  91. private:
  92. public:
  93. LoginCryptoDiffieHellmanHello() {};
  94. std::vector<uint8_t> gc;
  95. uint32_t server_keys_known;
  96. bool decodeField(std::shared_ptr<PbReader> reader) {
  97. switch (reader->currentTag)
  98. {
  99. case 10:
  100. reader->decodeVector(gc);
  101. break;
  102. case 20:
  103. server_keys_known = reader->decodeVarInt<uint32_t>();
  104. break;
  105. default:
  106. return false;
  107. }
  108. return true;
  109. }
  110. void encodeWithWriter(std::shared_ptr<PbWriter> writer) {
  111. writer->addVector(10, gc);
  112. writer->addVarInt(20, server_keys_known);
  113. }
  114. };
  115. class LoginCryptoHelloUnion : public BaseProtobufMessage {
  116. private:
  117. public:
  118. LoginCryptoHelloUnion() {};
  119. LoginCryptoDiffieHellmanHello diffie_hellman;
  120. bool decodeField(std::shared_ptr<PbReader> reader) {
  121. switch (reader->currentTag)
  122. {
  123. case 10:
  124. lastMessagePosition = reader->pos + reader->decodeVarInt<uint32_t>();
  125. diffie_hellman.parseWithReader(reader);
  126. reader->maxPosition = lastMessagePosition;
  127. break;
  128. default:
  129. return false;
  130. }
  131. return true;
  132. }
  133. void encodeWithWriter(std::shared_ptr<PbWriter> writer) {
  134. lastMessagePosition = writer->startMessage();
  135. diffie_hellman.encodeWithWriter(writer);
  136. writer->finishMessage(10, lastMessagePosition);
  137. }
  138. };
  139. class BuildInfo : public BaseProtobufMessage {
  140. private:
  141. public:
  142. BuildInfo() {};
  143. Product product;
  144. Platform platform;
  145. uint64_t version;
  146. bool decodeField(std::shared_ptr<PbReader> reader) {
  147. switch (reader->currentTag)
  148. {
  149. case 10:
  150. product = static_cast<Product>(reader->decodeVarInt<uint32_t>());
  151. break;
  152. case 30:
  153. platform = static_cast<Platform>(reader->decodeVarInt<uint32_t>());
  154. break;
  155. case 40:
  156. version = reader->decodeVarInt<uint64_t>();
  157. break;
  158. default:
  159. return false;
  160. }
  161. return true;
  162. }
  163. void encodeWithWriter(std::shared_ptr<PbWriter> writer) {
  164. writer->addVarInt(10, static_cast<uint32_t>(product));
  165. writer->addVarInt(30, static_cast<uint32_t>(platform));
  166. writer->addVarInt(40, version);
  167. }
  168. };
  169. class FeatureSet : public BaseProtobufMessage {
  170. private:
  171. public:
  172. FeatureSet() {};
  173. bool autoupdate2;
  174. bool decodeField(std::shared_ptr<PbReader> reader) {
  175. switch (reader->currentTag)
  176. {
  177. case 1:
  178. autoupdate2 = reader->decodeVarInt<bool>();
  179. break;
  180. default:
  181. return false;
  182. }
  183. return true;
  184. }
  185. void encodeWithWriter(std::shared_ptr<PbWriter> writer) {
  186. writer->addVarInt(1, autoupdate2);
  187. }
  188. };
  189. class APChallenge : public BaseProtobufMessage {
  190. private:
  191. public:
  192. APChallenge() {};
  193. LoginCryptoChallengeUnion login_crypto_challenge;
  194. bool decodeField(std::shared_ptr<PbReader> reader) {
  195. switch (reader->currentTag)
  196. {
  197. case 10:
  198. lastMessagePosition = reader->pos + reader->decodeVarInt<uint32_t>();
  199. login_crypto_challenge.parseWithReader(reader);
  200. reader->maxPosition = lastMessagePosition;
  201. break;
  202. default:
  203. return false;
  204. }
  205. return true;
  206. }
  207. void encodeWithWriter(std::shared_ptr<PbWriter> writer) {
  208. lastMessagePosition = writer->startMessage();
  209. login_crypto_challenge.encodeWithWriter(writer);
  210. writer->finishMessage(10, lastMessagePosition);
  211. }
  212. };
  213. class APResponseMessage : public BaseProtobufMessage {
  214. private:
  215. public:
  216. APResponseMessage() {};
  217. APChallenge challenge;
  218. bool decodeField(std::shared_ptr<PbReader> reader) {
  219. switch (reader->currentTag)
  220. {
  221. case 10:
  222. lastMessagePosition = reader->pos + reader->decodeVarInt<uint32_t>();
  223. challenge.parseWithReader(reader);
  224. reader->maxPosition = lastMessagePosition;
  225. break;
  226. default:
  227. return false;
  228. }
  229. return true;
  230. }
  231. void encodeWithWriter(std::shared_ptr<PbWriter> writer) {
  232. lastMessagePosition = writer->startMessage();
  233. challenge.encodeWithWriter(writer);
  234. writer->finishMessage(10, lastMessagePosition);
  235. }
  236. };
  237. class LoginCryptoDiffieHellmanResponse : public BaseProtobufMessage {
  238. private:
  239. public:
  240. LoginCryptoDiffieHellmanResponse() {};
  241. std::vector<uint8_t> hmac;
  242. bool decodeField(std::shared_ptr<PbReader> reader) {
  243. switch (reader->currentTag)
  244. {
  245. case 10:
  246. reader->decodeVector(hmac);
  247. break;
  248. default:
  249. return false;
  250. }
  251. return true;
  252. }
  253. void encodeWithWriter(std::shared_ptr<PbWriter> writer) {
  254. writer->addVector(10, hmac);
  255. }
  256. };
  257. class LoginCryptoResponseUnion : public BaseProtobufMessage {
  258. private:
  259. public:
  260. LoginCryptoResponseUnion() {};
  261. LoginCryptoDiffieHellmanResponse diffie_hellman;
  262. bool decodeField(std::shared_ptr<PbReader> reader) {
  263. switch (reader->currentTag)
  264. {
  265. case 10:
  266. lastMessagePosition = reader->pos + reader->decodeVarInt<uint32_t>();
  267. diffie_hellman.parseWithReader(reader);
  268. reader->maxPosition = lastMessagePosition;
  269. break;
  270. default:
  271. return false;
  272. }
  273. return true;
  274. }
  275. void encodeWithWriter(std::shared_ptr<PbWriter> writer) {
  276. lastMessagePosition = writer->startMessage();
  277. diffie_hellman.encodeWithWriter(writer);
  278. writer->finishMessage(10, lastMessagePosition);
  279. }
  280. };
  281. class CryptoResponseUnion : public BaseProtobufMessage {
  282. private:
  283. public:
  284. CryptoResponseUnion() {};
  285. bool decodeField(std::shared_ptr<PbReader> reader) {
  286. switch (reader->currentTag)
  287. {
  288. default:
  289. return false;
  290. }
  291. return true;
  292. }
  293. void encodeWithWriter(std::shared_ptr<PbWriter> writer) {
  294. }
  295. };
  296. class PoWResponseUnion : public BaseProtobufMessage {
  297. private:
  298. public:
  299. PoWResponseUnion() {};
  300. bool decodeField(std::shared_ptr<PbReader> reader) {
  301. switch (reader->currentTag)
  302. {
  303. default:
  304. return false;
  305. }
  306. return true;
  307. }
  308. void encodeWithWriter(std::shared_ptr<PbWriter> writer) {
  309. }
  310. };
  311. class ClientResponsePlaintext : public BaseProtobufMessage {
  312. private:
  313. public:
  314. ClientResponsePlaintext() {};
  315. LoginCryptoResponseUnion login_crypto_response;
  316. PoWResponseUnion pow_response;
  317. CryptoResponseUnion crypto_response;
  318. bool decodeField(std::shared_ptr<PbReader> reader) {
  319. switch (reader->currentTag)
  320. {
  321. case 10:
  322. lastMessagePosition = reader->pos + reader->decodeVarInt<uint32_t>();
  323. login_crypto_response.parseWithReader(reader);
  324. reader->maxPosition = lastMessagePosition;
  325. break;
  326. case 20:
  327. lastMessagePosition = reader->pos + reader->decodeVarInt<uint32_t>();
  328. pow_response.parseWithReader(reader);
  329. reader->maxPosition = lastMessagePosition;
  330. break;
  331. case 30:
  332. lastMessagePosition = reader->pos + reader->decodeVarInt<uint32_t>();
  333. crypto_response.parseWithReader(reader);
  334. reader->maxPosition = lastMessagePosition;
  335. break;
  336. default:
  337. return false;
  338. }
  339. return true;
  340. }
  341. void encodeWithWriter(std::shared_ptr<PbWriter> writer) {
  342. lastMessagePosition = writer->startMessage();
  343. login_crypto_response.encodeWithWriter(writer);
  344. writer->finishMessage(10, lastMessagePosition);
  345. lastMessagePosition = writer->startMessage();
  346. pow_response.encodeWithWriter(writer);
  347. writer->finishMessage(20, lastMessagePosition);
  348. lastMessagePosition = writer->startMessage();
  349. crypto_response.encodeWithWriter(writer);
  350. writer->finishMessage(30, lastMessagePosition);
  351. }
  352. };
  353. class ClientHello : public BaseProtobufMessage {
  354. private:
  355. public:
  356. ClientHello() {};
  357. BuildInfo build_info;
  358. LoginCryptoHelloUnion login_crypto_hello;
  359. std::vector<Cryptosuite> cryptosuites_supported;
  360. std::vector<uint8_t> client_nonce;
  361. std::vector<uint8_t> padding;
  362. FeatureSet feature_set;
  363. bool decodeField(std::shared_ptr<PbReader> reader) {
  364. if (firstField) {
  365. cryptosuites_supported.clear();
  366. }
  367. switch (reader->currentTag)
  368. {
  369. case 10:
  370. lastMessagePosition = reader->pos + reader->decodeVarInt<uint32_t>();
  371. build_info.parseWithReader(reader);
  372. reader->maxPosition = lastMessagePosition;
  373. break;
  374. case 50:
  375. lastMessagePosition = reader->pos + reader->decodeVarInt<uint32_t>();
  376. login_crypto_hello.parseWithReader(reader);
  377. reader->maxPosition = lastMessagePosition;
  378. break;
  379. case 30:
  380. cryptosuites_supported.push_back(Cryptosuite());
  381. cryptosuites_supported[cryptosuites_supported.size()-1] = static_cast<Cryptosuite>(reader->decodeVarInt<uint32_t>());
  382. break;
  383. case 60:
  384. reader->decodeVector(client_nonce);
  385. break;
  386. case 70:
  387. reader->decodeVector(padding);
  388. break;
  389. case 80:
  390. lastMessagePosition = reader->pos + reader->decodeVarInt<uint32_t>();
  391. feature_set.parseWithReader(reader);
  392. reader->maxPosition = lastMessagePosition;
  393. break;
  394. default:
  395. return false;
  396. }
  397. return true;
  398. }
  399. void encodeWithWriter(std::shared_ptr<PbWriter> writer) {
  400. lastMessagePosition = writer->startMessage();
  401. build_info.encodeWithWriter(writer);
  402. writer->finishMessage(10, lastMessagePosition);
  403. lastMessagePosition = writer->startMessage();
  404. login_crypto_hello.encodeWithWriter(writer);
  405. writer->finishMessage(50, lastMessagePosition);
  406. lastMessagePosition = writer->startMessage();
  407. for (int i = 0; i < cryptosuites_supported.size(); i++) {
  408. writer->encodeVarInt(static_cast<uint32_t>(cryptosuites_supported[i]));
  409. }
  410. writer->finishMessage(30, lastMessagePosition);
  411. writer->addVector(60, client_nonce);
  412. writer->addVector(70, padding);
  413. lastMessagePosition = writer->startMessage();
  414. feature_set.encodeWithWriter(writer);
  415. writer->finishMessage(80, lastMessagePosition);
  416. }
  417. };
  418. #endif