[Rt-commit] rt branch, 4.2/smime-v2, updated. rt-4.0.4-354-g1892444
Ruslan Zakirov
ruz at bestpractical.com
Tue Jan 10 09:29:19 EST 2012
The branch, 4.2/smime-v2 has been updated
via 18924446533432aa3640f58b7fc8b38264bb5d75 (commit)
from 4fba10295f28840f96f830671dce68a7c492946d (commit)
Summary of changes:
lib/RT/Attachment.pm | 2 +-
lib/RT/Crypt.pm | 27 ++++++++++++++++++++
t/crypt/gnupg/attachments-in-db.t | 49 +++++++++++++++++++++++++++++++++++++
3 files changed, 77 insertions(+), 1 deletions(-)
create mode 100644 t/crypt/gnupg/attachments-in-db.t
- Log -----------------------------------------------------------------
commit 18924446533432aa3640f58b7fc8b38264bb5d75
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Tue Jan 10 18:26:00 2012 +0400
first pass at generic attachments encrypt/decrypt in DB
diff --git a/lib/RT/Attachment.pm b/lib/RT/Attachment.pm
index e8c86be..081634b 100644
--- a/lib/RT/Attachment.pm
+++ b/lib/RT/Attachment.pm
@@ -782,7 +782,7 @@ sub Decrypt {
$self->SetHeader( 'Content-Type' => $type );
my $content = $self->Content;
- my %res = RT::Crypt::GnuPG::DecryptContent( Content => \$content, );
+ my %res = RT::Crypt->DecryptContent( Content => \$content );
if ( $res{'exit_code'} ) {
return (0, $self->loc('GnuPG error. Contact with administrator'));
}
diff --git a/lib/RT/Crypt.pm b/lib/RT/Crypt.pm
index f3f6503..70f7501 100644
--- a/lib/RT/Crypt.pm
+++ b/lib/RT/Crypt.pm
@@ -203,6 +203,23 @@ sub SignEncrypt {
return %res;
}
+sub SignEncryptContent {
+ my $self = shift;
+ my %args = (@_);
+
+ if ( $args{'Sign'} && !defined $args{'Signer'} ) {
+ $args{'Signer'} = $self->UseKeyForSigning;
+ }
+ if ( $args{'Encrypt'} && !$args{'Recipients'} ) {
+ $args{'Recipients'} = [ RT->Config->Get('CorrespondAddress') ];
+ }
+
+ my $protocol = delete $args{'Protocol'} || $self->UseForOutgoing;
+ my %res = $self->LoadImplementation( $protocol )->SignEncryptContent( %args );
+ $res{'Protocol'} = $protocol;
+ return %res;
+}
+
sub DrySign {
my $self = shift;
my %args = ( Protocol => undef, Signer => undef, @_ );
@@ -233,6 +250,16 @@ sub VerifyDecrypt {
return @res;
}
+sub DecryptContent {
+ my $self = shift;
+ my %args = (@_);
+
+ my $protocol = delete $args{'Protocol'} || $self->UseForOutgoing;
+ my %res = $self->LoadImplementation( $protocol )->DecryptContent( %args );
+ $res{'Protocol'} = $protocol;
+ return %res;
+}
+
sub ParseStatus {
my $self = shift;
my %args = (
diff --git a/t/crypt/gnupg/attachments-in-db.t b/t/crypt/gnupg/attachments-in-db.t
new file mode 100644
index 0000000..4f98c28
--- /dev/null
+++ b/t/crypt/gnupg/attachments-in-db.t
@@ -0,0 +1,49 @@
+#!/usr/bin/perl -w
+use strict;
+
+use RT::Test::GnuPG
+ tests => 12,
+ gnupg_options => {
+ passphrase => 'recipient',
+ 'trust-model' => 'always',
+ }
+;
+
+RT->Config->Get('GnuPG')->{'AllowEncryptDataInDB'} = 1;
+
+RT::Test->import_gnupg_key('general at example.com', 'public');
+RT::Test->import_gnupg_key('general at example.com', 'secret');
+my $queue = RT::Test->load_or_create_queue(
+ Name => 'General',
+ CorrespondAddress => 'general at example.com',
+);
+ok $queue && $queue->id, 'loaded or created queue';
+
+{
+ my $ticket = RT::Test->create_ticket(
+ Queue => $queue->id,
+ Subject => 'test',
+ Content => 'test',
+ );
+
+ my $txn = $ticket->Transactions->First;
+ ok $txn && $txn->id, 'found first transaction';
+ is $txn->Type, 'Create', 'it is Create transaction';
+
+ my $attach = $txn->Attachments->First;
+ ok $attach && $attach->id, 'found attachment';
+ is $attach->Content, 'test', 'correct content';
+
+ my ($status, $msg) = $attach->Encrypt;
+ ok $status, 'encrypted attachment';
+
+ isnt $attach->Content, 'test', 'correct content';
+
+ ($status, $msg) = $attach->Decrypt;
+ ok $status, 'decrypted attachment';
+
+ is $attach->Content, 'test', 'correct content';
+}
+
+
+
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list