Skip to content

Commit

Permalink
fix errors with ports and env file
Browse files Browse the repository at this point in the history
  • Loading branch information
mo9a7i committed Feb 18, 2022
1 parent fa10e0f commit fb3aeaa
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ celerybeat-schedule
*.sage.py

# Environments
docker_env_file
.env
.venv
env/
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM python:3

ADD main.py /
ADD requirements.txt /
ADD firebasescrypt /firebasescrypt

RUN pip install --upgrade pip
RUN pip install flask python-dotenv
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

1. First, you need some configuration variables from your firebase project, you can get them from firebase->authentication-> little three dots top right of users table

2. create an `.env` file in the project root directory, next to Dockerfile with the below content
2. create an `docker_env_file` file in the project root directory, next to Dockerfile with the below content. (You can rename the `docker_env_file.example` and use it)

```bash
base64_signer_key='get_from_your_firebase_project'
base64_salt_separator='get_from_your_firebase_project'
rounds=get_from_your_firebase_project
mem_cost=get_from_your_firebase_project
base64_signer_key=__get_from_your_firebase_project__
base64_salt_separator=__get_from_your_firebase_project__
rounds=__get_from_your_firebase_project__
mem_cost=__get_from_your_firebase_project__
```

3. Next, run the below commands in the project folder (next to Dockerfile)
Expand All @@ -21,7 +21,7 @@
$git clone this repo
$cd firebasescrypt
$docker build -t firebasescrypt
$docker run firebasescrypt
$docker run -p 5959 --env-file ./docker_env_file firebasescrypt
```

Now you have a flask endpoint running at your machine at `http://127.0.0.1:5959` (unless you changed the port or put on a server)
Expand Down
4 changes: 4 additions & 0 deletions docker_env_file.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
base64_signer_key=
base64_salt_separator=
rounds=
mem_cost=
2 changes: 1 addition & 1 deletion firebasescrypt/firebasescrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def verify_password(
) -> bool:
"""Verify if password matches known hash"""
derived_key: bytes = generate_derived_key(password, salt, salt_separator, rounds, mem_cost)
signer_key: bytes = base64.b64decode(signer_key)
signer_key: bytes = base64.urlsafe_b64decode(signer_key)

result = encrypt(signer_key, derived_key)

Expand Down
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def hash():
password_salt = urllib.parse.unquote(request.args.get('salt', ""))

if not isBase64(password_salt):
return "salt is not in correct syntax";
return "salt is not in correct syntax"

# Sample Password hash parameters from Firebase Console.
salt_separator = os.getenv('base64_salt_separator')
signer_key = os.getenv('base64_signer_key')
signer_key: bytes = base64.b64decode(signer_key)
signer_key: bytes = base64.urlsafe_b64decode(signer_key)
rounds= int(os.getenv('rounds'))
mem_cost= int(os.getenv('mem_cost'))
derived_key = firebasescrypt.generate_derived_key(password_native, password_salt, salt_separator, rounds, mem_cost)
Expand All @@ -41,4 +41,4 @@ def isBase64(sb):
return False

if __name__ == "__main__":
app.run(port=5959)
app.run(host='0.0.0.0', port=5959)

0 comments on commit fb3aeaa

Please sign in to comment.