Keygen for an android wireframe app

hack过几个Java的程序,发现他们的生产license key的方法几乎都一样,难道是用了什么library。大家的通用方法就是把用户信息用key=value的形式弄成一个文本,然后用privatekey签名。程序里面就是一个public key,验证这个签名。有趣的是,大家都会用GZIP之类的方式压缩,然后再Base64。可以反思一下怎么样更好的防止hack。。 keygen很简单,覆盖掉public key: keytool -genkeypair -keyalg DSA -alias mykey -keystore k.jks keytool -exportcert -keystore k.jks -alias mykey -file ccc.cer 然后,Keygen using groovy: import java.util.zip.* import java.security.* import java.security.cert.* str="""email=who@know.com issueDate=19/09/2013 maintenanceYears=99 quantity=99 registeredTo=Joe Doe """ KeyStore ks = KeyStore.getInstance("JKS"); ks.load(new FileInputStream("k.jks"), "hahaha".toCharArray()) KeyStore.ProtectionParameter protParam = new KeyStore.PasswordProtection("hahaha".toCharArray()); def pk = pkEntry = ks.getEntry("mykey", protParam).getPrivateKey(); Signature s = Signature.getInstance("SHA1withDSA") s.initSign(pk) s.update(str.getBytes()) sig = s.sign().encodeBase64() o=new ByteArrayOutputStream() m=new GZIPOutputStream(o) full = str + "__signature__=" + sig + "\n" println full m.write(full.getBytes()) m.close() b=o.toByteArray().encodeBase64() println b

十二月 19, 2013 · Shawn Ma

Random password

对市面上的random password管理器不是很放心,还是自己写一个来的安心。 生成器: #!/usr/bin/python import random,sys SPECIAL='~_+`-=!@#$%^&*(){}|\][:;<>,.?/' PRINT='asdfghjklqwertyuiopzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890' def get_next(s): return s[random.randrange(0, len(s))] length=15 if (len(sys.argv) ==2): length=int(sys.argv[1]) p='' for i in range(length): if random.random() > 0.8: p += get_next(SPECIAL) else: p += get_next(PRINT) print '' print p print '' 管理器 #!/usr/bin/python import os, sys, keyring, getpass, subprocess, shlex cmd_dir = os.path.dirname(sys.argv[0]) tmp_file = '%s/pwtmp' % (cmd_dir) option = '' if len(sys.argv) > 1: option = sys.argv[1] passwd = keyring.get_keyring().get_password("masterpw","sma").encode('ascii') enc_cmd='openssl aes-256-cbc -a -salt -in %s -out %s/pw.enc -pass pass:%s' % (tmp_file, cmd_dir, passwd) dec_cmd='openssl aes-256-cbc -d -a -salt -in %s/pw.enc -pass pass:%s' % (cmd_dir, passwd) dec_cmd_file='openssl aes-256-cbc -d -a -salt -in %s/pw.enc -out %s -pass pass:%s' % (cmd_dir, tmp_file, passwd) def my_exec(cmd): args = shlex.split(cmd) p = subprocess.Popen(args) ret = p.wait() if ret != 0: raise "Failed to exec %s" % cmd if option != 'edit': p = subprocess.Popen(shlex.split(dec_cmd), stdout=subprocess.PIPE) for l in p.stdout.readlines(): l = l.strip() if option: if l.lower().find(option) >= 0: print l else: print l elif option == 'edit': my_exec(dec_cmd_file) my_exec('vi ' + tmp_file) my_exec(enc_cmd) my_exec('rm ' + tmp_file) my_exec('scp %s/pw.enc shawnma.com:' % cmd_dir)

八月 10, 2013 · Shawn Ma

Re-engineering a java plugin

最近有一个软件,一切都挺好用的,就是不支持我们公司的版本控制系统。只有商业版才支持——但是只为了这么一个plugin就去买个商业版太亏了。所以就搞了一点手脚,扒了一个plugin出来,记录一下。 简单的安装那个plugin,失败:需要商业版本 unzip plugin.jar:很显然的有一个Verifier.class看起来很扎眼,反编译一下,里面在做一些类似RSA之类的计算。果断改编之,使其成为一个空方法。 plugin.xml是一个描述文件,里面写了depends on商业版,去掉。 再启动,有一个Verifier相关class找不到。这个软件使用pico作为container,作为constructor来说,有个很奇怪的class需要resolve dependency。还好这个class的接口很小,写一个空的class(反正verifier也是空的),然后在原有class上派生一个新的plugin class,直接new这个class给父类的constructor,这样,pico就只需要resolve剩余的三个dependency。。 一切看起来就ok了。最后的问题是,这个plugin引用了商业版某个实现类的一个XXXImpl.DEBUG的字段(真糟糕)。没办法,只好用javassist搞免费版本的class,给他强行加一个DEBUG字段: import javassist.*; cp = ClassPool.getDefault() cp.appendClassPath('/Applications/my.app/lib/pro.jar') c = cp.get("com.i.o.v.ChangeListManagerImpl") debug = new CtField(CtClass.booleanType, "DEBUG", c) debug.setModifiers(Modifier.PUBLIC|Modifier.STATIC) c.addField(debug) b = c.toBytecode() new FileOutputStream("A.class").write(b) 在重新package这个jar,搞定。so far so good..

八月 8, 2013 · Shawn Ma

priceline 竞标失败

实在是太可恶了,本来想同感priceline bid一个酒店,但是结果感觉是被骗了,记录一下。 有一个垃圾3.5星的酒店,趴在69这个价格上,我一路从60升到69,就中了,结果仔细一看,丫每天收15块的停车费,你妹美国哪有酒店收停车费的,69+15=84块一晚老子可以定4星了。不过,LA的酒店相比还是比较贵一点点的…… 总结一下: bid前要仔细研究某个区域里的所有酒店,如果有明显不好的,宁可放弃整个区域,或者去hotwire直接定。 太早定也可能没有很好的价格,据说需要自己定一个价格然后每天去bid几次。69相比其他人定的还是偏高。 betterbidding是个不错的网站。

