@@ -65,6 +65,9 @@ static void add_custom_client_parameters(SessionRegisterReq_t * sessionReq) {
6565 * this: SessionRegisterReq_addNewClientParameter(sessionReq,
6666 * "devicetype", "linux");
6767 */
68+ #ifdef __QATESTING__
69+ SessionRegisterReq_addNewClientParameter (sessionReq , "qatesting" , "true" );
70+ #endif
6871 return ;
6972} /* add_custom_client_parameters */
7073
@@ -135,17 +138,22 @@ static void update_config_from_session(SessionRegisterResp_t * sessionResp) {
135138 if (!ConfigData || !sessionResp ) return ;
136139 if (!ConfigData -> EnrollOnStartup ) return ;
137140
138- if (sessionResp -> Session .Certificate ) {
141+ if (sessionResp -> Session .Certificate && sessionResp -> Session . Certificate [ 0 ] != '\0' ) {
139142 log_info ("%s::%s(%d) : Received Agent Certificate. Turning off EnrollOnStartup." , LOG_INF );
140143 isChanged = true;
141144 ConfigData -> EnrollOnStartup = false;
145+ } else if (false == ConfigData -> UseAgentCert ) {
146+ log_info ("%s::%s(%d) : Not using an Agent Certificate. Turning off EnrollOnStartup." , LOG_INF );
147+ isChanged = true;
148+ ConfigData -> EnrollOnStartup = false;
149+ } else {
150+ log_info ("%s::%s(%d) : Received no Agent Certificate. BUT, we should have received one." , LOG_INF );
142151 }
143152
144153 if (isChanged ) {
145154 log_trace ("%s::%s(%d) : Saving configuration to file system" , LOG_INF );
146155 config_save ();
147156 }
148- return ;
149157} /* update_config_from_session */
150158
151159/* */
@@ -290,8 +298,8 @@ static void prioritize_jobs(ScheduledJob_t **pJobList,
290298 schedule_job (pJobList , job_to_schedule , time (NULL ));
291299 }
292300 }
293- return ;
294301} /* prioritize_jobs */
302+
295303/* */
296304/* Add the capabilities allowed in this version of the agent by */
297305/* capability GUID defined in Keyfactor */
@@ -376,7 +384,6 @@ static void set_registration_parameters(SessionRegisterReq_t * sessionReq) {
376384 /* Add any custom parameters for this customer */
377385 add_custom_client_parameters (sessionReq );
378386
379- return ;
380387} /* set_registration_parameters */
381388
382389/* */
@@ -808,34 +815,38 @@ static int re_register_agent(SessionInfo_t * session, ScheduledJob_t * *pJobList
808815static bool do_first_registration_response (SessionRegisterResp_t * resp , char * * status ,
809816 enum AgentApiResultStatus * statusCode )
810817{
811- if (NULL == resp ) {
812- log_error ("%s::%s(%d) : Error, response to parse is null" , LOG_INF );
813- return false;
814- }
815- bool bResult = false;
816- bool bIdOk = false;
817- log_trace ("%s::%s(%d): Updating config from session" , LOG_INF );
818- bIdOk = update_agentid_from_session (resp );
819-
820- if (ConfigData -> UseAgentCert && bIdOk ) {
821- if (resp -> Session .Certificate ) {
822- bResult = true;
823- log_info ("%s::%s(%d): Agent certificate recieved from platform. Saving Agent Specific Keypair and "
824- "Agent Specific Cert." , LOG_INF );
825- save_cert_key (ConfigData -> AgentCert ,
826- ConfigData -> AgentKey , ConfigData -> AgentKeyPassword ,
827- resp -> Session .Certificate , status , statusCode );
828- update_config_from_session (resp );
829- } else {
830- /* The platform should have provided a certificate */
831- log_error ("%s::%s(%d): Certificate not found" , LOG_INF );
832- }
833- } else {
834- /* We don't need a certificate, but we do need an AgentId */
835- if (bIdOk )
836- bResult = true;
837- }
838- return bResult ;
818+ if (NULL == resp ) {
819+ log_error ("%s::%s(%d) : Error, response to parse is null" , LOG_INF );
820+ return false;
821+ }
822+ bool bResult = false;
823+ bool bIdOk = false;
824+ log_trace ("%s::%s(%d): Updating config from session" , LOG_INF );
825+ bIdOk = update_agentid_from_session (resp );
826+
827+ if (ConfigData -> UseAgentCert && bIdOk ) {
828+ if (resp -> Session .Certificate ) {
829+ bResult = true;
830+ log_info ("%s::%s(%d): Agent certificate received from platform. Saving Agent Specific Keypair and "
831+ "Agent Specific Cert." , LOG_INF );
832+ save_cert_key (ConfigData -> AgentCert ,
833+ ConfigData -> AgentKey , ConfigData -> AgentKeyPassword ,
834+ resp -> Session .Certificate , status , statusCode );
835+ update_config_from_session (resp );
836+ } else {
837+ /* The platform should have provided a certificate */
838+ log_error ("%s::%s(%d): Certificate not found" , LOG_INF );
839+ }
840+ } else {
841+ /* We don't need a certificate, but we do need an AgentId */
842+ if (bIdOk )
843+ bResult = true;
844+ }
845+
846+ log_info ("%s::%s(%d): First registration completed with %s" ,
847+ LOG_INF , bResult ? "success" : "failure" );
848+
849+ return bResult ;
839850} /* do_first_registration_response */
840851
841852/* */
@@ -930,7 +941,7 @@ int register_session(SessionInfo_t * session, ScheduledJob_t * *pJobList, uint64
930941 log_trace ("%s::%s(%d) : Successfully set up /Session/Register data." , LOG_INF );
931942 }
932943 } else {
933- log_trace ("%s::%s(%d) : Skipping agent cert from configurtion " , LOG_INF );
944+ log_trace ("%s::%s(%d) : Configured to not use an Agent Certificate " , LOG_INF );
934945 }
935946 } else {
936947 if (ConfigData -> UseAgentCert ) {
@@ -1062,12 +1073,15 @@ int register_session(SessionInfo_t * session, ScheduledJob_t * *pJobList, uint64
10621073 log_trace ("%s::%s(%d) Performing second registration." , LOG_INF );
10631074 httpRes = do_second_registration (session , pJobList , agentVersion );
10641075 if (0 == httpRes ) {
1065- log_info ("%s::%s(%d): Re-enrollment jobs set up successfully" , LOG_INF );
1076+ log_info ("%s::%s(%d): Re-enrollment jobs set up successfully" , LOG_INF );
1077+ ConfigData -> EnrollOnStartup = false;
1078+ config_save ();
10661079 } else {
1067- /* Session failed, so we need to re-register the agent */
1068- /* on the next trigger */
1069- ConfigData -> EnrollOnStartup = true;
1070- log_warn ("%s::%s(%d) : Re-registering agent as second registration failed" , LOG_INF );
1080+ /* Session failed, so we need to re-register the agent */
1081+ /* on the next trigger */
1082+ ConfigData -> EnrollOnStartup = true;
1083+ log_warn ("%s::%s(%d) : Re-registering agent as second registration failed" , LOG_INF );
1084+ config_save ();
10711085 }
10721086 }
10731087
0 commit comments