version 1.1.1.1, 2012/02/21 22:14:23
|
version 1.1.1.2, 2013/07/22 11:54:42
|
Line 62
|
Line 62
|
#include "../include/win32/libnet.h" |
#include "../include/win32/libnet.h" |
#endif |
#endif |
|
|
u_int8_t * | uint8_t * |
libnet_build_asn1_int(u_int8_t *data, int *datalen, u_int8_t type, int32_t *int_p, | libnet_build_asn1_int(uint8_t *data, int *datalen, uint8_t type, int32_t *int_p, |
int int_s) |
int int_s) |
{ |
{ |
/* |
/* |
* ASN.1 integer ::= 0x02 asnlength byte {byte}* |
* ASN.1 integer ::= 0x02 asnlength byte {byte}* |
*/ |
*/ |
register int32_t integer; |
register int32_t integer; |
register u_int32_t mask; | register uint32_t mask; |
|
|
if (int_s != sizeof (int32_t)) |
if (int_s != sizeof (int32_t)) |
{ |
{ |
Line 83 libnet_build_asn1_int(u_int8_t *data, int *datalen, u_
|
Line 83 libnet_build_asn1_int(u_int8_t *data, int *datalen, u_
|
* 2's complement integer. There should be no sequence of 9 consecutive |
* 2's complement integer. There should be no sequence of 9 consecutive |
* 1's or 0's at the most significant end of the integer. |
* 1's or 0's at the most significant end of the integer. |
*/ |
*/ |
mask = ((u_int32_t) 0x1FF) << ((8 * (sizeof (int32_t) - 1)) - 1); | mask = ((uint32_t) 0x1FF) << ((8 * (sizeof (int32_t) - 1)) - 1); |
/* mask is 0xFF800000 on a big-endian machine */ |
/* mask is 0xFF800000 on a big-endian machine */ |
|
|
while ((((integer & mask) == 0) || ((integer & mask) == mask)) && int_s > 1) |
while ((((integer & mask) == 0) || ((integer & mask) == mask)) && int_s > 1) |
Line 101 libnet_build_asn1_int(u_int8_t *data, int *datalen, u_
|
Line 101 libnet_build_asn1_int(u_int8_t *data, int *datalen, u_
|
|
|
*datalen -= int_s; |
*datalen -= int_s; |
|
|
mask = ((u_int32_t) 0xFF) << (8 * (sizeof(int32_t) - 1)); | mask = ((uint32_t) 0xFF) << (8 * (sizeof(int32_t) - 1)); |
/* mask is 0xFF000000 on a big-endian machine */ |
/* mask is 0xFF000000 on a big-endian machine */ |
|
|
while (int_s--) |
while (int_s--) |
{ |
{ |
*data++ = (u_int8_t)((integer & mask) >> (8 * (sizeof (int32_t) - 1))); | *data++ = (uint8_t)((integer & mask) >> (8 * (sizeof (int32_t) - 1))); |
integer <<= 8; |
integer <<= 8; |
} |
} |
return (data); |
return (data); |
} |
} |
|
|
|
|
u_int8_t * | uint8_t * |
libnet_build_asn1_uint(u_int8_t *data, int *datalen, u_int8_t type, u_int32_t *int_p, | libnet_build_asn1_uint(uint8_t *data, int *datalen, uint8_t type, uint32_t *int_p, |
int int_s) |
int int_s) |
{ |
{ |
/* |
/* |
* ASN.1 integer ::= 0x02 asnlength byte {byte}* |
* ASN.1 integer ::= 0x02 asnlength byte {byte}* |
*/ |
*/ |
register u_int32_t integer; | register uint32_t integer; |
register u_int32_t mask; | register uint32_t mask; |
int add_null_byte = 0; |
int add_null_byte = 0; |
|
|
if (int_s != sizeof (int32_t)) |
if (int_s != sizeof (int32_t)) |
Line 130 libnet_build_asn1_uint(u_int8_t *data, int *datalen, u
|
Line 130 libnet_build_asn1_uint(u_int8_t *data, int *datalen, u
|
} |
} |
integer = *int_p; |
integer = *int_p; |
|
|
mask = ((u_int32_t) 0xFF) << (8 * (sizeof (int32_t) - 1)); | mask = ((uint32_t) 0xFF) << (8 * (sizeof (int32_t) - 1)); |
/* mask is 0xFF000000 on a big-endian machine */ |
/* mask is 0xFF000000 on a big-endian machine */ |
|
|
if ((u_int8_t)((integer & mask) >> (8 * (sizeof (int32_t) - 1))) & 0x80) | if ((uint8_t)((integer & mask) >> (8 * (sizeof (int32_t) - 1))) & 0x80) |
{ |
{ |
/* if MSB is set */ |
/* if MSB is set */ |
add_null_byte = 1; |
add_null_byte = 1; |
Line 147 libnet_build_asn1_uint(u_int8_t *data, int *datalen, u
|
Line 147 libnet_build_asn1_uint(u_int8_t *data, int *datalen, u
|
* consecutive 1's or 0's at the most significant end of the |
* consecutive 1's or 0's at the most significant end of the |
* integer. |
* integer. |
*/ |
*/ |
mask = ((u_int32_t) 0x1FF) << ((8 * (sizeof(int32_t) - 1)) - 1); | mask = ((uint32_t) 0x1FF) << ((8 * (sizeof(int32_t) - 1)) - 1); |
/* mask is 0xFF800000 on a big-endian machine */ |
/* mask is 0xFF800000 on a big-endian machine */ |
|
|
while (((integer & mask) == 0) && int_s > 1) |
while (((integer & mask) == 0) && int_s > 1) |
Line 172 libnet_build_asn1_uint(u_int8_t *data, int *datalen, u
|
Line 172 libnet_build_asn1_uint(u_int8_t *data, int *datalen, u
|
int_s--; |
int_s--; |
} |
} |
|
|
mask = ((u_int32_t) 0xFF) << (8 * (sizeof(int32_t) - 1)); | mask = ((uint32_t) 0xFF) << (8 * (sizeof(int32_t) - 1)); |
/* mask is 0xFF000000 on a big-endian machine */ |
/* mask is 0xFF000000 on a big-endian machine */ |
|
|
while (int_s--) |
while (int_s--) |
{ |
{ |
*data++ = (u_int8_t)((integer & mask) >> (8 * (sizeof (int32_t) - 1))); | *data++ = (uint8_t)((integer & mask) >> (8 * (sizeof (int32_t) - 1))); |
integer <<= 8; |
integer <<= 8; |
} |
} |
return (data); |
return (data); |
} |
} |
|
|
|
|
u_int8_t * | uint8_t * |
libnet_build_asn1_string(u_int8_t *data, int *datalen, u_int8_t type, | libnet_build_asn1_string(uint8_t *data, int *datalen, uint8_t type, |
u_int8_t *string, int str_s) | uint8_t *string, int str_s) |
{ |
{ |
|
|
/* |
/* |
Line 208 libnet_build_asn1_string(u_int8_t *data, int *datalen,
|
Line 208 libnet_build_asn1_string(u_int8_t *data, int *datalen,
|
} |
} |
|
|
|
|
u_int8_t * | uint8_t * |
libnet_build_asn1_header(u_int8_t *data, int *datalen, u_int8_t type, int len) | libnet_build_asn1_header(uint8_t *data, int *datalen, uint8_t type, int len) |
{ |
{ |
if (*datalen < 1) |
if (*datalen < 1) |
{ |
{ |
Line 222 libnet_build_asn1_header(u_int8_t *data, int *datalen,
|
Line 222 libnet_build_asn1_header(u_int8_t *data, int *datalen,
|
} |
} |
|
|
|
|
u_int8_t * | uint8_t * |
libnet_build_asn1_sequence(u_int8_t *data, int *datalen, u_int8_t type, int len) | libnet_build_asn1_sequence(uint8_t *data, int *datalen, uint8_t type, int len) |
{ |
{ |
*datalen -= 4; |
*datalen -= 4; |
if (*datalen < 0) |
if (*datalen < 0) |
Line 232 libnet_build_asn1_sequence(u_int8_t *data, int *datale
|
Line 232 libnet_build_asn1_sequence(u_int8_t *data, int *datale
|
return (NULL); |
return (NULL); |
} |
} |
*data++ = type; |
*data++ = type; |
*data++ = (u_int8_t)(0x02 | ASN_LONG_LEN); | *data++ = (uint8_t)(0x02 | ASN_LONG_LEN); |
*data++ = (u_int8_t)((len >> 8) & 0xFF); | *data++ = (uint8_t)((len >> 8) & 0xFF); |
*data++ = (u_int8_t)(len & 0xFF); | *data++ = (uint8_t)(len & 0xFF); |
return (data); |
return (data); |
} |
} |
|
|
|
|
u_int8_t * | uint8_t * |
libnet_build_asn1_length(u_int8_t *data, int *datalen, int len) | libnet_build_asn1_length(uint8_t *data, int *datalen, int len) |
{ |
{ |
u_int8_t *start_data = data; | uint8_t *start_data = data; |
|
|
/* no indefinite lengths sent */ |
/* no indefinite lengths sent */ |
if (len < 0x80) |
if (len < 0x80) |
Line 251 libnet_build_asn1_length(u_int8_t *data, int *datalen,
|
Line 251 libnet_build_asn1_length(u_int8_t *data, int *datalen,
|
{ |
{ |
return (NULL); |
return (NULL); |
} |
} |
*data++ = (u_int8_t)len; | *data++ = (uint8_t)len; |
} |
} |
else if (len <= 0xFF) |
else if (len <= 0xFF) |
{ |
{ |
Line 259 libnet_build_asn1_length(u_int8_t *data, int *datalen,
|
Line 259 libnet_build_asn1_length(u_int8_t *data, int *datalen,
|
{ |
{ |
return (NULL); |
return (NULL); |
} |
} |
*data++ = (u_int8_t)(0x01 | ASN_LONG_LEN); | *data++ = (uint8_t)(0x01 | ASN_LONG_LEN); |
*data++ = (u_int8_t)len; | *data++ = (uint8_t)len; |
} |
} |
else /* 0xFF < len <= 0xFFFF */ |
else /* 0xFF < len <= 0xFFFF */ |
{ |
{ |
Line 268 libnet_build_asn1_length(u_int8_t *data, int *datalen,
|
Line 268 libnet_build_asn1_length(u_int8_t *data, int *datalen,
|
{ |
{ |
return (NULL); |
return (NULL); |
} |
} |
*data++ = (u_int8_t)(0x02 | ASN_LONG_LEN); | *data++ = (uint8_t)(0x02 | ASN_LONG_LEN); |
*data++ = (u_int8_t)((len >> 8) & 0xFF); | *data++ = (uint8_t)((len >> 8) & 0xFF); |
*data++ = (u_int8_t)(len & 0xFF); | *data++ = (uint8_t)(len & 0xFF); |
} |
} |
*datalen -= (data - start_data); |
*datalen -= (data - start_data); |
return (data); |
return (data); |
} |
} |
|
|
|
|
u_int8_t * | uint8_t * |
libnet_build_asn1_objid(u_int8_t *data, int *datalen, u_int8_t type, oid *objid, | libnet_build_asn1_objid(uint8_t *data, int *datalen, uint8_t type, oid *objid, |
int objidlen) |
int objidlen) |
{ |
{ |
/* |
/* |
Line 289 libnet_build_asn1_objid(u_int8_t *data, int *datalen,
|
Line 289 libnet_build_asn1_objid(u_int8_t *data, int *datalen,
|
*/ |
*/ |
int asnlen; |
int asnlen; |
register oid *op = objid; |
register oid *op = objid; |
u_int8_t objid_size[MAX_OID_LEN]; | uint8_t objid_size[MAX_OID_LEN]; |
register u_int32_t objid_val; | register uint32_t objid_val; |
u_int32_t first_objid_val; | uint32_t first_objid_val; |
register int i; |
register int i; |
|
|
/* check if there are at least 2 sub-identifiers */ |
/* check if there are at least 2 sub-identifiers */ |
Line 362 libnet_build_asn1_objid(u_int8_t *data, int *datalen,
|
Line 362 libnet_build_asn1_objid(u_int8_t *data, int *datalen,
|
switch (objid_size[i]) |
switch (objid_size[i]) |
{ |
{ |
case 1: |
case 1: |
*data++ = (u_int8_t)objid_val; | *data++ = (uint8_t)objid_val; |
break; |
break; |
|
|
case 2: |
case 2: |
*data++ = (u_int8_t)((objid_val >> 7) | 0x80); | *data++ = (uint8_t)((objid_val >> 7) | 0x80); |
*data++ = (u_int8_t)(objid_val & 0x07f); | *data++ = (uint8_t)(objid_val & 0x07f); |
break; |
break; |
case 3: |
case 3: |
*data++ = (u_int8_t)((objid_val >> 14) | 0x80); | *data++ = (uint8_t)((objid_val >> 14) | 0x80); |
*data++ = (u_int8_t)((objid_val >> 7 & 0x7f) | 0x80); | *data++ = (uint8_t)((objid_val >> 7 & 0x7f) | 0x80); |
*data++ = (u_int8_t)(objid_val & 0x07f); | *data++ = (uint8_t)(objid_val & 0x07f); |
break; |
break; |
|
|
case 4: |
case 4: |
*data++ = (u_int8_t)((objid_val >> 21) | 0x80); | *data++ = (uint8_t)((objid_val >> 21) | 0x80); |
*data++ = (u_int8_t)((objid_val >> 14 & 0x7f) | 0x80); | *data++ = (uint8_t)((objid_val >> 14 & 0x7f) | 0x80); |
*data++ = (u_int8_t)((objid_val >> 7 & 0x7f) | 0x80); | *data++ = (uint8_t)((objid_val >> 7 & 0x7f) | 0x80); |
*data++ = (u_int8_t)(objid_val & 0x07f); | *data++ = (uint8_t)(objid_val & 0x07f); |
break; |
break; |
|
|
case 5: |
case 5: |
*data++ = (u_int8_t)((objid_val >> 28) | 0x80); | *data++ = (uint8_t)((objid_val >> 28) | 0x80); |
*data++ = (u_int8_t)((objid_val >> 21 & 0x7f) | 0x80); | *data++ = (uint8_t)((objid_val >> 21 & 0x7f) | 0x80); |
*data++ = (u_int8_t)((objid_val >> 14 & 0x7f) | 0x80); | *data++ = (uint8_t)((objid_val >> 14 & 0x7f) | 0x80); |
*data++ = (u_int8_t)((objid_val >> 7 & 0x7f) | 0x80); | *data++ = (uint8_t)((objid_val >> 7 & 0x7f) | 0x80); |
*data++ = (u_int8_t)(objid_val & 0x07f); | *data++ = (uint8_t)(objid_val & 0x07f); |
break; |
break; |
} |
} |
} |
} |
Line 398 libnet_build_asn1_objid(u_int8_t *data, int *datalen,
|
Line 398 libnet_build_asn1_objid(u_int8_t *data, int *datalen,
|
} |
} |
|
|
|
|
u_int8_t * | uint8_t * |
libnet_build_asn1_null(u_int8_t *data, int *datalen, u_int8_t type) | libnet_build_asn1_null(uint8_t *data, int *datalen, uint8_t type) |
{ |
{ |
/* |
/* |
* ASN.1 null ::= 0x05 0x00 |
* ASN.1 null ::= 0x05 0x00 |
Line 408 libnet_build_asn1_null(u_int8_t *data, int *datalen, u
|
Line 408 libnet_build_asn1_null(u_int8_t *data, int *datalen, u
|
} |
} |
|
|
|
|
u_int8_t * | uint8_t * |
libnet_build_asn1_bitstring(u_int8_t *data, int *datalen, u_int8_t type, | libnet_build_asn1_bitstring(uint8_t *data, int *datalen, uint8_t type, |
u_int8_t *string, int str_s) | uint8_t *string, int str_s) |
{ |
{ |
|
|
/* |
/* |