// Reset auth manager object. void authmgtReset(struct s_authmgt *mgt) { int i; int count = idspSize(&mgt->idsp); for(i=0; i<count; i++) { authReset(&mgt->authstate[i]); } idspReset(&mgt->idsp); mgt->fastauth = 0; mgt->current_authed_id = -1; mgt->current_completed_id = -1; debug("auth manager RESET completed"); }
// Create auth state object. static int authCreate(struct s_auth_state *authstate, struct s_netid *netid, struct s_nodekey *local_nodekey, struct s_dh_state *dhstate, const int authid) { utilWriteInt32(authstate->local_authid, authid); if(dhstate == NULL) return 0; if(local_nodekey == NULL) return 0; if(netid == NULL) return 0; if(!rsaIsValid(&local_nodekey->key)) return 0; if(!rsaIsPrivate(&local_nodekey->key)) return 0; authstate->dhstate = dhstate; authstate->local_nodekey = local_nodekey; authstate->netid = netid; if(nodekeyCreate(&authstate->remote_nodekey)) { if(cryptoCreate(authstate->crypto_ctx, auth_CRYPTOCTX_COUNT)) { authReset(authstate); return 1; } nodekeyDestroy(&authstate->remote_nodekey); } return 0; }
// Delete auth session. void authmgtDelete(struct s_authmgt *mgt, const int authstateid) { if(mgt->current_authed_id == authstateid) mgt->current_authed_id = -1; if(mgt->current_completed_id == authstateid) mgt->current_completed_id = -1; authReset(&mgt->authstate[authstateid]); idspDelete(&mgt->idsp, authstateid); }
// Destroy auth state object. static void authDestroy(struct s_auth_state *authstate) { authReset(authstate); cryptoDestroy(authstate->crypto_ctx, auth_CRYPTOCTX_COUNT); nodekeyDestroy(&authstate->remote_nodekey); }