cc.c File Reference

#include <config.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <isc/assertions.h>
#include <isc/hmacmd5.h>
#include <isc/hmacsha.h>
#include <isc/print.h>
#include <isc/safe.h>
#include <isc/stdlib.h>
#include <isccc/alist.h>
#include <isccc/base64.h>
#include <isccc/cc.h>
#include <isccc/result.h>
#include <isccc/sexpr.h>
#include <isccc/symtab.h>
#include <isccc/symtype.h>
#include <isccc/util.h>

Go to the source code of this file.

Defines

#define MAX_TAGS   256
#define DUP_LIFETIME   900
#define HMD5_OFFSET   21
 21 = 6 + 1 + 4 + 5 + 1 + 4
#define HMD5_LENGTH   22
#define HSHA_OFFSET   22
 21 = 6 + 1 + 4 + 5 + 1 + 4 + 1
#define HSHA_LENGTH   88

Typedefs

typedef isccc_sexpr_tsexpr_ptr

Functions

static isc_result_t table_towire (isccc_sexpr_t *alist, isc_buffer_t **buffer)
static isc_result_t list_towire (isccc_sexpr_t *alist, isc_buffer_t **buffer)
static isc_result_t value_towire (isccc_sexpr_t *elt, isc_buffer_t **buffer)
static isc_result_t sign (unsigned char *data, unsigned int length, unsigned char *hmac, isc_uint32_t algorithm, isccc_region_t *secret)
isc_result_t isccc_cc_towire (isccc_sexpr_t *alist, isc_buffer_t **buffer, isc_uint32_t algorithm, isccc_region_t *secret)
 Send to Wire.
static isc_result_t verify (isccc_sexpr_t *alist, unsigned char *data, unsigned int length, isc_uint32_t algorithm, isccc_region_t *secret)
static isc_result_t table_fromwire (isccc_region_t *source, isccc_region_t *secret, isc_uint32_t algorithm, isccc_sexpr_t **alistp)
static isc_result_t list_fromwire (isccc_region_t *source, isccc_sexpr_t **listp)
static isc_result_t value_fromwire (isccc_region_t *source, isccc_sexpr_t **valuep)
isc_result_t isccc_cc_fromwire (isccc_region_t *source, isccc_sexpr_t **alistp, isc_uint32_t algorithm, isccc_region_t *secret)
 Get From Wire.
static isc_result_t createmessage (isc_uint32_t version, const char *from, const char *to, isc_uint32_t serial, isccc_time_t now, isccc_time_t expires, isccc_sexpr_t **alistp, isc_boolean_t want_expires)
isc_result_t isccc_cc_createmessage (isc_uint32_t version, const char *from, const char *to, isc_uint32_t serial, isccc_time_t now, isccc_time_t expires, isccc_sexpr_t **alistp)
 Create Message.
isc_result_t isccc_cc_createack (isccc_sexpr_t *message, isc_boolean_t ok, isccc_sexpr_t **ackp)
 Create Acknowledgment.
isc_boolean_t isccc_cc_isack (isccc_sexpr_t *message)
 Is Ack?
isc_boolean_t isccc_cc_isreply (isccc_sexpr_t *message)
 Is Reply?
isc_result_t isccc_cc_createresponse (isccc_sexpr_t *message, isccc_time_t now, isccc_time_t expires, isccc_sexpr_t **alistp)
 Create Response.
isccc_sexpr_tisccc_cc_definestring (isccc_sexpr_t *alist, const char *key, const char *str)
 Define String.
isccc_sexpr_tisccc_cc_defineuint32 (isccc_sexpr_t *alist, const char *key, isc_uint32_t i)
 Define uint 32.
isc_result_t isccc_cc_lookupstring (isccc_sexpr_t *alist, const char *key, char **strp)
 Lookup String.
isc_result_t isccc_cc_lookupuint32 (isccc_sexpr_t *alist, const char *key, isc_uint32_t *uintp)
 Lookup uint 32.
static void symtab_undefine (char *key, unsigned int type, isccc_symvalue_t value, void *arg)
static isc_boolean_t symtab_clean (char *key, unsigned int type, isccc_symvalue_t value, void *arg)
isc_result_t isccc_cc_createsymtab (isccc_symtab_t **symtabp)
 Create Symbol Table.
void isccc_cc_cleansymtab (isccc_symtab_t *symtab, isccc_time_t now)
 Clean up Symbol Table.
