2013-10-05 23:12:31 +02:00
========
SnapPass
========
2022-05-17 19:32:12 +02:00
|pypi|
2017-04-30 23:17:14 +02:00
.. |pypi| image :: https://img.shields.io/pypi/v/snappass.svg
:target: https://pypi.python.org/pypi/snappass
:alt: Latest version released on PyPI
2013-10-05 23:12:31 +02:00
2019-01-16 15:11:56 +01:00
It's like SnapChat... for passwords.
2013-10-05 23:12:31 +02:00
2019-01-16 15:11:56 +01:00
This is a web app that lets you share passwords securely.
2013-10-05 23:12:31 +02:00
Let's say you have a password. You want to give it to your coworker, Jane.
You could email it to her, but then it's in her email, which might be backed up,
and probably is in some storage device controlled by the NSA.
You could send it to her over chat, but chances are Jane logs all her messages
2019-01-16 15:11:56 +01:00
because she uses Google Hangouts Chat, and Google Hangouts Chat might log everything.
2013-10-05 23:12:31 +02:00
You could write it down, but you can't find a pen, and there's way too many
2019-01-16 15:11:56 +01:00
characters because your security person, Paul, is paranoid.
2013-10-05 23:12:31 +02:00
2016-07-19 02:14:38 +02:00
So we built SnapPass. It's not that complicated, it does one thing. If
2013-10-05 23:12:31 +02:00
Jane gets a link to the password and never looks at it, the password goes away.
If the NSA gets a hold of the link, and they look at the password... well they
have the password. Also, Jane can't get the password, but now Jane knows that
not only is someone looking in her email, they are clicking on links.
Anyway, this took us very little time to write, but we figure we'd save you the
trouble of writing it yourself, because maybe you are busy and have other things
to do. Enjoy.
2017-05-16 03:34:13 +02:00
Security
2017-05-16 15:25:03 +02:00
--------
2017-05-16 03:34:13 +02:00
Passwords are encrypted using `Fernet`_ symmetric encryption, from the `cryptography`_ library.
A random unique key is generated for each password, and is never stored;
it is rather sent as part of the password link.
This means that even if someone has access to the Redis store, the passwords are still safe.
.. _Fernet: https://cryptography.io/en/latest/fernet/
.. _cryptography: https://cryptography.io/en/latest/
2013-10-05 23:12:31 +02:00
Requirements
------------
2021-01-12 22:47:28 +01:00
* `Redis`_
2023-12-02 02:04:38 +01:00
* Python 3.8+
2013-10-05 23:12:31 +02:00
2021-01-12 22:47:28 +01:00
.. _Redis: https://redis.io/
2013-10-05 23:12:31 +02:00
Installation
------------
::
$ pip install snappass
$ snappass
* Running on http://0.0.0.0:5000/
* Restarting with reloader
Configuration
-------------
2021-01-12 22:47:28 +01:00
Start by ensuring that Redis is up and running.
Then, you can configure the following via environment variables.
2013-10-05 23:12:31 +02:00
2018-08-12 23:41:14 +02:00
`` SECRET_KEY `` : unique key that's used to sign key. This should
2017-04-15 18:19:21 +02:00
be kept secret. See the `Flask Documentation`__ for more information.
2013-10-05 23:12:31 +02:00
2017-04-15 18:19:21 +02:00
.. __: http://flask.pocoo.org/docs/quickstart/#sessions
2016-12-20 05:24:26 +01:00
2018-08-12 23:41:14 +02:00
`` DEBUG `` : to run Flask web server in debug mode. See the `Flask Documentation`__ for more information.
2017-04-15 18:19:21 +02:00
.. __: http://flask.pocoo.org/docs/quickstart/#debug-mode
2013-10-05 23:12:31 +02:00
2018-08-12 23:41:14 +02:00
`` STATIC_URL `` : this should be the location of your static assets. You might not
2013-10-05 23:12:31 +02:00
need to change this.
2018-08-12 23:41:14 +02:00
`` NO_SSL `` : if you are not using SSL.
2016-07-16 16:11:36 +02:00
2019-08-09 23:07:49 +02:00
`` URL_PREFIX `` : useful when running snappass behind a reverse proxy like `nginx` . Example: `` "/some/path/" `` , Defaults to `` None ``
2018-08-12 23:41:14 +02:00
`` REDIS_HOST `` : this should be set by Redis, but you can override it if you want. Defaults to `` "localhost" ``
2016-07-19 02:14:38 +02:00
2018-08-12 23:41:14 +02:00
`` REDIS_PORT `` : is the port redis is serving on, defaults to 6379
2016-08-21 09:05:01 +02:00
2018-08-12 23:41:14 +02:00
`` SNAPPASS_REDIS_DB `` : is the database that you want to use on this redis server. Defaults to db 0
2016-08-21 09:05:01 +02:00
2018-08-12 23:41:14 +02:00
`` REDIS_URL `` : (optional) will be used instead of `` REDIS_HOST `` , `` REDIS_PORT `` , and `` SNAPPASS_REDIS_DB `` to configure the Redis client object. For example: redis://username:password@localhost:6379/0
2018-07-01 19:25:55 +02:00
2018-08-12 23:41:14 +02:00
`` REDIS_PREFIX `` : (optional, defaults to `` "snappass" `` ) prefix used on redis keys to prevent collisions with other potential clients
2016-09-08 22:44:03 +02:00
2021-07-29 19:39:47 +02:00
`` HOST_OVERRIDE `` : (optional) Used to override the base URL if the app is unaware. Useful when running behind reverse proxies like an identity-aware SSO. Example: `` sub.domain.com ``
2024-03-29 23:49:56 +01:00
APIs
----
2024-02-27 00:22:40 +01:00
2024-03-29 23:49:56 +01:00
SnapPass has 2 APIs :
1. A simple API : That can be used to create passwords links, and then share them with users
2. A more REST-y API : Which facilitate programmatic interactions with SnapPass, without having to parse HTML content when retrieving the password
Simple API
^^^^^^^^^^
The advantage of using the simple API is that you can create a password and retrieve the link without having to open the web interface. This is useful if you want to embed it in a script or use it in a CI/CD pipeline.
2024-02-27 00:22:40 +01:00
To create a password, send a POST request to `` /api/set_password `` like so:
::
$ curl -X POST -H "Content-Type: application/json" -d '{"password": "foobar"}' http://localhost:5000/api/set_password/
This will return a JSON response with the password link:
::
{
"link": "http://127.0.0.1:5000/snappassbedf19b161794fd288faec3eba15fa41~hHnILpQ50ZfJc3nurDfHCb_22rBr5gGEya68e_cZOrY%3D",
"ttl":1209600
}
the default TTL is 2 weeks (1209600 seconds), but you can override it by adding a expiration parameter:
::
$ curl -X POST -H "Content-Type: application/json" -d '{"password": "foobar", "ttl": 3600 }' http://localhost:5000/api/set_password/
2024-03-29 23:49:56 +01:00
REST API
^^^^^^^^
The advantage of using the REST API is that you can fully manage the lifecycle of the password stored in SnapPass without having to interact with any web user interface.
This is useful if you want to embed it in a script, use it in a CI/CD pipeline or share it between multiple client applications.
Create a password
"""""""""""""""""
To create a password, send a POST request to `` /api/v2/passwords `` like so:
::
$ curl -X POST -H "Content-Type: application/json" -d '{"password": "foobar"}' http://localhost:5000/api/v2/passwords
This will return a JSON response with a token and the password link:
::
{
2024-03-30 20:46:02 +01:00
"token": "snappassbedf19b161794fd288faec3eba15fa41~hHnILpQ50ZfJc3nurDfHCb_22rBr5gGEya68e_cZOrY=",
2024-03-29 23:49:56 +01:00
"links": [{
"rel": "self",
"href": "http://127.0.0.1:5000/api/v2/passwords/snappassbedf19b161794fd288faec3eba15fa41~hHnILpQ50ZfJc3nurDfHCb_22rBr5gGEya68e_cZOrY%3D",
2024-03-30 20:47:03 +01:00
},{
"rel": "web-view",
"href": "http://127.0.0.1:5000/snappassbedf19b161794fd288faec3eba15fa41~hHnILpQ50ZfJc3nurDfHCb_22rBr5gGEya68e_cZOrY%3D",
2024-03-29 23:49:56 +01:00
}],
"ttl":1209600
}
The default TTL is 2 weeks (1209600 seconds), but you can override it by adding a expiration parameter:
::
$ curl -X POST -H "Content-Type: application/json" -d '{"password": "foobar", "ttl": 3600 }' http://localhost:5000/api/v2/passwords
If the password is null or empty, and the TTL is larger than the max TTL of the application, the API will return an error like this:
Otherwise, the API will return a 404 (Not Found) response like so:
::
{
"invalid-params": [{
"name": "password",
"reason": "The password is required and should not be null or empty."
}, {
"name": "ttl",
"reason": "The specified TTL is longer than the maximum supported."
}],
"title": "The password and/or the TTL are invalid.",
"type": "https://127.0.0.1:5000/set-password-validation-error"
}
Check if a password exists
""""""""""""""""""""""""""
2024-03-30 20:46:02 +01:00
To check if a password exists, send a HEAD request to `` /api/v2/passwords/<token> `` , where `` <token> `` is the token of the API response when a password is created (url encoded), or simply use the `self` link:
2024-03-29 23:49:56 +01:00
::
$ curl --head http://localhost:5000/api/v2/passwords/snappassbedf19b161794fd288faec3eba15fa41~hHnILpQ50ZfJc3nurDfHCb_22rBr5gGEya68e_cZOrY%3D
If :
- the passwork_key is valid
- the password :
- exists,
- has not been read
- is not expired
Then the API will return a 200 (OK) response like so:
::
HTTP/1.1 200 OK
Server: Werkzeug/3.0.1 Python/3.12.2
Date: Fri, 29 Mar 2024 22:15:54 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 0
Connection: close
Otherwise, the API will return a 404 (Not Found) response like so:
::
HTTP/1.1 404 NOT FOUND
Server: Werkzeug/3.0.1 Python/3.12.2
Date: Fri, 29 Mar 2024 22:19:29 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 0
Connection: close
Read a password
"""""""""""""""
To read a password, send a GET request to `` /api/v2/passwords/<password_key> `` , where `` <password_key> `` is the token of the API response when a password is created, or simply use the `self` link:
::
$ curl -X GET http://localhost:5000/api/v2/passwords/snappassbedf19b161794fd288faec3eba15fa41~hHnILpQ50ZfJc3nurDfHCb_22rBr5gGEya68e_cZOrY%3D
If :
2024-03-30 20:46:02 +01:00
- the token is valid
2024-03-29 23:49:56 +01:00
- the password :
2024-03-30 20:46:02 +01:00
- exists
2024-03-29 23:49:56 +01:00
- has not been read
- is not expired
Then the API will return a 200 (OK) with a JSON response containing the password :
::
{
"password": "foobar"
}
Otherwise, the API will return a 404 (Not Found) response like so:
::
{
"invalid-params": [{
"name": "token"
}],
"title": "The password doesn't exist.",
"type": "https://127.0.0.1:5000/get-password-error"
}
Notes on APIs
^^^^^^^^^^^^^
2024-02-27 00:22:40 +01:00
Notes:
2024-03-29 23:49:56 +01:00
- When using the APIs, you can specify any ttl, as long as it is lower than the default.
2024-02-27 00:22:40 +01:00
- The password is passed in the body of the request rather than in the URL. This is to prevent the password from being logged in the server logs.
- Depending on the environment you are running it, you might want to expose the `` /api `` endpoint to your internal network only, and put the web interface behind authentication.
2024-03-29 23:49:56 +01:00
2016-07-16 16:11:36 +02:00
Docker
------
2016-07-19 02:41:34 +02:00
Alternatively, you can use `Docker`_ and `Docker Compose`_ to install and run SnapPass:
2016-07-16 16:11:36 +02:00
2016-07-19 02:41:34 +02:00
.. _Docker: https://www.docker.com/
.. _Docker Compose: https://docs.docker.com/compose/
2017-04-15 18:55:12 +02:00
2016-07-16 16:11:36 +02:00
::
$ docker-compose up -d
2018-07-13 03:54:54 +02:00
This will pull all dependencies, i.e. Redis and appropriate Python version (3.7), then start up SnapPass and Redis server. SnapPass server is accessible at: http://localhost:5000
2018-05-12 18:02:24 +02:00
2019-11-04 17:16:12 +01:00
Similar Tools
-------------
- `Snappass.NET <https://github.com/generateui/Snappass.NET> `_ is a .NET
(ASP.NET Core) port of SnapPass.
2018-05-12 18:02:24 +02:00
We're Hiring!
-------------
Are you really excited about open-source and great software engineering?
2019-11-04 17:16:12 +01:00
`Pinterest is hiring <https://careers.pinterest.com> `_ !