Loading encrypted data when offline problem

I’ve just become aware of a bug in my Load / Save table encryption when offline.

I use mime and open ssl to generate an encryption key.   

If you save data when online, then go offline and try to load data, my app will sometimes freeze, not all the time though!

Any ideas on how to make this work when the user has no internet connection?, I’m lost on this one!

local openssl = require “plugin.openssl”

local cipher =  openssl.get_cipher (“RC2-40-CBC”)

local mime = require ( “mime” )

— Load Table

  if ( file ) then

        local contents = file:read( “*a” )

      local decryptedData = cipher:decrypt ( mime.unb64 ( contents ), deviceID )

        local table = {}

        if _G.encryptedSaveData then

            table = json.decode( decryptedData );

        else

            table = json.decode( contents );

        end

            io.close( file )

        return table

end

– Save Table —

  if( file ~= nil ) then

        local contents = json.encode( table )

        local encryptedData = mime.b64 ( cipher:encrypt ( contents, deviceID ) )

        if _G.encryptedSaveData then

            file:write( encryptedData )      

        else

            file:write( contents )

        end

        io.close( file )

        return true

end

I’m not sure how being online/offline would affect this.

Could something else be causing the problem?  Have you looked at a device’s console log when this problem occurs to see if there are other errors being generated?

Rob

Hi Rob,

You’re right, if it wasn’t working, no data file would load properly offline which isn’t the case.  The only two things I do online is Admob and the file encrypting.

My tester reported as follows:

Greg, it’s almost definitely connected to offline play. Offline, I jumped zeta to essen to zeta to essen to kronos to [froze] essen.

I closed out, reconnected, reentered the game, and it loaded me into essen! WITHOUT A RESTORE *OR* A SECTOR RESET!

Does this make any sense to you???

I’m still confused about how your file encrypting is involved with anything online/offline. 

Really without some information from “adb logcat” or Android Studio’s log viewer (Android) or using Xcode to view an iOS device console log, it’s going to be hard to guess what could be the problem.

Rob

Well, its probably my misunderstanding but doesn’t

local cipher =  openssl.get_cipher (“RC2-40-CBC”)

get the cipher from the interrnet openssl repository?

Based on your response I’m guessing not…

It’s testers and clients who are having the problem of freezing on file load in the field.  I can’t duplicate the problem so far (sound familiar? :slight_smile: j/k)

The android testers don’t have logging ability so I am flying blind on this one…

Thanks for the help Rob, and have a great weekend

To be honest Greg, trying to read the OpenSSL docs as well as try to read the source code really makes my brain hurt. I can’t trace the code well enough, but I don’t see any attempts to connect to a server to fetch the cipher. **PLEASE NOTE** I could be 100% wrong on this. I’m just not seeing it. Normally calls to servers would involve callback functions because they take too much time and would block the interface and I don’t see any callback/listener functions in play.

If you don’t have your own Android device to test this on, maybe you could find a Corona developer willing to hook their device up to their computer and try to duplicate the issue.

Rob

So Rob,  do you feel like helping a poor struggling Indy developer with a quick test?  Will send canadian beer as recompense :slight_smile:

I’ll see if I can find some time to help. Do you have a URL to install the app from?

You could also join our community Slack and ask there if someone else could help.

https://coronalabs.com/slack

I’m not sure how being online/offline would affect this.

Could something else be causing the problem?  Have you looked at a device’s console log when this problem occurs to see if there are other errors being generated?

Rob

Hi Rob,

You’re right, if it wasn’t working, no data file would load properly offline which isn’t the case.  The only two things I do online is Admob and the file encrypting.

My tester reported as follows:

Greg, it’s almost definitely connected to offline play. Offline, I jumped zeta to essen to zeta to essen to kronos to [froze] essen.

I closed out, reconnected, reentered the game, and it loaded me into essen! WITHOUT A RESTORE *OR* A SECTOR RESET!

Does this make any sense to you???

I’m still confused about how your file encrypting is involved with anything online/offline. 

Really without some information from “adb logcat” or Android Studio’s log viewer (Android) or using Xcode to view an iOS device console log, it’s going to be hard to guess what could be the problem.

Rob

Well, its probably my misunderstanding but doesn’t

local cipher =  openssl.get_cipher (“RC2-40-CBC”)

get the cipher from the interrnet openssl repository?

Based on your response I’m guessing not…

It’s testers and clients who are having the problem of freezing on file load in the field.  I can’t duplicate the problem so far (sound familiar? :slight_smile: j/k)

The android testers don’t have logging ability so I am flying blind on this one…

Thanks for the help Rob, and have a great weekend

To be honest Greg, trying to read the OpenSSL docs as well as try to read the source code really makes my brain hurt. I can’t trace the code well enough, but I don’t see any attempts to connect to a server to fetch the cipher. **PLEASE NOTE** I could be 100% wrong on this. I’m just not seeing it. Normally calls to servers would involve callback functions because they take too much time and would block the interface and I don’t see any callback/listener functions in play.

If you don’t have your own Android device to test this on, maybe you could find a Corona developer willing to hook their device up to their computer and try to duplicate the issue.

Rob

So Rob,  do you feel like helping a poor struggling Indy developer with a quick test?  Will send canadian beer as recompense :slight_smile:

I’ll see if I can find some time to help. Do you have a URL to install the app from?

You could also join our community Slack and ask there if someone else could help.

https://coronalabs.com/slack