mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 03:16:55 -08:00
activitypub - signature testing
This commit is contained in:
parent
a9bfe2f391
commit
29c7720985
14 changed files with 234 additions and 0 deletions
|
@ -185,5 +185,6 @@ def find_actor_or_create(actor):
|
|||
user = User.query.filter_by(ap_profile_id=actor).first() # finds users formatted like https://kbin.social/u/tables
|
||||
if user is None:
|
||||
# todo: retrieve user details via webfinger, etc
|
||||
...
|
||||
else:
|
||||
return user
|
||||
|
|
39
test_signature.py
Normal file
39
test_signature.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
from app.activitypub.signature import HttpSignature
|
||||
|
||||
def file_get_contents(filename):
|
||||
with open(filename, 'r') as file:
|
||||
contents = file.read()
|
||||
return contents
|
||||
|
||||
body_1 = file_get_contents('testing_data/body_1.json')
|
||||
body_2 = file_get_contents('testing_data/body_2.json')
|
||||
body_3 = file_get_contents('testing_data/body_3.json')
|
||||
digest_1 = file_get_contents('testing_data/digest_1')
|
||||
digest_2 = file_get_contents('testing_data/digest_2')
|
||||
digest_3 = file_get_contents('testing_data/digest_3')
|
||||
signature_1 = file_get_contents('testing_data/signature_1')
|
||||
signature_2 = file_get_contents('testing_data/signature_2')
|
||||
signature_3 = file_get_contents('testing_data/signature_3')
|
||||
|
||||
assert digest_1 == HttpSignature.calculate_digest(body_1.encode())
|
||||
assert digest_2 == HttpSignature.calculate_digest(body_2.encode())
|
||||
assert digest_3 == HttpSignature.calculate_digest(body_3.encode())
|
||||
|
||||
parsed = HttpSignature.parse_signature(signature_1)
|
||||
original_signature = sorted(signature_1.split(','))
|
||||
processed_signature = sorted(HttpSignature.compile_signature(parsed).split(','))
|
||||
assert original_signature == processed_signature
|
||||
|
||||
parsed = HttpSignature.parse_signature(signature_2)
|
||||
original_signature = sorted(signature_2.split(','))
|
||||
processed_signature = sorted(HttpSignature.compile_signature(parsed).split(','))
|
||||
assert original_signature == processed_signature
|
||||
|
||||
parsed = HttpSignature.parse_signature(signature_3)
|
||||
original_signature = sorted(signature_3.split(','))
|
||||
processed_signature = sorted(HttpSignature.compile_signature(parsed).split(','))
|
||||
assert original_signature == processed_signature
|
||||
|
||||
|
||||
|
||||
print('Done')
|
1
testing_data/body_1.json
Normal file
1
testing_data/body_1.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"lemmy":"https://join-lemmy.org/ns#","litepub":"http://litepub.social/ns#","pt":"https://joinpeertube.org/ns#","sc":"http://schema.org/","ChatMessage":"litepub:ChatMessage","commentsEnabled":"pt:commentsEnabled","sensitive":"as:sensitive","matrixUserId":"lemmy:matrixUserId","postingRestrictedToMods":"lemmy:postingRestrictedToMods","removeData":"lemmy:removeData","stickied":"lemmy:stickied","moderators":{"@type":"@id","@id":"lemmy:moderators"},"expires":"as:endTime","distinguished":"lemmy:distinguished","language":"sc:inLanguage","identifier":"sc:identifier"}],"actor":"https://lemmy.ml/c/memes","to":["https://www.w3.org/ns/activitystreams#Public"],"object":{"id":"https://lemmy.blahaj.zone/activities/like/41bed132-3cb9-4571-bdb8-a8c42782b461","actor":"https://lemmy.blahaj.zone/u/RenegadeRangerX","@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"lemmy":"https://join-lemmy.org/ns#","litepub":"http://litepub.social/ns#","pt":"https://joinpeertube.org/ns#","sc":"http://schema.org/","ChatMessage":"litepub:ChatMessage","commentsEnabled":"pt:commentsEnabled","sensitive":"as:sensitive","matrixUserId":"lemmy:matrixUserId","postingRestrictedToMods":"lemmy:postingRestrictedToMods","removeData":"lemmy:removeData","stickied":"lemmy:stickied","moderators":{"@type":"@id","@id":"lemmy:moderators"},"expires":"as:endTime","distinguished":"lemmy:distinguished","language":"sc:inLanguage","identifier":"sc:identifier"}],"object":"https://kbin.social/m/memes@lemmy.ml/t/371636/-/comment/1843783","type":"Like","audience":"https://lemmy.ml/c/memes"},"cc":["https://lemmy.ml/c/memes/followers"],"type":"Announce","id":"https://lemmy.ml/activities/announce/7530ce36-2d23-442d-a2b5-211f615f63ba"}
|
68
testing_data/body_1_formatted.json
Normal file
68
testing_data/body_1_formatted.json
Normal file
|
@ -0,0 +1,68 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"lemmy": "https://join-lemmy.org/ns#",
|
||||
"litepub": "http://litepub.social/ns#",
|
||||
"pt": "https://joinpeertube.org/ns#",
|
||||
"sc": "http://schema.org/",
|
||||
"ChatMessage": "litepub:ChatMessage",
|
||||
"commentsEnabled": "pt:commentsEnabled",
|
||||
"sensitive": "as:sensitive",
|
||||
"matrixUserId": "lemmy:matrixUserId",
|
||||
"postingRestrictedToMods": "lemmy:postingRestrictedToMods",
|
||||
"removeData": "lemmy:removeData",
|
||||
"stickied": "lemmy:stickied",
|
||||
"moderators": {
|
||||
"@type": "@id",
|
||||
"@id": "lemmy:moderators"
|
||||
},
|
||||
"expires": "as:endTime",
|
||||
"distinguished": "lemmy:distinguished",
|
||||
"language": "sc:inLanguage",
|
||||
"identifier": "sc:identifier"
|
||||
}
|
||||
],
|
||||
"actor": "https://lemmy.ml/c/memes",
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"object": {
|
||||
"id": "https://lemmy.blahaj.zone/activities/like/41bed132-3cb9-4571-bdb8-a8c42782b461",
|
||||
"actor": "https://lemmy.blahaj.zone/u/RenegadeRangerX",
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"lemmy": "https://join-lemmy.org/ns#",
|
||||
"litepub": "http://litepub.social/ns#",
|
||||
"pt": "https://joinpeertube.org/ns#",
|
||||
"sc": "http://schema.org/",
|
||||
"ChatMessage": "litepub:ChatMessage",
|
||||
"commentsEnabled": "pt:commentsEnabled",
|
||||
"sensitive": "as:sensitive",
|
||||
"matrixUserId": "lemmy:matrixUserId",
|
||||
"postingRestrictedToMods": "lemmy:postingRestrictedToMods",
|
||||
"removeData": "lemmy:removeData",
|
||||
"stickied": "lemmy:stickied",
|
||||
"moderators": {
|
||||
"@type": "@id",
|
||||
"@id": "lemmy:moderators"
|
||||
},
|
||||
"expires": "as:endTime",
|
||||
"distinguished": "lemmy:distinguished",
|
||||
"language": "sc:inLanguage",
|
||||
"identifier": "sc:identifier"
|
||||
}
|
||||
],
|
||||
"object": "https://kbin.social/m/memes@lemmy.ml/t/371636/-/comment/1843783",
|
||||
"type": "Like",
|
||||
"audience": "https://lemmy.ml/c/memes"
|
||||
},
|
||||
"cc": [
|
||||
"https://lemmy.ml/c/memes/followers"
|
||||
],
|
||||
"type": "Announce",
|
||||
"id": "https://lemmy.ml/activities/announce/7530ce36-2d23-442d-a2b5-211f615f63ba"
|
||||
}
|
1
testing_data/body_2.json
Normal file
1
testing_data/body_2.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"@context":"https:\/\/www.w3.org\/ns\/activitystreams","id":"https:\/\/kbin.social\/f\/object\/503928e8-0474-45bf-84f1-c56b7c838970","type":"Like","actor":"https:\/\/kbin.social\/u\/Infiltrated_ad8271","object":"https:\/\/lemmy.world\/comment\/2742626"}
|
7
testing_data/body_2_formatted.json
Normal file
7
testing_data/body_2_formatted.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"@context": "https:\/\/www.w3.org\/ns\/activitystreams",
|
||||
"id": "https:\/\/kbin.social\/f\/object\/503928e8-0474-45bf-84f1-c56b7c838970",
|
||||
"type": "Like",
|
||||
"actor": "https:\/\/kbin.social\/u\/Infiltrated_ad8271",
|
||||
"object": "https:\/\/lemmy.world\/comment\/2742626"
|
||||
}
|
1
testing_data/body_3.json
Normal file
1
testing_data/body_3.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"lemmy":"https://join-lemmy.org/ns#","litepub":"http://litepub.social/ns#","pt":"https://joinpeertube.org/ns#","sc":"http://schema.org/","ChatMessage":"litepub:ChatMessage","commentsEnabled":"pt:commentsEnabled","sensitive":"as:sensitive","matrixUserId":"lemmy:matrixUserId","postingRestrictedToMods":"lemmy:postingRestrictedToMods","removeData":"lemmy:removeData","stickied":"lemmy:stickied","moderators":{"@type":"@id","@id":"lemmy:moderators"},"expires":"as:endTime","distinguished":"lemmy:distinguished","language":"sc:inLanguage","identifier":"sc:identifier"}],"actor":"https://lemmy.ml/c/asklemmy","to":["https://www.w3.org/ns/activitystreams#Public"],"object":{"id":"https://lemmy.world/activities/create/c22cc7ca-f1fc-4bf4-b591-4a3313430fc0","actor":"https://lemmy.world/u/Mojave","@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"lemmy":"https://join-lemmy.org/ns#","litepub":"http://litepub.social/ns#","pt":"https://joinpeertube.org/ns#","sc":"http://schema.org/","ChatMessage":"litepub:ChatMessage","commentsEnabled":"pt:commentsEnabled","sensitive":"as:sensitive","matrixUserId":"lemmy:matrixUserId","postingRestrictedToMods":"lemmy:postingRestrictedToMods","removeData":"lemmy:removeData","stickied":"lemmy:stickied","moderators":{"@type":"@id","@id":"lemmy:moderators"},"expires":"as:endTime","distinguished":"lemmy:distinguished","language":"sc:inLanguage","identifier":"sc:identifier"}],"to":["https://www.w3.org/ns/activitystreams#Public"],"object":{"type":"Note","id":"https://lemmy.world/comment/2744248","attributedTo":"https://lemmy.world/u/Mojave","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://lemmy.ml/c/asklemmy","https://lemm.ee/u/handsatinizer"],"content":"<p>No, I’m mentally stable</p>\n","inReplyTo":"https://lemm.ee/post/5204840","mediaType":"text/html","source":{"content":"No, I'm mentally stable","mediaType":"text/markdown"},"published":"2023-08-24T06:45:08.987710+00:00","tag":[{"href":"https://lemm.ee/u/handsatinizer","name":"@handsatinizer@lemm.ee","type":"Mention"}],"distinguished":false,"audience":"https://lemmy.ml/c/asklemmy"},"cc":["https://lemmy.ml/c/asklemmy","https://lemm.ee/u/handsatinizer"],"tag":[{"href":"https://lemm.ee/u/handsatinizer","name":"@handsatinizer@lemm.ee","type":"Mention"}],"type":"Create","audience":"https://lemmy.ml/c/asklemmy"},"cc":["https://lemmy.ml/c/asklemmy/followers"],"type":"Announce","id":"https://lemmy.ml/activities/announce/187b8b67-611f-43fb-b256-09090e29cff5"}
|
110
testing_data/body_3_formatted.json
Normal file
110
testing_data/body_3_formatted.json
Normal file
|
@ -0,0 +1,110 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"lemmy": "https://join-lemmy.org/ns#",
|
||||
"litepub": "http://litepub.social/ns#",
|
||||
"pt": "https://joinpeertube.org/ns#",
|
||||
"sc": "http://schema.org/",
|
||||
"ChatMessage": "litepub:ChatMessage",
|
||||
"commentsEnabled": "pt:commentsEnabled",
|
||||
"sensitive": "as:sensitive",
|
||||
"matrixUserId": "lemmy:matrixUserId",
|
||||
"postingRestrictedToMods": "lemmy:postingRestrictedToMods",
|
||||
"removeData": "lemmy:removeData",
|
||||
"stickied": "lemmy:stickied",
|
||||
"moderators": {
|
||||
"@type": "@id",
|
||||
"@id": "lemmy:moderators"
|
||||
},
|
||||
"expires": "as:endTime",
|
||||
"distinguished": "lemmy:distinguished",
|
||||
"language": "sc:inLanguage",
|
||||
"identifier": "sc:identifier"
|
||||
}
|
||||
],
|
||||
"actor": "https://lemmy.ml/c/asklemmy",
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"object": {
|
||||
"id": "https://lemmy.world/activities/create/c22cc7ca-f1fc-4bf4-b591-4a3313430fc0",
|
||||
"actor": "https://lemmy.world/u/Mojave",
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"lemmy": "https://join-lemmy.org/ns#",
|
||||
"litepub": "http://litepub.social/ns#",
|
||||
"pt": "https://joinpeertube.org/ns#",
|
||||
"sc": "http://schema.org/",
|
||||
"ChatMessage": "litepub:ChatMessage",
|
||||
"commentsEnabled": "pt:commentsEnabled",
|
||||
"sensitive": "as:sensitive",
|
||||
"matrixUserId": "lemmy:matrixUserId",
|
||||
"postingRestrictedToMods": "lemmy:postingRestrictedToMods",
|
||||
"removeData": "lemmy:removeData",
|
||||
"stickied": "lemmy:stickied",
|
||||
"moderators": {
|
||||
"@type": "@id",
|
||||
"@id": "lemmy:moderators"
|
||||
},
|
||||
"expires": "as:endTime",
|
||||
"distinguished": "lemmy:distinguished",
|
||||
"language": "sc:inLanguage",
|
||||
"identifier": "sc:identifier"
|
||||
}
|
||||
],
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"object": {
|
||||
"type": "Note",
|
||||
"id": "https://lemmy.world/comment/2744248",
|
||||
"attributedTo": "https://lemmy.world/u/Mojave",
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"cc": [
|
||||
"https://lemmy.ml/c/asklemmy",
|
||||
"https://lemm.ee/u/handsatinizer"
|
||||
],
|
||||
"content": "<p>No, I’m mentally stable</p>\n",
|
||||
"inReplyTo": "https://lemm.ee/post/5204840",
|
||||
"mediaType": "text/html",
|
||||
"source": {
|
||||
"content": "No, I'm mentally stable",
|
||||
"mediaType": "text/markdown"
|
||||
},
|
||||
"published": "2023-08-24T06:45:08.987710+00:00",
|
||||
"tag": [
|
||||
{
|
||||
"href": "https://lemm.ee/u/handsatinizer",
|
||||
"name": "@handsatinizer@lemm.ee",
|
||||
"type": "Mention"
|
||||
}
|
||||
],
|
||||
"distinguished": false,
|
||||
"audience": "https://lemmy.ml/c/asklemmy"
|
||||
},
|
||||
"cc": [
|
||||
"https://lemmy.ml/c/asklemmy",
|
||||
"https://lemm.ee/u/handsatinizer"
|
||||
],
|
||||
"tag": [
|
||||
{
|
||||
"href": "https://lemm.ee/u/handsatinizer",
|
||||
"name": "@handsatinizer@lemm.ee",
|
||||
"type": "Mention"
|
||||
}
|
||||
],
|
||||
"type": "Create",
|
||||
"audience": "https://lemmy.ml/c/asklemmy"
|
||||
},
|
||||
"cc": [
|
||||
"https://lemmy.ml/c/asklemmy/followers"
|
||||
],
|
||||
"type": "Announce",
|
||||
"id": "https://lemmy.ml/activities/announce/187b8b67-611f-43fb-b256-09090e29cff5"
|
||||
}
|
1
testing_data/digest_1
Normal file
1
testing_data/digest_1
Normal file
|
@ -0,0 +1 @@
|
|||
SHA-256=UAcIS2MuGuDJg5kc/vz64rs6p8T+NAWFONxNDoXUmmc=
|
1
testing_data/digest_2
Normal file
1
testing_data/digest_2
Normal file
|
@ -0,0 +1 @@
|
|||
SHA-256=Pa8VfLnz1+Nf53IDe1UccNsCeBhaJ1EHYxOXyObXXqM=
|
1
testing_data/digest_3
Normal file
1
testing_data/digest_3
Normal file
|
@ -0,0 +1 @@
|
|||
SHA-256=FiqS8ZvoDZlukuYpgmGwhAtl2o0PiQKBXDQLXZXJdLg=
|
1
testing_data/signature_1
Normal file
1
testing_data/signature_1
Normal file
|
@ -0,0 +1 @@
|
|||
keyId="https://lemmy.ml/c/memes#main-key",algorithm="hs2019",headers="(request-target) content-type date digest host",signature="q7zG1Nqc5S5K0boiPjs5IKbOSNsOad0EGL6AMd3F2BQ7AVY881SCVH4zbsker16L55g6W26OWE6vWMaMUXZWFAlY1kY2bCSI+/x81jqSC8DPoXPnX0zVhro+iOkGtB4yphVJBtTqO/HIxgvL4LI7Zgcpfb4VuunsUYChYDRjO+Tu2fFBnfg5JbUgn1kWq/y6OHHqEGoj0zmD5unBPa96v8T2AcKfLDju3ySufySsKF+RBfrTLzjHHEN9uFlZ31nlkj0AYhH/zEXFdhtpOubsl6o2bE0zbq7Ty2+q67LCRJmKF8iO0ZVUDAbOsoiAT3P5p50tv4W/hzfMd4a088GLoQ=="
|
1
testing_data/signature_2
Normal file
1
testing_data/signature_2
Normal file
|
@ -0,0 +1 @@
|
|||
keyId="https://kbin.social/u/Infiltrated_ad8271#main-key",headers="(request-target) date host digest",algorithm="rsa-sha256",signature="e5zneRjEQVQyQhnXqDr6gG+uvM6slbGfbS5XBxkyIXiJhbP3zJYf6OREqyuFW+kUqVhShLWalFTu9/LfIWBOuy+RnG9baogCTSE2eB5VN3PeI8p7CegtshcvGFPpWIEaBaoTmL1C7IU1DSm2CBG9AHuFyQlQURFpbrUImbrD54flQgYPzA3gJnspTSJVzh5s3IBr0cS9ns3VnVrvfn7ti+Gf07xYHH4Z7q7/plJ0vb9CHj9JHJGffATzzaILiB4i2MYcwr+l1WJFtN5hn3eGWB7oXgG9mWC0mZ7q/qoxXB2fTj/Tr98kCwQ+kuz630obh44cGb8Uq4PElB2efeb1Sa37eU/1Hd3KU1AYLQn/SLAYMT2ip37LO1oPGdpwwSIewXlgBjSZgIEftiCayGSqh7MJsoYtxppbQMfLZkpu35/7hl08QftllFI7rHQlil5y4xewSQ1BiN+9t08OCOm7nbKht8NILifkrUCeczTEzkUG7BqVTgHbceMA65y79lK3JDICB+n2bPU++ExnF7SVqTHtSJWA0gBe+O/KgfAb0YqMK5mUIYT82QtA8IF4ueDYiH5pmPxPDXa+RtuXcwiJ8Y5rEWKD4BI0HAe17PyVo+2Cn6FGmy6GAnBXVH2wOGDWtjqOnCp8UBZWb+A0j/CA1Xw0grnFDa7RNY70xtQvwCk="
|
1
testing_data/signature_3
Normal file
1
testing_data/signature_3
Normal file
|
@ -0,0 +1 @@
|
|||
keyId="https://lemmy.ml/c/asklemmy#main-key",algorithm="hs2019",headers="(request-target) content-type date digest host",signature="m4Y7PkL8RsGZ8iRXuaiu4skxEPz37zaFqh9rF10RZCwzDqvy3gxLnbN0l/s1swePMkEG+ZeCCmr3+kGlI3dEke2TmY3GDzUCnibVVXLwrwUiymLIyrZsIZSYFW4y+vs/wmYL7unWLe3Z1YCxaWbMb+APaDAKUv03fc9s4wTq40G99xxVRZB+IY1cuGC2yCulAQSRJwgqQ2KiFTV6B7CoCwWMCNH4JwNNJaZd1Y3a0wEYd5yRAjXTWPVi0oa9AnLBZRQpTbG0k/lkXjJ3/6MDYvLRlVGZ61iT5cJZjwrix4XJllqF0248eEQFnYMTPplgvjrUPlv3fvLY0qO5AQKkuw=="
|
Loading…
Reference in a new issue