Skip to content

Commit

Permalink
Merge branch 'release/0.53.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jericho committed Nov 22, 2022
2 parents c42a165 + ff5266f commit 7998fdf
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "2.3.0",
"version": "3.0.0",
"commands": [
"dotnet-cake"
]
Expand Down
15 changes: 1 addition & 14 deletions Source/ZoomNet/Extensions/Public.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ZoomNet.Models;
Expand Down Expand Up @@ -279,19 +277,8 @@ public static async Task<Event> VerifyAndParseEventWebhookAsync(this IWebhookPar
/// <returns>An <see cref="Event" />.</returns>
public static Event VerifyAndParseEventWebhook(this IWebhookParser parser, string requestBody, string secretToken, string signature, string timestamp)
{
// Construct the message
var message = $"v0:{timestamp}:{requestBody}";

// Hash the message
var hmac = new HMACSHA256(Encoding.ASCII.GetBytes(secretToken));
var hashAsBytes = hmac.ComputeHash(Encoding.ASCII.GetBytes(message));
var hashAsHex = hashAsBytes.ToHexString();

// Create the signature
var calculatedSignature = $"v0={hashAsHex}";

// Compare the signatures
if (calculatedSignature != signature) throw new SecurityException("Webhook signature validation failed.");
if (!parser.VerifySignature(requestBody, secretToken, signature, timestamp)) throw new SecurityException("Webhook signature validation failed.");

// Parse the webhook event
return parser.ParseEventWebhook(requestBody);
Expand Down
10 changes: 10 additions & 0 deletions Source/ZoomNet/IWebhookParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ namespace ZoomNet
/// </summary>
public interface IWebhookParser
{
/// <summary>
/// Verifies the webhook signature.
/// </summary>
/// <param name="requestBody">The content submitted by Zoom's webhook.</param>
/// <param name="secretToken">Your secret token. You can obtain this value in the 'Add Feature' configuration section of you Marketplace Zoom app.</param>
/// <param name="signature">The signature.</param>
/// <param name="timestamp">The timestamp.</param>
/// <returns>A boolean value indicating wether the signature was validated or not.</returns>
bool VerifySignature(string requestBody, string secretToken, string signature, string timestamp);

/// <summary>
/// Parses the event webhook.
/// </summary>
Expand Down
9 changes: 5 additions & 4 deletions Source/ZoomNet/Json/ZoomNetJsonConverter{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ internal void WriteJsonProperty(Utf8JsonWriter writer, string propertyName, obje

if (propertyConverterAttribute != null)
{
// It's important to clone the options in order to be able to modify the 'Converters' list
var clonedOptions = new JsonSerializerOptions(options);
clonedOptions.Converters.Add((JsonConverter)Activator.CreateInstance(propertyConverterAttribute.ConverterType));
JsonSerializer.Serialize(writer, propertyValue, propertyType, clonedOptions);
var customOptions = new JsonSerializerOptions()
{
Converters = { (JsonConverter)Activator.CreateInstance(propertyConverterAttribute.ConverterType) }
};
JsonSerializer.Serialize(writer, propertyValue, propertyType, customOptions);
}
else
{
Expand Down
26 changes: 21 additions & 5 deletions Source/ZoomNet/WebhookParser.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using ZoomNet.Json;
using ZoomNet.Models.Webhooks;
Expand All @@ -24,11 +26,25 @@ public class WebhookParser : IWebhookParser
/// </summary>
public const string TIMESTAMP_HEADER_NAME = "x-zm-request-timestamp";

/// <summary>
/// Parses the event webhook.
/// </summary>
/// <param name="requestBody">The content submitted by Zoom's WebHook.</param>
/// <returns>An <see cref="Event" />.</returns>
/// <inheritdoc/>
public bool VerifySignature(string requestBody, string secretToken, string signature, string timestamp)
{
// Construct the message
var message = $"v0:{timestamp}:{requestBody}";

// Hash the message
var hmac = new HMACSHA256(Encoding.ASCII.GetBytes(secretToken));
var hashAsBytes = hmac.ComputeHash(Encoding.ASCII.GetBytes(message));
var hashAsHex = hashAsBytes.ToHexString();

// Create the signature
var calculatedSignature = $"v0={hashAsHex}";

// Compare the signatures
return calculatedSignature == signature;
}

/// <inheritdoc/>
public Event ParseEventWebhook(string requestBody)
{
var webHookEvent = JsonSerializer.Deserialize<Event>(requestBody, JsonFormatter.DeserializerOptions);
Expand Down
38 changes: 16 additions & 22 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Install tools.
#tool dotnet:?package=GitVersion.Tool&version=5.10.3
#tool dotnet:?package=GitVersion.Tool&version=5.11.1
#tool dotnet:?package=coveralls.net&version=4.0.1
#tool nuget:?package=GitReleaseManager&version=0.13.0
#tool nuget:?package=ReportGenerator&version=5.1.10
#tool nuget:?package=ReportGenerator&version=5.1.11
#tool nuget:?package=xunit.runner.console&version=2.4.2
#tool nuget:?package=Codecov&version=1.13.0

Expand Down Expand Up @@ -295,30 +295,23 @@ Task("Run-Code-Coverage")
DotNetTest(unitTestsProject, testSettings);
});

Task("Upload-Coverage-Result")
Task("Upload-Coverage-Result-Coveralls")
.IsDependentOn("Run-Code-Coverage")
.OnError(exception => Information($"ONERROR: Failed to upload coverage result to Coveralls: {exception.Message}"))
.Does(() =>
{
//try
//CoverallsNet(new FilePath($"{codeCoverageDir}coverage.{DefaultFramework}.xml"), CoverallsNetReportType.OpenCover, new CoverallsNetSettings()
//{
// CoverallsNet(new FilePath($"{codeCoverageDir}coverage.{DefaultFramework}.xml"), CoverallsNetReportType.OpenCover, new CoverallsNetSettings()
// {
// RepoToken = coverallsToken
// });
//}
//catch (Exception e)
//{
// Warning(e.Message);
//}
// RepoToken = coverallsToken
//});
});

try
{
Codecov($"{codeCoverageDir}coverage.{DefaultFramework}.xml", codecovToken);
}
catch (Exception e)
{
Warning(e.Message);
}
Task("Upload-Coverage-Result-Codecov")
.IsDependentOn("Run-Code-Coverage")
.OnError(exception => Information($"ONERROR: Failed to upload coverage result to Codecov: {exception.Message}"))
.Does(() =>
{
//Codecov($"{codeCoverageDir}coverage.{DefaultFramework}.xml", codecovToken);
});

Task("Generate-Code-Coverage-Report")
Expand Down Expand Up @@ -514,7 +507,8 @@ Task("ReleaseNotes")

Task("AppVeyor")
.IsDependentOn("Run-Code-Coverage")
.IsDependentOn("Upload-Coverage-Result")
.IsDependentOn("Upload-Coverage-Result-Coveralls")
.IsDependentOn("Upload-Coverage-Result-Codecov")
.IsDependentOn("Create-NuGet-Package")
.IsDependentOn("Upload-AppVeyor-Artifacts")
.IsDependentOn("Publish-MyGet")
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.401",
"version": "7.0.100",
"rollForward": "latestFeature"
}
}

0 comments on commit 7998fdf

Please sign in to comment.