I am having a problem where my C# program running in Mono on a Raspberry Pi with Arch Linux gives an error when I try to make it load a key from an XML string or file. It can encrypt and decrypt a message when I tell it to generated its own keys but if I were to take the exact same XML of the generated keys gotten from ToXmlString and give them to it through FromXmlString then it complains about "System.Security.Cryptography.CryptographyException: Couldn't decode XML...".
I should mention that providing any code is probably useless because the exact same code works perfectly when run on Windows or my Arch Linux desktop, the issue obviously has something to do with the ARM Mono implementation for the RPi which after a quick version check is said to be V2 (I have updated it just now) whereas my desktop Arch Linux has V4.
I would therefore like to know if anyone knows of a workaround for this or could report it as a bug to the Mono developers.
EDIT:
Here is the full console output:
Unhandled Exception: System.Security.Cryptography.CryptographicException: Couldn't decode XML ---> System.Security.Cryptography.CryptographicException: Private/public key mismatch
at Mono.Security.Cryptography.RSAManaged.ImportParameters (RSAParameters parameters) [0x00000] in :0
at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters (RSAParameters parameters) [0x00000] in :0
at System.Security.Cryptography.RSA.FromXmlString (System.String xmlString) [0x00000] in :0
--- End of inner exception stack trace ---
at System.Security.Cryptography.RSA.FromXmlString (System.String xmlString) [0x00000] in :0
at PHPEncryptTest.RSA.EncryptData (System.String strData2Encrypt) [0x00000] in :0
at PHPEncryptTest.Program.Main (System.String[] args) [0x00000] in :0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Security.Cryptography.CryptographicException: Couldn't decode XML ---> System.Security.Cryptography.CryptographicException: Private/public key mismatch
at Mono.Security.Cryptography.RSAManaged.ImportParameters (RSAParameters parameters) [0x00000] in :0
at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters (RSAParameters parameters) [0x00000] in :0
at System.Security.Cryptography.RSA.FromXmlString (System.String xmlString) [0x00000] in :0
--- End of inner exception stack trace ---
at System.Security.Cryptography.RSA.FromXmlString (System.String xmlString) [0x00000] in :0
at PHPEncryptTest.RSA.EncryptData (System.String strData2Encrypt) [0x00000] in :0
at PHPEncryptTest.Program.Main (System.String[] args) [0x00000] in :0
I have been running mono on RPI for a while now, but i have not gone into the security namespace, since mono best supported on linux and they are porting (lose words) the .Net framework to fit linux we can always expect some bugs, especially when namespaces as security,
check out: Mono System.Security.Cryptography.CryptographicException when running on Linux
Related
I have an application which utilizes GeckoFX/xulrunner 22.
This program works great in Windows but no matter what I do I cannot get it to run in Linux nor Mac.
The primary focus is Mac though.
I've tried swapping out different versions of Windows, Linux & Mac xulrunner run-times as well as different initialization strings to try including both the Windows, Linux and Mac versions (of course only one at a time) like:
Gecko.Xpcom.Initialize("lib/xulrunner");
Gecko.Xpcom.Initialize("lib/XUL.framework/Versions/Current");
I have also tried prefixing with "./" as well as using code to obtain the current working directory to prepend to the path.
I've also tried copying over a dozen different versions of xul.dll into the executable folder and subdirectories within it.
No matter what I think to try, or search this site/google to try nothing has worked.
This is failing on the Initialize() call.
The program/class names are only starred out so this is not the first thing popping up in google when people search for the program.
Although my biggest concern is getting this running on Mac, I will also mention due to other posts on Stack Overflow and alike that on my Linux system, I have tried having various versions of Firefox installed and the path pointed to as per other peoples' instructions. It always shows the same error as on Mac.
Error follows: Unhandled Exception:
System.DllNotFoundException: xul
at (wrapper managed-to-native) Gecko.Xpcom:Alloc (intptr)
at Gecko.nsAString..ctor () [0x00000] in :0
at Gecko.nsAString..ctor (System.String value) [0x00000] in :0
at Gecko.Xpcom.Initialize (System.String binDirectory) [0x00000] in :0
at **********.**********.CreateBrowsers () [0x00000] in :0
at **********.**********.**********_Shown (System.Object sender, System.EventArgs e) [0x00000] in :0
at System.Windows.Forms.Form.OnShown (System.EventArgs e) [0x00000] in :0
at System.Windows.Forms.Form.SetVisibleCore (Boolean value) [0x00000] in :0
at System.Windows.Forms.Control.set_Visible (Boolean value) [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:set_Visible (bool)
at System.Windows.Forms.Application.RunLoop (Boolean Modal, System.Windows.Forms.ApplicationContext context) [0x00000] in
:0
at System.Windows.Forms.Application.Run (System.Windows.Forms.ApplicationContext context) [0x00000] in
:0
at System.Windows.Forms.Application.Run (System.Windows.Forms.Form mainForm) [0x00000] in :0
at **********.Program.Main () [0x00000] in :0
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: xul
at (wrapper managed-to-native) Gecko.Xpcom:Alloc (intptr)
at Gecko.nsAString..ctor () [0x00000] in :0
at Gecko.nsAString..ctor (System.String value) [0x00000] in :0
at Gecko.Xpcom.Initialize (System.String binDirectory) [0x00000] in :0
at **********.**********.CreateBrowsers () [0x00000] in :0
at **********.**********.**********_Shown (System.Object sender, System.EventArgs e) [0x00000] in :0
at System.Windows.Forms.Form.OnShown (System.EventArgs e) [0x00000] in :0
at System.Windows.Forms.Form.SetVisibleCore (Boolean value) [0x00000] in :0
at System.Windows.Forms.Control.set_Visible (Boolean value) [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:set_Visible (bool)
at System.Windows.Forms.Application.RunLoop (Boolean Modal, System.Windows.Forms.ApplicationContext context) [0x00000] in
:0
at System.Windows.Forms.Application.Run (System.Windows.Forms.ApplicationContext context) [0x00000] in
:0
at System.Windows.Forms.Application.Run (System.Windows.Forms.Form mainForm) [0x00000] in :0
at **********.Program.Main () [0x00000] in :0
Firstly, to my knowledge no one has ever run geckofx on OSX.
The problem you are seeing is probably easy fixable but before getting geckofx to work on mac you will likely hit more problems.
Geckofx's architecture on Windows is simple. The GeckoWebBrowser control is a winforms based control, which underneath are win32 controls and gecko/firefox on windows also uses win32 controls.
However on Linux things are a little more complicated as gecko/firefox uses GTK while the mono winform implementation is based upon X11. Hence geckofx has some fairly complex code to make that all work. (Which is why one needs to use a different build of geckofx on Linux (one with the GTK flag defined).
So firstly on OSX you have to determine what UI toolkit does mono uses for winforms, is it X11, carbon or something else? Then you have to determine which toolkit Firefox uses on OSX, carbon, cocoa or something else? If they happen to match then its probably worth proceeding with the windows build of geckofx. If they are different then you will probably have to modify geckofx itself to deal with this issue.
Now on to the DllNotFoundException.
The PInvoke/DllImport calls are probably looking for "xul.dll". This file could be named something different in OSX's firefox (eg. libxul.so) so a dllmap config file is needed to map xul.dll to the correct file.
Also setting these two environment variables, MONO_LOG_LEVEL="debug" and MONO_LOG_MASK="dll" should provide you with useful debug information.
Additionally one can use an absolute path for Gecko.Xpcom.Initialize to avoid any confusion about finding the path.
I'm working on a Unity3d project that involves Databases,
I wanted the other developer to work on the server's and produce a DLL for me to use in Unity
I tried to work directly in Unity with SqlServerCe but it always stated that it's missing libs
So I managed to load the Backend's DLL successfully in Unity3D (Using v3.5 .Net Client Profile, in both the VS and Unity's Mono Develop)
It initializes the SQL components successfully (reader ... etc)
But when I execute the reader the DLL returns this exception as a string (I handled that when an exception occurs it's returned as a string)
The Exception:
System.InvalidProgramException: Missing or incorrect header for method CompileQueryPlan
at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand (CommandBehavior behavior, System.String method, ResultSetOptions options) [0x00000] in <filename unknown>:0
at System.Data.SqlServerCe.SqlCeCommand.ExecuteReader (CommandBehavior behavior) [0x00000] in <filename unknown>:0
at System.Data.SqlServerCe.SqlCeCommand.ExecuteReader () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Data.SqlServerCe.SqlCeCommand:ExecuteReader ()
at AbuEl3orrefDatabaseBackend.DBHandler.PrepareAllQuestions () [0x00000] in <filename unknown>:0
Well I finally found the solution,
I was on Web Platform, as it doesn't support SQL Server Compact, so I switched to Desktop Platform from the Build Settings.
I downloaded the eBay SDK for use in an internal application we are developing. The catch is we are developing on Mono. When I run the eBay Hello World sample on .NET, it displays the following output:
+++++++++++++++++++++++++++++++++++++++
+ Welcome to eBay SDK for .Net Sample +
+ - HelloWorld +
+++++++++++++++++++++++++++++++++++++++
Begin to call eBay API, please wait ...
End to call eBay API, show call result:
eBay official Time: 11/27/2013 3:02:19 PM
When I run it with Mono, I get the following:
Unhandled Exception: eBay.Service.Core.Sdk.ApiException: Exception has been thrown by the target of an invocation.
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.InvalidOperationException: WebServiceBindingAttribute is required on proxy class 'eBay.Service.Core.Sdk.eBayAPIInterfaceService2'.
at System.Web.Services.Protocols.SoapTypeStubInfo..ctor (System.Web.Services.Protocols.LogicalTypeInfo logicalTypeInfo) [0x00000]
at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (object,object[],System.Exception&)
etc...etc...etc...
I found a workaround and will post it in an answer below.
I searched Xamarin's Bugzilla and found nothing, but I found this relevant bug posted in Novell's old Mono Bugzilla: https://bugzilla.novell.com/show_bug.cgi?id=693367
So I dug through the eBay SDK source and found that this was indeed the issue. eBay.Service.Core.Sdk.eBayAPIInterfaceService2 inherits from eBay.Service.Core.Sdk.eBayAPIInterfaceService, which is decorated with a System.Web.Services.WebServiceBindingAttribute.
So I changed eBay.Service.Core.Sdk.eBayAPIInterfaceService2, adding [System.Web.Services.WebServiceBindingAttribute(Name = "eBayAPISoapBinding", Namespace = "urn:ebay:apis:eBLBaseComponents")] so that it now looks like the following:
using System;
using System.Net;
using eBay.Service.Core.Soap;
namespace eBay.Service.Core.Sdk {
/// <summary>
/// Enhanced eBayAPIInterfaceService with GZIP compression support.
/// </summary>
[System.Web.Services.WebServiceBindingAttribute(Name = "eBayAPISoapBinding", Namespace = "urn:ebay:apis:eBLBaseComponents")]
internal class eBayAPIInterfaceService2 : eBayAPIInterfaceService {
...
}
}
I followed the instructions in the eBay SDK for building from the sources and the problem was solved.
Footnote: Incidentally, if this is your first time using Mono to connect to an HTTPS web service, you will likely immediately run into another exception. That one will look like this:
Unhandled Exception: System.Net.WebException: Error getting response stream (Write: The authentication or decryption has failed.): SendFailure ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010a
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection certificates) [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 () [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) Mono.Security.Protocol.Tls.Handshake.HandshakeMessage:Process ()
at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg) [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
For the solution to that, go here: http://www.mono-project.com/FAQ:_Security
I've recently came across the blog article Monovation: Assembly Injection into Live Processes of Miguel de Icaza.
I've tried to reproduce it with no luck. My command line was
'csharp --attach 5612'
where 5612 was the pid of a simple running mono 'Hello World' console application.
I've got an exception (see the stack trace above).
What I've tried so far:
using Mono 2.10.8 (csharp and csharp2 commands for .NET 4 and 2 )
using Mono 3.2.3 (only csharp command exists)
Q1: Missed I something?
Q2: Is it possible that this virtual machine attach facility (see Monovation: Assembly Injection into Live Processes) is available only in Linux installations? (I am using Windows 7) It sounds an easy answer, but Miguel does not mention platform restriction in his article, and the whole point of mono is the multiplatform, is not it? So I can not believe it so easy.
Q3: What about Mac? Is there any chance it will work in a Mac, or we must look elsewhere?
Thx in advance
Stack trace:
Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for Mono.Unix.Native.Syscall ---> System.EntryPointNotFoundException: Mono_Posix_Syscall_get_at_fdcwd
at (wrapper managed-to-native) Mono.Unix.Native.Syscall:get_at_fdcwd ()
at Mono.Unix.Native.Syscall..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Mono.Unix.UnixUserInfo.GetRealUserId () [0x00000] in <filename unknown>:0
at Mono.Unix.UnixUserInfo.GetRealUser () [0x00000] in <filename unknown>:0
at Mono.Attach.VirtualMachine.Attach (System.String agent, System.String args) [0x00000] in <filename unknown>:0
at Mono.ClientCSharpShell..ctor (Mono.CSharp.Evaluator evaluator, Int32 pid) [0x00000] in <filename unknown>:0
at Mono.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for Mono.Unix.Native.Syscall ---> System.EntryPointNotFoundException: Mono_Posix_Syscall_get_at_fdcwd
at (wrapper managed-to-native) Mono.Unix.Native.Syscall:get_at_fdcwd ()
at Mono.Unix.Native.Syscall..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Mono.Unix.UnixUserInfo.GetRealUserId () [0x00000] in <filename unknown>:0
at Mono.Unix.UnixUserInfo.GetRealUser () [0x00000] in <filename unknown>:0
at Mono.Attach.VirtualMachine.Attach (System.String agent, System.String args) [0x00000] in <filename unknown>:0
at Mono.ClientCSharpShell..ctor (Mono.CSharp.Evaluator evaluator, Int32 pid) [0x00000] in <filename unknown>:0
at Mono.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
Debian Sid, Mono 3.0. I'm trying to run mvc application (it worked before upgrading mono to 3.0). This is exception thrown:
Exception caught during reading the configuration file:
System.MissingMethodException: Method not found: 'System.Configuration.IConfigurationSectionHandler.Create'.
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00000] in <filename unknown>:0
at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00000] in <filename unknown>:0
at System.Configuration.ConfigurationManager.get_AppSettings () [0x00000] in <filename unknown>:0
at Mono.WebServer.Apache.Server.get_AppSettings () [0x00000] in <filename unknown>:0
at Mono.WebServer.Apache.Server+ApplicationSettings..ctor () [0x00000] in <filename unknown>:0
I've also found tip to make change in /usr/bin/mod-mono-server4 from:
#!/bin/sh
exec /usr/bin/mono $MONO_OPTIONS "/usr/lib/mono/4.0/mod-mono-server4.exe" "$#"
To:
#!/bin/sh
exec /usr/bin/mono $MONO_OPTIONS "/usr/lib/mono/4.5/mod-mono-server4.exe" "$#"
Unfortunatelly, there is no such file: /usr/lib/mono/4.5/mod-mono-server4.exe (no such file in /usr/lib/mono/4.5/ directory).
Do you have any ideas what's wrong? My application is ServiceStack simple webpage and it works on mono 2.10. But it doesn't work anymore after upgrade to 3.0.
You need to add a symbolic link for that file
# ln -s /usr/lib/mono/4.0/mod-mono-server4.exe /usr/lib/mono/4.5/mod-mono-server4.exe
That way it will still use mod-mono-server4.exe but with the 4.5 dll's