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

Side by Side Diff: Source/core/frame/csp/CSPSourceList.cpp

Issue 189373010: Get rid of WTF::SHA1. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase on ToT Created 6 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "config.h" 5 #include "config.h"
6 #include "core/frame/csp/CSPSourceList.h" 6 #include "core/frame/csp/CSPSourceList.h"
7 7
8 #include "core/frame/csp/CSPSource.h" 8 #include "core/frame/csp/CSPSource.h"
9 #include "core/frame/csp/ContentSecurityPolicy.h" 9 #include "core/frame/csp/ContentSecurityPolicy.h"
10 #include "platform/CryptoUtilities.h"
10 #include "platform/ParsingUtilities.h" 11 #include "platform/ParsingUtilities.h"
11 #include "platform/weborigin/KURL.h" 12 #include "platform/weborigin/KURL.h"
12 #include "platform/weborigin/SecurityOrigin.h" 13 #include "platform/weborigin/SecurityOrigin.h"
13 #include "wtf/HashSet.h" 14 #include "wtf/HashSet.h"
14 #include "wtf/StringHasher.h"
15 #include "wtf/text/Base64.h" 15 #include "wtf/text/Base64.h"
16 #include "wtf/text/WTFString.h" 16 #include "wtf/text/WTFString.h"
17 17
18 namespace WTF {
19
20 struct DigestValueHash {
21 static unsigned hash(const WebCore::DigestValue& v)
22 {
23 return StringHasher::computeHash(v.data(), v.size());
24 }
25 static bool equal(const WebCore::DigestValue& a, const WebCore::DigestValue& b)
26 {
27 return a == b;
28 };
29 static const bool safeToCompareToEmptyOrDeleted = true;
30 };
31 template <>
32 struct DefaultHash<WebCore::DigestValue> {
33 typedef DigestValueHash Hash;
34 };
35
36 template <>
37 struct DefaultHash<WebCore::ContentSecurityPolicyHashAlgorithm> {
38 typedef IntHash<WebCore::ContentSecurityPolicyHashAlgorithm> Hash;
39 };
40 template <>
41 struct HashTraits<WebCore::ContentSecurityPolicyHashAlgorithm> : UnsignedWithZer oKeyHashTraits<WebCore::ContentSecurityPolicyHashAlgorithm> {
42 };
43
44 } // namespace WTF
45
46 namespace WebCore { 18 namespace WebCore {
47 19
48 static bool isSourceListNone(const UChar* begin, const UChar* end) 20 static bool isSourceListNone(const UChar* begin, const UChar* end)
49 { 21 {
50 skipWhile<UChar, isASCIISpace>(begin, end); 22 skipWhile<UChar, isASCIISpace>(begin, end);
51 23
52 const UChar* position = begin; 24 const UChar* position = begin;
53 skipWhile<UChar, isSourceCharacter>(position, end); 25 skipWhile<UChar, isSourceCharacter>(position, end);
54 if (!equalIgnoringCase("'none'", begin, position - begin)) 26 if (!equalIgnoringCase("'none'", begin, position - begin))
55 return false; 27 return false;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 if (m_policy->experimentalFeaturesEnabled()) { 162 if (m_policy->experimentalFeaturesEnabled()) {
191 String nonce; 163 String nonce;
192 if (!parseNonce(begin, end, nonce)) 164 if (!parseNonce(begin, end, nonce))
193 return false; 165 return false;
194 166
195 if (!nonce.isNull()) { 167 if (!nonce.isNull()) {
196 addSourceNonce(nonce); 168 addSourceNonce(nonce);
197 return true; 169 return true;
198 } 170 }
199 171
200 DigestValue hash; 172 CryptoUtil::DigestValue hash;
201 ContentSecurityPolicyHashAlgorithm algorithm = ContentSecurityPolicyHash AlgorithmNone; 173 ContentSecurityPolicyHashAlgorithm algorithm = ContentSecurityPolicyHash AlgorithmNone;
202 if (!parseHash(begin, end, hash, algorithm)) 174 if (!parseHash(begin, end, hash, algorithm))
203 return false; 175 return false;
204 176
205 if (hash.size() > 0) { 177 if (hash.size() > 0) {
206 addSourceHash(algorithm, hash); 178 addSourceHash(algorithm, hash);
207 return true; 179 return true;
208 } 180 }
209 } 181 }
210 182
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 return false; 274 return false;
303 275
304 nonce = String(nonceBegin, position - nonceBegin); 276 nonce = String(nonceBegin, position - nonceBegin);
305 return true; 277 return true;
306 } 278 }
307 279
308 // hash-source = "'" hash-algorithm "-" hash-value "'" 280 // hash-source = "'" hash-algorithm "-" hash-value "'"
309 // hash-algorithm = "sha1" / "sha256" / "sha384" / "sha512" 281 // hash-algorithm = "sha1" / "sha256" / "sha384" / "sha512"
310 // hash-value = 1*( ALPHA / DIGIT / "+" / "/" / "=" ) 282 // hash-value = 1*( ALPHA / DIGIT / "+" / "/" / "=" )
311 // 283 //
312 bool CSPSourceList::parseHash(const UChar* begin, const UChar* end, DigestValue& hash, ContentSecurityPolicyHashAlgorithm& hashAlgorithm) 284 bool CSPSourceList::parseHash(const UChar* begin, const UChar* end, CryptoUtil:: DigestValue& hash, ContentSecurityPolicyHashAlgorithm& hashAlgorithm)
313 { 285 {
314 // Any additions or subtractions from this struct should also modify the 286 // Any additions or subtractions from this struct should also modify the
315 // respective entries in the kAlgorithmMap array in checkDigest(). 287 // respective entries in the kAlgorithmMap array in checkDigest().
316 static const struct { 288 static const struct {
317 const char* prefix; 289 const char* prefix;
318 ContentSecurityPolicyHashAlgorithm algorithm; 290 ContentSecurityPolicyHashAlgorithm algorithm;
319 } kSupportedPrefixes[] = { 291 } kSupportedPrefixes[] = {
320 { "'sha1-", ContentSecurityPolicyHashAlgorithmSha1 }, 292 { "'sha1-", ContentSecurityPolicyHashAlgorithmSha1 },
321 { "'sha256-", ContentSecurityPolicyHashAlgorithmSha256 }, 293 { "'sha256-", ContentSecurityPolicyHashAlgorithmSha256 },
322 { "'sha384-", ContentSecurityPolicyHashAlgorithmSha384 }, 294 { "'sha384-", ContentSecurityPolicyHashAlgorithmSha384 },
(...skipping 28 matching lines...) Expand all
351 323
352 // Base64 encodings may end with exactly one or two '=' characters 324 // Base64 encodings may end with exactly one or two '=' characters
353 skipExactly<UChar>(position, position + 1, '='); 325 skipExactly<UChar>(position, position + 1, '=');
354 skipExactly<UChar>(position, position + 1, '='); 326 skipExactly<UChar>(position, position + 1, '=');
355 327
356 if ((position + 1) != end || *position != '\'' || !(position - hashBegin)) 328 if ((position + 1) != end || *position != '\'' || !(position - hashBegin))
357 return false; 329 return false;
358 330
359 Vector<char> hashVector; 331 Vector<char> hashVector;
360 base64Decode(hashBegin, position - hashBegin, hashVector); 332 base64Decode(hashBegin, position - hashBegin, hashVector);
361 if (hashVector.size() > kMaxDigestSize) 333 if (hashVector.size() > CryptoUtil::kMaxDigestSize)
362 return false; 334 return false;
363 hash.append(reinterpret_cast<uint8_t*>(hashVector.data()), hashVector.size() ); 335 hash.append(reinterpret_cast<uint8_t*>(hashVector.data()), hashVector.size() );
364 return true; 336 return true;
365 } 337 }
366 338
367 // ; <scheme> production from RFC 3986 339 // ; <scheme> production from RFC 3986
368 // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) 340 // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
369 // 341 //
370 bool CSPSourceList::parseScheme(const UChar* begin, const UChar* end, String& sc heme) 342 bool CSPSourceList::parseScheme(const UChar* begin, const UChar* end, String& sc heme)
371 { 343 {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 void CSPSourceList::addSourceUnsafeEval() 471 void CSPSourceList::addSourceUnsafeEval()
500 { 472 {
501 m_allowEval = true; 473 m_allowEval = true;
502 } 474 }
503 475
504 void CSPSourceList::addSourceNonce(const String& nonce) 476 void CSPSourceList::addSourceNonce(const String& nonce)
505 { 477 {
506 m_nonces.add(nonce); 478 m_nonces.add(nonce);
507 } 479 }
508 480
509 void CSPSourceList::addSourceHash(const ContentSecurityPolicyHashAlgorithm& algo rithm, const DigestValue& hash) 481 void CSPSourceList::addSourceHash(const ContentSecurityPolicyHashAlgorithm& algo rithm, const CryptoUtil::DigestValue& hash)
510 { 482 {
511 m_hashes.add(CSPHashValue(algorithm, hash)); 483 m_hashes.add(CSPHashValue(algorithm, hash));
512 m_hashAlgorithmsUsed |= algorithm; 484 m_hashAlgorithmsUsed |= algorithm;
513 } 485 }
514 486
515 487
516 } // namespace WebCore 488 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698