Skip to content

Commit

Permalink
Change apiUrl + pass API errors to client
Browse files Browse the repository at this point in the history
  • Loading branch information
artemlos committed Apr 26, 2022
1 parent 23ad3de commit 804d43a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
23 changes: 22 additions & 1 deletion LicenseServer/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,27 @@ public static string ProcessActivateRequest(byte[] stream, Dictionary<LAKey, LAR
{
result.Response = ForwardRequest(stream, newRequest, context);
}
catch (WebException ex)
{
try
{
var output = ReadToByteArray(ex.Response.GetResponseStream());

context.Response.OutputStream.Write(output, 0, output.Length);
context.Response.KeepAlive = false;
context.Response.Close();

return $"Could not contact the server '{licenseKey}' and machine code '{machineCode}'. Error message {ex?.Message}.";
}
catch (Exception ex2)
{
ReturnResponse(JsonConvert.SerializeObject(new BasicResult { Result = ResultType.Error, Message = "Could not contact the central sever (api.cryptolens.io:443)." }), context);
return $"Could not contact the server '{licenseKey}' and machine code '{machineCode}'. Error message {ex2?.Message} and stack trace {ex2?.StackTrace}";
}
}
catch (Exception ex)
{
ReturnResponse(JsonConvert.SerializeObject(new BasicResult { Result = ResultType.Error, Message = "Could not contact the central sever (app.cryptolens.io:443)." }), context);
ReturnResponse(JsonConvert.SerializeObject(new BasicResult { Result = ResultType.Error, Message = "Could not contact the central sever (api.cryptolens.io:443)." }), context);
return $"Could not contact the server '{licenseKey}' and machine code '{machineCode}'. Error message {ex?.Message} and stack trace {ex?.StackTrace}";
}

Expand Down Expand Up @@ -513,6 +531,7 @@ public static bool LoadLicenseFromFile(Dictionary<LAKey, LAResult> licenseCache,

public static string ForwardRequest(byte[] originalStream, HttpWebRequest newRequest, HttpListenerContext context)
{

Stream reqStream = newRequest.GetRequestStream();

reqStream.Write(originalStream, 0, originalStream.Length);
Expand All @@ -522,6 +541,7 @@ public static string ForwardRequest(byte[] originalStream, HttpWebRequest newReq

context.Response.OutputStream.Write(output, 0, output.Length);
context.Response.KeepAlive = false;
context.Response.ContentType = "application/json";
context.Response.Close();

return System.Text.Encoding.Default.GetString(output);
Expand All @@ -531,6 +551,7 @@ public static void ReturnResponse(string response, HttpListenerContext context)
{
var output = System.Text.Encoding.UTF8.GetBytes(response);
context.Response.OutputStream.Write(output, 0, output.Length);
context.Response.ContentType = "application/json";
context.Response.KeepAlive = false;
context.Response.Close();
}
Expand Down
8 changes: 4 additions & 4 deletions LicenseServer/LicenseServerCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

<PackageId>LicenseServer</PackageId>

<AssemblyVersion>2.6.1.0</AssemblyVersion>
<AssemblyVersion>2.7.1.0</AssemblyVersion>

<FileVersion>2.6.1.0</FileVersion>
<FileVersion>2.7.1.0</FileVersion>

<Copyright>Copyright © 2019 - 2021 Cryptolens AB</Copyright>
<Copyright>Copyright © 2019 - 2022 Cryptolens AB</Copyright>

<Version>2.6</Version>
<Version>2.7</Version>

<AssemblyName>LicenseServer</AssemblyName>

Expand Down
8 changes: 3 additions & 5 deletions LicenseServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace LicenseServer
{
class Program
{
public const string versionInfo = "v2.7-preview (2021-12-22)" ;
public const string versionInfo = "v2.7 (2022-04-26)" ;

public const string ServiceName = "license-server";

Expand Down Expand Up @@ -78,9 +78,7 @@ protected override void OnStop()

// A configuration can be generated on https://app.cryptolens.io/extensions/licenseserver
// More instructions can be found here: https://github.com/Cryptolens/license-server/#floating-licenses-offline
public static string ConfigurationFromCryptolens = "ksUFW5jNH5DNAW3DkaxsaWNlbnNlZmlsZXPD2gGfPFJTQUtleVZhbHVlPjxNb2R1bHVzPnNHYnZ4d2RsRGJxRlhPTWxWVW5BRjVldzB0MFdwUFc3ckZwSTVqSFFPRmtodC8zMjZkdmg3dDc0UlllTXBqeTM1N05sam91aHBUTEEzYTZpZG5uNGo2YzNqbVBXQmtqWm5kR3NQTDRCcW0rZndFNDhuS3BHUGprajRxL3l6VDR0SFhCVH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Hh4OFVYbFFwVUwwZnBFK1lIay9UMmwrcHR0WFlUYWJJZXFjektmLzRDd21oSUNDQ3ZkbDgrSjRJUmFwZHVGNWsrQnVxRkIxa0JyZ05DY3hZUT09PC9EUT48SW52ZXJzZVE+b2ZJVnc3Mmxwem1rQlVmUkJJYVhRV29WZldkU0djeFVIdHFEUGc1SFJUVnZXQ3UxcElsT0pxMDBRVlc4VFZTS2tVV3ZiRGJpUGZWbUkzaHliVXBPM3c9PTwvSW52ZXJzZVE+PEQ+UXlpZGtlRExlUi9wRnBYTnEvdzE2TndjTlZwa1pZZHNDUFVwbmRNdHYrS0piaVE3aWFUNDkzZVBVMVBtR0tPSW5BN2F1em9JMHJOMkNjSnhIM3U5bmRtanRHLzFuQWhWRXhnN0R2a09oOU55K24yRFVtNlVtTDJwS1liSnVGNFVyeVEyMEZOSE12WEs5K2pUMEl1Ynhzc3JNYzZVMGFtTGtwZWwyMnhmU1NFPTwvRD48L1JTQUtleVZhbHVlPpLX/xNXkZBjYiw0AMUBAGIPD6Z1i5Ze9xVOHLDxFSa7JvDTvd7zld7LEQ5dCxtiezrjibT2Mo7PsWZd/ZEYZcBrwT0LtAEDkKvLUEWs0PCRLaMAflWHb4Zh+16uEYePYduU/4GxDhhDXxktzowX6EJA8KywsqrPUZgOgPijsjdHnqi63+PzGIhl7dBOphBuM2U441zh370PGIz0h58RZZh4CLGCcbCTNTHzEkBTT+eh4LT8g6GW5xfTVWAohRxUkMQr1zOoYCZm3hyhjmiNsPaXTdrOMSGvkoRzpBuxYhGaeaTl+fN0TJupuW+y+GPC6tp/0GOCFEvDIDxCbbajY0BpOQFWIxTR9PV0fXta7rU=";


public static string ConfigurationFromCryptolens = "Insert your configuration string here that can be obtained using the links above.";
static void Main(string[] args)
{
if (!Environment.UserInteractive)
Expand Down Expand Up @@ -339,7 +337,7 @@ static void ResponseThread()
// adapted from https://stackoverflow.com/a/700307/1275924
var original = context.Request;
var pathAndQuery = new Uri(context.Request.Url.OriginalString).PathAndQuery;
HttpWebRequest newRequest = (HttpWebRequest)WebRequest.Create("https://app.cryptolens.io/" + pathAndQuery);
HttpWebRequest newRequest = (HttpWebRequest)WebRequest.Create("https://api.cryptolens.io" + pathAndQuery);

newRequest.ContentType = original.ContentType;
newRequest.Method = original.HttpMethod;
Expand Down

0 comments on commit 804d43a

Please sign in to comment.