@@ -97,10 +97,30 @@ $wsseMiddleware = new WsseMiddleware(
97
97
);
98
98
```
99
99
100
- #### Signing a SOAP request with PKCS12 or X509 certificate.
100
+ ### Key stores
101
101
102
- This is one of the most common implementation of WSS out there.
103
- You are granted a certificate by the soap service with which you need to fetch data.
102
+ This package provides a couple of ` Key ` wrappers that can be used to pass private / public keys:
103
+
104
+ * ` KeyStore\Certificate ` : Contains a public X.509 certificate in PEM format.
105
+ * ` KeyStore\Key ` : Contains a PKCS_8 private key in PEM format.
106
+ * ` KeyStore\ClientCertificate ` : Contains both a public X.509 certificate and PKCS_8 private key in PEM format.
107
+
108
+ Example:
109
+
110
+ ``` php
111
+ use Soap\Psr18WsseMiddleware\WSSecurity\KeyStore\Certificate;
112
+ use Soap\Psr18WsseMiddleware\WSSecurity\KeyStore\ClientCertificate;
113
+ use Soap\Psr18WsseMiddleware\WSSecurity\KeyStore\Key;
114
+
115
+ $privKey = Key::fromFile('security_token.priv')->withPassphrase('xxx'); // Regular private key (not wrapped in X509)
116
+ $pubKey = Certificate::fromFile('security_token.pub'); // Public X509 cert
117
+
118
+ // or:
119
+
120
+ $bundle = ClientCertificate::fromFile('client-certificate.pem')->withPassphrase('xxx');
121
+ $privKey = $bunlde->privateKey();
122
+ $pubKey = $bunlde->publicCertificate();
123
+ ```
104
124
105
125
In case of a p12 certificate: convert it to a private key and public X509 certificate first:
106
126
@@ -109,6 +129,11 @@ openssl pkcs12 -in your.p12 -out security_token.pub -clcerts -nokeys
109
129
openssl pkcs12 -in your.p12 -out security_token.priv -nocerts -nodes
110
130
```
111
131
132
+ #### Signing a SOAP request with PKCS12 or X509 certificate.
133
+
134
+ This is one of the most common implementation of WSS out there.
135
+ You are granted a certificate by the soap service with which you need to fetch data.
136
+
112
137
Next, you can configure the middleware like this:
113
138
114
139
``` php
@@ -120,8 +145,8 @@ use Soap\Psr18WsseMiddleware\WSSecurity\KeyIdentifier;
120
145
use Soap\Psr18WsseMiddleware\WsseMiddleware;
121
146
use Soap\Psr18WsseMiddleware\WSSecurity\Entry;
122
147
123
- $privKey = Key::fromFile('security_token.priv')->withPassphrase('xxx'); // Regular private key (not wrapped in X509)
124
- $pubKey = Certificate::fromFile('security_token.pub'); // Public X509 cert
148
+ $privKey = Key::fromFile('security_token.priv')->withPassphrase('xxx');
149
+ $pubKey = Certificate::fromFile('security_token.pub');
125
150
126
151
$wsseMiddleware = new WsseMiddleware(
127
152
outgoing: [
@@ -162,7 +187,7 @@ use Soap\Psr18WsseMiddleware\WSSecurity\Entry;
162
187
use VeeWee\Xml\Dom\Document;
163
188
use function VeeWee\Xml\Dom\Locator\document_element;
164
189
165
- $privKey = Key::fromFile('security_token.priv')->withPassphrase('xxx'); // Regular private key (not wrapped in X509)
190
+ $privKey = Key::fromFile('security_token.priv')->withPassphrase('xxx');
166
191
167
192
// These are provided through the STS service.
168
193
$samlAssertion = Document::fromXmlString(<<<EOXML
@@ -227,7 +252,7 @@ use Soap\Psr18WsseMiddleware\WSSecurity\KeyIdentifier;
227
252
use Soap\Psr18WsseMiddleware\WsseMiddleware;
228
253
use Soap\Psr18WsseMiddleware\WSSecurity\Entry;
229
254
230
- $privKey = Key::fromFile('security_token.priv')->withPassphrase('xxx'); // Regular private key (not wrapped in X509)
255
+ $privKey = Key::fromFile('security_token.priv')->withPassphrase('xxx'); // Private key
231
256
$pubKey = Certificate::fromFile('security_token.pub'); // Public X509 cert
232
257
$signKey = Certificate::fromFile('sign-key.pem'); // X509 cert for signing. Could be the same as $pubKey.
233
258
0 commit comments