apsig 0.5.4__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- apsig-0.6.0/.github/workflows/docs.yml +34 -0
- apsig-0.6.0/.github/workflows/test.yml +39 -0
- apsig-0.6.0/.pre-commit-config.yaml +72 -0
- apsig-0.6.0/.zed/settings.json +36 -0
- apsig-0.6.0/PKG-INFO +205 -0
- apsig-0.6.0/README.md +170 -0
- {apsig-0.5.4 → apsig-0.6.0}/Taskfile.yaml +1 -1
- apsig-0.6.0/docs/compatibility.md +23 -0
- apsig-0.6.0/docs/index.md +165 -0
- apsig-0.6.0/docs/reference/cavage.md +10 -0
- apsig-0.6.0/docs/reference/fep-8b32.md +10 -0
- apsig-0.6.0/docs/reference/rsasig2017.md +10 -0
- {apsig-0.5.4 → apsig-0.6.0}/pyproject.toml +80 -13
- apsig-0.6.0/scripts/sync_deps_with_linter.py +60 -0
- {apsig-0.5.4 → apsig-0.6.0}/src/apsig/__init__.py +1 -3
- {apsig-0.5.4 → apsig-0.6.0}/src/apsig/_version.py +2 -2
- {apsig-0.5.4 → apsig-0.6.0}/src/apsig/actor/keytools.py +7 -5
- {apsig-0.5.4 → apsig-0.6.0}/src/apsig/draft/__init__.py +1 -4
- {apsig-0.5.4 → apsig-0.6.0}/src/apsig/draft/sign.py +66 -29
- {apsig-0.5.4 → apsig-0.6.0}/src/apsig/draft/tools.py +5 -3
- {apsig-0.5.4 → apsig-0.6.0}/src/apsig/draft/verify.py +40 -23
- apsig-0.6.0/src/apsig/exceptions.py +14 -0
- {apsig-0.5.4 → apsig-0.6.0}/src/apsig/ld_signature.py +59 -31
- apsig-0.6.0/src/apsig/proof/__init__.py +4 -0
- {apsig-0.5.4 → apsig-0.6.0}/src/apsig/proof/sign.py +13 -7
- {apsig-0.5.4 → apsig-0.6.0}/src/apsig/proof/verify.py +30 -18
- apsig-0.6.0/src/apsig/rfc9421.py +363 -0
- {apsig-0.5.4 → apsig-0.6.0}/src/apsig/tools.py +2 -1
- apsig-0.6.0/tests/test_draft.py +162 -0
- apsig-0.6.0/tests/test_ld.py +72 -0
- apsig-0.6.0/tests/test_multibase_ed25519.py +23 -0
- apsig-0.6.0/tests/test_proof.py +79 -0
- apsig-0.6.0/tests/test_rfc9421.py +178 -0
- apsig-0.6.0/uv.lock +1671 -0
- apsig-0.6.0/zensical.toml +323 -0
- apsig-0.5.4/.github/workflows/lint.yml +0 -67
- apsig-0.5.4/.github/workflows/test.yml +0 -34
- apsig-0.5.4/PKG-INFO +0 -52
- apsig-0.5.4/README.md +0 -18
- apsig-0.5.4/dev/e2e/faker/actor.py +0 -38
- apsig-0.5.4/dev/e2e/server_ld.py +0 -98
- apsig-0.5.4/dev/e2e/server_proof.py +0 -104
- apsig-0.5.4/docs/README.md +0 -8
- apsig-0.5.4/docs/httpsig.md +0 -2
- apsig-0.5.4/docs/ldsignature.md +0 -2
- apsig-0.5.4/docs/proof.md +0 -2
- apsig-0.5.4/pdm.lock +0 -1202
- apsig-0.5.4/src/apsig/__polyfill/datetime.py +0 -9
- apsig-0.5.4/src/apsig/exceptions.py +0 -11
- apsig-0.5.4/tests/test_draft.py +0 -161
- apsig-0.5.4/tests/test_ld.py +0 -50
- apsig-0.5.4/tests/test_multibase_ed25519.py +0 -35
- apsig-0.5.4/tests/test_proof.py +0 -93
- apsig-0.5.4/uv.lock +0 -1316
- {apsig-0.5.4 → apsig-0.6.0}/.github/workflows/publish.yml +0 -0
- {apsig-0.5.4 → apsig-0.6.0}/.gitignore +0 -0
- {apsig-0.5.4 → apsig-0.6.0}/.vscode/launch.json +0 -0
- {apsig-0.5.4 → apsig-0.6.0}/CHANGELOG.md +0 -0
- {apsig-0.5.4 → apsig-0.6.0}/COPYING.md +0 -0
- {apsig-0.5.4 → apsig-0.6.0}/LICENSE +0 -0
- {apsig-0.5.4 → apsig-0.6.0}/SECURITY.md +0 -0
- {apsig-0.5.4 → apsig-0.6.0}/cliff.toml +0 -0
- {apsig-0.5.4 → apsig-0.6.0}/renovate.json +0 -0
- {apsig-0.5.4 → apsig-0.6.0}/tests/__init__.py +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: Documentation
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- stable
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
pages: write
|
|
12
|
+
id-token: write
|
|
13
|
+
jobs:
|
|
14
|
+
deploy:
|
|
15
|
+
environment:
|
|
16
|
+
name: github-pages
|
|
17
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/configure-pages@v5
|
|
21
|
+
- uses: actions/checkout@v5
|
|
22
|
+
|
|
23
|
+
- name: Install uv
|
|
24
|
+
uses: astral-sh/setup-uv@v7
|
|
25
|
+
|
|
26
|
+
- run: uv sync --dev --locked
|
|
27
|
+
- run: uv run zensical build --clean
|
|
28
|
+
|
|
29
|
+
- uses: actions/upload-pages-artifact@v4
|
|
30
|
+
with:
|
|
31
|
+
path: site
|
|
32
|
+
|
|
33
|
+
- uses: actions/deploy-pages@v4
|
|
34
|
+
id: deployment
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
permissions:
|
|
2
|
+
contents: read
|
|
3
|
+
name: pytest
|
|
4
|
+
|
|
5
|
+
on:
|
|
6
|
+
push:
|
|
7
|
+
branches:
|
|
8
|
+
- stable
|
|
9
|
+
pull_request:
|
|
10
|
+
branches:
|
|
11
|
+
- main
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
pytest:
|
|
15
|
+
name: Run tests with pytest
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
strategy:
|
|
18
|
+
matrix:
|
|
19
|
+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
|
|
20
|
+
steps:
|
|
21
|
+
- name: Checkout
|
|
22
|
+
uses: actions/checkout@v4
|
|
23
|
+
- name: Setup uv
|
|
24
|
+
uses: astral-sh/setup-uv@v6
|
|
25
|
+
with:
|
|
26
|
+
version: ">=0.9.13,<0.10"
|
|
27
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
28
|
+
env:
|
|
29
|
+
PYTHON_VERSION: ${{ matrix.python-version }}
|
|
30
|
+
run: uv venv --python $PYTHON_VERSION
|
|
31
|
+
- name: Install Dependencies
|
|
32
|
+
run: uv sync --dev --locked
|
|
33
|
+
- name: Run Tests
|
|
34
|
+
run: uv run pytest --cov=./src/apsig --cov-branch --cov-report=xml
|
|
35
|
+
|
|
36
|
+
- name: Upload coverage reports to Codecov
|
|
37
|
+
uses: codecov/codecov-action@v5
|
|
38
|
+
with:
|
|
39
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- hooks:
|
|
3
|
+
- additional_dependencies:
|
|
4
|
+
- authlib>=1.6.0
|
|
5
|
+
- cryptography>=43.0.1
|
|
6
|
+
- git-cliff>=2.10.0
|
|
7
|
+
- http-sf>=1.0.3
|
|
8
|
+
- jcs>=0.2.1
|
|
9
|
+
- multiformats>=0.3.1.post4
|
|
10
|
+
- pyld[aiohttp,requests]>=2.0.4
|
|
11
|
+
- pytest-cov>=7.0.0
|
|
12
|
+
- pytest>=9.0.2
|
|
13
|
+
- pytz>=2025.1
|
|
14
|
+
- pyyaml>=6.0.3
|
|
15
|
+
- typing-extensions>=4.12.2
|
|
16
|
+
args:
|
|
17
|
+
- --fix
|
|
18
|
+
description: Run 'ruff' for extremely fast Python linting
|
|
19
|
+
entry: ruff check --force-exclude
|
|
20
|
+
id: ruff
|
|
21
|
+
language: python
|
|
22
|
+
minimum_pre_commit_version: 2.9.2
|
|
23
|
+
name: ruff
|
|
24
|
+
require_serial: true
|
|
25
|
+
types_or:
|
|
26
|
+
- python
|
|
27
|
+
- pyi
|
|
28
|
+
- additional_dependencies:
|
|
29
|
+
- authlib>=1.6.0
|
|
30
|
+
- cryptography>=43.0.1
|
|
31
|
+
- git-cliff>=2.10.0
|
|
32
|
+
- http-sf>=1.0.3
|
|
33
|
+
- jcs>=0.2.1
|
|
34
|
+
- multiformats>=0.3.1.post4
|
|
35
|
+
- pyld[aiohttp,requests]>=2.0.4
|
|
36
|
+
- pytest-cov>=7.0.0
|
|
37
|
+
- pytest>=9.0.2
|
|
38
|
+
- pytz>=2025.1
|
|
39
|
+
- pyyaml>=6.0.3
|
|
40
|
+
- typing-extensions>=4.12.2
|
|
41
|
+
args: []
|
|
42
|
+
description: Run 'ruff format' for extremely fast Python formatting
|
|
43
|
+
entry: ruff format --force-exclude
|
|
44
|
+
id: ruff-format
|
|
45
|
+
language: python
|
|
46
|
+
minimum_pre_commit_version: 2.9.2
|
|
47
|
+
name: ruff-format
|
|
48
|
+
require_serial: true
|
|
49
|
+
types_or:
|
|
50
|
+
- python
|
|
51
|
+
- pyi
|
|
52
|
+
repo: https://github.com/astral-sh/ruff-pre-commit
|
|
53
|
+
rev: v0.14.10
|
|
54
|
+
- hooks:
|
|
55
|
+
- additional_dependencies:
|
|
56
|
+
- authlib>=1.6.0
|
|
57
|
+
- cryptography>=43.0.1
|
|
58
|
+
- git-cliff>=2.10.0
|
|
59
|
+
- http-sf>=1.0.3
|
|
60
|
+
- jcs>=0.2.1
|
|
61
|
+
- multiformats>=0.3.1.post4
|
|
62
|
+
- pyld[aiohttp,requests]>=2.0.4
|
|
63
|
+
- pytest-cov>=7.0.0
|
|
64
|
+
- pytest>=9.0.2
|
|
65
|
+
- pytz>=2025.1
|
|
66
|
+
- pyyaml>=6.0.3
|
|
67
|
+
- typing-extensions>=4.12.2
|
|
68
|
+
id: pyrefly-check
|
|
69
|
+
name: Pyrefly (type checking)
|
|
70
|
+
pass_filenames: false
|
|
71
|
+
repo: https://github.com/facebook/pyrefly-pre-commit
|
|
72
|
+
rev: 0.46.1
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"languages": {
|
|
3
|
+
"Python": {
|
|
4
|
+
"language_servers": ["ruff", "pyrefly"]
|
|
5
|
+
}
|
|
6
|
+
},
|
|
7
|
+
"lsp": {
|
|
8
|
+
"pyrefly": {
|
|
9
|
+
"binary": {
|
|
10
|
+
"path": ".venv/bin/pyrefly",
|
|
11
|
+
"arguments": ["lsp"]
|
|
12
|
+
},
|
|
13
|
+
"settings": {
|
|
14
|
+
"python": {
|
|
15
|
+
"pythonPath": ".venv/bin/python"
|
|
16
|
+
},
|
|
17
|
+
"pyrefly": {
|
|
18
|
+
"project_includes": ["src/**/*.py", "tests/**/*.py"],
|
|
19
|
+
"project_excludes": ["**/.[!/.]*", "**/*venv/**"],
|
|
20
|
+
"search_path": ["src"],
|
|
21
|
+
"ignore_errors_in_generated_code": true
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"ruff": {
|
|
26
|
+
"initialization_options": {
|
|
27
|
+
"settings": {
|
|
28
|
+
"lineLength": 80,
|
|
29
|
+
"lint": {
|
|
30
|
+
"extendSelect": ["I"]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
apsig-0.6.0/PKG-INFO
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: apsig
|
|
3
|
+
Version: 0.6.0
|
|
4
|
+
Summary: apsig is collection of signature implemention used in ActivityPub.
|
|
5
|
+
Project-URL: Repository, https://github.com/fedi-libs/apsig
|
|
6
|
+
Project-URL: Issues, https://github.com/fedi-libs/apsig/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/fedi-libs/apsig/blob/main/CHANGELOG.md
|
|
8
|
+
Author-email: AmaseCocoa <cocoa@amase.cc>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: COPYING.md
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Natural Language :: English
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Security
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: authlib>=1.6.0
|
|
27
|
+
Requires-Dist: cryptography>=43.0.1
|
|
28
|
+
Requires-Dist: http-sf>=1.0.3
|
|
29
|
+
Requires-Dist: jcs>=0.2.1
|
|
30
|
+
Requires-Dist: multiformats>=0.3.1.post4
|
|
31
|
+
Requires-Dist: pyld[aiohttp,requests]>=2.0.4
|
|
32
|
+
Requires-Dist: pytz>=2025.1
|
|
33
|
+
Requires-Dist: typing-extensions>=4.12.2
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# apsig
|
|
37
|
+
 [](https://github.com/AmaseCocoa/apsig/actions/workflows/github-code-scanning/codeql)
|
|
38
|
+
|
|
39
|
+
apsig is collection of signature implemention used in ActivityPub.
|
|
40
|
+
|
|
41
|
+
This library implements the creation/verification of signatures for HTTP Signatures ([draft-cavage-http-signatures-12](https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures-12)), [Linked Data Signatures 1.0](https://docs.joinmastodon.org/spec/security/#ld), and Object Integrity Proofs ([FEP-8b32](https://codeberg.org/fediverse/fep/src/branch/main/fep/8b32/fep-8b32.md)).
|
|
42
|
+
|
|
43
|
+
[RFC9421](https://datatracker.ietf.org/doc/html/rfc9421) implementation is progress.
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# pip
|
|
49
|
+
pip install apsig
|
|
50
|
+
|
|
51
|
+
# uv
|
|
52
|
+
uv add apsig
|
|
53
|
+
|
|
54
|
+
# pdm
|
|
55
|
+
pdm add apsig
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Example
|
|
59
|
+
|
|
60
|
+
First, prepare the keys for signing and verification. `apsig` uses the `cryptography` library.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from cryptography.hazmat.primitives.asymmetric import rsa, ed25519
|
|
64
|
+
from cryptography.hazmat.primitives import serialization
|
|
65
|
+
|
|
66
|
+
# For HTTP Signatures (RSA)
|
|
67
|
+
private_key_rsa = rsa.generate_private_key(public_exponent=65537, key_size=3092)
|
|
68
|
+
public_key_rsa_pem = private_key_rsa.public_key().public_bytes(
|
|
69
|
+
encoding=serialization.Encoding.PEM,
|
|
70
|
+
format=serialization.PublicFormat.SubjectPublicKeyInfo,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# For Object Integrity Proofs (Ed25519)
|
|
74
|
+
private_key_ed = ed25519.Ed25519PrivateKey.generate()
|
|
75
|
+
public_key_ed = private_key_ed.public_key()
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### HTTP Signature (draft)
|
|
79
|
+
|
|
80
|
+
This is used for signing HTTP requests.
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
import email.utils
|
|
84
|
+
from apsig.draft import Signer, Verifier
|
|
85
|
+
|
|
86
|
+
# === Signing ===
|
|
87
|
+
method = "POST"
|
|
88
|
+
url = "https://example.com/api/resource"
|
|
89
|
+
headers = {
|
|
90
|
+
"Content-Type": "application/json",
|
|
91
|
+
"Date": email.utils.formatdate(usegmt=True),
|
|
92
|
+
}
|
|
93
|
+
body = '{"key": "value"}'
|
|
94
|
+
key_id = "https://example.com/users/johndoe#main-key"
|
|
95
|
+
|
|
96
|
+
signer = Signer(
|
|
97
|
+
headers=headers,
|
|
98
|
+
private_key=private_key_rsa,
|
|
99
|
+
method=method,
|
|
100
|
+
url=url,
|
|
101
|
+
key_id=key_id,
|
|
102
|
+
body=body.encode("utf-8"),
|
|
103
|
+
)
|
|
104
|
+
signed_headers = signer.sign()
|
|
105
|
+
|
|
106
|
+
print(signed_headers)
|
|
107
|
+
|
|
108
|
+
# === Verifying ===
|
|
109
|
+
verifier = Verifier(
|
|
110
|
+
public_pem=public_key_rsa_pem.decode("utf-8"),
|
|
111
|
+
method=method,
|
|
112
|
+
url=url,
|
|
113
|
+
headers=signed_headers,
|
|
114
|
+
body=body.encode("utf-8"),
|
|
115
|
+
)
|
|
116
|
+
verified_key_id = verifier.verify(raise_on_fail=True)
|
|
117
|
+
|
|
118
|
+
print(f"Verified with key: {verified_key_id}")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Object Integrity Proofs (proof)
|
|
122
|
+
|
|
123
|
+
This is used for signing JSON objects (like ActivityStreams objects).
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from apsig import ProofSigner, ProofVerifier
|
|
127
|
+
|
|
128
|
+
# === Signing ===
|
|
129
|
+
json_object = {
|
|
130
|
+
"@context": [
|
|
131
|
+
"https://www.w3.org/ns/activitystreams",
|
|
132
|
+
"https://w3id.org/security/data-integrity/v1",
|
|
133
|
+
],
|
|
134
|
+
"id": "https://server.example/objects/1",
|
|
135
|
+
"type": "Note",
|
|
136
|
+
"content": "Hello world",
|
|
137
|
+
}
|
|
138
|
+
proof_options = {
|
|
139
|
+
"type": "DataIntegrityProof",
|
|
140
|
+
"cryptosuite": "eddsa-jcs-2022",
|
|
141
|
+
"verificationMethod": "https://example.com/keys/1",
|
|
142
|
+
"created": "2024-01-01T09:00:00Z",
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
signer = ProofSigner(private_key_ed)
|
|
146
|
+
signed_object = signer.sign(json_object, proof_options)
|
|
147
|
+
|
|
148
|
+
print(signed_object)
|
|
149
|
+
|
|
150
|
+
# === Verifying ===
|
|
151
|
+
verifier = ProofVerifier(public_key_ed)
|
|
152
|
+
verified_key_id = verifier.verify(signed_object, raise_on_fail=True)
|
|
153
|
+
|
|
154
|
+
print(f"Verified with key: {verified_key_id}")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Linked Data Signature (LD-Signature)
|
|
158
|
+
|
|
159
|
+
This is another method for signing JSON-LD objects, often used in older ActivityPub implementations.
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from apsig import LDSignature
|
|
163
|
+
|
|
164
|
+
# === Signing ===
|
|
165
|
+
ld_signer = LDSignature()
|
|
166
|
+
json_ld_object = {
|
|
167
|
+
"@context": [
|
|
168
|
+
"https://www.w3.org/ns/activitystreams",
|
|
169
|
+
"https://w3id.org/security/v1",
|
|
170
|
+
],
|
|
171
|
+
"type": "Note",
|
|
172
|
+
"content": "Hello, Linked Data!",
|
|
173
|
+
}
|
|
174
|
+
creator = "https://example.com/users/johndoe#main-key"
|
|
175
|
+
|
|
176
|
+
signed_ld_object = ld_signer.sign(
|
|
177
|
+
doc=json_ld_object,
|
|
178
|
+
creator=creator,
|
|
179
|
+
private_key=private_key_rsa
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
print(signed_ld_object)
|
|
183
|
+
|
|
184
|
+
# === Verifying ===
|
|
185
|
+
# The public key can be passed directly.
|
|
186
|
+
public_key_rsa = private_key_rsa.public_key()
|
|
187
|
+
verified_creator = ld_signer.verify(
|
|
188
|
+
doc=signed_ld_object,
|
|
189
|
+
public_key=public_key_rsa,
|
|
190
|
+
raise_on_fail=True
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
print(f"Verified with creator: {verified_creator}")
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Documents
|
|
197
|
+
The document can be viewed [here](https://fedi-libs.github.io/apsig/).
|
|
198
|
+
|
|
199
|
+
## Thanks
|
|
200
|
+
- [Hong Minhee](https://github.com/dahlia) ([Fedify](https://fedify.dev/) Author)
|
|
201
|
+
- [Takahē](https://github.com/jointakahe/takahe) Authors (apsig.LDSignature was ported from Takahē)
|
|
202
|
+
- And All Contributor/Users
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
MIT License
|
apsig-0.6.0/README.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# apsig
|
|
2
|
+
 [](https://github.com/AmaseCocoa/apsig/actions/workflows/github-code-scanning/codeql)
|
|
3
|
+
|
|
4
|
+
apsig is collection of signature implemention used in ActivityPub.
|
|
5
|
+
|
|
6
|
+
This library implements the creation/verification of signatures for HTTP Signatures ([draft-cavage-http-signatures-12](https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures-12)), [Linked Data Signatures 1.0](https://docs.joinmastodon.org/spec/security/#ld), and Object Integrity Proofs ([FEP-8b32](https://codeberg.org/fediverse/fep/src/branch/main/fep/8b32/fep-8b32.md)).
|
|
7
|
+
|
|
8
|
+
[RFC9421](https://datatracker.ietf.org/doc/html/rfc9421) implementation is progress.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
# pip
|
|
14
|
+
pip install apsig
|
|
15
|
+
|
|
16
|
+
# uv
|
|
17
|
+
uv add apsig
|
|
18
|
+
|
|
19
|
+
# pdm
|
|
20
|
+
pdm add apsig
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Example
|
|
24
|
+
|
|
25
|
+
First, prepare the keys for signing and verification. `apsig` uses the `cryptography` library.
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from cryptography.hazmat.primitives.asymmetric import rsa, ed25519
|
|
29
|
+
from cryptography.hazmat.primitives import serialization
|
|
30
|
+
|
|
31
|
+
# For HTTP Signatures (RSA)
|
|
32
|
+
private_key_rsa = rsa.generate_private_key(public_exponent=65537, key_size=3092)
|
|
33
|
+
public_key_rsa_pem = private_key_rsa.public_key().public_bytes(
|
|
34
|
+
encoding=serialization.Encoding.PEM,
|
|
35
|
+
format=serialization.PublicFormat.SubjectPublicKeyInfo,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
# For Object Integrity Proofs (Ed25519)
|
|
39
|
+
private_key_ed = ed25519.Ed25519PrivateKey.generate()
|
|
40
|
+
public_key_ed = private_key_ed.public_key()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### HTTP Signature (draft)
|
|
44
|
+
|
|
45
|
+
This is used for signing HTTP requests.
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import email.utils
|
|
49
|
+
from apsig.draft import Signer, Verifier
|
|
50
|
+
|
|
51
|
+
# === Signing ===
|
|
52
|
+
method = "POST"
|
|
53
|
+
url = "https://example.com/api/resource"
|
|
54
|
+
headers = {
|
|
55
|
+
"Content-Type": "application/json",
|
|
56
|
+
"Date": email.utils.formatdate(usegmt=True),
|
|
57
|
+
}
|
|
58
|
+
body = '{"key": "value"}'
|
|
59
|
+
key_id = "https://example.com/users/johndoe#main-key"
|
|
60
|
+
|
|
61
|
+
signer = Signer(
|
|
62
|
+
headers=headers,
|
|
63
|
+
private_key=private_key_rsa,
|
|
64
|
+
method=method,
|
|
65
|
+
url=url,
|
|
66
|
+
key_id=key_id,
|
|
67
|
+
body=body.encode("utf-8"),
|
|
68
|
+
)
|
|
69
|
+
signed_headers = signer.sign()
|
|
70
|
+
|
|
71
|
+
print(signed_headers)
|
|
72
|
+
|
|
73
|
+
# === Verifying ===
|
|
74
|
+
verifier = Verifier(
|
|
75
|
+
public_pem=public_key_rsa_pem.decode("utf-8"),
|
|
76
|
+
method=method,
|
|
77
|
+
url=url,
|
|
78
|
+
headers=signed_headers,
|
|
79
|
+
body=body.encode("utf-8"),
|
|
80
|
+
)
|
|
81
|
+
verified_key_id = verifier.verify(raise_on_fail=True)
|
|
82
|
+
|
|
83
|
+
print(f"Verified with key: {verified_key_id}")
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Object Integrity Proofs (proof)
|
|
87
|
+
|
|
88
|
+
This is used for signing JSON objects (like ActivityStreams objects).
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from apsig import ProofSigner, ProofVerifier
|
|
92
|
+
|
|
93
|
+
# === Signing ===
|
|
94
|
+
json_object = {
|
|
95
|
+
"@context": [
|
|
96
|
+
"https://www.w3.org/ns/activitystreams",
|
|
97
|
+
"https://w3id.org/security/data-integrity/v1",
|
|
98
|
+
],
|
|
99
|
+
"id": "https://server.example/objects/1",
|
|
100
|
+
"type": "Note",
|
|
101
|
+
"content": "Hello world",
|
|
102
|
+
}
|
|
103
|
+
proof_options = {
|
|
104
|
+
"type": "DataIntegrityProof",
|
|
105
|
+
"cryptosuite": "eddsa-jcs-2022",
|
|
106
|
+
"verificationMethod": "https://example.com/keys/1",
|
|
107
|
+
"created": "2024-01-01T09:00:00Z",
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
signer = ProofSigner(private_key_ed)
|
|
111
|
+
signed_object = signer.sign(json_object, proof_options)
|
|
112
|
+
|
|
113
|
+
print(signed_object)
|
|
114
|
+
|
|
115
|
+
# === Verifying ===
|
|
116
|
+
verifier = ProofVerifier(public_key_ed)
|
|
117
|
+
verified_key_id = verifier.verify(signed_object, raise_on_fail=True)
|
|
118
|
+
|
|
119
|
+
print(f"Verified with key: {verified_key_id}")
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Linked Data Signature (LD-Signature)
|
|
123
|
+
|
|
124
|
+
This is another method for signing JSON-LD objects, often used in older ActivityPub implementations.
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from apsig import LDSignature
|
|
128
|
+
|
|
129
|
+
# === Signing ===
|
|
130
|
+
ld_signer = LDSignature()
|
|
131
|
+
json_ld_object = {
|
|
132
|
+
"@context": [
|
|
133
|
+
"https://www.w3.org/ns/activitystreams",
|
|
134
|
+
"https://w3id.org/security/v1",
|
|
135
|
+
],
|
|
136
|
+
"type": "Note",
|
|
137
|
+
"content": "Hello, Linked Data!",
|
|
138
|
+
}
|
|
139
|
+
creator = "https://example.com/users/johndoe#main-key"
|
|
140
|
+
|
|
141
|
+
signed_ld_object = ld_signer.sign(
|
|
142
|
+
doc=json_ld_object,
|
|
143
|
+
creator=creator,
|
|
144
|
+
private_key=private_key_rsa
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
print(signed_ld_object)
|
|
148
|
+
|
|
149
|
+
# === Verifying ===
|
|
150
|
+
# The public key can be passed directly.
|
|
151
|
+
public_key_rsa = private_key_rsa.public_key()
|
|
152
|
+
verified_creator = ld_signer.verify(
|
|
153
|
+
doc=signed_ld_object,
|
|
154
|
+
public_key=public_key_rsa,
|
|
155
|
+
raise_on_fail=True
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
print(f"Verified with creator: {verified_creator}")
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Documents
|
|
162
|
+
The document can be viewed [here](https://fedi-libs.github.io/apsig/).
|
|
163
|
+
|
|
164
|
+
## Thanks
|
|
165
|
+
- [Hong Minhee](https://github.com/dahlia) ([Fedify](https://fedify.dev/) Author)
|
|
166
|
+
- [Takahē](https://github.com/jointakahe/takahe) Authors (apsig.LDSignature was ported from Takahē)
|
|
167
|
+
- And All Contributor/Users
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
MIT License
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
icon: lucide/file
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Compatibility Report
|
|
6
|
+
|
|
7
|
+
This report summarizes the degree of compatibility between apsig and various ActivityPub implementations and HTTP Signatures implementations.
|
|
8
|
+
|
|
9
|
+
# 1. Overview
|
|
10
|
+
!!! note
|
|
11
|
+
RFC9421 implementation is in progress, not merged to main code.
|
|
12
|
+
|
|
13
|
+
apsig tested in following implementations:
|
|
14
|
+
|
|
15
|
+
| Implementation | draft-cavage-http-signatures-12 | Linked Data Signatures 1.0 | FEP-8b32 | RFC9421 | Notes |
|
|
16
|
+
| -------------- | ------------------------------- | -------------------------- | -------- | ------- | ------------------------------------------------- |
|
|
17
|
+
| Mastodon | ✔ | - | - | - | FEP-8b32 is not implemented. |
|
|
18
|
+
| Misskey | ✔ | - | - | - | FEP-8b32 is not implemented. |
|
|
19
|
+
| Fedify | ✔ | ✔ | ✔ | × | apsig's implementation is tested in fedify first. |
|
|
20
|
+
|
|
21
|
+
- `✔`: working correctly
|
|
22
|
+
- `×`: not working
|
|
23
|
+
- `-`: not tested
|