-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Crypt4GH support using LocalStorage
- Loading branch information
Showing
62 changed files
with
2,363 additions
and
612 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,34 @@ | ||
# Crypt4GH example file | ||
|
||
This is just a customised summary for htsget-rs. Please refer to the official [`crypt4gh-rust` documentation](https://ega-archive.github.io/crypt4gh-rust) for further information. | ||
|
||
## Keygen | ||
|
||
```sh | ||
cargo install crypt4gh | ||
crypt4gh keygen --sk keys/alice.sec --pk keys/alice.pub | ||
crypt4gh keygen --sk keys/bob.sec --pk keys/bob.pub | ||
``` | ||
|
||
## Encrypt | ||
``` | ||
crypt4gh encrypt --sk keys/alice.sec --recipient_pk keys/bob.pub < htsnexus_test_NA12878.bam > htsnexus_test_NA12878.bam.c4gh | ||
``` | ||
|
||
## Decrypt | ||
|
||
```sh | ||
crypt4gh decryptor --range 0-65535 --sk data/crypt4gh/keys/bob.sec \ | ||
--sender-pk data/crypt4gh/keys/alice.pub \ | ||
< data/crypt4gh/htsnexus_test_NA12878.bam.c4gh \ | ||
> out.bam | ||
|
||
samtools view out.bam | ||
(...) | ||
SRR098401.61822403 83 11 5009470 60 76M = 5009376 -169 TCTTCTTGCCCTGGTGTTTCGCCGTTCCAGTGCCCCCTGCTGCAGACCATAAAGGATGGGACTTTGTTGAGGTAGG ?B6BDCD@I?JFI?FHHFEAIIAHHDIJHHFIIIIIJEIIFIJGHCIJDDEEHHHDEHHHCIGGEGFDGFGFBEDC X0:i:1 X1:i:0 MD:Z:76 RG:Z:SRR098401 AM:i:37 NM:i:0 SM:i:37 MQ:i:60 XT:A:U BQ:Z:@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@B | ||
|
||
samtools view: error reading file "out.bam" | ||
samtools view: error closing "out.bam": -1 | ||
``` | ||
|
||
The last samtools view error suggests that the returned bytes do not include BAM file termination. |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,3 @@ | ||
-----BEGIN CRYPT4GH PUBLIC KEY----- | ||
ToQrpj4UfuLgxZRe1wSGIZtXC19fOEHUHe3RQy63qwM= | ||
-----END CRYPT4GH PUBLIC KEY----- |
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,3 @@ | ||
-----BEGIN CRYPT4GH PRIVATE KEY----- | ||
YzRnaC12MQAEbm9uZQAEbm9uZQAgxi4tNmUO++HAApv9ryZB9S8QfqrWKKe5CunJuChH5vU= | ||
-----END CRYPT4GH PRIVATE KEY----- |
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,3 @@ | ||
-----BEGIN CRYPT4GH PUBLIC KEY----- | ||
TyKEXZPnfon6dj1kRXl6HumfZDzo/h60RIc8Wd0Ig2s= | ||
-----END CRYPT4GH PUBLIC KEY----- |
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,3 @@ | ||
-----BEGIN CRYPT4GH PRIVATE KEY----- | ||
YzRnaC12MQAEbm9uZQAEbm9uZQAg6uLXNqcXAi6FRKzRBk2KBKF4BnmueySZv5MGzKjIPcI= | ||
-----END CRYPT4GH PRIVATE KEY----- |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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
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,12 @@ | ||
# An example of running htsget-rs with Crypt4GH enabled. | ||
# Run with `cargo run -p htsget-axum --features c4gh-experimental -- --config htsget-config/examples/config-files/c4gh.toml` | ||
|
||
ticket_server_addr = "127.0.0.1:8080" | ||
data_server_addr = "127.0.0.1:8081" | ||
|
||
[[resolvers]] | ||
regex = ".*" | ||
substitution_string = "$0" | ||
|
||
[resolvers.storage] | ||
object_type = { private_key = "data/c4gh/keys/bob.sec", recipient_public_key = "data/c4gh/keys/alice.pub" } # pragma: allowlist secret |
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,62 @@ | ||
//! Crypt4GH key parsing. | ||
//! | ||
|
||
use crate::error::Error::ParseError; | ||
use crate::error::{Error, Result}; | ||
use crypt4gh::error::Crypt4GHError; | ||
use crypt4gh::keys::{get_private_key, get_public_key}; | ||
use crypt4gh::Keys; | ||
use serde::Deserialize; | ||
use std::path::PathBuf; | ||
|
||
/// Config for Crypt4GH keys. | ||
#[derive(Deserialize, Debug, Clone, PartialEq, Eq)] | ||
#[serde(try_from = "C4GHPath")] | ||
pub struct C4GHKeys { | ||
keys: Vec<Keys>, | ||
} | ||
|
||
impl C4GHKeys { | ||
/// Get the inner value. | ||
pub fn into_inner(self) -> Vec<Keys> { | ||
self.keys | ||
} | ||
} | ||
|
||
#[derive(Deserialize, Debug, Clone, PartialEq, Eq)] | ||
pub struct C4GHPath { | ||
private_key: PathBuf, | ||
recipient_public_key: PathBuf, | ||
} | ||
|
||
impl C4GHPath { | ||
pub fn new(private_key: PathBuf, recipient_public_key: PathBuf) -> Self { | ||
Self { | ||
private_key, | ||
recipient_public_key, | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<C4GHPath> for C4GHKeys { | ||
type Error = Error; | ||
|
||
fn try_from(path: C4GHPath) -> Result<Self> { | ||
let private_key = get_private_key(path.private_key, Ok("".to_string()))?; | ||
let recipient_public_key = get_public_key(path.recipient_public_key)?; | ||
|
||
Ok(C4GHKeys { | ||
keys: vec![Keys { | ||
method: 0, | ||
privkey: private_key, | ||
recipient_pubkey: recipient_public_key, | ||
}], | ||
}) | ||
} | ||
} | ||
|
||
impl From<Crypt4GHError> for Error { | ||
fn from(err: Crypt4GHError) -> Self { | ||
ParseError(err.to_string()) | ||
} | ||
} |
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,23 @@ | ||
//! Defines the type of object used by storage. | ||
//! | ||
|
||
#[cfg(feature = "c4gh-experimental")] | ||
pub mod c4gh; | ||
|
||
#[cfg(feature = "c4gh-experimental")] | ||
use crate::storage::object::c4gh::C4GHKeys; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// An object type, can be regular or Crypt4GH encrypted. | ||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq)] | ||
#[serde(untagged, deny_unknown_fields)] | ||
#[non_exhaustive] | ||
pub enum ObjectType { | ||
#[default] | ||
Regular, | ||
#[cfg(feature = "c4gh-experimental")] | ||
C4GH { | ||
#[serde(flatten, skip_serializing)] | ||
keys: C4GHKeys, | ||
}, | ||
} |
Oops, something went wrong.