Skip to content

Commit

Permalink
Docker port complete
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrumpis committed Feb 9, 2023
1 parent 9d63502 commit 025e8a5
Show file tree
Hide file tree
Showing 86 changed files with 4,885 additions and 7,166 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git
mysql
nginx
node_modules
ssl
.env
gencert.sh
npm-debug.log
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

server/.env
server/package-lock.json
server/node_modules/*
node_modules/
ssl/studio-app.snapchat.com.crt
ssl/studio-app.snapchat.com.key
.env
package-lock.json
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:16

WORKDIR /usr/src/app

COPY package*.json /usr/src/app

RUN npm install --omit=dev

COPY . /usr/src/app

CMD [ "node", "server.js" ]
101 changes: 70 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,94 @@
## Notice
As of January 26th, 2023 the domain Snap Camera normally uses is now offline. We will not be able to recovery any lenses that are missing, please do not create issues looking for lenses or messaging me about it. If I find a way to bring missing lenses I will make an update but as of now, we do not have the ability to do this.
## Information
Host your own Snap Camera Lens server after the shutdown on January 25, 2023 and continue using Snap Camera by Snap Inc. as usual without restrictions.

If you do not have 1.21.0 installed for Windows you can search for the installer, be careful though some installers may have extra software packed in with them. You can check the installer is the original one from Snap Camera by uploading your installer to https://emn178.github.io/online-tools/md5_checksum.html, if you get an MD5 of anything other than ec0816368314db8a35ddf06784ffadfe I recommend finding site with the installer.
The code is a fork of https://github.com/jaku/SnapCameraPreservation and has been changed for running your own local server with Docker. An S3 Storage solution is no longer required.

By default `snapchatreverse.jaku.tv` is configured as relay server to download Snap Lenses.
All files will be stored on your local machine inside a Docker Volume and you may disable the relay server at any time.

# SnapCameraPreservation
The purpose of this project is to allow users to still use and find snap chat lenses with the snap camera application after the Jan 25th, 2023 shutdown.
### New Features & Improvements
- Run your own server locally with Docker (no S3 Storage required)
- Access, Browse and Backup all server files locally
- Use *snapchatreverse.jaku.tv* or any other public server as relay for missing Snap Lenses
- No patching or swapping .exe files, keep the original
- Improved search functionality to find Snap Lenses easier
- Search by lens ID e.g. => *47655570879*
- Search by hash/UUID e.g. => *93776b3a994440c4b069b5c61ae352eb*
- Search by link share URL e.g. => *https://www.snapchat.com/unlock/?type=SNAPCODE&uuid=b534a2ce946c4c87ac089e7abed05bc9&metadata=01*
- Search by creator name (automatically without special syntax) e.g. => *Snap Inc*

This project uses a modified version of the 1.21.0 version of Snap Chat for Windows. Be sure to install that one before following the instructions on this page.
### Requirements
- Docker
- OpenSSL (for .key and .crt file generation)

# Instructions for PC
Head over to https://snapchatreverse.jaku.tv/snap/ and make sure you have 1.21.0 installed. Provide the site the 1.21.0 version of "Snap Camera.exe" located at the default install location of "C:\Program Files\Snap Inc\Snap Camera". Do not patch the installer, this will not work if you patch the installer. Make sure the 1.21.0 PC patch file is selected on the site, and make sure you replace the original "Snap Camera.exe" file with the newly created patch file, you will need to remove/renme the original file and then rename the patched file to "Snap Camera.exe" when neither one is running.
You can download [Docker Desktop](https://www.docker.com/products/docker-desktop/) from the offical website.

If you have issues, make sure you don't have any adblock or things blocking the patch site and that you are patching the correct version. Additionally make sure that the original Snap Camera application is stopped and not running at all. I recommend checking your task manager and searching for "Snap Camera" and closing it there to be sure. If it is running you will not be able to replace it's file with mine.
### Usage
You need to complete the following 4 steps:
- Configuration
- Generating SSL Certificate
- Importing Root Certificate
- Starting Docker

I cannot host the EXE due to possible copyrights but I can patch it if you provide the original exe.
#### Configuration
Make sure there is a file named `.env` in the directory. Just `.env` without a filename.
If it is missing create a copy of the file `example.env` and name the copy `.env`.

You'll know you are communicating with my server because a new category will be listed in the app called "Jaku Snap Backup".
You can go with all default values and don't need to change anything unless your having problems with certain ports being occupied.

If you see the above, go ahead and click on each of your saved lenses and activat them once to ensure they are backed up. After that you are free to sit back and relax.
#### Generating SSL Certificate
Snap Camera will refuse to connect to your local server if you don't have a trusted SSL certificate.
You need to generate a .crt and .key file and have the .crt file installed as trusted root certificate on your operating system.

# Instructions for Mac
Patching the application similar to Windows does not work. The built-in security of MacOS is preventing modified binaries to run, and attempts to resign are failing. However another solution for MacOS users exists, it's not my favoriate approach, but it does work and is available for users.
The required files can be generated with the included script `./gencert.sh` which will output:
- ./ssl/studio-app.snapchat.com.crt
- ./ssl/studio-app.snapchat.com.key

Download the [studio-app.snapchat.com.crt.zip](https://github.com/jaku/SnapCameraPreservation/raw/main/studio-app.snapchat.com.zip) file in this repository, and extract it. You should now have a studio-app.snapchat.com.crt file, double-clicking it should open up your Keychain Manager, click on the login option on the left-hand side of the Keychain Manager, and then on the right-hand side click Certificates. You should see studio-app.snapchat.com listed with a red icon to the left of the name. Go ahead and right-click on this file and select "Get Info", click the Trust arrow at the top and for the option "When using this certificate" select "Always Trust", close this window and it should prompt you for your MacOS password.
Docker compose expects these two files by default, otherwise the containers will not start.

Almost done!
#### Importing Root Certificate
On Windows you can import the certificate in two differnt ways
- By double-clicking the file and going through the pop up dialog (not recommended)
- By simply executing a command called *certutil* (what I recommend)

Open up terminal, you can type terminal into spotlight. Next you'll need to type this into the terminal ```echo "66.228.41.64 studio-app.snapchat.com" | sudo tee -a /etc/hosts```, it will prompt for your local computers password. But from there you should be all set.
```bash
certutil -addstore -enterprise Root ./ssl/studio-app.snapchat.com.crt
```

With that you can now close the terminal window and open Snap Camera, if everything works you should see "Jaku Snap Backup" as one of the categories.
#### Starting Docker
You may start the docker containers now with
```bash
docker compose up
```

# Unlock Lenses?
**The below will no longer work now that they shutdown the servers.**
Or run the docker containers in the background with
```bash
docker compose up -d
```

Since starting this project I learned that some lenses are not available in the search of Snap Camera and instead must be directly searched for by their URL in the search box. I'm happy to report that these also work on this project and as an extra bounus I made it so that you can use links like ``https://lens.snapchat.com/81f476238cf84615ba349efe82b36c27`` instead of the ``https://www.snapchat.com/unlock/?type=SNAPCODE&uuid=81f476238cf84615ba349efe82b36c27&metadata=01`` style links. However at this time there are still some lenses that remain locked even when searching directly. I'm currently investigating that.
### Connecting Snap Camera application to the server

**The above will no longer work now that they shutdown the servers.**
Patching the exe file may work, but I find it much easier to edit a line in a text file. This step is also easier to undo.

# How does this work?
I've modified the Snap Camera.exe (for Windows) to use my servers instead of the Snap Chat servers. This was done with a hex editor and 2 modifications were made. Instead of communicating with studio-app.snapchat.com it now communicates with snapchatreverse.jaku.tv.For Mac users we aren't changing the host but instead telling it that the hosts IP is something else and installing a self-signed certificate By doing so my server then communicates to the Snap servers to get the lenses data as if you were accessing it directly and downloads the lenses to an S3 bucket on Amazon.
1. I suggest to edit your `/etc/hosts` file. For Windows users that file is located at `%SYSTEMROOT%\System32\drivers\etc\hosts`

I then wrote a server that relays the information from the camera app to the snap chat servers (for now), which downloads the lenses separately and communicates back to the app in the way it expects.
2. Open the file as Administrator and add a single line to connect your Snap Camera application to the local server
```hosts
127.0.0.1 studio-app.snapchat.com
```

3. You can disable the connection anytime by placing a hash before the line
```hosts
#127.0.0.1 studio-app.snapchat.com
```

### Additional Information

# Where is the code?
Server code can be found in the server folder. After being sick for way to long I finally got around to clearning it up from the pervious attempts. You can see how the server works by relaying the information from the Snap Chat servers for now. I also created a reference folder which contains all the known endpoints and their expected responses.
I was able to reverse engineer the Snap Lens file format. The file format is now documented and open source.

# Who are you and why are you doing this?
I am Jaku. If you're familiar with the software on Twitch called Crowd Control then you're already familiar with some of my work as I run the company behind that. Or maybe you were an Animal Crossing fan and played in 2020 and used https://turnip.exchange, I along with another friend (Ross) built that. You can find more about me at https://about.me/jaku but overall I just like to build things and have been building things for Twitch streamers, gamers and others for over 7 years now. I have a background that allows for this sort of stuff, and I enjoy working on them.
I also provided an example Snap Lens File to Zip converter purely written in JavaScript. It will work on modern Browsers without installation or NodeJS.

- https://github.com/ptrumpis/snap-lens-file-format
- https://github.com/ptrumpis/snap-lens-file-extractor

# I have more questions or comments.
Feel free to submit an issue on Github with questions or message me on Twitter at https://twitter.com/jaku.
This conversion process is important because the Lens files are actually stored and served as zip archives on the server.
1 change: 0 additions & 1 deletion Snap Camera.bps

This file was deleted.

57 changes: 57 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
version: '3.8'

services:
mysql:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
ports:
- ${MYSQL_LOCAL_PORT}:${MYSQL_DOCKER_PORT}
volumes:
- db:/var/lib/mysql
- ./mysql:/docker-entrypoint-initdb.d:ro

webproxy:
image: nginx
environment:
- WEBAPP_PORT=${APP_DOCKER_PORT}
- HTTP_PORT=${NGINX_DOCKER_PORT}
- WWW_ROOT=${NGINX_WWW_ROOT}
volumes:
- storage:${NGINX_WWW_ROOT}
- ./nginx/snap-camera-categories-media:${NGINX_WWW_ROOT}/snap-camera-categories-media:ro
- ./nginx/default.conf.template:/etc/nginx/templates/default.conf.template:ro
- ./ssl/studio-app.snapchat.com.crt:/etc/ssl/certs/studio-app.snapchat.com.crt
- ./ssl/studio-app.snapchat.com.key:/etc/ssl/private/studio-app.snapchat.com.key
ports:
- ${NGINX_LOCAL_PORT}:${NGINX_DOCKER_PORT}
- 443:443

webapp:
build: .
environment:
- DB_HOST=mysql
- DB_USER=${MYSQL_USER}
- DB_PASS=${MYSQL_ROOT_PASSWORD}
- DB_NAME=${MYSQL_DATABASE}
- DB_PORT=${MYSQL_DOCKER_PORT}
- PORT=${APP_DOCKER_PORT}
- STORAGE_SERVER=http://127.0.0.1:${NGINX_LOCAL_PORT}
- STORAGE_PATH=/var/lib/snapcamera
volumes:
- storage:/var/lib/snapcamera
- ./:/usr/src/app
- /usr/src/app/node_modules
ports:
- ${APP_LOCAL_PORT}:${APP_DOCKER_PORT}
restart: on-failure
depends_on:
- mysql
- webproxy

volumes:
storage:
name: server-storage
db:
name: mysql-db
39 changes: 39 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
###########################
# Application Configuration
###########################

# relay source for missing lenses, leave blank to disable
RELAY_SERVER=https://snapchatreverse.jaku.tv

###########################
# Docker Configuration
###########################
MYSQL_USER=root
MYSQL_ROOT_PASSWORD=123456
MYSQL_DATABASE=snapcamera
MYSQL_LOCAL_PORT=3306
MYSQL_DOCKER_PORT=3306

APP_LOCAL_PORT=5645
APP_DOCKER_PORT=5645

NGINX_WWW_ROOT=/var/www/snapcamera
NGINX_LOCAL_PORT=80
NGINX_DOCKER_PORT=80

##############################################################
# Changes below this line are not required and not recommended
# Docker Compose will auto set everything correctly
# These values are meant for standalone usage without Docker
# Running inside a virtual machine for example
##############################################################

# values will be set by Docker if you run docker compose
#DB_HOST=localhost
#DB_PORT=3306
#DB_NAME=snapcamera
#DB_USER=root
#DB_PASS=123456
#PORT=5645
#STORAGE_SERVER="http://127.0.0.1:80"
#STORAGE_PATH=/var/lib/snapcamera
2 changes: 2 additions & 0 deletions gencert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
openssl req -x509 -nodes -days 3650 -subj "/C=CA/ST=QC/O=Snap Inc./CN=studio-app.snapchat.com" -addext "subjectAltName=DNS:studio-app.snapchat.com" -newkey rsa:2048 -keyout ./ssl/studio-app.snapchat.com.key -out ./ssl/studio-app.snapchat.com.crt
31 changes: 31 additions & 0 deletions mysql/db_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- Database name provided in .env file
USE snapcamera;

CREATE TABLE IF NOT EXISTS `lenses` (
`unlockable_id` varchar(14) NOT NULL,
`uuid` varchar(32) DEFAULT NULL,
`snapcode_url` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL,
`user_display_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
`lens_name` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,
`lens_status` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
`deeplink` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL,
`icon_url` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL,
`thumbnail_media_url` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL,
`standard_media_url` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL,
`obfuscated_user_slug` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
`image_sequence` json DEFAULT NULL,
`thumbnail_media_poster_url` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL,
`standard_media_poster_url` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL,
`mirrored` tinyint(1) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`unlockable_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS `unlocks` (
`lens_id` bigint(14) NOT NULL,
`lens_url` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL,
`signature` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL,
`hint_id` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
`additional_hint_ids` json DEFAULT NULL,
`mirrored` tinyint(1) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`lens_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
40 changes: 40 additions & 0 deletions nginx/default.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
server {
listen *:${HTTP_PORT} default_server;
listen *:443 default_server ssl;

server_name studio-app.snapchat.com;

ssl_certificate /etc/ssl/certs/studio-app.snapchat.com.crt;
ssl_certificate_key /etc/ssl/private/studio-app.snapchat.com.key;

# redirect all API calls
location /vc/ {
proxy_pass http://webapp:${WEBAPP_PORT}/vc/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $server_name;
}

# serve lens media
location / {
root ${WWW_ROOT};

sendfile on;
tcp_nopush on;

autoindex on;
autoindex_exact_size off;
autoindex_format html;
autoindex_localtime on;
}

# new snapcode url support
location = /web/deeplink/snapcode {
rewrite "^/web/deeplink/snapcode?data=([a-f0-9]{32]})&version=(\d+)&type=([a-z]{3})$" /web/deeplink/snapcode/$1.$3 break;
return 404;
}
}
Binary file added nginx/snap-camera-categories-media/BG_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added nginx/snap-camera-categories-media/Winter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added nginx/snap-camera-categories-media/WnSFH (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added nginx/snap-camera-categories-media/cute_07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"type": "module",
"name": "snap-camera-server",
"version": "1.21.0",
"description": "Host your own Snap Camera private server",
"keywords": [
"snapchat",
"snapcamera",
"snap",
"lens",
"server"
],
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "ptrumpis <ptrumpis@pm.me>",
"repository": {
"type": "git",
"url": "git+https://github.com/ptrumpis/SnapCameraPreservation.git"
},
"bugs": {
"url": "https://github.com/ptrumpis/SnapCameraPreservation/issues"
},
"license": "MIT",
"dependencies": {
"dotenv": "^16.0.3",
"express": "^4.18.2",
"mysql2": "^2.3.3",
"node-fetch": "^3.3.0"
}
}
8 changes: 0 additions & 8 deletions references/GET/vc/v1.md

This file was deleted.

Loading

0 comments on commit 025e8a5

Please sign in to comment.