/**
  * 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;
 }
Esempio n. 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());
    }
Esempio n. 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());
        }
    }
}
Esempio n. 4
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();
Esempio n. 5
0
File: client.php Progetto: ztobs/wsf
 * 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.
 */
$reqPayloadString = <<<XML
<ns1:echo xmlns:ns1="http://wso2.org/wsfphp/samples"><text>Hello World!</text></ns1:echo>
XML;
try {
    $rec_cert = ws_get_cert_from_file("../keys/bob_cert.cert");
    $pvt_key = ws_get_key_from_file("../keys/alice_key.pem");
    $reqMessage = new WSMessage($reqPayloadString, array("to" => "http://localhost/samples/security/encryption/service.php", "action" => "http://wso2.org/wsfphp/samples/echoString"));
    $sec_array = array("encrypt" => TRUE, "algorithmSuite" => "Basic256Rsa15", "securityTokenReference" => "IssuerSerial");
    $policy = new WSPolicy(array("security" => $sec_array));
    $sec_token = new WSSecurityToken(array("privateKey" => $pvt_key, "receiverCertificate" => $rec_cert));
    $client = new WSClient(array("useWSA" => TRUE, "policy" => $policy, "securityToken" => $sec_token));
    $resMessage = $client->request($reqMessage);
    printf("Response = %s \n", $resMessage->str);
} catch (Exception $e) {
    if ($e instanceof WSFault) {
        printf("Soap Fault: %s\n", $e->Reason);
    } else {
        printf("Message = %s\n", $e->getMessage());
    }
}
Esempio n. 6
0
         <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 {
    /* Load the design*/
    $f = file_get_contents("./design.jpg");
    /* Build the message*/
    $requestMessage = new WSMessage($requestPayloadString, array("to" => "http://localhost:8080/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);
    /* Print the response*/
    echo $responseMessage->str;
} catch (Exception $e) {
    if ($e instanceof WSFault) {
        printf("Soap Fault: %s\n", $e->Reason);
    } else {
Esempio n. 7
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();