This file is indexed.

/usr/include/sipxtapi/os/StunMessage.h is in libsipxtapi-dev 3.3.0~test17-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
//
// Copyright (C) 2006 Robert J. Andreasen, Jr.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// Copyright (C) 2004-2006 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2004-2006 Pingtel Corp.  All rights reserved.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// $$
///////////////////////////////////////////////////////////////////////////////

#ifndef _StunMessage_h_
#define _StunMessage_h_

// SYSTEM INCLUDES
// APPLICATION INCLUDES
#include "os/OsIntTypes.h"
#include "utl/UtlRandom.h"

// DEFINES
#define STUN_MAX_STRING_LENGTH              128 
#define STUN_MAX_UNKNOWN_ATTRIBUTES         16
#define STUN_MAX_MESSAGE_INTEGRITY_LENGTH   20
#define STUN_MIN_CHAR_PAD                   4
#define STUN_MAGIC_COOKIE                   0x2112A442

/**
 * STUN Message IDs
 */
#define MSG_STUN_BIND_REQUEST                   0x0001
#define MSG_STUN_BIND_RESPONSE                  0x0101
#define MSG_STUN_BIND_ERROR_RESPONSE            0x0111
#define MSG_STUN_SHARED_SECRET_REQUEST          0x0002
#define MSG_STUN_SHARED_SECRET_RESPONSE         0x0102
#define MSG_STUN_SHARED_SECRET_ERROR_RESPONSE   0x0112

/**
 * STUN attribute IDs
 */
#define ATTR_STUN_MAPPED_ADDRESS                0x0001
#define ATTR_STUN_RESPONSE_ADDRESS              0x0002  // deprecated
#define ATTR_STUN_CHANGE_REQUEST                0x0003  // deprecated
#define ATTR_STUN_SOURCE_ADDRESS                0x0004  // deprecated
#define ATTR_STUN_CHANGED_ADDRESS               0x0005  // deprecated
#define ATTR_STUN_USERNAME                      0x0006
#define ATTR_STUN_PASSWORD                      0x0007  // deprecated
#define ATTR_STUN_MESSAGE_INTEGRITY             0x0008
#define ATTR_STUN_ERROR_CODE                    0x0009
#define ATTR_STUN_UNKNOWN_ATTRIBUTE             0x000A
#define ATTR_STUN_REFLECTED_FROM                0x000B  // deprecated
#define ATTR_STUN_ALTERNATE_SERVER2             0x000E  // deprecated
#define ATTR_STUN_REALM                         0x0014
#define ATTR_STUN_NONCE                         0x0015
#define ATTR_STUN_XOR_MAPPED_ADDRESS            0x0020
#define ATTR_STUN_XOR_ONLY                      0x0021  // deprecated
#define ATTR_STUN_FINGERPRINT                   0x0023
#define ATTR_STUN_XOR_MAPPED_ADDRESS2           0x8020  // deprecated
#define ATTR_STUN_SERVER                        0x8022  
#define ATTR_STUN_SERVER2                       0x0022  // deprecated
#define ATTR_STUN_ALTERNATE_SERVER              0x8023  
#define ATTR_STUN_BINDING_LIFETIME              0x8024 

#define ATTR_CHANGE_FLAG_PORT                   0x0002  // deprecated
#define ATTR_CHANGE_FLAG_IP                     0x0004  // deprecated

#define ATTR_ADDRESS_FAMILY_IPV4                0x01
#define ATTR_ADDRESS_FAMILY_IPV6                0x02

// Error Defines

#define STUN_ERROR_TRY_ALTERNATE_CODE           300
#define STUN_ERROR_TRY_ALTERNATE_TEXT           "Try Alternative"

#define STUN_ERROR_BAD_REQUEST_CODE             400
#define STUN_ERROR_BAD_REQUEST_TEXT             "Bad request"

#define STUN_ERROR_UNAUTHORIZED_CODE            401
#define STUN_ERROR_UNAUTHORIZED_TEXT            "Unauthorized"

#define STUN_ERROR_UNKNOWN_ATTRIBUTE_CODE       420
#define STUN_ERROR_UNKNOWN_ATTRIBUTE_TEXT       "Unknown attribute"

#define STUN_ERROR_STALE_CREDENTIAL_CODE        430
#define STUN_ERROR_STALE_CREDENTIAL_TEXT        "Stale credential"

#define STUN_ERROR_BAD_INTEGRITY_CODE           431
#define STUN_ERROR_BAD_INTEGRITY_TEXT           "Bad integrity"

#define STUN_ERROR_MISSING_USERNAME_CODE        432
#define STUN_ERROR_MISSING_USERNAME_TEXT        "Missing username"

