Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by mdeletrain · Jan 30, 2012 at 02:46 PM · crashiphonesecuritystrippingcryptography

Crash on a stripped iOS binary when using System.Security.Cryptography

Hi,

The game I'm working on uses several classes from the System.Security.Cryptography package. If I run it on a normal build it works perfectly, but if I try to strip it using either StrippingLevel.StripAssemblies or StrippingLevel.StripByteCode stripping levels, it crashes with a EXC_BAD_ACCESS.

Here is the mono code that crashes :

 PasswordDeriveBytes passwordDeriveBytes = new PasswordDeriveBytes(ENCODING_KEY, new byte[] {some bytes...});
 Rijndael alg = Rijndael.Create();
 alg.Key = passwordDeriveBytes.GetBytes(32);
 alg.IV = passwordDeriveBytes.GetBytes(16);

Here is the assembly code that crashes (on the last '.byte' line) :

 System_Security_Cryptography_PasswordDeriveBytes_Reset:
 
     .byte 13,192,160,225,128,64,45,233,13,112,160,225,0,93,45,233,20,208,77,226,13,176,160,225,0,160,160,225,0,0,160,227
     .byte 24,0,138,229,0,0,160,227,40,0,138,229,0,0,160,227,44,0,138,229,8,0,154,229
 bl p_209
 
     .byte 20,0,138,229,12,0,154,229,0,0,80,227,28,0,0,10,20,192,154,229,28,16,154,229,1,0,160,225,12,48,144,229
     .byte 28,0,154,229,12,32,160,225,8,32,139,229,0,32,160,227,0,0,141,229,0,0,160,227,4,0,141,229,8,0,155,229
     .byte 0,224,156,229
 bl Lm_1803

Here is the end of the stack when the application crashes :

 #0    0x0040311c in System_Security_Cryptography_PasswordDeriveBytes_Reset at /Users/me/projects/MyGame/iOS/Libraries/mscorlib.dll.s:131226
 #1    0x00402df0 in System_Security_Cryptography_PasswordDeriveBytes_GetBytes_int at /Users/me/projects/MyGame/iOS/Libraries/mscorlib.dll.s:131153

So it seems both the PasswordDeriveBytes and Rijndael instances have been created, but that the first (probably) call to GetBytes calls an inner function Reset that is actually causing the crash.

Looking at the IL code of the aforementioned classes, I extracted all dependencies to other classes and added them to the following link.xml file that I put into project's Resources folder (just to be sure and despite the fact they are all present in the assembly source) :

 <linker>
     <assembly fullname="mscorlib">
         <type fullname="System.Security.Cryptography.CipherMode" preseve="all"/>
         <type fullname="System.Security.Cryptography.CryptoConfig" preseve="all"/>
         <type fullname="System.Security.Cryptography.CryptoStream" preseve="all"/>
         <type fullname="System.Security.Cryptography.CryptoStreamMode" preseve="all"/>
         <type fullname="System.Security.Cryptography.CryptographicException" preseve="all"/>
         <type fullname="System.Security.Cryptography.CryptographicUnexpectedOperationException" preseve="all"/>
         <type fullname="System.Security.Cryptography.CspParameters" preseve="all"/>
         <type fullname="System.Security.Cryptography.DeriveBytes" preseve="all"/>
         <type fullname="System.Security.Cryptography.HashAlgorithm" preseve="all"/>
         <type fullname="System.Security.Cryptography.ICryptoTransform" preseve="all"/>
         <type fullname="System.Security.Cryptography.KeySizes" preseve="all"/>
         <type fullname="System.Security.Cryptography.PaddingMode" preseve="all"/>
         <type fullname="System.Security.Cryptography.PasswordDeriveBytes" preseve="all"/>
         <type fullname="System.Security.Cryptography.Rijndael" preseve="all"/>
         <type fullname="System.Security.Cryptography.SHA1" preseve="all"/>
         <type fullname="System.Security.Cryptography.SHA1CryptoServiceProvider" preseve="all"/>
         <type fullname="System.Security.Cryptography.SymmetricAlgorithm" preseve="all"/>
     </assembly>
 </linker>

And, to be even more complete, I also tried :

 <linker>
     <assembly fullname="mscorlib">
         <type fullname="System.Security.Cryptography" preseve="all"/>
     </assembly>
 </linker>

... but the application continues to crash. Off course, if I stop using those classes, the game works perfectly well, just lacking some features !

Edit : As a side note, I use the SHA256Managed class somewhere else in the code, which is also in the System.Security.Cryptography package, and it works perfectly well, so the problem seems tied to the PasswordDeriveBytes class or one of the class it uses...

Does anyone have any idea on what I am missing ?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image unitynoob · May 21, 2012 at 01:10 AM 0
Share

Hello how did you solve this problem? I run into the same issue. Thanks.

avatar image mdeletrain · May 21, 2012 at 08:46 AM 0
Share

We searched for the exact cryptography class that was causing the problem by successively deactivating whole portions of code until the game stops crashing. Then we stopped using that class, replacing it by our own implementation of it.

Unfortunately, I don't remember what class it was, probably a Rijndael related one.

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by cpx_matthew · Apr 23, 2013 at 05:51 AM

Avoid the call to Rijndael.Create(); which uses dynamic providers and reflection and instead directly use a concrete provider.

For example, I fixed Uniweb Websockets on iOS AOT by replacing

 var sha = System.Security.Cryptography.SHA1.Create ();

with

 var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider ();

This looks to be fixed in Mono 3.0.2. Commit notes:

  Make the Crypto stack work with Full AOT.
 
 * System.Security.Cryptography.*cs: To make Crypto work with
     Full AOT we remove the usage of providers and reflection. We hardcode
     the default algorithms for hashing, rng and symmetric cyphers.


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Rod-Green · Mar 24, 2012 at 12:46 AM

Try changing "

This tripped me up too..

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KimPixeleap · Feb 25, 2013 at 01:19 PM 0
Share

Can anyone confirm that this will fix the problem?

avatar image
0

Answer by nah0y · Jul 01, 2013 at 12:30 PM

Same thing here, the correct syntax working for me is :

 <linker>
     <assembly fullname="mscorlib">
         <namespace fullname="System.Security.Cryptography" preserve="all" />
     </assembly>
 </linker>
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[URGENT] OpenFeint integration problems 0 Answers

Tracking down a SIGABRT on startup 8 Answers

[iOS Memory Question] At ~35MB of memory on a heavily multitasked iPhone4/iPad we are getting suspend-crashes after lowmemory warnings. Is there anything we can do? 1 Answer

Does Unity have any symmetric crypto libraries? 1 Answer

Program Recieved Signal: 0 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges