Ignore padding for salmon public keys.
This commit is contained in:
parent
67bfa19b35
commit
fecbd099cd
3 changed files with 14 additions and 1 deletions
|
@ -60,7 +60,7 @@ defmodule Pleroma.Web.Salmon do
|
||||||
|
|
||||||
[modulus, exponent] = magickey
|
[modulus, exponent] = magickey
|
||||||
|> String.split(".")
|
|> String.split(".")
|
||||||
|> Enum.map(&Base.url_decode64!/1)
|
|> Enum.map(fn (n) -> Base.url_decode64!(n, padding: false) end)
|
||||||
|> Enum.map(make_integer)
|
|> Enum.map(make_integer)
|
||||||
|
|
||||||
{:RSAPublicKey, modulus, exponent}
|
{:RSAPublicKey, modulus, exponent}
|
||||||
|
|
7
test/fixtures/friendica_salmon.xml
vendored
Normal file
7
test/fixtures/friendica_salmon.xml
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<me:env xmlns:me="http://salmon-protocol.org/ns/magic-env">
|
||||||
|
<me:data type="application/atom+xml">PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPGVudHJ5IHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDA1L0F0b20iIHhtbG5zOnRocj0iaHR0cDovL3B1cmwub3JnL3N5bmRpY2F0aW9uL3RocmVhZC8xLjAiIHhtbG5zOmdlb3Jzcz0iaHR0cDovL3d3dy5nZW9yc3Mub3JnL2dlb3JzcyIgeG1sbnM6YWN0aXZpdHk9Imh0dHA6Ly9hY3Rpdml0eXN0cmVhLm1zL3NwZWMvMS4wLyIgeG1sbnM6bWVkaWE9Imh0dHA6Ly9wdXJsLm9yZy9zeW5kaWNhdGlvbi9hdG9tbWVkaWEiIHhtbG5zOnBvY289Imh0dHA6Ly9wb3J0YWJsZWNvbnRhY3RzLm5ldC9zcGVjLzEuMCIgeG1sbnM6b3N0YXR1cz0iaHR0cDovL29zdGF0dXMub3JnL3NjaGVtYS8xLjAiIHhtbG5zOnN0YXR1c25ldD0iaHR0cDovL3N0YXR1cy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xlPmxhaW48L3RpdGxlPgogICAgPGxpbmsgcmVsPSJhbHRlcm5hdGUiIHR5cGU9InRleHQvaHRtbCIgaHJlZj0iaHR0cHM6Ly9wbGVyb21hLnNveWthZi5jb20vdXNlcnMvbGFpbiIvPgogICAgPGxpbmsgcmVsPSJhdmF0YXIiIHR5cGU9ImltYWdlL2pwZWciIG1lZGlhOndpZHRoPSIxNzUiIG1lZGlhOmhlaWdodD0iMTc1IiBocmVmPSJodHRwczovL3BsZXJvbWEuc295a2FmLmNvbS9tZWRpYS82NTE5YzhmOS1iMmFkLTQ5YjAtOTZlOC1lMjg4NWUxNjNmNTQvNERBMzUwNkVBMTBBRTc0QTZDREU2MTI3NzgxOEE0RTg4RkVDNjY1QTk4NEU4Njc4OUM0NDBDOEJCRERDNEI1OS5naWYiLz4KICAgIDxwb2NvOnByZWZlcnJlZFVzZXJuYW1lPmxhaW48L3BvY286cHJlZmVycmVkVXNlcm5hbWU-CiAgICA8cG9jbzpkaXNwbGF5TmFtZT5MYWluIEl3YWt1cmE8L3BvY286ZGlzcGxheU5hbWU-CiAgPC9hY3Rpdml0eTpvYmplY3Q-CjwvZW50cnk-</me:data>
|
||||||
|
<me:encoding>base64url</me:encoding>
|
||||||
|
<me:alg>RSA-SHA256</me:alg>
|
||||||
|
<me:sig key_id="MTU1ODkzNjliMGE4MzQ5NmEwMjkyMGJiNjUwMTg1ODZkMTdjOWQ0MWVhZTBmOGM3ZTYwNzU5Y2I1NWU1OTZjMw">l5O0lORlg5chdRQZkb-1GiEPU6OLY6FI-IBP84FwbOKY_hjy9on_VBxXcvcLN5r32VDbma0Ra4r933wQuATu1Q==</me:sig>
|
||||||
|
</me:env>
|
|
@ -8,6 +8,8 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
|
||||||
|
|
||||||
@wrong_magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAA"
|
@wrong_magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAA"
|
||||||
|
|
||||||
|
@magickey_friendica "RSA.AMwa8FUs2fWEjX0xN7yRQgegQffhBpuKNC6fa5VNSVorFjGZhRrlPMn7TQOeihlc9lBz2OsHlIedbYn2uJ7yCs0.AQAB"
|
||||||
|
|
||||||
test "decodes a salmon" do
|
test "decodes a salmon" do
|
||||||
{:ok, salmon} = File.read("test/fixtures/salmon.xml")
|
{:ok, salmon} = File.read("test/fixtures/salmon.xml")
|
||||||
{:ok, doc} = Salmon.decode_and_validate(@magickey, salmon)
|
{:ok, doc} = Salmon.decode_and_validate(@magickey, salmon)
|
||||||
|
@ -32,6 +34,10 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
|
||||||
assert @magickey == magic_key
|
assert @magickey == magic_key
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it decodes a friendica public key" do
|
||||||
|
key = Salmon.decode_key(@magickey_friendica)
|
||||||
|
end
|
||||||
|
|
||||||
test "returns a public and private key from a pem" do
|
test "returns a public and private key from a pem" do
|
||||||
pem = File.read!("test/fixtures/private_key.pem")
|
pem = File.read!("test/fixtures/private_key.pem")
|
||||||
{:ok, private, public} = Salmon.keys_from_pem(pem)
|
{:ok, private, public} = Salmon.keys_from_pem(pem)
|
||||||
|
|
Loading…
Reference in a new issue