#define STUN_ERROR_USE_TLS_CODE                 433
#define STUN_ERROR_USE_TLS_TEXT                 "Use TLS"

#define STUN_ERROR_MISSING_REALM_CODE           434
#define STUN_ERROR_MISSING_REALM_TEXT           "Missing Realm"

#define STUN_ERROR_MISSING_NONCE_CODE           435
#define STUN_ERROR_MISSING_NONCE_TEXT           "Missing Nonce"

#define STUN_ERROR_UNKNOWN_USERNAME_CODE        436
#define STUN_ERROR_UNKNOWN_USERNAME_TEXT        "Unknown username"

#define STUN_ERROR_STALE_NONCE_CODE             438
#define STUN_ERROR_STALE_NONCE_TEXT             "Stale Nonce"

#define STUN_ERROR_SERVER_CODE                  500
#define STUN_ERROR_SERVER_TEXT                  "Server error"

#define STUN_ERROR_GLOBAL_CODE                  600
#define STUN_ERROR_GLOBAL_TEXT                  "Global error"

// MACROS
// EXTERNAL FUNCTIONS
// EXTERNAL VARIABLES
// CONSTANTS
// STRUCTS
// TYPEDEFS
typedef struct
{
    uint32_t id ;
} STUN_MAGIC_ID ;

typedef struct {
    uint8_t id[12];
} STUN_TRANSACTION_ID;

typedef struct
{
    uint16_t      type ;
    uint16_t      length ;
    STUN_MAGIC_ID       magicId ;
    STUN_TRANSACTION_ID transactionId ;
} STUN_MESSAGE_HEADER ;

typedef struct
{
    uint16_t type;
    uint16_t length;
} STUN_ATTRIBUTE_HEADER ;

typedef struct
{
    uint8_t unused ;
    uint8_t family ;  /* unused today */
    uint16_t port;
    uint32_t address ;    
} STUN_ATTRIBUTE_ADDRESS;

typedef struct
{
    uint16_t unused ;
    uint8_t unused2:4 ;
    uint8_t errorClass:4 ;   // between 1 and 6
    uint8_t errorNumber ; // between 0 and 99
    char szReasonPhrase[STUN_MAX_STRING_LENGTH+1] ;  
} STUN_ATTRIBUTE_ERROR ;

typedef struct
{
    //size_t nTypes ;
    uint32_t nTypes ;
    uint16_t type[STUN_MAX_UNKNOWN_ATTRIBUTES] ;
} STUN_ATTRIBUTE_UNKNOWN ;


// FORWARD DECLARATIONS

/**
 * A StunMessage includes all of the parse and encoding for a STUN message
 * as defined by draft-ietf-behave-rfc3489bis-04.txt:
 *
 * All data is stored internally in host byte order
 *
 *                         Error
 *                                     Error
 * Attribute         Request  Response Response Indication
 * _______________________________________________________
 * MAPPED-ADDRESS       -        C         -       -
 * USERNAME             O        -         -       O
 * PASSWORD             -        C         -       -
 * MESSAGE-INTEGRITY    O        O         O       O
 * ERROR-CODE           -        -         M       -
 * ALTERNATE-SERVER     -        -         C       -
 * REALM                C        -         C       -
 * NONCE                C        -         C       -
 * UNKNOWN-ATTRIBUTES   -        -         C       -
 * XOR-MAPPED-ADDRESS   -        C         -       -
 * SERVER               -        O         O       O
 * REFRESH-INTERVAL     -        O         -       -
 * FINGERPRINT          M        M         M       M
 *
 *
 *                    Shared   Shared    Shared
 *                    Secret   Secret    Secret
 * Attribute          Request  Response  Error
 *                                         Response
 * ____________________________________________________________________
 * USERNAME             O         M         -
 * PASSWORD             -         M         -
 * MESSAGE-INTEGRITY    O         O         O
 * ERROR-CODE           -         -         M
 * ALTERNATE-SERVER     -         -         C
 * UNKNOWN-ATTRIBUTES   -         -         C
 * SERVER               -         O         O
 * REALM                C         -         C
 * NONCE                C         -         C
 */
class StunMessage
{
/* //////////////////////////// PUBLIC //////////////////////////////////// */
  public:

/* ============================ CREATORS ================================== */

    /**
     * Default constructor, if a msg is passed, the magic/transaction id 
     * is copied -- otherwise a new magic/transaction id is generated.
     */
    StunMessage(StunMessage* pRequest = NULL,
                bool         bLegacyMode = true) ;

    /**
     * Destructor
     */
    virtual ~StunMessage() ;

/* ============================ MANIPULATORS ============================== */

    virtual void reset() ;

    virtual bool parse(const char* pBuf, size_t nBufLength) ;
    
    virtual bool encode(char* pBuf, size_t nBufLength, size_t& nActualLength) ;

    virtual bool encodeBody(char* pBuf, size_t nBufLength, size_t& nBytesUsed) ;

    void setMagicId(STUN_MAGIC_ID& rMagicId) ;

    void setTransactionId(STUN_TRANSACTION_ID& rTransactionId) ;

    void allocTransactionId() ;

    void setType(uint16_t type) ;

    void setMappedAddress(const char* szIp, const uint16_t port) ;

    void setResponseAddress(const char* szIp, const uint16_t port) ;

    void setChangePort(const bool bChange) ;

    void setChangeIp(const bool bChange) ;

    void setSourceAddress(const char* szIp, const uint16_t port) ;

    void setChangedAddress(const char* szIp, const uint16_t port) ;

    void setUsername(const char* szUsername) ;

    void setPassword(const char* szPassword) ;

    void setRealm(const char* szRealm) ;

    void setNonce(const char* szNonce) ;

    void setError(const uint16_t code, const char* szReason) ;

    void addUnknownAttribute(uint16_t attributeId) ;

    void setReflectedFrom(const char* szIp, const uint16_t port) ;

    void setServer(const char* szServer) ;

    void setRequestXorOnly() ;

    void setSendXorOnly() ;

    void setIncludeMessageIntegrity(bool bInclude) ;

    void setIncludeFingerPrint(bool bInclude) ;

    void setAltServer(const char* szIp, uint16_t port) ;

/* ============================ ACCESSORS ================================= */

    void getMagicId(STUN_MAGIC_ID* pMagicId) ;

    void getTransactionId(STUN_TRANSACTION_ID* pTransactionId) ;

    uint16_t getType() ;

    bool getMappedAddress(char* szIp, uint16_t& rPort) ;

    bool getResponseAddress(char* szIp, uint16_t& rPort) ;

    bool getChangePort() ;

    bool getChangeIp() ;

    bool getSourceAddress(char* szIp, uint16_t& rPort) ;

    bool getChangedAddress(char* szIp, uint16_t& rPort) ;

    bool getUsername(char* szUsername) ;

    bool getPassword(char* szPassword) ;

    bool getRealm(char *szRealm) ;
    
    bool getNonce(char* szNonce) ;

    bool getMessageIntegrity(char* cMessageIntegrity) ;

    bool getError(uint16_t& rCode, char* szReason) ;

    bool getUnknownAttributes(uint16_t* pList, size_t nMaxItems, size_t& nActualItems) ;

    bool getReflectedFrom(char* szIp, uint16_t& rPort) ;

    bool getServer(char* szServer) ;

    bool getUnknownParsedAttributes(uint16_t* pList, size_t nMaxItems, size_t& nActualItems) ;

    bool getRequestXorOnly() ;

    bool getAltServer(char* szIp, uint16_t& rPort) ;

    bool getFingerPrint(bool& bValid) ;

/* ============================ INQUIRY =================================== */

    virtual bool validateMessageType(uint16_t type) ;

    static bool isStunMessage(const char* pBuf, uint16_t nBufLength) ;

    static bool isFingerPrintValid(const char* pBuf, uint16_t nBufLength, bool bMissingOk) ;

    virtual bool isRequestOrNonErrorResponse() ;

    virtual bool isMessageIntegrityValid(const char* cPassword, size_t nPassword) ;

    virtual bool isFingerPrintValid() ;

/* //////////////////////////// PROTECTED ///////////////////////////////// */
  protected:

    bool encodeByte(char c, char*& pBuf, size_t& nBytesLeft) ;

    bool encodeShort(uint16_t value, char*& pBuf, size_t& nBytesLeft) ;

    bool encodeLong(uint32_t value, char*& pBuf, size_t& nBytesLeft) ;

    bool encodeRaw(const char* cRaw, size_t length, char*& pBuf, size_t& nBytesLeft) ;

    bool encodeHeader(STUN_MESSAGE_HEADER* pHeader, char*& pBuf, size_t& nBytesLeft) ;

    bool encodeAttributeHeader(int16_t type, int16_t length, char*& pBuf, size_t& nBytesLeft) ;

    bool encodeAttributeAddress(uint16_t type, STUN_ATTRIBUTE_ADDRESS* pAddress, char*& pBuf, size_t& nBytesLeft) ;

    bool encodeXorAttributeAddress(uint16_t type, STUN_ATTRIBUTE_ADDRESS* pAddress, char*& pBuf, size_t& nBytesLeft) ;