九月 19, 2012 · Shawn Ma

被HTC Desire搞死了

水货手机,基本上的问题就是,启动很困难,Radio那部分总是crash。这是几分钟内连续重启的结果: [ 20.648101] ARM9 has CRASHED [ 20.648284] smem: DIAG ‘[WCDMA] 08:14:04 FATAL: (DS :PFault :36888) (0) [ 20.648315] ‘ [ 20.648742] [ 20.648864] Restarting Linux version 2.6.37.4-cyanogenmod-82245-g7f230e8 (android@giulio-desktop) (gcc version 4.4.3 (GCC) ) #3 PREEMPT Tue Apr 12 22:27:17 CEST 2011 [ 20.648895] 其中加亮部分可以被替换为: [ 53.288482] smem: DIAG ‘[WCDMA] 08:00:22 FATAL: GPRS RLC UL (dsmi.c:00191) (0) [ 82.440185] smem: DIAG ‘[WCDMA] 08:01:51 FATAL: GPRS RLC UL (dsmi.c:00191) (0) [ 47.035705] smem: DIAG ‘[WCDMA] 08:02:44 FATAL: GPRS RLC UL (dsmi.c:00191) (0) [ 40.520263] smem: DIAG ‘[WCDMA] 08:03:30 FATAL: (GSM :XFault :00000) (0) [ 12.618225] smem: DIAG ‘[WCDMA] 08:07:23 FATAL: (SLEE:XFault :00000) (0) [ 40.406524] smem: DIAG ‘[WCDMA] 08:09:33 FATAL: (SMD :XFault :00004) (0) [ 20.300048] smem: DIAG ‘[WCDMA] 08:10:42 FATAL: (DS :XFault :00004) (0) [ 32.339019] smem: DIAG ‘[WCDMA] 08:12:53 FATAL: (IST0:XFault :00068) (0) [ 20.648284] smem: DIAG ‘[WCDMA] 08:14:04 FATAL: (DS :PFault :36888) (0) [ 8.030181] smem: DIAG ‘[WCDMA] 08:16:03 FATAL: (SLEE:XFault :00000) (0) ...

五月 9, 2011 · Shawn Ma

Export Private Key from JKS

四月 12, 2011 · Shawn Ma

面试题

请听题: 一个屋子里有三个人,如何在不互相知道工资的情况下,得出三个人工资的平均值?

六月 10, 2010 · Shawn Ma

记录一下,搜索mp3封面的脚本

最近比较忙……不过似乎我在google reader上subscribe的个人写作者也更新很少了,看来博客快死了? 贵国都过了十一了,居然还封着twitter, facebook, blogspot……真视自由为洪水猛兽啊。有没有人有快速连接twitter的方法?我是没有什么特快捷的方法…… 跑题了。现在很多音乐播放器支持播放的时候显示这个CD的封面,不过自动搜索的结果总是不是很满意,自己做了一个脚本在douban搜索封面,效果还不错,记录一下,免得自己忘了。 —-getfront.bat— @echo off set TEMPDIR=d:<br /> d: cd %1 echo http://www.douban.com/opensearch?start=^&limit=1^&q=%2 %3 > %TEMPDIR%\i.txt “C:\Program Files\bin\iconv\bin\iconv” -t utf-8 %TEMPDIR%\i.txt > %TEMPDIR%\ii.txt wget -q -O – -i %TEMPDIR%\ii.txt | grep link |grep subject |sed “s:.*>\(.*\)<.*:\1:” > %TEMPDIR%\i.txt wget -q -O – -i %TEMPDIR%\i.txt | grep “lpic” |sed “s/.*\(http.*lpic[^ ]*jpg\).*/\1/” > %TEMPDIR%\ii.txt wget -q -O cover.jpg -i %TEMPDIR%\ii.txt rm %TEMPDIR%\i.txt %TEMPDIR%\ii.txt ...

十月 30, 2009 · Shawn Ma

Google就是skynet

我从来没有在Google上输入过中文名字,为什么google reader里显示我的时候却是我的中文名字呢?嗯哼,越来越像SKYNET了。都不知道怎么取消掉,改Profile都不行。。。

八月 7, 2009 · Shawn Ma

Netflix是个什么样的公司?

今天看到一个ppt,(来自TechCrunch),觉得说的很好。这应该是Netflix公司的内部资料,不过里面说的内容很有共鸣。用原话说: Other Companies Should Have To Read This Internal Netflix Presentation “The presentation, which you can see for yourself [attached], is as interesting as any 128-page document can be. If you read it over, about half-way through, you’ll probably start wishing you worked for Netflix. This was meant to be an internal document for employees to read, but it’s also one hell of a recruitment pitch.” 摘录几句: Great Workplace is Stunning Colleagues Great workplace is not day-care, espresso, health benefits, sushi lunches, nice offices, or big compensation, and we only do those that are efficient at attracting stunning colleagues Loyalty is good But unlimited loyalty to a shrinking firm, or to an ineffective employee, is not what we are about Hard Work – Not Directly Relevant We don’t measure people by how many evenings or weekends they are in their cube We do try to measure people by how much, how quickly and how well they get work done – especially under deadline We should focus on what people get done, not how many hours or days worked. Just as we don’t have an 9-5 day policy, we don’t need a vacation policy. ——这个太强大了。 Individuals should manage their own career paths, and not rely on a corporation for planning their careers 不过不是每个公司都能做到这样的。下载。 ...

八月 6, 2009 · Shawn Ma