| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  *  Copyright 2004 The WebRTC Project Authors. All rights reserved. |    2  *  Copyright 2004 The WebRTC Project Authors. All rights reserved. | 
|    3  * |    3  * | 
|    4  *  Use of this source code is governed by a BSD-style license |    4  *  Use of this source code is governed by a BSD-style license | 
|    5  *  that can be found in the LICENSE file in the root of the source |    5  *  that can be found in the LICENSE file in the root of the source | 
|    6  *  tree. An additional intellectual property rights grant can be found |    6  *  tree. An additional intellectual property rights grant can be found | 
|    7  *  in the file PATENTS.  All contributing project authors may |    7  *  in the file PATENTS.  All contributing project authors may | 
|    8  *  be found in the AUTHORS file in the root of the source tree. |    8  *  be found in the AUTHORS file in the root of the source tree. | 
|    9  */ |    9  */ | 
|   10  |   10  | 
|   11 #include "webrtc/p2p/base/stun.h" |   11 #include "webrtc/p2p/base/stun.h" | 
|   12  |   12  | 
|   13 #include <string.h> |   13 #include <string.h> | 
|   14  |   14  | 
 |   15 #include <memory> | 
 |   16  | 
|   15 #include "webrtc/base/byteorder.h" |   17 #include "webrtc/base/byteorder.h" | 
|   16 #include "webrtc/base/common.h" |   18 #include "webrtc/base/common.h" | 
|   17 #include "webrtc/base/crc32.h" |   19 #include "webrtc/base/crc32.h" | 
|   18 #include "webrtc/base/logging.h" |   20 #include "webrtc/base/logging.h" | 
|   19 #include "webrtc/base/messagedigest.h" |   21 #include "webrtc/base/messagedigest.h" | 
|   20 #include "webrtc/base/scoped_ptr.h" |  | 
|   21 #include "webrtc/base/stringencode.h" |   22 #include "webrtc/base/stringencode.h" | 
|   22  |   23  | 
|   23 using rtc::ByteBufferReader; |   24 using rtc::ByteBufferReader; | 
|   24 using rtc::ByteBufferWriter; |   25 using rtc::ByteBufferWriter; | 
|   25  |   26  | 
|   26 namespace cricket { |   27 namespace cricket { | 
|   27  |   28  | 
|   28 const char STUN_ERROR_REASON_TRY_ALTERNATE_SERVER[] = "Try Alternate Server"; |   29 const char STUN_ERROR_REASON_TRY_ALTERNATE_SERVER[] = "Try Alternate Server"; | 
|   29 const char STUN_ERROR_REASON_BAD_REQUEST[] = "Bad Request"; |   30 const char STUN_ERROR_REASON_BAD_REQUEST[] = "Bad Request"; | 
|   30 const char STUN_ERROR_REASON_UNAUTHORIZED[] = "Unauthorized"; |   31 const char STUN_ERROR_REASON_UNAUTHORIZED[] = "Unauthorized"; | 
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  166       current_pos += (4 - (attr_length % 4)); |  167       current_pos += (4 - (attr_length % 4)); | 
|  167     } |  168     } | 
|  168   } |  169   } | 
|  169  |  170  | 
|  170   if (!has_message_integrity_attr) { |  171   if (!has_message_integrity_attr) { | 
|  171     return false; |  172     return false; | 
|  172   } |  173   } | 
|  173  |  174  | 
|  174   // Getting length of the message to calculate Message Integrity. |  175   // Getting length of the message to calculate Message Integrity. | 
|  175   size_t mi_pos = current_pos; |  176   size_t mi_pos = current_pos; | 
|  176   rtc::scoped_ptr<char[]> temp_data(new char[current_pos]); |  177   std::unique_ptr<char[]> temp_data(new char[current_pos]); | 
|  177   memcpy(temp_data.get(), data, current_pos); |  178   memcpy(temp_data.get(), data, current_pos); | 
|  178   if (size > mi_pos + kStunAttributeHeaderSize + kStunMessageIntegritySize) { |  179   if (size > mi_pos + kStunAttributeHeaderSize + kStunMessageIntegritySize) { | 
|  179     // Stun message has other attributes after message integrity. |  180     // Stun message has other attributes after message integrity. | 
|  180     // Adjust the length parameter in stun message to calculate HMAC. |  181     // Adjust the length parameter in stun message to calculate HMAC. | 
|  181     size_t extra_offset = size - |  182     size_t extra_offset = size - | 
|  182         (mi_pos + kStunAttributeHeaderSize + kStunMessageIntegritySize); |  183         (mi_pos + kStunAttributeHeaderSize + kStunMessageIntegritySize); | 
|  183     size_t new_adjusted_len = size - extra_offset - kStunHeaderSize; |  184     size_t new_adjusted_len = size - extra_offset - kStunHeaderSize; | 
|  184  |  185  | 
|  185     // Writing new length of the STUN message @ Message Length in temp buffer. |  186     // Writing new length of the STUN message @ Message Length in temp buffer. | 
|  186     //      0                   1                   2                   3 |  187     //      0                   1                   2                   3 | 
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  910       digest, sizeof(digest)); |  911       digest, sizeof(digest)); | 
|  911   if (size == 0) { |  912   if (size == 0) { | 
|  912     return false; |  913     return false; | 
|  913   } |  914   } | 
|  914  |  915  | 
|  915   *hash = std::string(digest, size); |  916   *hash = std::string(digest, size); | 
|  916   return true; |  917   return true; | 
|  917 } |  918 } | 
|  918  |  919  | 
|  919 }  // namespace cricket |  920 }  // namespace cricket | 
| OLD | NEW |