Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add editorkeyhash calculation #689

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Facebook.Unity.Editor/FacebookSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class FacebookSettingsEditor : Editor
private GUIContent packageNameLabel = new GUIContent("Package Name [?]", "aka: the bundle identifier");
private GUIContent classNameLabel = new GUIContent("Class Name [?]", "aka: the activity name");
private GUIContent debugAndroidKeyLabel = new GUIContent("Debug Android Key Hash [?]", "Copy this key to the Facebook Settings in order to test a Facebook Android app");
private GUIContent editorAndroidKeyLabel = new GUIContent("Editor Android Key Hash [?]", "Copy this key to the Facebook Settings in order to test a Facebook Android app");

private GUIContent autoLogAppEventsLabel = new GUIContent("Auto Logging App Events [?]", "If true, automatically log app install, app launch and in-app purchase events to Facebook. https://developers.facebook.com/docs/app-events/");
private GUIContent advertiserIDCollectionLabel = new GUIContent("AdvertiserID Collection [?]", "If true, attempts to collect user's AdvertiserID. https://developers.facebook.com/docs/app-ads/targeting/mobile-advertiser-ids/");
Expand Down Expand Up @@ -313,6 +314,7 @@ private void AndroidUtilGUI()
this.SelectableLabelField(this.packageNameLabel, Utility.GetApplicationIdentifier());
this.SelectableLabelField(this.classNameLabel, ManifestMod.DeepLinkingActivityName);
this.SelectableLabelField(this.debugAndroidKeyLabel, FacebookAndroidUtil.DebugKeyHash);
this.SelectableLabelField(this.editorAndroidKeyLabel, FacebookAndroidUtil.CurrentKeyHash);
if (GUILayout.Button("Regenerate Android Manifest"))
{
ManifestMod.GenerateManifest();
Expand Down
44 changes: 42 additions & 2 deletions Facebook.Unity.Editor/android/FacebookAndroidUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class FacebookAndroidUtil
public const string ErrorKeytoolError = "java_keytool_error";

private static string debugKeyHash;
private static string currentKeyHash;
private static string setupError;

public static bool SetupProperly
Expand Down Expand Up @@ -86,6 +87,44 @@ public static string DebugKeyHash
}
}

public static string CurrentKeyHash
{
get
{
if (currentKeyHash == null)
{
if (!HasAndroidSDK())
{
return ErrorNoSDK;
}

if(string.IsNullOrEmpty(PlayerSettings.Android.keystoreName))
{
return ErrorNoKeystore;
}

if(string.IsNullOrEmpty(PlayerSettings.Android.keyaliasName))
{
return ErrorNoKeystore;
}

if (!DoesCommandExist("echo \"xxx\" | openssl base64"))
{
return ErrorNoOpenSSL;
}

if (!DoesCommandExist("keytool"))
{
return ErrorNoKeytool;
}

currentKeyHash = GetKeyHash(PlayerSettings.Android.keyaliasName, PlayerSettings.Android.keystoreName, PlayerSettings.Android.keystorePass, PlayerSettings.Android.keyaliasPass);
}

return currentKeyHash;
}
}

public static string SetupError
{
get
Expand Down Expand Up @@ -145,7 +184,8 @@ public static string GetAndroidSdkPath()
return sdkPath;
}

private static string GetKeyHash(string alias, string keyStore, string password)
private static string GetKeyHash(string alias, string keyStore, string password) => GetKeyHash(alias,keyStore,password,password);
private static string GetKeyHash(string alias, string keyStore, string keystorePassword, string aliasPassword)
{
var proc = new Process();
var arguments = @"""keytool -storepass {0} -keypass {1} -exportcert -alias {2} -keystore {3} | openssl sha1 -binary | openssl base64""";
Expand All @@ -160,7 +200,7 @@ private static string GetKeyHash(string alias, string keyStore, string password)
arguments = @"-c " + arguments;
}

proc.StartInfo.Arguments = string.Format(arguments, password, password, alias, keyStore);
proc.StartInfo.Arguments = string.Format(arguments, keystorePassword, aliasPassword, alias, keyStore);
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = true;
Expand Down