static isc_boolean_t has_whitespace (const char *str)
isc_result_t isccc_cc_checkdup (isccc_symtab_t *symtab, isccc_sexpr_t *message, isccc_time_t now)
 Check for Duplicates.

Variables

static unsigned char auth_hmd5 []
static unsigned char auth_hsha []


Detailed Description

Definition in file cc.c.


Define Documentation

#define MAX_TAGS   256

Definition at line 58 of file cc.c.

#define DUP_LIFETIME   900

Definition at line 59 of file cc.c.

Referenced by symtab_clean().

#define HMD5_OFFSET   21

21 = 6 + 1 + 4 + 5 + 1 + 4

Definition at line 79 of file cc.c.

Referenced by isccc_cc_towire().

#define HMD5_LENGTH   22

Definition at line 80 of file cc.c.

Referenced by sign(), and verify().

#define HSHA_OFFSET   22

21 = 6 + 1 + 4 + 5 + 1 + 4 + 1

Definition at line 107 of file cc.c.

Referenced by isccc_cc_towire().

#define HSHA_LENGTH   88

Definition at line 108 of file cc.c.

Referenced by sign(), and verify().


Typedef Documentation

typedef isccc_sexpr_t* sexpr_ptr

Definition at line 61 of file cc.c.


Function Documentation

static isc_result_t table_towire ( isccc_sexpr_t alist,
isc_buffer_t **  buffer 
) [static]

Definition at line 206 of file cc.c.

References INSIST, isc_buffer_putmem, isc_buffer_putuint8, isc_buffer_reserve(), ISC_R_NOSPACE, ISC_R_SUCCESS, isccc_alist_first(), ISCCC_SEXPR_CAR, ISCCC_SEXPR_CDR, isccc_sexpr_tostring(), and value_towire().

Referenced by isccc_cc_towire(), and value_towire().

static isc_result_t list_towire ( isccc_sexpr_t alist,
isc_buffer_t **  buffer 
) [static]

Definition at line 241 of file cc.c.

References ISC_R_SUCCESS, ISCCC_SEXPR_CAR, ISCCC_SEXPR_CDR, and value_towire().

Referenced by value_towire().

static isc_result_t value_towire ( isccc_sexpr_t elt,
isc_buffer_t **  buffer 
) [static]

Definition at line 117 of file cc.c.

References isc_buffer::base, INSIST, isc_buffer_init, isc_buffer_putmem, isc_buffer_putuint32, isc_buffer_putuint8, isc_buffer_reserve(), ISC_R_NOSPACE, ISC_R_SUCCESS, isccc_alist_alistp(), ISCCC_CCMSGTYPE_BINARYDATA, ISCCC_CCMSGTYPE_LIST, ISCCC_CCMSGTYPE_TABLE, isccc_sexpr_binaryp(), isccc_sexpr_listp(), isccc_sexpr_tobinary(), list_towire(), REGION_SIZE, isccc_region::rstart, and table_towire().

Referenced by list_towire(), and table_towire().

static isc_result_t sign ( unsigned char *  data,
unsigned int  length,
unsigned char *  hmac,
isc_uint32_t  algorithm,
isccc_region_t secret 
) [static]

Definition at line 255 of file cc.c.

References digest, HMD5_LENGTH, HSHA_LENGTH, isc_hmacmd5_init(), isc_hmacmd5_sign(), isc_hmacmd5_update(), isc_hmacsha1_init(), isc_hmacsha1_sign(), isc_hmacsha1_update(), isc_hmacsha224_init(), isc_hmacsha224_sign(), isc_hmacsha224_update(), isc_hmacsha256_init(), isc_hmacsha256_sign(), isc_hmacsha256_update(), isc_hmacsha384_init(), isc_hmacsha384_sign(), isc_hmacsha384_update(), isc_hmacsha512_init(), isc_hmacsha512_sign(), isc_hmacsha512_update(), ISC_MD5_DIGESTLENGTH, ISC_R_FAILURE, ISC_R_SUCCESS, ISC_SHA1_DIGESTLENGTH, ISC_SHA224_DIGESTLENGTH, ISC_SHA256_DIGESTLENGTH, ISC_SHA384_DIGESTLENGTH, ISC_SHA512_DIGESTLENGTH, ISCCC_ALG_HMACMD5, ISCCC_ALG_HMACSHA1, ISCCC_ALG_HMACSHA224, ISCCC_ALG_HMACSHA256, ISCCC_ALG_HMACSHA384, ISCCC_ALG_HMACSHA512, isccc_base64_encode(), PUT_MEM, REGION_SIZE, isccc_region::rend, and isccc_region::rstart.

