Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: components/webcrypto/fuzzer_support.cc

Issue 2162303002: [webcrypto] Add support for import/export of "raw" formatted EC keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usage_order
Patch Set: address feedback Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/webcrypto/fuzzer_support.h" 5 #include "components/webcrypto/fuzzer_support.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/numerics/safe_conversions.h" 9 #include "base/numerics/safe_conversions.h"
10 #include "components/test_runner/test_common.h" 10 #include "components/test_runner/test_common.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 CreateEcImportAlgorithm(algorithm_id, curve), true, usages, &key); 88 CreateEcImportAlgorithm(algorithm_id, curve), true, usages, &key);
89 89
90 // These errors imply a bad setup of parameters, and means ImportKey() may not 90 // These errors imply a bad setup of parameters, and means ImportKey() may not
91 // be testing the actual parsing. 91 // be testing the actual parsing.
92 DCHECK_NE(status.error_details(), 92 DCHECK_NE(status.error_details(),
93 Status::ErrorUnsupportedImportKeyFormat().error_details()); 93 Status::ErrorUnsupportedImportKeyFormat().error_details());
94 DCHECK_NE(status.error_details(), 94 DCHECK_NE(status.error_details(),
95 Status::ErrorCreateKeyBadUsages().error_details()); 95 Status::ErrorCreateKeyBadUsages().error_details());
96 } 96 }
97 97
98 void ImportEcKeyFromRawFuzzData(const uint8_t* data, size_t size) {
99 EnsureInitialized();
100
101 // There are 3 possible EC named curves. Consume the first byte to decide on
102 // the curve.
103 uint8_t curve_index = 0;
104 if (size > 0) {
105 curve_index = data[0];
106 data++;
107 size--;
108 }
109
110 blink::WebCryptoNamedCurve curve;
111
112 switch (curve_index % 3) {
113 case 0:
114 curve = blink::WebCryptoNamedCurveP256;
115 break;
116 case 1:
117 curve = blink::WebCryptoNamedCurveP384;
118 break;
119 default:
120 curve = blink::WebCryptoNamedCurveP521;
121 break;
122 }
123
124 // Always use ECDSA as the algorithm. Shouldn't make an difference for import.
125 blink::WebCryptoAlgorithmId algorithm_id = blink::WebCryptoAlgorithmIdEcdsa;
126
127 // Use key usages that are compatible with the chosen algorithm and key type.
128 blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageVerify;
129
130 blink::WebCryptoKey key;
131 webcrypto::Status status = webcrypto::ImportKey(
132 blink::WebCryptoKeyFormatRaw,
133 webcrypto::CryptoData(data, base::checked_cast<uint32_t>(size)),
134 CreateEcImportAlgorithm(algorithm_id, curve), true, usages, &key);
135
136 // These errors imply a bad setup of parameters, and means ImportKey() may not
137 // be testing the actual parsing.
138 DCHECK_NE(status.error_details(),
139 Status::ErrorUnsupportedImportKeyFormat().error_details());
140 DCHECK_NE(status.error_details(),
141 Status::ErrorCreateKeyBadUsages().error_details());
142 }
143
98 void ImportRsaKeyFromDerFuzzData(const uint8_t* data, 144 void ImportRsaKeyFromDerFuzzData(const uint8_t* data,
99 size_t size, 145 size_t size,
100 blink::WebCryptoKeyFormat format) { 146 blink::WebCryptoKeyFormat format) {
101 DCHECK(format == blink::WebCryptoKeyFormatSpki || 147 DCHECK(format == blink::WebCryptoKeyFormatSpki ||
102 format == blink::WebCryptoKeyFormatPkcs8); 148 format == blink::WebCryptoKeyFormatPkcs8);
103 EnsureInitialized(); 149 EnsureInitialized();
104 150
105 // There are several possible hash functions. Fix this parameter. It shouldn't 151 // There are several possible hash functions. Fix this parameter. It shouldn't
106 // matter based on the current implementation for PKCS8 or SPKI. But it 152 // matter based on the current implementation for PKCS8 or SPKI. But it
107 // will have an impact when parsing JWK format. 153 // will have an impact when parsing JWK format.
(...skipping 15 matching lines...) Expand all
123 169
124 // These errors imply a bad setup of parameters, and means ImportKey() may not 170 // These errors imply a bad setup of parameters, and means ImportKey() may not
125 // be testing the actual parsing. 171 // be testing the actual parsing.
126 DCHECK_NE(status.error_details(), 172 DCHECK_NE(status.error_details(),
127 Status::ErrorUnsupportedImportKeyFormat().error_details()); 173 Status::ErrorUnsupportedImportKeyFormat().error_details());
128 DCHECK_NE(status.error_details(), 174 DCHECK_NE(status.error_details(),
129 Status::ErrorCreateKeyBadUsages().error_details()); 175 Status::ErrorCreateKeyBadUsages().error_details());
130 } 176 }
131 177
132 } // namespace webcrypto 178 } // namespace webcrypto
OLDNEW
« no previous file with comments | « components/webcrypto/fuzzer_support.h ('k') | third_party/WebKit/LayoutTests/crypto/subtle/ecdh/import-export-raw.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698