Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF-3023 SMime signature validation #3061

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assets/images/ic_bad_signature.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/images/ic_good_signature.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions core/lib/presentation/resources/image_paths.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ class ImagePaths {
String get icRemoveRule => _getImagePath('ic_remove_rule.svg');
String get icCheckboxUnselected => _getImagePath('ic_checkbox_unselected.svg');
String get icCheckboxSelected => _getImagePath('ic_checkbox_selected.svg');
String get icGoodSignature => _getImagePath('ic_good_signature.svg');
String get icBadSignature => _getImagePath('ic_bad_signature.svg');

String _getImagePath(String imageName) {
return AssetsPaths.images + imageName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import 'package:model/email/presentation_email.dart';
import 'package:model/extensions/list_email_header_extension.dart';
import 'package:tmail_ui_user/features/email/presentation/model/smime_signature_status.dart';
import 'package:tmail_ui_user/features/email/presentation/utils/smime_signature_constant.dart';

extension PresentationEmailExtension on PresentationEmail {

SMimeSignatureStatus get sMimeStatus {
final status = emailHeader?.toSet().sMimeStatus;
if (status == SMimeSignatureConstant.GOOD_SIGNATURE) {
return SMimeSignatureStatus.goodSignature;
} else if (status == SMimeSignatureConstant.BAD_SIGNATURE) {
return SMimeSignatureStatus.badSignature;
} else {
return SMimeSignatureStatus.notSigned;
}
}
}
32 changes: 32 additions & 0 deletions lib/features/email/presentation/model/smime_signature_status.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

import 'package:core/presentation/resources/image_paths.dart';
import 'package:flutter/material.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';

enum SMimeSignatureStatus {
goodSignature,
badSignature,
notSigned;

String getIcon(ImagePaths imagePaths) {
switch(this) {
case SMimeSignatureStatus.goodSignature:
return imagePaths.icGoodSignature;
case SMimeSignatureStatus.badSignature:
return imagePaths.icBadSignature;
case SMimeSignatureStatus.notSigned:
return '';
}
}

String getTooltipMessage(BuildContext context) {
switch(this) {
case SMimeSignatureStatus.goodSignature:
return AppLocalizations.of(context).sMimeGoodSignatureMessage;
case SMimeSignatureStatus.badSignature:
return AppLocalizations.of(context).sMimeBadSignatureMessage;
case SMimeSignatureStatus.notSigned:
return '';
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

class SMimeSignatureConstant {
static const String GOOD_SIGNATURE = 'Good signature';
static const String BAD_SIGNATURE = 'Bad signature';
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import 'package:core/presentation/resources/image_paths.dart';
import 'package:core/presentation/utils/responsive_utils.dart';
import 'package:core/presentation/views/button/tmail_button_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:model/email/email_action_type.dart';
import 'package:model/email/presentation_email.dart';
import 'package:model/extensions/presentation_email_extension.dart';
import 'package:tmail_ui_user/features/base/widget/email_avatar_builder.dart';
import 'package:tmail_ui_user/features/email/presentation/extensions/presentation_email_extension.dart';
import 'package:tmail_ui_user/features/email/presentation/model/email_unsubscribe.dart';
import 'package:tmail_ui_user/features/email/presentation/model/smime_signature_status.dart';
import 'package:tmail_ui_user/features/email/presentation/widgets/email_receiver_widget.dart';
import 'package:tmail_ui_user/features/email/presentation/widgets/email_sender_builder.dart';
import 'package:tmail_ui_user/features/email/presentation/widgets/email_view_app_bar_widget.dart';
Expand All @@ -29,7 +32,7 @@ class InformationSenderAndReceiverBuilder extends StatelessWidget {
required this.emailSelected,
required this.responsiveUtils,
required this.imagePaths,
required this.emailUnsubscribe,
this.emailUnsubscribe,
this.maxBodyHeight,
this.openEmailAddressDetailAction,
this.onEmailActionClick,
Expand Down Expand Up @@ -61,6 +64,18 @@ class InformationSenderAndReceiverBuilder extends StatelessWidget {
openEmailAddressDetailAction: openEmailAddressDetailAction,
)
)),
if (emailSelected.sMimeStatus != SMimeSignatureStatus.notSigned)
Tooltip(
key: const Key('smime_signature_status_icon'),
message: emailSelected.sMimeStatus.getTooltipMessage(context),
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: SvgPicture.asset(
emailSelected.sMimeStatus.getIcon(imagePaths),
fit: BoxFit.fill,
),
),
),
if (!emailSelected.isSubscribed && emailUnsubscribe != null && !responsiveUtils.isPortraitMobile(context))
TMailButtonWidget.fromText(
text: AppLocalizations.of(context).unsubscribe,
Expand Down
14 changes: 13 additions & 1 deletion lib/l10n/intl_messages.arb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"@@last_modified": "2024-07-17T01:36:03.095458",
"@@last_modified": "2024-08-05T16:49:32.139855",
"initializing_data": "Initializing data...",
"@initializing_data": {
"type": "text",
Expand Down Expand Up @@ -3963,5 +3963,17 @@
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"sMimeGoodSignatureMessage": "The authenticity of this message had been verified with SMime signature.",
"@sMimeGoodSignatureMessage": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"sMimeBadSignatureMessage": "This message failed SMime signature verification.",
"@sMimeBadSignatureMessage": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
}
}
14 changes: 14 additions & 0 deletions lib/main/localizations/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4148,4 +4148,18 @@ class AppLocalizations {
name: 'dialogMessageSessionHasExpired',
);
}

String get sMimeGoodSignatureMessage {
return Intl.message(
'The authenticity of this message had been verified with SMime signature.',
name: 'sMimeGoodSignatureMessage',
);
}

String get sMimeBadSignatureMessage {
return Intl.message(
'This message failed SMime signature verification.',
name: 'sMimeBadSignatureMessage',
);
}
}
2 changes: 2 additions & 0 deletions model/lib/email/email_property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ class EmailProperty {
static const String headerMdnKey = 'Disposition-Notification-To';
static const String messageId = 'messageId';
static const String references = 'references';
static const String headerUnsubscribeKey = 'List-Unsubscribe';
static const String headerSMimeStatusKey = 'X-SMIME-Status';
}
10 changes: 1 addition & 9 deletions model/lib/extensions/email_extension.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

import 'dart:convert';

import 'package:collection/collection.dart';
import 'package:core/domain/extensions/datetime_extension.dart';
import 'package:core/utils/app_logger.dart';
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_body_part.dart';
Expand All @@ -14,8 +12,6 @@ import 'package:model/model.dart';

extension EmailExtension on Email {

static const String unsubscribeHeaderName = 'List-Unsubscribe';

String asString() => jsonEncode(toJson());

bool get hasRead => keywords?.containsKey(KeyWordIdentifier.emailSeen) == true;
Expand All @@ -30,11 +26,7 @@ extension EmailExtension on Email {

bool get withAttachments => hasAttachment == true;

String get listUnsubscribe {
final listUnsubscribe = headers?.firstWhereOrNull((header) => header.name == unsubscribeHeaderName);
log('EmailExtension::listUnsubscribe: $listUnsubscribe');
return listUnsubscribe?.value ?? '';
}
String get listUnsubscribe => headers.listUnsubscribe;

bool get hasListUnsubscribe => listUnsubscribe.isNotEmpty;

Expand Down
11 changes: 11 additions & 0 deletions model/lib/extensions/list_email_header_extension.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import 'package:collection/collection.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_header.dart';
import 'package:model/email/email_property.dart';

Expand All @@ -11,4 +12,14 @@ extension ListEmailHeaderExtension on Set<EmailHeader>? {
return false;
}
}

String get listUnsubscribe {
final listUnsubscribe = this?.firstWhereOrNull((header) => header.name == EmailProperty.headerUnsubscribeKey);
return listUnsubscribe?.value ?? '';
}

String get sMimeStatus {
final sMimeStatus = this?.firstWhereOrNull((header) => header.name == EmailProperty.headerSMimeStatusKey);
return sMimeStatus?.value ?? '';
}
}
Loading