Referenced by assignwork(), and isccc_cc_towire().

isc_result_t isccc_cc_towire ( isccc_sexpr_t alist,
isc_buffer_t **  buffer,
isc_uint32_t  algorithm,
isccc_region_t secret 
)

Send to Wire.

Definition at line 345 of file cc.c.

References auth_hmd5, auth_hsha, HMD5_OFFSET, HSHA_OFFSET, isc_buffer_putmem, isc_buffer_putuint32, isc_buffer_reserve(), isc_buffer_used, ISC_R_NOSPACE, ISC_R_SUCCESS, ISCCC_ALG_HMACMD5, isccc_alist_delete(), sign(), and table_towire().

Referenced by control_recvmessage(), rndc_connected(), and rndc_recvnonce().

static isc_result_t verify ( isccc_sexpr_t alist,
unsigned char *  data,
unsigned int  length,
isc_uint32_t  algorithm,
isccc_region_t secret 
) [static]

Definition at line 406 of file cc.c.

References digest, GET8, HMD5_LENGTH, HSHA_LENGTH, isc_hmacmd5_init(), isc_hmacmd5_sign(), isc_hmacmd5_update(), isc_hmacsha1_init(), isc_hmacsha1_sign(), isc_hmacsha1_update(), isc_hmacsha224_init(), isc_hmacsha224_sign(), isc_hmacsha224_update(), isc_hmacsha256_init(), isc_hmacsha256_sign(), isc_hmacsha256_update(), isc_hmacsha384_init(), isc_hmacsha384_sign(), isc_hmacsha384_update(), isc_hmacsha512_init(), isc_hmacsha512_sign(), isc_hmacsha512_update(), ISC_MD5_DIGESTLENGTH, ISC_R_FAILURE, ISC_R_SUCCESS, isc_safe_memcmp(), ISC_SHA1_DIGESTLENGTH, ISC_SHA224_DIGESTLENGTH, ISC_SHA256_DIGESTLENGTH, ISC_SHA384_DIGESTLENGTH, ISC_SHA512_DIGESTLENGTH, ISCCC_ALG_HMACMD5, ISCCC_ALG_HMACSHA1, ISCCC_ALG_HMACSHA224, ISCCC_ALG_HMACSHA256, ISCCC_ALG_HMACSHA384, ISCCC_ALG_HMACSHA512, isccc_alist_lookup(), isccc_base64_encode(), ISCCC_R_BADAUTH, isccc_sexpr_tostring(), REGION_SIZE, isccc_region::rend, and isccc_region::rstart.

static isc_result_t table_fromwire ( isccc_region_t source,
isccc_region_t secret,
isc_uint32_t  algorithm,
isccc_sexpr_t **  alistp 
) [static]

Definition at line 571 of file cc.c.

References GET8, GET_MEM, ISC_FALSE, ISC_R_NOMEMORY, ISC_R_SUCCESS, ISC_R_UNEXPECTEDEND, ISC_TRUE, isccc_alist_create(), isccc_alist_define(), ISCCC_R_BADAUTH, isccc_sexpr_free(), key, REGION_EMPTY, REGION_SIZE, isccc_region::rend, REQUIRE, isccc_region::rstart, value_fromwire(), and verify().

Referenced by isccc_cc_fromwire(), and value_fromwire().

static isc_result_t list_fromwire ( isccc_region_t source,
isccc_sexpr_t **  listp 
) [static]

Definition at line 631 of file cc.c.

References ISC_R_SUCCESS, isccc_sexpr_addtolist(), isccc_sexpr_free(), REGION_EMPTY, and value_fromwire().

Referenced by value_fromwire().

static isc_result_t value_fromwire ( isccc_region_t source,
isccc_sexpr_t **  valuep 
) [static]

Definition at line 536 of file cc.c.

References GET32, GET8, ISC_R_NOMEMORY, ISC_R_SUCCESS, ISC_R_UNEXPECTEDEND, ISCCC_CCMSGTYPE_BINARYDATA, ISCCC_CCMSGTYPE_LIST, ISCCC_CCMSGTYPE_TABLE, ISCCC_R_SYNTAX, isccc_sexpr_frombinary(), list_fromwire(), REGION_SIZE, isccc_region::rend, isccc_region::rstart, and table_fromwire().

