Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

BlackBerry® World™ Development

Reply
New Developer
Pigleg
Posts: 10
Registered: ‎09-02-2009
My Device: Not Specified

Re: Dynamic Licensing and Automated License Key Capturing

Now Sept 2009.... Can anyone provide an updated summary of the current experience with dynamic licensing?

 

- Is it working well?

 

- Is the license key stored reliably in CodeModuleGroup or do you find users have to enter the key manually? If they enter it manually, can it be saved in CodeModuleGroup for next time?

 

- Is there now any way to test in advance of going live?

 

- Are there any other common gotchas?

 

- Does anyone have a blog with an end-to-end example?

 

- Is this the model that the majority of people are using?

 

Also, does any one have experience with NOT doing this, i.e. using Static? I get the impression that the best practice is to go the dynamic licensing route, but I'd be interested to know how many are using each model and the relative sales numbers (to get an idea how much of a hit there is from piracy 10%? 90%?). I suppose it's the age old problem. I don't have too much time wrapped up in my little utility, so i'm tempted to just let it go to avoid dealing with this and just test the waters. I just have no clue to what degree piracy is a problem. Probably worse than I think.

 

Thanks guys.

Developer
RLord321
Posts: 343
Registered: ‎02-23-2009
My Device: 8700 | 8310 | BOLD | STORM

Re: Dynamic Licensing and Automated License Key Capturing

Pigleg,

 

- The Dynamic Licensing is working well.

 

- The License Key is stored in the CodeModuleGroup and they do not have to enter it manually.  The code is below in the link just for reference:

 

http://supportforums.blackberry.com/rim/board/message?board.id=appworld_dev&message.id=355&query.id=...

 

- There's really no way to test this

 

- No common gotchas except for people getting new devices.  It will show up in your logs as a new purchase but they are just getting the new key since they got a new PIN.

 

No matter how much piracy is out there, protect yourself as much as you can with the dynamic license keys.  You won't know if your sales are affected because of piracy unless your app makes http connections and you pass PIN numbers that your site checks and its not in your license table.

New Developer
Pigleg
Posts: 10
Registered: ‎09-02-2009
My Device: Not Specified

Re: Dynamic Licensing and Automated License Key Capturing

Fantastic, much appreciated RL. I'm going to give it a shot.

One more question related to the key if anyone is willing:

So, the key I provide in my licensing page response and what I get back from RIM through group.getProperty("RIM_APP_WORLD_LICENSE_KEY") should match - what's the TYPE? Is my key a string or a hex number?

In this doc:http://na.blackberry.com/eng/developers/appworld/Dynamic_License_Flow.pdf

 

The example response is:

 

HTTP/1.1 200 OK
Content-Type: application/www-url-encoded
Content-Length: 20
key=ABCDEFGHIJK

...the example key appears to be a string since GHIJK are included, but I've also read somewhere that RIM_APP_WORLD_LICENSE_KEY will be hex when you retrieve it in the app.

 

Does my licensing page have to return a hex key or can key be any string?

 

 

Developer
RLord321
Posts: 343
Registered: ‎02-23-2009
My Device: 8700 | 8310 | BOLD | STORM

Re: Dynamic Licensing and Automated License Key Capturing

Pigleg,

 

You are getting two things confused here:  PIN and License Key.  The PIN number is what all blackberry devices have and this is what AppWorld sends you to your dynamic license generator web page.  You then create a LicenseKey based off of this (or something else) and you return this back.  This will be a String.

 

So the answer to your question is a String but I wanted to make sure you were on the right page.

New Developer
Pigleg
Posts: 10
Registered: ‎09-02-2009
My Device: Not Specified

Re: Dynamic Licensing and Automated License Key Capturing

[ Edited ]

 

Right on, thanks RL. I gather that PIN is the recommended seed you'd want to use to generate the key?

 

I'll go for broke and post some code (though fearing ROFLs)

 

Using the complex key algorithm of appending "XYZ" to the device PIN for demo sake.

 

In the app:

 

 

 

 

