23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

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

Obfuscating Code and Protecting Intellectual Property<br />

Back in Chapter 1, in the section “Playing in Your Own Room: The App Container,” we saw how apps<br />

written in <strong>HTML</strong>, <strong>CSS</strong>, and JavaScript exist on a consumer’s device as source files, which the app host<br />

loads and executes. By now you’ve probably realized that for as much as Windows tries to hide app<br />

packages from casual access, all that code is there on their device where a determined user can gain<br />

access to it. In other words, assume your code is just as visible in an app package as it is on the web<br />

through a browser’s View Source command.<br />

It’s certainly possible—and common, in fact—to draw on web services that aren’t so exposed for<br />

much of an app’s functionality, in the same way that web apps take advantage of server-side processing.<br />

Still, there will be parts of an app that must exist and run on the client, so you are always running the<br />

risk of someone taking advantage of your generosity!<br />

Ever since developers started playing with Windows 8 apps written in <strong>HTML</strong>, <strong>CSS</strong>, and JavaScript,<br />

they’ve been asking about how to protect their code. In fact, developers using C# and Visual Basic ask<br />

similar questions because although those languages are compiled to IL (intermediate language), plenty<br />

of decompilers exist to produce source code from that IL just as other tools circumvent JavaScript<br />

minification. Neither JavaScript nor .NET languages are particularly good at hiding their details.<br />

Code written in C++, being compiled down to machine code, is significantly harder to<br />

reverse-engineer, although it’s still not impossible for someone to undertake such a task (in which case<br />

you have to ask why they aren’t just writing their own code to begin with!). Nevertheless, it’s the best<br />

protection you can provide for code that lives on the client machine. The only real way to protect an<br />

algorithm is to keep it on a remote server.<br />

If the rest of the app is written in a language other than C++, especially JavaScript, know that it’s a<br />

straightforward manner to also reverse-engineer the interface to a component. The issue here, then, is<br />

whether a malicious party could use the knowledge of a component’s interface to employ that<br />

component in their own apps. The short answer is yes, because your code might show them exactly<br />

how. In such cases, a more flexible and nearly watertight solution would be for the component vendor<br />

to individually manage licenses to app developers. The component would have some kind of<br />

initialization call to enable the rest of its functionality. Within that call, it would compare details of the<br />

app package obtained through the Windows.ApplicationModel.PackageId class against a known and<br />

secure registry of its own, knowing that the uniqueness of app identity is enforced by the Windows<br />

Store. Here are some options for validation:<br />

• Check with an online service This would require network connectivity, which might not be a<br />

problem in various scenarios. Just remember to encrypt the data you send over the network to<br />

avoid snooping with a tool like Fiddler!<br />

• Check against information encrypted and compiled into the component itself That is, the<br />

component is compiled for each licensee uniquely. This is the most difficult to hack.<br />

752

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

Saved successfully!

Ooh no, something went wrong!