Minor - format code

pull/2487/head
jmontoyaa 7 years ago
parent e0a8a36229
commit e61ffc63df
  1. 1
      plugin/sepe/src/formative-action-edit.php
  2. 12
      plugin/sepe/src/formative-action.php
  3. 5
      plugin/sepe/src/formative-actions-list.php
  4. 3
      plugin/sepe/src/identification-data-edit.php
  5. 5
      plugin/sepe/src/identification-data.php
  6. 21
      plugin/sepe/src/participant-action-edit.php
  7. 1
      plugin/sepe/src/participant-specialty-edit.php
  8. 5
      plugin/sepe/src/sepe-administration-menu.php
  9. 8
      plugin/sepe/src/sepe.lib.php
  10. 1
      plugin/sepe/src/specialty-action-edit.php
  11. 1
      plugin/sepe/src/specialty-classroom-edit.php
  12. 37
      plugin/sepe/src/wsse/soap-server-wsse.php
  13. 304
      plugin/sepe/src/wsse/soap-wsa.php
  14. 397
      plugin/sepe/src/wsse/soap-wsse.php

@ -217,4 +217,5 @@ if (api_is_platform_admin()) {
$tpl->display_one_col_template();
} else {
header('Location:'.api_get_path(WEB_PATH));
exit;
}

