php-imap icon indicating copy to clipboard operation
php-imap copied to clipboard

stream_context_create have no proxy option in ssl

Open famfamfam opened this issue 4 years ago • 6 comments

Describe the bug stream_context_create ssl context have no proxy option, so proxy doesn't working.

Used config

Code to Reproduce

$client = $cm->make([
    'host' => 'imap.somehost.com',
    'port' => 993,
    'encryption' => 'ssl',
    'validate_cert' => true,
    'username' => '[email protected]',
    'password' => 'Password',
    'protocol' => 'imap',
    'proxy' => [
        'socket' => "tcp://proxy.com:3444",
        'request_fulluri' => false,
        'username' => "my_username",
        'password' => "secret_password",
    ]
]);

Bigged code

/**
     * Prepare socket options
     * @var string $transport
     *
     * @return array
     */
    private function defaultSocketOptions($transport) {
        $options = [];
        if ($this->encryption != false) {
            $options["ssl"] = [
                'verify_peer_name' => $this->getCertValidation(),
                'verify_peer'      => $this->getCertValidation(),
            ];
        }

        if ($this->proxy["socket"] != null) {
            $options[$transport]["proxy"] = $this->proxy["socket"];
            $options[$transport]["request_fulluri"] = $this->proxy["request_fulluri"];

            if ($this->proxy["username"] != null) {
                $auth = base64_encode($this->proxy["username"].':'.$this->proxy["password"]);

                $options[$transport]["header"] = [
                    "Proxy-Authorization: Basic $auth"
                ];
            }
        }

        return $options;
    }

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop / Server (please complete the following information):

  • OS: all
  • PHP: 7
  • Version last

Additional context Add any other context about the problem here.

famfamfam avatar Aug 30 '21 10:08 famfamfam

Hi @famfamfam , many thanks for your report.

Could you dump the variable $transport and $this->encryption in line 160? https://github.com/Webklex/php-imap/blob/bd123fa62fb597ddd9a43d1b05d377fc73bb57a2/src/Connection/Protocols/Protocol.php#L152-L175

var_dump($transport);
var_dump($this->encryption);

Best regards,

Webklex avatar Sep 04 '21 15:09 Webklex

Have you a idea for a fix? I have the same issue. I have try to use the proxy Part with another $transport (http) like your post here: https://github.com/Webklex/php-imap/issues/53#issuecomment-747624990 But I get allways this stream_socket_client(): Unable to connect to ssl://imapserver:993 (Connection timed out)

To test the proxy I have disabled port 993 and only enable the proxy port.

The output of the two variables: 'ssl' I have the same issue with ssl and with http (for proxy)

KodaCHC avatar Sep 30 '21 07:09 KodaCHC

Proxy is still not working, i wonder why. I've tried all means. it just ignores the proxy and connects directly. Please is there a work around to this ? I can provide a proxy for you for testing

rigesjahgo avatar Nov 14 '21 21:11 rigesjahgo

I found a work around to it, the proxy is working now

rigesjahgo avatar Nov 15 '21 05:11 rigesjahgo

@rigesjahgo what is your solution?

KodaCHC avatar Nov 15 '21 18:11 KodaCHC

@rigesjahgo Please share your workaround, I am facing the same problem! Thank you.

manraf avatar Jan 04 '22 16:01 manraf