nextcloud / nextcloud/mail

S/MIME decryption fails if your email is in CC instead of To

Open
#8,663 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0. to triage bug feature:smime
Dominant language
JavaScript
Stars
1k
Forks
348
Avg merge
12h 28m
Merged PRs (30d)
91

Description

Steps to reproduce
  1. Have someone send an encrypted email with your email in CC instead of To
Expected behavior

Email should be decrypted if you are included in the CC header

Actual behavior

A ServiceException is thrown with the message "Failed to find a suitable S/MIME certificate for decryption" when debugging is enabled. Otherwise a "Not found" message is shown.

Mail app version

3.2.4, 3.3.0-alpha.1

Mailserver or service

Outlook

Operating system

Ubuntu 22.04

PHP engine version

PHP 8.1

Web server

Apache (supported)

Database

MySQL

Additional info

Error is thrown in SmimeService.php in the decryptDataFetch function. For a workaround, I just cloned the foreach loop and replaced $envelope->to with $envelope->cc and have it run again.

if ($decryptionResult === null){
  foreach ($envelope->cc as $recipient) {
	  /** @var Horde_Mail_Rfc822_Address $recipient  */
	  $recipientAddress = $recipient->bare_address;
	  $certs = $this->findCertificatesByEmailAddress(
		  $recipientAddress,
		  $userId,
	  );
  
	  foreach ($certs as $cert) {
		  try {
			  $decryptionResult = $this->decryptMimePartText($encryptedText, $cert);
		  } catch (ServiceException | SmimeDecryptException $e) {
			  // Certificate probably didn't match -> continue
			  // TODO: filter a real decryption error
			  // (is hard because openssl doesn't return a proper error code)
			  continue;
		  }
	  }
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in SmimeService.php at decryptDataFetch and trace how recipient addresses and certificates are selected from the envelope. Reproduce the CC case with an encrypted message, then verify that a recipient in the CC header can be used for decryption without changing the existing To behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.