@ -20,8 +20,14 @@ if (api_is_platform_admin()) {
header("Location: formative-actions-list.php");
}
$templateName = $plugin->get_lang('FormativeActionData');
$interbreadcrumb[] = array("url" => "/plugin/sepe/src/sepe-administration-menu.php", "name" => $plugin->get_lang('MenuSepe'));
$interbreadcrumb[] = array("url" => "formative-actions-list.php", "name" => $plugin->get_lang('FormativesActionsList'));
$interbreadcrumb[] = array(
"url" => "/plugin/sepe/src/sepe-administration-menu.php",
"name" => $plugin->get_lang('MenuSepe'),
);
$interbreadcrumb[] = array(
"url" => "formative-actions-list.php",
"name" => $plugin->get_lang('FormativesActionsList'),
);
$tpl = new Template($templateName);
if (isset($_SESSION['sepe_message_info'])) {
@ -32,7 +38,7 @@ if (api_is_platform_admin()) {
$tpl->assign('message_error', $_SESSION['sepe_message_error']);
unset($_SESSION['sepe_message_error']);
}
$tpl->assign('info', $info);
$tpl->assign('start_date', date("d/m/Y", strtotime($info['start_date'])));
$tpl->assign('end_date', date("d/m/Y", strtotime($info['end_date'])));

@ -26,15 +26,16 @@ if (api_is_platform_admin()) {
$courseActionList = listCourseAction();
$courseFreeList = listCourseFree();
$actionFreeList = listActionFree();
$tpl->assign('course_action_list', $courseActionList);
$tpl->assign('course_free_list', $courseFreeList);
$tpl->assign('action_free_list', $actionFreeList);
$listing_tpl = 'sepe/view/formative-actions-list.tpl';
$content = $tpl->fetch($listing_tpl);
$tpl->assign('content', $content);
$tpl->display_one_col_template();
} else {
header('Location:'.api_get_path(WEB_PATH));
exit;
}

@ -21,7 +21,7 @@ if (!empty($_POST)) {
$phone = Database::escape_string(trim($_POST['phone']));
$mail = Database::escape_string(trim($_POST['mail']));
$id = intval($_POST['id']);
if (checkIdentificationData()) {
$sql = "UPDATE $tableSepeCenter SET
center_origin = '".$centerOrigin."',
@ -91,4 +91,5 @@ if (api_is_platform_admin()) {
$tpl->display_one_col_template();
} else {
header('Location:'.api_get_path(WEB_PATH));
exit;
}

@ -15,7 +15,10 @@ $_cid = 0;
if (api_is_platform_admin()) {
$info = getInfoIdentificationData();
$templateName = $plugin->get_lang('DataCenter');
$interbreadcrumb[] = array("url" => "/plugin/sepe/src/sepe-administration-menu.php", "name" => $plugin->get_lang('MenuSepe'));
$interbreadcrumb[] = array(
"url" => "/plugin/sepe/src/sepe-administration-menu.php",
"name" => $plugin->get_lang('MenuSepe'),
);
$tpl = new Template($templateName);
if (isset($_SESSION['sepe_message_info'])) {

@ -61,7 +61,10 @@ if (!empty($_POST)) {
if (isset($trainingTutorId) && $trainingTutorId == 0) {
$sql = "SELECT * FROM $tableTutorCompany
WHERE document_type = '".$tutorTrainingDocumentType."' AND document_number = '".$tutorTrainingDocumentNumber."' AND document_letter = '".$tutorTrainingDocumentLetter."';";
WHERE
document_type = '".$tutorTrainingDocumentType."' AND
document_number = '".$tutorTrainingDocumentNumber."' AND
document_letter = '".$tutorTrainingDocumentLetter."';";
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
@ -178,9 +181,18 @@ if (!empty($_POST)) {
if (api_is_platform_admin()) {
$actionId = intval($_GET['action_id']);
$courseId = getCourse($actionId);
$interbreadcrumb[] = array("url" => "/plugin/sepe/src/sepe-administration-menu.php", "name" => $plugin->get_lang('MenuSepe'));
$interbreadcrumb[] = array("url" => "formative-actions-list.php", "name" => $plugin->get_lang('FormativesActionsList'));
$interbreadcrumb[] = array("url" => "formative-action.php?cid=".$courseId, "name" => $plugin->get_lang('FormativeAction'));
$interbreadcrumb[] = array(
"url" => "/plugin/sepe/src/sepe-administration-menu.php",
"name" => $plugin->get_lang('MenuSepe'),
);
$interbreadcrumb[] = array(
"url" => "formative-actions-list.php",
"name" => $plugin->get_lang('FormativesActionsList'),
);
$interbreadcrumb[] = array(
"url" => "formative-action.php?cid=".$courseId,
"name" => $plugin->get_lang('FormativeAction'),
);
if (isset($_GET['new_participant']) && intval($_GET['new_participant']) == 1) {
$templateName = $plugin->get_lang('NewParticipantAction');
$tpl = new Template($templateName);
@ -237,4 +249,5 @@ if (api_is_platform_admin()) {
$tpl->display_one_col_template();
} else {
header('Location:'.api_get_path(WEB_PATH));
exit;
}

@ -275,4 +275,5 @@ if (api_is_platform_admin()) {
$tpl->display_one_col_template();
} else {
header('Location:'.api_get_path(WEB_PATH));
exit;
}

@ -46,16 +46,17 @@ if (api_is_platform_admin() && $enable) {
$htmlText .= '</div>';
$htmlText .= '</div>';
$htmlText .= '</div>';
$templateName = $plugin->get_lang('MenuSepeAdministrator');
$interbreadcrumb[] = array("url" => "/main/admin/index.php", "name" => get_lang('Administration'));
$tpl = new Template($templateName);
$tpl->assign('html_text', $htmlText);
$listing_tpl = 'sepe/view/sepe-administration-menu.tpl';
$content = $tpl->fetch($listing_tpl);
$tpl->assign('content', $content);
$tpl->display_one_col_template();
} else {
header('Location:'.api_get_path(WEB_PATH));
exit;
}

@ -4,8 +4,6 @@
* @package chamilo.plugin.sepe
*/
require_once 'sepe_plugin.class.php';
$tableSepeCenter = Database::get_main_table(SepePlugin::TABLE_SEPE_CENTER);
$tableSepeActions = Database::get_main_table(SepePlugin::TABLE_SEPE_ACTIONS);
$tableSepeSpecialty = Database::get_main_table(SepePlugin::TABLE_SEPE_SPECIALTY);
@ -171,7 +169,7 @@ function list_tutor($specialtyId)
return $row;
}
function getCentersList()
function getCentersList()
{
global $tableCenters;
$sql = "SELECT * FROM $tableCenters;";
@ -193,7 +191,7 @@ function listTutorType($condition)
$tmp = array();
$tmp['id'] = $row['id'];
if (trim($row['alias']) != '') {
$tmp['alias'] = $row['alias'].' - '.$row['document_type'].' '.$row['document_number'].' '.$row['document_letter'];
$tmp['alias'] = $row['alias'].' - '.$row['document_type'].' '.$row['document_number'].' '.$row['document_letter'];
} else {
$tmp['alias'] = $row['document_type'].' '.$row['document_number'].' '.$row['document_letter'];
}
@ -222,7 +220,7 @@ function getTutorsSpecialty($specialtyId)
$tutor = array();
$tutor['id'] = $row['id'];
if (trim($row['firstname']) != '' || trim($row['lastname']) != '') {
$tutor['data'] = $row['firstname'].' '.$row['lastname'].' ('.$row['document_type'].' '.$row['document_number'].' '.$row['document_letter'].' )';
$tutor['data'] = $row['firstname'].' '.$row['lastname'].' ('.$row['document_type'].' '.$row['document_number'].' '.$row['document_letter'].' )';
} else {
$tutor['data'] = $row['document_type'].' '.$row['document_number'].' '.$row['document_letter'];
}

@ -241,4 +241,5 @@ if (api_is_platform_admin()) {
} else {
header('Location:'.api_get_path(WEB_PATH));
exit;
}

@ -130,4 +130,5 @@ if (api_is_platform_admin()) {
$tpl->display_one_col_template();
} else {
header('Location:'.api_get_path(WEB_PATH));
exit;
}

@ -43,28 +43,33 @@
use RobRichards\XMLSecLibs\XMLSecurityDSig;
use RobRichards\XMLSecLibs\XMLSecurityKey;
class WSSESoapServer {
/**
* Class WSSESoapServer
*/
class WSSESoapServer
{
const WSSENS = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
const WSSENS_2003 = 'http://schemas.xmlsoap.org/ws/2003/06/secext';
const WSUNS = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
const WSSEPFX = 'wsse';
const WSUPFX = 'wsu';
private $soapNS, $soapPFX;
private $soapDoc = NULL;
private $envelope = NULL;
private $SOAPXPath = NULL;
private $secNode = NULL;
public $signAllHeaders = FALSE;
private function locateSecurityHeader($setActor=NULL) {
$wsNamespace = NULL;
if ($this->secNode == NULL) {
$secnode = NULL;
private $soapDoc = null;
private $envelope = null;
private $SOAPXPath = null;
private $secNode = null;
public $signAllHeaders = false;
private function locateSecurityHeader($setActor = null)
{
$wsNamespace = null;
if ($this->secNode == null) {
$secnode = null;
$headers = $this->SOAPXPath->query('//wssoap:Envelope/wssoap:Header');
if ($header = $headers->item(0)) {
$secnodes = $this->SOAPXPath->query('./*[local-name()="Security"]', $header);
foreach ($secnodes AS $node) {
foreach ($secnodes as $node) {
$nsURI = $node->namespaceURI;
if (($nsURI == self::WSSENS) || ($nsURI == self::WSSENS_2003)) {
$actor = $node->getAttributeNS($this->soapNS, 'actor');
@ -110,11 +115,11 @@ class WSSESoapServer {
$objXMLSecDSig->canonicalizeSignedInfo();
$retVal = $objXMLSecDSig->validateReference();
if (! $retVal) {
if (!$retVal) {
throw new Exception("Validation Failed");
}
$key = NULL;
$key = null;
$objKey = $objXMLSecDSig->locateKey();
if ($objKey) {
@ -133,7 +138,6 @@ class WSSESoapServer {
$nodeset = $this->SOAPXPath->query($query, $refNode);
if ($encmeth = $nodeset->item(0)) {
if ($uri = $encmeth->getAttribute("URI")) {
$arUrl = parse_url($uri);
if (empty($arUrl['path']) && ($identifier = $arUrl['fragment'])) {
@ -183,7 +187,7 @@ class WSSESoapServer {
$node = $nextNode;
}
$this->secNode->parentNode->removeChild($this->secNode);
$this->secNode = NULL;
$this->secNode = null;
return true;
}
@ -198,4 +202,3 @@ class WSSESoapServer {
return $this->soapDoc->save($file);
}
}

@ -1,152 +1,168 @@
<?php
/**
* soap-wsa.php
*
* Copyright (c) 2007, Robert Richards <rrichards@ctindustries.net>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Robert Richards nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @author Robert Richards <rrichards@ctindustries.net>
* @copyright 2007 Robert Richards <rrichards@ctindustries.net>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version 1.0.0
*/
class WSASoap {
const WSANS = 'http://schemas.xmlsoap.org/ws/2004/08/addressing';
const WSAPFX = 'wsa';
private $soapNS, $soapPFX;
private $soapDoc = NULL;
private $envelope = NULL;
private $SOAPXPath = NULL;
private $header = NULL;
private $messageID = NULL;
private function locateHeader() {
if ($this->header == NULL) {
$headers = $this->SOAPXPath->query('//wssoap:Envelope/wssoap:Header');
$header = $headers->item(0);
if (! $header) {
$header = $this->soapDoc->createElementNS($this->soapNS, $this->soapPFX.':Header');
$this->envelope->insertBefore($header, $this->envelope->firstChild);
}
$this->header = $header;
}
return $this->header;
}
public function __construct($doc) {
$this->soapDoc = $doc;
$this->envelope = $doc->documentElement;
$this->soapNS = $this->envelope->namespaceURI;
$this->soapPFX = $this->envelope->prefix;
$this->SOAPXPath = new DOMXPath($doc);
$this->SOAPXPath->registerNamespace('wssoap', $this->soapNS);
<?php
/**
* soap-wsa.php
*
* Copyright (c) 2007, Robert Richards <rrichards@ctindustries.net>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Robert Richards nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @author Robert Richards <rrichards@ctindustries.net>
* @copyright 2007 Robert Richards <rrichards@ctindustries.net>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version 1.0.0
*/
/**
* Class WSASoap
*/
class WSASoap
{
const WSANS = 'http://schemas.xmlsoap.org/ws/2004/08/addressing';
const WSAPFX = 'wsa';
private $soapNS, $soapPFX;
private $soapDoc = null;
private $envelope = null;
private $SOAPXPath = null;
private $header = null;
private $messageID = null;
private function locateHeader()
{
if ($this->header == null) {
$headers = $this->SOAPXPath->query('//wssoap:Envelope/wssoap:Header');
$header = $headers->item(0);
if (!$header) {
$header = $this->soapDoc->createElementNS($this->soapNS, $this->soapPFX.':Header');
$this->envelope->insertBefore($header, $this->envelope->firstChild);
}
$this->header = $header;
}
return $this->header;
}
public function __construct($doc)
{
$this->soapDoc = $doc;
$this->envelope = $doc->documentElement;
$this->soapNS = $this->envelope->namespaceURI;
$this->soapPFX = $this->envelope->prefix;
$this->SOAPXPath = new DOMXPath($doc);
$this->SOAPXPath->registerNamespace('wssoap', $this->soapNS);
$this->SOAPXPath->registerNamespace('wswsa', self::WSANS);
$this->envelope->setAttributeNS("http://www.w3.org/2000/xmlns/", 'xmlns:'.self::WSAPFX, self::WSANS);
$this->locateHeader();
}
$this->locateHeader();
}
public function addAction($action) {
/* Add the WSA Action */
$header = $this->locateHeader();
public function addAction($action)
{
/* Add the WSA Action */
$header = $this->locateHeader();
$nodeAction = $this->soapDoc->createElementNS(self::WSANS, self::SAPFX.':Action', $action);
$header->appendChild($nodeAction);
}
public function addTo($location) {
/* Add the WSA To */
$header = $this->locateHeader();
$nodeTo = $this->soapDoc->createElementNS(WSASoap::WSANS, WSASoap::WSAPFX.':To', $location);
$header->appendChild($nodeTo);
}
private function createID() {
$uuid = md5(uniqid(rand(), true));
$guid = 'uudi:'.substr($uuid,0,8)."-".
substr($uuid,8,4)."-".
substr($uuid,12,4)."-".
substr($uuid,16,4)."-".
substr($uuid,20,12);
return $guid;
}
public function addMessageID($id=NULL) {
/* Add the WSA MessageID or return existing ID */
if (! is_null($this->messageID)) {
return $this->messageID;
}
if (empty($id)) {
$id = $this->createID();
}
$header = $this->locateHeader();
$header->appendChild($nodeAction);
}
public function addTo($location)
{
/* Add the WSA To */
$header = $this->locateHeader();
$nodeTo = $this->soapDoc->createElementNS(WSASoap::WSANS, WSASoap::WSAPFX.':To', $location);
$header->appendChild($nodeTo);
}
private function createID()
{
$uuid = md5(uniqid(rand(), true));
$guid = 'uudi:'.substr($uuid, 0, 8)."-".
substr($uuid, 8, 4)."-".
substr($uuid, 12, 4)."-".
substr($uuid, 16, 4)."-".
substr($uuid, 20, 12);
return $guid;
}
public function addMessageID($id = null)
{
/* Add the WSA MessageID or return existing ID */
if (!is_null($this->messageID)) {
return $this->messageID;
}
if (empty($id)) {
$id = $this->createID();
}
$header = $this->locateHeader();
$nodeID = $this->soapDoc->createElementNS(self::WSANS, self::WSAPFX.':MessageID', $id);
$header->appendChild($nodeID);
$this->messageID = $id;
}
public function addReplyTo($address = NULL) {
/* Create Message ID is not already added - required for ReplyTo */
if (is_null($this->messageID)) {
$this->addMessageID();
}
/* Add the WSA ReplyTo */
$header = $this->locateHeader();
$nodeReply = $this->soapDoc->createElementNS(self::WSANS, self::WSAPFX.':ReplyTo');
$header->appendChild($nodeReply);
if (empty($address)) {
$address = 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous';
}
$nodeAddress = $this->soapDoc->createElementNS(self::WSANS, self::WSAPFX.':Address', $address);
$nodeReply->appendChild($nodeAddress);
}
public function getDoc() {
return $this->soapDoc;
}
public function saveXML() {
return $this->soapDoc->saveXML();
}
public function save($file) {
return $this->soapDoc->save($file);
}
}
$header->appendChild($nodeID);
$this->messageID = $id;
}
public function addReplyTo($address = null)
{
/* Create Message ID is not already added - required for ReplyTo */
if (is_null($this->messageID)) {
$this->addMessageID();
}
/* Add the WSA ReplyTo */
$header = $this->locateHeader();
$nodeReply = $this->soapDoc->createElementNS(self::WSANS, self::WSAPFX.':ReplyTo');
$header->appendChild($nodeReply);
if (empty($address)) {
$address = 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous';
}
$nodeAddress = $this->soapDoc->createElementNS(self::WSANS, self::WSAPFX.':Address', $address);
$nodeReply->appendChild($nodeAddress);
}
public function getDoc()
{
return $this->soapDoc;
}
public function saveXML()
{
return $this->soapDoc->saveXML();
}
public function save($file)
{
return $this->soapDoc->save($file);
}
}

@ -43,37 +43,42 @@
use RobRichards\XMLSecLibs\XMLSecurityDSig;
use RobRichards\XMLSecLibs\XMLSecurityKey;
class WSSESoap {
/**
* Class WSSESoap
*/
class WSSESoap
{
const WSSENS = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
const WSUNS = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
const WSUNAME = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0';
const WSSEPFX = 'wsse';
const WSUPFX = 'wsu';
private $soapNS, $soapPFX;
private $soapDoc = NULL;
private $envelope = NULL;
private $SOAPXPath = NULL;
private $secNode = NULL;
public $signAllHeaders = FALSE;
private function locateSecurityHeader($bMustUnderstand = TRUE, $setActor = NULL) {
if ($this->secNode == NULL) {
private $soapDoc = null;
private $envelope = null;
private $SOAPXPath = null;
private $secNode = null;
public $signAllHeaders = false;
private function locateSecurityHeader($bMustUnderstand = true, $setActor = null)
{
if ($this->secNode == null) {
$headers = $this->SOAPXPath->query('//wssoap:Envelope/wssoap:Header');
$header = $headers->item(0);
if (! $header) {
if (!$header) {
$header = $this->soapDoc->createElementNS($this->soapNS, $this->soapPFX.':Header');
$this->envelope->insertBefore($header, $this->envelope->firstChild);
}
$secnodes = $this->SOAPXPath->query('./wswsse:Security', $header);
$secnode = NULL;
foreach ($secnodes AS $node) {
$secnode = null;
foreach ($secnodes as $node) {
$actor = $node->getAttributeNS($this->soapNS, 'actor');
if ($actor == $setActor) {
$secnode = $node;
break;
}
}
if (! $secnode) {
if (!$secnode) {
$secnode = $this->soapDoc->createElementNS(self::WSSENS, self::WSSEPFX.':Security');
///if (isset($secnode) && !empty($secnode)) {
$header->appendChild($secnode);
@ -94,7 +99,8 @@ class WSSESoap {
return $this->secNode;
}
public function __construct($doc, $bMustUnderstand = TRUE, $setActor=NULL) {
public function __construct($doc, $bMustUnderstand = true, $setActor = null)
{
$this->soapDoc = $doc;
$this->envelope = $doc->documentElement;
$this->soapNS = $this->envelope->namespaceURI;
@ -105,22 +111,32 @@ class WSSESoap {
$this->locateSecurityHeader($bMustUnderstand, $setActor);
}
public function addTimestamp($secondsToExpire=3600) {
public function addTimestamp($secondsToExpire = 3600)
{
/* Add the WSU timestamps */
$security = $this->locateSecurityHeader();
$timestamp = $this->soapDoc->createElementNS(self::WSUNS, self::WSUPFX.':Timestamp');
$security->insertBefore($timestamp, $security->firstChild);
$currentTime = time();
$created = $this->soapDoc->createElementNS(self::WSUNS, self::WSUPFX.':Created', gmdate("Y-m-d\TH:i:s", $currentTime).'Z');
$created = $this->soapDoc->createElementNS(
self::WSUNS,
self::WSUPFX.':Created',
gmdate("Y-m-d\TH:i:s", $currentTime).'Z'
);
$timestamp->appendChild($created);
if (! is_null($secondsToExpire)) {
$expire = $this->soapDoc->createElementNS(self::WSUNS, self::WSUPFX.':Expires', gmdate("Y-m-d\TH:i:s", $currentTime + $secondsToExpire).'Z');
if (!is_null($secondsToExpire)) {
$expire = $this->soapDoc->createElementNS(
self::WSUNS,
self::WSUPFX.':Expires',
gmdate("Y-m-d\TH:i:s", $currentTime + $secondsToExpire).'Z'
);
$timestamp->appendChild($expire);
}
}
public function addUserToken($userName, $password=NULL, $passwordDigest=FALSE) {
public function addUserToken($userName, $password = null, $passwordDigest = false)
{
if ($passwordDigest && empty($password)) {
throw new Exception("Cannot calculate the digest without a password");
}
@ -130,7 +146,7 @@ class WSSESoap {
$token = $this->soapDoc->createElementNS(self::WSSENS, self::WSSEPFX.':UsernameToken');
$security->insertBefore($token, $security->firstChild);
$username = $this->soapDoc->createElementNS(self::WSSENS, self::WSSEPFX.':Username', $userName);
$username = $this->soapDoc->createElementNS(self::WSSENS, self::WSSEPFX.':Username', $userName);
$token->appendChild($username);
/* Generate nonce - create a 256 bit session key to be used */
@ -142,37 +158,45 @@ class WSSESoap {
if ($password) {
$passType = self::WSUNAME.'#PasswordText';
if ($passwordDigest) {
$password = base64_encode(sha1($nonce.$createdate. $password, true));
$password = base64_encode(sha1($nonce.$createdate.$password, true));
$passType = self::WSUNAME.'#PasswordDigest';
}
$passwordNode = $this->soapDoc->createElementNS(self::WSSENS, self::WSSEPFX.':Password', $password);
$passwordNode = $this->soapDoc->createElementNS(self::WSSENS, self::WSSEPFX.':Password', $password);
$token->appendChild($passwordNode);
$passwordNode->setAttribute('Type', $passType);
}
$nonceNode = $this->soapDoc->createElementNS(self::WSSENS, self::WSSEPFX.':Nonce', base64_encode($nonce));
$nonceNode = $this->soapDoc->createElementNS(self::WSSENS, self::WSSEPFX.':Nonce', base64_encode($nonce));
$token->appendChild($nonceNode);
$created = $this->soapDoc->createElementNS(self::WSUNS, self::WSUPFX.':Created', $createdate);
$created = $this->soapDoc->createElementNS(self::WSUNS, self::WSUPFX.':Created', $createdate);
$token->appendChild($created);
}
public function addBinaryToken($cert, $isPEMFormat=TRUE, $isDSig=TRUE) {
public function addBinaryToken($cert, $isPEMFormat = true, $isDSig = true)
{
$security = $this->locateSecurityHeader();
$data = XMLSecurityDSig::get509XCert($cert, $isPEMFormat);
$token = $this->soapDoc->createElementNS(self::WSSENS, self::WSSEPFX.':BinarySecurityToken', $data);
$security->insertBefore($token, $security->firstChild);
$token->setAttribute('EncodingType', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary');
$token->setAttribute(
'EncodingType',
'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary'
);
$token->setAttributeNS(self::WSUNS, self::WSUPFX.':Id', XMLSecurityDSig::generate_GUID());
$token->setAttribute('ValueType', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3');
$token->setAttribute(
'ValueType',
'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3'
);
return $token;
}
public function attachTokentoSig($token) {
if (! ($token instanceof DOMElement)) {
public function attachTokentoSig($token)
{
if (!($token instanceof DOMElement)) {
throw new Exception('Invalid parameter: BinarySecurityToken element expected');
}
$objXMLSecDSig = new XMLSecurityDSig();
@ -182,7 +206,7 @@ class WSSESoap {
$query = "./secdsig:KeyInfo";
$nodeset = $this->SOAPXPath->query($query, $objDSig);
$keyInfo = $nodeset->item(0);
if (! $keyInfo) {
if (!$keyInfo) {
$keyInfo = $objXMLSecDSig->createNewSignNode('KeyInfo');
$objDSig->appendChild($keyInfo);
}
@ -197,28 +221,27 @@ class WSSESoap {
}
}
public function signSoapDoc($objKey, $options = NULL) {
public function signSoapDoc($objKey, $options = null)
{
$objDSig = new XMLSecurityDSig();
$objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);
$arNodes = array();
foreach ($this->secNode->childNodes AS $node) {
foreach ($this->secNode->childNodes as $node) {
if ($node->nodeType == XML_ELEMENT_NODE) {
$arNodes[] = $node;
}
}
if ($this->signAllHeaders) {
foreach ($this->secNode->parentNode->childNodes AS $node) {
foreach ($this->secNode->parentNode->childNodes as $node) {
if (($node->nodeType == XML_ELEMENT_NODE) &&
($node->namespaceURI != self::WSSENS)) {
($node->namespaceURI != self::WSSENS)) {
$arNodes[] = $node;
}
}
}
foreach ($this->envelope->childNodes AS $node) {
foreach ($this->envelope->childNodes as $node) {
if ($node->namespaceURI == $this->soapNS && $node->localName == 'Body') {
$arNodes[] = $node;
break;
@ -230,63 +253,70 @@ class WSSESoap {
$algorithm = $options["algorithm"];
}
$arOptions = array('prefix'=>self::WSUPFX, 'prefix_ns'=>self::WSUNS);
$objDSig->addReferenceList($arNodes, $algorithm, NULL, $arOptions);
$arOptions = array('prefix' => self::WSUPFX, 'prefix_ns' => self::WSUNS);
$objDSig->addReferenceList($arNodes, $algorithm, null, $arOptions);
$objDSig->sign($objKey);
$insertTop = TRUE;
$insertTop = true;
if (is_array($options) && isset($options["insertBefore"])) {
$insertTop = (bool)$options["insertBefore"];
}
$objDSig->appendSignature($this->secNode, $insertTop);
/* New suff */
/* New suff */
if (is_array($options)) {
if (! empty($options["KeyInfo"]) ) {
if (! empty($options["KeyInfo"]["X509SubjectKeyIdentifier"])) {
if (!empty($options["KeyInfo"])) {
if (!empty($options["KeyInfo"]["X509SubjectKeyIdentifier"])) {
$sigNode = $this->secNode->firstChild->nextSibling;
$objDoc = $sigNode->ownerDocument;
$keyInfo = $sigNode->ownerDocument->createElementNS(XMLSecurityDSig::XMLDSIGNS, 'ds:KeyInfo');
$sigNode->appendChild($keyInfo);
$tokenRef = $objDoc->createElementNS(self::WSSENS, self::WSSEPFX . ':SecurityTokenReference');
$keyInfo->appendChild($tokenRef);
$reference = $objDoc->createElementNS(self::WSSENS, self::WSSEPFX . ':KeyIdentifier');
$reference->setAttribute("ValueType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier");
$reference->setAttribute("EncodingType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
$tokenRef = $objDoc->createElementNS(self::WSSENS, self::WSSEPFX.':SecurityTokenReference');
$keyInfo->appendChild($tokenRef);
$reference = $objDoc->createElementNS(self::WSSENS, self::WSSEPFX.':KeyIdentifier');
$reference->setAttribute(
"ValueType",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier"
);
$reference->setAttribute(
"EncodingType",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
);
$tokenRef->appendChild($reference);
$x509 = openssl_x509_parse($objKey->getX509Certificate());
$keyid = $x509["extensions"]["subjectKeyIdentifier"];
$arkeyid = split(":", $keyid);
$data = "";
foreach ($arkeyid AS $hexchar) {
$data .= chr(hexdec($hexchar));
}
$dataNode = new DOMText(base64_encode($data));
$reference->appendChild($dataNode);
$x509 = openssl_x509_parse($objKey->getX509Certificate());
$keyid = $x509["extensions"]["subjectKeyIdentifier"];
$arkeyid = split(":", $keyid);
$data = "";
foreach ($arkeyid as $hexchar) {
$data .= chr(hexdec($hexchar));
}
$dataNode = new DOMText(base64_encode($data));
$reference->appendChild($dataNode);
}
}
}
}
public function addEncryptedKey($node, $key, $token, $options = NULL) {
if (! $key->encKey) {
return FALSE;
public function addEncryptedKey($node, $key, $token, $options = null)
{
if (!$key->encKey) {
return false;
}
$encKey = $key->encKey;
$security = $this->locateSecurityHeader();
$doc = $security->ownerDocument;
if (! $doc->isSameNode($encKey->ownerDocument)) {
$key->encKey = $security->ownerDocument->importNode($encKey, TRUE);
if (!$doc->isSameNode($encKey->ownerDocument)) {
$key->encKey = $security->ownerDocument->importNode($encKey, true);
$encKey = $key->encKey;
}
if (! empty($key->guid)) {
return TRUE;
if (!empty($key->guid)) {
return true;
}
$lastToken = NULL;
$lastToken = null;
$findTokens = $security->firstChild;
while ($findTokens) {
if ($findTokens->localName == 'BinarySecurityToken') {
@ -313,24 +343,31 @@ class WSSESoap {
$encKey->insertBefore($keyInfo, $encMethod);
$tokenRef = $objDoc->createElementNS(self::WSSENS, self::WSSEPFX.':SecurityTokenReference');
$keyInfo->appendChild($tokenRef);
/* New suff */
/* New suff */
if (is_array($options)) {
if (! empty($options["KeyInfo"]) ) {
if (! empty($options["KeyInfo"]["X509SubjectKeyIdentifier"])) {
$reference = $objDoc->createElementNS(self::WSSENS, self::WSSEPFX . ':KeyIdentifier');
$reference->setAttribute("ValueType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier");
$reference->setAttribute("EncodingType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
$tokenRef->appendChild($reference);
$x509 = openssl_x509_parse($token->getX509Certificate());
$keyid = $x509["extensions"]["subjectKeyIdentifier"];
$arkeyid = split(":", $keyid);
$data = "";
foreach ($arkeyid AS $hexchar) {
$data .= chr(hexdec($hexchar));
}
$dataNode = new DOMText(base64_encode($data));
$reference->appendChild($dataNode);
return TRUE;
if (!empty($options["KeyInfo"])) {
if (!empty($options["KeyInfo"]["X509SubjectKeyIdentifier"])) {
$reference = $objDoc->createElementNS(self::WSSENS, self::WSSEPFX.':KeyIdentifier');
$reference->setAttribute(
"ValueType",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier"
);
$reference->setAttribute(
"EncodingType",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
);
$tokenRef->appendChild($reference);
$x509 = openssl_x509_parse($token->getX509Certificate());
$keyid = $x509["extensions"]["subjectKeyIdentifier"];
$arkeyid = split(":", $keyid);
$data = "";
foreach ($arkeyid as $hexchar) {
$data .= chr(hexdec($hexchar));
}
$dataNode = new DOMText(base64_encode($data));
$reference->appendChild($dataNode);
return true;
}
}
}
@ -340,13 +377,14 @@ class WSSESoap {
$reference->setAttribute("URI", $tokenURI);
$tokenRef->appendChild($reference);
return TRUE;
return true;
}
public function AddReference($baseNode, $guid) {
$refList = NULL;
public function AddReference($baseNode, $guid)
{
$refList = null;
$child = $baseNode->firstChild;
while($child) {
while ($child) {
if (($child->namespaceURI == XMLSecEnc::XMLENCNS) && ($child->localName == 'ReferenceList')) {
$refList = $child;
break;
@ -363,18 +401,18 @@ class WSSESoap {
$dataref->setAttribute('URI', '#'.$guid);
}
public function EncryptBody($siteKey, $objKey, $token) {
public function EncryptBody($siteKey, $objKey, $token)
{
$enc = new XMLSecEnc();
$node = false;
foreach ($this->envelope->childNodes AS $node) {
foreach ($this->envelope->childNodes as $node) {
if ($node->namespaceURI == $this->soapNS && $node->localName == 'Body') {
break;
}
}
$enc->setNode($node);
/* encrypt the symmetric key */
$enc->encryptKey($siteKey, $objKey, FALSE);
$enc->encryptKey($siteKey, $objKey, false);
$enc->type = XMLSecEnc::Content;
/* Using the symmetric key to actually encrypt the data */
@ -384,7 +422,7 @@ class WSSESoap {
$encNode->setAttribute('Id', $guid);
$refNode = $encNode->firstChild;
while($refNode && $refNode->nodeType != XML_ELEMENT_NODE) {
while ($refNode && $refNode->nodeType != XML_ELEMENT_NODE) {
$refNode = $refNode->nextSibling;
}
if ($refNode) {
@ -395,104 +433,107 @@ class WSSESoap {
}
}
public function encryptSoapDoc($siteKey, $objKey, $options=NULL, $encryptSignature=TRUE) {
$enc = new XMLSecEnc();
public function encryptSoapDoc($siteKey, $objKey, $options = null, $encryptSignature = true)
{
$enc = new XMLSecEnc();
$xpath = new DOMXPath($this->envelope->ownerDocument);
if ($encryptSignature == FALSE) {
$nodes = $xpath->query('//*[local-name()="Body"]');
} else {
$nodes = $xpath->query('//*[local-name()="Signature"] | //*[local-name()="Body"]');
}
$xpath = new DOMXPath($this->envelope->ownerDocument);
if ($encryptSignature == false) {
$nodes = $xpath->query('//*[local-name()="Body"]');
} else {
$nodes = $xpath->query('//*[local-name()="Signature"] | //*[local-name()="Body"]');
}
foreach ($nodes AS $node) {
$type = XMLSecEnc::Element;
$name = $node->localName;
if ($name == "Body") {
$type = XMLSecEnc::Content;
}
$enc->addReference($name, $node, $type);
}
foreach ($nodes as $node) {
$type = XMLSecEnc::Element;
$name = $node->localName;
if ($name == "Body") {
$type = XMLSecEnc::Content;
}
$enc->addReference($name, $node, $type);
}
$enc->encryptReferences($objKey);
$enc->encryptReferences($objKey);
$enc->encryptKey($siteKey, $objKey, false);
$enc->encryptKey($siteKey, $objKey, false);
$nodes = $xpath->query('//*[local-name()="Security"]');
$signode = $nodes->item(0);
$this->addEncryptedKey($signode, $enc, $siteKey, $options);
$nodes = $xpath->query('//*[local-name()="Security"]');
$signode = $nodes->item(0);
$this->addEncryptedKey($signode, $enc, $siteKey, $options);
}
public function decryptSoapDoc($doc, $options) {
$privKey = NULL;
$privKey_isFile = FALSE;
$privKey_isCert = FALSE;
if (is_array($options)) {
$privKey = (! empty($options["keys"]["private"]["key"]) ? $options["keys"]["private"]["key"] : NULL);
$privKey_isFile = (! empty($options["keys"]["private"]["isFile"]) ? TRUE : FALSE);
$privKey_isCert = (! empty($options["keys"]["private"]["isCert"]) ? TRUE : FALSE);
}
$objenc = new XMLSecEnc();
$xpath = new DOMXPath($doc);
$envns = $doc->documentElement->namespaceURI;
$xpath->registerNamespace("soapns", $envns);
$xpath->registerNamespace("soapenc", "http://www.w3.org/2001/04/xmlenc#");
$nodes = $xpath->query('/soapns:Envelope/soapns:Header/*[local-name()="Security"]/soapenc:EncryptedKey');
$references = array();
if ($node = $nodes->item(0)) {
$objenc = new XMLSecEnc();
$objenc->setNode($node);
if (! $objKey = $objenc->locateKey()) {
throw new Exception("Unable to locate algorithm for this Encrypted Key");
}
$objKey->isEncrypted = TRUE;
$objKey->encryptedCtx = $objenc;
XMLSecEnc::staticLocateKeyInfo($objKey, $node);
if ($objKey && $objKey->isEncrypted) {
$objencKey = $objKey->encryptedCtx;
$objKey->loadKey($privKey, $privKey_isFile, $privKey_isCert);
$key = $objencKey->decryptKey($objKey);
$objKey->loadKey($key);
}
$refnodes = $xpath->query('./soapenc:ReferenceList/soapenc:DataReference/@URI', $node);
foreach ($refnodes as $reference) {
$references[] = $reference->nodeValue;
}
}
foreach ($references AS $reference) {
$arUrl = parse_url($reference);
$reference = $arUrl['fragment'];
$query = '//*[@Id="'.$reference.'"]';
$nodes = $xpath->query($query);
$encData = $nodes->item(0);
if ($algo = $xpath->evaluate("string(./soapenc:EncryptionMethod/@Algorithm)", $encData)) {
$objKey = new XMLSecurityKey($algo);
$objKey->loadKey($key);
}
$objenc->setNode($encData);
$objenc->type = $encData->getAttribute("Type");
$decrypt = $objenc->decryptNode($objKey, TRUE);
}
return TRUE;
public function decryptSoapDoc($doc, $options)
{
$privKey = null;
$privKey_isFile = false;
$privKey_isCert = false;
if (is_array($options)) {
$privKey = (!empty($options["keys"]["private"]["key"]) ? $options["keys"]["private"]["key"] : null);
$privKey_isFile = (!empty($options["keys"]["private"]["isFile"]) ? true : false);
$privKey_isCert = (!empty($options["keys"]["private"]["isCert"]) ? true : false);
}
$objenc = new XMLSecEnc();
$xpath = new DOMXPath($doc);
$envns = $doc->documentElement->namespaceURI;
$xpath->registerNamespace("soapns", $envns);
$xpath->registerNamespace("soapenc", "http://www.w3.org/2001/04/xmlenc#");
$nodes = $xpath->query('/soapns:Envelope/soapns:Header/*[local-name()="Security"]/soapenc:EncryptedKey');
$references = array();
if ($node = $nodes->item(0)) {
$objenc = new XMLSecEnc();
$objenc->setNode($node);
if (!$objKey = $objenc->locateKey()) {
throw new Exception("Unable to locate algorithm for this Encrypted Key");
}
$objKey->isEncrypted = true;
$objKey->encryptedCtx = $objenc;
XMLSecEnc::staticLocateKeyInfo($objKey, $node);
if ($objKey && $objKey->isEncrypted) {
$objencKey = $objKey->encryptedCtx;
$objKey->loadKey($privKey, $privKey_isFile, $privKey_isCert);
$key = $objencKey->decryptKey($objKey);
$objKey->loadKey($key);
}
$refnodes = $xpath->query('./soapenc:ReferenceList/soapenc:DataReference/@URI', $node);
foreach ($refnodes as $reference) {
$references[] = $reference->nodeValue;
}
}
foreach ($references as $reference) {
$arUrl = parse_url($reference);
$reference = $arUrl['fragment'];
$query = '//*[@Id="'.$reference.'"]';
$nodes = $xpath->query($query);
$encData = $nodes->item(0);
if ($algo = $xpath->evaluate("string(./soapenc:EncryptionMethod/@Algorithm)", $encData)) {
$objKey = new XMLSecurityKey($algo);
$objKey->loadKey($key);
}
$objenc->setNode($encData);
$objenc->type = $encData->getAttribute("Type");
$decrypt = $objenc->decryptNode($objKey, true);
}
return true;
}
public function saveXML() {
public function saveXML()
{
return $this->soapDoc->saveXML();
}
public function save($file) {
public function save($file)
{
return $this->soapDoc->save($file);
}
}

Loading…
Cancel
Save