[jruby-user] Source Code Encryption

13 views
Skip to first unread message

Kengsreng Tang

unread,
May 5, 2015, 2:15:19 AM5/5/15
to us...@jruby.codehaus.org
How to encrypt source code deployed on Apache Tomcat?

I using rails on jruby deployed on client machine, and I want to prevent
client from hacking my source code.

Any ideas?

Thanks
Kengsreng

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Karol Bucek

unread,
May 5, 2015, 3:36:01 AM5/5/15
to us...@jruby.codehaus.org

 Chances are you're already using Warbler to generate a .war ... just try it's compiled feature.

It will pre-compile all .rb files into -> .class ones and replace .rb file's content to load the compiled .class.

If you're really into it you can further obfuscate with tools such as Proguard, although I would be a little cautious there.

K.

Kengsreng Tang

unread,
May 7, 2015, 6:29:42 PM5/7/15
to us...@jruby.codehaus.org
Karol,

Do you know how to compile xxx.yml files ?

Doug Hathaway

unread,
May 7, 2015, 6:49:15 PM5/7/15
to us...@jruby.codehaus.org, us...@jruby.codehaus.org
You could perhaps encrypt the contents of the YML file, then decrypt before parsing.


Sent from Mailbox

Christian MICHON

unread,
May 9, 2015, 3:46:03 AM5/9/15
to us...@jruby.codehaus.org

Use jrubyc to compile your main ruby script to class files. That should do.

Keith Bennett

unread,
May 9, 2015, 3:18:20 PM5/9/15
to JRuby Users
Even with compiling, the resulting class files can be inspected (somewhat) with javap.

If you run javap -v on the file (don’t included the .class extension) then you can see the method signatures and Java byte code instructions.  Not at all like seeing the original source, but not at all encrypted either.

- Keith

Christian MICHON

unread,
May 9, 2015, 3:49:28 PM5/9/15
to us...@jruby.codehaus.org

I agree but there's no way to really recover the original ruby script. At best you'll retrieve what you listed and the string constants.

It's the easiest form of obfuscation I know for jruby.

If you have another suggestion, I will test it

Christian MICHON

unread,
May 9, 2015, 3:51:54 PM5/9/15
to us...@jruby.codehaus.org

I almost forgot... Have a look at jd-gui if you're using Windows. You'll get a much better java decompilation than what you suggested.

Kengsreng Tang

unread,
May 11, 2015, 1:59:25 AM5/11/15
to us...@jruby.codehaus.org
Hi Christian,

Is Jrubyc can compile yaml file?

Christian MICHON

unread,
May 11, 2015, 6:36:55 AM5/11/15
to us...@jruby.codehaus.org
No jrubyc will only compile ruby files, ie .rb files.

If you wish to preserve the yaml content, I would suggest to simply encrypt it with ruby-rc4 (why not?) and obfuscate the string used as key through a dictionary. That would do.

So in total:
- compile all rb files into class files using jrubyc
- encrypt yaml and xml with ruby-rc4, and obfuscate the key within a dictionary.

If you need more dedicated help, just point me to a git repository. ;-)

--
Christian

Tim Uckun

unread,
May 11, 2015, 12:04:42 PM5/11/15
to us...@jruby.codehaus.org
Why don't you just put your settings in a .rb file?

Christian MICHON

unread,
May 11, 2015, 4:47:04 PM5/11/15
to us...@jruby.codehaus.org

I'm not the creator of this thread, but I believe settings should be part of a configuration file instead of being in the code itself.

Database.yaml in rails is a typical example of such approach.

christian

unread,
May 12, 2015, 4:29:11 PM5/12/15
to us...@jruby.codehaus.org
I followed the thread and realized the you want to "encrypt" some passwords or something when you asked about yaml file.

if you use something like configurator gem to replace yaml with ruby code then the jrubyc will still keep yaml values as literals inside the class files. even you decide to use some encryption for the yaml file you will face the same problem that the encryption key which is just a literal or byte array inside a class file. all you gain is that nobody tumbles over the "password" accidentally but anyone who wants to unwrap if can do so and it might take only a few minutes to do so.

if your intention is to obfuscate your ruby codebase then jrubyc could be OK but even this can be reversed. but is probably not feasible for bigger codebase as it is manual procedure.

I personally find it important to think on how to undo the protection you put in place - just to get a feeling how good your protection is.

- christian
Reply all
Reply to author
Forward
0 new messages