コード例 #1
0
ファイル: Gitapi.py プロジェクト: yatchol6214/AngelBot
 def __init__(self, redis):
     self.apiurl = "https://api.github.com"
     self.pools = redis
     self.header = {
         'Accept': 'application/vnd.github.v3+json',
         'User-Agent': 'AngelBot ( aiohttp 0.26.1 python 3.5.1 )'
     }
     self.crypt = encryption.AESCipher(cryptokey)
     self.commands = [['gitinfo', self.get_user_info]]
     self.auth_limit = 5000
コード例 #2
0
def reg_user():
    # Program reads list of users
    if 'users.txt' not in os.listdir(os.getcwd()):
        open("users.txt", "a")
    with open("users.txt", "rb") as f:
        text = f.read().decode("utf-8")
    lines = text.splitlines()
    users = [line.split(":")[0] for line in lines]

    while 1:
        # User enters username and password
        new_user = input("Username: "******"Password: "******"utf-8")

        # Program checks if the username is in the userlist
        if new_user in users:
            print("Username already exists")
            break
        else:
            # If it's not, program calculates the password hash
            pswd_hash = get_hash(new_user.encode("utf-8") + new_password)

            # And write username and password hash to the file
            out = "{}:{}\n".format(new_user, pswd_hash).encode("utf-8")
            open("users.txt", "ab").write(out)

            # Next program creates a folder for user database
            os.makedirs(os.getcwd() + os.sep + "databases" + os.sep + new_user)
            os.chdir(os.getcwd() + os.sep + "databases" + os.sep + new_user)

            # After that program creates database file and encrypts it
            # First line of file contains username and user password
            output = "{}:{}\n".format(new_user, new_password).encode("utf-8")
            cipher = encryption.AESCipher(new_password)
            encrypted = cipher.encrypt(output)

            open(new_user + ".database", "a")
            with open(new_user + ".database", "w") as f:
                f.write(encrypted)
            os.chdir("..")
            os.chdir("..")
            print("User successfully registered. Now you can log in")
            break
コード例 #3
0
def db_append(username, password):

    # First function gets password list from database
    passwords = get_passwords(username, password)

    os.chdir("databases" + os.sep + username)
    if username + ".database" not in os.listdir(os.getcwd()):
        open(username + ".database", "a")

    # Next, the begins loop to input
    print("Type data as following: login:password (no whitespaces and :)\n" +
          "Or type !end to stop\n")
    while 1:
        # User enters login:password
        db_create_command = input("@" + username + "(db_append)>")
        pattern = re.compile("^.+\S:.+\S$")
        match = pattern.fullmatch(db_create_command)

        # If entered string matches to the pattern
        if match:
            db_create_command = db_create_command.split(":")
            if db_create_command[0] in passwords.keys():
                print("\n!!!This login is already exists!!!\n")
                continue
            passwords[db_create_command[0]] = db_create_command[1]
        elif db_create_command == "!end":
            break
        elif db_create_command == "":
            continue
        else:
            print("\n!!!Unknown command!!!\n")

    # When input finished, program encrypts data and write it to the file
    output = ""
    for login, login_passwd in zip(passwords.keys(), passwords.values()):
        output += "{}:{}\n".format(login, login_passwd)
    output = output.encode("utf-8")
    cipher = encryption.AESCipher(password)
    with open(username + ".database", "w") as f:
        f.write(cipher.encrypt(output))
    os.chdir("..")
    os.chdir("..")
    print("\nBack to program...\n\nType !end to exit the program\n")
コード例 #4
0
def get_passwords(username, password):
    os.chdir("databases" + os.sep + username)
    # Function decrypts database
    cipher = encryption.AESCipher(password)
    with open(username + ".database", "r") as f:
        encrypted = f.read()
        text = cipher.decrypt(encrypted)
    if not text:
        os.chdir("..")
        return None

    # Then from decrypted text it extracts line with login and password
    text = text.splitlines()
    passwords_table = {}
    for line in text:
        line = line.strip().split(':')
        passwords_table[line[0]] = line[1]
    os.chdir('..')
    os.chdir('..')
    return passwords_table
コード例 #5
0
port = 9500
s.bind(('0.0.0.0', port))
print('Socket binded to port 9500')
s.listen(3)
print('Socket is listening')

while True:
    #Send client server name necessary to verify against CA Authority
    clientConnection, addr = s.accept()
    print('Connection made')
    hostname = "Homebase"
    clientConnection.sendall(hostname.encode())

    #Recieves encrypted response from client once Certificate is verified through session key reciept
    msg = clientConnection.recv(1024)
    cipher = encryption.AESCipher(Public_Key)
    decryptedMsg = cipher.decrypt(msg)
    data = decryptedMsg.decode("utf-8")
    print('Message recieved:', data)
    if data == "session key":
        reply = "key acknowledged"
        encryptedRply = cipher.encrypt(reply)
        clientConnection.sendall(encryptedRply)
        print('Reply Sent:', reply)
    else:
        clientConnection.close()

    #Trust established, server sends encrypted response to client depending on reponse decrypted message from client
    msg2 = clientConnection.recv(1024)
    decryptedMsg = cipher.decrypt(msg2)
    data2 = decryptedMsg.decode("utf-8")
コード例 #6
0
port = 9500
s.connect(('localhost', port))

#Recieves broadcasted server name for Certificate Authority Validation
replyMsg = s.recv(1024)
data = replyMsg.decode("utf-8")
print('Reply received:', data)

#Queries CA Database for recieved hostname and recieves public_key for
#encryption if hostname exists
pKey = CA_Server.checkCAInfo(data)
print(pKey[0])

#uses key to encrypt a session key to send to application server once trust has
# been established
cipher = encryption.AESCipher(pKey[0])
sessionKey = 'session key'
encryptedMsg = cipher.encrypt(sessionKey)
s.sendall(encryptedMsg)

#Client recieves acknoledgement from Server once sesion key is recieved
replyMsg2 = s.recv(1024)
decryptedRply = cipher.decrypt(replyMsg2)
reply = decryptedRply.decode("utf-8")
print("Reply Recieved: ", reply)

#If session key acknowledgement is recieved by client, client processes secure
#data to be recieved by server and awaits secure reply
if reply == "key acknowledged":
    myMessage = input('Input: ')
    encryptedMsg = cipher.encrypt(myMessage)
コード例 #7
0
ファイル: main.py プロジェクト: pepsipu/discord.fs
import discord
import json
import io
import compression
from db import db
from discordUtils import serverData, embeds
import encryption

# discord bot stuff
client = discord.Client()
config = json.load(open("./config.json"))
auth = lambda discord_id, server: discord_id in config[
    "adminIds"] or server.owner.id == discord_id  # auth check
not_init = lambda channel: channel.send("The database is not initialized!")
# encryption related stuff
aes = encryption.AESCipher(config["aesPass"][:16].encode())


@client.event
async def on_ready():
    print(
        f"Ready! Running on user {client.user.name}#{client.user.discriminator}."
    )


@client.event
async def on_message(msg):
    if msg.author.bot:
        return
    if msg.content.startswith(config["prefix"]):
        db_guild = msg.guild