Topic
  • 9 replies
  • Latest Post - ‏2013-01-14T21:41:52Z by SystemAdmin
SystemAdmin
SystemAdmin
2327 Posts

Pinned topic JSONStore - encryption not working

‏2013-01-09T18:03:01Z |
Hello,

I have been testing out the new JSONStore and am trying to understand the flow of the encryption process. In the documentation it says that I need to supply a password with the usePassword command. After I supply, there is communication with the worklight server to create encryption keys and give those back to my device. From there the data into the store should be encrypted. (Thats my understanding)

I have built the following test case, but when pulling the android file data/com.myapp/databases/com.ibm.worklight.database from the emulator I still see the data in a readable format.

<RUN ON ANDROID>
usePassword("abc");
initCollection
collection.add({name:'Aaron',city:'Raleigh');
closeAll()
<STOP APP>

I can clearly read the name value pairs inserted simply by opening the database with a text editor. I am attempting to get a sqlite view plugin to see if its encrypted when it comes out through the jdbc driver select

Specs:
Windows 7
Eclipse Juno + Worklight 5.0.5
Android environment
Emulator - AVD version 4.0.3 API Level 15

Can anyone describe what I am doing wrong? I can provide code snippets of the actions if need be.

I really appreciate the help.

Aaron Allsbrook
ClearBlade Mobile Lead
  • christianIBM
    christianIBM
    78 Posts

    Re: JSONStore - encryption not working

    ‏2013-01-09T18:25:03Z  
    First I would reset the emulator or whatever device you are using for testing and then try the same steps again. Have you looked through the JSONStore sample app?

    -Worklight Development Team, iOS-Christian Linares
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: JSONStore - encryption not working

    ‏2013-01-09T18:29:20Z  
    "I can provide code snippets of the actions if need be. "

    If you attach or paste in JavaScript code I can test it and see if you're doing something wrong or if there's a bug.
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: JSONStore - encryption not working

    ‏2013-01-09T19:40:39Z  
    "I can provide code snippets of the actions if need be. "

    If you attach or paste in JavaScript code I can test it and see if you're doing something wrong or if there's a bug.
    Thank you both for the responses. I will run the test again with a new AVD, although it will be the second time I have created a new AVD.

    Regarding the tutorial - for some reason I can not download through the ftp server. ftp://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v505/module_07_12_JSONStore_with_Security.zip is dead for me. I was able to find the google cached versions of the ppts (Module_07_10_-_Using_JSONStore.pdf) This may be a firewall issue.

    Attached is my sample code. You should be able to put these into a worklight project with dojo added

    Update - I will do a second post with my helper js file due to devworks limit.

    This UI allows for issuing each command individually via tap. My order has been
    1. Destroy JSON Storage
    2. Set Password
    3. Initialize Collection
    4. Stub Fields (modify UI as desired)
    5. Write fields to JSONStorage
    6. Close JSONStorage

    Aaron Allsbrook
    ClearBlade Mobile Lead
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: JSONStore - encryption not working

    ‏2013-01-09T19:41:33Z  
    Thank you both for the responses. I will run the test again with a new AVD, although it will be the second time I have created a new AVD.

    Regarding the tutorial - for some reason I can not download through the ftp server. ftp://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v505/module_07_12_JSONStore_with_Security.zip is dead for me. I was able to find the google cached versions of the ppts (Module_07_10_-_Using_JSONStore.pdf) This may be a firewall issue.

    Attached is my sample code. You should be able to put these into a worklight project with dojo added

    Update - I will do a second post with my helper js file due to devworks limit.

    This UI allows for issuing each command individually via tap. My order has been
    1. Destroy JSON Storage
    2. Set Password
    3. Initialize Collection
    4. Stub Fields (modify UI as desired)
    5. Write fields to JSONStorage
    6. Close JSONStorage

    Aaron Allsbrook
    ClearBlade Mobile Lead
    Here is the utility js file.

    Aaron Allsbrook
    ClearBlade Mobile Lead
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: JSONStore - encryption not working

    ‏2013-01-09T20:22:29Z  
    First I would reset the emulator or whatever device you are using for testing and then try the same steps again. Have you looked through the JSONStore sample app?

    -Worklight Development Team, iOS-Christian Linares
    As a follow-up. I deleted my AVD and started fresh. Still got the same result... I am happy to try other ideas if you have them. Thanks

    Aaron Allsbrook
    ClearBlade Mobile Lead
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: JSONStore - encryption not working

    ‏2013-01-10T00:00:06Z  
    As a follow-up. I deleted my AVD and started fresh. Still got the same result... I am happy to try other ideas if you have them. Thanks

    Aaron Allsbrook
    ClearBlade Mobile Lead
    Um, it seems to be working fine for me. Here's the simplified version of the code I tried:

    
    var cardCollection; var exampleData = 
    { userCardName: 
    'carlos', policyNum: 
    '00000111', expirationDate: 
    '01-10-2012', policyType: 
    'Plus' 
    };   function wlCommonInit()
    { initializeStore(
    'hello', function (initData, storeData) 
    { console.log(
    'initData: '+initData+
    ' storeData: ' + storeData); 
    }); 
    }   var initializeStore = function (pwd, callback) 
    { var initializeFailureCallback = function(data) 
    { WL.Logger.debug(
    "Initialize Collection failed - Message:"+WL.JSONStore.getErrorMessage(data)); 
    };   var initializeSuccessCallback = function(data) 
    { var m = 
    'Collection already existed'; 
    
    if (data === 0) 
    { m=
    'New Collection'; 
    } WL.Logger.debug(
    "Initialize Collection succeeded "+m);   cardCollection.store(exampleData, 
    {onSuccess: function (stored) 
    { callback(data, stored); 
    }, onFailure: initializeFailureCallback
    }); 
    }; WL.JSONStore.usePassword(pwd); cardCollection = WL.JSONStore.initCollection( 
    "cards", 
    {userCardName: 
    'string', policyNum: 
    'string', expirationDate: 
    'string', policyType: 
    'string'
    }, 
    { onSuccess:initializeSuccessCallback, onFailure:initializeFailureCallback
    }); 
    };
    


    If you cat the database after running that you should see the same thing I saw, just gibberish:
    http://cl.ly/image/0d0P42091y3g

    Next I selected "Wipe User Data" and commented the: WL.JSONStore.usePassword(pwd); line to see what happens when I create the DB without a password:
    http://cl.ly/image/3B1C211i271T

    This is the expected output:
    http://cl.ly/image/1N0F2G1j2w2l

    It seems to be working fine for me, can you try with the code above?
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: JSONStore - encryption not working

    ‏2013-01-11T17:24:49Z  
    Um, it seems to be working fine for me. Here's the simplified version of the code I tried:

    <pre class="jive-pre"> var cardCollection; var exampleData = { userCardName: 'carlos', policyNum: '00000111', expirationDate: '01-10-2012', policyType: 'Plus' }; function wlCommonInit() { initializeStore( 'hello', function (initData, storeData) { console.log( 'initData: '+initData+ ' storeData: ' + storeData); }); } var initializeStore = function (pwd, callback) { var initializeFailureCallback = function(data) { WL.Logger.debug( "Initialize Collection failed - Message:"+WL.JSONStore.getErrorMessage(data)); }; var initializeSuccessCallback = function(data) { var m = 'Collection already existed'; if (data === 0) { m= 'New Collection'; } WL.Logger.debug( "Initialize Collection succeeded "+m); cardCollection.store(exampleData, {onSuccess: function (stored) { callback(data, stored); }, onFailure: initializeFailureCallback }); }; WL.JSONStore.usePassword(pwd); cardCollection = WL.JSONStore.initCollection( "cards", {userCardName: 'string', policyNum: 'string', expirationDate: 'string', policyType: 'string' }, { onSuccess:initializeSuccessCallback, onFailure:initializeFailureCallback }); }; </pre>

    If you cat the database after running that you should see the same thing I saw, just gibberish:
    http://cl.ly/image/0d0P42091y3g

    Next I selected "Wipe User Data" and commented the: WL.JSONStore.usePassword(pwd); line to see what happens when I create the DB without a password:
    http://cl.ly/image/3B1C211i271T

    This is the expected output:
    http://cl.ly/image/1N0F2G1j2w2l

    It seems to be working fine for me, can you try with the code above?
    Hmmm,

    Thanks for the response. Everytime I just see the unencrypted data like your second image.

    So, I'll give your code a try. Out of curiousity - are you running ADB with a rooted device or are you using an emulator

    Aaron Allsbrook
    ClearBlade Mobile Lead
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: JSONStore - encryption not working

    ‏2013-01-13T04:39:38Z  
    Hmmm,

    Thanks for the response. Everytime I just see the unencrypted data like your second image.

    So, I'll give your code a try. Out of curiousity - are you running ADB with a rooted device or are you using an emulator

    Aaron Allsbrook
    ClearBlade Mobile Lead
    I used an emulator, specifically "AVD version 4.0.3 API Level 15" -- just like you listed.

    Here's picture of the settings page for that AVD:
    http://cl.ly/image/1a0E3s2H2k3k

    Make sure your CPU/ABI is "ARM (armeabi-v7a)".

    Maybe you can attach your logcat output? or the whole common folder of a simple project that reproduces the issue?

    Remember to wipe the AVD and the logs before trying anything.
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: JSONStore - encryption not working

    ‏2013-01-14T21:41:52Z  
    I used an emulator, specifically "AVD version 4.0.3 API Level 15" -- just like you listed.

    Here's picture of the settings page for that AVD:
    http://cl.ly/image/1a0E3s2H2k3k

    Make sure your CPU/ABI is "ARM (armeabi-v7a)".

    Maybe you can attach your logcat output? or the whole common folder of a simple project that reproduces the issue?

    Remember to wipe the AVD and the logs before trying anything.
    Hi Carlos,

    Thanks for the help and patience. I have manage to get my code up and working. Although I have changed my configuration a good bit
    • no emulator snapshot, clear all user data, etc

    I think the issue came down to a simple/embarrassing coding error. Ultimately my code was passing "undefined" or an object into the setPassword call. Without a callback to check for success and nothing in the logcat I was continuing as if things were ok. In any case, with a string as the input, the encryption is working great. All the samples provided also worked and encrypted the data for me.

    Thanks again.

    Aaron Allsbrook
    ClearBlade Mobile Lead