{"action":"created","issue":{"url":"https://api.github.com/repos/AzureAD/azure-activedirectory-library-for-dotnet/issues/509","repository_url":"https://api.github.com/repos/AzureAD/azure-activedirectory-library-for-dotnet","labels_url":"https://api.github.com/repos/AzureAD/azure-activedirectory-library-for-dotnet/issues/509/labels{/name}","comments_url":"https://api.github.com/repos/AzureAD/azure-activedirectory-library-for-dotnet/issues/509/comments","events_url":"https://api.github.com/repos/AzureAD/azure-activedirectory-library-for-dotnet/issues/509/events","html_url":"https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/issues/509","id":168812464,"node_id":"MDU6SXNzdWUxNjg4MTI0NjQ=","number":509,"title":"Keyset does not exist in Mono","user":{"login":"dodoatsalesforce","id":20343754,"node_id":"MDQ6VXNlcjIwMzQzNzU0","avatar_url":"https://avatars2.githubusercontent.com/u/20343754?v=4","gravatar_id":"","url":"https://api.github.com/users/dodoatsalesforce","html_url":"https://github.com/dodoatsalesforce","followers_url":"https://api.github.com/users/dodoatsalesforce/followers","following_url":"https://api.github.com/users/dodoatsalesforce/following{/other_user}","gists_url":"https://api.github.com/users/dodoatsalesforce/gists{/gist_id}","starred_url":"https://api.github.com/users/dodoatsalesforce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dodoatsalesforce/subscriptions","organizations_url":"https://api.github.com/users/dodoatsalesforce/orgs","repos_url":"https://api.github.com/users/dodoatsalesforce/repos","events_url":"https://api.github.com/users/dodoatsalesforce/events{/privacy}","received_events_url":"https://api.github.com/users/dodoatsalesforce/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2016-08-02T06:54:43Z","updated_at":"2018-07-26T16:43:39Z","closed_at":"2016-08-24T03:32:06Z","author_association":"NONE","body":"I am seeing the following stack trace when authenticating to Office 365 as a service account (with a X.509 certificate). The below stack trace only occurs when running on Mono (currently version 4.4.0.182). Doesn't happen on Windows.\n\n```\nException caught! - System.AggregateException: One or more errors occurred. ---> System.Security.Cryptography.CryptographicException: Keyset does not exist\n  at System.Security.Cryptography.RSACryptoServiceProvider.Common (System.Security.Cryptography.CspParameters p) <0x40a9b3f0 + 0x0011b> in <filename unknown>:0\n  at System.Security.Cryptography.RSACryptoServiceProvider..ctor (Int32 dwKeySize, System.Security.Cryptography.CspParameters parameters) <0x40a9b370 + 0x0005f> in <filename unknown>:0\n  at System.Security.Cryptography.RSACryptoServiceProvider..ctor (System.Security.Cryptography.CspParameters parameters) <0x40a9b340 + 0x0001b> in <filename unknown>:0\n  at Microsoft.IdentityModel.Clients.ActiveDirectory.CryptographyHelper.GetCryptoProviderForSha256 (System.Security.Cryptography.RSACryptoServiceProvider rsaProvider) <0x40a9b060 + 0x00187> in <filename u\nnknown>:0\n  at Microsoft.IdentityModel.Clients.ActiveDirectory.CryptographyHelper.SignWithCertificate (System.String message, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate) <0x40a9a730\n+ 0x000d7> in <filename unknown>:0\n  at Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate.Sign (System.String message) <0x40a9a6e0 + 0x0003b> in <filename unknown>:0\n  at Microsoft.IdentityModel.Clients.ActiveDirectory.JsonWebToken.Sign (IClientAssertionCertificate credential) <0x40a8e7e0 + 0x0005c> in <filename unknown>:0\n  at Microsoft.IdentityModel.Clients.ActiveDirectory.ClientKey.AddToParameters (IDictionary`2 parameters) <0x40a8e020 + 0x00173> in <filename unknown>:0\n  at Microsoft.IdentityModel.Clients.ActiveDirectory.DictionaryRequestParameters..ctor (System.String resource, Microsoft.IdentityModel.Clients.ActiveDirectory.ClientKey clientKey) <0x40a8dfa0 + 0x00053>\nin <filename unknown>:0\n  at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase+<SendTokenRequestAsync>d__65.MoveNext () <0x40a8dc90 + 0x000af> in <filename unknown>:0\n--- End of stack trace from previous location where exception was thrown ---\n  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x40a9e080 + 0x0002b> in <filename unknown>:0\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x40a9dbe0 + 0x000cf> in <filename unknown>:0\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x409bd120 + 0x00097> in <filename unknown>:0\n  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x40931a00 + 0x0003b> in <filename unknown>:0\n  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () <0x409acc00 + 0x00017> in <filename unknown>:0\n  at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase+<RunAsync>d__55.MoveNext () <0x40a85900 + 0x013b7> in <filename unknown>:0\n--- End of stack trace from previous location where exception was thrown ---\n  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x40a9e080 + 0x0002b> in <filename unknown>:0\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x40a9dbe0 + 0x000cf> in <filename unknown>:0\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x409bd120 + 0x00097> in <filename unknown>:0\n  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x40931a00 + 0x0003b> in <filename unknown>:0\n  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () <0x409acc00 + 0x00017> in <filename unknown>:0\n  at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext+<AcquireTokenForClientCommonAsync>d__49.MoveNext () <0x40a83d70 + 0x00333> in <filename unknown>:0\n--- End of stack trace from previous location where exception was thrown ---\n  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x40a9e080 + 0x0002b> in <filename unknown>:0\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x40a9dbe0 + 0x000cf> in <filename unknown>:0\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x409bd120 + 0x00097> in <filename unknown>:0\n  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x40931a00 + 0x0003b> in <filename unknown>:0\n  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () <0x409acc00 + 0x00017> in <filename unknown>:0\n  at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext+<AcquireTokenAsync>d__27.MoveNext () <0x40a83550 + 0x00213> in <filename unknown>:0\n  --- End of inner exception stack trace ---\n  at System.Threading.Tasks.Task.ThrowIfExceptional (Boolean includeTaskCanceledExceptions) <0x40a9fad0 + 0x0003f> in <filename unknown>:0\n  at System.Threading.Tasks.Task`1[TResult].GetResultCore (Boolean waitCompletionNotification) <0x40a9fa20 + 0x0008b> in <filename unknown>:0\n  at System.Threading.Tasks.Task`1[TResult].get_Result () <0x40a9f990 + 0x00027> in <filename unknown>:0\n  at utils.O365Auth.getAccessTokenFromCertificate (System.String tid, System.String client_id, System.String certificate_blob) [0x0003e]\n```\n\nIt seem to be related to ADAL.PCL.Desktop/CryptographyHelper.cs:GetCryptoProviderForSha256\nMono passes `rsaProvider.CspKeyContainerInfo.ProviderType == 1` so a new RSACryptoServiceProvider is created. \n\nIf I simply use the original rsaProvider, everything works and the authentication is successful. \n\nIs this an issue on Mono's end? Should I be configuring the system differently somehow?\n\nBelow is the code initiating the authentication (using ADAL v3.13.1):\n\n```\nbyte[] certificateBytes = Convert.FromBase64String(certificate_blob);\nX509Certificate2 certificate = new X509Certificate2(certificateBytes);\nClientAssertionCertificate assertion = new ClientAssertionCertificate(client_id, certificate);\nAuthenticationResult result = authContext.AcquireTokenAsync(office365OutlookResource, assertion).Result;\n```\n"},"comment":{"url":"https://api.github.com/repos/AzureAD/azure-activedirectory-library-for-dotnet/issues/comments/408160381","html_url":"https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/issues/509#issuecomment-408160381","issue_url":"https://api.github.com/repos/AzureAD/azure-activedirectory-library-for-dotnet/issues/509","id":408160381,"node_id":"MDEyOklzc3VlQ29tbWVudDQwODE2MDM4MQ==","user":{"login":"jmprieur","id":13203188,"node_id":"MDQ6VXNlcjEzMjAzMTg4","avatar_url":"https://avatars0.githubusercontent.com/u/13203188?v=4","gravatar_id":"","url":"https://api.github.com/users/jmprieur","html_url":"https://github.com/jmprieur","followers_url":"https://api.github.com/users/jmprieur/followers","following_url":"https://api.github.com/users/jmprieur/following{/other_user}","gists_url":"https://api.github.com/users/jmprieur/gists{/gist_id}","starred_url":"https://api.github.com/users/jmprieur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmprieur/subscriptions","organizations_url":"https://api.github.com/users/jmprieur/orgs","repos_url":"https://api.github.com/users/jmprieur/repos","events_url":"https://api.github.com/users/jmprieur/events{/privacy}","received_events_url":"https://api.github.com/users/jmprieur/received_events","type":"User","site_admin":false},"created_at":"2018-07-26T16:43:39Z","updated_at":"2018-07-26T16:43:39Z","author_association":"CONTRIBUTOR","body":"thanks for confirming @nddipiazza "}}
{"actor":{"display_login":"jmprieur"}}