mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 01:48:25 +03:00
generate facet id
This commit is contained in:
parent
12da6fbd18
commit
19374a5df4
2 changed files with 47 additions and 0 deletions
|
@ -105,6 +105,10 @@ namespace Bit.Android
|
|||
{
|
||||
LaunchApp(args);
|
||||
});
|
||||
|
||||
var appid = Utilities.GetFacetID(Application, Process.MyUid());
|
||||
Console.WriteLine("APPID: " + appid);
|
||||
Utilities.SendCrashEmail(appid);
|
||||
}
|
||||
|
||||
private void AndroidEnvironment_UnhandledExceptionRaiser(object sender, RaiseThrowableEventArgs e)
|
||||
|
|
|
@ -3,6 +3,10 @@ using Android.App;
|
|||
using Android.Content;
|
||||
using Java.Security;
|
||||
using System.IO;
|
||||
using Java.IO;
|
||||
using Java.Security.Cert;
|
||||
using Android.Util;
|
||||
using Android.Content.PM;
|
||||
|
||||
namespace Bit.Android
|
||||
{
|
||||
|
@ -93,5 +97,44 @@ namespace Bit.Android
|
|||
|
||||
return message;
|
||||
}
|
||||
|
||||
public static string GetFacetID(Application aContext, int callingUid)
|
||||
{
|
||||
var packageNames = aContext.PackageManager.GetPackagesForUid(callingUid);
|
||||
if(packageNames == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var info = aContext.PackageManager.GetPackageInfo(packageNames[0], PackageInfoFlags.Signatures);
|
||||
|
||||
byte[] cert = info.Signatures[0].ToByteArray();
|
||||
var input = new MemoryStream(cert);
|
||||
|
||||
var cf = CertificateFactory.GetInstance("X509");
|
||||
var c = (X509Certificate)cf.GenerateCertificate(input);
|
||||
|
||||
var md = MessageDigest.GetInstance("SHA1");
|
||||
|
||||
return "android:apk-key-hash:" + Base64.EncodeToString(md.Digest(c.GetEncoded()),
|
||||
Base64Flags.Default | Base64Flags.NoPadding | Base64Flags.NoWrap);
|
||||
}
|
||||
catch(PackageManager.NameNotFoundException e)
|
||||
{
|
||||
e.PrintStackTrace();
|
||||
}
|
||||
catch(CertificateException e)
|
||||
{
|
||||
e.PrintStackTrace();
|
||||
}
|
||||
catch(NoSuchAlgorithmException e)
|
||||
{
|
||||
e.PrintStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue