@@ -44,9 +44,7 @@ protected function validate()
44
44
{
45
45
$ in = escapeshellarg ($ this ->getPathname ());
46
46
47
- $ command = "openssl pkcs12 -in $ in -passin pass: -noout " ;
48
-
49
- $ process = new Process ($ command );
47
+ $ process = new Process ("openssl pkcs12 -in $ in -passin pass: -noout " );
50
48
$ process ->run ();
51
49
52
50
$ invalidPassword = false !== strpos ($ process ->getErrorOutput (), 'invalid password ' );
@@ -85,18 +83,17 @@ public static function create($path, $passPhrase, PublicKeyFile $publicKeyFile,
85
83
$ privateKeyInForm = escapeshellarg ($ privateKeyFile ->getFormat ());
86
84
$ privateKeyPass = escapeshellarg ($ privateKeyPassPhrase );
87
85
88
- $ command = "
89
- {
90
- openssl rsa -in $ privateKeyIn -inform $ privateKeyInForm -passin pass: $ privateKeyPass -passout pass:pipe -des3
91
- openssl x509 -in $ publicKeyIn -inform $ publicKeyInForm
92
- } |
93
- openssl pkcs12 -passin pass:pipe -out $ out~ -passout pass: $ pass -export &&
94
- mv --force $ out~ $ out ||
95
- rm --force $ out~ " ;
86
+ $ process1 = new Process ("openssl rsa -in $ privateKeyIn -inform $ privateKeyInForm -passin pass: $ privateKeyPass -passout pass:pipe -des3 " );
87
+ $ process1 ->mustRun ();
88
+
89
+ $ process2 = new Process ("openssl x509 -in $ publicKeyIn -inform $ publicKeyInForm " );
90
+ $ process2 ->mustRun ();
96
91
97
- $ process = new Process ($ command );
98
- $ process ->mustRun ();
92
+ $ process3 = new Process ("openssl pkcs12 -passin pass:pipe -passout pass: $ pass -export " );
93
+ $ process3 ->setInput ($ process1 ->getOutput () . $ process2 ->getOutput ());
94
+ $ process3 ->mustRun ();
99
95
96
+ @file_put_contents ($ path , $ process3 ->getOutput ());
100
97
@chmod ($ path , 0666 & ~umask ());
101
98
102
99
return new self ($ path );
@@ -125,19 +122,21 @@ public function getPem($path, $passPhrase)
125
122
$ rsaPassOut = '' ;
126
123
}
127
124
128
- $ command = "
129
- {
130
- openssl pkcs12 -in $ in -passin pass: $ pass -nokeys |
131
- openssl x509
132
- openssl pkcs12 -in $ in -passin pass: $ pass -nocerts -passout pass:pipe |
133
- openssl rsa -passin pass:pipe $ rsaPassOut
134
- } > $ out ~ &&
135
- mv --force $ out ~ $ out ||
136
- rm --force $ out ~ " ;
125
+ $ process1 = new Process ( " openssl pkcs12 -in $ in -passin pass: $ pass -nokeys " );
126
+ $ process1 -> mustRun ();
127
+
128
+ $ process2 = new Process ( " openssl x509 " );
129
+ $ process2 -> setInput ( $ process1 -> getOutput ());
130
+ $ process2 -> mustRun ();
131
+
132
+ $ process3 = new Process ( " openssl pkcs12 -in $ in -passin pass: $ pass -nocerts -passout pass:pipe " );
133
+ $ process3 -> mustRun () ;
137
134
138
- $ process = new Process ($ command );
139
- $ process ->mustRun ();
135
+ $ process4 = new Process ("openssl rsa -passin pass:pipe $ rsaPassOut " );
136
+ $ process4 ->setInput ($ process3 ->getOutput ());
137
+ $ process4 ->mustRun ();
140
138
139
+ @file_put_contents ($ path , $ process2 ->getOutput () . $ process4 ->getOutput ());
141
140
@chmod ($ path , 0666 & ~umask ());
142
141
143
142
return new PemFile ($ path );
@@ -159,15 +158,14 @@ public function getPublicKey($path, $passPhrase)
159
158
$ out = escapeshellarg ($ path );
160
159
$ pass = escapeshellarg ($ passPhrase );
161
160
162
- $ command = "
163
- openssl pkcs12 -in $ in -passin pass: $ pass -nokeys |
164
- openssl x509 -out $ out~ &&
165
- mv --force $ out~ $ out ||
166
- rm --force $ out~ " ;
161
+ $ process1 = new Process ("openssl pkcs12 -in $ in -passin pass: $ pass -nokeys " );
162
+ $ process1 ->mustRun ();
167
163
168
- $ process = new Process ($ command );
169
- $ process ->mustRun ();
164
+ $ process2 = new Process ("openssl x509 " );
165
+ $ process2 ->setInput ($ process1 ->getOutput ());
166
+ $ process2 ->mustRun ();
170
167
168
+ @file_put_contents ($ path , $ process2 ->getOutput ());
171
169
@chmod ($ path , 0666 & ~umask ());
172
170
173
171
return new PublicKeyFile ($ path );
@@ -199,15 +197,14 @@ public function getPrivateKey($path, $passPhrase)
199
197
$ rsaPassOut = '' ;
200
198
}
201
199
202
- $ command = "
203
- openssl pkcs12 -in $ in -passin pass: $ pass -nocerts -passout pass:pipe |
204
- openssl rsa -passin pass:pipe -out $ out~ $ rsaPassOut &&
205
- mv --force $ out~ $ out ||
206
- rm --force $ out~ " ;
200
+ $ process1 = new Process ("openssl pkcs12 -in $ in -passin pass: $ pass -nocerts -passout pass:pipe " );
201
+ $ process1 ->mustRun ();
207
202
208
- $ process = new Process ($ command );
209
- $ process ->mustRun ();
203
+ $ process2 = new Process ("openssl rsa -passin pass:pipe $ rsaPassOut " );
204
+ $ process2 ->setInput ($ process1 ->getOutput ());
205
+ $ process2 ->mustRun ();
210
206
207
+ @file_put_contents ($ path , $ process2 ->getOutput ());
211
208
@chmod ($ path , 0666 & ~umask ());
212
209
213
210
return new PrivateKeyFile ($ path );
@@ -227,14 +224,14 @@ public function getSubject($passPhrase)
227
224
$ in = escapeshellarg ($ this ->getPathname ());
228
225
$ pass = escapeshellarg ($ passPhrase );
229
226
230
- $ command = "
231
- openssl pkcs12 -in $ in -passin pass: $ pass -nokeys |
232
- openssl x509 -noout -subject " ;
227
+ $ process1 = new Process ("openssl pkcs12 -in $ in -passin pass: $ pass -nokeys " );
228
+ $ process1 ->mustRun ();
233
229
234
- $ process = new Process ($ command );
235
- $ process ->mustRun ();
230
+ $ process2 = new Process ('openssl x509 -noout -subject ' );
231
+ $ process2 ->setInput ($ process1 ->getOutput ());
232
+ $ process2 ->mustRun ();
236
233
237
- return trim (preg_replace ('/^subject=/ ' , '' , $ process ->getOutput ()));
234
+ return trim (preg_replace ('/^subject=/ ' , '' , $ process2 ->getOutput ()));
238
235
}
239
236
240
237
/**
@@ -251,14 +248,14 @@ public function getIssuer($passPhrase)
251
248
$ in = escapeshellarg ($ this ->getPathname ());
252
249
$ pass = escapeshellarg ($ passPhrase );
253
250
254
- $ command = "
255
- openssl pkcs12 -in $ in -passin pass: $ pass -nokeys |
256
- openssl x509 -noout -issuer " ;
251
+ $ process1 = new Process ("openssl pkcs12 -in $ in -passin pass: $ pass -nokeys " );
252
+ $ process1 ->mustRun ();
257
253
258
- $ process = new Process ($ command );
259
- $ process ->mustRun ();
254
+ $ process2 = new Process ('openssl x509 -noout -issuer ' );
255
+ $ process2 ->setInput ($ process1 ->getOutput ());
256
+ $ process2 ->mustRun ();
260
257
261
- return trim (preg_replace ('/^issuer=/ ' , '' , $ process ->getOutput ()));
258
+ return trim (preg_replace ('/^issuer=/ ' , '' , $ process2 ->getOutput ()));
262
259
}
263
260
264
261
/**
@@ -275,14 +272,14 @@ public function getNotBefore($passPhrase)
275
272
$ in = escapeshellarg ($ this ->getPathname ());
276
273
$ pass = escapeshellarg ($ passPhrase );
277
274
278
- $ command = "
279
- openssl pkcs12 -in $ in -passin pass: $ pass -nokeys |
280
- openssl x509 -noout -startdate " ;
275
+ $ process1 = new Process ("openssl pkcs12 -in $ in -passin pass: $ pass -nokeys " );
276
+ $ process1 ->mustRun ();
281
277
282
- $ process = new Process ($ command );
283
- $ process ->mustRun ();
278
+ $ process2 = new Process ('openssl x509 -noout -startdate ' );
279
+ $ process2 ->setInput ($ process1 ->getOutput ());
280
+ $ process2 ->mustRun ();
284
281
285
- return new \DateTime (trim (preg_replace ('/^notBefore=/ ' , '' , $ process ->getOutput ())));
282
+ return new \DateTime (trim (preg_replace ('/^notBefore=/ ' , '' , $ process2 ->getOutput ())));
286
283
}
287
284
288
285
/**
@@ -299,14 +296,14 @@ public function getNotAfter($passPhrase)
299
296
$ in = escapeshellarg ($ this ->getPathname ());
300
297
$ pass = escapeshellarg ($ passPhrase );
301
298
302
- $ command = "
303
- openssl pkcs12 -in $ in -passin pass: $ pass -nokeys |
304
- openssl x509 -noout -enddate " ;
299
+ $ process1 = new Process ("openssl pkcs12 -in $ in -passin pass: $ pass -nokeys " );
300
+ $ process1 ->mustRun ();
305
301
306
- $ process = new Process ($ command );
307
- $ process ->mustRun ();
302
+ $ process2 = new Process ('openssl x509 -noout -enddate ' );
303
+ $ process2 ->setInput ($ process1 ->getOutput ());
304
+ $ process2 ->mustRun ();
308
305
309
- return new \DateTime (trim (preg_replace ('/^notAfter=/ ' , '' , $ process ->getOutput ())));
306
+ return new \DateTime (trim (preg_replace ('/^notAfter=/ ' , '' , $ process2 ->getOutput ())));
310
307
}
311
308
312
309
/**
@@ -321,9 +318,7 @@ public function verifyPassPhrase($passPhrase)
321
318
$ in = escapeshellarg ($ this ->getPathname ());
322
319
$ pass = escapeshellarg ($ passPhrase );
323
320
324
- $ command = "openssl pkcs12 -in $ in -passin pass: $ pass -noout " ;
325
-
326
- $ process = new Process ($ command );
321
+ $ process = new Process ("openssl pkcs12 -in $ in -passin pass: $ pass -noout " );
327
322
$ process ->run ();
328
323
329
324
return $ process ->isSuccessful ();
@@ -346,20 +341,25 @@ public function changePassPhrase($passPhrase, $newPassPhrase)
346
341
$ pass = escapeshellarg ($ passPhrase );
347
342
$ newPass = escapeshellarg ($ newPassPhrase );
348
343
349
- $ command = "
350
- {
351
- openssl pkcs12 -in $ in -passin pass: $ pass -nocerts -passout pass:pipe |
352
- openssl rsa -passin pass:pipe -passout pass:pipe
353
- openssl pkcs12 -in $ in -passin pass: $ pass -nokeys |
354
- openssl x509
355
- } |
356
- openssl pkcs12 -passin pass:pipe -out $ in~ -passout pass: $ newPass -export &&
357
- mv --force $ in~ $ in ||
358
- rm --force $ in~ " ;
344
+ $ process1 = new Process ("openssl pkcs12 -in $ in -passin pass: $ pass -nocerts -passout pass:pipe " );
345
+ $ process1 ->mustRun ();
346
+
347
+ $ process2 = new Process ("openssl rsa -passin pass:pipe -passout pass:pipe " );
348
+ $ process2 ->setInput ($ process1 ->getOutput ());
349
+ $ process2 ->mustRun ();
350
+
351
+ $ process3 = new Process ("openssl pkcs12 -in $ in -passin pass: $ pass -nokeys " );
352
+ $ process3 ->mustRun ();
353
+
354
+ $ process4 = new Process ("openssl x509 " );
355
+ $ process4 ->setInput ($ process3 ->getOutput ());
356
+ $ process4 ->mustRun ();
359
357
360
- $ process = new Process ($ command );
361
- $ process ->mustRun ();
358
+ $ process5 = new Process ("openssl pkcs12 -passin pass:pipe -passout pass: $ newPass -export " );
359
+ $ process5 ->setInput ($ process2 ->getOutput () . $ process4 ->getOutput ());
360
+ $ process5 ->mustRun ();
362
361
362
+ @file_put_contents ($ this ->getPathname (), $ process5 ->getOutput ());
363
363
@chmod ($ this ->getPathname (), 0666 & ~umask ());
364
364
clearstatcache (true , $ this ->getPathname ());
365
365
0 commit comments