feat: create new onion services via api
This commit is contained in:
parent
192dacf760
commit
24cac76f70
10 changed files with 631 additions and 280 deletions
|
@ -1,5 +1,3 @@
|
|||
import base64
|
||||
import hashlib
|
||||
from typing import Optional, TypedDict
|
||||
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
@ -8,6 +6,7 @@ from app.brm.brn import BRN
|
|||
from app.extensions import db
|
||||
from app.models import AbstractConfiguration, AbstractResource
|
||||
from app.models.base import Group
|
||||
from app.util.onion import onion_hostname
|
||||
|
||||
|
||||
class OnionDict(TypedDict):
|
||||
|
@ -40,20 +39,7 @@ class Onion(AbstractConfiguration):
|
|||
|
||||
@property
|
||||
def onion_name(self) -> str:
|
||||
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()
|
||||
return onion_hostname(self.onion_public_key)
|
||||
|
||||
def to_dict(self) -> OnionDict:
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue