Commit 58363bc3 authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][Passwords] Expire copied passwords after 20 minutes

Context:
https://docs.google.com/document/d/1vjo-PTxVBFpY0aZUozRuBOpL2bd9J4qahZTsGyQWvXE/edit#heading=h.uonvs79xfbra

Bug: N/A
Change-Id: I4153dd3a50ff9eb9652d585cd368d90931ff9681
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2352910
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarNohemi Fernandez <fernandex@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799727}
parent 1dd8f98c
...@@ -56,6 +56,7 @@ source_set("password") { ...@@ -56,6 +56,7 @@ source_set("password") {
"//ios/chrome/browser/ui/table_view/cells:cells_constants", "//ios/chrome/browser/ui/table_view/cells:cells_constants",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
"//ios/chrome/common", "//ios/chrome/common",
"//ios/chrome/common:constants",
"//ios/chrome/common/ui/colors", "//ios/chrome/common/ui/colors",
"//ios/chrome/common/ui/elements:popover_label_view_controller", "//ios/chrome/common/ui/elements:popover_label_view_controller",
"//ios/chrome/common/ui/reauthentication", "//ios/chrome/common/ui/reauthentication",
...@@ -66,6 +67,7 @@ source_set("password") { ...@@ -66,6 +67,7 @@ source_set("password") {
"//ui/base/clipboard:clipboard_types", "//ui/base/clipboard:clipboard_types",
"//url", "//url",
] ]
frameworks = [ "MobileCoreServices.framework" ]
} }
source_set("password_ui") { source_set("password_ui") {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/settings/password/legacy_password_details_table_view_controller.h" #import "ios/chrome/browser/ui/settings/password/legacy_password_details_table_view_controller.h"
#import <MobileCoreServices/UTCoreTypes.h>
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <MaterialComponents/MaterialSnackbar.h> #import <MaterialComponents/MaterialSnackbar.h>
...@@ -28,6 +29,7 @@ ...@@ -28,6 +29,7 @@
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_text_item.h"
#include "ios/chrome/browser/ui/ui_feature_flags.h" #include "ios/chrome/browser/ui/ui_feature_flags.h"
#include "ios/chrome/browser/ui/util/uikit_ui_util.h" #include "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/common/constants.h"
#import "ios/chrome/common/ui/colors/semantic_color_names.h" #import "ios/chrome/common/ui/colors/semantic_color_names.h"
#import "ios/chrome/common/ui/reauthentication/reauthentication_module.h" #import "ios/chrome/common/ui/reauthentication/reauthentication_module.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
...@@ -397,9 +399,15 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -397,9 +399,15 @@ typedef NS_ENUM(NSInteger, ItemType) {
// If the password is displayed in plain text, there is no need to // If the password is displayed in plain text, there is no need to
// re-authenticate the user when copying the password because they are already // re-authenticate the user when copying the password because they are already
// granted access to it. // granted access to it.
NSDate* expirationDate =
[NSDate dateWithTimeIntervalSinceNow:kSecurePasteboardExpiration];
NSDictionary* options = @{UIPasteboardOptionExpirationDate : expirationDate};
if (_plainTextPasswordShown) { if (_plainTextPasswordShown) {
UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; NSDictionary* item = @{(NSString*)kUTTypePlainText : _password};
generalPasteboard.string = _password; [[UIPasteboard generalPasteboard] setItems:@[ item ] options:options];
[self showToast:l10n_util::GetNSString( [self showToast:l10n_util::GetNSString(
IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE) IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE)
forSuccess:YES]; forSuccess:YES];
...@@ -419,11 +427,12 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -419,11 +427,12 @@ typedef NS_ENUM(NSInteger, ItemType) {
[strongSelf logPasswordSettingsReauthResult:result]; [strongSelf logPasswordSettingsReauthResult:result];
if (result != ReauthenticationResult::kFailure) { if (result != ReauthenticationResult::kFailure) {
UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard];
[generalPasteboard setItems:@[ @{ [generalPasteboard
@"public.plain-text" : strongSelf->_password, setItems:@[ @{
ui::kUTTypeConfidentialData : strongSelf->_password (NSString*)kUTTypePlainText : strongSelf->_password,
} ] ui::kUTTypeConfidentialData : strongSelf->_password
options:@{}]; } ]
options:options];
[strongSelf showToast:l10n_util::GetNSString( [strongSelf showToast:l10n_util::GetNSString(
IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE) IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE)
forSuccess:YES]; forSuccess:YES];
......
...@@ -31,6 +31,15 @@ source_set("common") { ...@@ -31,6 +31,15 @@ source_set("common") {
frameworks = [ "QuartzCore.framework" ] frameworks = [ "QuartzCore.framework" ]
} }
source_set("constants") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"constants.h",
"constants.mm",
]
frameworks = [ "Foundation.framework" ]
}
source_set("timing") { source_set("timing") {
sources = [ sources = [
"material_timing.h", "material_timing.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_COMMON_CONSTANTS_H_
#define IOS_CHROME_COMMON_CONSTANTS_H_
#import <Foundation/Foundation.h>
// Time to expire passwords copied to the pasteboard.
extern const NSTimeInterval kSecurePasteboardExpiration;
#endif // IOS_CHROME_COMMON_CONSTANTS_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/common/constants.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
const NSTimeInterval kSecurePasteboardExpiration = 60 * 20; // 20 minutes.
...@@ -27,6 +27,7 @@ source_set("ui") { ...@@ -27,6 +27,7 @@ source_set("ui") {
deps = [ deps = [
":utils", ":utils",
"//base", "//base",
"//ios/chrome/common:constants",
"//ios/chrome/common/app_group", "//ios/chrome/common/app_group",
"//ios/chrome/common/app_group:client", "//ios/chrome/common/app_group:client",
"//ios/chrome/common/credential_provider", "//ios/chrome/common/credential_provider",
...@@ -44,6 +45,7 @@ source_set("ui") { ...@@ -44,6 +45,7 @@ source_set("ui") {
frameworks = [ frameworks = [
"UIKit.framework", "UIKit.framework",
"AuthenticationServices.framework", "AuthenticationServices.framework",
"MobileCoreServices.framework",
] ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
} }
......
...@@ -4,8 +4,11 @@ ...@@ -4,8 +4,11 @@
#import "ios/chrome/credential_provider_extension/ui/credential_details_view_controller.h" #import "ios/chrome/credential_provider_extension/ui/credential_details_view_controller.h"
#import <MobileCoreServices/UTCoreTypes.h>
#import "base/mac/foundation_util.h" #import "base/mac/foundation_util.h"
#include "ios/chrome/common/app_group/app_group_metrics.h" #include "ios/chrome/common/app_group/app_group_metrics.h"
#import "ios/chrome/common/constants.h"
#import "ios/chrome/common/credential_provider/credential.h" #import "ios/chrome/common/credential_provider/credential.h"
#import "ios/chrome/common/ui/colors/semantic_color_names.h" #import "ios/chrome/common/ui/colors/semantic_color_names.h"
#import "ios/chrome/credential_provider_extension/metrics_util.h" #import "ios/chrome/credential_provider_extension/metrics_util.h"
...@@ -178,8 +181,11 @@ typedef NS_ENUM(NSInteger, RowIdentifier) { ...@@ -178,8 +181,11 @@ typedef NS_ENUM(NSInteger, RowIdentifier) {
// Copy password to clipboard. // Copy password to clipboard.
- (void)copyPassword { - (void)copyPassword {
UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; NSDictionary* item = @{(NSString*)kUTTypePlainText : self.clearPassword};
generalPasteboard.string = self.clearPassword; NSDate* expirationDate =
[NSDate dateWithTimeIntervalSinceNow:kSecurePasteboardExpiration];
NSDictionary* options = @{UIPasteboardOptionExpirationDate : expirationDate};
[[UIPasteboard generalPasteboard] setItems:@[ item ] options:options];
UpdateUMACountForKey(app_group::kCredentialExtensionCopyPasswordCount); UpdateUMACountForKey(app_group::kCredentialExtensionCopyPasswordCount);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment