Skip to content

Commit ed2346d

Browse files
committed
Random id & tests
1 parent 8c85f73 commit ed2346d

File tree

12 files changed

+356
-2
lines changed

12 files changed

+356
-2
lines changed

ext/soap/php_soap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,5 +260,6 @@ static zend_always_inline zval *php_soap_deref(zval *zv) {
260260
#define Z_CLIENT_WSS_TIMESTAMP_EXPIRES_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 40))
261261
#define Z_CLIENT_WSS_DIGEST_METHOD_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 41))
262262
#define Z_CLIENT_WSS_VERSION_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 42))
263+
#define Z_CLIENT_WSS_RANDOM_ID_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 43))
263264

264265
#endif

ext/soap/php_wss.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ static int add_reference_to_signed_info(zval *this_ptr, xmlNodePtr signed_info,
119119
void add_wss_to_function_call(zval *this_ptr, int soap_version, xmlNodePtr envelope, xmlNodePtr head, xmlNodePtr body) /* {{{ */
120120
{
121121
char random_s[10];
122-
sprintf(random_s, "%d", (int)php_mt_rand_common(100000000,999999999));
122+
if (Z_TYPE_P(Z_CLIENT_WSS_RANDOM_ID_P(this_ptr)) == IS_TRUE) {
123+
sprintf(random_s, "%d", (int)php_mt_rand_common(100000000,999999999));
124+
} else {
125+
sprintf(random_s, "%d", 1);
126+
}
123127

124128
zend_string *body_id = zend_string_concat2(
125129
"BodyID-", strlen("BodyID-"),

ext/soap/soap.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,6 +2836,7 @@ PHP_METHOD(SoapClient, __setWSS)
28362836
convert_to_null(Z_CLIENT_WSS_TIMESTAMP_EXPIRES_P(this_ptr));
28372837
convert_to_null(Z_CLIENT_WSS_DIGEST_METHOD_P(this_ptr));
28382838
convert_to_null(Z_CLIENT_WSS_VERSION_P(this_ptr));
2839+
ZVAL_TRUE(Z_CLIENT_WSS_RANDOM_ID_P(this_ptr));
28392840
}
28402841

28412842
if (options != NULL && !processed) {
@@ -2931,6 +2932,16 @@ PHP_METHOD(SoapClient, __setWSS)
29312932
}
29322933
}
29332934

2935+
if ((tmp = zend_hash_str_find(ht, "random_id", sizeof("random_id")-1)) != NULL) {
2936+
if (Z_TYPE_P(tmp) == IS_FALSE) {
2937+
ZVAL_FALSE(Z_CLIENT_WSS_RANDOM_ID_P(this_ptr));
2938+
} else if (Z_TYPE_P(tmp) != IS_TRUE) {
2939+
zend_type_error("%s(): \"random_id\" must be of type bool, %s given", get_active_function_name(), zend_zval_type_name(tmp));
2940+
success = 0;
2941+
goto cleanup;
2942+
}
2943+
}
2944+
29342945
if (success && wss_set) {
29352946
if ((tmp = zend_hash_str_find(ht, "wss_version", sizeof("wss_version")-1)) != NULL) {
29362947
if (Z_TYPE_P(tmp) == IS_LONG) {

ext/soap/soap.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class SoapClient
137137
private ?int $_wss_timestamp_expires = null;
138138
private ?int $_wss_digest_method = null;
139139
private ?int $_wss_version = null;
140+
private bool $_wss_random_id = true;
140141

141142
public function __construct(?string $wsdl, array $options = []) {}
142143

ext/soap/soap_arginfo.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 9be909ecc245d559096af1fba97ff2634211caca */
2+
* Stub hash: 653d3384207f336026346fcfc531ee40cf0fa5dd */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_use_soap_error_handler, 0, 0, _IS_BOOL, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, enable, _IS_BOOL, 0, "true")
@@ -682,5 +682,11 @@ static zend_class_entry *register_class_SoapClient(void)
682682
zend_declare_typed_property(class_entry, property__wss_version_name, &property__wss_version_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG|MAY_BE_NULL));
683683
zend_string_release(property__wss_version_name);
684684

685+
zval property__wss_random_id_default_value;
686+
ZVAL_BOOL(&property__wss_random_id_default_value, 1);
687+
zend_string *property__wss_random_id_name = zend_string_init("_wss_random_id", sizeof("_wss_random_id") - 1, 1);
688+
zend_declare_typed_property(class_entry, property__wss_random_id_name, &property__wss_random_id_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL));
689+
zend_string_release(property__wss_random_id_name);
690+
685691
return class_entry;
686692
}

ext/soap/tests/wss/T01.phpt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--TEST--
2+
SOAP CLIENT WSS: WSS 1.0 SHA1 echo
3+
--EXTENSIONS--
4+
soap
5+
--INI--
6+
soap.wsdl_cache_enabled=0
7+
--FILE--
8+
<?php
9+
include __DIR__.DIRECTORY_SEPARATOR."wss-test.inc";
10+
11+
$client = new LocalSoapClient(__DIR__.DIRECTORY_SEPARATOR."wss-test.wsdl");
12+
13+
$client->__setWSS(array(
14+
"random_id" => false,
15+
"x509_binsectoken" => "TEST CERTIFICATE",
16+
"signfunc" => function($data) {
17+
return "TEST SIGNATURE";
18+
}
19+
));
20+
21+
$client->testFunction(array(
22+
"Param1" => "foo",
23+
"Param2" => "bar"
24+
));
25+
?>
26+
--EXPECTF--
27+
<?xml version="1.0" encoding="UTF-8"?>
28+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
29+
%w<SOAP-ENV:Header>
30+
%w<wsse:Security SOAP-ENV:mustUnderstand="1">
31+
%w<wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="TokenID-1">VEVTVCBDRVJUSUZJQ0FURQ==</wsse:BinarySecurityToken>
32+
%w<ds:Signature>
33+
%w<ds:SignedInfo>
34+
%w<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
35+
%w<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
36+
%w<ds:Reference URI="#BodyID-1">
37+
%w<ds:Transforms>
38+
%w<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
39+
%w</ds:Transforms>
40+
%w<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
41+
%w<ds:DigestValue>OaQiUDsEKrCjytgTUqF4CLsB9jo=</ds:DigestValue>
42+
%w</ds:Reference>
43+
%w</ds:SignedInfo>
44+
%w<ds:SignatureValue>VEVTVCBTSUdOQVRVUkU=</ds:SignatureValue>
45+
%w<ds:KeyInfo>
46+
%w<wsse:SecurityTokenReference>
47+
%w<wsse:Reference URI="#TokenID-1" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
48+
%w</wsse:SecurityTokenReference>
49+
%w</ds:KeyInfo>
50+
%w</ds:Signature>
51+
%w</wsse:Security>
52+
%w</SOAP-ENV:Header>
53+
%w<SOAP-ENV:Body wsu:Id="BodyID-1">
54+
%w<ns1:testFunctionIn>
55+
%w<ns1:Param1>foo</ns1:Param1>
56+
%w<ns1:Param2>bar</ns1:Param2>
57+
%w</ns1:testFunctionIn>
58+
%w</SOAP-ENV:Body>
59+
</SOAP-ENV:Envelope>

ext/soap/tests/wss/T02.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
SOAP CLIENT WSS: Remove WSS headers echo
3+
--EXTENSIONS--
4+
soap
5+
--INI--
6+
soap.wsdl_cache_enabled=0
7+
--FILE--
8+
<?php
9+
include __DIR__.DIRECTORY_SEPARATOR."wss-test.inc";
10+
11+
$client = new LocalSoapClient(__DIR__.DIRECTORY_SEPARATOR."wss-test.wsdl");
12+
13+
$client->__setWSS(array(
14+
"x509_binsectoken" => "TEST CERTIFICATE",
15+
"signfunc" => function($data) {
16+
return "TEST SIGNATURE";
17+
}
18+
));
19+
20+
$client->__setWSS();
21+
22+
$client->testFunction(array(
23+
"Param1" => "foo",
24+
"Param2" => "bar"
25+
));
26+
?>
27+
--EXPECTF--
28+
<?xml version="1.0" encoding="UTF-8"?>
29+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/">
30+
%w<SOAP-ENV:Body>
31+
%w<ns1:testFunctionIn>
32+
%w<ns1:Param1>foo</ns1:Param1>
33+
%w<ns1:Param2>bar</ns1:Param2>
34+
%w</ns1:testFunctionIn>
35+
%w</SOAP-ENV:Body>
36+
</SOAP-ENV:Envelope>

ext/soap/tests/wss/T03.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
SOAP CLIENT WSS: No WSS headers echo
3+
--EXTENSIONS--
4+
soap
5+
--INI--
6+
soap.wsdl_cache_enabled=0
7+
--FILE--
8+
<?php
9+
include __DIR__.DIRECTORY_SEPARATOR."wss-test.inc";
10+
11+
$client = new LocalSoapClient(__DIR__.DIRECTORY_SEPARATOR."wss-test.wsdl");
12+
13+
$client->testFunction(array(
14+
"Param1" => "foo",
15+
"Param2" => "bar"
16+
));
17+
?>
18+
--EXPECTF--
19+
<?xml version="1.0" encoding="UTF-8"?>
20+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/">
21+
%w<SOAP-ENV:Body>
22+
%w<ns1:testFunctionIn>
23+
%w<ns1:Param1>foo</ns1:Param1>
24+
%w<ns1:Param2>bar</ns1:Param2>
25+
%w</ns1:testFunctionIn>
26+
%w</SOAP-ENV:Body>
27+
</SOAP-ENV:Envelope>

ext/soap/tests/wss/T04.phpt

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
--TEST--
2+
SOAP CLIENT WSS: WSS 1.1 SHA256 with timestamp and random id echo
3+
--EXTENSIONS--
4+
soap
5+
--INI--
6+
soap.wsdl_cache_enabled=0
7+
--FILE--
8+
<?php
9+
include __DIR__.DIRECTORY_SEPARATOR."wss-test.inc";
10+
11+
$client = new LocalSoapClient(__DIR__.DIRECTORY_SEPARATOR."wss-test.wsdl");
12+
13+
$client->__setWSS(array(
14+
"add_timestamp" => true,
15+
"timestamp_expires" => 300,
16+
"digest_method" => SOAP_WSS_DIGEST_METHOD_SHA256,
17+
"wss_version" => SOAP_WSS_VERSION_1_1,
18+
"x509_binsectoken" => "TEST CERTIFICATE",
19+
"signfunc" => function($data) {
20+
return "TEST SIGNATURE";
21+
}
22+
));
23+
24+
$client->testFunction(array(
25+
"Param1" => "foo",
26+
"Param2" => "bar"
27+
));
28+
?>
29+
--EXPECTF--
30+
<?xml version="1.0" encoding="UTF-8"?>
31+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/" xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
32+
%w<SOAP-ENV:Header>
33+
%w<wsse11:Security SOAP-ENV:mustUnderstand="1">
34+
%w<wsu:Timestamp wsu:Id="TimestampID-%i">
35+
%w<wsu:Created>%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c</wsu:Created>
36+
%w<wsu:Expires>%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c</wsu:Expires>
37+
%w</wsu:Timestamp>
38+
%w<wsse11:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="TokenID-%i">%s</wsse11:BinarySecurityToken>
39+
%w<ds:Signature>
40+
%w<ds:SignedInfo>
41+
%w<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
42+
%w<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
43+
%w<ds:Reference URI="#TimestampID-%i">
44+
%w<ds:Transforms>
45+
%w<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
46+
%w</ds:Transforms>
47+
%w<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
48+
%w<ds:DigestValue>%s</ds:DigestValue>
49+
%w</ds:Reference>
50+
%w<ds:Reference URI="#BodyID-%i">
51+
%w<ds:Transforms>
52+
%w<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
53+
%w</ds:Transforms>
54+
%w<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
55+
%w<ds:DigestValue>%s</ds:DigestValue>
56+
%w</ds:Reference>
57+
%w</ds:SignedInfo>
58+
%w<ds:SignatureValue>%s</ds:SignatureValue>
59+
%w<ds:KeyInfo>
60+
%w<wsse11:SecurityTokenReference>
61+
%w<wsse11:Reference URI="#TokenID-%i" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
62+
%w</wsse11:SecurityTokenReference>
63+
%w</ds:KeyInfo>
64+
%w</ds:Signature>
65+
%w</wsse11:Security>
66+
%w</SOAP-ENV:Header>
67+
%w<SOAP-ENV:Body wsu:Id="BodyID-%i">
68+
%w<ns1:testFunctionIn>
69+
%w<ns1:Param1>foo</ns1:Param1>
70+
%w<ns1:Param2>bar</ns1:Param2>
71+
%w</ns1:testFunctionIn>
72+
%w</SOAP-ENV:Body>
73+
</SOAP-ENV:Envelope>

ext/soap/tests/wss/T05.phpt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
--TEST--
2+
SOAP CLIENT WSS: WSS 1.1 SHA512 with additional header echo
3+
--EXTENSIONS--
4+
soap
5+
--INI--
6+
soap.wsdl_cache_enabled=0
7+
--FILE--
8+
<?php
9+
include __DIR__.DIRECTORY_SEPARATOR."wss-test.inc";
10+
11+
$client = new LocalSoapClient(__DIR__.DIRECTORY_SEPARATOR."wss-test.wsdl");
12+
13+
$client->__setWSS(array(
14+
"random_id" => false,
15+
"digest_method" => SOAP_WSS_DIGEST_METHOD_SHA512,
16+
"wss_version" => SOAP_WSS_VERSION_1_1,
17+
"x509_binsectoken" => "TEST CERTIFICATE",
18+
"signfunc" => function($data) {
19+
return "TEST SIGNATURE";
20+
}
21+
));
22+
23+
$client->__setSoapHeaders(array(
24+
new SoapHeader(
25+
'http://localhost/header/',
26+
'TestHeader1',
27+
'Hello'
28+
),
29+
new SoapHeader(
30+
'http://localhost/header/',
31+
'TestHeader2',
32+
'World'
33+
),
34+
));
35+
36+
$client->testFunction(array(
37+
"Param1" => "foo",
38+
"Param2" => "bar"
39+
));
40+
?>
41+
--EXPECTF--
42+
<?xml version="1.0" encoding="UTF-8"?>
43+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/" xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:ns2="http://localhost/header/">
44+
%w<SOAP-ENV:Header>
45+
%w<wsse11:Security SOAP-ENV:mustUnderstand="1">
46+
%w<wsse11:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="TokenID-1">%s</wsse11:BinarySecurityToken>
47+
%w<ds:Signature>
48+
%w<ds:SignedInfo>
49+
%w<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
50+
%w<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
51+
%w<ds:Reference URI="#BodyID-1">
52+
%w<ds:Transforms>
53+
%w<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
54+
%w</ds:Transforms>
55+
%w<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha512"/>
56+
%w<ds:DigestValue>%s</ds:DigestValue>
57+
%w</ds:Reference>
58+
%w</ds:SignedInfo>
59+
%w<ds:SignatureValue>%s</ds:SignatureValue>
60+
%w<ds:KeyInfo>
61+
%w<wsse11:SecurityTokenReference>
62+
%w<wsse11:Reference URI="#TokenID-1" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
63+
%w</wsse11:SecurityTokenReference>
64+
%w</ds:KeyInfo>
65+
%w</ds:Signature>
66+
%w</wsse11:Security>
67+
%w<ns2:TestHeader1>Hello</ns2:TestHeader1>
68+
%w<ns2:TestHeader2>World</ns2:TestHeader2>
69+
%w</SOAP-ENV:Header>
70+
%w<SOAP-ENV:Body wsu:Id="BodyID-1">
71+
%w<ns1:testFunctionIn>
72+
%w<ns1:Param1>foo</ns1:Param1>
73+
%w<ns1:Param2>bar</ns1:Param2>
74+
%w</ns1:testFunctionIn>
75+
%w</SOAP-ENV:Body>
76+
</SOAP-ENV:Envelope>

ext/soap/tests/wss/wss-test.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
class LocalSoapClient extends SoapClient {
3+
public function __doRequest(string $request, string $location, string $action, int $version, bool $oneWay = false): ?string {
4+
$doc = new DOMDocument();
5+
$doc->preserveWhiteSpace = false;
6+
$doc->formatOutput = true;
7+
$doc->loadXML($request);
8+
die($doc->saveXML());
9+
}
10+
}

0 commit comments

Comments
 (0)