xref: /aosp_15_r20/external/libchrome/libchrome_tools/patches/libchrome-Update-crypto.patch (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard WorkerFrom 23ecc2149133fa0cf369f53b5d7d28e78815bca3 Mon Sep 17 00:00:00 2001
2*635a8641SAndroid Build Coastguard WorkerFrom: Hidehiko Abe <[email protected]>
3*635a8641SAndroid Build Coastguard WorkerDate: Thu, 13 Jun 2019 22:27:41 +0900
4*635a8641SAndroid Build Coastguard WorkerSubject: [PATCH] libchrome: Update crypto.
5*635a8641SAndroid Build Coastguard Worker
6*635a8641SAndroid Build Coastguard Workerlibchrome uses OpenSSH, instead of BoringSSH, although its support
7*635a8641SAndroid Build Coastguard Workerwas dropped in Chrome already.
8*635a8641SAndroid Build Coastguard WorkerTo lengthen its lifetime, this patch adds minor fix.
9*635a8641SAndroid Build Coastguard Worker- Use base::data() instead of base::string_as_array().
10*635a8641SAndroid Build Coastguard Worker  The method was removed. cf) crrev.com/c/1056014.
11*635a8641SAndroid Build Coastguard Worker- Use base::PostTaskAndReply instead of base::WorkerPool.
12*635a8641SAndroid Build Coastguard Worker  The class was removed. cf) crrev.com/c/650368
13*635a8641SAndroid Build Coastguard Worker- tracked_object::Location is renamed to base::Location.
14*635a8641SAndroid Build Coastguard Worker  cf) crbug.com/763556
15*635a8641SAndroid Build Coastguard Worker- base::Location::Write was removed. Use ToString().
16*635a8641SAndroid Build Coastguard Worker  cf) crrev.com/c/707310
17*635a8641SAndroid Build Coastguard Worker- base::MakeUnique was removed. Use std::make_unique.
18*635a8641SAndroid Build Coastguard Worker  cf) crrev.com/c/944048
19*635a8641SAndroid Build Coastguard Worker
20*635a8641SAndroid Build Coastguard WorkerBUG=chromium:909719
21*635a8641SAndroid Build Coastguard WorkerTEST=Built locally.
22*635a8641SAndroid Build Coastguard Worker
23*635a8641SAndroid Build Coastguard WorkerChange-Id: I2ba45db7592ea9addc2df230b977ffb950f0b342
24*635a8641SAndroid Build Coastguard Worker---
25*635a8641SAndroid Build Coastguard Worker crypto/nss_util.cc     | 37 ++++++++++++++-----------------------
26*635a8641SAndroid Build Coastguard Worker crypto/openssl_util.cc |  6 ++----
27*635a8641SAndroid Build Coastguard Worker crypto/openssl_util.h  |  7 +++----
28*635a8641SAndroid Build Coastguard Worker crypto/sha2.cc         |  2 +-
29*635a8641SAndroid Build Coastguard Worker 4 files changed, 20 insertions(+), 32 deletions(-)
30*635a8641SAndroid Build Coastguard Worker
31*635a8641SAndroid Build Coastguard Workerdiff --git a/crypto/nss_util.cc b/crypto/nss_util.cc
32*635a8641SAndroid Build Coastguard Workerindex a7752d3..f9c6373 100644
33*635a8641SAndroid Build Coastguard Worker--- a/crypto/nss_util.cc
34*635a8641SAndroid Build Coastguard Worker+++ b/crypto/nss_util.cc
35*635a8641SAndroid Build Coastguard Worker@@ -38,14 +38,13 @@
36*635a8641SAndroid Build Coastguard Worker #include "base/files/file_util.h"
37*635a8641SAndroid Build Coastguard Worker #include "base/lazy_instance.h"
38*635a8641SAndroid Build Coastguard Worker #include "base/logging.h"
39*635a8641SAndroid Build Coastguard Worker-#include "base/memory/ptr_util.h"
40*635a8641SAndroid Build Coastguard Worker #include "base/message_loop/message_loop.h"
41*635a8641SAndroid Build Coastguard Worker #include "base/native_library.h"
42*635a8641SAndroid Build Coastguard Worker #include "base/stl_util.h"
43*635a8641SAndroid Build Coastguard Worker #include "base/strings/stringprintf.h"
44*635a8641SAndroid Build Coastguard Worker+#include "base/task_scheduler/post_task.h"
45*635a8641SAndroid Build Coastguard Worker #include "base/threading/thread_checker.h"
46*635a8641SAndroid Build Coastguard Worker #include "base/threading/thread_restrictions.h"
47*635a8641SAndroid Build Coastguard Worker-#include "base/threading/worker_pool.h"
48*635a8641SAndroid Build Coastguard Worker #include "build/build_config.h"
49*635a8641SAndroid Build Coastguard Worker
50*635a8641SAndroid Build Coastguard Worker #if !defined(OS_CHROMEOS)
51*635a8641SAndroid Build Coastguard Worker@@ -380,22 +379,16 @@ class NSSInitSingleton {
52*635a8641SAndroid Build Coastguard Worker     std::unique_ptr<TPMModuleAndSlot> tpm_args(
53*635a8641SAndroid Build Coastguard Worker         new TPMModuleAndSlot(chaps_module_));
54*635a8641SAndroid Build Coastguard Worker     TPMModuleAndSlot* tpm_args_ptr = tpm_args.get();
55*635a8641SAndroid Build Coastguard Worker-    if (base::WorkerPool::PostTaskAndReply(
56*635a8641SAndroid Build Coastguard Worker-            FROM_HERE,
57*635a8641SAndroid Build Coastguard Worker-            base::Bind(&NSSInitSingleton::InitializeTPMTokenOnWorkerThread,
58*635a8641SAndroid Build Coastguard Worker-                       system_slot_id,
59*635a8641SAndroid Build Coastguard Worker-                       tpm_args_ptr),
60*635a8641SAndroid Build Coastguard Worker-            base::Bind(&NSSInitSingleton::OnInitializedTPMTokenAndSystemSlot,
61*635a8641SAndroid Build Coastguard Worker-                       base::Unretained(this),  // NSSInitSingleton is leaky
62*635a8641SAndroid Build Coastguard Worker-                       callback,
63*635a8641SAndroid Build Coastguard Worker-                       base::Passed(&tpm_args)),
64*635a8641SAndroid Build Coastguard Worker-            true /* task_is_slow */
65*635a8641SAndroid Build Coastguard Worker-            )) {
66*635a8641SAndroid Build Coastguard Worker-      initializing_tpm_token_ = true;
67*635a8641SAndroid Build Coastguard Worker-    } else {
68*635a8641SAndroid Build Coastguard Worker-      base::MessageLoop::current()->task_runner()->PostTask(
69*635a8641SAndroid Build Coastguard Worker-          FROM_HERE, base::Bind(callback, false));
70*635a8641SAndroid Build Coastguard Worker-    }
71*635a8641SAndroid Build Coastguard Worker+    base::PostTaskAndReply(
72*635a8641SAndroid Build Coastguard Worker+        FROM_HERE,
73*635a8641SAndroid Build Coastguard Worker+        base::Bind(&NSSInitSingleton::InitializeTPMTokenOnWorkerThread,
74*635a8641SAndroid Build Coastguard Worker+                   system_slot_id,
75*635a8641SAndroid Build Coastguard Worker+                   tpm_args_ptr),
76*635a8641SAndroid Build Coastguard Worker+        base::Bind(&NSSInitSingleton::OnInitializedTPMTokenAndSystemSlot,
77*635a8641SAndroid Build Coastguard Worker+                   base::Unretained(this),  // NSSInitSingleton is leaky
78*635a8641SAndroid Build Coastguard Worker+                   callback,
79*635a8641SAndroid Build Coastguard Worker+                   base::Passed(&tpm_args)));
80*635a8641SAndroid Build Coastguard Worker+    initializing_tpm_token_ = true;
81*635a8641SAndroid Build Coastguard Worker   }
82*635a8641SAndroid Build Coastguard Worker
83*635a8641SAndroid Build Coastguard Worker   static void InitializeTPMTokenOnWorkerThread(CK_SLOT_ID token_slot_id,
84*635a8641SAndroid Build Coastguard Worker@@ -508,7 +501,7 @@ class NSSInitSingleton {
85*635a8641SAndroid Build Coastguard Worker         "%s %s", kUserNSSDatabaseName, username_hash.c_str());
86*635a8641SAndroid Build Coastguard Worker     ScopedPK11Slot public_slot(OpenPersistentNSSDBForPath(db_name, path));
87*635a8641SAndroid Build Coastguard Worker     chromeos_user_map_[username_hash] =
88*635a8641SAndroid Build Coastguard Worker-        base::MakeUnique<ChromeOSUserData>(std::move(public_slot));
89*635a8641SAndroid Build Coastguard Worker+        std::make_unique<ChromeOSUserData>(std::move(public_slot));
90*635a8641SAndroid Build Coastguard Worker     return true;
91*635a8641SAndroid Build Coastguard Worker   }
92*635a8641SAndroid Build Coastguard Worker
93*635a8641SAndroid Build Coastguard Worker@@ -543,7 +536,7 @@ class NSSInitSingleton {
94*635a8641SAndroid Build Coastguard Worker     std::unique_ptr<TPMModuleAndSlot> tpm_args(
95*635a8641SAndroid Build Coastguard Worker         new TPMModuleAndSlot(chaps_module_));
96*635a8641SAndroid Build Coastguard Worker     TPMModuleAndSlot* tpm_args_ptr = tpm_args.get();
97*635a8641SAndroid Build Coastguard Worker-    base::WorkerPool::PostTaskAndReply(
98*635a8641SAndroid Build Coastguard Worker+    base::PostTaskAndReply(
99*635a8641SAndroid Build Coastguard Worker         FROM_HERE,
100*635a8641SAndroid Build Coastguard Worker         base::Bind(&NSSInitSingleton::InitializeTPMTokenOnWorkerThread,
101*635a8641SAndroid Build Coastguard Worker                    slot_id,
102*635a8641SAndroid Build Coastguard Worker@@ -551,9 +544,7 @@ class NSSInitSingleton {
103*635a8641SAndroid Build Coastguard Worker         base::Bind(&NSSInitSingleton::OnInitializedTPMForChromeOSUser,
104*635a8641SAndroid Build Coastguard Worker                    base::Unretained(this),  // NSSInitSingleton is leaky
105*635a8641SAndroid Build Coastguard Worker                    username_hash,
106*635a8641SAndroid Build Coastguard Worker-                   base::Passed(&tpm_args)),
107*635a8641SAndroid Build Coastguard Worker-        true /* task_is_slow */
108*635a8641SAndroid Build Coastguard Worker-        );
109*635a8641SAndroid Build Coastguard Worker+                   base::Passed(&tpm_args)));
110*635a8641SAndroid Build Coastguard Worker   }
111*635a8641SAndroid Build Coastguard Worker
112*635a8641SAndroid Build Coastguard Worker   void OnInitializedTPMForChromeOSUser(
113*635a8641SAndroid Build Coastguard Workerdiff --git a/crypto/openssl_util.cc b/crypto/openssl_util.cc
114*635a8641SAndroid Build Coastguard Workerindex c1b7a90..b671eab 100644
115*635a8641SAndroid Build Coastguard Worker--- a/crypto/openssl_util.cc
116*635a8641SAndroid Build Coastguard Worker+++ b/crypto/openssl_util.cc
117*635a8641SAndroid Build Coastguard Worker@@ -46,15 +46,13 @@ void EnsureOpenSSLInit() {
118*635a8641SAndroid Build Coastguard Worker #endif
119*635a8641SAndroid Build Coastguard Worker }
120*635a8641SAndroid Build Coastguard Worker
121*635a8641SAndroid Build Coastguard Worker-void ClearOpenSSLERRStack(const tracked_objects::Location& location) {
122*635a8641SAndroid Build Coastguard Worker+void ClearOpenSSLERRStack(const base::Location& location) {
123*635a8641SAndroid Build Coastguard Worker   if (DCHECK_IS_ON() && VLOG_IS_ON(1)) {
124*635a8641SAndroid Build Coastguard Worker     uint32_t error_num = ERR_peek_error();
125*635a8641SAndroid Build Coastguard Worker     if (error_num == 0)
126*635a8641SAndroid Build Coastguard Worker       return;
127*635a8641SAndroid Build Coastguard Worker
128*635a8641SAndroid Build Coastguard Worker-    std::string message;
129*635a8641SAndroid Build Coastguard Worker-    location.Write(true, true, &message);
130*635a8641SAndroid Build Coastguard Worker-    DVLOG(1) << "OpenSSL ERR_get_error stack from " << message;
131*635a8641SAndroid Build Coastguard Worker+    DVLOG(1) << "OpenSSL ERR_get_error stack from " << location.ToString();
132*635a8641SAndroid Build Coastguard Worker     ERR_print_errors_cb(&OpenSSLErrorCallback, NULL);
133*635a8641SAndroid Build Coastguard Worker   } else {
134*635a8641SAndroid Build Coastguard Worker     ERR_clear_error();
135*635a8641SAndroid Build Coastguard Workerdiff --git a/crypto/openssl_util.h b/crypto/openssl_util.h
136*635a8641SAndroid Build Coastguard Workerindex d608cde..c3d6cc9 100644
137*635a8641SAndroid Build Coastguard Worker--- a/crypto/openssl_util.h
138*635a8641SAndroid Build Coastguard Worker+++ b/crypto/openssl_util.h
139*635a8641SAndroid Build Coastguard Worker@@ -63,8 +63,7 @@ CRYPTO_EXPORT void EnsureOpenSSLInit();
140*635a8641SAndroid Build Coastguard Worker // Drains the OpenSSL ERR_get_error stack. On a debug build the error codes
141*635a8641SAndroid Build Coastguard Worker // are send to VLOG(1), on a release build they are disregarded. In most
142*635a8641SAndroid Build Coastguard Worker // cases you should pass FROM_HERE as the |location|.
143*635a8641SAndroid Build Coastguard Worker-CRYPTO_EXPORT void ClearOpenSSLERRStack(
144*635a8641SAndroid Build Coastguard Worker-    const tracked_objects::Location& location);
145*635a8641SAndroid Build Coastguard Worker+CRYPTO_EXPORT void ClearOpenSSLERRStack(const base::Location& location);
146*635a8641SAndroid Build Coastguard Worker
147*635a8641SAndroid Build Coastguard Worker // Place an instance of this class on the call stack to automatically clear
148*635a8641SAndroid Build Coastguard Worker // the OpenSSL error stack on function exit.
149*635a8641SAndroid Build Coastguard Worker@@ -73,7 +72,7 @@ class OpenSSLErrStackTracer {
150*635a8641SAndroid Build Coastguard Worker   // Pass FROM_HERE as |location|, to help track the source of OpenSSL error
151*635a8641SAndroid Build Coastguard Worker   // messages. Note any diagnostic emitted will be tagged with the location of
152*635a8641SAndroid Build Coastguard Worker   // the constructor call as it's not possible to trace a destructor's callsite.
153*635a8641SAndroid Build Coastguard Worker-  explicit OpenSSLErrStackTracer(const tracked_objects::Location& location)
154*635a8641SAndroid Build Coastguard Worker+  explicit OpenSSLErrStackTracer(const base::Location& location)
155*635a8641SAndroid Build Coastguard Worker       : location_(location) {
156*635a8641SAndroid Build Coastguard Worker     EnsureOpenSSLInit();
157*635a8641SAndroid Build Coastguard Worker   }
158*635a8641SAndroid Build Coastguard Worker@@ -82,7 +81,7 @@ class OpenSSLErrStackTracer {
159*635a8641SAndroid Build Coastguard Worker   }
160*635a8641SAndroid Build Coastguard Worker
161*635a8641SAndroid Build Coastguard Worker  private:
162*635a8641SAndroid Build Coastguard Worker-  const tracked_objects::Location location_;
163*635a8641SAndroid Build Coastguard Worker+  const base::Location location_;
164*635a8641SAndroid Build Coastguard Worker
165*635a8641SAndroid Build Coastguard Worker   DISALLOW_IMPLICIT_CONSTRUCTORS(OpenSSLErrStackTracer);
166*635a8641SAndroid Build Coastguard Worker };
167*635a8641SAndroid Build Coastguard Workerdiff --git a/crypto/sha2.cc b/crypto/sha2.cc
168*635a8641SAndroid Build Coastguard Workerindex 1b302b3..71566a9 100644
169*635a8641SAndroid Build Coastguard Worker--- a/crypto/sha2.cc
170*635a8641SAndroid Build Coastguard Worker+++ b/crypto/sha2.cc
171*635a8641SAndroid Build Coastguard Worker@@ -21,7 +21,7 @@ void SHA256HashString(const base::StringPiece& str, void* output, size_t len) {
172*635a8641SAndroid Build Coastguard Worker
173*635a8641SAndroid Build Coastguard Worker std::string SHA256HashString(const base::StringPiece& str) {
174*635a8641SAndroid Build Coastguard Worker   std::string output(kSHA256Length, 0);
175*635a8641SAndroid Build Coastguard Worker-  SHA256HashString(str, base::string_as_array(&output), output.size());
176*635a8641SAndroid Build Coastguard Worker+  SHA256HashString(str, base::data(output), output.size());
177*635a8641SAndroid Build Coastguard Worker   return output;
178*635a8641SAndroid Build Coastguard Worker }
179*635a8641SAndroid Build Coastguard Worker
180*635a8641SAndroid Build Coastguard Worker--
181*635a8641SAndroid Build Coastguard Worker2.22.0.rc2.383.gf4fbbf30c2-goog
182*635a8641SAndroid Build Coastguard Worker
183