Referenced by list_fromwire(), and table_fromwire().

isc_result_t isccc_cc_fromwire ( isccc_region_t source,
isccc_sexpr_t **  alistp,
isc_uint32_t  algorithm,
isccc_region_t secret 
)

Get From Wire.

Definition at line 657 of file cc.c.

References GET32, ISC_R_UNEXPECTEDEND, ISCCC_R_UNKNOWNVERSION, REGION_SIZE, isccc_region::rstart, table_fromwire(), and version.

Referenced by control_recvmessage(), rndc_recvdone(), and rndc_recvnonce().

static isc_result_t createmessage ( isc_uint32_t  version,
const char *  from,
const char *  to,
isc_uint32_t  serial,
isccc_time_t  now,
isccc_time_t  expires,
isccc_sexpr_t **  alistp,
isc_boolean_t  want_expires 
) [static]

Definition at line 674 of file cc.c.

References ISC_R_NOMEMORY, ISC_R_SUCCESS, isccc_alist_create(), isccc_alist_define(), isccc_cc_definestring(), isccc_cc_defineuint32(), ISCCC_R_UNKNOWNVERSION, isccc_sexpr_free(), and REQUIRE.

Referenced by isccc_cc_createack(), and isccc_cc_createmessage().

isc_result_t isccc_cc_createmessage ( isc_uint32_t  version,
const char *  from,
const char *  to,
isc_uint32_t  serial,
isccc_time_t  now,
isccc_time_t  expires,
isccc_sexpr_t **  alistp 
)

Create Message.

Definition at line 732 of file cc.c.

References createmessage(), and ISC_TRUE.

Referenced by isccc_cc_createresponse(), rndc_connected(), and rndc_recvnonce().

isc_result_t isccc_cc_createack ( isccc_sexpr_t message,
isc_boolean_t  ok,
isccc_sexpr_t **  ackp 
)

Create Acknowledgment.

Definition at line 741 of file cc.c.

References createmessage(), ISC_FALSE, ISC_R_FAILURE, ISC_R_NOMEMORY, ISC_R_SUCCESS, isccc_alist_lookup(), isccc_cc_definestring(), isccc_cc_lookupstring(), isccc_cc_lookupuint32(), isccc_sexpr_free(), REQUIRE, and serial.

isc_boolean_t isccc_cc_isack ( isccc_sexpr_t message  ) 

Is Ack?

Definition at line 793 of file cc.c.

References ISC_FALSE, ISC_R_SUCCESS, ISC_TRUE, isccc_alist_lookup(), and isccc_cc_lookupstring().

isc_boolean_t isccc_cc_isreply ( isccc_sexpr_t message  ) 

Is Reply?

Definition at line 806 of file cc.c.

References ISC_FALSE, ISC_R_SUCCESS, ISC_TRUE, isccc_alist_lookup(), and isccc_cc_lookupstring().

Referenced by control_recvmessage().

isc_result_t isccc_cc_createresponse ( isccc_sexpr_t message,
isccc_time_t  now,
isccc_time_t  expires,
isccc_sexpr_t **  alistp 
)

Create Response.

Definition at line 819 of file cc.c.

References ISC_R_FAILURE, ISC_R_NOMEMORY, ISC_R_SUCCESS, isccc_alist_lookup(), isccc_cc_createmessage(), isccc_cc_definestring(), isccc_cc_lookupstring(), isccc_cc_lookupuint32(), isccc_sexpr_free(), REQUIRE, and serial.

Referenced by control_recvmessage().

isccc_sexpr_t* isccc_cc_definestring ( isccc_sexpr_t alist,
const char *  key,
const char *  str 
)

Define String.

Definition at line 880 of file cc.c.

References DE_CONST, isccc_alist_definebinary(), r, isccc_region::rend, and isccc_region::rstart.

Referenced by control_recvmessage(), createmessage(), isccc_cc_createack(), isccc_cc_createresponse(), rndc_connected(), and rndc_recvnonce().

isccc_sexpr_t* isccc_cc_defineuint32 ( isccc_sexpr_t alist,
const char *  key,
isc_uint32_t  i 
)

Define uint 32.

Definition at line 893 of file cc.c.

References isccc_alist_definebinary(), r, isccc_region::rend, and isccc_region::rstart.

Referenced by control_recvmessage(), createmessage(), and rndc_recvnonce().

isc_result_t isccc_cc_lookupstring ( isccc_sexpr_t alist,
const char *  key,
char **  strp 
)

Lookup String.

Definition at line 908 of file cc.c.

References ISC_R_EXISTS, ISC_R_NOTFOUND, ISC_R_SUCCESS, isccc_alist_assq(), isccc_sexpr_binaryp(), ISCCC_SEXPR_CDR, isccc_sexpr_tostring(), and REQUIRE.

Referenced by isccc_cc_checkdup(), isccc_cc_createack(), isccc_cc_createresponse(), isccc_cc_isack(), isccc_cc_isreply(), ns_control_docommand(), and rndc_recvdone().

isc_result_t isccc_cc_lookupuint32 ( isccc_sexpr_t alist,
const char *  key,
isc_uint32_t uintp 
)

Lookup uint 32.

Definition at line 929 of file cc.c.

References ISC_R_EXISTS, ISC_R_NOTFOUND, ISC_R_SUCCESS, isccc_alist_assq(), isccc_sexpr_binaryp(), ISCCC_SEXPR_CDR, and isccc_sexpr_tostring().

Referenced by control_recvmessage(), isccc_cc_createack(), isccc_cc_createresponse(), and rndc_recvnonce().

static void symtab_undefine ( char *  key,
unsigned int  type,
isccc_symvalue_t  value,
void *  arg 
) [static]

Definition at line 951 of file cc.c.

References free(), and UNUSED.

Referenced by isccc_cc_createsymtab().

static isc_boolean_t symtab_clean ( char *  key,
unsigned int  type,
isccc_symvalue_t  value,
void *  arg 
) [static]

Definition at line 962 of file cc.c.

References isccc_symvalue::as_uinteger, DUP_LIFETIME, ISC_FALSE, ISC_TRUE, now, and UNUSED.

Referenced by isccc_cc_cleansymtab().

isc_result_t isccc_cc_createsymtab ( isccc_symtab_t **  symtabp  ) 

Create Symbol Table.

Definition at line 980 of file cc.c.

References ISC_FALSE, isccc_symtab_create(), and symtab_undefine().

Referenced by ns_controls_create().

void isccc_cc_cleansymtab ( isccc_symtab_t symtab,
isccc_time_t  now 
)

Clean up Symbol Table.

Definition at line 987 of file cc.c.

References isccc_symtab_foreach(), and symtab_clean().

Referenced by control_recvmessage().

static isc_boolean_t has_whitespace ( const char *  str  )  [static]

Definition at line 993 of file cc.c.

References ISC_FALSE, and ISC_TRUE.

Referenced by isccc_cc_checkdup().

isc_result_t isccc_cc_checkdup ( isccc_symtab_t symtab,
isccc_sexpr_t message,
isccc_time_t  now 
)

Check for Duplicates.

Definition at line 1007 of file cc.c.

References isccc_symvalue::as_uinteger, free(), has_whitespace(), INSIST, ISC_R_FAILURE, ISC_R_NOMEMORY, ISC_R_SUCCESS, isccc_alist_lookup(), isccc_cc_lookupstring(), isccc_symexists_reject, isccc_symtab_define(), ISCCC_SYMTYPE_CCDUP, and key.

Referenced by control_recvmessage().


Variable Documentation

unsigned char auth_hmd5[] [static]

Initial value:

 {
        0x05, 0x5f, 0x61, 0x75, 0x74, 0x68,             
        ISCCC_CCMSGTYPE_TABLE,                          
        0x00, 0x00, 0x00, 0x20,                         
        0x04, 0x68, 0x6d, 0x64, 0x35,                   
        ISCCC_CCMSGTYPE_BINARYDATA,                     
        0x00, 0x00, 0x00, 0x16,                         
        
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}

Definition at line 63 of file cc.c.

Referenced by isccc_cc_towire().

unsigned char auth_hsha[] [static]

Initial value:

 {
        0x05, 0x5f, 0x61, 0x75, 0x74, 0x68,             
        ISCCC_CCMSGTYPE_TABLE,                          
        0x00, 0x00, 0x00, 0x63,                         
        0x04, 0x68, 0x73, 0x68, 0x61,                   
        ISCCC_CCMSGTYPE_BINARYDATA,                     
        0x00, 0x00, 0x00, 0x59,                         
        0x00,                                           
        
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}

Definition at line 82 of file cc.c.

Referenced by isccc_cc_towire().


Generated on Tue Apr 28 17:41:19 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha