Compare commits

...

4 commits

Author SHA1 Message Date
2457a85564 alembic/update database models 2023-03-16 21:26:04 +08:00
ec099b76ec feat/add digest calculate 2023-03-16 21:25:56 +08:00
a379706f78 chores/add .gitignore 2023-03-16 21:22:52 +08:00
086c025785 chores/update packages 2023-03-16 21:22:06 +08:00
7 changed files with 839 additions and 707 deletions

1
.gitignore vendored
View file

@ -2,6 +2,7 @@
.idea
*.log
tmp/
*.patch
*.py[cod]
*.egg

View file

@ -26,6 +26,8 @@ def upgrade() -> None:
sa.Column('ap_actor', sa.String(), nullable=False),
sa.Column('is_blocked', sa.Boolean(), server_default='0', nullable=False),
sa.Column('is_deleted', sa.Boolean(), server_default='0', nullable=False),
sa.Column('ap_type', sa.String(), nullable=False),
sa.Column('handle', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_actor_ap_id'), 'actor', ['ap_id'], unique=True)
@ -39,6 +41,7 @@ def upgrade() -> None:
)
op.create_index(op.f('ix_ingress_ap_id'), 'ingress', ['ap_id'], unique=False)
op.create_index(op.f('ix_ingress_id'), 'ingress', ['id'], unique=False)
op.create_index(op.f('ix_actor_handle'), 'actor', ['handle'], unique=False)
# ### end Alembic commands ###
@ -49,5 +52,6 @@ def downgrade() -> None:
op.drop_table('ingress')
op.drop_index(op.f('ix_actor_id'), table_name='actor')
op.drop_index(op.f('ix_actor_ap_id'), table_name='actor')
op.drop_index(op.f('ix_actor_handle'), table_name='actor')
op.drop_table('actor')
# ### end Alembic commands ###

26
app/httpsig.py Normal file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import base64
from typing import Literal, TypedDict, cast, Any
from Crypto.Hash import SHA256
from Crypto.Signature import PKCS1_v1_5
class HttpSignature:
"""
calculation and verification of HTTP signatures
"""
@classmethod
def calculation_digest(cls,
body: bytes,
algorithm="sha-256")-> str :
"""
Calculates the digest header value for a given HTTP body
"""
if "sha-256" == algorithm:
h = SHA256.new()
h.update(body)
return "SHA-256=" + \
base64.b64encode(h.digest()).decode("utf-8")
else:
raise ValueError(f"Not support algorithm {algorithm}")

View file

@ -32,7 +32,9 @@ class Actor(Base):
ap_id: Mapped[str] = Column(String, unique=True, nullable=False, index=True) # type: ignore
ap_actor = Column(JSON, nullable=False)
ap_actor = Column(String, nullable=False)
ap_type = Column(String, nullable=False)
handle = Column(String, nullable=True, index=True)
is_blocked = Column(Boolean, nullable=False, default=False, server_default="0")
is_deleted = Column(Boolean, nullable=False, default=False, server_default="0")

12
data/.gitignore vendored Normal file
View file

@ -0,0 +1,12 @@
.DS_Store
.idea
*.log
tmp/
config.toml
*.pem
*.db
*.py[cod]
*.egg
build
htmlcov

1496
poetry.lock generated

File diff suppressed because it is too large Load diff

View file

@ -9,7 +9,6 @@ readme = "README.md"
python = "^3.10"
fastapi = "^0.87.0"
httpx = "^0.23.0"
invoke = "^1.7.3"
uvicorn = {extras = ["standard"], version = "^0.19.0"}
loguru = "^0.6.0"
sqlalchemy = "^1.4.44"
@ -20,6 +19,8 @@ pycryptodome = "^3.15.0"
prompt-toolkit = "^3.0.33"
pydantic = "^1.10.2"
tomli-w = "^1.0.0"
invoke = "^2.0.0"
cffi = "^1.15.1"
[tool.poetry.group.dev.dependencies]