Subversion Repositories Sigmater

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6 Andrea 1
<?
2
 
3
	// client con soap FIRMATA:
4
	// firmo richiesta e imbusto come attachment
5
 
6
	// FIRMA IL FILE
7
	$attachment_filename = tempnam('./Log','XML_');
8
	$signed_filename = tempnam('./Log', 'P7M_');
9
 
10
    if(!write_file($attachment_filename,$xml)) {
11
 
12
    	@unlink($attachment_filename);
13
    	echo 'Errore scrittura file XML: '.$attachment_filename;
14
    }
15
 
16
	if (!openssl_pkcs7_sign($attachment_filename, $signed_filename, CERT_ENTE, $arr_privkey, $arr_header, PKCS7_TEXT + PKCS7_DETACHED)) {
17
 
18
		while($msg = openssl_error_string())
19
			$err.= $msg;
20
 
21
	    @unlink($signed_filename);
22
	    @unlink($attachment_filename);
23
 
24
		echo $err;
25
	}
26
	else {
27
 
28
		require_once('SOAP/Client.php');
29
 
30
		$soapclient = new SOAP_Client($url);
31
 
32
		$DatiXmlRequest = new SOAP_Attachment('{'.NS_WSDL.'}'.$operation, 'text/xml', $signed_filename);
33
 
34
		$methodValue = new SOAP_Value('DatiXmlattach', 'Struct', array($DatiXmlRequest));
35
 
36
		$arr_Segnatura = get_segnatura_client();
37
		$header = new SOAP_Header('{'.NS_HEADER.'}Segnatura', 'Struct', $arr_Segnatura, 1, "");
38
 
39
		// creazione SOAP headers
40
		$soapclient->addHeader($header);
41
 
42
		// questi sono gli header nella richiesta http
43
		$arr_headers = array();
44
		$options = array('Attachments'=>'Mime', 'namespace' => NS_WSDL, 'trace' => 1, 'style' => 'document', 'use' => 'literal', 'headers' => $arr_headers, 'timeout' => 300, 'soapaction' => 'http://www.agenziaterritorio.it/ws/transazionali');
45
 
46
		// chiamata al web service
47
		$ritorno = $soapclient->call("", $DatiXmlRequest, $options);
48
 
49
		@unlink($signed_filename);
50
	    @unlink($attachment_filename);
51
 
52
/*
53
echo '<pre>';
54
print htmlentities($soapclient->__get_wire());
55
echo '</pre>';
56
*/
57
 
58
		if (PEAR::isError($ritorno)) {
59
 
60
            //print 'Errore: <b>'.$ritorno->getMessage().'</b>';
61
            if (strstr(strtoupper($ritorno->code), 'CLIENT.NODATA'))
62
            	echo(' - CLIENT.NODATA');
63
 
64
			print ('<BR> <BR>');
65
            //exit;
66
  		}
67
        else {
68
 
69
			$part_to_verify = $ritorno;
70
 
71
            print '<b>RISPOSTA RICEVUTA</b>';
72
            print ('<BR> <BR>');
73
 
74
			// Verifica della firma
75
			$server_cert_filename = tempnam ("./Log", "CERT_");
76
 
77
            $ret = verify($part_to_verify, $server_cert_filename);
78
 
79
            //$arr_cert_data = read_cert($server_cert_filename);
80
            //show($arr_cert_data);
81
 
82
            // Test sulla verifica della firma
83
            if ($ret === false) {
84
                print '<b>FIRMA NON VERIFICATA</b>';
85
            }
86
            elseif ($ret === -1) {
87
                print '<b>ERRORE VERIFICA FIRMA</b>';
88
            }
89
            elseif ($ret === true) {
90
                print '<b>FIRMA VERIFICATA</b>';
91
                print ('<BR> ');
92
 
93
				$struct_pkcs7 = decode_pkcs7($part_to_verify);
94
 
95
			    $ritorno = $struct_pkcs7->parts[0]->body;
96
 
97
				/*
98
            	$dati_cert  = read_cert($server_cert_filename);
99
 
100
		 		echo "utente: ".$dati_cert["name"];
101
		 		echo "<br>";
102
		 		echo "issuer: ".$dati_cert["issuer"]["CN"];
103
		 		echo "<br>";
104
		 		echo "serial: ".$dati_cert["serialNumber"];
105
		 		echo "<br>";
106
		 		echo "server_cert_filename: ".$server_cert_filename;
107
		 		echo "<br>";
108
		 		*/
109
 
110
			}
111
			else {
112
                print '<b>ERRORE FIRMA NON PREVISTO</b>';
113
                print ('<BR> ');
114
			}
115
 
116
			@unlink($server_cert_filename);
117
 
118
		} // se pear_error
119
	} // se sign
120
?>