Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6 | Andrea | 1 | <? |
2 | ////////////////////////////////////////////////////////////////////////////////////// |
||
3 | ////////////////////////////////////////////////////////////////////////////////////// |
||
4 | // COSTANTI DA RIDEFINIRE |
||
5 | ////////////////////////////////////////////////////////////////////////////////////// |
||
6 | ////////////////////////////////////////////////////////////////////////////////////// |
||
7 | //define('FILE_CA', '/opt/web/php/sigmater/sec/Cert_CA.pem'); |
||
8 | define('FILE_CA', '/home/sigmater/SitoWeb/sigmater/TEU_Test/sec/Cert_CA.pem'); |
||
9 | |||
10 | //define('CERT_ENTE', 'file:///opt/web/php/sigmater/sec/Cert_Ente.pem'); |
||
11 | define('CERT_ENTE', 'file:///home/sigmater/SitoWeb/sigmater/TEU_Test/sec/Cert_Ente.pem'); |
||
12 | |||
13 | //define('PK_ENTE', 'file:///opt/web/php/sigmater/sec/Pk_Ente.pem'); |
||
14 | define('PK_ENTE', 'file:///home/sigmater/SitoWeb/sigmater/TEU_Test/sec/Pk_Ente.pem'); |
||
15 | |||
16 | //define('PK_PWD', 'liguria_07112007'); |
||
17 | define('PK_PWD', 'regioneliguria_0408'); |
||
18 | |||
19 | define('ADDR_SERVER', 'https://catasto.tel.agenziaterritorio.it'); |
||
20 | |||
21 | ////////////////////////////////////////////////////////////////////////////////////// |
||
22 | ////////////////////////////////////////////////////////////////////////////////////// |
||
23 | |||
24 | $template_dir = "../template"; |
||
25 | |||
26 | $url = ADDR_SERVER.'/php/ws/N0SC_soap_dispatcher.php?coduff=GE'; |
||
27 | |||
28 | define('NS_WSDL', 'http://www.agenziaterritorio.it/ws.wsdl'); |
||
29 | define('NS_HEADER', 'http://www.agenziaterritorio.it/segnatura.xsd'); |
||
30 | |||
31 | $arr_privkey = array(PK_ENTE, PK_PWD); |
||
32 | $arr_header = array(); |
||
33 | |||
34 | $logfile = "./Log/wslog.log"; |
||
35 | $debug = true; |
||
36 | $default_log_level = PEAR_LOG_DEBUG; |
||
37 | |||
38 | function read_cert($cert_filename) { |
||
39 | |||
40 | if (!file_exists($cert_filename)) |
||
41 | { |
||
42 | return array(); |
||
43 | } |
||
44 | |||
45 | $pemdata = implode('', file($cert_filename)); |
||
46 | |||
47 | // Get a certificate resource from the PEM string. |
||
48 | $cert_handler = openssl_x509_read($pemdata); |
||
49 | |||
50 | // Parse the resource |
||
51 | $arr_cert_data = openssl_x509_parse($cert_handler); |
||
52 | |||
53 | // Free the resource |
||
54 | openssl_x509_free($cert_handler); |
||
55 | |||
56 | return $arr_cert_data; |
||
57 | |||
58 | } |
||
59 | |||
60 | function get_segnatura_client() { |
||
61 | |||
62 | $arr_Identificatore = array('CodiceAmministrazione' => '', |
||
63 | 'CodiceAOO' => '', |
||
64 | 'NumeroRegistrazione' => '', |
||
65 | 'DataRegistrazione' => ''); |
||
66 | |||
67 | // ------------------ |
||
68 | $arr_Ruolo = array('Denominazione' => 'Text', |
||
69 | 'Identificativo' => ''); |
||
70 | |||
71 | $arr_Amministrazione = array('Denominazione' => '', |
||
72 | 'CodiceAmministrazione' => '', |
||
73 | 'Ruolo' => $arr_Ruolo); |
||
74 | |||
75 | $arr_Mittente = array('Amministrazione' => $arr_Amministrazione, |
||
76 | 'AOO' => ''); |
||
77 | |||
78 | $arr_Origine = array('IndirizzoTelematico' => '', |
||
79 | 'Mittente' => $arr_Mittente); |
||
80 | // ------------------ |
||
81 | |||
82 | $arr_Destinazione = array('IndirizzoTelematico' => ''); |
||
83 | |||
84 | // ------------------ |
||
85 | |||
86 | |||
87 | $arr_Intestazione = array('Identificatore' => $arr_Identificatore, |
||
88 | 'Origine' => $arr_Origine, |
||
89 | 'Destinazione' => $arr_Destinazione, |
||
90 | 'Oggetto' => ''); |
||
91 | // ------------------ |
||
92 | $arr_Segnatura = array('Intestazione' => $arr_Intestazione); |
||
93 | |||
94 | return $arr_Segnatura; |
||
95 | } |
||
96 | |||
97 | function write_file($fname,$buf) { |
||
98 | |||
99 | $fn = fopen($fname,"a+"); |
||
100 | $b = fwrite($fn,$buf); |
||
101 | fclose($fn); |
||
102 | return($b); |
||
103 | } |
||
104 | |||
105 | function verify($pkcs7, $cert_filename) { |
||
106 | |||
107 | // salvo l'allegato su file per poterne verificare la firma |
||
108 | $to_verify_filename = tempnam('./Log', 'P7M_'); |
||
109 | |||
110 | $fp = fopen($to_verify_filename, "w"); |
||
111 | fwrite($fp, $pkcs7); |
||
112 | fclose($fp); |
||
113 | |||
114 | $cainfo[0] = FILE_CA; |
||
115 | |||
116 | // verifica della firma |
||
117 | $ret = openssl_pkcs7_verify($to_verify_filename, 0, $cert_filename, $cainfo); |
||
118 | //$ret = openssl_pkcs7_verify($to_verify_filename, 0, $cert_filename, $cainfo); |
||
119 | |||
120 | @unlink($to_verify_filename); |
||
121 | |||
122 | // log errori openssl_pkcs7_verify |
||
123 | while($msg = openssl_error_string()) |
||
124 | error_log (date("d/m/Y H:i:s")." - VERIFICA FIRMA - ".$msg."\n",3,'./Log/openssl_error.log'); |
||
125 | |||
126 | return $ret; |
||
127 | } |
||
128 | |||
129 | function show($var) { |
||
130 | |||
131 | echo"<br>show<pre>"; |
||
132 | print_r($var); |
||
133 | echo'</pre><br>'; |
||
134 | } |
||
135 | |||
136 | function decode_pkcs7($pkcs7) { |
||
137 | |||
138 | require_once('Mail/mimeDecode.php'); |
||
139 | |||
140 | $params['include_bodies'] = TRUE; |
||
141 | $params['decode_bodies'] = TRUE; |
||
142 | $params['decode_headers'] = TRUE; |
||
143 | $params['crlf'] = "\r\n"; |
||
144 | |||
145 | $decode = new Mail_mimeDecode($pkcs7); |
||
146 | $structure = $decode->decode($params); |
||
147 | |||
148 | return $structure; |
||
149 | } |
||
150 | |||
151 | function clear_dir($dir) { |
||
152 | |||
153 | $dir = rtrim($dir, '/'); |
||
154 | |||
155 | if (is_dir($dir)) { |
||
156 | |||
157 | $dh = opendir($dir); |
||
158 | |||
159 | while (false !== ($file = readdir($dh))) { |
||
160 | |||
161 | if ($file != '.' && $file != '..') { |
||
162 | |||
163 | $path = $dir.'/'.$file; |
||
164 | |||
165 | if (is_dir($path)) |
||
166 | clear_dir($path); |
||
167 | else |
||
168 | unlink($path); |
||
169 | } |
||
170 | } |
||
171 | |||
172 | return true; |
||
173 | } |
||
174 | else { |
||
175 | |||
176 | return false; |
||
177 | } |
||
178 | } |
||
179 | ?> |