Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<Files ".env">
Require all denied
<Files .env>
Order allow,deny
Deny from all
</Files>
2 changes: 1 addition & 1 deletion Depfiles/dependencies.pip
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ colorconsole
cunyfirstapi
mysql
mysql-connector
pycryptodome
pycryptodome
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function display()
<script type="text/javascript">
function encryptPassword() {
let rsa = forge.pki.rsa;
let publicKeyEncoded = <?php echo '`'.file_get_contents("keys/public.pem").'`'?>;
let publicKeyEncoded = <?php echo '`'.file_get_contents("../../private/keys/public.pem").'`'?>;
let publicKey = forge.pki.publicKeyFromPem(publicKeyEncoded);
let ciphertext = publicKey.encrypt(document.userform.password.value, 'RSA-OAEP', {
md: forge.md.sha256.create(),
Expand Down
3 changes: 2 additions & 1 deletion keys/.htaccess
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
deny from all
Order Allow,Deny
Deny from all
6 changes: 2 additions & 4 deletions src/core/grade_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@
import mysql.connector
###********* GLOBALS *********###

# Create .env file path.
dotenv_path = join(constants.abs_repo_path(), '.env')

# Load file from the path.
load_dotenv()
load_dotenv('../../private/.env')

# Accessing variables.
account_sid = os.getenv('TWILIO_SID')
Expand Down Expand Up @@ -250,7 +248,7 @@ def start_notifier():

cursor.execute(f'UPDATE Users SET lastUpdated = NOW() WHERE id={__id};')

decrypted_password = decrypt(encrypted_password, 'keys/private.pem')
decrypted_password = decrypt(encrypted_password, '../../private/keys/private.pem')
api = CUNYFirstAPI(username, decrypted_password, school.upper())
api.login()

Expand Down
5 changes: 2 additions & 3 deletions src/core/initializegn.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@
__status__ = "Production"

# Load file.
load_dotenv()
load_dotenv('../../private/.env')

# Accessing variables.
DB_USERNAME = os.getenv('DB_USERNAME')
DB_PASSWORD = os.getenv('DB_PASSWORD')
DB_HOST = os.getenv('DB_HOST')
PRIVATE_RSA_KEY = os.getenv('PRIVATE_RSA_KEY').replace(r'\n', '\n')

def add_to_db(username, encrypted_password, school, phone):

Expand Down Expand Up @@ -127,7 +126,7 @@ def main():
)
return

password = decrypt(encrypted_password, 'keys/private.pem')
password = decrypt(encrypted_password, '../../private/keys/private.pem')

api = cunyfirstapi.CUNYFirstAPI(username, password)
api.login()
Expand Down
12 changes: 8 additions & 4 deletions src/helper/security.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import os
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
from Crypto.Signature import PKCS1_PSS
import Crypto
import base64
KEY_SIZE = 2048

def gen_keys():
def gen_keys(path='../../private/keys'):
if not os.path.isdir(path):
os.makedirs(path)

key = RSA.generate(KEY_SIZE)
private_key = key.export_key("PEM")
file_out = open("keys/private.pem", "wb")
file_out = open(f"{path}/private.pem", "wb")
file_out.write(private_key)
file_out.close()

public_key = key.publickey().export_key("PEM")
file_out = open("keys/public.pem", "wb")
file_out = open(f"{path}/public.pem", "wb")
file_out.write(public_key)
file_out.close()
print("Keys have been written to keys/")
print(f"Keys have been written to {path}")

def encrypt(message, path='keys/public.pem'):
key = RSA.importKey(open(path).read())
Expand Down