我正在反转一个android apk,它使用http作为协议,每个http请求都包含一个时间戳和一个签名,例如:
http://x/req?....×tamp=1501234567890&signature=....(256-byte rsa signature of timestamp '1501234567890')
参数签名是时间戳(1501234567890)的 sha256WithRSA 签名。我猜原因是它保证了数据包只能在一段时间内工作,并且用户不能修改时间戳,因为它不会通过签名验证。
但奇怪的是,apk 使用随机生成的 RSA KeyPair 对时间戳进行签名。apk在第一次启动时会生成KeyPair,我知道RSA验证需要public_key,但是apk不会将public_key发送到服务器(服务器不会知道public_key)。服务器如何验证它?
apk 生成 KeyPair,如下所示:
Calendar cal = Calendar.getInstance();
Date now = cal.getTime();
cal.add(Calendar.YEAR, 1);
Date end = cal.getTime();
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore");
kpg.initialize(new KeyPairGeneratorSpec.Builder(getApplicationContext())
.setAlias(alias)
.setStartDate(now)
.setEndDate(end)
.setSerialNumber(BigInteger.valueOf(1))
.setSubject(new X500Principal("CN=test1"))
.build());
KeyPair kp = kpg.generateKeyPair();
服务器不知道public_key时如何验证时间戳?
还是我错过了什么?