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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

XML signature validation in AIR<br />

The following example implem<strong>en</strong>ts a derefer<strong>en</strong>cer for validating AIR application signatures. The implem<strong>en</strong>tation is<br />

kept simple by relying on the known structure of an AIR signature. A g<strong>en</strong>eral-purpose derefer<strong>en</strong>cer could be<br />

significantly more complex.<br />

package<br />

{<br />

import flash.ev<strong>en</strong>ts.ErrorEv<strong>en</strong>t;<br />

import flash.security.IURIDerefer<strong>en</strong>cer;<br />

import flash.utils.ByteArray;<br />

import flash.utils.IDataInput;<br />

}<br />

public class AIRSignatureDerefer<strong>en</strong>cer implem<strong>en</strong>ts IURIDerefer<strong>en</strong>cer {<br />

private const XML_SIG_NS:Namespace =<br />

new Namespace( "http://www.w3.org/2000/09/xmldsig#" );<br />

private var airSignature:XML;<br />

}<br />

public function AIRSignatureDerefer<strong>en</strong>cer( airSignature:XML ) {<br />

this.airSignature = airSignature;<br />

}<br />

public function derefer<strong>en</strong>ce( uri:String ):IDataInput {<br />

var data:ByteArray = null;<br />

try<br />

{<br />

if( uri != "#PackageCont<strong>en</strong>ts" )<br />

{<br />

throw( new Error("Unsupported signature type.") );<br />

}<br />

var manifest:XMLList =<br />

airSignature.XML_SIG_NS::Object.XML_SIG_NS::Manifest;<br />

data = new ByteArray();<br />

data.writeUTFBytes( manifest.toXMLString());<br />

data.position = 0;<br />

}<br />

catch (e:Error)<br />

{<br />

data = null;<br />

throw new Error("Refer<strong>en</strong>ce not resolvable: " + uri + ", " + e.message);<br />

}<br />

finally<br />

{<br />

return data;<br />

}<br />

}<br />

Wh<strong>en</strong> you verify this type of signature, only the data in the Manifest elem<strong>en</strong>t is validated. The actual files in the package<br />

are not checked at all. To check the package files for tampering, you must read the files, compute the SHA256 digest<br />

and compare the result to digest recorded in the manifest. The XMLSignatureValidator does not automatically check<br />

such secondary refer<strong>en</strong>ces.<br />

Note: This example is provided only to illustrate the signature validation process. There is little use in an AIR application<br />

validating its own signature. If the application has already be<strong>en</strong> tampered with, the tampering ag<strong>en</strong>t could simply remove<br />

the validation check.<br />

Last updated 6/6/2012<br />

866

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

Saved successfully!

Ooh no, something went wrong!