/** * @brief * Update server data into the database * * @param[in] conn - Connection handle * @param[in] obj - Information of server to be updated * * @return Error code * @retval -1 - Failure * @retval 0 - Success * @retval 1 - Success but no rows updated * */ int pg_db_update_svr(pbs_db_conn_t *conn, pbs_db_obj_info_t *obj) { pbs_db_svr_info_t *ps = obj->pbs_db_un.pbs_db_svr; LOAD_STR(conn, ps->sv_name, 0); LOAD_STR(conn, ps->sv_hostname, 1); LOAD_INTEGER(conn, ps->sv_numjobs, 2); LOAD_INTEGER(conn, ps->sv_numque, 3); LOAD_INTEGER(conn, ps->sv_jobidnumber, 4); LOAD_BIGINT(conn, ps->sv_svraddr, 5); LOAD_INTEGER(conn, ps->sv_svrport, 6); return (pg_db_cmd(conn, STMT_UPDATE_SVR, 7)); }
static uint32_t tpm_oiap(uint32_t locality, tpm_authhandle_t *hauth, tpm_nonce_t *nonce_even) { uint32_t ret, offset, out_size; if ( hauth == NULL || nonce_even == NULL ) return TPM_BAD_PARAMETER; offset = 0; out_size = sizeof(*hauth) + sizeof(*nonce_even); ret = tpm_submit_cmd(locality, TPM_ORD_OIAP, offset, &out_size); #ifdef TPM_TRACE printf("TPM: start OIAP, return value = %08X\n", ret); #endif if ( ret != TPM_SUCCESS ) { printf("TPM: start OIAP, return value = %08X\n", ret); return ret; } #ifdef TPM_TRACE { printf("TPM: "); print_hex(NULL, WRAPPER_OUT_BUF, out_size); } #endif offset = 0; LOAD_INTEGER(WRAPPER_OUT_BUF, offset, *hauth); LOAD_BLOB_TYPE(WRAPPER_OUT_BUF, offset, nonce_even); return ret; }
/** * @brief * Insert server data into the database * * @param[in] conn - Connection handle * @param[in] obj - Information of server to be inserted * * @return Error code * @retval -1 - Failure * @retval 0 - Success * */ int pg_db_insert_svr(pbs_db_conn_t *conn, pbs_db_obj_info_t *obj) { pbs_db_svr_info_t *ps = obj->pbs_db_un.pbs_db_svr; LOAD_STR(conn, ps->sv_name, 0); LOAD_STR(conn, ps->sv_hostname, 1); LOAD_INTEGER(conn, ps->sv_numjobs, 2); LOAD_INTEGER(conn, ps->sv_numque, 3); LOAD_INTEGER(conn, ps->sv_jobidnumber, 4); LOAD_BIGINT(conn, ps->sv_svraddr, 5); LOAD_INTEGER(conn, ps->sv_svrport, 6); if (pg_db_cmd(conn, STMT_INSERT_SVR, 7) != 0) return -1; return 0; }
static uint32_t tpm_osap(uint32_t locality, tpm_entity_type_t ent_type, uint32_t ent_value, const tpm_nonce_t *odd_osap, tpm_authhandle_t *hauth, tpm_nonce_t *nonce_even, tpm_nonce_t *even_osap) { uint32_t ret, offset, out_size; if ( odd_osap == NULL || hauth == NULL || nonce_even == NULL || even_osap == NULL ) return TPM_BAD_PARAMETER; offset = 0; UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, ent_type); UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, ent_value); UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, odd_osap); out_size = sizeof(*hauth) + sizeof(*nonce_even) + sizeof(*even_osap); ret = tpm_submit_cmd(locality, TPM_ORD_OSAP, offset, &out_size); #ifdef TPM_TRACE printf("TPM: start OSAP, return value = %08X\n", ret); #endif if ( ret != TPM_SUCCESS ) { printf("TPM: start OSAP, return value = %08X\n", ret); return ret; } #ifdef TPM_TRACE { printf("TPM: "); print_hex(NULL, WRAPPER_OUT_BUF, out_size); } #endif offset = 0; LOAD_INTEGER(WRAPPER_OUT_BUF, offset, *hauth); LOAD_BLOB_TYPE(WRAPPER_OUT_BUF, offset, nonce_even); LOAD_BLOB_TYPE(WRAPPER_OUT_BUF, offset, even_osap); return ret; }
extern uint32_t tpm_get_nv_data_public(uint32_t locality, tpm_nv_index_t index, tpm_nv_data_public_t *pub) { uint32_t ret, offset, resp_size; uint8_t sub_cap[sizeof(index)]; uint8_t resp[sizeof(tpm_nv_data_public_t)]; tpm_nv_index_t idx; if ( pub == NULL ) { printf("TPM: tpm_get_nvindex_size() bad parameter\n"); return TPM_BAD_PARAMETER; } offset = 0; UNLOAD_INTEGER(sub_cap, offset, index); resp_size = sizeof(resp); ret = tpm_get_capability(locality, TPM_CAP_NV_INDEX, sizeof(sub_cap), sub_cap, &resp_size, resp); #ifdef TPM_TRACE printf("TPM: get nv_data_public, return value = %08X\n", ret); #endif if ( ret != TPM_SUCCESS ) { printf("TPM: fail to get public data of 0x%08X in TPM NV\n", index); return ret; } #ifdef TPM_TRACE { printf("TPM: "); print_hex(NULL, resp, resp_size); } #endif /* check size */ if ( resp_size == 0 ) { printf("TPM: Index 0x%08X does not exist\n", index); return TPM_BADINDEX; } /* check index */ offset = sizeof(tpm_structure_tag_t); LOAD_INTEGER(resp, offset, idx); #ifdef TPM_TRACE printf("TPM: get index value = %08X\n", idx); #endif if ( idx != index ) { printf("TPM: Index 0x%08X is not the one expected 0x%08X\n", idx, index); return TPM_BADINDEX; } if ( resp_size != sizeof(resp) ) { printf("TPM: public data size of Index 0x%08X responsed incorrect\n", index); return TPM_FAIL; } offset = 0; LOAD_NV_DATA_PUBLIC(resp, offset, pub); /*print_hex(" NV pub: ", pub, resp_size);*/ return ret; }
static uint32_t _tpm_unseal(uint32_t locality, tpm_key_handle_t hkey, const uint8_t *in_data, tpm_authhandle_t hauth, const tpm_nonce_t *nonce_odd, uint8_t *cont_session, const tpm_authdata_t *auth, tpm_authhandle_t hauth_d, const tpm_nonce_t *nonce_odd_d, uint8_t *cont_session_d, const tpm_authdata_t *auth_d, uint32_t *secret_size, uint8_t *secret, tpm_nonce_t *nonce_even, tpm_authdata_t *res_auth, tpm_nonce_t *nonce_even_d, tpm_authdata_t *res_auth_d) { uint32_t ret, offset, out_size; if ( in_data == NULL || nonce_odd == NULL || cont_session == NULL || auth == NULL || nonce_odd_d == NULL || cont_session_d == NULL || auth_d == NULL || secret_size == NULL || secret == NULL || nonce_even == NULL || res_auth == NULL || nonce_even_d == NULL || res_auth_d == NULL ) { printf("TPM: _tpm_unseal() bad parameter\n"); return TPM_BAD_PARAMETER; } offset = 0; UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, hkey); UNLOAD_STORED_DATA12(WRAPPER_IN_BUF, offset, in_data); UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, hauth); UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, nonce_odd); UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, *cont_session); UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, auth); UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, hauth_d); UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, nonce_odd_d); UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, *cont_session_d); UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, auth_d); out_size = WRAPPER_OUT_MAX_SIZE; ret = tpm_submit_cmd_auth2(locality, TPM_ORD_UNSEAL, offset, &out_size); #ifdef TPM_TRACE printf("TPM: unseal data, return value = %08X\n", ret); #endif if ( ret != TPM_SUCCESS ) { printf("TPM: unseal data, return value = %08X\n", ret); return ret; } #ifdef TPM_TRACE { printf("TPM: "); print_hex(NULL, WRAPPER_OUT_BUF, out_size); } #endif if ( *secret_size < ( out_size - sizeof(*secret_size) - sizeof(*nonce_even) - sizeof(*cont_session) - sizeof(*res_auth) - sizeof(*nonce_even_d) - sizeof(*cont_session_d) - sizeof(*res_auth_d) ) ) { printf("TPM: unsealed data too small\n"); return TPM_NOSPACE; } offset = 0; LOAD_INTEGER(WRAPPER_OUT_BUF, offset, *secret_size); LOAD_BLOB(WRAPPER_OUT_BUF, offset, secret, *secret_size); LOAD_BLOB_TYPE(WRAPPER_OUT_BUF, offset, nonce_even); LOAD_INTEGER(WRAPPER_OUT_BUF, offset, *cont_session); LOAD_BLOB_TYPE(WRAPPER_OUT_BUF, offset, res_auth); LOAD_BLOB_TYPE(WRAPPER_OUT_BUF, offset, nonce_even_d); LOAD_INTEGER(WRAPPER_OUT_BUF, offset, *cont_session_d); LOAD_BLOB_TYPE(WRAPPER_OUT_BUF, offset, res_auth_d); return ret; }
static uint32_t _tpm_seal(uint32_t locality, tpm_key_handle_t hkey, const tpm_encauth_t *enc_auth, uint32_t pcr_info_size, const tpm_pcr_info_long_t *pcr_info, uint32_t in_data_size, const uint8_t *in_data, tpm_authhandle_t hauth, const tpm_nonce_t *nonce_odd, uint8_t *cont_session, const tpm_authdata_t *pub_auth, uint32_t *sealed_data_size, uint8_t *sealed_data, tpm_nonce_t *nonce_even, tpm_authdata_t *res_auth) { uint32_t ret, offset, out_size; if ( enc_auth == NULL || pcr_info == NULL || in_data == NULL || nonce_odd == NULL || cont_session == NULL || pub_auth == NULL || sealed_data_size == NULL || sealed_data == NULL || nonce_even == NULL || res_auth == NULL ) { printf("TPM: _tpm_seal() bad parameter\n"); return TPM_BAD_PARAMETER; } offset = 0; UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, hkey); UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, enc_auth); UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, pcr_info_size); UNLOAD_PCR_INFO_LONG(WRAPPER_IN_BUF, offset, pcr_info); UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, in_data_size); UNLOAD_BLOB(WRAPPER_IN_BUF, offset, in_data, in_data_size); UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, hauth); UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, nonce_odd); UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, *cont_session); UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, pub_auth); out_size = WRAPPER_OUT_MAX_SIZE; ret = tpm_submit_cmd_auth1(locality, TPM_ORD_SEAL, offset, &out_size); #ifdef TPM_TRACE printf("TPM: seal data, return value = %08X\n", ret); #endif if ( ret != TPM_SUCCESS ) { printf("TPM: seal data, return value = %08X\n", ret); return ret; } #ifdef TPM_TRACE { printf("TPM: "); print_hex(NULL, WRAPPER_OUT_BUF, out_size); } #endif if ( *sealed_data_size < ( out_size - sizeof(*nonce_even) - sizeof(*cont_session) - sizeof(*res_auth) ) ) { printf("TPM: sealed blob is too small\n"); return TPM_NOSPACE; } offset = 0; LOAD_STORED_DATA12(WRAPPER_OUT_BUF, offset, sealed_data); *sealed_data_size = offset; LOAD_BLOB_TYPE(WRAPPER_OUT_BUF, offset, nonce_even); LOAD_INTEGER(WRAPPER_OUT_BUF, offset, *cont_session); LOAD_BLOB_TYPE(WRAPPER_OUT_BUF, offset, res_auth); return ret; }