-
Notifications
You must be signed in to change notification settings - Fork 690
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5958 from evilaliv3/fix-5933
Bump 2FA secret bit length from 80 to 160 bits as recommended by RFC4226
- Loading branch information
Showing
7 changed files
with
127 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
securedrop/alembic/versions/de00920916bf_updates_journalists_otp_secret_length_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Updates journalists.otp_secret length from 16 to 32 | ||
Revision ID: de00920916bf | ||
Revises: 1ddb81fb88c2 | ||
Create Date: 2021-05-21 15:51:39.202368 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'de00920916bf' | ||
down_revision = '1ddb81fb88c2' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('journalists', schema=None) as batch_op: | ||
batch_op.alter_column('otp_secret', | ||
existing_type=sa.VARCHAR(length=16), | ||
type_=sa.String(length=32), | ||
existing_nullable=True) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('journalists', schema=None) as batch_op: | ||
batch_op.alter_column('otp_secret', | ||
existing_type=sa.String(length=32), | ||
type_=sa.VARCHAR(length=16), | ||
existing_nullable=True) | ||
|
||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# -*- coding: utf-8 -*- | ||
import random | ||
import uuid | ||
|
||
from sqlalchemy import text | ||
|
||
from db import db | ||
from journalist_app import create_app | ||
from .helpers import random_chars | ||
|
||
random.seed('くコ:彡') | ||
|
||
|
||
class Helper: | ||
|
||
def __init__(self): | ||
self.journalist_id = None | ||
|
||
def create_journalist(self, otp_secret="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"): | ||
if self.journalist_id is not None: | ||
raise RuntimeError('Journalist already created') | ||
|
||
params = { | ||
'uuid': str(uuid.uuid4()), | ||
'username': random_chars(50), | ||
'session_nonce': 0, | ||
'otp_secret': otp_secret | ||
} | ||
sql = '''INSERT INTO journalists (uuid, username, otp_secret, session_nonce) | ||
VALUES (:uuid, :username, :otp_secret, :session_nonce) | ||
''' | ||
self.journalist_id = db.engine.execute(text(sql), **params).lastrowid | ||
|
||
|
||
class UpgradeTester(Helper): | ||
""" | ||
Checks schema to verify that the otp_secret varchar "length" has been updated. | ||
Varchar specified length isn't enforced by sqlite but it's good to verify that | ||
the migration worked as expected. | ||
""" | ||
|
||
def __init__(self, config): | ||
Helper.__init__(self) | ||
self.config = config | ||
self.app = create_app(config) | ||
|
||
def load_data(self): | ||
with self.app.app_context(): | ||
self.create_journalist() | ||
|
||
def check_upgrade(self): | ||
with self.app.app_context(): | ||
journalists_sql = "SELECT * FROM journalists" | ||
journalist = db.engine.execute(text(journalists_sql)).first() | ||
assert len(journalist['otp_secret']) == 32 # Varchar ignores length | ||
|
||
|
||
class DowngradeTester(Helper): | ||
|
||
def __init__(self, config): | ||
Helper.__init__(self) | ||
self.config = config | ||
self.app = create_app(config) | ||
|
||
def load_data(self): | ||
with self.app.app_context(): | ||
self.create_journalist() | ||
|
||
def check_downgrade(self): | ||
with self.app.app_context(): | ||
journalists_sql = "SELECT * FROM journalists" | ||
journalist = db.engine.execute(text(journalists_sql)).first() | ||
assert len(journalist['otp_secret']) == 32 # Varchar ignores length |