Skip to content

Commit

Permalink
Merge changes from main
Browse files Browse the repository at this point in the history
  • Loading branch information
haga-rak committed Apr 15, 2024
2 parents 0df9823 + b67a47f commit b5b0645
Show file tree
Hide file tree
Showing 43 changed files with 538 additions and 94 deletions.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

[![Fluxzy.Core](https://img.shields.io/nuget/v/Fluxzy.Core.svg?label=Fluxzy.Core&logo=nuget)](https://www.nuget.org/packages/Fluxzy.Core)
[![Fluxzy.Core](https://img.shields.io/nuget/v/Fluxzy.Core.svg?label=Fluxzy.Core.Pcap&logo=nuget)](https://www.nuget.org/packages/Fluxzy.Core.Pcap)
[![Docker Image Version](https://img.shields.io/docker/v/fluxzy/fluxzy?label=docker&color=7155ab)](https://hub.docker.com/r/fluxzy/fluxzy)
[![build](https://github.com/haga-rak/fluxzy.core/actions/workflows/ci.yml/badge.svg)](https://github.com/haga-rak/fluxzy.core/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/haga-rak/fluxzy.core/graph/badge.svg?token=AD5R7Q1FHJ)](https://codecov.io/gh/haga-rak/fluxzy.core)
[![gitter](https://img.shields.io/badge/docs-latest-b36567)](https://docs.fluxzy.io/documentation/core/introduction.html)


[Features](#1-features) | [Quick usage (.NET)](#2-quick-usage) | [Quick usage (CLI)](#sample-usage) | [Documentation](https://docs.fluxzy.io/documentation/core/introduction.html) | [Build](#3-build) | [License](LICENSE.md) | [Releases](https://github.com/haga-rak/fluxzy.core/releases)
[Features](#1-features) | [Quick usage (.NET)](#2-quick-usage) | [Quick usage (CLI)](#sample-usage) | [Quick usage (Docker)](#run-with-docker) | [Documentation](https://docs.fluxzy.io/documentation/core/introduction.html) | [Build](#3-build) | [License](LICENSE.md) | [Releases](https://github.com/haga-rak/fluxzy.core/releases)

</div>

Expand Down Expand Up @@ -131,9 +132,6 @@ More examples are available at [docs.fluxzy.io](https://docs.fluxzy.io/documenta

### 2.2 Fluxzy CLI


### Download CLI

| Fluxzy CLI | Version |
| --- | --- |
| Windows | [![win32](https://fluxzy.io/misc/badge/cli/Windows32) ![win64](https://fluxzy.io/misc/badge/cli/Windows64) ![winArm64](https://fluxzy.io/misc/badge/cli/WindowsArm64)](https://www.fluxzy.io/download#cli) |
Expand Down Expand Up @@ -206,6 +204,19 @@ More command and options are available, including [exporting to HAR](https://www

By default, fluxzy will bind to `127.0.0.1:44344`.

### Run with docker

The CLI can be run from a [docker image](https://hub.docker.com/r/fluxzy/fluxzy).

```bash
docker run -it -p 43444:43444 fluxzy/fluxzy:latest start
```

To test:

```bash
curl -x 127.0.0.1:44344 https://www.fluxzy.io
```

## 3. Build

Expand Down
40 changes: 20 additions & 20 deletions build/Fluxzy.Build/Fluxzy.Build.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bullseye" Version="4.2.1" />
<PackageReference Include="Octokit" Version="9.1.0" />
<PackageReference Include="SimpleExec" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.133" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bullseye" Version="4.2.1" />
<PackageReference Include="Octokit" Version="10.0.0" />
<PackageReference Include="SimpleExec" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.133" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ ignore:
- "src/Fluxzy.Core/Clients/H2Logger.cs"
- "src/Fluxzy.Core/Clients/H1Logger.cs"
- "src/Fluxzy.Core/Misc/Streams/DebugFileStream.cs"
- "src/Fluxzy/ArgsHelper.cs"
- "src/Fluxzy.Core/Misc/Traces/**"
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageReference Include="Fluxzy.Core" Version="1.22.12" />
<PackageReference Include="Fluxzy.Core" Version="1.23.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageReference Include="Fluxzy.Core.Pcap" Version="1.22.12" />
<PackageReference Include="Fluxzy.Core.Pcap" Version="1.23.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageReference Include="Fluxzy.Core" Version="1.22.12" />
<PackageReference Include="Fluxzy.Core" Version="1.23.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageReference Include="Fluxzy.Core" Version="1.22.12" />
<PackageReference Include="Fluxzy.Core" Version="1.23.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageReference Include="Fluxzy.Core" Version="1.22.12" />
<PackageReference Include="Fluxzy.Core" Version="1.23.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageReference Include="Fluxzy.Core" Version="1.22.12" />
<PackageReference Include="Fluxzy.Core" Version="1.23.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageReference Include="Fluxzy.Core" Version="1.22.12" />
<PackageReference Include="Fluxzy.Core" Version="1.23.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageReference Include="Fluxzy.Core" Version="1.22.12" />
<PackageReference Include="Fluxzy.Core" Version="1.23.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageReference Include="Fluxzy.Core" Version="1.22.12" />
<PackageReference Include="Fluxzy.Core" Version="1.23.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageReference Include="Fluxzy.Core" Version="1.22.12" />
<PackageReference Include="Fluxzy.Core" Version="1.23.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageReference Include="Fluxzy.Core" Version="1.22.12" />
<PackageReference Include="Fluxzy.Core" Version="1.23.1" />
</ItemGroup>

</Project>
14 changes: 0 additions & 14 deletions src/Fluxzy.Core.Pcap.Cli/Fluxzy - Backup.Interop.Pcap.Cli.csproj

This file was deleted.

2 changes: 1 addition & 1 deletion src/Fluxzy.Core.Pcap/Pcapng/Merge/EnhancedBlockReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Fluxzy.Core.Pcap.Pcapng.Merge
internal class EnhancedBlockReader : SleepyStreamBlockReader
{
private readonly PcapBlockWriter _blockWriter;
private readonly byte[] _defaultBuffer = new byte[1024 * 4];
private readonly byte[] _defaultBuffer = new byte[FluxzySharedSetting.PcapEnhancedBlockMaxLength];

public EnhancedBlockReader(PcapBlockWriter blockWriter,
StreamLimiter streamLimiter, IStreamSource streamFactory)
Expand Down
2 changes: 1 addition & 1 deletion src/Fluxzy.Core/Certificates/Certificate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public X509Certificate2 GetX509Certificate()

switch (RetrieveMode) {
case CertificateRetrieveMode.FluxzyDefault:
return _cachedCertificate = FluxzySecurity.BuiltinCertificate;
return _cachedCertificate = FluxzySecurityParams.Current.BuiltinCertificate;

case CertificateRetrieveMode.FromUserStoreSerialNumber: {
using var store = new X509Store(StoreName.My,
Expand Down
4 changes: 2 additions & 2 deletions src/Fluxzy.Core/Certificates/CertificateAuthorityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class CertificateAuthorityManager
/// <returns></returns>
public virtual void DumpDefaultCertificate(Stream stream)
{
FluxzySecurity.BuiltinCertificate.ExportToPem(stream);
FluxzySecurityParams.Current.BuiltinCertificate.ExportToPem(stream);
}

/// <summary>
Expand Down Expand Up @@ -58,7 +58,7 @@ public virtual void DumpDefaultCertificate(Stream stream)
/// <returns></returns>
public virtual ValueTask<bool> InstallDefaultCertificate()
{
return InstallCertificate(FluxzySecurity.BuiltinCertificate);
return InstallCertificate(FluxzySecurityParams.Current.BuiltinCertificate);
}

/// <summary>
Expand Down
43 changes: 34 additions & 9 deletions src/Fluxzy.Core/Certificates/FluxzySecurity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using Fluxzy.Core;

namespace Fluxzy.Certificates
{
Expand All @@ -14,17 +15,30 @@ namespace Fluxzy.Certificates
///
/// For the two first cases, if the PKCS12 file has a password, it must be specified in the environment variable FLUXZY_ROOT_CERTIFICATE_PASSWORD
/// </summary>
internal static class FluxzySecurity
internal class FluxzySecurity
{
static FluxzySecurity()
public static readonly string DefaultCertificatePath = "%appdata%/.fluxzy/rootca.pfx";
private readonly string _certificatePath;
private readonly EnvironmentProvider _environmentProvider;

public FluxzySecurity(string certificatePath, EnvironmentProvider environmentProvider)
{
_certificatePath = certificatePath;
_environmentProvider = environmentProvider;
BuiltinCertificate = GetDefaultCertificate();

if (!BuiltinCertificate.HasPrivateKey)
{
throw new ArgumentException("The built-in certificate must have a private key");
}
}

private static X509Certificate2 GetDefaultCertificate()

public X509Certificate2 BuiltinCertificate { get; }

private X509Certificate2 GetDefaultCertificate()
{
var certificatePath = Environment.GetEnvironmentVariable("FLUXZY_ROOT_CERTIFICATE");
var certificatePassword = Environment.GetEnvironmentVariable("FLUXZY_ROOT_CERTIFICATE_PASSWORD");
var certificatePath = _environmentProvider.GetEnvironmentVariable("FLUXZY_ROOT_CERTIFICATE");
var certificatePassword = _environmentProvider.GetEnvironmentVariable("FLUXZY_ROOT_CERTIFICATE_PASSWORD");

if (certificatePath != null) {
if (!File.Exists(certificatePath)) {
Expand All @@ -33,7 +47,7 @@ private static X509Certificate2 GetDefaultCertificate()
}
else
{
var defaultPath = Environment.ExpandEnvironmentVariables("%appdata%/.fluxzy/rootca.pfx");
var defaultPath = _environmentProvider.ExpandEnvironmentVariables(_certificatePath);

if (File.Exists(defaultPath))
{
Expand All @@ -54,8 +68,19 @@ private static X509Certificate2 GetDefaultCertificate()
return new X509Certificate2(FileStore.Fluxzy, "youshallnotpass");
}

public static X509Certificate2 BuiltinCertificate { get; }
public static void SetDefaultCertificateForUser(
byte[] certificateContent,
EnvironmentProvider environmentProvider,
string certificatePath)
{
var certificateFileInfo = new FileInfo(environmentProvider.ExpandEnvironmentVariables(certificatePath));
var certificateDirectory = certificateFileInfo.Directory;

public static string DefaultThumbPrint => BuiltinCertificate.Thumbprint!;
if (certificateDirectory != null) {
Directory.CreateDirectory(certificateDirectory.FullName);
}

File.WriteAllBytes(certificateFileInfo.FullName, certificateContent);
}
}
}
12 changes: 12 additions & 0 deletions src/Fluxzy.Core/Certificates/FluxzySecurityParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2021 - Haga Rakotoharivelo - https://github.com/haga-rak

using Fluxzy.Core;

namespace Fluxzy.Certificates
{
internal class FluxzySecurityParams
{
public static FluxzySecurity Current { get; } = new FluxzySecurity(FluxzySecurity.DefaultCertificatePath, new SystemEnvironmentProvider());

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace Fluxzy.Cli.Dockering
namespace Fluxzy.Core
{
internal class DictionaryEnvironmentProvider : EnvironmentProvider
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@

using System;

namespace Fluxzy.Cli.Dockering
namespace Fluxzy.Core
{
internal abstract class EnvironmentProvider
public abstract class EnvironmentProvider
{
public virtual string ExpandEnvironmentVariables(string original)
{
// Find with regex matching %variablename% and replace everything with GetEnvironmentVariable
// Warning, this implementation is meant for testing purposes only and may be invalid in some cases

var regex = new System.Text.RegularExpressions.Regex("%([^%]+)%");

return regex.Replace(original, match => {
var variableName = match.Groups[1].Value;
return GetEnvironmentVariable(variableName) ?? match.Value;
});
}

public virtual bool EnvironmentVariableActive(string name)
{
var variableValue = GetEnvironmentVariable(name);
Expand Down
2 changes: 1 addition & 1 deletion src/Fluxzy.Core/Core/ExchangeSourceProviderHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static class ExchangeSourceProviderHelper
{
public static ExchangeSourceProvider GetSourceProvider(FluxzySetting setting,
SecureConnectionUpdater secureConnectionUpdater,
IIdProvider idProvider, ICertificateProvider? certificateProvider,
IIdProvider idProvider, ICertificateProvider certificateProvider,
ProxyAuthenticationMethod proxyAuthenticationMethod)
{
if (!setting.ReverseMode)
Expand Down
Loading

0 comments on commit b5b0645

Please sign in to comment.