Skip to content

Commit e27237a

Browse files
committed
Project scaffolding
1 parent 4452a27 commit e27237a

File tree

7 files changed

+176
-22
lines changed

7 files changed

+176
-22
lines changed

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

LICENSE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Tomasz Pęczek
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27130.2010
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib.Net.Http.WebPush", "Lib.Net.Http.WebPush\Lib.Net.Http.WebPush.csproj", "{79FDCAAA-6129-4FBB-B94E-7F7BE9A07C7C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{79FDCAAA-6129-4FBB-B94E-7F7BE9A07C7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{79FDCAAA-6129-4FBB-B94E-7F7BE9A07C7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{79FDCAAA-6129-4FBB-B94E-7F7BE9A07C7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{79FDCAAA-6129-4FBB-B94E-7F7BE9A07C7C}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {88535C7E-5564-4AC1-A41B-18DD05637943}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.IO;
3+
using Org.BouncyCastle.Asn1;
4+
using Org.BouncyCastle.Asn1.Nist;
5+
using Org.BouncyCastle.Asn1.X9;
6+
using Org.BouncyCastle.Crypto;
7+
using Org.BouncyCastle.Crypto.Parameters;
8+
using Org.BouncyCastle.OpenSsl;
9+
using Org.BouncyCastle.Security;
10+
11+
namespace Lib.Net.Http.WebPush.Internals
12+
{
13+
internal static class ECKeyHelper
14+
{
15+
internal static ECPrivateKeyParameters GetECPrivateKeyParameters(byte[] privateKey)
16+
{
17+
Asn1Object derSequence = new DerSequence(
18+
new DerInteger(1),
19+
new DerOctetString(privateKey),
20+
new DerTaggedObject(0, new DerObjectIdentifier("1.2.840.10045.3.1.7"))
21+
);
22+
23+
string pemKey = "-----BEGIN EC PRIVATE KEY-----\n"
24+
+ Convert.ToBase64String(derSequence.GetDerEncoded())
25+
+ "\n-----END EC PRIVATE KEY----";
26+
27+
PemReader pemKeyReader = new PemReader(new StringReader(pemKey));
28+
AsymmetricCipherKeyPair keyPair = (AsymmetricCipherKeyPair)pemKeyReader.ReadObject();
29+
30+
return (ECPrivateKeyParameters)keyPair.Private;
31+
}
32+
33+
internal static ECPublicKeyParameters GetECPublicKeyParameters(byte[] publicKey)
34+
{
35+
Asn1Object derSequence = new DerSequence(
36+
new DerSequence(new DerObjectIdentifier(@"1.2.840.10045.2.1"), new DerObjectIdentifier(@"1.2.840.10045.3.1.7")),
37+
new DerBitString(publicKey)
38+
);
39+
40+
string pemKey = "-----BEGIN PUBLIC KEY-----\n"
41+
+ Convert.ToBase64String(derSequence.GetDerEncoded())
42+
+ "\n-----END PUBLIC KEY-----";
43+
44+
PemReader pemKeyReader = new PemReader(new StringReader(pemKey));
45+
return (ECPublicKeyParameters)pemKeyReader.ReadObject();
46+
}
47+
48+
internal static AsymmetricCipherKeyPair GenerateAsymmetricCipherKeyPair()
49+
{
50+
X9ECParameters ecParameters = NistNamedCurves.GetByName("P-256");
51+
ECDomainParameters ecDomainParameters = new ECDomainParameters(ecParameters.Curve, ecParameters.G, ecParameters.N, ecParameters.H, ecParameters.GetSeed());
52+
53+
IAsymmetricCipherKeyPairGenerator keyPairGenerator = GeneratorUtilities.GetKeyPairGenerator("ECDH");
54+
keyPairGenerator.Init(new ECKeyGenerationParameters(ecDomainParameters, new SecureRandom()));
55+
56+
return keyPairGenerator.GenerateKeyPair();
57+
}
58+
}
59+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
3+
namespace Lib.Net.Http.WebPush.Internals
4+
{
5+
internal static class UrlBase64Converter
6+
{
7+
internal static byte[] FromUrlBase64String(string input)
8+
{
9+
input = input.Replace('-', '+').Replace('_', '/');
10+
11+
while (input.Length % 4 != 0)
12+
{
13+
input += "=";
14+
}
15+
16+
return Convert.FromBase64String(input);
17+
}
18+
19+
internal static string ToUrlBase64String(byte[] input)
20+
{
21+
return Convert.ToBase64String(input).Replace('+', '-').Replace('/', '_').TrimEnd('=');
22+
}
23+
}
24+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Description>Lib.Net.Http.WebPush is a library which provides a Web Push Protocol based client for Push Service.</Description>
4+
<Copyright>Copyright © 2018 Tomasz Pęczek</Copyright>
5+
<VersionPrefix>1.0.0</VersionPrefix>
6+
<Authors>Tomasz Pęczek</Authors>
7+
<TargetFrameworks>net451;netstandard1.6</TargetFrameworks>
8+
<AssemblyTitle>Lib.Net.Http.WebPush</AssemblyTitle>
9+
<AssemblyName>Lib.Net.Http.WebPush</AssemblyName>
10+
<PackageId>Lib.Net.Http.WebPush</PackageId>
11+
<PackageTags>push;notifications;webpush;vapid</PackageTags>
12+
<PackageProjectUrl>https://github.com/tpeczek/Lib.Net.Http.WebPush</PackageProjectUrl>
13+
<PackageLicenseUrl>https://github.com/tpeczek/Lib.Net.Http.WebPush/blob/master/LICENSE.md</PackageLicenseUrl>
14+
<RepositoryType>git</RepositoryType>
15+
<RepositoryUrl>git://github.com/tpeczek/Lib.Net.Http.WebPush</RepositoryUrl>
16+
<GenerateAssemblyTitleAttribute>true</GenerateAssemblyTitleAttribute>
17+
<GenerateAssemblyDescriptionAttribute>true</GenerateAssemblyDescriptionAttribute>
18+
<GenerateAssemblyProductAttribute>true</GenerateAssemblyProductAttribute>
19+
<GenerateAssemblyCopyrightAttribute>true</GenerateAssemblyCopyrightAttribute>
20+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
21+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
22+
<LangVersion>latest</LangVersion>
23+
</PropertyGroup>
24+
<ItemGroup>
25+
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
26+
<PackageReference Include="Lib.Net.Http.EncryptedContentEncoding" Version="1.1.0" />
27+
</ItemGroup>
28+
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
29+
<PackageReference Include="BouncyCastle" Version="1.8.1" />
30+
<PackageReference Include="System.Net.Http" Version="4.3.1" />
31+
</ItemGroup>
32+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">
33+
<PackageReference Include="BouncyCastle.CoreClr" Version="1.0.0" />
34+
</ItemGroup>
35+
</Project>

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
# Lib.Net.Http.WebPush
2-
Lib.Net.Http.WebPush is a library which provides a Web Push Protocol based client for Push Service.
2+
Lib.Net.Http.WebPush is a library which provides a [Web Push Protocol](https://tools.ietf.org/html/rfc8030) based client for Push Service. It provides support for [Voluntary Application Server Identification (VAPID) for Web Push](https://tools.ietf.org/html/rfc8292) and [Message Encryption for Web Push](https://tools.ietf.org/html/rfc8291).
3+
4+
## Donating
5+
6+
My blog and open source projects are result of my passion for software development, but they require a fair amount of my personal time. If you got value from any of the content I create, then I would appreciate your support by [buying me a coffee](https://www.buymeacoffee.com/tpeczek).
7+
8+
<a href="https://www.buymeacoffee.com/tpeczek"><img src="https://www.buymeacoffee.com/assets/img/custom_images/black_img.png" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" target="_blank"></a>
9+
10+
## Copyright and License
11+
12+
Copyright © 2018 Tomasz Pęczek
13+
14+
Licensed under the [MIT License](https://github.com/tpeczek/Lib.Net.Http.WebPush/blob/master/LICENSE.md)

0 commit comments

Comments
 (0)