Bug 59315 - Mono.Security.Cryptography.KeyPairPersistence attempts to create a folder in a non-writable location
Summary: Mono.Security.Cryptography.KeyPairPersistence attempts to create a folder in ...
Status: CONFIRMED
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.Security ()
Version: master
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-09-08 00:04 UTC by Timothy Risi
Modified: 2018-03-13 10:46 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 59315 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Timothy Risi 2017-09-08 00:04:21 UTC
The MachinePath property attempts to create a '.mono' folder inside Environment.SpecialFolder.CommonApplicationData.  CommonApplicationData points to '/usr/share', which is no longer a writable location as of OS X 10.11.

This causes an UnauthorizedAccessException when attempting to create the key store in System.Configuration.LicenseProvider - per https://forums.xamarin.com/discussion/comment/295354/#Comment_295354

The full stack trace for the exception is:
System.Security.Cryptography.CryptographicException: Could not create machine key store '/usr/share/.mono/keypairs'. ---> System.UnauthorizedAccessException: Access to the path "/usr/share/.mono" is denied.
at System.IO.Directory.CreateDirectoriesInternal (System.String path) [0x00057] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/corlib/System.IO/Directory.cs:118 
at System.IO.Directory.CreateDirectory (System.String path) [0x0008f] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/corlib/System.IO/Directory.cs:85 
at System.IO.DirectoryInfo.Create () [0x00000] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/corlib/System.IO/DirectoryInfo.cs:144 
at (wrapper remoting-invoke-with-check) System.IO.DirectoryInfo:Create ()
at System.IO.Directory.CreateDirectoriesInternal (System.String path) [0x00030] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/corlib/System.IO/Directory.cs:103 
at System.IO.Directory.CreateDirectory (System.String path) [0x0008f] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/corlib/System.IO/Directory.cs:85 
at Mono.Security.Cryptography.KeyPairPersistence.get_MachinePath () [0x0005e] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/Mono.Security/Mono.Security.Cryptography/KeyPairPersistence.cs:253 
--- End of inner exception stack trace ---
at Mono.Security.Cryptography.KeyPairPersistence.get_MachinePath () [0x00076] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/Mono.Security/Mono.Security.Cryptography/KeyPairPersistence.cs:257 
at Mono.Security.Cryptography.KeyPairPersistence.get_Filename () [0x0004b] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/Mono.Security/Mono.Security.Cryptography/KeyPairPersistence.cs:139 
at Mono.Security.Cryptography.KeyPairPersistence.Load () [0x00000] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/Mono.Security/Mono.Security.Cryptography/KeyPairPersistence.cs:167 
at System.Security.Cryptography.RSACryptoServiceProvider.Common (System.Security.Cryptography.CspParameters p) [0x0000c] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/corlib/System.Security.Cryptography/RSACryptoServiceProvider.cs:112 
at System.Security.Cryptography.RSACryptoServiceProvider..ctor (System.Int32 dwKeySize, System.Security.Cryptography.CspParameters parameters) [0x0001d] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/corlib/System.Security.Cryptography/RSACryptoServiceProvider.cs:84 
at DERSACryptoServiceProvider..ctor (System.Int32 dwKeySize) [0x00029] in /Users/will/Projects/Shark/st.webapp/wwwroot/App_Code/External/Base/RSA1.cs:155 
at RSA1.GenerateKeyPair (System.Int32 bitLength, DEObjectData& publicKey, DERSAParameters& privateKey) [0x00001] in /Users/will/Projects/Shark/st.webapp/wwwroot/App_Code/External/Base/RSA1.cs:195 
at RSA1KeyPairCache.ObtainKeyPair (DEObjectData& publicKey, DERSAParameters& privateKey) [0x00125] in /Users/will/Projects/Shark/st.webapp/wwwroot/App_Code/Server/RSA1KeyPairCache.cs:62 
at ServerSession..ctor (DEObjectData remoteRSA, System.Guid sessionId) [0x000a8] in /Users/will/Projects/Shark/st.webapp/wwwroot/App_Code/Server/ServerSession.cs:47 
at ServerSession.Create (DEObjectData remoteRSA, System.Guid sessionId) [0x00060] in /Users/will/Projects/Shark/st.webapp/wwwroot/App_Code/Server/ServerSession.cs:90 
at ServerSessionManager.CreateSession (DEObjectData requestData) [0x00050] in /Users/will/Projects/Shark/st.webapp/wwwroot/App_Code/Server/ServerSessionManager.cs:70 
Stacktrace:
at Mono.Security.Cryptography.KeyPairPersistence.get_MachinePath () [0x00076] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/Mono.Security/Mono.Security.Cryptography/KeyPairPersistence.cs:257 
at Mono.Security.Cryptography.KeyPairPersistence.get_Filename () [0x0004b] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/Mono.Security/Mono.Security.Cryptography/KeyPairPersistence.cs:139 
at Mono.Security.Cryptography.KeyPairPersistence.Load () [0x00000] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/Mono.Security/Mono.Security.Cryptography/KeyPairPersistence.cs:167 
at System.Security.Cryptography.RSACryptoServiceProvider.Common (System.Security.Cryptography.CspParameters p) [0x0000c] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/corlib/System.Security.Cryptography/RSACryptoServiceProvider.cs:112 
at System.Security.Cryptography.RSACryptoServiceProvider..ctor (System.Int32 dwKeySize, System.Security.Cryptography.CspParameters parameters) [0x0001d] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/corlib/System.Security.Cryptography/RSACryptoServiceProvider.cs:84 
at DERSACryptoServiceProvider..ctor (System.Int32 dwKeySize) [0x00029] in /Users/will/Projects/Shark/st.webapp/wwwroot/App_Code/External/Base/RSA1.cs:155 
at RSA1.GenerateKeyPair (System.Int32 bitLength, DEObjectData& publicKey, DERSAParameters& privateKey) [0x00001] in /Users/will/Projects/Shark/st.webapp/wwwroot/App_Code/External/Base/RSA1.cs:195 
at RSA1KeyPairCache.ObtainKeyPair (DEObjectData& publicKey, DERSAParameters& privateKey) [0x00125] in /Users/will/Projects/Shark/st.webapp/wwwroot/App_Code/Server/RSA1KeyPairCache.cs:62 
at ServerSession..ctor (DEObjectData remoteRSA, System.Guid sessionId) [0x000a8] in /Users/will/Projects/Shark/st.webapp/wwwroot/App_Code/Server/ServerSession.cs:47 
at ServerSession.Create (DEObjectData remoteRSA, System.Guid sessionId) [0x00060] in /Users/will/Projects/Shark/st.webapp/wwwroot/App_Code/Server/ServerSession.cs:90 
at ServerSessionManager.CreateSession (DEObjectData requestData) [0x00050] in /Users/will/Projects/Shark/st.webapp/wwwroot/App_Code/Server/ServerSessionManager.cs:70
Comment 1 Marek Safar 2017-09-11 12:00:14 UTC
Timothy could you provide a sample which matters for you. This stack trace seems to be from web app
Comment 2 Egorbo 2018-02-14 00:25:14 UTC
Test case:

var store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite);
store.Add(new X509Certificate2(X509Certificate.CreateFromCertFile(myCertFile)));
store.Close();