Skip to content
/ Yafp Public

A toolkit for implementing forward proxy based on ASP.NET Core and YARP.

License

Notifications You must be signed in to change notification settings

mayuki/Yafp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yafp - Yet Another Forward Proxy

A toolkit for implementing forward proxy based on ASP.NET Core and YARP.

It can be used to implement custom local proxies. For example, it is possible to create something like Fiddler.

Important

This project is a PoC and is not recommended for production use, but it works well for hobby use with customization. It can be used as a replacement for Titanium Web Proxy, etc.

Architecture

Yafp receives CONNECT requests not supported by ASP.NET Core instead and forwards them to ASP.NET Core + YARP using Unix Domain Socket or Named Pipe.

Yafp can read and modify the content of HTTPS communications with clients by dynamically issuing server certificates.

Demo (Blazor + Yafp)

video-01.mp4

Quick start

Install Yafp package from NuGet.

dotnet add package Yafp

Next, create an empty Web Application (ASP.NET Core Empty) project and modify Program.cs as follows:

using Yafp;

var builder = WebApplication.CreateBuilder(args);

// Add: Register Yafp services
builder.WebHost.UseYafpForwardProxy();

var app = builder.Build();

// Add: Use forward proxy middleware
app.MapForwardProxy();

app.MapGet("/", () => "Hello World!");
app.Run();

Next, add the proxy port and certificate settings in appsettings.json. Here we specify 18080 as the proxy port and use the sample certificate (ca.key, ca.pem).

{
  "Yafp": {
    "ListenPort": 18080,
    "RootCertificate": {
      "Path": "ca.pem",
      "KeyPath": "ca.key"
    }
  },
  ...
}

You need to copy ca.key and ca.pem from samples/ProxySample.

Warning

To access HTTPS, the CA certificate must be trusted. It is recommended that you create and trust your own certificates in the steps described below.

Last, Set the browser's HTTP proxy port to localhost:18080.

Now, launch the application, and if you can access http://www.example.com/ from your browser. You can browse the web site and see YARP logs in your console.

Create CA private key/certificate

Instead of using the temporary private key/certificate included in the repository, you can create your own.

openssl genrsa -out ca.key 2048
openssl req -x509 -sha256 -new -nodes -key ca.key -days 3650 -out ca.pem

To trust a certificate in Windows, you can create a .der file with the following command:

openssl x509 -outform der -in ca.pem -out ca.der

License

MIT License

About

A toolkit for implementing forward proxy based on ASP.NET Core and YARP.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages