Splash method: encrypting the main stack

If you find an issue in LiveCode but are having difficulty pinning down a reliable recipe or want to sanity-check your findings with others, this is the place.

Please have one thread per issue, and try to summarize the issue concisely in the thread title so others can find related issues here.

Moderator: Klaus

Post Reply
trevix
Posts: 1077
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Splash method: encrypting the main stack

Post by trevix » Wed Oct 30, 2024 5:35 pm

I am converting my standalone so that it uses the splash method, using LC10.0.1RC1.
There is a launcher Splash stack and the Main stack (the real thing). This last is inside a folder on resources, with other stuff that gets updated from the cloud when I need to.
On first launch, the folder inside the app gets copied to the mobile document folder: in this way, since I can read and write there, I can manage version auto updates from the web. (it's a long story but, mainly, the devices are not easily reached by the users and store auto update cannot be set).
This is how I set the all thing and it works great.

But I need then to protect the Main stack (I cannot do it, because of my choices, in the standalone setting of the Splash stack), in such a way that the stack gets password protected only when building the standalone and I can easily work with it when in development.
I tried to put the following code in the Splash Stack:

Code: Select all

on savingMobileStandalone pTargetType, pAppBundle
put specialfolderpath("resources") & "/MyFolder/Mainstack.livecode" into tPath
 if there is a stack tPath then --
          ProtectMyStacks tPath--this password protect the Main stack 
          save stack tPath
     end if
end savingMobileStandalone

private command ProtectMyStacks pStackPath
     if there is a stack pStack then
          repeat for each line tSubStack in the substacks of stack pStackPath
               set the password of stack tSubStack of stack pStackPath to "xxx"
          end repeat
          set the password of stack pStackPath  to "xxx"
     end if
end ProtectMyStacks
But it does not work.
It probably will, using the parameter pAppBundle of savingMobileStandalone, for iOS (which has a bundle) but not for the Android .aab file, where I think is not possible to explore or do changes.
I guess that I could password protect the Main stack before savingMobileStandalone if I only new how to intercept the "build standalone" command of LC. Then, once finished, I could remove the password on mobileStandaloneSaved.
Any help?
Thanks
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

Klaus
Posts: 14189
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Splash method: encrypting the main stack

Post by Klaus » Wed Oct 30, 2024 7:13 pm

Hi Trevix,

hm, clueless... 8)

Try to add a
...
answer the result
## or put the result AFTER a field or msg
...
After:
save stack tPath
and
set the password of stack tSubStack of stack pStackPath to "xxx"

Maybe that will give us a hint...

Best

Klaus

trevix
Posts: 1077
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: Splash method: encrypting the main stack

Post by trevix » Thu Oct 31, 2024 1:28 pm

Is it possible that the content of the Copy Files on standalone settings gets copied "before" the command savingMobileStandalone?
If this is the case, can I somehow intercept the building process "before" the copy of things, so that I can password protect the Main stack (which is in the Copy pane of standalone settings)
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

trevix
Posts: 1077
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: Splash method: encrypting the main stack SOLVED ??

Post by trevix » Thu Oct 31, 2024 7:21 pm

This seems to work, since I develop for iOS and Android.
During development, the Main stack is always unlocked and this is nice.
The Main stack gets password protected before loading it to the bundle.
Any idea if this procedure is correct or prone to bugs?

Code: Select all

on savingMobileStandalone pTargetType, pAppBundle --simulator or device
     --sequence is iOS - Android. I protect only during iOS and remove protection after Android
     if "/iOS/" is in pAppBundle then
          Answer "Protect the standalone stack?" with "OK" or "Cancel"
          if it = "OK" then
               if there is a stack gPrefTF["AllPath"]["PathStack"] then
                    put gPrefTF["AllPath"]["PathStack"] into tStackPath
                    lock messages
                    open stack tStackPath --need to re-open and close in order to apply password
                    repeat for each line tSubStack in the substacks of stack tStackPath
                         set the password of stack tSubStack of stack tStackPath to "xxx"
                    end repeat
                    set the password of stack tStackPath  to "xxx"
                    SAVE STACK tStackPath
                    close stack tStackPath --mmmmh may not be needed
                    unlock messages
               end if
          end if
     end if
end savingMobileStandalone

on mobileStandaloneSaved pTargetType, pAppBundle 
     rename specialfolderpath("resources") & "/info.plist2" to specialfolderpath("resources") & "/info.plist" --this if for other stuff
     --I remove protection on the secon pass
     if "/Android/" is in pAppBundle then
          put gPrefTF["AllPath"]["PathStack"] into tStackPath
          DeProtectMyStacks tStackPath
          RemovePassword tStackPath
          SAVE STACK tStackPath
     end if
end mobileStandaloneSaved

private command DeProtectMyStacks pStackPath
     repeat for each line tSubStack in the substacks of stack pStackPath
          set the passkey of stack tSubStack of stack pStackPath to "xxx"
     end repeat
     set the passkey of stack pStackPath  to "xxx"
end DeProtectMyStacks

command RemovePassword pStackPath
     repeat for each line tSubStack in the substacks of stack pStackPath
          set the password of stack tSubStack of stack pStackPath to empty
     end repeat
     set the password of stack pStackPath  to empty
end RemovePassword
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

trevix
Posts: 1077
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: Splash method: encrypting the main stack

Post by trevix » Fri Nov 22, 2024 5:29 pm

One more problem with the Splash method:
Since I am using the remote debugger, I passkey the main stack and its substack before opening, using this:

Code: Select all

DeProtectMyStacks sStackPath --temporary remove protection
     go to stack sStackPath--path to the Main stack, be it intheresources or Documents folder

Code: Select all

private command DeProtectMyStacks pStackPath
     try
          set the passkey of stack pStackPath  to "xxx"
          repeat for each line tSubStack in the substacks of stack pStackPath
               set the passkey of stack tSubStack of stack pStackPath to xxx"
          end repeat
      ---all ok
     catch errorVariable
        ---show eventual error
     end try
end DeProtectMyStacks
The problem is that the passkey, on the Android hardware device, does not seem to temporary unlock the main stack and does not catch any error, while the remote debugger does not show the running script (it stops at breakpoints but with a blank code editor).
Anybody encontered this problem? Is there a solution?
Thanks
Trevix
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

trevix
Posts: 1077
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: Splash method: encrypting the main stack

Post by trevix » Sat Nov 23, 2024 5:45 pm

I also want to confirm that password protecting a stack, if it contains a datagrid, you must passkey the "Data Grid Templates ..." substack, in order to make the datagrid to work.

So this is my solution:
- I keep the Flash and Main stack password free on development.
- When test installing or creating a standalone, on the "savingMobileStandalone" I ask if I want to password protect the Main stack (for a real situation install) or not (for debugging) and act accordingly.
- If password protecting subastacks, I skip "Data Grid Templates" or other substack that copy or clone objects (it shouldn't be this way but this is needed...)
- In the "mobileStandaloneSaved" I then remove again the password protection

It would be nice if somebody can confirm that this procedure is correct.
Thanks
Trevix
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

Post Reply