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

Side by Side Diff: Source/modules/websockets/WebSocketHandshake.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 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 3 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 20 matching lines...) Expand all
31 31
32 #include "config.h" 32 #include "config.h"
33 33
34 #include "modules/websockets/WebSocketHandshake.h" 34 #include "modules/websockets/WebSocketHandshake.h"
35 35
36 #include "core/dom/Document.h" 36 #include "core/dom/Document.h"
37 #include "core/inspector/ScriptCallStack.h" 37 #include "core/inspector/ScriptCallStack.h"
38 #include "core/loader/CookieJar.h" 38 #include "core/loader/CookieJar.h"
39 #include "modules/websockets/WebSocket.h" 39 #include "modules/websockets/WebSocket.h"
40 #include "platform/Cookie.h" 40 #include "platform/Cookie.h"
41 #include "platform/CryptoUtilities.h"
41 #include "platform/Logging.h" 42 #include "platform/Logging.h"
42 #include "platform/network/HTTPHeaderMap.h" 43 #include "platform/network/HTTPHeaderMap.h"
43 #include "platform/network/HTTPParsers.h" 44 #include "platform/network/HTTPParsers.h"
44 #include "platform/weborigin/SecurityOrigin.h" 45 #include "platform/weborigin/SecurityOrigin.h"
45 #include "public/platform/Platform.h" 46 #include "public/platform/Platform.h"
46 #include "wtf/CryptographicallyRandomNumber.h" 47 #include "wtf/CryptographicallyRandomNumber.h"
47 #include "wtf/SHA1.h"
48 #include "wtf/StdLibExtras.h" 48 #include "wtf/StdLibExtras.h"
49 #include "wtf/StringExtras.h" 49 #include "wtf/StringExtras.h"
50 #include "wtf/Vector.h" 50 #include "wtf/Vector.h"
51 #include "wtf/text/Base64.h" 51 #include "wtf/text/Base64.h"
52 #include "wtf/text/CString.h" 52 #include "wtf/text/CString.h"
53 #include "wtf/text/StringBuilder.h" 53 #include "wtf/text/StringBuilder.h"
54 #include "wtf/unicode/CharacterNames.h" 54 #include "wtf/unicode/CharacterNames.h"
55 55
56 namespace WebCore { 56 namespace WebCore {
57 57
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 { 112 {
113 static const size_t nonceSize = 16; 113 static const size_t nonceSize = 16;
114 unsigned char key[nonceSize]; 114 unsigned char key[nonceSize];
115 cryptographicallyRandomValues(key, nonceSize); 115 cryptographicallyRandomValues(key, nonceSize);
116 return base64Encode(reinterpret_cast<char*>(key), nonceSize); 116 return base64Encode(reinterpret_cast<char*>(key), nonceSize);
117 } 117 }
118 118
119 String WebSocketHandshake::getExpectedWebSocketAccept(const String& secWebSocket Key) 119 String WebSocketHandshake::getExpectedWebSocketAccept(const String& secWebSocket Key)
120 { 120 {
121 static const char webSocketKeyGUID[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11 "; 121 static const char webSocketKeyGUID[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11 ";
122 SHA1 sha1;
123 CString keyData = secWebSocketKey.ascii(); 122 CString keyData = secWebSocketKey.ascii();
124 sha1.addBytes(reinterpret_cast<const uint8_t*>(keyData.data()), keyData.leng th()); 123
125 sha1.addBytes(reinterpret_cast<const uint8_t*>(webSocketKeyGUID), strlen(web SocketKeyGUID)); 124 StringBuilder digestable;
126 Vector<uint8_t, SHA1::outputSizeBytes> hash; 125 digestable.append(secWebSocketKey);
127 sha1.computeHash(hash); 126 digestable.append(webSocketKeyGUID, strlen(webSocketKeyGUID));
128 return base64Encode(reinterpret_cast<const char*>(hash.data()), 127 CString digestableCString = digestable.toString().utf8();
129 SHA1::outputSizeBytes); 128 CryptoUtil::DigestValue digest;
129 CryptoUtil::computeDigest(CryptoUtil::HashAlgorithmSha1, digestableCString.d ata(), digestableCString.length(), digest);
130
131 return base64Encode(reinterpret_cast<const char*>(digest.data()), CryptoUtil ::sha1HashSize);
eseidel 2014/03/12 06:50:29 Do we really need a reinterpret cast here?
jww 2014/04/01 23:29:09 Yes. As per your other comment, it's a vector of u
130 } 132 }
131 133
132 WebSocketHandshake::WebSocketHandshake(const KURL& url, const String& protocol, Document* document) 134 WebSocketHandshake::WebSocketHandshake(const KURL& url, const String& protocol, Document* document)
133 : m_url(url) 135 : m_url(url)
134 , m_clientProtocol(protocol) 136 , m_clientProtocol(protocol)
135 , m_secure(m_url.protocolIs("wss")) 137 , m_secure(m_url.protocolIs("wss"))
136 , m_document(document) 138 , m_document(document)
137 , m_mode(Incomplete) 139 , m_mode(Incomplete)
138 { 140 {
139 m_secWebSocketKey = generateSecWebSocketKey(); 141 m_secWebSocketKey = generateSecWebSocketKey();
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 } 579 }
578 if (!match) { 580 if (!match) {
579 m_failureReason = formatHandshakeFailureReason("Sent non-empty 'Sec- WebSocket-Protocol' header but no response was received"); 581 m_failureReason = formatHandshakeFailureReason("Sent non-empty 'Sec- WebSocket-Protocol' header but no response was received");
580 return false; 582 return false;
581 } 583 }
582 } 584 }
583 return true; 585 return true;
584 } 586 }
585 587
586 } // namespace WebCore 588 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698