We are using Renci.SshNet C# library to connect to SFTP server.
Today connection on code line
client.Connect();
to server stopped working with error message:
Unhandled Exception: Renci.SshNet.Common.SshConnectionException: The
connection was closed by the server: Your cipher needs to be updated:
https://developer.eba
y.com/devzone/merchant-products/mipng/user-guide-en/default.html#advanced-featur
es.html . please contact MIP Support for help (ByApplication). at
Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan
timeout)
I installed latest SSH.NET and .NET Framework, and still same error
Could anyone help what needs to be done to fix that error?
Appreciate any help
I encountered the same issue. Here is the fix for SSH.NET client w/ C#
var connectionInfo = new ConnectionInfo(...);
var deprecatedMacs = new List<string>
{
"hmac-md5",
"hmac-md5-96",
"hmac-md5-etm#openssh.com",
"hmac-sha1-96",
"hmac-sha2-256-96",
"hmac-sha2-512-96"
};
var deprecatedCiphers = new List<string>
{
"aes128-cbc",
"aes192-cbc",
"aes256-cbc",
"blowfish-cbc",
"3des-cbc",
"3des-ctr",
"arcfour",
"arcfour128",
"arcfour256"
};
// remove deprecated macs
foreach(var deprecatedMac in deprecatedMacs)
{
connectionInfo.HmacAlgorithms.Remove(deprecatedMac);
}
// remove deprecated ciphers
foreach(var deprecatedCipher in deprecatedCiphers)
{
connectionInfo.Encryptions.Remove(deprecatedCipher);
}
using (var client = new SftpClient(connectionInfo))
{
try
{
client.Connect(); // Should work now
}
catch (Exception ex)
{
// ...
}
}
Related
I'm trying to produce to kafka using c# and confluent.
This code works just fine when I'm connected To Internet:
ProducerConfig _config = new ProducerConfig();
_config.BootstrapServers = "127.0.0.1:9092";
using (var producer = new ProducerBuilder<Null, string>(_config).Build())
{
await producer.ProduceAsync("NewTopic", new Message<Null, string> { Value = "NewTopic" });
producer.Flush(TimeSpan.FromSeconds(10));
Console.WriteLine("Message Send!");
Console.ReadLine();
}
But When I'm Offline I Get This Error: %3|1639785660.784|FAIL|rdkafka#producer-1| [thrd:localhost:9092/0]: localhost:9092/0: Failed to resolve 'localhost:9092': The requested name is valid, but no data of the requested type was found. (after 4ms in state CONNECT)
Does Anyone Knows Why?
i programming an Application for my study.
I try to use gRPC in Xamarin.Forms.
The gRPC is in a seperate Libyry (.NET Standart 2.1).
If i use the code in WPF-Core Project every thing works fine.
But if I try to use the same in my Xamarin.Forms-Project the Connection don't work.
if I use the connectionString "http://my.server.com:5050" I get these Exception
Error starting gRPC call: unexpected end of stream on Connection{my.server.com:5050, proxy=DIRECT hostAddress=5.189.149.82 cipherSuite=none protocol=http/1.1} (recycle count=0)
if I the SSL Version"https://my.server.com:5050" I get these Exception
Error starting gRPC call: Connection closed by peer
Here is the Code of the gRPC-Libary
...
if (connectionString.Contains("http://"))
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
channel = GrpcChannel.ForAddress(connectionString);
client = new Haushaltsbuch.HaushaltsbuchClient(channel);
SuccsessReply reply = new SuccsessReply { Result = false };
try
{
reply = client.Login(new UserRequest
{
User = new GRPC_User
{
Username = username,
PassHash = passHash
}
});
}
catch (RpcException e) when (e.Status.Detail.Contains("The SSL connection could not be established"))
{
client = null;
throw new CommunicationException("Fehler mit SSL-Zertifikat des Servers", e);
}
catch (RpcException e)
{
client = null;
throw new CommunicationException("Server nicht erreichbar", e);
}
...
I am only a student and if I google, then it says that Xamarin Forms is supporting gRPC.
But why is it not working?
the .Android Project has the GRPC.Core package from NuGet istalled.
Solved it by Replacing
channel = GrpcChannel.ForAddress(connectionString);
with
if (connectionString.Contains("http://"))
{
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
string newConString = connectionString.Replace("http://", "");
return new Channel(newConString, ChannelCredentials.Insecure);
}
else
{
string newConString = connectionString.Replace("https://", "");
return new Channel(newConString, new SslCredentials());
}
It seems like the GrpcChannel Class isn't working on Andriod.
Update: May, 2021
Xamarin does not fully support gRPC, so be aware of this when developing your software on Xamarin.Forms.
Starting w/ gRPC version 2.34.X, gRPC has started partial support for Xamarin.Forms w/ Android and iOS devices.
Please see this for more information.
I'm working on a Xamarin application where i'm establishing a connection with a Server. The server code is currently a blackbox for me, i only have the documentation.
However, since the server switched to TLS1.2 i'm trying use .NET's SslStream to authenticate on my app. I made sure that both are using the same certificate. The certificate is selfsigned though.
Whenever i try to do AuthenticateAsClient i get the following exception:
Mono.Security.Interface.TlsException: Unknown Secure Transport error `PeerHandshakeFail'.
Here's some part of my code:
using (var stream = new SslStream(new NetworkStream(mainSocket), false, new RemoteCertificateValidationCallback(ValidateServerCertificate)))
{
try
{
stream.AuthenticateAsClient(ServerIpAdressServer, GetX509CertificateCollection(), System.Security.Authentication.SslProtocols.Tls12, false);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
(The ValidateServerCertificate always returns true)
Here's my method to get the certificate:
public static X509CertificateCollection GetX509CertificateCollection()
{
var assembly = IntrospectionExtensions.GetTypeInfo(typeof(MyClass)).Assembly;
X509CertificateCollection collection1;
using (MemoryStream ms = new MemoryStream())
{
assembly.GetManifestResourceStream("namespace.cert.pem").CopyTo(ms);
X509Certificate2 certificate1 = new X509Certificate2(ms.ToArray());
collection1 = new X509CertificateCollection();
collection1.Add(certificate1);
}
return collection1;
}
Thanks in advance!
Here is a Warning in document about TLS1.2 in Xamarin IOS.May be helpful for you.
the downside is that it requires the event loop to be running for async operations to be executed.
SslStream.AuthenticateAsClientAsync Method : Authenticate the client side of a client-server connection as an asynchronous operation.
So from your testing with async method ,this is the right solution. Glad solved it.
According to https://github.com/dotnet/corefx/issues/10981, I copied the implementation from corefx/src/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.cs and use it locally like below. (I'm using dotnet core 2.0.0 on Ubuntu)
Socket s = new Socket(AddressFamily.Unix, SocketType.Dgram, ProtocolType.Unspecified);
Console.WriteLine(s.SendBufferSize);
Console.WriteLine(s.ReceiveBufferSize);
var unixSocket = "./my.sock.1";
var ep = new UnixDomainSocketEndPoint(unixSocket);
Console.WriteLine(ep.AddressFamily);
try
{
System.IO.File.Delete(unixSocket);
s.Bind(ep);
s.Listen(5); // **Operation not supported**
while(true)
{
var newS = s.Accept();
byte[] content = new byte[1000];
var result = s.Receive(content);
Console.WriteLine(result);
Console.WriteLine(Encoding.Default.GetString(content));
newS.Close();
}
}
catch(Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
s.Close();
}
The exception is something like below:
Operation not supported
at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
at System.Net.Sockets.Socket.Listen(Int32 backlog)
at test01.Program.Main(String[] args) in /home/nonstatic/code/temp/test01/Program.cs:line 106
Is there any solution or workaround to let dotnet core build a domain socket server in Linux? Thanks!
It looks like #stephentoub replied with the answer on your corresponding GitHub issue.
Did you try SocketType.Stream instead of SocketType.Dgram?
For implementing my websocket server in C# I'm using Alchemy framework. I'm stuck with this issue. In the method OnReceive when I try to deserialize json object, I get a FormatException:
"Incorrect format of the input string." (maybe it's different in english, but I'm getting a localized exception message and that's my translation :P). What is odd about this is that when I print out the context.DataFrame I get: 111872281.1341000479.1335108793.1335108793.1335108793.1; __ad which is a substring of the cookies sent by the browser: __gutp=entrystamp%3D1288455757%7Csid%3D65a51a83cbf86945d0fd994e15eb94f9%7Cstamp%3D1288456520%7Contime%3D155; __utma=111872281.1341000479.1335108793.1335108793.1335108793.1; __adtaily_ui=cupIiq90q9.
JS code:
// I'm really not doing anything more than this
var ws = new WebSocket("ws://localhost:8080");
C# code:
static void Main(string[] args) {
int port = 8080;
WebSocketServer wsServer = new WebSocketServer(port, IPAddress.Any) {
OnReceive = OnReceive,
OnSend = OnSend,
OnConnect = OnConnect,
OnConnected = OnConnected,
OnDisconnect = OnDisconnect,
TimeOut = new TimeSpan(0, 5, 0)
};
wsServer.Start();
Console.WriteLine("Server started listening on port: " + port + "...");
string command = string.Empty;
while (command != "exit") {
command = Console.ReadLine();
}
Console.WriteLine("Server stopped listening on port: " + port + "...");
wsServer.Stop();
Console.WriteLine("Server exits...");
}
public static void OnReceive(UserContext context) {
string json = "";
dynamic obj;
try {
json = context.DataFrame.ToString();
Console.WriteLine(json);
obj = JsonConvert.DeserializeObject(json);
} catch (Exception e) {
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
return;
}
}
On the C# side I'm using Newtonsoft.Json, though it's not a problem with this library...
EDIT:
One more thing - I browsed through the code in here: https://github.com/Olivine-Labs/Alchemy-Websockets-Example and found nothing - I mean, I'm doing everything the same way authors did in this tutorial...
EDIT:
I was testing the above code in Firefox v 17.0.1, and it didn't work, so I tested it under google chrome, and it works. So let me rephrase the question - what changes can be made in js, so that firefox would not send aforementioned string?
I ran into the same issue - simply replacing
var ws = new WebSocket("ws://localhost:8080");
with
var ws = new WebSocket("ws://127.0.0.1:8080");
fixed the issue for me.
In C# console app I connect the client to the server using :
var aClient = new WebSocketClient(#"ws://127.0.0.1:81/beef");
Your code above is connecting using
var ws = new WebSocket("ws://localhost:8080");
There could be one of two issues -
First is to see if WebSocketClient works instead.
To make sure your url is of the format ws://ur:port/context. This threw me off for a while.