airsdk / Adobe-Runtime-Support

Report, track and discuss issues in Adobe AIR. Monitored by Adobe - and HARMAN - and maintained by the AIR community.
200 stars 11 forks source link

air.security.Digest bug #2317

Open manishpatel0404 opened 1 year ago

manishpatel0404 commented 1 year ago

Following is a sample code:

`private static function getSHA256Hash():void {

var myInputBA:ByteArray = new ByteArray();

myInputBA.writeUTFBytes("TestString");

var myDigest:Digest = new Digest(Digest.SHA256);

var myOutputBA:ByteArray = Digest.hash(Digest.SHA256, myInputBA);

var myString:String = myOutputBA.readUTFBytes(myOutputBA.length);

trace(myString);

}`

Following is the trace output:

`typecheck screens.code::MainScreen$/getSHA256Hash()

outer-scope = [global Object$]

    [screens.code::MainScreen$~[O] *[A] *[A] *[A] *[A]] {} ()
0:getlocal0
    [screens.code::MainScreen$~[O] *[A] *[A] *[A] *[A]] {} (screens.code::MainScreen$~[O])
1:pushscope
    [screens.code::MainScreen$~[O] *[A] *[A] *[A] *[A]] {screens.code::MainScreen$~[O]} ()
2:debugfile "D:\CodeExperiments\src;screens\code;MainScreen.as"
    [screens.code::MainScreen$~[O] *[A] *[A] *[A] *[A]] {screens.code::MainScreen$~[O]} ()
4:debug
    [screens.code::MainScreen$~[O] *[A] *[A] *[A] *[A]] {screens.code::MainScreen$~[O]} ()
9:debug
    [screens.code::MainScreen$~[O] *[A] *[A] *[A] *[A]] {screens.code::MainScreen$~[O]} ()
15:debug
    [screens.code::MainScreen$~[O] *[A] *[A] *[A] *[A]] {screens.code::MainScreen$~[O]} ()
21:debug
    [screens.code::MainScreen$~[O] *[A] *[A] *[A] *[A]] {screens.code::MainScreen$~[O]} ()
27:findpropstrict flash.utils::ByteArray
    [screens.code::MainScreen$~[O] *[A] *[A] *[A] *[A]] {screens.code::MainScreen$~[O]} (global~[O])
30:debugline 1404
    [screens.code::MainScreen$~[O] *[A] *[A] *[A] *[A]] {screens.code::MainScreen$~[O]} (global~[O])
33:constructprop 173 0
    [screens.code::MainScreen$~[O] *[A] *[A] *[A] *[A]] {screens.code::MainScreen$~[O]} (flash.utils::ByteArray~[O])
37:coerce flash.utils::ByteArray
    [screens.code::MainScreen$~[O] *[A] *[A] *[A] *[A]] {screens.code::MainScreen$~[O]} (flash.utils::ByteArray~[O])
40:setlocal2
    [screens.code::MainScreen$~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {screens.code::MainScreen$~[O]} ()
41:getlocal2
    [screens.code::MainScreen$~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {screens.code::MainScreen$~[O]} (flash.utils::ByteArray~[O])
42:debugline 1405
    [screens.code::MainScreen$~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {screens.code::MainScreen$~[O]} (flash.utils::ByteArray~[O])
45:pushstring "TestString"
    [screens.code::MainScreen$~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {screens.code::MainScreen$~[O]} (flash.utils::ByteArray~[O] String~[S])
48:callproperty writeUTFBytes 1
    [screens.code::MainScreen$~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {screens.code::MainScreen$~[O]} (void[A])
52:pop
    [screens.code::MainScreen$~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {screens.code::MainScreen$~[O]} ()
53:findpropstrict air.security::Digest
    [screens.code::MainScreen$~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {screens.code::MainScreen$~[O]} (Object~[A])
56:debugline 1407
    [screens.code::MainScreen$~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {screens.code::MainScreen$~[O]} (Object~[A])
59:pushstring "SHA-256"
    [screens.code::MainScreen$~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {screens.code::MainScreen$~[O]} (Object~[A] String~[S])
62:constructprop 208 1
    [screens.code::MainScreen$~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {screens.code::MainScreen$~[O]} (*[A])
66:coerce air.security::Digest
    [Fault] exception, information=VerifyError: Error #1014: Class air.security::Digest could not be found.

`

Dangerous stuff!

AIR_SDK_50.0.1.2

ajwfrost commented 1 year ago

Hi

When we see VerifyError: Error #1014: Class air.security::Digest could not be found. it most likely indicates a mismatch in the version numbering.. so e.g. the runtime thinks that you're not using the AIR 50.0 API level...

