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

[#22] Unmanaged Decryption #32

Merged
merged 9 commits into from
Aug 20, 2019
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ java/scala/src/test/resources/service-keys.conf
java/scala/src/test/resources/service-keys.conf.stage
java/scala/src/test/resources/service-keys.conf.local
.vscode
src/proto/transform.rs
35 changes: 34 additions & 1 deletion src/document/advanced.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::document::{partition_user_or_group, DocumentEncryptOpts};
use crate::internal;
use crate::internal::document_api::DocumentEncryptUnmanagedResult;
pub use crate::internal::document_api::{
DocumentDecryptUnmanagedResult, DocumentEncryptUnmanagedResult,
};
use crate::Result;
use itertools::EitherOrBoth;
use tokio::runtime::current_thread::Runtime;
Expand All @@ -25,6 +27,21 @@ pub trait DocumentAdvancedOps {
data: &[u8],
encrypt_opts: &DocumentEncryptOpts,
) -> Result<DocumentEncryptUnmanagedResult>;

/// (Advanced) Decrypt a document not managed by the ironcore service. Both the encrypted
/// data and the encrypted deks need to be provided.
///
/// The webservice is still needed to transform a chosen encrypted dek so it can be decrypted
/// by the caller's private key.
///
/// # Arguments
/// - `encrypted_data` - Encrypted document
/// - `encrypted_deks` - Associated encrypted DEKs for the `encrypted_data`
fn document_decrypt_unmanaged(
&self,
encrypted_data: &[u8],
clintfred marked this conversation as resolved.
Show resolved Hide resolved
encrypted_deks: &[u8],
) -> Result<DocumentDecryptUnmanagedResult>;
}

impl DocumentAdvancedOps for crate::IronOxide {
Expand Down Expand Up @@ -66,4 +83,20 @@ impl DocumentAdvancedOps for crate::IronOxide {
policy_grants,
))
}

fn document_decrypt_unmanaged(
&self,
encrypted_data: &[u8],
encrypted_deks: &[u8],
) -> Result<DocumentDecryptUnmanagedResult> {
let mut rt = Runtime::new().unwrap();

rt.block_on(internal::document_api::decrypt_document_unmanaged(
self.device.auth(),
&self.recrypt,
self.device().private_device_key(),
encrypted_data,
encrypted_deks,
))
}
}
4 changes: 2 additions & 2 deletions src/document/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub use crate::internal::document_api::{
AssociationType, DocAccessEditErr, DocumentAccessResult, DocumentDecryptResult,
DocumentEncryptResult, DocumentEncryptUnmanagedResult, DocumentListMeta, DocumentListResult,
DocumentMetadataResult, UserOrGroup, VisibleGroup, VisibleUser,
DocumentEncryptResult, DocumentListMeta, DocumentListResult, DocumentMetadataResult,
UserOrGroup, VisibleGroup, VisibleUser,
};
use crate::{
internal::{
Expand Down
Loading