android - Confirm APK identity with keystore -
i building android application communicates online webservice. plan on releasing application's source code on github. production version, utilize personal webservice want allow digitally signed apk connect.
is possible request apk's keystore , confirm username/password keystore?
if not possible how else can produce functionality?
edit:
i have read class certificate looks might able user public/private keys confirm identity. still unsure of implementation
i use --
static public string getpackagefingerprint( context ctx ) { packagemanager pm = ctx.getpackagemanager(); string packagename = ctx.getpackagename(); int flags = packagemanager.get_signatures; packageinfo packageinfo = null; try { packageinfo = pm.getpackageinfo(packagename, flags); } catch (namenotfoundexception e) { return ""; } signature[] signatures = packageinfo.signatures; byte[] cert = signatures[0].tobytearray(); inputstream input = new bytearrayinputstream(cert); certificatefactory cf = null; try { cf = certificatefactory.getinstance("x509"); } catch (certificateexception e) { return ""; } x509certificate c = null; try { c = (x509certificate) cf.generatecertificate(input); } catch (certificateexception e) { return ""; } try { messagedigest md = messagedigest.getinstance("sha1"); byte[] publickey = md.digest(c.getpublickey().getencoded()); stringbuffer hexstring = new stringbuffer(); (int i=0;i<publickey.length;i++) { string appendstring = integer.tohexstring(0xff & publickey[i]); if(appendstring.length()==1)hexstring.append("0"); hexstring.append(appendstring); } return hexstring.tostring(); } catch (nosuchalgorithmexception e1) { return ""; } }
the problem see approach determine package fingerprint or package , send web-service. better possibility use challenge-response mechanism: web-service sends unique session-token, app encrypts or digests using shared algorithm, , sends encrypted token service verification. of course, wouldn't want publish algorithm github.
Comments
Post a Comment