OLD | NEW |
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 { | 114 { |
115 static const size_t nonceSize = 16; | 115 static const size_t nonceSize = 16; |
116 unsigned char key[nonceSize]; | 116 unsigned char key[nonceSize]; |
117 cryptographicallyRandomValues(key, nonceSize); | 117 cryptographicallyRandomValues(key, nonceSize); |
118 return base64Encode(reinterpret_cast<char*>(key), nonceSize); | 118 return base64Encode(reinterpret_cast<char*>(key), nonceSize); |
119 } | 119 } |
120 | 120 |
121 String WebSocketHandshake::getExpectedWebSocketAccept(const String& secWebSocket
Key) | 121 String WebSocketHandshake::getExpectedWebSocketAccept(const String& secWebSocket
Key) |
122 { | 122 { |
123 static const char webSocketKeyGUID[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11
"; | 123 static const char webSocketKeyGUID[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11
"; |
124 static const size_t sha1HashSize = 20; // FIXME: This should be defined in S
HA1.h. | |
125 SHA1 sha1; | 124 SHA1 sha1; |
126 CString keyData = secWebSocketKey.ascii(); | 125 CString keyData = secWebSocketKey.ascii(); |
127 sha1.addBytes(reinterpret_cast<const uint8_t*>(keyData.data()), keyData.leng
th()); | 126 sha1.addBytes(reinterpret_cast<const uint8_t*>(keyData.data()), keyData.leng
th()); |
128 sha1.addBytes(reinterpret_cast<const uint8_t*>(webSocketKeyGUID), strlen(web
SocketKeyGUID)); | 127 sha1.addBytes(reinterpret_cast<const uint8_t*>(webSocketKeyGUID), strlen(web
SocketKeyGUID)); |
129 Vector<uint8_t, sha1HashSize> hash; | 128 Vector<uint8_t, SHA1::outputSizeBytes> hash; |
130 sha1.computeHash(hash); | 129 sha1.computeHash(hash); |
131 return base64Encode(reinterpret_cast<const char*>(hash.data()), sha1HashSize
); | 130 return base64Encode(reinterpret_cast<const char*>(hash.data()), |
| 131 SHA1::outputSizeBytes); |
132 } | 132 } |
133 | 133 |
134 WebSocketHandshake::WebSocketHandshake(const KURL& url, const String& protocol,
ExecutionContext* context) | 134 WebSocketHandshake::WebSocketHandshake(const KURL& url, const String& protocol,
ExecutionContext* context) |
135 : m_url(url) | 135 : m_url(url) |
136 , m_clientProtocol(protocol) | 136 , m_clientProtocol(protocol) |
137 , m_secure(m_url.protocolIs("wss")) | 137 , m_secure(m_url.protocolIs("wss")) |
138 , m_context(context) | 138 , m_context(context) |
139 , m_mode(Incomplete) | 139 , m_mode(Incomplete) |
140 { | 140 { |
141 m_secWebSocketKey = generateSecWebSocketKey(); | 141 m_secWebSocketKey = generateSecWebSocketKey(); |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 } | 581 } |
582 if (!match) { | 582 if (!match) { |
583 m_failureReason = formatHandshakeFailureReason("Sent non-empty 'Sec-
WebSocket-Protocol' header but no response was received"); | 583 m_failureReason = formatHandshakeFailureReason("Sent non-empty 'Sec-
WebSocket-Protocol' header but no response was received"); |
584 return false; | 584 return false; |
585 } | 585 } |
586 } | 586 } |
587 return true; | 587 return true; |
588 } | 588 } |
589 | 589 |
590 } // namespace WebCore | 590 } // namespace WebCore |
OLD | NEW |