The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
4.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. /**
  18. Contains static utilities for generating key-files that can be unlocked by
  19. the OnlineUnlockStatus class.
  20. */
  21. class JUCE_API KeyGeneration
  22. {
  23. public:
  24. /**
  25. Generates the content of a key-file which can be sent to a user's machine to
  26. unlock a product.
  27. The returned value is a block of text containing an RSA-encoded block, followed
  28. by some human-readable details. If you pass this block of text to
  29. OnlineUnlockStatus::applyKeyFile(), it will decrpyt it, and if the
  30. key matches and the machine numbers match, it will unlock that machine.
  31. Typically the way you'd use this on a server would be to build a small executable
  32. that simply calls this method and prints the result, so that the webserver can
  33. use this as a reply to the product's auto-registration mechanism. The
  34. keyGenerationAppMain() function is an example of how to build such a function.
  35. @see OnlineUnlockStatus
  36. */
  37. static String JUCE_CALLTYPE generateKeyFile (const String& appName,
  38. const String& userEmail,
  39. const String& userName,
  40. const String& machineNumbers,
  41. const RSAKey& privateKey);
  42. //==============================================================================
  43. /** This is a simple implementation of a key-generator that you could easily wrap in
  44. a command-line main() function for use on your server.
  45. So for example you might use this in a command line app called "unlocker" and
  46. then call it like this:
  47. unlocker MyGreatApp Joe_Bloggs joebloggs@foobar.com 1234abcd,95432ff 22d9aec92d986dd1,923ad49e9e7ff294c
  48. */
  49. static inline int keyGenerationAppMain (int argc, char* argv[])
  50. {
  51. StringArray args;
  52. for (int i = 1; i < argc; ++i)
  53. args.add (argv[i]);
  54. if (args.size() != 5)
  55. {
  56. std::cout << "Requires 5 arguments: app-name user-email username machine-numbers private-key" << std::endl
  57. << " app-name: name of the product being unlocked" << std::endl
  58. << " user-email: user's email address" << std::endl
  59. << " username: name of the user. Careful not to allow any spaces!" << std::endl
  60. << " machine-numbers: a comma- or semicolon-separated list of all machine ID strings this user can run this product on (no whitespace between items!)" << std::endl
  61. << " private-key: the RSA private key corresponding to the public key you've used in the app" << std::endl
  62. << std::endl;
  63. return 1;
  64. }
  65. if (! args[4].containsChar (','))
  66. {
  67. std::cout << "Not a valid RSA key!" << std::endl;
  68. return 1;
  69. }
  70. std::cout << generateKeyFile (args[0], args[1], args[2], args[3], RSAKey (args[4])) << std::endl;
  71. return 0;
  72. }
  73. };