kennyp / fernetex Goto Github PK
View Code? Open in Web Editor NEWImplementation of https://github.com/fernet/spec for Elixir
License: MIT License
Implementation of https://github.com/fernet/spec for Elixir
License: MIT License
Here’s the issue..
iex(1)> secret = "fJXYWeIEcXMO3tLDheFVezM5QWBVFvkymG80n0Rluqs="
"fJXYWeIEcXMO3tLDheFVezM5QWBVFvkymG80n0Rluqs="
iex(2)> s = "abc"
"abc"
iex(3)> {:ok, _iv, t} = Fernet.generate(s, key: secret)
{:ok,
<<171, 20, 174, 159, 83, 157, 204, 91, 237, 149, 121, 205, 255, 101, 152, 241>>,
"gAAAAABbMo1mqxSun1OdzFvtlXnN_2WY8TlATVJvCKC6oPuO_kzHnLSC3YN6uj0b-a0DBzBQYfWmaxdUb28p3-RyFOLV8gBwPQ=="}
iex(4)> t
"gAAAAABbMo1mqxSun1OdzFvtlXnN_2WY8TlATVJvCKC6oPuO_kzHnLSC3YN6uj0b-a0DBzBQYfWmaxdUb28p3-RyFOLV8gBwPQ=="
iex(5)> Fernet.verify(t, key: secret)
{:ok, "abc"}
iex(6)> s = String.pad_trailing("hello", 32)
"hello "
iex(7)> {:ok, _iv, t} = Fernet.generate(s, key: secret)
{:ok,
<<4, 195, 63, 250, 139, 163, 64, 222, 249, 190, 47, 118, 19, 79, 199, 13>>,
"gAAAAABbMo2BBMM_-oujQN75vi92E0_HDf-TWTLLZYX6S3sqDyJh4QL9Qqi4oPP47mEcc5OBQ2qUmqJfJVmt1UBuRBK096V8Rp5M-f-sjS79HKJedlg9Ay4="}
iex(8)> Fernet.verify(t, key: secret)
{:error, "padding error"}
Interactive Elixir (1.6.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> token = "gAAAAABarIpNcPrFWVd01p5IfMDtOZxxxjjEjYalDpYRJXd53iKEAVh_N15ctLUHlZOWGZH5fpaGn7dPyK-3pukgQSp8kbwPE3YsW01sBCmE_XovgxHNFJVc0v5YHCrMYpEr1e0AArFX2QyeuYfNgoqIxNWaX0jv4mgvfnX7POC5rEKjo8x5xe9WmRfecjSxGrqfecgKXzgUD3drPC7SjRphy_q8oow6zw=="
"gAAAAABarIpNcPrFWVd01p5IfMDtOZxxxjjEjYalDpYRJXd53iKEAVh_N15ctLUHlZOWGZH5fpaGn7dPyK-3pukgQSp8kbwPE3YsW01sBCmE_XovgxHNFJVc0v5YHCrMYpEr1e0AArFX2QyeuYfNgoqIxNWaX0jv4mgvfnX7POC5rEKjo8x5xe9WmRfecjSxGrqfecgKXzgUD3drPC7SjRphy_q8oow6zw=="
iex(2)> key = "fJXYWeIEcXMO3tLDheFVezM5QWBVFvkymG80n0Rluqs="
"fJXYWeIEcXMO3tLDheFVezM5QWBVFvkymG80n0Rluqs="
iex(3)> import Fernet
Fernet
iex(4)> Fernet.verify(token, key: key)
** (MatchError) no match of right hand side value: "{\"server\":\"mock\",\"secret\":\"0ec8a78e385f5e8a8591c48ea178c386a6135af7caf0525fb3123c18c9766ae3\",\"login\":\"testuser\"}"
(fernetex) lib/fernetex.ex:237: Fernet.decrypt/3
This token was generated by Poison.encode! - ing a map with these four key/value pairs.
If I encode the map replacing the key word of "login" with something else, the .verify works fine. If "login" is in the string (for some reason), it crashes.
Can you reproduce?
Here's another sequence top down the other way..(this key has no ttl)
iex(6)> key
"fJXYWeIEcXMO3tLDheFVezM5QWBVFvkymG80n0Rluqs="
iex(7)> Fernet.generate("{\"server\":\"mock\",\"secret\":\"8b867cb14f753cc2fbc32742f18ea38557e7a378a725c509b30cba35f3d4908b\",\"login\":\"testuser\"}", key: key)
{:ok, <<187, 127, 106, 50, 239, 93, 27, 123, 31, 43, 81, 84, 59, 169, 148, 201>>,
"gAAAAABarI0cu39qMu9dG3sfK1FUO6mUyXVSNDvEI3WBeZ8JDAWsjI_6XfQRK5OwQhfXXi584nxQL8FVu54DSng5WB4JvJf4fsvx4gJkAdoy13K3uvcb4JFaV57V5OyzkbePBbymrok4eGAsMovz-YRxqBynfpLnlpATS7zR9Mm9KXEJB-YmKfYCja-HjXygWecqY8nqS0Y_HdZ-fswuEemDSRmbhnETyA=="}
iex(8)> Fernet.verify("gAAAAABarIzsSVoepQ3QqL9MeqlpsbfXDF2WoibsMTJzBRV7g6mTsGOsxUzMVB3ULdd2AbfGodRlJflOq6pMOdtn09h9zpqCkfYafScC_WVHVtICQHHhWNfwokMAvu4ccY3dEVnAKGDOc8LT0PhqmdxF7n2k5HYa6SEaree8hQAJtnkyeLQmX2jdOxyERNbx_fqocIuYjONH4C8sYF8gaFB9kjMNIg-NuA==", key: key)
** (MatchError) no match of right hand side value: "{\"server\":\"mock\",\"secret\":\"8b867cb14f753cc2fbc32742f18ea38557e7a378a725c509b30cba35f3d4908b\",\"login\":\"testuser\"}"
(fernetex) lib/fernetex.ex:237: Fernet.decrypt/3
Now change the string of login to else..
iex(8)> Fernet.generate("{\"server\":\"mock\",\"secret\":\"8b867cb14f753cc2fbc32742f18ea38557e7a378a725c509b30cba35f3d4908b\",\"else\":\"testuser\"}", key: key)
{:ok, <<75, 171, 229, 109, 64, 64, 214, 175, 213, 4, 59, 110, 156, 28, 154, 21>>,
"gAAAAABarI1vS6vlbUBA1q_VBDtunByaFTAwwXeeKtJPDJat3v7GzpmCg9318EwT9gS6XiIAYgX_TaaqgcnsToZmP3hrkLzrPbGM8JP8W8BqmluP9HjZ9yTxNRS6TKXSZ65nDZVfWYnMRpjLtuzgnWqPZu3kzhpH-AF-a7Iic4MZz2pA4rH8CVZOy3CazfGDgqTmLZJsnWNkG84C0DRH4BzuALR6eSpb7g=="}
iex(9)> Fernet.verify("gAAAAABarI1vS6vlbUBA1q_VBDtunByaFTAwwXeeKtJPDJat3v7GzpmCg9318EwT9gS6XiIAYgX_TaaqgcnsToZmP3hrkLzrPbGM8JP8W8BqmluP9HjZ9yTxNRS6TKXSZ65nDZVfWYnMRpjLtuzgnWqPZu3kzhpH-AF-a7Iic4MZz2pA4rH8CVZOy3CazfGDgqTmLZJsnWNkG84C0DRH4BzuALR6eSpb7g==", key: key)
{:ok,
"{\"server\":\"mock\",\"secret\":\"8b867cb14f753cc2fbc32742f18ea38557e7a378a725c509b30cba35f3d4908b\",\"else\":\"testuser\"}"}
and it works. ??
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.