Merge pull request #1488 from mbarnathan/master

Client certificates (with password authentication)
This commit is contained in:
RainLoop Team 2019-03-28 01:56:24 +03:00 committed by GitHub
commit 3c059d4434
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 10308 additions and 10282 deletions

View file

@ -137,6 +137,7 @@ class ImapClient extends \MailSo\Net\NetClient
* @param int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT * @param int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT
* @param bool $bVerifySsl = false * @param bool $bVerifySsl = false
* @param bool $bAllowSelfSigned = true * @param bool $bAllowSelfSigned = true
* @param string $sClientCert = NULL
* *
* @return \MailSo\Imap\ImapClient * @return \MailSo\Imap\ImapClient
* *
@ -146,11 +147,12 @@ class ImapClient extends \MailSo\Net\NetClient
*/ */
public function Connect($sServerName, $iPort = 143, public function Connect($sServerName, $iPort = 143,
$iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT, $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT,
$bVerifySsl = false, $bAllowSelfSigned = true) $bVerifySsl = false, $bAllowSelfSigned = true,
$sClientCert = '')
{ {
$this->aTagTimeouts['*'] = \microtime(true); $this->aTagTimeouts['*'] = \microtime(true);
parent::Connect($sServerName, $iPort, $iSecurityType, $bVerifySsl, $bAllowSelfSigned); parent::Connect($sServerName, $iPort, $iSecurityType, $bVerifySsl, $bAllowSelfSigned, $sClientCert);
$this->parseResponseWithValidation('*', true); $this->parseResponseWithValidation('*', true);

View file

@ -59,6 +59,7 @@ class MailClient
* @param int $iPort = 143 * @param int $iPort = 143
* @param int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT * @param int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT
* @param bool $bVerifySsl = false * @param bool $bVerifySsl = false
* @param string $sClientCert = ""
* *
* @return \MailSo\Mail\MailClient * @return \MailSo\Mail\MailClient
* *
@ -67,9 +68,9 @@ class MailClient
* @throws \MailSo\Imap\Exceptions\Exception * @throws \MailSo\Imap\Exceptions\Exception
*/ */
public function Connect($sServerName, $iPort = 143, public function Connect($sServerName, $iPort = 143,
$iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT, $bVerifySsl = false) $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT, $bVerifySsl = false, $bAllowSelfSigned = false, $sClientCert = '')
{ {
$this->oImapClient->Connect($sServerName, $iPort, $iSecurityType, $bVerifySsl); $this->oImapClient->Connect($sServerName, $iPort, $iSecurityType, $bVerifySsl, $bAllowSelfSigned, $sClientCert);
return $this; return $this;
} }

View file

@ -196,6 +196,7 @@ abstract class NetClient
* @param int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT * @param int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT
* @param bool $bVerifySsl = false * @param bool $bVerifySsl = false
* @param bool $bAllowSelfSigned = true * @param bool $bAllowSelfSigned = true
* @param string $sClientCert = NULL
* *
* @return void * @return void
* *
@ -205,7 +206,8 @@ abstract class NetClient
*/ */
public function Connect($sServerName, $iPort, public function Connect($sServerName, $iPort,
$iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT, $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT,
$bVerifySsl = false, $bAllowSelfSigned = true) $bVerifySsl = false, $bAllowSelfSigned = true,
$sClientCert = '')
{ {
if (!\MailSo\Base\Validator::NotEmptyString($sServerName, true) || !\MailSo\Base\Validator::PortInt($iPort)) if (!\MailSo\Base\Validator::NotEmptyString($sServerName, true) || !\MailSo\Base\Validator::PortInt($iPort))
{ {
@ -254,13 +256,13 @@ abstract class NetClient
$bVerifySsl = !!$bVerifySsl; $bVerifySsl = !!$bVerifySsl;
$bAllowSelfSigned = $bVerifySsl ? !!$bAllowSelfSigned : true; $bAllowSelfSigned = $bVerifySsl ? !!$bAllowSelfSigned : true;
$aStreamContextSettings = array( $aStreamContextSettings = array(
'ssl' => array( 'ssl' => array(
'verify_host' => $bVerifySsl, 'verify_host' => $bVerifySsl,
'verify_peer' => $bVerifySsl, 'verify_peer' => $bVerifySsl,
'verify_peer_name' => $bVerifySsl, 'verify_peer_name' => $bVerifySsl,
'allow_self_signed' => $bAllowSelfSigned 'allow_self_signed' => $bAllowSelfSigned,
'local_cert' => $sClientCert
) )
); );

File diff suppressed because it is too large Load diff

View file

@ -218,6 +218,7 @@ class Application extends \RainLoop\Config\AbstractConfig
'allow_self_signed' => array(true, 'Allow self-signed certificates. Requires verify_certificate.'), 'allow_self_signed' => array(true, 'Allow self-signed certificates. Requires verify_certificate.'),
'cafile' => array('', 'Location of Certificate Authority file on local filesystem (/etc/ssl/certs/ca-certificates.crt)'), 'cafile' => array('', 'Location of Certificate Authority file on local filesystem (/etc/ssl/certs/ca-certificates.crt)'),
'capath' => array('', 'capath must be a correctly hashed certificate directory. (/etc/ssl/certs/)'), 'capath' => array('', 'capath must be a correctly hashed certificate directory. (/etc/ssl/certs/)'),
'client_cert' => array('', 'Location of client certificate file (pem format with private key) on local filesystem'),
), ),
'capa' => array( 'capa' => array(

View file

@ -29,6 +29,11 @@ class Account extends \RainLoop\Account // for backward compatibility
*/ */
private $sProxyAuthPassword; private $sProxyAuthPassword;
/**
* @var string
*/
private $sClientCert;
/** /**
* @var string * @var string
*/ */
@ -56,7 +61,7 @@ class Account extends \RainLoop\Account // for backward compatibility
* @return void * @return void
*/ */
protected function __construct($sEmail, $sLogin, $sPassword, \RainLoop\Model\Domain $oDomain, protected function __construct($sEmail, $sLogin, $sPassword, \RainLoop\Model\Domain $oDomain,
$sSignMeToken = '', $sProxyAuthUser = '', $sProxyAuthPassword = '') $sSignMeToken = '', $sProxyAuthUser = '', $sProxyAuthPassword = '', $sClientCert = '')
{ {
$this->sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail, true); $this->sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail, true);
$this->sLogin = \MailSo\Base\Utils::IdnToAscii($sLogin); $this->sLogin = \MailSo\Base\Utils::IdnToAscii($sLogin);
@ -65,6 +70,7 @@ class Account extends \RainLoop\Account // for backward compatibility
$this->sSignMeToken = $sSignMeToken; $this->sSignMeToken = $sSignMeToken;
$this->sProxyAuthUser = $sProxyAuthUser; $this->sProxyAuthUser = $sProxyAuthUser;
$this->sProxyAuthPassword = $sProxyAuthPassword; $this->sProxyAuthPassword = $sProxyAuthPassword;
$this->sClientCert = $sClientCert;
$this->sParentEmail = ''; $this->sParentEmail = '';
} }
@ -80,9 +86,9 @@ class Account extends \RainLoop\Account // for backward compatibility
* @return \RainLoop\Model\Account * @return \RainLoop\Model\Account
*/ */
public static function NewInstance($sEmail, $sLogin, $sPassword, \RainLoop\Model\Domain $oDomain, public static function NewInstance($sEmail, $sLogin, $sPassword, \RainLoop\Model\Domain $oDomain,
$sSignMeToken = '', $sProxyAuthUser = '', $sProxyAuthPassword = '') $sSignMeToken = '', $sProxyAuthUser = '', $sProxyAuthPassword = '', $sClientCert = '')
{ {
return new self($sEmail, $sLogin, $sPassword, $oDomain, $sSignMeToken, $sProxyAuthUser, $sProxyAuthPassword); return new self($sEmail, $sLogin, $sPassword, $oDomain, $sSignMeToken, $sProxyAuthUser, $sProxyAuthPassword, $sClientCert);
} }
/** /**
@ -185,6 +191,14 @@ class Account extends \RainLoop\Account // for backward compatibility
return $this->IncPassword(); return $this->IncPassword();
} }
/**
* @return string
*/
public function ClientCert()
{
return $this->sClientCert;
}
/** /**
* @return bool * @return bool
*/ */
@ -362,7 +376,8 @@ class Account extends \RainLoop\Account // for backward compatibility
\RainLoop\Utils::GetShortToken(), // 7 \RainLoop\Utils::GetShortToken(), // 7
$this->sProxyAuthUser, // 8 $this->sProxyAuthUser, // 8
$this->sProxyAuthPassword, // 9 $this->sProxyAuthPassword, // 9
0 // 10 // timelife 0, // 10 // timelife
$this->sClientCert // 11
)); ));
} }
@ -382,7 +397,8 @@ class Account extends \RainLoop\Account // for backward compatibility
\RainLoop\Utils::GetShortToken(), // 7 \RainLoop\Utils::GetShortToken(), // 7
$this->sProxyAuthUser, // 8 $this->sProxyAuthUser, // 8
$this->sProxyAuthPassword, // 9 $this->sProxyAuthPassword, // 9
0 // 10 // timelife 0, // 10 // timelife
$this->sClientCert // 11
)); ));
} }
@ -408,6 +424,7 @@ class Account extends \RainLoop\Account // for backward compatibility
'ProxyAuthUser' => $this->ProxyAuthUser(), 'ProxyAuthUser' => $this->ProxyAuthUser(),
'ProxyAuthPassword' => $this->ProxyAuthPassword(), 'ProxyAuthPassword' => $this->ProxyAuthPassword(),
'VerifySsl' => !!$oConfig->Get('ssl', 'verify_certificate', false), 'VerifySsl' => !!$oConfig->Get('ssl', 'verify_certificate', false),
'ClientCert' => $this->ClientCert(),
'AllowSelfSigned' => !!$oConfig->Get('ssl', 'allow_self_signed', true), 'AllowSelfSigned' => !!$oConfig->Get('ssl', 'allow_self_signed', true),
'UseAuthPlainIfSupported' => !!$oConfig->Get('labs', 'imap_use_auth_plain', true), 'UseAuthPlainIfSupported' => !!$oConfig->Get('labs', 'imap_use_auth_plain', true),
'UseAuthCramMd5IfSupported' => !!$oConfig->Get('labs', 'imap_use_auth_cram_md5', true) 'UseAuthCramMd5IfSupported' => !!$oConfig->Get('labs', 'imap_use_auth_cram_md5', true)
@ -421,7 +438,8 @@ class Account extends \RainLoop\Account // for backward compatibility
{ {
$oMailClient $oMailClient
->Connect($aImapCredentials['Host'], $aImapCredentials['Port'], ->Connect($aImapCredentials['Host'], $aImapCredentials['Port'],
$aImapCredentials['Secure'], $aImapCredentials['VerifySsl'], $aImapCredentials['AllowSelfSigned']); $aImapCredentials['Secure'], $aImapCredentials['VerifySsl'],
$aImapCredentials['AllowSelfSigned'], $aImapCredentials['ClientCert']);
} }