What platform were you running this on? And is it just a single SWF file (rather than one loaded into another)? It works fine for me using that SDK on Windows with ADL...

thanks

manishpatel0404 commented 1 year ago

@ajwfrost I am running this on Windows with ADL using FlashDevelop IDE. I was just trying out the new AIR_SDK_50.0.1.2

My PATH setting was still pointing to earlier 935 version, which is what might have created this error.

Now, I get the result mן'p »8;J_ð on the above code. Do I need to convert this to a hex string?

Thanks.

ajwfrost commented 1 year ago

Hi

Thanks -> I'm trying to work out how the SWF was even allowed to run on a runtime that's not got support for SWF version 50! It makes it a bit confusing... the Digest class is configured in our build with the 'swf 50' tag which means you should only be able to compile this if you're creating a SWF with version code 50, and to load a SWF with version code 50 your app descriptor should have at least namespace 50.0, and if you have that, then AIR 33.1 shouldn't even run it....! So just to help us try to work out what's happening and get a better error message up, are you able to check/confirm what your app descriptor namespace is, and if you open the SWF in a hex editor, can you see what the fourth byte is?

In terms of the string result - yes it's not a string, it's just the hash bytes, so normally that would be converted to hex bytes. I think we were going to add some utility functions for that, will check where we are with those....! but you could do something like:

                var myString : String = "";
                while (myOutputBA.bytesAvailable)
                {
                    var b:uint = myOutputBA.readUnsignedByte();
                    var strHex : String = b.toString(16);
                    if (strHex.length == 1) strHex = "0" + strHex;
                    myString += strHex;
                }
                trace(myString);

thanks

manishpatel0404 commented 1 year ago

@ajwfrost When I got the error, the SWF was 44 and the namespace in the app descriptor was 33.1. with my SDK PATH setting to 935 version binaries.

This, I changed to SWF 50 and namespace 50.0, and changed the PATH setting to point to the 50.0 version binaries. This worked correctly without errors.

My apologies for the incomplete information. I wasn't focused while replying.

ajwfrost commented 1 year ago

Thanks .. but I'm still wondering how you even managed to build the SWF file using 33.1 and SWF version 44. When I try it I get:

Main.as:747:Error: Type was not found or was not a compile-time constant: Digest.
            var d : Digest = new Digest(Digest.MD5);
                    ^

Are you able to share how you compiled the SWF, as this may be exposing a bug or issue that it would be good to tighten up! Always better for us to highlight errors at compile-time, rather than waiting until it's running and then throwing a verify error..!

thanks

manishpatel0404 commented 1 year ago

I sure will, once I reach home. You see, I had decided to try out the new SDK while having my 'morning' tea (actually, 2:00 pm in the afternoon :-))

I will retrace my steps so as to recreate the error and send you the SWF.

manishpatel0404 commented 1 year ago

Ok. I am home and have recreated the error.

I realised that I had only changed the SDK Path in FlashDevelop to 50.0.1.2 and left the rest of the settings as they were in 33.1.1.935. This built a SWF 44 (because of my standard debug_config.xml below) file using SDK 50.

Settings of 33.1.1.935:

FlashDevelop Output window log follows:

Running process: C:\Program Files (x86)\FlashDevelop\Tools\fdbuild\fdbuild.exe "D:\CodeExperiments\CodeExperiments.as3proj" -ipc 5f95c20a-c5a4-4a8e-89a0-7e914feb48f2 -version "50.0.1" -compiler "D:\__SDK\__AIR-sdk_50_0_1_2" -library "C:\Program Files (x86)\FlashDevelop\Library"

Building CodeExperiments

mxmlc-cli -load-config="D:\__SDK\__AIR-sdk_50_0_1_2/frameworks/air-config.xml" -load-config+=obj\CodeExperimentsConfig.xml -load-config+=bat\debug_config.xml -debug=true +configname=air -swf-version=44 -o obj\CodeExperiments638048321275455398

Running java as: D:\__SDK\openjdk11\bin\java

Loading configuration: D:\__SDK\__AIR-sdk_50_0_1_2\frameworks\air-config.xml

Loading configuration: D:\Work Backups\MJP's Documents\Mediapro Tech Development\___Current WIP\AIR_PROJECTS\projects\CodeExperiments\obj\CodeExperimentsConfig.xml

Loading configuration: D:\Work Backups\MJP's Documents\Mediapro Tech Development\___Current WIP\AIR_PROJECTS\projects\CodeExperiments\bat\debug_config.xml

959 bytes written to D:\CodeExperiments\obj\CodeExperiments638048321275455398 in 1.262 seconds Build succeeded Done(0)

