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 />

The following example illustrates a derefer<strong>en</strong>cer for <strong>en</strong>veloped signatures:<br />

package<br />

{<br />

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

import flash.ev<strong>en</strong>ts.Ev<strong>en</strong>tDispatcher;<br />

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

import flash.utils.ByteArray;<br />

import flash.utils.IDataInput;<br />

}<br />

public class EnvelopedDerefer<strong>en</strong>cer<br />

ext<strong>en</strong>ds Ev<strong>en</strong>tDispatcher implem<strong>en</strong>ts IURIDerefer<strong>en</strong>cer<br />

{<br />

private var signedMessage:XML;<br />

}<br />

public function EnvelopedDerefer<strong>en</strong>cer( signedMessage:XML )<br />

{<br />

this.signedMessage = signedMessage;<br />

}<br />

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

{<br />

try<br />

{<br />

if( uri.l<strong>en</strong>gth != 0 )<br />

{<br />

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

}<br />

var data:ByteArray = new ByteArray();<br />

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

data.position = 0;<br />

}<br />

catch (e:Error)<br />

{<br />

var error:ErrorEv<strong>en</strong>t =<br />

new ErrorEv<strong>en</strong>t("Ref error " + uri + " ", false, false, e.message);<br />

this.dispatchEv<strong>en</strong>t(error);<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 />

This derefer<strong>en</strong>cer class uses a constructor function with a parameter, signedMessage, to make the <strong>en</strong>veloped<br />

signature docum<strong>en</strong>t available to the derefer<strong>en</strong>ce() method. Since the refer<strong>en</strong>ce in an <strong>en</strong>veloped signature always<br />

refers to the root of the signed data, the derefer<strong>en</strong>cer() method writes the docum<strong>en</strong>t into a byte array and returns it.<br />

Last updated 6/6/2012<br />

864

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

Saved successfully!

Ooh no, something went wrong!