# pms-proxy

> PMS mitm proxy

Latest version **1.1.7** (published 2022-06-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install pms-proxy
pnpm add pms-proxy
yarn add pms-proxy
bun add pms-proxy
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.7 |
| Published | 2022-06-02 |
| First published | 2022-05-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12.0.0 |
| Dependencies | 5 |
| Unpacked size | 207.7 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 16 |
| Author | wawahuy |
| Maintainers | zayuh |
| Keywords | proxy, mitm, https proxy |

## Links

- npm: https://www.npmjs.com/package/pms-proxy
- Repository: https://github.com/wawahuy/pms-proxy
- Homepage: https://github.com/wawahuy/pms-proxy#readme
- Issues: https://github.com/wawahuy/pms-proxy/issues
- npm.io page: https://npm.io/package/pms-proxy

## Dependencies (5)

- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [express](https://npm.io/package/express.md) ^4.18.1
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.7
- [node-forge](https://npm.io/package/node-forge.md) ^1.3.1
- [abort-controller](https://npm.io/package/abort-controller.md) ^3.0.0

## Recent versions

- 1.1.7 (latest) — 2022-06-02
- 1.1.6 — 2022-06-02
- 1.1.5 — 2022-06-02
- 1.1.4 — 2022-05-28
- 1.1.3 — 2022-05-09
- 1.1.2 — 2022-05-09
- 1.1.1 — 2022-05-08
- 1.1.0 — 2022-05-08
- 1.0.6 — 2022-05-07
- 1.0.5 — 2022-05-07
- 1.0.4 — 2022-05-07
- 1.0.3 — 2022-05-07
- 1.0.2 — 2022-05-07
- 1.0.1 — 2022-05-07
- 1.0.0 — 2022-05-07

## README

# PMS Proxy
[![Available on NPM](https://img.shields.io/npm/v/pms-proxy.svg)](https://npmjs.com/package/pms-proxy)  [![Try Mockttp on RunKit](https://badge.runkitcdn.com/pms-proxy.svg)](https://npm.runkit.com/pms-proxy)
<br>
Supports http/https traffic monitoring.

## Get Started
```bash
npm install pms-proxy
```


## Todo
- Write unit test
- Setup CI
- 

## Progress
- Support http2
-

## Document
### Require
- Javascript
```javascript
const {PPServerProxy} = require('pms-proxy');
```
- Typescript
```javascript
import PPServerProxy from "pms-proxy";
```

### Create server

```javascript
    const server = new PPServerProxy()
    server.listen(1234).then(() => {
        console('created!');
    })
```

### Websocket Forward
```javascript
    const forwardDst = 'wss://socketsbay.com/wss/v2/2/demo/';
    server.getWebsocket()
        .addRule()
        .host('abc.com')
        .then(new PPPassThroughWsHandler(forwardDst))
    server.getWebsocket()
        .addRule()
        .url(/wss:\/\/hello\.com/)
        .then(new PPPassThroughWsHandler(forwardDst))
```

### Monitor all traffics http & https
Note: https only capture when provide CA cert, and install CA cert in machine
```javascript
    server.addRule()
        .any()
        .then(async (request, response) => {
            console.log(request.method, request.url);

            const passThrough = new PPPassThroughHttpHandler();
            passThrough.injectBuffer((request, buffer) => {
                console.log('--> response buffer size', buffer.length);
                return { data: buffer };
            })

            await passThrough.handle(request, response);
        })
```

### Inject page 'abc.com'

```javascript
    const pass = new PPPassThroughHttpHandler();
    pass.injectBuffer((req, buffer) => {
        return {
            data: buffer.toString() + "<script>alert('hello world!')</script>"
        };
    })

    server.addRule()
        .host(/abc\.com/g)
        // or .host("abc.com")
        // or .host((host) => host === "abc.com")
        .then(pass);
```

### Handle any request
```javascript
    server.addRule()
        .any()
        .then((req, res) => {
            res.status(200).write('Hello world!');
        })
```

### Create fake website
```javascript
    /// app as express
    const app = createAppHttpHandler();
    app.get('/', (req, res) => {
        res.status(200).send('oke');
    })
    server.addRule().host('test-fake.com').then(app);
```

### Create fake websocket 'abc.com'
```javascript
    const ws = server.getWebsocket();
    ws.addRule()
        .host('abc.com')
        .then((req, ws) => {
            ws.send('oke ws');
        })
```

### Inject websocket 'abc.com'
```javascript
    const inject = new PPPassThroughWsHandler();
    inject.injectSend(data => data.toString() + ' inject!');
    inject.injectReceive(data => data.toString() + ' inject!');

    const ws = server.getWebsocket();
    ws.addRule().host('abc.com').then(inject)
```

### Support monitor https traffic

```javascript
    const server = new PPServerProxy({
    https: {
        certPath: path.join(__dirname, '../certs/rootCA.pem'),
        keyPath: path.join(__dirname, '../certs/rootCA.key')
    }
});
```

- create CA cert:
```shell
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1825 -out rootCA.pem
openssl pkcs12 -export -out rootCA.p12 -inkey rootCA.key -in rootCA.pem
```

- create monitor https & SPKI
```typescript
    const https = await PPCa.generateCACertificate();
    const spki = PPCa.generateSPKIFingerprint((<PPCaFileOptions>https).cert);
    const userData = path.join('C:/test-chrome');

    const server = new PPServerProxy({https});
    await server.listen(1234);

    // node module
    child_process.exec(
        `start chrome --proxy-server="http://127.0.0.1:1234" --ignore-certificate-errors-spki-list=\"${spki}\" --user-data-dir=\"${userData}\"`
    );
```

---
_Source: https://npm.io/package/pms-proxy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
