-
Notifications
You must be signed in to change notification settings - Fork 687
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 #6892 from freedomofpress/sequoia-initial
New source creation uses Sequoia
- Loading branch information
Showing
39 changed files
with
791 additions
and
623 deletions.
There are no files selected for viewing
12 changes: 9 additions & 3 deletions
12
install_files/ansible-base/roles/app/tasks/initialize_securedrop_app.yml
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
# type stub for redwood module | ||
# see https://pyo3.rs/v0.16.4/python_typing_hints.html | ||
from pathlib import Path | ||
from typing import BinaryIO | ||
|
||
def generate_source_key_pair(passphrase: str, email: str) -> (str, str, str): ... | ||
def encrypt_message(recipients: list[str], plaintext: str, destination: Path) -> None: ... | ||
def encrypt_file(recipients: list[str], plaintext: Path, destination: Path) -> None: ... | ||
def decrypt(ciphertext: bytes, secret_key: str, passphrase: str) -> str: ... | ||
def encrypt_stream(recipients: list[str], plaintext: BinaryIO, destination: Path) -> None: ... | ||
def decrypt(ciphertext: bytes, secret_key: str, passphrase: str) -> bytes: ... | ||
|
||
class RedwoodError(Exception): ... |
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,32 @@ | ||
use pyo3::types::PyBytes; | ||
use pyo3::{PyAny, PyResult}; | ||
use std::io::{self, ErrorKind, Read, Write}; | ||
|
||
/// Wrapper to implement the `Read` trait around a Python | ||
/// object that contains a `.read()` function. | ||
pub(crate) struct Stream<'a> { | ||
pub(crate) reader: &'a PyAny, | ||
} | ||
|
||
impl Stream<'_> { | ||
/// Read the specified number of bytes out of the object | ||
fn read_bytes(&self, len: usize) -> PyResult<&PyBytes> { | ||
let func = self.reader.getattr("read")?; | ||
// In Python this is effectively calling `reader.read(len)` | ||
let bytes = func.call1((len,))?; | ||
let bytes = bytes.downcast::<PyBytes>()?; | ||
Ok(bytes) | ||
} | ||
} | ||
|
||
impl Read for Stream<'_> { | ||
fn read(&mut self, mut buf: &mut [u8]) -> std::io::Result<usize> { | ||
let bytes = self.read_bytes(buf.len()).map_err(|err| { | ||
// The PyErr could be a type error (e.g. no "read" method) or an | ||
// actual I/O failure if the read() call failed, let's just treat | ||
// all of them as "other" for simplicity. | ||
io::Error::new(ErrorKind::Other, err.to_string()) | ||
})?; | ||
buf.write(bytes.as_bytes()) | ||
} | ||
} |
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,30 @@ | ||
"""sequoia_pgp | ||
Revision ID: 811334d7105f | ||
Revises: c5a02eb52f2d | ||
Create Date: 2023-06-29 18:19:59.314380 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "811334d7105f" | ||
down_revision = "c5a02eb52f2d" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
with op.batch_alter_table("sources", schema=None) as batch_op: | ||
batch_op.add_column(sa.Column("pgp_fingerprint", sa.String(length=40), nullable=True)) | ||
batch_op.add_column(sa.Column("pgp_public_key", sa.Text(), nullable=True)) | ||
batch_op.add_column(sa.Column("pgp_secret_key", sa.Text(), nullable=True)) | ||
|
||
|
||
def downgrade() -> None: | ||
# We do NOT drop the columns here, because doing so would break any | ||
# source that had its key pair stored here. If a downgrade is needed for | ||
# whatever reason, the extra columns will just be ignored, and the sources | ||
# will still be temporarily broken, but there will be no data loss. | ||
pass |
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
Oops, something went wrong.