feat: Version for .netstandard2.0
Problems: - can't validate custom CA certificates
This commit is contained in:
parent
3f5190fd94
commit
de6285466c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>library</OutputType>
|
<OutputType>library</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -27,25 +27,25 @@ internal static class Helpers
|
|||||||
|
|
||||||
internal static string GetCmdString(FrameType type)
|
internal static string GetCmdString(FrameType type)
|
||||||
{
|
{
|
||||||
return type switch
|
switch (type)
|
||||||
{
|
{
|
||||||
FrameType.Unknown => "UNKNOWN",
|
case FrameType.Unknown: return "UNKNOWN";
|
||||||
FrameType.Connected => "CONNECTED",
|
case FrameType.Connected: return "CONNECTED";
|
||||||
FrameType.Message => "MESSAGE",
|
case FrameType.Message: return "MESSAGE";
|
||||||
FrameType.Receipt => "RECEIPT",
|
case FrameType.Receipt: return "RECEIPT";
|
||||||
FrameType.Error => "ERROR",
|
case FrameType.Error: return "ERROR";
|
||||||
FrameType.Stomp => "STOMP",
|
case FrameType.Stomp: return "STOMP";
|
||||||
FrameType.Send => "SEND",
|
case FrameType.Send: return "SEND";
|
||||||
FrameType.Subscribe => "SUBSCRIBE",
|
case FrameType.Subscribe: return "SUBSCRIBE";
|
||||||
FrameType.Unsubscribe => "UNSUBSCRIBE",
|
case FrameType.Unsubscribe: return "UNSUBSCRIBE";
|
||||||
FrameType.Ack => "ACK",
|
case FrameType.Ack: return "ACK";
|
||||||
FrameType.Nack => "NACK",
|
case FrameType.Nack: return "NACK";
|
||||||
FrameType.Begin => "BEGIN",
|
case FrameType.Begin: return "BEGIN";
|
||||||
FrameType.Commit => "COMMIT",
|
case FrameType.Commit: return "COMMIT";
|
||||||
FrameType.Abort => "ABORT",
|
case FrameType.Abort: return "ABORT";
|
||||||
FrameType.Disconnect => "DISCONNECT",
|
case FrameType.Disconnect: return "DISCONNECT";
|
||||||
FrameType.Heartbeat => "",
|
case FrameType.Heartbeat: return "";
|
||||||
_ => "UNKNOWN"
|
default: return "UNKNOWN";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
private static async Task GetMessage(MemoryStream output, ClientWebSocket ws, CancellationToken cancellationToken)
|
private static async Task GetMessage(MemoryStream output, ClientWebSocket ws, CancellationToken cancellationToken)
|
||||||
@ -148,7 +148,7 @@ internal static class Helpers
|
|||||||
throw new Exception("Cannot parse header");
|
throw new Exception("Cannot parse header");
|
||||||
}
|
}
|
||||||
var key = line.Substring(0, colon);
|
var key = line.Substring(0, colon);
|
||||||
var value = line[(colon + 1)..];
|
var value = line.Substring(colon + 1);
|
||||||
frame.Headers[key.ToLower()] = value;
|
frame.Headers[key.ToLower()] = value;
|
||||||
|
|
||||||
line = reader.ReadLine().TrimEnd(); // next header
|
line = reader.ReadLine().TrimEnd(); // next header
|
||||||
@ -180,4 +180,11 @@ internal static class Helpers
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
internal static class Backports
|
||||||
|
{
|
||||||
|
public static void WriteWholeArray(this MemoryStream stream, byte[] data)
|
||||||
|
{
|
||||||
|
stream.Write(data, 0, data.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,9 @@ namespace ArStomp
|
|||||||
if (certCollection != null && certCollection.Count > 0)
|
if (certCollection != null && certCollection.Count > 0)
|
||||||
{
|
{
|
||||||
this.certCollection = certCollection;
|
this.certCollection = certCollection;
|
||||||
ws.Options.RemoteCertificateValidationCallback = RemoteCertificateValidationCallback;
|
|
||||||
|
// TODO find alternative method in case of .netstandard2.0
|
||||||
|
// ws.Options.RemoteCertificateValidationCallback = RemoteCertificateValidationCallback;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +76,7 @@ namespace ArStomp
|
|||||||
(sslPolicyErrors & (SslPolicyErrors.RemoteCertificateNotAvailable)) > 0
|
(sslPolicyErrors & (SslPolicyErrors.RemoteCertificateNotAvailable)) > 0
|
||||||
) return false;
|
) return false;
|
||||||
// last certificate in chain should be one of our trust anchors
|
// last certificate in chain should be one of our trust anchors
|
||||||
X509Certificate2 projectedRootCert = chain.ChainElements[^1].Certificate;
|
X509Certificate2 projectedRootCert = chain.ChainElements[chain.ChainElements.Count - 1].Certificate;
|
||||||
// check if server's root ca is one of our trusted
|
// check if server's root ca is one of our trusted
|
||||||
bool anytrusted = false;
|
bool anytrusted = false;
|
||||||
foreach (var cert in certCollection)
|
foreach (var cert in certCollection)
|
||||||
@ -97,7 +99,7 @@ namespace ArStomp
|
|||||||
{
|
{
|
||||||
if (frame.Body != null)
|
if (frame.Body != null)
|
||||||
{
|
{
|
||||||
reason = Encoding.UTF8.GetString(frame.Body);
|
reason = Encoding.UTF8.GetString(frame.Body.Array, frame.Body.Offset, frame.Body.Count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Exception($"Unexpected frame '{frame.Type}'. Message from server: {reason}");
|
throw new Exception($"Unexpected frame '{frame.Type}'. Message from server: {reason}");
|
||||||
@ -138,7 +140,7 @@ namespace ArStomp
|
|||||||
/// <param name="destination">queue o exchange (eg /exchange/name/routing-key in case of RabbitMQ)</param>
|
/// <param name="destination">queue o exchange (eg /exchange/name/routing-key in case of RabbitMQ)</param>
|
||||||
/// <param name="correlationId">property correlationId for the message</param>
|
/// <param name="correlationId">property correlationId for the message</param>
|
||||||
/// <param name="body">content of the message</param>
|
/// <param name="body">content of the message</param>
|
||||||
public ValueTask Send(string destination, string correlationId, byte[] body)
|
public Task Send(string destination, string correlationId, byte[] body)
|
||||||
{
|
{
|
||||||
var ct = Token.Token;
|
var ct = Token.Token;
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ namespace ArStomp
|
|||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal ValueTask Serialize(ClientWebSocket ws, CancellationToken cancellationToken)
|
internal Task Serialize(ClientWebSocket ws, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var utf8 = Encoding.UTF8;
|
var utf8 = Encoding.UTF8;
|
||||||
var EOL = utf8.GetBytes("\n");
|
var EOL = utf8.GetBytes("\n");
|
||||||
@ -78,29 +78,29 @@ namespace ArStomp
|
|||||||
|
|
||||||
// write command
|
// write command
|
||||||
var cmd = Helpers.GetCmdString(Type);
|
var cmd = Helpers.GetCmdString(Type);
|
||||||
stream.Write(utf8.GetBytes(cmd));
|
stream.WriteWholeArray(utf8.GetBytes(cmd));
|
||||||
stream.Write(EOL);
|
stream.WriteWholeArray(EOL);
|
||||||
// write headers
|
// write headers
|
||||||
foreach (var i in Headers)
|
foreach (var i in Headers)
|
||||||
{
|
{
|
||||||
stream.Write(utf8.GetBytes(i.Key));
|
stream.WriteWholeArray(utf8.GetBytes(i.Key));
|
||||||
stream.Write(COLON);
|
stream.WriteWholeArray(COLON);
|
||||||
stream.Write(utf8.GetBytes(i.Value));
|
stream.WriteWholeArray(utf8.GetBytes(i.Value));
|
||||||
stream.Write(EOL);
|
stream.WriteWholeArray(EOL);
|
||||||
}
|
}
|
||||||
// write empty line
|
// write empty line
|
||||||
stream.Write(EOL);
|
stream.WriteWholeArray(EOL);
|
||||||
// write body
|
// write body
|
||||||
if (Body != null && Body.Count > 0)
|
if (Body != null && Body.Count > 0)
|
||||||
{
|
{
|
||||||
stream.Write(Body);
|
stream.Write(Body.Array, Body.Offset, Body.Count);
|
||||||
}
|
}
|
||||||
// write NUL character
|
// write NUL character
|
||||||
stream.Write(NUL);
|
stream.WriteWholeArray(NUL);
|
||||||
stream.Flush();
|
stream.Flush();
|
||||||
var array = stream.GetBuffer();
|
var array = stream.GetBuffer();
|
||||||
if (StompClient.Debug) Console.WriteLine(">>>\n{0}\n>>>\n", this);
|
if (StompClient.Debug) Console.WriteLine(">>>\n{0}\n>>>\n", this);
|
||||||
return ws.SendAsync(array.AsMemory(0, (int)stream.Position), WebSocketMessageType.Binary, true, cancellationToken);
|
return ws.SendAsync(new ArraySegment<byte>(array, 0, (int)stream.Position), WebSocketMessageType.Binary, true, cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ namespace ArStomp
|
|||||||
Headers["reply-to"] = "/temp-queue/rpc-replies";
|
Headers["reply-to"] = "/temp-queue/rpc-replies";
|
||||||
if (correlationId != null) Headers["correlation-id"] = correlationId;
|
if (correlationId != null) Headers["correlation-id"] = correlationId;
|
||||||
Headers["content-length"] = body.Length.ToString();
|
Headers["content-length"] = body.Length.ToString();
|
||||||
Body = body;
|
Body = new ArraySegment<byte>(body, 0, body.Length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user