示例#1
0
/*FUNCTION:------------------------------------------------------
 *  NAME
 *      zbee_security_parse_prefs
 *  DESCRIPTION
 *      Parses the security preferences into the parameters needed
 *      for decryption.
 *  PARAMETERS
 *      none
 *  RETURNS
 *      void
 *---------------------------------------------------------------
 */
static void
zbee_security_parse_prefs(void)
{
    int             i;
    const gchar *   str_ptr;
    gchar           temp;

    /* Get the network key. */
    zbee_sec_have_nwk_key = zbee_security_parse_key(gPREF_zbee_sec_nwk_key, zbee_sec_nwk_key);
    /* Get the trust-center link key. */
    zbee_sec_have_tclink_key = zbee_security_parse_key(gPREF_zbee_sec_tclink_key, zbee_sec_tclink_key);
    /* Get the trust-center address. */
    zbee_sec_tcaddr = 0;
    str_ptr = gPREF_zbee_sec_tcaddr;
    temp = *(str_ptr++);
    for (i=0;i<(int)sizeof(guint64);i++) {
        /* Except for the first octet, ensure the next character is a
         * separator and skip over it.
         */
        if ((temp == ':') || (temp == '-')) temp = *(str_ptr++);
        else if (i!=0) goto bad_tcaddr;
        /* Process this nibble. */
        if (('0' <= temp) && (temp <= '9'))      zbee_sec_tcaddr |= ((guint64)(temp-'0'+0x00)<<(8*(sizeof(guint64)-i)-4));
        else if (('a' <= temp) && (temp <= 'f')) zbee_sec_tcaddr |= ((guint64)(temp-'a'+0x0a)<<(8*(sizeof(guint64)-i)-4));
        else if (('A' <= temp) && (temp <= 'F')) zbee_sec_tcaddr |= ((guint64)(temp-'A'+0x0A)<<(8*(sizeof(guint64)-i)-4));
        else goto bad_tcaddr;
        /* Get the next nibble. */
        temp = *(str_ptr++);
        /* Process this nibble. */
        if (('0' <= temp) && (temp <= '9'))      zbee_sec_tcaddr |= ((guint64)(temp-'0'+0x00)<<(8*(sizeof(guint64)-i)-8));
        else if (('a' <= temp) && (temp <= 'f')) zbee_sec_tcaddr |= ((guint64)(temp-'a'+0x0a)<<(8*(sizeof(guint64)-i)-8));
        else if (('A' <= temp) && (temp <= 'F')) zbee_sec_tcaddr |= ((guint64)(temp-'A'+0x0A)<<(8*(sizeof(guint64)-i)-8));
        else goto bad_tcaddr;
        /* Get the next nibble. */
        temp = *(str_ptr++);
    } /* for */
    /* Done */
    return;

bad_tcaddr:
    zbee_sec_tcaddr = 0;
} /* zbee_security_parse_prefs */
static void uat_key_record_update_cb(void* r, const char** err) {
    uat_key_record_t* rec = (uat_key_record_t *)r;

    if (rec->string == NULL) {
         *err = ep_strdup_printf("Key can't be blank");
    } else {
        g_strstrip(rec->string);

        if (rec->string[0] != 0) {
            *err = NULL;
            if ( !zbee_security_parse_key(rec->string, rec->key, rec->byte_order) ) {
                *err = ep_strdup_printf("Expecting %d hexadecimal bytes or\n"
                        "a %d character double-quoted string", ZBEE_SEC_CONST_KEYSIZE, ZBEE_SEC_CONST_KEYSIZE);
            }
        } else {
            *err = ep_strdup_printf("Key can't be blank");
        }
    }
}
示例#3
0
static void uat_key_record_post_update(void) {
    guint           i;
    key_record_t    key_record;
    guint8          key[ZBEE_SEC_CONST_KEYSIZE];

    /* empty the key ring */
    if (zbee_pc_keyring) {
       g_slist_free(zbee_pc_keyring);
       zbee_pc_keyring = NULL;
    }

    /* Load the pre-configured slist from the UAT. */
    for (i=0; (uat_key_records) && (i<num_uat_key_records) ; i++) {
        key_record.frame_num = ZBEE_SEC_PC_KEY; /* means it's a user PC key */
        key_record.label = g_strdup(uat_key_records[i].label);
        if (zbee_security_parse_key(uat_key_records[i].string, key, uat_key_records[i].byte_order)) {
            memcpy(&key_record.key, key, ZBEE_SEC_CONST_KEYSIZE);
            zbee_pc_keyring = g_slist_prepend(zbee_pc_keyring, g_memdup(&key_record, sizeof(key_record_t)));
        }
    }
}
示例#4
0
static gboolean uat_key_record_update_cb(void* r, char** err) {
    uat_key_record_t* rec = (uat_key_record_t *)r;
    guint8 key[ZBEE_SEC_CONST_KEYSIZE];

    if (rec->string == NULL) {
        *err = g_strdup("Key can't be blank");
        return FALSE;
    } else {
        g_strstrip(rec->string);

        if (rec->string[0] != 0) {
            *err = NULL;
            if ( !zbee_security_parse_key(rec->string, key, rec->byte_order) ) {
                *err = g_strdup_printf("Expecting %d hexadecimal bytes or\n"
                        "a %d character double-quoted string", ZBEE_SEC_CONST_KEYSIZE, ZBEE_SEC_CONST_KEYSIZE);
                return FALSE;
            }
        } else {
            *err = g_strdup("Key can't be blank");
            return FALSE;
        }
    }
    return TRUE;
}