onion: add keys and certs to database
This commit is contained in:
parent
f603cb9101
commit
d5824aa518
4 changed files with 107 additions and 6 deletions
|
@ -1,3 +1,6 @@
|
|||
import base64
|
||||
import hashlib
|
||||
|
||||
from app.brm.brn import BRN
|
||||
from app.extensions import db
|
||||
from app.models import AbstractConfiguration, AbstractResource
|
||||
|
@ -18,8 +21,31 @@ class Onion(AbstractConfiguration):
|
|||
domain_name = db.Column(db.String(255), nullable=False)
|
||||
onion_name = db.Column(db.String(56), nullable=False, unique=True)
|
||||
|
||||
onion_public_key = db.Column(db.LargeBinary, nullable=False)
|
||||
onion_private_key = db.Column(db.LargeBinary, nullable=False)
|
||||
|
||||
tls_public_key = db.Column(db.LargeBinary, nullable=False)
|
||||
tls_private_key = db.Column(db.LargeBinary, nullable=False)
|
||||
|
||||
group = db.relationship("Group", back_populates="onions")
|
||||
|
||||
@property
|
||||
def calculated_onion_name(self):
|
||||
p = self.onion_public_key[32:]
|
||||
|
||||
h = hashlib.sha3_256()
|
||||
h.update(b".onion checksum")
|
||||
h.update(p)
|
||||
h.update(b"\x03")
|
||||
checksum = h.digest()
|
||||
|
||||
result = bytearray(p)
|
||||
result.extend(checksum[0:2])
|
||||
result.append(0x03)
|
||||
|
||||
onion = base64.b32encode(result).decode("utf-8").strip("=")
|
||||
return onion.lower()
|
||||
|
||||
|
||||
class Eotk(AbstractResource):
|
||||
group_id = db.Column(db.Integer(), db.ForeignKey("group.id"), nullable=False)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue