Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* |
michael@0 | 2 | Copyright (c) 2007, Adobe Systems, Incorporated |
michael@0 | 3 | All rights reserved. |
michael@0 | 4 | |
michael@0 | 5 | Redistribution and use in source and binary forms, with or without |
michael@0 | 6 | modification, are permitted provided that the following conditions are |
michael@0 | 7 | met: |
michael@0 | 8 | |
michael@0 | 9 | * Redistributions of source code must retain the above copyright |
michael@0 | 10 | notice, this list of conditions and the following disclaimer. |
michael@0 | 11 | |
michael@0 | 12 | * Redistributions in binary form must reproduce the above copyright |
michael@0 | 13 | notice, this list of conditions and the following disclaimer in the |
michael@0 | 14 | documentation and/or other materials provided with the distribution. |
michael@0 | 15 | |
michael@0 | 16 | * Neither the name of Adobe Systems, Network Resonance nor the names of its |
michael@0 | 17 | contributors may be used to endorse or promote products derived from |
michael@0 | 18 | this software without specific prior written permission. |
michael@0 | 19 | |
michael@0 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
michael@0 | 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@0 | 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@0 | 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
michael@0 | 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
michael@0 | 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
michael@0 | 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 31 | */ |
michael@0 | 32 | |
michael@0 | 33 | |
michael@0 | 34 | |
michael@0 | 35 | #ifndef _stun_msg_h |
michael@0 | 36 | #define _stun_msg_h |
michael@0 | 37 | |
michael@0 | 38 | #include "csi_platform.h" |
michael@0 | 39 | #include "nr_api.h" |
michael@0 | 40 | #include "transport_addr.h" |
michael@0 | 41 | |
michael@0 | 42 | #define NR_STUN_MAX_USERNAME_BYTES 513 |
michael@0 | 43 | #define NR_STUN_MAX_ERROR_CODE_REASON_BYTES 763 |
michael@0 | 44 | #define NR_STUN_MAX_ERROR_CODE_REASON_CHARS 128 |
michael@0 | 45 | #define NR_STUN_MAX_REALM_BYTES 763 |
michael@0 | 46 | #define NR_STUN_MAX_REALM_CHARS 128 |
michael@0 | 47 | #define NR_STUN_MAX_NONCE_BYTES 763 |
michael@0 | 48 | #define NR_STUN_MAX_NONCE_CHARS 128 |
michael@0 | 49 | #define NR_STUN_MAX_SERVER_BYTES 763 |
michael@0 | 50 | #define NR_STUN_MAX_SERVER_CHARS 128 |
michael@0 | 51 | #define NR_STUN_MAX_STRING_SIZE 763 /* any possible string */ |
michael@0 | 52 | #define NR_STUN_MAX_UNKNOWN_ATTRIBUTES 16 |
michael@0 | 53 | #define NR_STUN_MAX_MESSAGE_SIZE 2048 |
michael@0 | 54 | |
michael@0 | 55 | #define NR_STUN_MAGIC_COOKIE 0x2112A442 |
michael@0 | 56 | #define NR_STUN_MAGIC_COOKIE2 0xc5cb4e1d /* used recognize old stun messages */ |
michael@0 | 57 | |
michael@0 | 58 | typedef struct { UCHAR octet[12]; } UINT12; |
michael@0 | 59 | |
michael@0 | 60 | typedef struct nr_stun_attr_error_code_ { |
michael@0 | 61 | UINT2 number; |
michael@0 | 62 | char reason[NR_STUN_MAX_ERROR_CODE_REASON_BYTES+1]; /* +1 for \0 */ |
michael@0 | 63 | } nr_stun_attr_error_code; |
michael@0 | 64 | |
michael@0 | 65 | typedef struct nr_stun_attr_fingerprint_ { |
michael@0 | 66 | UINT4 checksum; |
michael@0 | 67 | int valid; |
michael@0 | 68 | } nr_stun_attr_fingerprint; |
michael@0 | 69 | |
michael@0 | 70 | typedef struct nr_stun_attr_message_integrity_ { |
michael@0 | 71 | UCHAR hash[20]; |
michael@0 | 72 | int unknown_user; |
michael@0 | 73 | UCHAR password[1024]; |
michael@0 | 74 | int passwordlen; |
michael@0 | 75 | int valid; |
michael@0 | 76 | } nr_stun_attr_message_integrity; |
michael@0 | 77 | |
michael@0 | 78 | typedef struct nr_stun_attr_unknown_attributes_ { |
michael@0 | 79 | UINT2 attribute[NR_STUN_MAX_UNKNOWN_ATTRIBUTES]; |
michael@0 | 80 | int num_attributes; |
michael@0 | 81 | } nr_stun_attr_unknown_attributes; |
michael@0 | 82 | |
michael@0 | 83 | typedef struct nr_stun_attr_xor_mapped_address_ { |
michael@0 | 84 | nr_transport_addr masked; |
michael@0 | 85 | nr_transport_addr unmasked; |
michael@0 | 86 | } nr_stun_attr_xor_mapped_address; |
michael@0 | 87 | |
michael@0 | 88 | typedef struct nr_stun_attr_data_ { |
michael@0 | 89 | UCHAR data[NR_STUN_MAX_MESSAGE_SIZE]; |
michael@0 | 90 | int length; |
michael@0 | 91 | } nr_stun_attr_data; |
michael@0 | 92 | |
michael@0 | 93 | |
michael@0 | 94 | typedef struct nr_stun_encoded_attribute_ { |
michael@0 | 95 | UINT2 type; |
michael@0 | 96 | UINT2 length; |
michael@0 | 97 | UCHAR value[NR_STUN_MAX_MESSAGE_SIZE]; |
michael@0 | 98 | } nr_stun_encoded_attribute; |
michael@0 | 99 | |
michael@0 | 100 | typedef struct nr_stun_message_attribute_ { |
michael@0 | 101 | UINT2 type; |
michael@0 | 102 | UINT2 length; |
michael@0 | 103 | union { |
michael@0 | 104 | nr_transport_addr address; |
michael@0 | 105 | nr_transport_addr alternate_server; |
michael@0 | 106 | nr_stun_attr_error_code error_code; |
michael@0 | 107 | nr_stun_attr_fingerprint fingerprint; |
michael@0 | 108 | nr_transport_addr mapped_address; |
michael@0 | 109 | nr_stun_attr_message_integrity message_integrity; |
michael@0 | 110 | char nonce[NR_STUN_MAX_NONCE_BYTES+1]; /* +1 for \0 */ |
michael@0 | 111 | char realm[NR_STUN_MAX_REALM_BYTES+1]; /* +1 for \0 */ |
michael@0 | 112 | nr_stun_attr_xor_mapped_address relay_address; |
michael@0 | 113 | char server_name[NR_STUN_MAX_SERVER_BYTES+1]; /* +1 for \0 */ |
michael@0 | 114 | nr_stun_attr_unknown_attributes unknown_attributes; |
michael@0 | 115 | char username[NR_STUN_MAX_USERNAME_BYTES+1]; /* +1 for \0 */ |
michael@0 | 116 | nr_stun_attr_xor_mapped_address xor_mapped_address; |
michael@0 | 117 | |
michael@0 | 118 | #ifdef USE_ICE |
michael@0 | 119 | UINT4 priority; |
michael@0 | 120 | UINT8 ice_controlled; |
michael@0 | 121 | UINT8 ice_controlling; |
michael@0 | 122 | #endif /* USE_ICE */ |
michael@0 | 123 | |
michael@0 | 124 | #ifdef USE_TURN |
michael@0 | 125 | UINT4 lifetime_secs; |
michael@0 | 126 | nr_transport_addr remote_address; |
michael@0 | 127 | UCHAR requested_transport; |
michael@0 | 128 | nr_stun_attr_data data; |
michael@0 | 129 | #endif /* USE_TURN */ |
michael@0 | 130 | |
michael@0 | 131 | #ifdef USE_STUND_0_96 |
michael@0 | 132 | UINT4 change_request; |
michael@0 | 133 | #endif /* USE_STUND_0_96 */ |
michael@0 | 134 | |
michael@0 | 135 | /* make sure there's enough room here to place any possible |
michael@0 | 136 | * attribute */ |
michael@0 | 137 | UCHAR largest_possible_attribute[NR_STUN_MAX_MESSAGE_SIZE]; |
michael@0 | 138 | } u; |
michael@0 | 139 | nr_stun_encoded_attribute *encoding; |
michael@0 | 140 | int encoding_length; |
michael@0 | 141 | char *name; |
michael@0 | 142 | char *type_name; |
michael@0 | 143 | int invalid; |
michael@0 | 144 | TAILQ_ENTRY(nr_stun_message_attribute_) entry; |
michael@0 | 145 | } nr_stun_message_attribute; |
michael@0 | 146 | |
michael@0 | 147 | typedef TAILQ_HEAD(nr_stun_message_attribute_head_,nr_stun_message_attribute_) nr_stun_message_attribute_head; |
michael@0 | 148 | |
michael@0 | 149 | typedef struct nr_stun_message_header_ { |
michael@0 | 150 | UINT2 type; |
michael@0 | 151 | UINT2 length; |
michael@0 | 152 | UINT4 magic_cookie; |
michael@0 | 153 | UINT12 id; |
michael@0 | 154 | } nr_stun_message_header; |
michael@0 | 155 | |
michael@0 | 156 | typedef struct nr_stun_message_ { |
michael@0 | 157 | char *name; |
michael@0 | 158 | UCHAR buffer[NR_STUN_MAX_MESSAGE_SIZE]; |
michael@0 | 159 | int length; |
michael@0 | 160 | nr_stun_message_header header; |
michael@0 | 161 | int comprehension_required_unknown_attributes; |
michael@0 | 162 | int comprehension_optional_unknown_attributes; |
michael@0 | 163 | nr_stun_message_attribute_head attributes; |
michael@0 | 164 | } nr_stun_message; |
michael@0 | 165 | |
michael@0 | 166 | int nr_stun_message_create(nr_stun_message **msg); |
michael@0 | 167 | int nr_stun_message_create2(nr_stun_message **msg, UCHAR *buffer, int length); |
michael@0 | 168 | int nr_stun_message_destroy(nr_stun_message **msg); |
michael@0 | 169 | |
michael@0 | 170 | int nr_stun_message_attribute_create(nr_stun_message *msg, nr_stun_message_attribute **attr); |
michael@0 | 171 | int nr_stun_message_attribute_destroy(nr_stun_message *msg, nr_stun_message_attribute **attr); |
michael@0 | 172 | |
michael@0 | 173 | int nr_stun_message_has_attribute(nr_stun_message *msg, UINT2 type, nr_stun_message_attribute **attribute); |
michael@0 | 174 | |
michael@0 | 175 | int nr_stun_message_add_alternate_server_attribute(nr_stun_message *msg, nr_transport_addr *alternate_server); |
michael@0 | 176 | int nr_stun_message_add_error_code_attribute(nr_stun_message *msg, UINT2 number, char *reason); |
michael@0 | 177 | int nr_stun_message_add_fingerprint_attribute(nr_stun_message *msg); |
michael@0 | 178 | int nr_stun_message_add_message_integrity_attribute(nr_stun_message *msg, Data *password); |
michael@0 | 179 | int nr_stun_message_add_nonce_attribute(nr_stun_message *msg, char *nonce); |
michael@0 | 180 | int nr_stun_message_add_realm_attribute(nr_stun_message *msg, char *realm); |
michael@0 | 181 | int nr_stun_message_add_server_attribute(nr_stun_message *msg, char *server_name); |
michael@0 | 182 | int nr_stun_message_add_unknown_attributes_attribute(nr_stun_message *msg, nr_stun_attr_unknown_attributes *unknown_attributes); |
michael@0 | 183 | int nr_stun_message_add_username_attribute(nr_stun_message *msg, char *username); |
michael@0 | 184 | int nr_stun_message_add_xor_mapped_address_attribute(nr_stun_message *msg, nr_transport_addr *mapped_address); |
michael@0 | 185 | |
michael@0 | 186 | #ifdef USE_ICE |
michael@0 | 187 | int nr_stun_message_add_ice_controlled_attribute(nr_stun_message *msg, UINT8 ice_controlled); |
michael@0 | 188 | int nr_stun_message_add_ice_controlling_attribute(nr_stun_message *msg, UINT8 ice_controlling); |
michael@0 | 189 | int nr_stun_message_add_priority_attribute(nr_stun_message *msg, UINT4 priority); |
michael@0 | 190 | int nr_stun_message_add_use_candidate_attribute(nr_stun_message *msg); |
michael@0 | 191 | #endif /* USE_ICE */ |
michael@0 | 192 | |
michael@0 | 193 | #ifdef USE_TURN |
michael@0 | 194 | int nr_stun_message_add_data_attribute(nr_stun_message *msg, UCHAR *data, int length); |
michael@0 | 195 | int nr_stun_message_add_lifetime_attribute(nr_stun_message *msg, UINT4 lifetime_secs); |
michael@0 | 196 | int nr_stun_message_add_requested_transport_attribute(nr_stun_message *msg, UCHAR transport); |
michael@0 | 197 | int |
michael@0 | 198 | nr_stun_message_add_xor_peer_address_attribute(nr_stun_message *msg, nr_transport_addr *peer_address); |
michael@0 | 199 | #endif /* USE_TURN */ |
michael@0 | 200 | |
michael@0 | 201 | #ifdef USE_STUND_0_96 |
michael@0 | 202 | int nr_stun_message_add_change_request_attribute(nr_stun_message *msg, UINT4 change_request); |
michael@0 | 203 | #endif /* USE_STUND_0_96 */ |
michael@0 | 204 | |
michael@0 | 205 | #endif |
michael@0 | 206 |