/**
  * Devuelve un objeto WSF con la configuracion de certificados ssl existente o null
  * @param string $proyecto
  * @param string $servicio
  * @throws toba_error
  * @return WSSecurityToken
  */
 static function get_ws_token($proyecto, $servicio)
 {
     $security_token = null;
     self::get_modelo_proyecto($proyecto);
     $ini_conf = toba_modelo_servicio_web::get_ini_cliente(self::$modelo_proyecto, $servicio);
     $directorio = toba_instancia::instancia()->get_path_instalacion_proyecto($proyecto) . "/servicios_cli/{$servicio}";
     //Directorio perteneciente al servicio
     //Busco los datos para los certificados en el archivo perteneciente al servicio
     if (!is_null($ini_conf) && $ini_conf->existe_entrada('certificado')) {
         chdir($directorio);
         $config = $ini_conf->get_datos_entrada('certificado');
         //Cargo las claves y armo el objeto WSF
         if (!file_exists($config['clave_cliente'])) {
             throw new toba_error("El archivo " . $config['clave_cliente'] . " no existe");
         }
         $clave_cliente = ws_get_key_from_file($config['clave_cliente']);
         if (!file_exists($config['cert_cliente'])) {
             throw new toba_error("El archivo " . $config['cert_cliente'] . " no existe");
         }
         $cert_cliente = ws_get_cert_from_file($config['cert_cliente']);
         if (!file_exists($config['cert_servidor'])) {
             throw new toba_error("El archivo " . $config['cert_servidor'] . " no existe");
         }
         $cert_server = ws_get_cert_from_file($config['cert_servidor']);
         $security_token = new WSSecurityToken(array("privateKey" => $clave_cliente, "receiverCertificate" => $cert_server, "certificate" => $cert_cliente));
     }
     return $security_token;
 }
Exemple #2
0
    /**
     * Seguridad programada completamente
     */
    function evt__form__enviar($datos)
    {
        $carpeta = dirname(__FILE__);
        //--1- Arma el mensaje	(incluyendo los headers)
        $this->s__echo = $datos;
        $clave = xml_encode($datos['clave']);
        $valor = xml_encode($datos['valor']);
        $payload = <<<XML
<ns1:test xmlns:ns1="http://siu.edu.ar/toba_referencia/serv_pruebas">
\t<texto>{$clave} {$valor}</texto>
</ns1:test>
XML;
        $mensaje = new toba_servicio_web_mensaje($payload);
        //--2- Arma el servicio indicando certificado del server y clave privada del cliente
        $cert_server = ws_get_cert_from_file($carpeta . '/servidor.crt');
        $clave_privada = ws_get_key_from_file($carpeta . "/cliente.pkey");
        $cert_cliente = ws_get_cert_from_file($carpeta . "/cliente.crt");
        $seguridad = array("sign" => true, "encrypt" => true, "algorithmSuite" => "Basic256Rsa15", "securityTokenReference" => "IssuerSerial");
        $policy = new WSPolicy(array("security" => $seguridad));
        $security_token = new WSSecurityToken(array("privateKey" => $clave_privada, "receiverCertificate" => $cert_server, "certificate" => $cert_cliente));
        $opciones = array('to' => 'http://localhost/' . toba_recurso::url_proyecto() . '/servicios.php/serv_seguro_codigo', 'action' => 'http://siu.edu.ar/toba_referencia/serv_pruebas/test', 'policy' => $policy, 'securityToken' => $security_token);
        $servicio = toba::servicio_web('cli_seguro', $opciones);
        //-- 3 - Muestra la respuesta
        $respuesta = $servicio->request($mensaje);
        toba::notificacion()->info($respuesta->get_payload());
    }
Exemple #3
0
function requestBags()
{
    /* Generate a random number for the purchase order*/
    $randNum = rand() % 99;
    /* Requested date is two weeks from today*/
    $reqDate = mktime(0, 0, 0, date("m"), date("d") + 14, date("Y"));
    $reqDateStr = date("Y/m/d", $reqDate);
    /* The payload string*/
    $requestPayloadString = <<<XML
          <po:Order xmlns:po="http://www.back_packers.com/ws/purchaseorder">
             <po:OrderId>po-{$randNum}</po:OrderId>
             <po:ReqDate>{$reqDateStr}</po:ReqDate>
             <po:Design>
                <po:FileName>design.jpg</po:FileName>
                <po:Image><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:myid1"></xop:Include></po:Image>
             </po:Design>
          </po:Order>
XML;
    try {
        global $request_str;
        global $response_str;
        /* Load the design*/
        $f = file_get_contents("./design.jpg");
        /* Build the message*/
        $requestMessage = new WSMessage($requestPayloadString, array("to" => "http://localhost/solutions/store/manuf_service.php", "action" => "http://www.back_packers.com/purchaseOrder", "attachments" => array("myid1" => $f)));
        /* Load certificates and keys*/
        $rec_cert = ws_get_cert_from_file("keys/bob_cert.cert");
        $my_cert = ws_get_cert_from_file("keys/alice_cert.cert");
        $my_key = ws_get_key_from_file("keys/alice_key.pem");
        /* Load policy file*/
        $policy_xml = file_get_contents("policy.xml");
        $policy = new WSPolicy($policy_xml);
        /* Ceate a security token with reqd configurations*/
        $sec_token = new WSSecurityToken(array("user" => "Alice", "password" => "abcd!1234", "passwordType" => "Digest", "privateKey" => $my_key, "certificate" => $my_cert, "receiverCertificate" => $rec_cert));
        /* Create a new client*/
        $client = new WSClient(array("useWSA" => TRUE, "useMTOM" => FALSE, "policy" => $policy, "securityToken" => $sec_token));
        /* Request*/
        $responseMessage = $client->request($requestMessage);
        /* to track the messages */
        $request_str = $client->getLastRequest();
        $response_str = $client->getLastResponse();
        $request_str = format_xml($request_str);
        $response_str = format_xml($response_str);
        /* Print the response*/
        print "<div id=\"message\">More Backpacks requested : The purchase order number is {$responseMessage->str}</div>";
    } catch (Exception $e) {
        if ($e instanceof WSFault) {
            printf("Soap Fault: %s\n", $e->Reason);
        } else {
            printf("Message = %s\n", $e->getMessage());
        }
    }
}
Exemple #4
0
 static function get_opciones()
 {
     $carpeta = dirname(__FILE__);
     //Agrego los certificados manualmente
     $cert_cliente = ws_get_cert_from_file($carpeta . "/cliente.crt");
     $cert_server = ws_get_cert_from_file($carpeta . '/servidor.crt');
     $clave_privada = ws_get_cert_from_file($carpeta . "/servidor.pkey");
     $seguridad = array("sign" => true, "encrypt" => true, "algorithmSuite" => "Basic256Rsa15", "securityTokenReference" => "IssuerSerial");
     $policy = new WSPolicy(array("security" => $seguridad));
     $security = new WSSecurityToken(array("privateKey" => $clave_privada, "certificate" => $cert_server));
     return array("seguro" => true, "policy" => $policy, "securityToken" => $security, 'actions' => array("http://siu.edu.ar/toba_referencia/serv_pruebas/test" => "test"));
 }
Exemple #5
0
 /**
  * @ignore Metodo interno que llama la solicitud web para obtener las configuraciones del servicio 
  */
 public static function _get_opciones($id, $clase)
 {
     $seguro = false;
     self::cargar_ini($id);
     $directorio = toba_instancia::get_path_instalacion_proyecto(toba::proyecto()->get_id()) . "/servicios_serv/{$id}";
     if (isset(self::$ini)) {
         chdir($directorio);
         if (self::$ini->existe_entrada('conexion')) {
             self::$opciones = self::$ini->get_datos_entrada('conexion');
         }
         if (self::$ini->existe_entrada('certificado')) {
             $seguridad = array("sign" => true, "encrypt" => true, "algorithmSuite" => "Basic256Rsa15", "securityTokenReference" => "IssuerSerial");
             $policy = new WSPolicy(array("security" => $seguridad));
             //Agrego los certificados manualmente
             if (!file_exists(self::$ini->get("certificado", "clave_servidor"))) {
                 throw new toba_error("El archivo " . self::$ini->get("certificado", "clave_servidor") . " no existe");
             }
             $clave_privada = ws_get_cert_from_file(self::$ini->get("certificado", "clave_servidor"));
             if (!file_exists(self::$ini->get("certificado", "cert_servidor"))) {
                 throw new toba_error("El archivo " . self::$ini->get("certificado", "cert_servidor") . " no existe");
             }
             $certificado_servidor = ws_get_cert_from_file(self::$ini->get("certificado", "cert_servidor"));
             $certificados = array("privateKey" => $clave_privada, "certificate" => $certificado_servidor);
             $security = new WSSecurityToken($certificados);
             self::$opciones['policy'] = $policy;
             self::$opciones['securityToken'] = $security;
             $seguro = true;
         }
         //Averiguo los IDs de firmas definidos
         foreach (self::$ini->get_entradas() as $entrada => $valores) {
             if (strpos($entrada, '=')) {
                 if (file_exists($valores['archivo'])) {
                     $pares = array();
                     foreach (explode(",", $entrada) as $par) {
                         list($clave, $valor) = explode('=', trim($par));
                         $pares[$clave] = $valor;
                     }
                     self::agregar_mapeo_firmas(realpath($valores['archivo']), $pares, $valores['fingerprint']);
                 } else {
                     throw new toba_error("El archivo {$valores['archivo']} no existe");
                 }
             }
         }
     }
     self::$opciones = array_merge(self::$opciones, call_user_func(array($clase, 'get_opciones')));
     return self::$opciones;
 }
