Search Unity

CrossPlatformValidator throws InvalidSignatureException

Discussion in 'Unity IAP' started by hippo_san, May 15, 2019.

  1. hippo_san

    hippo_san

    Joined:
    Oct 29, 2014
    Posts:
    23
    Hi, I saw there were a couple of threads about this topic but I didn't manage to find the right answer. My problem is when CrossPlatformValidator always throws an InvalidSignatureException when I'm buying an auto-renewable product from the store.

    Here is my code:
    Code (CSharp):
    1. PurchaseProcessingResult IStoreListener.ProcessPurchase (PurchaseEventArgs args) {
    2.     try {
    3.       var receipts = validator.Validate (args.purchasedProduct.receipt);
    4.     } catch (IAPSecurityException e) {
    5.         Debug.LogException(e);
    6.     }
    7.        return PurchaseProcessingResult.Complete;
    8.     }
    The error only happens on Android. Here is the log from logcat:
    05-15 10:20:21.562 17378 17446 E Unity : InvalidSignatureException: Exception of type 'UnityEngine.Purchasing.Security.InvalidSignatureException' was thrown.
    05-15 10:20:21.562 17378 17446 E Unity : at UnityEngine.Purchasing.Security.GooglePlayValidator.Validate (System.String receipt, System.String signature) [0x00000] in <filename unknown>:0
    05-15 10:20:21.562 17378 17446 E Unity : at UnityEngine.Purchasing.Security.CrossPlatformValidator.Validate (System.String unityIAPReceipt) [0x00000] in <filename unknown>:0
    05-15 10:20:21.562 17378 17446 E Unity : UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
    05-15 10:20:21.562 17378 17446 E Unity : UnityEngine.DebugLogHandler:LogException(Exception, Object)
    05-15 10:20:21.562 17378 17446 E Unity : UnityEngine.Logger:LogException(Exception, Object)
    05-15 10:20:21.562 17378 17446 E Unity : UnityEngine.Debug:LogException(Exception)

    I'm doing a sandbox test and the receipt looks correct. Here is the receipt json from logcat:
    {"Store":"GooglePlay","TransactionID":"GPA.3317-...","Payload":"{\"json\":\"{\\\"orderId\\\":...

    Environment:
    Unity 2017.4.20f2
    Unity IAP 1.22.0

    What could cause InvalidSignatureException? I also filed a report here https://analytics.cloud.unity3d.com/support/.
     
    Last edited: May 15, 2019
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Does it occur on all your purchases? An invalid signature would cause the exception.
     
  3. hippo_san

    hippo_san

    Joined:
    Oct 29, 2014
    Posts:
    23
    Yes, it occurs on all purchases on Android. What caused an invalid signature?
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you test with Unity 2018.3 or above?
     
  5. hippo_san

    hippo_san

    Joined:
    Oct 29, 2014
    Posts:
    23
    Sadly testing with 2018.3 or above would involve too many changes, it's not an option. However I tried to run another project with the same setup, and everything is fine. So I suppose it's not related to Unity version.
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you elaborate, "everything is fine", so you are not seeing the exception in another project? What is different?
     
  7. hippo_san

    hippo_san

    Joined:
    Oct 29, 2014
    Posts:
    23
    Yes, I didn't see any exceptions in another project. These two projects share the same Google Play RSA public key and code base. And this is exactly what I'm wondering about - why one works but not the other.
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I tested with 2018,3 without issue. This the code I'm using. Did you remember to generate your Tangle files?

    Code (CSharp):
    1. #if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
    2.  
    3.         var validator = new CrossPlatformValidator(GooglePlayTangle.Data(),
    4.            AppleTangle.Data(), Application.identifier);
    5.  
    6.  
    7.         try
    8.         {
    9.             // On Google Play, result has a single product ID.
    10.             // On Apple stores, receipts contain multiple products.
    11.             var result = validator.Validate(args.purchasedProduct.receipt);
    12.             // For informational purposes, we list the receipt(s)
    13.             Debug.Log("Receipt is valid. Contents:");
    14.             foreach (IPurchaseReceipt productReceipt in result)
    15.             {
    16.                 MyDebug(productReceipt.productID);
    17.                 MyDebug(productReceipt.purchaseDate.ToString());
    18.                 MyDebug(productReceipt.transactionID);
    19.             }
    20.         }
    21.         catch (Exception e)
    22.         {
    23.             MyDebug("Invalid receipt, not unlocking content" + e.Message.ToString());
    24.             validPurchase = false;
    25.         }
    26.         #endif
     
  9. hippo_san

    hippo_san

    Joined:
    Oct 29, 2014
    Posts:
    23
    This is my code of making the validator which exactly like yours:
    Code (CSharp):
    1. validator = new CrossPlatformValidator (GooglePlayTangle.Data (), AppleTangle.Data (), Application.identifier);
    Is this code for generating Tangle files?
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  11. hippo_san

    hippo_san

    Joined:
    Oct 29, 2014
    Posts:
    23
    Unfortunately, this does not help either... I copied RSA public key from Services and APIs in Google Play Console, and pasted it to Receipt Validation Obfuscator, then pressed "Obfuscate Google Play License Key".

    I notice that there are a bunch of other errors print out after purchasing succeeded from the store (the green check icon shows), for example:
    05-16 10:50:01.370 22324 22460 D Unity : ? getMethodID("java.lang.Class", "forName", "(Ljava/lang/String;)Ljava/lang/Object;", static)
    05-16 10:50:01.370 22324 22460 D Unity : ! Class Class.forName(String);
    05-16 10:50:01.370 22324 22460 D Unity : > AndroidJNI_CUSTOM_INTERNAL_CALL_ExceptionOccurred()
    05-16 10:50:01.370 22324 22460 D Unity : > AndroidJNI_CUSTOM_DeleteLocalRef()
    05-16 10:50:01.370 22324 22460 D Unity : > AndroidJNI_CUSTOM_DeleteLocalRef()
    05-16 10:50:01.370 22324 22460 D Unity : > AndroidJNI_CUSTOM_INTERNAL_CALL_FromReflectedMethod()
    05-16 10:50:01.370 22324 22460 D Unity : > AndroidJNI_CUSTOM_INTERNAL_CALL_ExceptionOccurred()
    05-16 10:50:01.370 22324 22460 D Unity : > AndroidJNI_CUSTOM_DeleteLocalRef()
    05-16 10:50:01.370 22324 22460 D Unity : > AndroidJNI_CUSTOM_INTERNAL_CALL_NewStringUTF()
    05-16 10:50:01.370 22324 22460 D Unity : > AndroidJNI_CUSTOM_INTERNAL_CALL_ExceptionOccurred()
    05-16 10:50:01.370 22324 22460 D Unity : > AndroidJNI_CUSTOM_INTERNAL_CALL_CallStaticObjectMethod(0x2a4a, 0x6f8d6bac
    05-16 10:50:01.370 22324 22460 D Unity : > , 00000015
    05-16 10:50:01.370 22324 22460 D Unity : > )

    Don't know if it has something to do with this.
     
  12. hippo_san

    hippo_san

    Joined:
    Oct 29, 2014
    Posts:
    23
    Now it works! I opened Window - Services - In-app Purchasing, then I found a newer version was detected. After updating to the new version, it works. I wonder why it is not the case for the other project that I mentioned before. They are in the same Unity project, just different scenes.
     
  13. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Sorry I'm not clear, you said both "why it is not the case for the other project" followed by "They are in the same Unity project"
     
  14. hippo_san

    hippo_san

    Joined:
    Oct 29, 2014
    Posts:
    23
    Sorry what I meant is I have two scenes (although they use different App IDs so I treat it as two "projects"). It has no problem when building and running one of the two, but the other requires to update Unity IAP plugin to work. However after updating the plugin from Window - Services - In-app Purchasing, the version of the plugin did not change, but the purchasing works somehow.
     
  15. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Sorry I'm still not clear. What AppIDs are you referring to? If they are separate projects, you need to load each individually in Unity by opening a separate project. At any rate, you'll need to figure out what is different between the two projects. Look for any differences under Package Manager too. Are both projects created with the same version of Unity? Do they have different assets installed, etc.
     
  16. hippo_san

    hippo_san

    Joined:
    Oct 29, 2014
    Posts:
    23
    They are not different projects, just two different scenes. But the information, e.g. Bundle ID in Player Settings are configured differently for each of them. You can think I mixed two apps into one Unity project, and they share the same code base. I'm using Unity 2017.4.20, where can I find Package Manager?
     
  17. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You can't mix two apps in one project. Please show a screenshot. And for questions regarding Package Manager, please open a separate topic. Package Manager was introduced in Unity 2018.
     
  18. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    I must awaken this thread because I just came about the same error and I also found myself in the scenario where I had to update Unity IAP. I thought I might test this on my side by doing the update and see if it resolved the error when trying to test the purchasing of IAP items.

    But I made something bad. I stopped the process before the importing phase (where the hierarchy of the files to be installed in Assets is explained) because I forgot to back the project up before the update.
    I closed Unity, made the project's backup and reopened it. I knew it might be leaving an unclean version and I was right.
    In Services, the Unity IAP module told me the system was up to date and the button first showed "Import" before quickly changing to "Reimport" as a I moved the cursor closer to it. The installation files had not been completely removed and it seems the installation process has not really been entirely built with, in mind, the (unsafe) possibility that someone might interrupt and stop the installation process and even close Unity.
    Nevertheless, I looked into the Package Manager too and still was on 3.0.1 although I saw the 3.0.2 was there and it was verified btw, contrary to 3.0.1.
    So, ahem, I went on to reimport the files through the little Unity IAP Installer popup, with its message "please import Unity packages in sequence".
    I also docked the Package Manager tab and kept an eye on it.
    I cleaned the installation scripts and waited for the PM to show that I had moved to IAP 3.0.2. Nope, still on 3.0.1 and I had four new errors:

    I have a few ideas about what to do, following the suggestions in these error logs like destroying all files named in these logs, then perhaps reimport things either via the Service tab or via the Package Manager, but I'd rather follow proper counsel before doing experimentations on my side.

    I hope that when the situation will be solved without using the Package Manager's "Update to xxx" button, it will refresh itself automatically and display IAP v3.0.2.

    In fact, that's something I don't understand. If the Package Manager is meant to be a hub, shouldn't the Update button in Services open the PM and at least furnish the illusion (maybe) that it's the PM that's called to manage the update? Why is there a little IAP updater popup at all?
     
  19. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    For extra fun, in the Services' IAP tab, there's the Options category right below the Welcome section, showing the key for Analytics. I'm also shown that I can update it. But when I go in Analytics tab, there's no such suggestion. What gives?
     
  20. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    This is what I did. I remove the IAP package and deactivated the IAP module in Services.
    I deleted the two Unity Purchasing folders in Plugins and Scripts.
    Then I closed Unity and deleted the Library folder.
    Relaunched Unity, forcing the Library folder to be rebuilt. Loaded iOS build settingds (it's on PC/Mac by default).
    Loaded the scene to test IAPs on the computer.
    I checked the IAP module in Services, I'm told to update it but the IAP package in the PM is at 3.0.2 (verified), for the latest 2019.4 LTS.
    So this is basically my project state before I begun an update which I didn't complete (remember, I stopped it before the importation phase).
    Without the IAP update from Services and trying to buy some items, without surprise I still get the error reported by hippo_san. Right.

    I doubt this might be caused by the plugin that I use to manage the IAP part. It comes with a fakestore management but didn't bother me before.

    I do not understand why Unity makes a difference between Services: IAP and Package Manager: IAP. This is confusing.
    Despite being on the highest version as of now (3.0.2), the former still tells me to go for an update.
    So this time I do a proper backup of what I deem to be a clean version, minus this relatively new bug.

    Again, I'll go through this step by step, following this method because it seems to have worked for hippo_san.
    https://forum.unity.com/threads/cro...nvalidsignatureexception.678703/#post-4547032

    First, the update through the Services: IAP module (with the Unity IAP installer).
    I see the Purchasing.Common.dll in UnityPurchasing > Bin that proved troublesome before. Let's import all that stuff nevertheless and see what happens. I'm hoping that Unity will be smart and avoid the former caveats.

    Installing... ...

    There we go.
    I get the same four errors. *sigh*
    I can't stand it. This is just retarded. Do the thing by the book, follow Unity's own instructions, be served with file conflicts.
    What I love is that in the IAP module it reads "import our store package to get started on:", huh, a store package. So it's both a store (asset, implied) and a package too... which if you didn't know *.package being the extension of Unity assets gotten from the store (\O/). Or it means it's just that, a package from the store but then Unity should throw a warning about this.
    Why can't that module tell me "oh, right, you already have the package manager's IAP, don't mind our notification, actually forget about it entirely and we're not going to display anything any longer, we're on the same team, sorry for the trouble"?

    Unity really needs to put to rest that schizophrenic mindset about not being able to decide whether it should go full asset or full package on such essential systems. It's absolutely laughable that the software has two brains that can't even talk to each other, are not aware of each other, and require modifications that generate pure and unadultered internal conflicts. It's insane.

    In other words, I'll just IGNORE UNITY and never update through the Services' tab anymore. Stupid design is stupid.
    Then I'll have to find why the original bug happens at all.
    What a complete waste of time. Thank you.


    EDIT: after typing this I took another look at Services: IAP and again there was that UPDATE button. The hell? Clicked on it, it transformed into REIMPORT. Ok, clicking on it does nothing aside from quickly displaying a small rectangular pop up that flashes in and out, barely any time to read what it does. Having enough of this nonsense, I close Unity and reopen it.
    11 frigging errors in the console right from the beginning. Library this, assembly that, all to do with purchasing. This is just a sad joke.
     
    Last edited: Apr 9, 2021
  21. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Unity IAP is a Package Manager product now, please follow the instructions in the release notes. You likely want to use a project backup prior to your upgrade process. Also, compare to a new project when adding IAP. Are you using asmdefs? You need to add additional IAP references if so (Security and SecurityStub). Your post does not look related to the CrossPlatformValidator.
     

    Attached Files: