This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 51562 - NullReferenceException in BTLS X509CertificateImplBtls.Import()
Summary: NullReferenceException in BTLS X509CertificateImplBtls.Import()
Status: CLOSED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.Security (show other bugs)
Version: 4.8.0 (C9)
Hardware: PC Mac OS
: --- normal
Target Milestone: 4.8.0 (C9)
Assignee: Martin Baulig
URL:
Depends on:
Blocks:
 
Reported: 2017-01-16 18:53 UTC by Alexander Köplinger [MSFT]
Modified: 2017-03-03 21:34 UTC (History)
3 users (show)

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


Attachments

Description Alexander Köplinger [MSFT] 2017-01-16 18:53:47 UTC
Original report: https://gitter.im/mono/mono?at=587a9ed5300f220a66ea8f8e

> System.Security.Cryptography.CryptographicException : Unable to decode certificate.
>  ---- System.NullReferenceException : Object reference not set to an instance of an object
>  Stack Trace:
>      at Mono.Btls.X509CertificateImplBtls.Import (System.Byte[] data, System.String password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags) [0x00033] in <405ddf444dab4253998152605d2d9311>:0 
>      at Mono.Btls.MonoBtlsProvider.GetNativeCertificate (System.Byte[] data, System.String password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags flags) [0x00007] in <405ddf444dab4253998152605d2d9311>:0 
>      at System.Security.Cryptography.X509Certificates.X509Helper2.Import (System.Byte[] rawData, System.String password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags, System.Boolean disableProvider) [0x00017] in <405ddf444dab4253998152605d2d9311>:0 
>      at System.Security.Cryptography.X509Certificates.X509Certificate2.Import (System.Byte[] rawData, System.String password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags) [0x00000] in <405ddf444dab4253998152605d2d9311>:0 
>      at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor (System.Byte[] rawData) [0x00011] in <405ddf444dab4253998152605d2d9311>:0 
>      at Nancy.Hosting.Aspnet.NancyHandler.CreateNancyRequest (System.Web.HttpContextBase context) [0x001a1] in <1ad1d03e2aec4ce6a58c8a5ae24d0722>:0 
>      at Nancy.Hosting.Aspnet.NancyHandler+<ProcessRequest>d__2.MoveNext () [0x0000f] in <1ad1d03e2aec4ce6a58c8a5ae24d0722>:0 
>    --- End of stack trace from previous location where exception was thrown ---
>      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at Nancy.Hosting.Aspnet.Tests.NancyHandlerFixture+<Should_invoke_engine_with_requested_method>d__7.MoveNext () [0x0019f] in <9641625e55ad42f4b7956318c6bb76d0>:0 
>    --- End of stack trace from previous location where exception was thrown ---
>      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <111faffb08a0411a893ed183e82e8c28>:0 
>    --- End of stack trace from previous location where exception was thrown ---
>      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <111faffb08a0411a893ed183e82e8c28>:0 
>    --- End of stack trace from previous location where exception was thrown ---
>      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <111faffb08a0411a893ed183e82e8c28>:0 
>      at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <111faffb08a0411a893ed183e82e8c28>:0 
>    ----- Inner Stack Trace -----
>      at Mono.Btls.X509CertificateImplBtls.Import (System.Byte[] data) [0x00000] in <405ddf444dab4253998152605d2d9311>:0 
>      at Mono.Btls.X509CertificateImplBtls.Import (System.Byte[] data, System.String password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags) [0x00006] in <405ddf444dab4253998152605d2d9311>:0 

This happened after we switched to BTLS by default in one of the C9 alpha packages. Reverting to the legacy provider with MONO_TLS_PROVIDER=legacy fixed the issue so it's a BTLS specific problem.
Comment 1 Martin Baulig 2017-02-01 18:45:59 UTC
The problem is that the test is calling X509Certificate2's constructor with a null byte[].

Should be fixed by https://github.com/mono/mono/pull/4316.
Comment 3 Mohit Kheterpal 2017-02-02 12:25:54 UTC
Today, I have tried to verify this issue, but I am not sure about the steps to reproduce it. Could you please provide some steps or sample app so that we can reproduce this issue at our end and verify it?

Thanks
Comment 4 Shruti 2017-02-07 10:40:40 UTC
@Alexander, It would be great If you have a look to comment3 and give us  your valuable response. It will help us to reproduce/verify this issue.

Note You need to log in before you can comment on or make changes to this bug.