Exemple #6
0
<?php

/*
 * Copyright 2005,2008 WSO2, Inc. http://wso2.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
function echoFunction($inMessage)
{
    $returnMessage = new WSMessage($inMessage->str);
    return $returnMessage;
}
$cert = ws_get_cert_from_file("../../keys/bob_cert.cert");
$pvt_key = ws_get_key_from_file("../../keys/bob_key.pem");
$operations = array("echoString" => "echoFunction");
$policy_xml = file_get_contents("policy.xml");
$policy = new WSPolicy($policy_xml);
$sec_token = new WSSecurityToken(array("privateKey" => $pvt_key, "certificate" => $cert));
$actions = array("http://wso2.org/wsfphp/samples/echoString" => "echoString");
$svr = new WSService(array("operations" => $operations, "actions" => $actions, "policy" => $policy, "securityToken" => $sec_token));
$svr->reply();
<?php

function echoFunction($inMessage)
{
    $returnMessage = new WSMessage($inMessage->str);
    return $returnMessage;
}
$pub_key = ws_get_cert_from_file("keys/alice_cert.cert");
$pvt_key = ws_get_key_from_file("keys/bob_key.pem");
$operations = array("echoString" => "echoFunction");
$sec_array = array("encrypt" => TRUE, "algorithmSuite" => "Basic128Rsa15", "securityTokenReference" => "IssuerSerial");
$actions = array("http://php.axis2.org/samples/echoString" => "echoString");
$policy = new WSPolicy(array("security" => $sec_array));
$sec_token = new WSSecurityToken(array("privateKey" => $pvt_key, "ttl" => 300, "receiverCertificate" => $pub_key));
$svr = new WSService(array("actions" => $actions, "operations" => $operations, "policy" => $policy, "securityToken" => $sec_token));
$svr->reply();
Exemple #8
0
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// Request payload string
$reqPayloadString = <<<XML
<ns1:echo xmlns:ns1="http://wso2.org/wsfphp/samples"><text>Hello World!</text></ns1:echo>
XML;
try {
    $my_cert = ws_get_cert_from_file("../keys/alice_cert.cert");
    $my_key = ws_get_key_from_file("../keys/alice_key.pem");
    // Create message with request payload and options
    $reqMessage = new WSMessage($reqPayloadString, array("to" => "http://localhost/samples/security/username_token/service.php", "action" => "http://php.axis2.org/samples/echoString"));
    // Set up security options
    $security_options = array("useUsernameToken" => TRUE);
    $policy = new WSPolicy(array("security" => $security_options));
    $security_token = new WSSecurityToken(array("user" => "Raigama", "password" => "RaigamaPW", "passwordType" => "Digest", "privateKey" => $my_key, "certificate" => $my_cert));
    // Create client with options
    $client = new WSClient(array("useWSA" => TRUE, "policy" => $policy, "securityToken" => $security_token));
    // Send request and capture response
    $resMessage = $client->request($reqMessage);
    printf("Response = %s \n", $resMessage->str);
} catch (Exception $e) {
    if ($e instanceof WSFault) {
        printf("Soap Fault: %s\n", $e->Reason);
Exemple #9
0
        $poElems = $dom->documentElement->getElementsByTagName('OrderId');
        $poElem = $poElems->item(0);
        $purchaseOrderNum = $poElem->nodeValue;
    }
    /* The response payload*/
    $resPayload = <<<XML
      <manuf:RecievedOrder xmlns:manuf="http://www.factory.com/ws/purchaseOrder">
         <manuf:OrderId>{$purchaseOrderNum}</manuf:OrderId>
      </manuf:RecievedOrder>
XML;
    /* Create a response message*/
    $returnMessage = new WSMessage($resPayload);
    return $returnMessage;
}
/* Load certificates/keys*/
$rec_cert = ws_get_cert_from_file("keys/alice_cert.cert");
$my_key = ws_get_key_from_file("keys/bob_key.pem");
$my_cert = ws_get_key_from_file("keys/bob_cert.cert");
/*Function mapping = manuf*/
$operations = array("purchaseOrder" => "manuf");
/* Load and create a policy*/
$policy_xml = file_get_contents("policy.xml");
$policy = new WSPolicy($policy_xml);
/* Create a security token*/
$sec_token = new WSSecurityToken(array("passwordType" => "Digest", "password" => "abcd!1234", "user" => "Alice", "privateKey" => $my_key, "certificate" => $my_cert, "receiverCertificate" => $rec_cert));
/* Define actions*/
$actions = array("http://www.back_packers.com/purchaseOrder" => "purchaseOrder");
/* Create a new service*/
$svr = new WSService(array("actions" => $actions, "operations" => $operations, "policy" => $policy, "requestXOP" => TRUE, "securityToken" => $sec_token));
/* Reply*/
$svr->reply();