Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require strict base64 decoding #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
require strict base64 decoding
  • Loading branch information
reaperhulk committed May 28, 2015
commit 8a219208ed1884505ff1f638028fd6fcc51aeb5a
6 changes: 5 additions & 1 deletion Spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ All encryption in this version is done with AES 128 in CBC mode.
All base 64 encoding is done with the "URL and Filename Safe"
variant, defined in [RFC 4648](http://tools.ietf.org/html/rfc4648#section-5) as "base64url".

Implementations **MUST** implement strict checking of the base64 payload. This means
rejection of invalid characters as well as additional characters after the padding byte(s).

## Key Format

A fernet *key* is the base64url encoding of the following
Expand Down Expand Up @@ -110,7 +113,8 @@ Given a key and token, to verify that the token is valid and
recover the original message, perform the following steps, in
order:

1. base64url decode the token.
1. base64url decode the token rejecting any token that has invalid
characters or bytes after padding.
2. Ensure the first byte of the token is 0x80.
3. If the user has specified a maximum age (or "time-to-live") for
the token, ensure the recorded timestamp is not too far in the
Expand Down
21 changes: 21 additions & 0 deletions invalid.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,26 @@
"now": "1985-10-26T01:20:01-07:00",
"ttl_sec": 60,
"secret": "cw_0x689RpI-jtRR7oE8h_eQsKImvJapLeSbXpwF4e4="
},
{
"desc": "trailing characters after b64 padding",
"token": "gAAAAAAdwJ6wAAECAwQFBgcICQoLDA0ODy021cpGVWKZ_eEwCGM4BLLF_5CV9dOPmrhuVUPgJobwOz7JcbmrR64jVmpU4IwqDA==trailingdata",
"now": "1985-10-26T01:20:01-07:00",
"ttl_sec": 60,
"secret": "cw_0x689RpI-jtRR7oE8h_eQsKImvJapLeSbXpwF4e4="
},
{
"desc": "invalid characters in b64",
"token": "*gAAAAAAdwJ6wAAECAwQFBgcI!CQoLDA0ODy021?cpGVWKZ_eEwC@GM4BLLF_5CV9dOPmrhuVUPgJobwOz7JcbmrR64jVmpU4IwqDA==",
"now": "1985-10-26T01:20:01-07:00",
"ttl_sec": 60,
"secret": "cw_0x689RpI-jtRR7oE8h_eQsKImvJapLeSbXpwF4e4="
},
{
"desc": "invalid non-urlsafe characters in b64",
"token": "gAAAAAAdwJ6wAAEC/AwQFBgcICQoLDA0ODy+021cpGVWKZ_eEwCGM4BLLF_5CV9dOPmrhuVUPgJobwOz7JcbmrR64jVmpU4IwqDA==",
"now": "1985-10-26T01:20:01-07:00",
"ttl_sec": 60,
"secret": "cw_0x689RpI-jtRR7oE8h_eQsKImvJapLeSbXpwF4e4="
}
]