File tree Expand file tree Collapse file tree 3 files changed +61
-1
lines changed Expand file tree Collapse file tree 3 files changed +61
-1
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,16 @@ class Client {
100
100
'password ' => null ,
101
101
];
102
102
103
+
104
+ /**
105
+ * SSL stream context options
106
+ *
107
+ * @see https://www.php.net/manual/en/context.ssl.php for possible options
108
+ *
109
+ * @var array
110
+ */
111
+ protected array $ ssl_options = [];
112
+
103
113
/**
104
114
* Connection timeout
105
115
* @var int $timeout
@@ -184,7 +194,8 @@ class Client {
184
194
'username ' => null ,
185
195
'password ' => null ,
186
196
],
187
- "timeout " => 30
197
+ 'ssl_options ' => [],
198
+ "timeout " => 30 ,
188
199
];
189
200
190
201
/**
@@ -436,6 +447,7 @@ public function connect(): Client {
436
447
$ this ->connection = new ImapProtocol ($ this ->config , $ this ->validate_cert , $ this ->encryption );
437
448
$ this ->connection ->setConnectionTimeout ($ this ->timeout );
438
449
$ this ->connection ->setProxy ($ this ->proxy );
450
+ $ this ->connection ->setSslOptions ($ this ->ssl_options );
439
451
}else {
440
452
if (extension_loaded ('imap ' ) === false ) {
441
453
throw new ConnectionFailedException ("connection setup failed " , 0 , new ProtocolNotSupportedException ($ protocol ." is an unsupported protocol " ));
Original file line number Diff line number Diff line change @@ -71,6 +71,15 @@ abstract class Protocol implements ProtocolInterface {
71
71
'password ' => null ,
72
72
];
73
73
74
+ /**
75
+ * SSL stream context options
76
+ *
77
+ * @see https://www.php.net/manual/en/context.ssl.php for possible options
78
+ *
79
+ * @var array
80
+ */
81
+ protected array $ ssl_options = [];
82
+
74
83
/**
75
84
* Cache for uid of active folder.
76
85
*
@@ -162,6 +171,28 @@ public function getProxy(): array {
162
171
return $ this ->proxy ;
163
172
}
164
173
174
+ /**
175
+ * Set SSL context options settings
176
+ * @var array $options
177
+ *
178
+ * @return Protocol
179
+ */
180
+ public function setSslOptions (array $ options ): Protocol
181
+ {
182
+ $ this ->ssl_options = $ options ;
183
+
184
+ return $ this ;
185
+ }
186
+
187
+ /**
188
+ * Get the current SSL context options settings
189
+ *
190
+ * @return array
191
+ */
192
+ public function getSslOptions (): array {
193
+ return $ this ->ssl_options ;
194
+ }
195
+
165
196
/**
166
197
* Prepare socket options
167
198
* @return array
@@ -175,6 +206,11 @@ private function defaultSocketOptions(string $transport): array {
175
206
'verify_peer_name ' => $ this ->getCertValidation (),
176
207
'verify_peer ' => $ this ->getCertValidation (),
177
208
];
209
+
210
+ if (count ($ this ->ssl_options )) {
211
+ /* Get the ssl context options from the config, but prioritize the 'validate_cert' config over the ssl context options */
212
+ $ options ["ssl " ] = array_replace ($ this ->ssl_options , $ options ["ssl " ]);
213
+ }
178
214
}
179
215
180
216
if ($ this ->proxy ["socket " ] != null ) {
Original file line number Diff line number Diff line change @@ -48,5 +48,17 @@ public function testImapProtocol(): void {
48
48
49
49
self ::assertSame (true , $ protocol ->getCertValidation ());
50
50
self ::assertSame ("ssl " , $ protocol ->getEncryption ());
51
+
52
+ $ protocol ->setSslOptions ([
53
+ 'verify_peer ' => true ,
54
+ 'cafile ' => '/dummy/path/for/testing ' ,
55
+ 'peer_fingerprint ' => ['md5 ' => 40 ],
56
+ ]);
57
+
58
+ self ::assertSame ([
59
+ 'verify_peer ' => true ,
60
+ 'cafile ' => '/dummy/path/for/testing ' ,
61
+ 'peer_fingerprint ' => ['md5 ' => 40 ],
62
+ ], $ protocol ->getSslOptions ());
51
63
}
52
64
}
You can’t perform that action at this time.
0 commit comments