From 6d73b395a1619df82239ed44abd13966d622241e Mon Sep 17 00:00:00 2001 From: Marco Villegas Date: Fri, 15 Nov 2013 13:50:19 -0500 Subject: [PATCH 1/5] tx-io: use the right key on received blob metadata identify method. Following 5e8f843a8259dd1d1e4bfa39c0d5a287ecb1327d. --- src/ChamiloLMS/Transaction/Envelope.php | 2 +- src/ChamiloLMS/Transaction/TransactionLogController.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ChamiloLMS/Transaction/Envelope.php b/src/ChamiloLMS/Transaction/Envelope.php index 2564f10c1e..d834f38076 100644 --- a/src/ChamiloLMS/Transaction/Envelope.php +++ b/src/ChamiloLMS/Transaction/Envelope.php @@ -160,7 +160,7 @@ class Envelope * * @return array * An array with the metadata. Contains the following keys: - * - 'type': The wrapper plugin machine name. + * - 'blob_type': The wrapper plugin machine name. * - 'origin_branch_id': The branch where the blob was generated. */ public static function identifyBlobMetadata($blob) { diff --git a/src/ChamiloLMS/Transaction/TransactionLogController.php b/src/ChamiloLMS/Transaction/TransactionLogController.php index 1d20a8d64a..22088da4bc 100644 --- a/src/ChamiloLMS/Transaction/TransactionLogController.php +++ b/src/ChamiloLMS/Transaction/TransactionLogController.php @@ -188,7 +188,7 @@ class TransactionLogController try { $blob_metadata = Envelope::identifyBlobMetadata($row['data']); $origin_branch = $this->branchRepository->find($blob_metadata['origin_branch_id']); - $wrapper_plugin = self::createPlugin('wrapper', $blob_metadata['type'], $origin_branch->getPluginData('wrapper')); + $wrapper_plugin = self::createPlugin('wrapper', $blob_metadata['blob_type'], $origin_branch->getPluginData('wrapper')); $envelope_data = array('blob' => $blob, 'origin_branch_id' => $blob_metadata['origin_branch_id']); $envelope = new Envelope($wrapper_plugin, $envelope_data); $envelope->unwrap(); @@ -567,7 +567,7 @@ class TransactionLogController try { $blob_metadata = Envelope::identifyBlobMetadata($blob); $origin_branch = $this->branchRepository->find($blob_metadata['origin_branch_id']); - $wrapper_plugin = self::createPlugin('wrapper', $blob_metadata['type'], $origin_branch->getPluginData('wrapper')); + $wrapper_plugin = self::createPlugin('wrapper', $blob_metadata['blob_type'], $origin_branch->getPluginData('wrapper')); $envelope_data = array('blob' => $blob, 'origin_branch_id' => $blob_metadata['origin_branch_id']); $envelope = new Envelope($wrapper_plugin, $envelope_data); } From 54ff2e4a666ac95e12c8df200e68585957d43092 Mon Sep 17 00:00:00 2001 From: Marco Villegas Date: Fri, 15 Nov 2013 14:01:25 -0500 Subject: [PATCH 2/5] Extra check for non-recognized branch identified in the blob during receive. --- src/ChamiloLMS/Transaction/TransactionLogController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ChamiloLMS/Transaction/TransactionLogController.php b/src/ChamiloLMS/Transaction/TransactionLogController.php index 22088da4bc..345b6c4168 100644 --- a/src/ChamiloLMS/Transaction/TransactionLogController.php +++ b/src/ChamiloLMS/Transaction/TransactionLogController.php @@ -567,6 +567,9 @@ class TransactionLogController try { $blob_metadata = Envelope::identifyBlobMetadata($blob); $origin_branch = $this->branchRepository->find($blob_metadata['origin_branch_id']); + if (!$origin_branch) { + throw new Exception(sprintf('Cannot find a local branch with id %s', $blob_metadata['origin_branch_id'])); + } $wrapper_plugin = self::createPlugin('wrapper', $blob_metadata['blob_type'], $origin_branch->getPluginData('wrapper')); $envelope_data = array('blob' => $blob, 'origin_branch_id' => $blob_metadata['origin_branch_id']); $envelope = new Envelope($wrapper_plugin, $envelope_data); From 8b29aa347e5bd14842a7f9fcfd4c9482da9e52d4 Mon Sep 17 00:00:00 2001 From: Marco Villegas Date: Fri, 15 Nov 2013 14:22:15 -0500 Subject: [PATCH 3/5] TransactionLogController::importPendingEnvelopes should not be static. --- src/ChamiloLMS/Transaction/TransactionLogController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ChamiloLMS/Transaction/TransactionLogController.php b/src/ChamiloLMS/Transaction/TransactionLogController.php index 345b6c4168..95154570bc 100644 --- a/src/ChamiloLMS/Transaction/TransactionLogController.php +++ b/src/ChamiloLMS/Transaction/TransactionLogController.php @@ -172,7 +172,7 @@ class TransactionLogController * An array keyed by received envelope id containing an array transaction * ids added based on that received envelope. */ - public static function importPendingEnvelopes($limit = 0) { + public function importPendingEnvelopes($limit = 0) { $table = Database::get_main_table(TABLE_RECEIVED_ENVELOPES); $log_entry = array('log_type' => self::LOG_IMPORT_TO_TX_QUEUE); // Sadly limit clause is not supported by Database::select(). From b867308bf381e50e1812bb6d0d436ffe0c05bbf6 Mon Sep 17 00:00:00 2001 From: Marco Villegas Date: Fri, 15 Nov 2013 14:24:38 -0500 Subject: [PATCH 4/5] fix variable name on TransactionLogController::importPendingEnvelopes --- src/ChamiloLMS/Transaction/TransactionLogController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ChamiloLMS/Transaction/TransactionLogController.php b/src/ChamiloLMS/Transaction/TransactionLogController.php index 95154570bc..886eb0b6f2 100644 --- a/src/ChamiloLMS/Transaction/TransactionLogController.php +++ b/src/ChamiloLMS/Transaction/TransactionLogController.php @@ -189,7 +189,7 @@ class TransactionLogController $blob_metadata = Envelope::identifyBlobMetadata($row['data']); $origin_branch = $this->branchRepository->find($blob_metadata['origin_branch_id']); $wrapper_plugin = self::createPlugin('wrapper', $blob_metadata['blob_type'], $origin_branch->getPluginData('wrapper')); - $envelope_data = array('blob' => $blob, 'origin_branch_id' => $blob_metadata['origin_branch_id']); + $envelope_data = array('blob' => $row['data'], 'origin_branch_id' => $blob_metadata['origin_branch_id']); $envelope = new Envelope($wrapper_plugin, $envelope_data); $envelope->unwrap(); $transactions = $envelope->getTransactions(); From fb59011eff595e986fe3b4e3495aa927cc083d2c Mon Sep 17 00:00:00 2001 From: Marco Villegas Date: Fri, 15 Nov 2013 14:32:08 -0500 Subject: [PATCH 5/5] fix variable name --- src/ChamiloLMS/Transaction/Plugin/SslSignedJsonWrapper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ChamiloLMS/Transaction/Plugin/SslSignedJsonWrapper.php b/src/ChamiloLMS/Transaction/Plugin/SslSignedJsonWrapper.php index aac5ec472d..b0817aaa24 100644 --- a/src/ChamiloLMS/Transaction/Plugin/SslSignedJsonWrapper.php +++ b/src/ChamiloLMS/Transaction/Plugin/SslSignedJsonWrapper.php @@ -192,7 +192,7 @@ class SslSignedJsonWrapper extends JsonWrapper throw new UnwrapException(self::format_log(sprintf('Problem veryfing signer branch: %s.', $exception->getMessage()))); } if (!$declared_branch_is_valid) { - $message = sprintf('Declared branch with id "%d" is not the same than real signer branch. Possible attack attempt to inject transactions with other valid branch signature.', $branch->getId()); + $message = sprintf('Declared branch with id "%d" is not the same than real signer branch. Possible attack attempt to inject transactions with other valid branch signature.', $declared_origin_branch->getId()); // Try to identify it. if (!$branch_id = $this->identifySignerBranch($envelope_metadata['origin_branch_id'], $signer_certificates_file)) { $message .= sprintf(' Cannot retrieve any valid branch associated with the signer certificate file "%s". Altered data?', $signer_certificates_file);