private boolean CheckLicense() { boolean Result = false; //The standard chunk of code to get the group provided by Mr.mkirkup CodeModuleGroup group = null; CodeModuleGroup[] groupArray = CodeModuleGroupManager.loadAll(); String moduleName = ApplicationDescriptor.currentApplicationDescriptor().getModuleName(); for( int i = 0; i < groupArray.length; i++ ) { if( groupArray[i].containsModule( moduleName )) { group = groupArray[i]; break; } } //Now we have the group hopefully if(group != null) { //Normal production path String key = group.getProperty("RIM_APP_WORLD_LICENSE_KEY"); Result = IsValidKey(key); } else { //assuming simulator only? So, for testing make fake key Result = IsValidKey(DeviceInfo.getDeviceId() + "XYZ"); } return Result; } private boolean IsValidKey(String key) { boolean Result = false; int DeviceId = DeviceInfo.getDeviceId(); //Same key gen logic as in the web page String KeyToMatch = DeviceId + "XYZ"; KeyToMatch = KeyToMatch.trim(); key = key.trim(); if(KeyToMatch.equalsIgnoreCase(key)) Result = true; return Result; }

 

 

 

 


.... And the web page code - warning: it's UNHOLY: C# 

 

 

protected void Page_Load(object sender, EventArgs e)
{
string DynamicKey = String.Empty;
string PIN = String.Empty;

  //this will arrive in Hex from RIM

PIN = Request["PIN"];

 

if (!string.IsNullOrEmpty(PIN))
{

DynamicKey = GenerateDynamicKey(PIN);

Response.Clear();
Response.ClearHeaders();

Response.ContentType = "application/www-url-encoded";
Response.AddHeader("Content-Length", DynamicKey.Length.ToString());
Response.Write(DynamicKey);
Response.End();
}
}

private string GenerateDynamicKey(string pin)
{
string Result = string.Empty;

//Convert PIN from hex to decimal
int PinNum = int.Parse(pin, System.Globalization.NumberStyles.HexNumber);

//*magic* to generate key from PIN
Result = "key=" + PinNum.ToString() + "XYZ";

return Result;
}

 

 Thanks again RL.

 

 

 

 

 

Message Edited by Pigleg on 09-07-2009 08:13 PM
Developer
RLord321
Posts: 343
Registered: ‎02-23-2009
My Device: 8700 | 8310 | BOLD | STORM

Re: Dynamic Licensing and Automated License Key Capturing

No problem....and yes, you should use the PIN number.  The code looks great.  However, in your C# code, it looks like you are taking the decimal PIN number and appending "XYZ" to it.  Then in your logic to check to see if it is a valid key, you are using the Hex PIN number (in your production path).  So it would never be equal.  If I may have missed something, forgive me... I did a quick scan of the code while coding myself :-)
New Developer
Pigleg
Posts: 10
Registered: ‎09-02-2009
My Device: Not Specified

Re: Dynamic Licensing and Automated License Key Capturing

Egad, yes I had a nice mix of hex and decimal going on... ok, edited - I hope I've got key = decimal PIN + "XYZ" in all cases now.

 

Sweet irony that my simple algorithm proved too complex for me, just wait til I try and hash it or something fancy...

 

Thanks again RL, hopefully that's all the coddling I require for now.

New Developer
Pigleg
Posts: 10
Registered: ‎09-02-2009
My Device: Not Specified

Re: Dynamic Licensing and Automated License Key Capturing

And followup post: It worked! No hiccups (...yet, knock on wood).

 

App submit process took 2 weeks as advertised, flicked the switch in the vendor portal and shazam there it was. Have made a couple sales and received some comments.

 

Fairly thrilling!

 

Appreciated the assistance RL.

 

Now, on to app #2...

Developer
RLord321
Posts: 343
Registered: ‎02-23-2009
My Device: 8700 | 8310 | BOLD | STORM

Re: Dynamic Licensing and Automated License Key Capturing

Congrats!  I know it feels good to put your first app out there.  Yes, on to App #2.. Don't sit and be content with the sales of app number 1 because just imagine if you had 2 apps out there and then double that...and then double that....you see where this is going.  I've been working on App #3 for too long now and I need to just stop messing around and get it done!
Developer
nmaddix
Posts: 111
Registered: ‎12-16-2008
My Device: Not Specified

Re: Dynamic Licensing and Automated License Key Capturing

I went through a lot of issues with getting this dynamic license key business to work. Support was helpful, though they don't sem to have access to resources like system logs and databases to track problems down. Turned out rim is sending some PINs with all uppercase letters and some with lowercase and I wasn't handling both cases. Watch out for that!

 

Once we got that resolved I was able to test and see that the license key capture code in my app was working on the first try. It's based on code elsewhere in this thread but I wanted to share it in case it's useful to someone.

 

This code runs on app startup and makes sure the app is unlocked each time it runs.

 

CodeModuleGroup group = null;
CodeModuleGroup[] groupArray = CodeModuleGroupManager.loadAll();
if (groupArray != null) {
    String moduleName = ApplicationDescriptor.currentApplicationDescriptor().getModuleName();
    for (int i=0; i<groupArray.length; ++i) {
        if (groupArray[i].containsModule(moduleName)) {
            group = groupArray[i];
            break;
        }
    }

    // find license code
    if (group != null) {
        String lc = group.getProperty("RIM_APP_WORLD_LICENSE_KEY");
        if (lc != null && isUnlockCode(lc))  // isUnlockCode() and unlock() are my custom fns
            unlock(lc);
    }
}

 

Hope this helps prevent all the confusion we went through!