2
0

AuthChallenges.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. #include <cstdint> // for uint8_t
  3. #include <memory> // for unique_ptr
  4. #include <string> // for string
  5. #include <vector> // for vector
  6. #include "Crypto.h" // for Crypto
  7. #include "protobuf/authentication.pb.h" // for ClientResponseEncrypted
  8. #include "protobuf/keyexchange.pb.h" // for APResponseMessage, ClientHello
  9. namespace cspot {
  10. class AuthChallenges {
  11. public:
  12. AuthChallenges();
  13. ~AuthChallenges();
  14. /**
  15. * @brief Prepares a spotify authentication packet
  16. * @param authBlob authentication blob bytes
  17. * @param authType value representing spotify's authentication type
  18. * @param deviceId device id to use during auth.
  19. * @param username spotify's username
  20. *
  21. * @returns vector containing bytes of the authentication packet
  22. */
  23. std::vector<uint8_t> prepareAuthPacket(std::vector<uint8_t>& authBlob,
  24. int authType,
  25. const std::string& deviceId,
  26. const std::string& username);
  27. /**
  28. * @brief Solves the ApHello packet, and returns a packet with response
  29. *
  30. * @param helloPacket hello packet bytes received from the server
  31. * @param data authentication data received from the server
  32. *
  33. * @returns vector containing response packet
  34. */
  35. std::vector<uint8_t> solveApHello(std::vector<uint8_t>& helloPacket,
  36. std::vector<uint8_t>& data);
  37. /**
  38. * @brief Prepares an client hello packet, used for initial auth with spotify
  39. *
  40. * @returns vector containing the packet's data
  41. */
  42. std::vector<uint8_t> prepareClientHello();
  43. std::vector<uint8_t> shanSendKey = {};
  44. std::vector<uint8_t> shanRecvKey = {};
  45. private:
  46. const long long SPOTIFY_VERSION = 0x10800000000;
  47. // Protobuf structures
  48. ClientResponseEncrypted authRequest;
  49. ClientResponsePlaintext clientResPlaintext;
  50. ClientHello clientHello;
  51. APResponseMessage apResponse;
  52. std::unique_ptr<Crypto> crypto;
  53. };
  54. } // namespace cspot