    bool encodeString(uint16_t type, const char* szString, char*& pBuf, size_t& nBytesLeft) ;

    bool encodeAttributeError(STUN_ATTRIBUTE_ERROR* pError, char*& pBuf, size_t& nBytesLeft) ;

    bool encodeAttributesUnknown(STUN_ATTRIBUTE_UNKNOWN* pAttributes, char*& pBuf, size_t& nBytesLeft) ;

    virtual bool parseAttribute(STUN_ATTRIBUTE_HEADER* pHeader, char* pBuf) ;

    bool parseAddressAttribute(char *pBuf, size_t nLength, STUN_ATTRIBUTE_ADDRESS* pAddress) ;

    bool parseXorAddressAttribute(char *pBuf, size_t nLength, STUN_ATTRIBUTE_ADDRESS* pAddress) ;

    bool parseShortAttribute(char *pBuf, size_t nLength, uint16_t* pShort) ;

    bool parseLongAttribute(char *pBuf, size_t nLength, uint32_t* pLong) ;

    bool parseStringAttribute(char* pBuf, size_t nLength, char* pString) ;

    bool parseRawAttribute(char* pBuf, size_t nLength, char* pDest, size_t nDest) ;

    bool parseErrorAttribute(char *pBuf, size_t nLength, STUN_ATTRIBUTE_ERROR* pError) ;

    bool parseUnknownAttribute(char* pBuf, size_t nLength, STUN_ATTRIBUTE_UNKNOWN* pAttributes) ;

    /**
     * zero pads to 64 boundry and results will be 20 bytes long for hmac/sha1
     */
    static void calculateHmacSha1(const char* pDataIn, 
                                  size_t      nDataIn, 
                                  const char* pKey, 
                                  size_t      nKey, 
                                  char        results[20]) ;

/* //////////////////////////// PRIVATE /////////////////////////////////// */
  private:
    STUN_MESSAGE_HEADER    mMsgHeader ;
    bool                   mbMsgHeaderValid ;
    STUN_ATTRIBUTE_ADDRESS mMappedAddress ;
    bool                   mbMappedAddressValid ;
    STUN_ATTRIBUTE_ADDRESS mResponseAddress ;
    bool                   mbResponseAddressValid ;
    STUN_ATTRIBUTE_ADDRESS mChangedAddress ;
    bool                   mbChangedAddressValid ;
    uint32_t          mChangeRequest ;
    bool                   mbChangeRequestValid ;
    STUN_ATTRIBUTE_ADDRESS mSourceAddress ;
    bool                   mbSourceAddressValid ;
    char                   mUsername[STUN_MAX_STRING_LENGTH+1] ;
    bool                   mbUsernameValid ;
    char                   mPassword[STUN_MAX_STRING_LENGTH+1] ;
    bool                   mbPasswordValid ;
    char                   mRealm[STUN_MAX_STRING_LENGTH+1] ;
    bool                   mbRealmValid ;
    char                   mNonce[STUN_MAX_STRING_LENGTH+1] ;
    bool                   mbNonceValid ;
    char                   mMessageIntegrity[STUN_MAX_MESSAGE_INTEGRITY_LENGTH] ;
    bool                   mbMessageIntegrityValid ;
    STUN_ATTRIBUTE_ERROR   mError ;
    bool                   mbErrorValid;
    STUN_ATTRIBUTE_UNKNOWN mUnknownAttributes ;
    bool                   mbUnknownAttributesValid ;    
    STUN_ATTRIBUTE_ADDRESS mReflectedFrom ;
    bool                   mbReflectedFromValid ;
    char                   mServer[STUN_MAX_STRING_LENGTH+1];
    bool                   mbServerValid ;
    bool                   mbSendXorOnly ;
    bool                   mbRequestXorOnly ;
    UtlRandom              mbRandomGenerator ;
    bool                   mbIncludeMessageIntegrity ;
    STUN_ATTRIBUTE_ADDRESS mAltServer ;
    bool                   mbAltServerValid ;
    bool                   mbIncludeFingerPrint ;
    char                   mbFingerPrintValid ;
    uint32_t          mFingerPrint ;
    char*                  mpRawData ;
    size_t                 mnRawData ;
    bool                   mbLegacyMode ;

    STUN_ATTRIBUTE_UNKNOWN mUnknownParsedAttributes ;

   /** Disabled copy constructor */
   StunMessage(const StunMessage& rStunMessage);   

   /** Disabled equals operator */
   StunMessage& operator=(const StunMessage& rhs);  
};

/* ============================ INLINE METHODS ============================ */

#endif  // _StunMessage_h_