fix macOS build (following Projucer changes made in Windows, which removed /Applications/JUCE/modules from its headers). move JUCE headers under source control, so that Windows and macOS can both build against same version of JUCE. remove AUv3 target (I think it's an iOS thing, so it will never work with this macOS fluidsynth dylib).
This commit is contained in:
@ -0,0 +1,116 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2017 - ROLI Ltd.
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
|
||||
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
|
||||
27th April 2017).
|
||||
|
||||
End User License Agreement: www.juce.com/juce-5-licence
|
||||
Privacy Policy: www.juce.com/juce-5-privacy-policy
|
||||
|
||||
Or: You may also use this code under the terms of the GPL v3 (see
|
||||
www.gnu.org/licenses).
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
/**
|
||||
Contains static utilities for generating key-files that can be unlocked by
|
||||
the OnlineUnlockStatus class.
|
||||
|
||||
@tags{ProductUnlocking}
|
||||
*/
|
||||
class JUCE_API KeyGeneration
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Generates the content of a key-file which can be sent to a user's machine to
|
||||
unlock a product.
|
||||
|
||||
The returned value is a block of text containing an RSA-encoded block, followed
|
||||
by some human-readable details. If you pass this block of text to
|
||||
OnlineUnlockStatus::applyKeyFile(), it will decrypt it, and if the
|
||||
key matches and the machine numbers match, it will unlock that machine.
|
||||
|
||||
Typically the way you'd use this on a server would be to build a small executable
|
||||
that simply calls this method and prints the result, so that the webserver can
|
||||
use this as a reply to the product's auto-registration mechanism. The
|
||||
keyGenerationAppMain() function is an example of how to build such a function.
|
||||
|
||||
@see OnlineUnlockStatus
|
||||
*/
|
||||
static String JUCE_CALLTYPE generateKeyFile (const String& appName,
|
||||
const String& userEmail,
|
||||
const String& userName,
|
||||
const String& machineNumbers,
|
||||
const RSAKey& privateKey);
|
||||
|
||||
/** Similar to the above key file generation method but with an expiry time.
|
||||
You must supply a Time after which this key file should no longer be considered as active.
|
||||
|
||||
N.B. when an app is unlocked with an expiring key file, OnlineUnlockStatus::isUnlocked will
|
||||
still return false. You must then check OnlineUnlockStatus::getExpiryTime to see if this
|
||||
expiring key file is still in date and act accordingly.
|
||||
|
||||
@see OnlineUnlockStatus
|
||||
*/
|
||||
static String JUCE_CALLTYPE generateExpiringKeyFile (const String& appName,
|
||||
const String& userEmail,
|
||||
const String& userName,
|
||||
const String& machineNumbers,
|
||||
const Time expiryTime,
|
||||
const RSAKey& privateKey);
|
||||
|
||||
//==============================================================================
|
||||
/** This is a simple implementation of a key-generator that you could easily wrap in
|
||||
a command-line main() function for use on your server.
|
||||
|
||||
So for example you might use this in a command line app called "unlocker" and
|
||||
then call it like this:
|
||||
|
||||
unlocker MyGreatApp Joe_Bloggs joebloggs@foobar.com 1234abcd,95432ff 22d9aec92d986dd1,923ad49e9e7ff294c
|
||||
*/
|
||||
static inline int keyGenerationAppMain (int argc, char* argv[])
|
||||
{
|
||||
StringArray args;
|
||||
for (int i = 1; i < argc; ++i)
|
||||
args.add (argv[i]);
|
||||
|
||||
if (args.size() != 5)
|
||||
{
|
||||
std::cout << "Requires 5 arguments: app-name user-email username machine-numbers private-key" << std::endl
|
||||
<< " app-name: name of the product being unlocked" << std::endl
|
||||
<< " user-email: user's email address" << std::endl
|
||||
<< " username: name of the user. Careful not to allow any spaces!" << std::endl
|
||||
<< " 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
|
||||
<< " private-key: the RSA private key corresponding to the public key you've used in the app" << std::endl
|
||||
<< std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (! args[4].containsChar (','))
|
||||
{
|
||||
std::cout << "Not a valid RSA key!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << generateKeyFile (args[0], args[1], args[2], args[3], RSAKey (args[4])) << std::endl;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace juce
|
@ -0,0 +1,320 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2017 - ROLI Ltd.
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
|
||||
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
|
||||
27th April 2017).
|
||||
|
||||
End User License Agreement: www.juce.com/juce-5-licence
|
||||
Privacy Policy: www.juce.com/juce-5-privacy-policy
|
||||
|
||||
Or: You may also use this code under the terms of the GPL v3 (see
|
||||
www.gnu.org/licenses).
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
struct Spinner : public Component,
|
||||
private Timer
|
||||
{
|
||||
Spinner() { startTimer (1000 / 50); }
|
||||
void timerCallback() override { repaint(); }
|
||||
|
||||
void paint (Graphics& g) override
|
||||
{
|
||||
getLookAndFeel().drawSpinningWaitAnimation (g, Colours::darkgrey, 0, 0, getWidth(), getHeight());
|
||||
}
|
||||
};
|
||||
|
||||
struct OnlineUnlockForm::OverlayComp : public Component,
|
||||
private Thread,
|
||||
private Timer,
|
||||
private Button::Listener
|
||||
{
|
||||
OverlayComp (OnlineUnlockForm& f, bool hasCancelButton = false)
|
||||
: Thread (String()), form (f)
|
||||
{
|
||||
result.succeeded = false;
|
||||
email = form.emailBox.getText();
|
||||
password = form.passwordBox.getText();
|
||||
addAndMakeVisible (spinner);
|
||||
|
||||
if (hasCancelButton)
|
||||
{
|
||||
cancelButton.reset (new TextButton (TRANS ("Cancel")));
|
||||
addAndMakeVisible (cancelButton.get());
|
||||
cancelButton->addListener (this);
|
||||
}
|
||||
|
||||
startThread (4);
|
||||
}
|
||||
|
||||
~OverlayComp()
|
||||
{
|
||||
stopThread (10000);
|
||||
}
|
||||
|
||||
void paint (Graphics& g) override
|
||||
{
|
||||
g.fillAll (Colours::white.withAlpha (0.97f));
|
||||
|
||||
g.setColour (Colours::black);
|
||||
g.setFont (15.0f);
|
||||
|
||||
g.drawFittedText (TRANS("Contacting XYZ...").replace ("XYZ", form.status.getWebsiteName()),
|
||||
getLocalBounds().reduced (20, 0).removeFromTop (proportionOfHeight (0.6f)),
|
||||
Justification::centred, 5);
|
||||
}
|
||||
|
||||
void resized() override
|
||||
{
|
||||
const int spinnerSize = 40;
|
||||
spinner.setBounds ((getWidth() - spinnerSize) / 2, proportionOfHeight (0.6f), spinnerSize, spinnerSize);
|
||||
|
||||
if (cancelButton != nullptr)
|
||||
cancelButton->setBounds (getLocalBounds().removeFromBottom (50).reduced (getWidth() / 4, 5));
|
||||
}
|
||||
|
||||
void run() override
|
||||
{
|
||||
result = form.status.attemptWebserverUnlock (email, password);
|
||||
startTimer (100);
|
||||
}
|
||||
|
||||
void timerCallback() override
|
||||
{
|
||||
spinner.setVisible (false);
|
||||
stopTimer();
|
||||
|
||||
if (result.errorMessage.isNotEmpty())
|
||||
{
|
||||
AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
|
||||
TRANS("Registration Failed"),
|
||||
result.errorMessage);
|
||||
}
|
||||
else if (result.informativeMessage.isNotEmpty())
|
||||
{
|
||||
AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
|
||||
TRANS("Registration Complete!"),
|
||||
result.informativeMessage);
|
||||
}
|
||||
else if (result.urlToLaunch.isNotEmpty())
|
||||
{
|
||||
URL url (result.urlToLaunch);
|
||||
url.launchInDefaultBrowser();
|
||||
}
|
||||
|
||||
// (local copies because we're about to delete this)
|
||||
const bool worked = result.succeeded;
|
||||
OnlineUnlockForm& f = form;
|
||||
|
||||
delete this;
|
||||
|
||||
if (worked)
|
||||
f.dismiss();
|
||||
}
|
||||
|
||||
void buttonClicked (Button* button) override
|
||||
{
|
||||
if (button == cancelButton.get())
|
||||
{
|
||||
form.status.userCancelled();
|
||||
|
||||
spinner.setVisible (false);
|
||||
stopTimer();
|
||||
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
OnlineUnlockForm& form;
|
||||
Spinner spinner;
|
||||
OnlineUnlockStatus::UnlockResult result;
|
||||
String email, password;
|
||||
|
||||
std::unique_ptr<TextButton> cancelButton;
|
||||
|
||||
JUCE_LEAK_DETECTOR (OnlineUnlockForm::OverlayComp)
|
||||
};
|
||||
|
||||
static juce_wchar getDefaultPasswordChar() noexcept
|
||||
{
|
||||
#if JUCE_LINUX
|
||||
return 0x2022;
|
||||
#else
|
||||
return 0x25cf;
|
||||
#endif
|
||||
}
|
||||
|
||||
OnlineUnlockForm::OnlineUnlockForm (OnlineUnlockStatus& s,
|
||||
const String& userInstructions,
|
||||
bool hasCancelButton,
|
||||
bool overlayHasCancelButton)
|
||||
: message (String(), userInstructions),
|
||||
passwordBox (String(), getDefaultPasswordChar()),
|
||||
registerButton (TRANS("Register")),
|
||||
cancelButton (TRANS ("Cancel")),
|
||||
status (s),
|
||||
showOverlayCancelButton (overlayHasCancelButton)
|
||||
{
|
||||
// Please supply a message to tell your users what to do!
|
||||
jassert (userInstructions.isNotEmpty());
|
||||
|
||||
setOpaque (true);
|
||||
|
||||
emailBox.setText (status.getUserEmail());
|
||||
message.setJustificationType (Justification::centred);
|
||||
|
||||
addAndMakeVisible (message);
|
||||
addAndMakeVisible (emailBox);
|
||||
addAndMakeVisible (passwordBox);
|
||||
addAndMakeVisible (registerButton);
|
||||
|
||||
if (hasCancelButton)
|
||||
addAndMakeVisible (cancelButton);
|
||||
|
||||
emailBox.setEscapeAndReturnKeysConsumed (false);
|
||||
passwordBox.setEscapeAndReturnKeysConsumed (false);
|
||||
|
||||
registerButton.addShortcut (KeyPress (KeyPress::returnKey));
|
||||
|
||||
registerButton.addListener (this);
|
||||
cancelButton.addListener (this);
|
||||
|
||||
lookAndFeelChanged();
|
||||
setSize (500, 250);
|
||||
}
|
||||
|
||||
OnlineUnlockForm::~OnlineUnlockForm()
|
||||
{
|
||||
unlockingOverlay.deleteAndZero();
|
||||
}
|
||||
|
||||
void OnlineUnlockForm::paint (Graphics& g)
|
||||
{
|
||||
g.fillAll (Colours::lightgrey);
|
||||
}
|
||||
|
||||
void OnlineUnlockForm::resized()
|
||||
{
|
||||
/* If you're writing a plugin, then DO NOT USE A POP-UP A DIALOG WINDOW!
|
||||
Plugins that create external windows are incredibly annoying for users, and
|
||||
cause all sorts of headaches for hosts. Don't be the person who writes that
|
||||
plugin that irritates everyone with a nagging dialog box every time they scan!
|
||||
*/
|
||||
jassert (JUCEApplicationBase::isStandaloneApp() || findParentComponentOfClass<DialogWindow>() == nullptr);
|
||||
|
||||
const int buttonHeight = 22;
|
||||
|
||||
Rectangle<int> r (getLocalBounds().reduced (10, 20));
|
||||
|
||||
Rectangle<int> buttonArea (r.removeFromBottom (buttonHeight));
|
||||
registerButton.changeWidthToFitText (buttonHeight);
|
||||
cancelButton.changeWidthToFitText (buttonHeight);
|
||||
|
||||
const int gap = 20;
|
||||
buttonArea = buttonArea.withSizeKeepingCentre (registerButton.getWidth()
|
||||
+ (cancelButton.isVisible() ? gap + cancelButton.getWidth() : 0),
|
||||
buttonHeight);
|
||||
registerButton.setBounds (buttonArea.removeFromLeft (registerButton.getWidth()));
|
||||
buttonArea.removeFromLeft (gap);
|
||||
cancelButton.setBounds (buttonArea);
|
||||
|
||||
r.removeFromBottom (20);
|
||||
|
||||
// (force use of a default system font to make sure it has the password blob character)
|
||||
Font font (Font::getDefaultTypefaceForFont (Font (Font::getDefaultSansSerifFontName(),
|
||||
Font::getDefaultStyle(),
|
||||
5.0f)));
|
||||
|
||||
const int boxHeight = 24;
|
||||
passwordBox.setBounds (r.removeFromBottom (boxHeight));
|
||||
passwordBox.setInputRestrictions (64);
|
||||
passwordBox.setFont (font);
|
||||
|
||||
r.removeFromBottom (20);
|
||||
emailBox.setBounds (r.removeFromBottom (boxHeight));
|
||||
emailBox.setInputRestrictions (512);
|
||||
emailBox.setFont (font);
|
||||
|
||||
r.removeFromBottom (20);
|
||||
|
||||
message.setBounds (r);
|
||||
|
||||
if (unlockingOverlay != nullptr)
|
||||
unlockingOverlay->setBounds (getLocalBounds());
|
||||
}
|
||||
|
||||
void OnlineUnlockForm::lookAndFeelChanged()
|
||||
{
|
||||
Colour labelCol (findColour (TextEditor::backgroundColourId).contrasting (0.5f));
|
||||
|
||||
emailBox.setTextToShowWhenEmpty (TRANS("Email Address"), labelCol);
|
||||
passwordBox.setTextToShowWhenEmpty (TRANS("Password"), labelCol);
|
||||
}
|
||||
|
||||
void OnlineUnlockForm::showBubbleMessage (const String& text, Component& target)
|
||||
{
|
||||
bubble.reset (new BubbleMessageComponent (500));
|
||||
addChildComponent (bubble.get());
|
||||
|
||||
AttributedString attString;
|
||||
attString.append (text, Font (16.0f));
|
||||
|
||||
bubble->showAt (getLocalArea (&target, target.getLocalBounds()),
|
||||
attString, 500, // numMillisecondsBeforeRemoving
|
||||
true, // removeWhenMouseClicked
|
||||
false); // deleteSelfAfterUse
|
||||
}
|
||||
|
||||
void OnlineUnlockForm::buttonClicked (Button* b)
|
||||
{
|
||||
if (b == ®isterButton)
|
||||
attemptRegistration();
|
||||
else if (b == &cancelButton)
|
||||
dismiss();
|
||||
}
|
||||
|
||||
void OnlineUnlockForm::attemptRegistration()
|
||||
{
|
||||
if (unlockingOverlay == nullptr)
|
||||
{
|
||||
if (emailBox.getText().trim().length() < 3)
|
||||
{
|
||||
showBubbleMessage (TRANS ("Please enter a valid email address!"), emailBox);
|
||||
return;
|
||||
}
|
||||
|
||||
if (passwordBox.getText().trim().length() < 3)
|
||||
{
|
||||
showBubbleMessage (TRANS ("Please enter a valid password!"), passwordBox);
|
||||
return;
|
||||
}
|
||||
|
||||
status.setUserEmail (emailBox.getText());
|
||||
|
||||
addAndMakeVisible (unlockingOverlay = new OverlayComp (*this, showOverlayCancelButton));
|
||||
resized();
|
||||
unlockingOverlay->enterModalState();
|
||||
}
|
||||
}
|
||||
|
||||
void OnlineUnlockForm::dismiss()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
} // namespace juce
|
@ -0,0 +1,100 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2017 - ROLI Ltd.
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
|
||||
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
|
||||
27th April 2017).
|
||||
|
||||
End User License Agreement: www.juce.com/juce-5-licence
|
||||
Privacy Policy: www.juce.com/juce-5-privacy-policy
|
||||
|
||||
Or: You may also use this code under the terms of the GPL v3 (see
|
||||
www.gnu.org/licenses).
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
/** Acts as a GUI which asks the user for their details, and calls the approriate
|
||||
methods on your OnlineUnlockStatus object to attempt to register the app.
|
||||
|
||||
You should create one of these components and add it to your parent window,
|
||||
or use a DialogWindow to display it as a pop-up. But if you're writing a plugin,
|
||||
then DO NOT USE A DIALOG WINDOW! Add it as a child component of your plugin's editor
|
||||
component instead. Plugins that pop up external registration windows are incredibly
|
||||
annoying, and cause all sorts of headaches for hosts. Don't be the person who
|
||||
writes that plugin that irritates everyone with a dialog box every time they
|
||||
try to scan for new plugins!
|
||||
|
||||
Note that after adding it, you should put the component into a modal state,
|
||||
and it will automatically delete itself when it has completed.
|
||||
|
||||
Although it deletes itself, it's also OK to delete it manually yourself
|
||||
if you need to get rid of it sooner.
|
||||
|
||||
@see OnlineUnlockStatus
|
||||
|
||||
@tags{ProductUnlocking}
|
||||
*/
|
||||
class JUCE_API OnlineUnlockForm : public Component,
|
||||
private Button::Listener
|
||||
{
|
||||
public:
|
||||
/** Creates an unlock form that will work with the given status object.
|
||||
The userInstructions will be displayed above the email and password boxes.
|
||||
*/
|
||||
OnlineUnlockForm (OnlineUnlockStatus&,
|
||||
const String& userInstructions,
|
||||
bool hasCancelButton = true,
|
||||
bool overlayHasCancelButton = false);
|
||||
|
||||
/** Destructor. */
|
||||
~OnlineUnlockForm();
|
||||
|
||||
/** This is called when the form is dismissed (either cancelled or when registration
|
||||
succeeds).
|
||||
By default it will delete this, but you can override it to do other things.
|
||||
*/
|
||||
virtual void dismiss();
|
||||
|
||||
/** @internal */
|
||||
void paint (Graphics&) override;
|
||||
/** @internal */
|
||||
void resized() override;
|
||||
/** @internal */
|
||||
void lookAndFeelChanged() override;
|
||||
|
||||
Label message;
|
||||
TextEditor emailBox, passwordBox;
|
||||
TextButton registerButton, cancelButton;
|
||||
|
||||
private:
|
||||
OnlineUnlockStatus& status;
|
||||
std::unique_ptr<BubbleMessageComponent> bubble;
|
||||
|
||||
bool showOverlayCancelButton;
|
||||
|
||||
struct OverlayComp;
|
||||
friend struct OverlayComp;
|
||||
Component::SafePointer<Component> unlockingOverlay;
|
||||
|
||||
void buttonClicked (Button*) override;
|
||||
void attemptRegistration();
|
||||
void showBubbleMessage (const String&, Component&);
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OnlineUnlockForm)
|
||||
};
|
||||
|
||||
} // namespace juce
|
@ -0,0 +1,496 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2017 - ROLI Ltd.
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
|
||||
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
|
||||
27th April 2017).
|
||||
|
||||
End User License Agreement: www.juce.com/juce-5-licence
|
||||
Privacy Policy: www.juce.com/juce-5-privacy-policy
|
||||
|
||||
Or: You may also use this code under the terms of the GPL v3 (see
|
||||
www.gnu.org/licenses).
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
/* Note: there's a bit of light obfuscation in this code, just to make things
|
||||
a bit more annoying for crackers who try to reverse-engineer your binaries, but
|
||||
nothing particularly foolproof.
|
||||
*/
|
||||
|
||||
struct KeyFileUtils
|
||||
{
|
||||
static XmlElement createKeyFileContent (const String& appName,
|
||||
const String& userEmail,
|
||||
const String& userName,
|
||||
const String& machineNumbers,
|
||||
const String& machineNumbersAttributeName)
|
||||
{
|
||||
XmlElement xml ("key");
|
||||
|
||||
xml.setAttribute ("user", userName);
|
||||
xml.setAttribute ("email", userEmail);
|
||||
xml.setAttribute (machineNumbersAttributeName, machineNumbers);
|
||||
xml.setAttribute ("app", appName);
|
||||
xml.setAttribute ("date", String::toHexString (Time::getCurrentTime().toMilliseconds()));
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
||||
static String createKeyFileComment (const String& appName,
|
||||
const String& userEmail,
|
||||
const String& userName,
|
||||
const String& machineNumbers)
|
||||
{
|
||||
String comment;
|
||||
comment << "Keyfile for " << appName << newLine;
|
||||
|
||||
if (userName.isNotEmpty())
|
||||
comment << "User: " << userName << newLine;
|
||||
|
||||
comment << "Email: " << userEmail << newLine
|
||||
<< "Machine numbers: " << machineNumbers << newLine
|
||||
<< "Created: " << Time::getCurrentTime().toString (true, true);
|
||||
|
||||
return comment;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
static String encryptXML (const XmlElement& xml, RSAKey privateKey)
|
||||
{
|
||||
MemoryOutputStream text;
|
||||
text << xml.createDocument (StringRef(), true);
|
||||
|
||||
BigInteger val;
|
||||
val.loadFromMemoryBlock (text.getMemoryBlock());
|
||||
|
||||
privateKey.applyToValue (val);
|
||||
|
||||
return val.toString (16);
|
||||
}
|
||||
|
||||
static String createKeyFile (String comment,
|
||||
const XmlElement& xml,
|
||||
RSAKey rsaPrivateKey)
|
||||
{
|
||||
String asHex ("#" + encryptXML (xml, rsaPrivateKey));
|
||||
|
||||
StringArray lines;
|
||||
lines.add (comment);
|
||||
lines.add (String());
|
||||
|
||||
const int charsPerLine = 70;
|
||||
while (asHex.length() > 0)
|
||||
{
|
||||
lines.add (asHex.substring (0, charsPerLine));
|
||||
asHex = asHex.substring (charsPerLine);
|
||||
}
|
||||
|
||||
lines.add (String());
|
||||
|
||||
return lines.joinIntoString ("\r\n");
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
static XmlElement decryptXML (String hexData, RSAKey rsaPublicKey)
|
||||
{
|
||||
BigInteger val;
|
||||
val.parseString (hexData, 16);
|
||||
|
||||
RSAKey key (rsaPublicKey);
|
||||
jassert (key.isValid());
|
||||
|
||||
std::unique_ptr<XmlElement> xml;
|
||||
|
||||
if (! val.isZero())
|
||||
{
|
||||
key.applyToValue (val);
|
||||
|
||||
const MemoryBlock mb (val.toMemoryBlock());
|
||||
|
||||
if (CharPointer_UTF8::isValidString (static_cast<const char*> (mb.getData()), (int) mb.getSize()))
|
||||
xml.reset (XmlDocument::parse (mb.toString()));
|
||||
}
|
||||
|
||||
return xml != nullptr ? *xml : XmlElement("key");
|
||||
}
|
||||
|
||||
static XmlElement getXmlFromKeyFile (String keyFileText, RSAKey rsaPublicKey)
|
||||
{
|
||||
return decryptXML (keyFileText.fromLastOccurrenceOf ("#", false, false).trim(), rsaPublicKey);
|
||||
}
|
||||
|
||||
static StringArray getMachineNumbers (XmlElement xml, StringRef attributeName)
|
||||
{
|
||||
StringArray numbers;
|
||||
numbers.addTokens (xml.getStringAttribute (attributeName), ",; ", StringRef());
|
||||
numbers.trim();
|
||||
numbers.removeEmptyStrings();
|
||||
return numbers;
|
||||
}
|
||||
|
||||
static String getLicensee (const XmlElement& xml) { return xml.getStringAttribute ("user"); }
|
||||
static String getEmail (const XmlElement& xml) { return xml.getStringAttribute ("email"); }
|
||||
static String getAppID (const XmlElement& xml) { return xml.getStringAttribute ("app"); }
|
||||
|
||||
struct KeyFileData
|
||||
{
|
||||
String licensee, email, appID;
|
||||
StringArray machineNumbers;
|
||||
|
||||
bool keyFileExpires;
|
||||
Time expiryTime;
|
||||
};
|
||||
|
||||
static KeyFileData getDataFromKeyFile (XmlElement xml)
|
||||
{
|
||||
KeyFileData data;
|
||||
|
||||
data.licensee = getLicensee (xml);
|
||||
data.email = getEmail (xml);
|
||||
data.appID = getAppID (xml);
|
||||
|
||||
if (xml.hasAttribute ("expiryTime") && xml.hasAttribute ("expiring_mach"))
|
||||
{
|
||||
data.keyFileExpires = true;
|
||||
data.machineNumbers.addArray (getMachineNumbers (xml, "expiring_mach"));
|
||||
data.expiryTime = Time (xml.getStringAttribute ("expiryTime").getHexValue64());
|
||||
}
|
||||
else
|
||||
{
|
||||
data.keyFileExpires = false;
|
||||
data.machineNumbers.addArray (getMachineNumbers (xml, "mach"));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
#if JUCE_MODULE_AVAILABLE_juce_data_structures
|
||||
const char* OnlineUnlockStatus::unlockedProp = "u";
|
||||
const char* OnlineUnlockStatus::expiryTimeProp = "t";
|
||||
static const char* stateTagName = "REG";
|
||||
static const char* userNameProp = "user";
|
||||
static const char* keyfileDataProp = "key";
|
||||
|
||||
static var machineNumberAllowed (StringArray numbersFromKeyFile,
|
||||
StringArray localMachineNumbers)
|
||||
{
|
||||
var result;
|
||||
|
||||
for (int i = 0; i < localMachineNumbers.size(); ++i)
|
||||
{
|
||||
String localNumber (localMachineNumbers[i].trim());
|
||||
|
||||
if (localNumber.isNotEmpty())
|
||||
{
|
||||
for (int j = numbersFromKeyFile.size(); --j >= 0;)
|
||||
{
|
||||
var ok (localNumber.trim().equalsIgnoreCase (numbersFromKeyFile[j].trim()));
|
||||
result.swapWith (ok);
|
||||
|
||||
if (result)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
OnlineUnlockStatus::OnlineUnlockStatus() : status (stateTagName)
|
||||
{
|
||||
}
|
||||
|
||||
OnlineUnlockStatus::~OnlineUnlockStatus()
|
||||
{
|
||||
}
|
||||
|
||||
void OnlineUnlockStatus::load()
|
||||
{
|
||||
MemoryBlock mb;
|
||||
mb.fromBase64Encoding (getState());
|
||||
|
||||
if (mb.getSize() > 0)
|
||||
status = ValueTree::readFromGZIPData (mb.getData(), mb.getSize());
|
||||
else
|
||||
status = ValueTree (stateTagName);
|
||||
|
||||
StringArray localMachineNums (getLocalMachineIDs());
|
||||
|
||||
if (machineNumberAllowed (StringArray ("1234"), localMachineNums))
|
||||
status.removeProperty (unlockedProp, nullptr);
|
||||
|
||||
KeyFileUtils::KeyFileData data;
|
||||
data = KeyFileUtils::getDataFromKeyFile (KeyFileUtils::getXmlFromKeyFile (status[keyfileDataProp], getPublicKey()));
|
||||
|
||||
if (data.keyFileExpires)
|
||||
{
|
||||
if (! doesProductIDMatch (data.appID))
|
||||
status.removeProperty (expiryTimeProp, nullptr);
|
||||
|
||||
if (! machineNumberAllowed (data.machineNumbers, localMachineNums))
|
||||
status.removeProperty (expiryTimeProp, nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! doesProductIDMatch (data.appID))
|
||||
status.removeProperty (unlockedProp, nullptr);
|
||||
|
||||
if (! machineNumberAllowed (data.machineNumbers, localMachineNums))
|
||||
status.removeProperty (unlockedProp, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void OnlineUnlockStatus::save()
|
||||
{
|
||||
MemoryOutputStream mo;
|
||||
|
||||
{
|
||||
GZIPCompressorOutputStream gzipStream (mo, 9);
|
||||
status.writeToStream (gzipStream);
|
||||
}
|
||||
|
||||
saveState (mo.getMemoryBlock().toBase64Encoding());
|
||||
}
|
||||
|
||||
char OnlineUnlockStatus::MachineIDUtilities::getPlatformPrefix()
|
||||
{
|
||||
#if JUCE_MAC
|
||||
return 'M';
|
||||
#elif JUCE_WINDOWS
|
||||
return 'W';
|
||||
#elif JUCE_LINUX
|
||||
return 'L';
|
||||
#elif JUCE_IOS
|
||||
return 'I';
|
||||
#elif JUCE_ANDROID
|
||||
return 'A';
|
||||
#endif
|
||||
}
|
||||
|
||||
String OnlineUnlockStatus::MachineIDUtilities::getEncodedIDString (const String& input)
|
||||
{
|
||||
const String platform (String::charToString (static_cast<juce_wchar> (getPlatformPrefix())));
|
||||
|
||||
return platform + MD5 ((input + "salt_1" + platform).toUTF8())
|
||||
.toHexString().substring (0, 9).toUpperCase();
|
||||
}
|
||||
|
||||
bool OnlineUnlockStatus::MachineIDUtilities::addFileIDToList (StringArray& ids, const File& f)
|
||||
{
|
||||
if (uint64 num = f.getFileIdentifier())
|
||||
{
|
||||
ids.add (getEncodedIDString (String::toHexString ((int64) num)));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void OnlineUnlockStatus::MachineIDUtilities::addMACAddressesToList (StringArray& ids)
|
||||
{
|
||||
Array<MACAddress> addresses;
|
||||
MACAddress::findAllAddresses (addresses);
|
||||
|
||||
for (int i = 0; i < addresses.size(); ++i)
|
||||
ids.add (getEncodedIDString (addresses.getReference(i).toString()));
|
||||
}
|
||||
|
||||
StringArray OnlineUnlockStatus::MachineIDUtilities::getLocalMachineIDs()
|
||||
{
|
||||
auto identifiers = SystemStats::getDeviceIdentifiers();
|
||||
for (auto& identifier : identifiers)
|
||||
identifier = getEncodedIDString (identifier);
|
||||
|
||||
return identifiers;
|
||||
}
|
||||
|
||||
StringArray OnlineUnlockStatus::getLocalMachineIDs()
|
||||
{
|
||||
return MachineIDUtilities::getLocalMachineIDs();
|
||||
}
|
||||
|
||||
void OnlineUnlockStatus::userCancelled()
|
||||
{
|
||||
}
|
||||
|
||||
void OnlineUnlockStatus::setUserEmail (const String& usernameOrEmail)
|
||||
{
|
||||
status.setProperty (userNameProp, usernameOrEmail, nullptr);
|
||||
}
|
||||
|
||||
String OnlineUnlockStatus::getUserEmail() const
|
||||
{
|
||||
return status[userNameProp].toString();
|
||||
}
|
||||
|
||||
bool OnlineUnlockStatus::applyKeyFile (String keyFileContent)
|
||||
{
|
||||
KeyFileUtils::KeyFileData data;
|
||||
data = KeyFileUtils::getDataFromKeyFile (KeyFileUtils::getXmlFromKeyFile (keyFileContent, getPublicKey()));
|
||||
|
||||
if (data.licensee.isNotEmpty() && data.email.isNotEmpty() && doesProductIDMatch (data.appID))
|
||||
{
|
||||
setUserEmail (data.email);
|
||||
status.setProperty (keyfileDataProp, keyFileContent, nullptr);
|
||||
status.removeProperty (data.keyFileExpires ? expiryTimeProp : unlockedProp, nullptr);
|
||||
|
||||
var actualResult (0), dummyResult (1.0);
|
||||
var v (machineNumberAllowed (data.machineNumbers, getLocalMachineIDs()));
|
||||
actualResult.swapWith (v);
|
||||
v = machineNumberAllowed (StringArray ("01"), getLocalMachineIDs());
|
||||
dummyResult.swapWith (v);
|
||||
jassert (! dummyResult);
|
||||
|
||||
if (data.keyFileExpires)
|
||||
{
|
||||
if ((! dummyResult) && actualResult)
|
||||
status.setProperty (expiryTimeProp, data.expiryTime.toMilliseconds(), nullptr);
|
||||
|
||||
return getExpiryTime().toMilliseconds() > 0;
|
||||
}
|
||||
|
||||
if ((! dummyResult) && actualResult)
|
||||
status.setProperty (unlockedProp, actualResult, nullptr);
|
||||
|
||||
return isUnlocked();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool canConnectToWebsite (const URL& url)
|
||||
{
|
||||
std::unique_ptr<InputStream> in (url.createInputStream (false, nullptr, nullptr, String(), 2000, nullptr));
|
||||
return in != nullptr;
|
||||
}
|
||||
|
||||
static bool areMajorWebsitesAvailable()
|
||||
{
|
||||
const char* urlsToTry[] = { "http://google.com", "http://bing.com", "http://amazon.com",
|
||||
"https://google.com", "https://bing.com", "https://amazon.com", nullptr};
|
||||
|
||||
for (const char** url = urlsToTry; *url != nullptr; ++url)
|
||||
if (canConnectToWebsite (URL (*url)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
OnlineUnlockStatus::UnlockResult OnlineUnlockStatus::handleXmlReply (XmlElement xml)
|
||||
{
|
||||
UnlockResult r;
|
||||
|
||||
if (const XmlElement* keyNode = xml.getChildByName ("KEY"))
|
||||
{
|
||||
const String keyText (keyNode->getAllSubText().trim());
|
||||
r.succeeded = keyText.length() > 10 && applyKeyFile (keyText);
|
||||
}
|
||||
else
|
||||
{
|
||||
r.succeeded = false;
|
||||
}
|
||||
|
||||
if (xml.hasTagName ("MESSAGE"))
|
||||
r.informativeMessage = xml.getStringAttribute ("message").trim();
|
||||
|
||||
if (xml.hasTagName ("ERROR"))
|
||||
r.errorMessage = xml.getStringAttribute ("error").trim();
|
||||
|
||||
if (xml.getStringAttribute ("url").isNotEmpty())
|
||||
r.urlToLaunch = xml.getStringAttribute ("url").trim();
|
||||
|
||||
if (r.errorMessage.isEmpty() && r.informativeMessage.isEmpty() && r.urlToLaunch.isEmpty() && ! r.succeeded)
|
||||
r.errorMessage = TRANS ("Unexpected or corrupted reply from XYZ").replace ("XYZ", getWebsiteName()) + "...\n\n"
|
||||
+ TRANS("Please try again in a few minutes, and contact us for support if this message appears again.");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
OnlineUnlockStatus::UnlockResult OnlineUnlockStatus::handleFailedConnection()
|
||||
{
|
||||
UnlockResult r;
|
||||
r.succeeded = false;
|
||||
|
||||
r.errorMessage = TRANS("Couldn't connect to XYZ").replace ("XYZ", getWebsiteName()) + "...\n\n";
|
||||
|
||||
if (areMajorWebsitesAvailable())
|
||||
r.errorMessage << TRANS("Your internet connection seems to be OK, but our webserver "
|
||||
"didn't respond... This is most likely a temporary problem, so try "
|
||||
"again in a few minutes, but if it persists, please contact us for support!");
|
||||
else
|
||||
r.errorMessage << TRANS("No internet sites seem to be accessible from your computer.. Before trying again, "
|
||||
"please check that your network is working correctly, and make sure "
|
||||
"that any firewall/security software installed on your machine isn't "
|
||||
"blocking your web connection.");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
OnlineUnlockStatus::UnlockResult OnlineUnlockStatus::attemptWebserverUnlock (const String& email,
|
||||
const String& password)
|
||||
{
|
||||
// This method will block while it contacts the server, so you must run it on a background thread!
|
||||
jassert (! MessageManager::getInstance()->isThisTheMessageThread());
|
||||
|
||||
String reply (readReplyFromWebserver (email, password));
|
||||
|
||||
DBG ("Reply from server: " << reply);
|
||||
|
||||
std::unique_ptr<XmlElement> xml (XmlDocument::parse (reply));
|
||||
|
||||
if (xml != nullptr)
|
||||
return handleXmlReply (*xml);
|
||||
|
||||
return handleFailedConnection();
|
||||
}
|
||||
|
||||
#endif // JUCE_MODULE_AVAILABLE_juce_data_structures
|
||||
|
||||
//==============================================================================
|
||||
String KeyGeneration::generateKeyFile (const String& appName,
|
||||
const String& userEmail,
|
||||
const String& userName,
|
||||
const String& machineNumbers,
|
||||
const RSAKey& privateKey)
|
||||
{
|
||||
XmlElement xml (KeyFileUtils::createKeyFileContent (appName, userEmail, userName, machineNumbers, "mach"));
|
||||
const String comment (KeyFileUtils::createKeyFileComment (appName, userEmail, userName, machineNumbers));
|
||||
|
||||
return KeyFileUtils::createKeyFile (comment, xml, privateKey);
|
||||
}
|
||||
|
||||
String KeyGeneration::generateExpiringKeyFile (const String& appName,
|
||||
const String& userEmail,
|
||||
const String& userName,
|
||||
const String& machineNumbers,
|
||||
const Time expiryTime,
|
||||
const RSAKey& privateKey)
|
||||
{
|
||||
XmlElement xml (KeyFileUtils::createKeyFileContent (appName, userEmail, userName, machineNumbers, "expiring_mach"));
|
||||
xml.setAttribute ("expiryTime", String::toHexString (expiryTime.toMilliseconds()));
|
||||
|
||||
String comment (KeyFileUtils::createKeyFileComment (appName, userEmail, userName, machineNumbers));
|
||||
comment << newLine << "Expires: " << expiryTime.toString (true, true);
|
||||
|
||||
return KeyFileUtils::createKeyFile (comment, xml, privateKey);
|
||||
}
|
||||
|
||||
} // namespace juce
|
@ -0,0 +1,275 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2017 - ROLI Ltd.
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
|
||||
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
|
||||
27th April 2017).
|
||||
|
||||
End User License Agreement: www.juce.com/juce-5-licence
|
||||
Privacy Policy: www.juce.com/juce-5-privacy-policy
|
||||
|
||||
Or: You may also use this code under the terms of the GPL v3 (see
|
||||
www.gnu.org/licenses).
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
/**
|
||||
A base class for online unlocking systems.
|
||||
|
||||
This class stores information about whether your app has been unlocked for the
|
||||
current machine, and handles communication with a web-store to perform the
|
||||
unlock procedure.
|
||||
|
||||
You probably won't ever use this base class directly, but rather a store-specific
|
||||
subclass such as TracktionMarketplaceStatus, which knows how to talk to the particular
|
||||
online store that you're using.
|
||||
|
||||
To use it, you create a subclass which implements all the pure virtual methods
|
||||
(see their comments to find out what you'll need to make them do).
|
||||
|
||||
Then you can create an instance of your subclass which will hold the registration
|
||||
state. Typically, you'll want to just keep a single instance of the class around for
|
||||
the duration of your app. You can then call its methods to handle the various
|
||||
registration tasks.
|
||||
|
||||
Areas of your code that need to know whether the user is registered (e.g. to decide
|
||||
whether a particular feature is available) should call isUnlocked() to find out.
|
||||
|
||||
If you want to create a GUI that allows your users to enter their details and
|
||||
register, see the OnlineUnlockForm class.
|
||||
|
||||
@see OnlineUnlockForm, KeyGeneration
|
||||
|
||||
@tags{ProductUnlocking}
|
||||
*/
|
||||
class JUCE_API OnlineUnlockStatus
|
||||
{
|
||||
public:
|
||||
OnlineUnlockStatus();
|
||||
|
||||
/** Destructor. */
|
||||
virtual ~OnlineUnlockStatus();
|
||||
|
||||
//==============================================================================
|
||||
/** This must return your product's ID, as allocated by the store. */
|
||||
virtual String getProductID() = 0;
|
||||
|
||||
/** This must check whether a product ID string that the server returned is OK for
|
||||
unlocking the current app.
|
||||
*/
|
||||
virtual bool doesProductIDMatch (const String& returnedIDFromServer) = 0;
|
||||
|
||||
/** This must return the RSA public key for authenticating responses from
|
||||
the server for this app. You can get this key from your marketplace
|
||||
account page.
|
||||
*/
|
||||
virtual RSAKey getPublicKey() = 0;
|
||||
|
||||
/** This method must store the given string somewhere in your app's
|
||||
persistent properties, so it can be retrieved later by getState().
|
||||
*/
|
||||
virtual void saveState (const String&) = 0;
|
||||
|
||||
/** This method must retrieve the last state that was provided by the
|
||||
saveState method.
|
||||
|
||||
On first-run, it should just return an empty string.
|
||||
*/
|
||||
virtual String getState() = 0;
|
||||
|
||||
/** Returns the name of the web-store website, not for communication, but for
|
||||
presenting to the user.
|
||||
*/
|
||||
virtual String getWebsiteName() = 0;
|
||||
|
||||
/** Returns the URL of the authentication API. */
|
||||
virtual URL getServerAuthenticationURL() = 0;
|
||||
|
||||
/** Subclasses that talk to a particular web-store will implement this method
|
||||
to contact their webserver and attempt to unlock the current machine for
|
||||
the given username and password. The return value is the XML text from the
|
||||
server which contains error information and/or the encrypted keyfile.
|
||||
*/
|
||||
virtual String readReplyFromWebserver (const String& email, const String& password) = 0;
|
||||
|
||||
/** Returns a list of strings, any of which should be unique to this
|
||||
physical computer.
|
||||
|
||||
When testing whether the user is allowed to use the product on this
|
||||
machine, this list of tokens is compared to the ones that were stored
|
||||
on the webserver.
|
||||
|
||||
The default implementation of this method will simply call
|
||||
MachineIDUtilities::getLocalMachineIDs(), which provides a default
|
||||
version of this functionality.
|
||||
*/
|
||||
virtual StringArray getLocalMachineIDs();
|
||||
|
||||
/** This method will be called if the user cancels the connection to the webserver
|
||||
by clicking the cancel button in OnlineUnlockForm::OverlayComp.
|
||||
|
||||
The default implementation of this method does nothing but you should use it to
|
||||
cancel any WebInputStreams that may be connecting.
|
||||
*/
|
||||
virtual void userCancelled();
|
||||
|
||||
//==============================================================================
|
||||
// The following methods can be called by your app:
|
||||
|
||||
/** Returns true if the product has been successfully authorised for this machine.
|
||||
|
||||
The reason it returns a variant rather than a bool is just to make it marginally
|
||||
more tedious for crackers to work around. Hopefully if this method gets inlined
|
||||
they'll need to hack all the places where you call it, rather than just the
|
||||
function itself.
|
||||
|
||||
Bear in mind that each place where you check this return value will need to be
|
||||
changed by a cracker in order to unlock your app, so the more places you call this
|
||||
method, the more hassle it will be for them to find and crack them all.
|
||||
*/
|
||||
inline var isUnlocked() const { return status[unlockedProp]; }
|
||||
|
||||
/** Returns the Time when the keyfile expires.
|
||||
|
||||
If a the key file obtained has an expiry time, isUnlocked will return false and this
|
||||
will return a non-zero time. The interpretation of this is up to your app but could
|
||||
be used for subscription based models or trial periods.
|
||||
*/
|
||||
inline Time getExpiryTime() const { return Time (static_cast<int64> (status[expiryTimeProp])); }
|
||||
|
||||
/** Optionally allows the app to provide the user's email address if
|
||||
it is known.
|
||||
You don't need to call this, but if you do it may save the user
|
||||
typing it in.
|
||||
*/
|
||||
void setUserEmail (const String& usernameOrEmail);
|
||||
|
||||
/** Returns the user's email address if known. */
|
||||
String getUserEmail() const;
|
||||
|
||||
/** Attempts to perform an unlock using a block of key-file data provided.
|
||||
You may wish to use this as a way of allowing a user to unlock your app
|
||||
by drag-and-dropping a file containing the key data, or by letting them
|
||||
select such a file. This is often needed for allowing registration on
|
||||
machines without internet access.
|
||||
*/
|
||||
bool applyKeyFile (String keyFileContent);
|
||||
|
||||
/** This provides some details about the reply that the server gave in a call
|
||||
to attemptWebserverUnlock().
|
||||
*/
|
||||
struct UnlockResult
|
||||
{
|
||||
/** If an unlock operation fails, this is the error message that the webserver
|
||||
supplied (or a message saying that the server couldn't be contacted)
|
||||
*/
|
||||
String errorMessage;
|
||||
|
||||
/** This is a message that the webserver returned, and which the user should
|
||||
be shown.
|
||||
|
||||
It's not necessarily an error message, e.g. it might say that there's a
|
||||
new version of the app available or some other status update.
|
||||
*/
|
||||
String informativeMessage;
|
||||
|
||||
/** If the webserver wants the user to be directed to a web-page for further
|
||||
information, this is the URL that it would like them to go to.
|
||||
*/
|
||||
String urlToLaunch;
|
||||
|
||||
/** If the unlock operation succeeded, this will be set to true. */
|
||||
bool succeeded;
|
||||
};
|
||||
|
||||
/** Contacts the webserver and attempts to perform a registration with the
|
||||
given user details.
|
||||
|
||||
The return value will either be a success, or a failure with an error message
|
||||
from the server, so you should show this message to your user.
|
||||
|
||||
Because this method blocks while it contacts the server, you must run it on
|
||||
a background thread, not on the message thread. For an easier way to create
|
||||
a GUI to do the unlocking, see OnlineUnlockForm.
|
||||
*/
|
||||
UnlockResult attemptWebserverUnlock (const String& email, const String& password);
|
||||
|
||||
/** Attempts to load the status from the state retrieved by getState().
|
||||
Call this somewhere in your app's startup code.
|
||||
*/
|
||||
void load();
|
||||
|
||||
/** Triggers a call to saveState which you can use to store the current unlock status
|
||||
in your app's settings.
|
||||
*/
|
||||
void save();
|
||||
|
||||
/** This class contains some utility functions that might help with machine ID generation. */
|
||||
struct MachineIDUtilities
|
||||
{
|
||||
/** Returns a character that represents the current OS.
|
||||
E.g. 'M' for Mac, 'W' for windows, etc
|
||||
*/
|
||||
static char getPlatformPrefix();
|
||||
|
||||
/** Returns an encoded hash string from the given input string, prefixing it with
|
||||
a letter to represent the current OS type.
|
||||
*/
|
||||
static String getEncodedIDString (const String& inputString);
|
||||
|
||||
/** Utility function that you may want to use in your machine-ID generation code.
|
||||
This adds an ID string to the given array which is a hash of the filesystem ID of the
|
||||
given file.
|
||||
*/
|
||||
static bool addFileIDToList (StringArray& result, const File& file);
|
||||
|
||||
/** Utility function that you may want to use in your machine-ID generation code.
|
||||
This adds some ID strings to the given array which represent each MAC address of the machine.
|
||||
*/
|
||||
static void addMACAddressesToList (StringArray& result);
|
||||
|
||||
/** This method calculates some machine IDs based on things like network
|
||||
MAC addresses, hard-disk IDs, etc, but if you want, you can overload
|
||||
it to generate your own list of IDs.
|
||||
|
||||
The IDs that are returned should be short alphanumeric strings
|
||||
without any punctuation characters. Since users may need to type
|
||||
them, case is ignored when comparing them.
|
||||
|
||||
Note that the first item in the list is considered to be the
|
||||
"main" ID, and this will be the one that is displayed to the user
|
||||
and registered with the marketplace webserver. Subsequent IDs are
|
||||
just used as fallback to avoid false negatives when checking for
|
||||
registration on machines which have had hardware added/removed
|
||||
since the product was first registered.
|
||||
*/
|
||||
static StringArray getLocalMachineIDs();
|
||||
};
|
||||
|
||||
private:
|
||||
ValueTree status;
|
||||
|
||||
UnlockResult handleXmlReply (XmlElement);
|
||||
UnlockResult handleFailedConnection();
|
||||
|
||||
static const char* unlockedProp;
|
||||
static const char* expiryTimeProp;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OnlineUnlockStatus)
|
||||
};
|
||||
|
||||
} // namespace juce
|
@ -0,0 +1,109 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2017 - ROLI Ltd.
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
|
||||
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
|
||||
27th April 2017).
|
||||
|
||||
End User License Agreement: www.juce.com/juce-5-licence
|
||||
Privacy Policy: www.juce.com/juce-5-privacy-policy
|
||||
|
||||
Or: You may also use this code under the terms of the GPL v3 (see
|
||||
www.gnu.org/licenses).
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
TracktionMarketplaceStatus::TracktionMarketplaceStatus() {}
|
||||
|
||||
URL TracktionMarketplaceStatus::getServerAuthenticationURL()
|
||||
{
|
||||
return URL ("https://www.tracktion.com/marketplace/authenticate.php");
|
||||
}
|
||||
|
||||
String TracktionMarketplaceStatus::getWebsiteName()
|
||||
{
|
||||
return "tracktion.com";
|
||||
}
|
||||
|
||||
bool TracktionMarketplaceStatus::doesProductIDMatch (const String& returnedIDFromServer)
|
||||
{
|
||||
return getProductID() == returnedIDFromServer;
|
||||
}
|
||||
|
||||
String TracktionMarketplaceStatus::readReplyFromWebserver (const String& email, const String& password)
|
||||
{
|
||||
URL url (getServerAuthenticationURL()
|
||||
.withParameter ("product", getProductID())
|
||||
.withParameter ("email", email)
|
||||
.withParameter ("pw", password)
|
||||
.withParameter ("os", SystemStats::getOperatingSystemName())
|
||||
.withParameter ("mach", getLocalMachineIDs()[0]));
|
||||
|
||||
DBG ("Trying to unlock via URL: " << url.toString (true));
|
||||
|
||||
{
|
||||
ScopedLock lock (streamCreationLock);
|
||||
stream.reset (new WebInputStream (url, true));
|
||||
}
|
||||
|
||||
if (stream->connect (nullptr))
|
||||
{
|
||||
auto* thread = Thread::getCurrentThread();
|
||||
|
||||
if (thread->threadShouldExit() || stream->isError())
|
||||
return {};
|
||||
|
||||
auto contentLength = stream->getTotalLength();
|
||||
auto downloaded = 0;
|
||||
|
||||
const size_t bufferSize = 0x8000;
|
||||
HeapBlock<char> buffer (bufferSize);
|
||||
|
||||
while (! (stream->isExhausted() || stream->isError() || thread->threadShouldExit()))
|
||||
{
|
||||
auto max = jmin ((int) bufferSize, contentLength < 0 ? std::numeric_limits<int>::max()
|
||||
: static_cast<int> (contentLength - downloaded));
|
||||
|
||||
auto actualBytesRead = stream->read (buffer.get() + downloaded, max - downloaded);
|
||||
|
||||
if (actualBytesRead < 0 || thread->threadShouldExit() || stream->isError())
|
||||
break;
|
||||
|
||||
downloaded += actualBytesRead;
|
||||
|
||||
if (downloaded == contentLength)
|
||||
break;
|
||||
}
|
||||
|
||||
if (thread->threadShouldExit() || stream->isError() || (contentLength > 0 && downloaded < contentLength))
|
||||
return {};
|
||||
|
||||
return { CharPointer_UTF8 (buffer.get()) };
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void TracktionMarketplaceStatus::userCancelled()
|
||||
{
|
||||
ScopedLock lock (streamCreationLock);
|
||||
|
||||
if (stream != nullptr)
|
||||
stream->cancel();
|
||||
}
|
||||
|
||||
} // namespace juce
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library.
|
||||
Copyright (c) 2017 - ROLI Ltd.
|
||||
|
||||
JUCE is an open source library subject to commercial or open-source
|
||||
licensing.
|
||||
|
||||
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
|
||||
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
|
||||
27th April 2017).
|
||||
|
||||
End User License Agreement: www.juce.com/juce-5-licence
|
||||
Privacy Policy: www.juce.com/juce-5-privacy-policy
|
||||
|
||||
Or: You may also use this code under the terms of the GPL v3 (see
|
||||
www.gnu.org/licenses).
|
||||
|
||||
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
||||
DISCLAIMED.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace juce
|
||||
{
|
||||
|
||||
/**
|
||||
An implementation of the OnlineUnlockStatus class which talks to the
|
||||
Tracktion Marketplace server.
|
||||
|
||||
For details about how to use this class, see the docs for the base
|
||||
class: OnlineUnlockStatus. Basically, you need to inherit from it, and
|
||||
implement all the pure virtual methods to tell it about your product.
|
||||
|
||||
@see OnlineUnlockStatus, OnlineUnlockForm, KeyGeneration
|
||||
|
||||
@tags{ProductUnlocking}
|
||||
*/
|
||||
class JUCE_API TracktionMarketplaceStatus : public OnlineUnlockStatus
|
||||
{
|
||||
public:
|
||||
TracktionMarketplaceStatus();
|
||||
|
||||
/** @internal */
|
||||
bool doesProductIDMatch (const String& returnedIDFromServer) override;
|
||||
/** @internal */
|
||||
URL getServerAuthenticationURL() override;
|
||||
/** @internal */
|
||||
String getWebsiteName() override;
|
||||
/** @internal */
|
||||
String readReplyFromWebserver (const String& email, const String& password) override;
|
||||
/** @internal */
|
||||
void userCancelled() override;
|
||||
|
||||
private:
|
||||
CriticalSection streamCreationLock;
|
||||
std::unique_ptr<WebInputStream> stream;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TracktionMarketplaceStatus)
|
||||
};
|
||||
|
||||
} // namespace juce
|
Reference in New Issue
Block a user