Commit 155afed1 authored by ishan masdekar's avatar ishan masdekar
Browse files

Now signature(secretcode) is a 2560 bits RSA private key.

parent c41beec4
......@@ -39,7 +39,7 @@ from sqlalchemy import and_
import jwt
import gkcore
from gkcore.models.meta import dbconnect
from Crypto.PublicKey import RSA
@view_defaults(route_name='organisations')
class api_organisation(object):
......@@ -85,6 +85,14 @@ class api_organisation(object):
dataset = self.request.json_body
orgdata = dataset["orgdetails"]
userdata = dataset["userdetails"]
result = self.con.execute(select([func.count(gkdb.organisation.c.orgcode).label('ocount')]))
orgcount = result.fetchone()
if orgcount["ocount"]==0:
key = RSA.generate(2560)
privatekey = key.exportKey('PEM')
sig = {"secretcode":privatekey}
gkcore.secret = privatekey
result = self.con.execute(gkdb.signature.insert(),[sig])
result = self.con.execute(gkdb.organisation.insert(),[orgdata])
if result.rowcount==1:
code = self.con.execute(select([gkdb.organisation.c.orgcode]).where(and_(gkdb.organisation.c.orgname==orgdata["orgname"], gkdb.organisation.c.orgtype==orgdata["orgtype"], gkdb.organisation.c.yearstart==orgdata["yearstart"], gkdb.organisation.c.yearend==orgdata["yearend"])))
......
......@@ -39,13 +39,6 @@ After creating all tables, it will also create the signature based on timestamp
eng = dbconnect()
metadata.create_all(eng)
print "database created successfully"
curtime=datetime.datetime.now()
str_time=str(curtime.microsecond)
new_microsecond=str_time[0:2]
secret = str(curtime.year) + str(curtime.month) + str(curtime.day) + str(curtime.hour) + str(curtime.minute) + str(curtime.second) + new_microsecond
eng.execute("insert into signature values(%s)"%secret)
eng.execute("alter table groupsubgroups add foreign key (subgroupof) references groupsubgroups(groupcode)")
print "secret signature generated"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment