13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

XML signature validation in AIR<br />

}<br />

var base64Encoder:Base64Encoder = new Base64Encoder();<br />

base64Encoder.insertNewLines = false;<br />

base64Encoder.<strong>en</strong>codeBytes( digest, 0, digest.bytesAvailable );<br />

var digestBase64:String = base64Encoder.toString();<br />

if( digestBase64 == refer<strong>en</strong>ce.nameSpace::DigestValue )<br />

{<br />

result = result && true;<br />

message += " " + refer<strong>en</strong>ce.@URI + " verified.\n";<br />

}<br />

else<br />

{<br />

result = false;<br />

message += " ---- " + refer<strong>en</strong>ce.@URI + " has be<strong>en</strong> modified!\n";<br />

}<br />

base64Encoder.reset();<br />

}<br />

trace( message );<br />

return result;<br />

The function loops through all the refer<strong>en</strong>ces in the Manifest elem<strong>en</strong>t. For each refer<strong>en</strong>ce, the SHA256 digest is<br />

computed, <strong>en</strong>coded in base64 format, and compared to the digest in the manifest. The URIs in an AIR package refer<br />

to paths relative to the application directory. The paths are resolved based on the location of the signature file, which<br />

is always in the META-INF subdirectory within the application directory. Note that the Flex SHA256 class returns the<br />

digest as a string of hexadecimal characters. This string must be converted into a ByteArray containing the bytes<br />

repres<strong>en</strong>ted by the hexadecimal string.<br />

To use the mx.utils.SHA256 and Base64Encoder classes in Flash CS4, you can either locate and copy these classes into<br />

your application developm<strong>en</strong>t directory or compile a library SWF containing the classes using the Flex SDK.<br />

Derefer<strong>en</strong>cing URIs in detached signatures refer<strong>en</strong>cing external data<br />

Adobe AIR 1.5 and later<br />

Wh<strong>en</strong> a URI refers to an external resource, the data must be accessed and loaded into a ByteArray object. If the URI<br />

contains an absolute URL, th<strong>en</strong> it is simply a matter of reading a file or requesting a URL. If, as is probably the more<br />

common case, the URI contains to a relative path, th<strong>en</strong> your IURIDerefer<strong>en</strong>cer implem<strong>en</strong>tation must include a way to<br />

resolve the paths to the signed files.<br />

The following example uses a File object initialized wh<strong>en</strong> the derefer<strong>en</strong>cer instance is constructed as the base for<br />

resolving signed files.<br />

Last updated 6/6/2012<br />

868

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!