Debugger startup error. For troubleshooting see: http://www.flashdevelop.org/wikidocs/index.php?title=F.A.Q Error details: System.NullReferenceException: Object reference not set to an instance of an object. at net.sf.jni4net.jni.JNIEnv.GetFieldID(Class clazz, String name, String sig) at net.sf.jni4net.Ref.Init() at net.sf.jni4net.Bridge.BindCore(JNIEnv env, BridgeSetup newSetup) at net.sf.jni4net.Bridge.CreateJVM() at net.sf.jni4net.Bridge.CreateJVM(BridgeSetup setup) at FlashDebugger.DebuggerManager.Start(Boolean alwaysStart) [Capturing traces with FDB]

Getting this error ever since I switched to openjdk11 from openjdk8, so not an issue. The Debugger still works anyway.

typecheck CodeExperiments() outer-scope = [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ CodeExperiments$] [CodeExperiments~[O] *[A] *[A] *[A] *[A]] {} () 0:getlocal0 [CodeExperiments~[O] *[A] *[A] *[A] *[A]] {} (CodeExperiments~[O]) 1:pushscope [CodeExperiments~[O] *[A] *[A] *[A] *[A]] {CodeExperiments~[O]} () 2:debugfile "D:\Work Backups\MJP's Documents\Mediapro Tech Development\___Current WIP\AIR_PROJECTS\projects\CodeExperiments\src;;CodeExperiments.as" [CodeExperiments~[O] *[A] *[A] *[A] *[A]] {CodeExperiments~[O]} () 4:debug [CodeExperiments~[O] *[A] *[A] *[A] *[A]] {CodeExperiments~[O]} () 9:debug [CodeExperiments~[O] *[A] *[A] *[A] *[A]] {CodeExperiments~[O]} () 14:debug [CodeExperiments~[O] *[A] *[A] *[A] *[A]] {CodeExperiments~[O]} () 19:debug [CodeExperiments~[O] *[A] *[A] *[A] *[A]] {CodeExperiments~[O]} () 24:getlocal0 [CodeExperiments~[O] *[A] *[A] *[A] *[A]] {CodeExperiments~[O]} (CodeExperiments~[O]) 25:constructsuper 0 [CodeExperiments~[O] *[A] *[A] *[A] *[A]] {CodeExperiments~[O]} () 27:findpropstrict flash.utils::ByteArray [CodeExperiments~[O] *[A] *[A] *[A] *[A]] {CodeExperiments~[O]} (global~[O]) 29:debugline 24 [CodeExperiments~[O] *[A] *[A] *[A] *[A]] {CodeExperiments~[O]} (global~[O]) 31:constructprop 1 0 [CodeExperiments~[O] *[A] *[A] *[A] *[A]] {CodeExperiments~[O]} (flash.utils::ByteArray~[O]) 34:coerce flash.utils::ByteArray [CodeExperiments~[O] *[A] *[A] *[A] *[A]] {CodeExperiments~[O]} (flash.utils::ByteArray~[O]) 36:setlocal2 [CodeExperiments~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {CodeExperiments~[O]} () 37:getlocal2 [CodeExperiments~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {CodeExperiments~[O]} (flash.utils::ByteArray~[O]) 38:debugline 25 [CodeExperiments~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {CodeExperiments~[O]} (flash.utils::ByteArray~[O]) 40:pushstring "TestString" [CodeExperiments~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {CodeExperiments~[O]} (flash.utils::ByteArray~[O] String~[S]) 42:callproperty writeUTFBytes 1 [CodeExperiments~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {CodeExperiments~[O]} (void[A]) 45:pop [CodeExperiments~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {CodeExperiments~[O]} () 46:findpropstrict air.security::Digest [CodeExperiments~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {CodeExperiments~[O]} (Object~[A]) 48:debugline 27 [CodeExperiments~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {CodeExperiments~[O]} (Object~[A]) 50:pushstring "SHA-256" [CodeExperiments~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {CodeExperiments~[O]} (Object~[A] String~[S]) 52:constructprop 3 1 [CodeExperiments~[O] *[A] flash.utils::ByteArray~[O] *[A] *[A]] {CodeExperiments~[O]} (*[A]) 55:coerce air.security::Digest [Fault] exception, information=VerifyError: Error #1014: Class air.security::Digest could not be found.

AIR exception error window stacktrace follows:

VerifyError: Error #1014: Class air.security::Digest could not be found.

at runtime::ContentPlayer/loadInitialContent() at runtime::ContentPlayer/playRawContent() at runtime::ContentPlayer/playContent() at runtime::AppRunner/run() at ADLAppEntry/run() at global/runtime::ADLEntry()

I have zipped the swf file so that it can be uploaded here.

CodeExperiments.zip

Thanks.