fhg
Volume 12, Number 17 -- June 27, 2012

Protect Your Intellectual Property: Obfuscate DB2 For i Source Code

Published: June 27, 2012

by Michael Sansoterra

Every "old timer" IBM i developer knows about the compiler option to include or exclude source statements within an OPM or ILE program. The CL compilers even have an option to allow CL source to be retrieved from the Retrieve CL Source (RTVCLSRC) command.

While high-level language programmers can decide whether or not to include source statements with their objects, DB2 SQL developers had no such option because anyone could use a tool like iNavigator to retrieve the SQL source. Thanks to the IBM i 7.1 technology refresh 4 update, SQL developers now have the option to obfuscate their source code.

First, understand that while HLL developers have the option to exclude source statements from their program objects, DB2 for i SQL developers can obfuscate or scramble the underlying source code. When obfuscated, the SQL source code is still present but it's in a format that the average guy won't bother trying to decipher.

Here's a demonstration on how it works. Say you have written top secret SQL function "Pizza_Area" that receives the radius of a pizza and returns its area:

CREATE OR REPLACE FUNCTION dev.Pizza_Area(radius float)
RETURNS float 
RETURN PI()*radius*radius

You know that any savvy developer can retrieve this SQL code via iNavigator or the Generate Data Definition Language (QSQGNDDL) API. To conceal the source, you decide to obfuscate it using the new WRAP function:

VALUES WRAP('CREATE OR REPLACE FUNCTION dev.Pizza_Area(radius float)
 RETURNS float RETURN PI()*radius*radius');

The WRAP function simply takes a CLOB string expression (containing a valid SQL CREATE statement) and returns an obfuscated version of the source. The result of the above statement is this string (WRAP does not create any objects):

CREATE OR REPLACE FUNCTION DEV . PIZZA_AREA ( RADIUS FLOAT )  
WRAPPED QSQ07010 
aacxW8plW8FjG8pzG8pfG8Vj68FH68Vjl9Vp1_ph1qpdW8pdW8pdW9pLaqebaqebad0
ses7slmf5lhnpUxaORQh:D5pVHrBDNaxQj6_NsGvkJBlyfmpBC4_jKkG8eJuNGi1j4eqaa

What do we have here? Simply the function name and parameter signature, followed by the WRAPPED keyword (indicating it has been obfuscated) and a special value (QSQ07010) that identifies the code as DB2 for i version 7.1. The remaining gobbly-gook characters are an obfuscation of the original source code. This obfuscated code returned by wrap is what should be executed to create the object instead of the original code.

Executing the output of the WRAP function will create the function and will execute identically to the original. After executing the obfuscated CREATE FUNCTION statement we can try it out:

VALUES dev.Pizza_Area(8); -- Returns 201.06

Now, the only real difference is that when the source code is retrieved, the obfuscated source will be returned instead of the original code. So the obfuscated SQL routine can still be retrieved and installed on other systems, it just can't be read by a developer.

When using obfuscated code, make sure to keep safe backups of the original (maintainable) source!

Incidentally, IBM also has overridden "SET OPTION DBGVIEW=*LIST" so that a sneaky developer can't take a peak at the code in the underlying C service program either.

Currently, the wrap function only supports CREATE FUNCTION (table or scalar) or CREATE PROCEDURE SQL routines. For some reason, CREATE TRIGGER is not yet supported.

Obfuscating source code has been an industry standard for some time, being oft-used in .NET, Java, and other development environments. It is a welcome addition to the DB2 for i arena.

Note: As an alternative to the WRAP function, DB2 for i also offers the CREATE_WRAPPED built in stored procedure as a method of obfuscating a source routine.


Michael Sansoterra is a DBA for Broadway Systems in Grand Rapids, Michigan. Send your questions or comments for Mike via the IT Jungle Contact page.




                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot


Sponsored By
HELP/SYSTEMS

                                  Attend the leading IT educational event for IBM i users
                                  on September 17-20 in Minneapolis, MN.

                                  The 2012 Solutions Summit offers course tracks for
                                  your top IT initiatives:

                                      Automated Operations
                                      Data Access
                                      Security
                                      Industry Trends

                                  Don't miss the conference that keeps you competitive
                                  and future-oriented.

                                  Early bird pricing ends June 30.
                                  Register today and save $100!


Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Edwin Earley, Brian Kelly, Michael Sansoterra
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

Abacus Solutions:  More affordable and flexible alternatives to deliver secondary workloads
New Generation Software:  Announcing the $475 IBM i Query & BI SDK. Order a FREE trial by June 30
Help/Systems:  2012 Solutions Summit. Early bird pricing ends June 30. Save $100!


 

IT Jungle Store Top Book Picks

BACK IN STOCK: Easy Steps to Internet Programming for System i: List Price, $49.95

The iSeries Express Web Implementer's Guide: List Price, $49.95
The iSeries Pocket Database Guide: List Price, $59
The iSeries Pocket SQL Guide: List Price, $59
The iSeries Pocket WebFacing Primer: List Price, $39
Migrating to WebSphere Express for iSeries: List Price, $49
Getting Started with WebSphere Express for iSeries: List Price, $49
The All-Everything Operating System: List Price, $35
The Best Joomla! Tutorial Ever!: List Price, $19.95


 
The Four Hundred
The Big Two Four For The Four Oh Oh

DB2 For i Modernization Gets Assist From RPG OA

IBM Tweaks Flex Prices, Offers Flex Services

As I See It: The Three Graces

EMC Touts Successful Data Domain Installation At IBM i Shop

Four Hundred Stuff
Cybele Goes Mobile with 5250 Emulator

Misys Partner Launches IBM i Client for Subversion 1.75

Synergivity Touts Workflow Enhancements in MDCMS

Bug Busters Tackles Journaling Issues with HA Software

HiT Software Takes DBMoto To the Cloud

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

System i PTF Guide
June 23, 2012: Volume 14, Number 25

June 16, 2012: Volume 14, Number 24

June 9, 2012: Volume 14, Number 23

June 2, 2012: Volume 14, Number 22

May 26, 2012: Volume 14, Number 21

May 19, 2012: Volume 14, Number 20

TPM at The Register
Cisco, Citrix link arms for VDI partner push

Dell still on a Quest quest for software?

Taiwanese weathermen pick Fujitsu PrimeHPC super

Cisco bends UCS rack and blade metal around new Xeon E5s

AMD puts network, chip guru in charge of Opterons

Red Hat pumps up Enterprise Linux to 6.3

Red Hat hits the top and bottom numbers in fiscal Q1

Bromium twists chip virty circuits to secure PCs and servers

HP rolls up virty desktop system bundles for SMBs

Mellanox FDR InfiniBand pushes PCI-Express 3.0 to the limits

Unisys upgrades Libra mainframes with Xeon E5s

HP taps Intel Atom for next-gen Moonshot hyperscale servers

THIS ISSUE SPONSORED BY:

Help/Systems
WorksRight Software
American Top Tools


Printer Friendly Version


TABLE OF CONTENTS
Protect Your Intellectual Property: Obfuscate DB2 For i Source Code

Another Way To Skin A Generic Cat

Admin Alert: Finding TCP/IP Interface History And More On The NetServer GO Nets Installation Library

Four Hundred Guru

BACK ISSUES




 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2012 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement