string ArscImpl::checkSignature(string messageStream) { MessagePacket signedMessagePacket = MessagePacket(messageStream); gss_qop_t qopState; gss_buffer_desc *in_buf, *out_buf; int state=wrap; OM_uint32 minorStatus,majorStatus; in_buf=(gss_buffer_t) malloc(sizeof(gss_buffer_desc)); in_buf->value = (void*) signedMessagePacket.getMsg().c_str(); in_buf->length = signedMessagePacket.getMsg().length(); out_buf=(gss_buffer_desc*) malloc(sizeof(gss_buffer_desc)); majorStatus = gss_unwrap(&minorStatus, context, in_buf, out_buf, &state, (gss_qop_t *) NULL); // TODO release buffer // gss_release_buffer(minorStatus,&messageBuffer); //gss_release_buffer(minorStatus,&signToken); if(majorStatus != GSS_S_COMPLETE) { cerr<<"Data Verify error."<<endl; throw SignatureCheckingException(); }else { if (! state) { cerr<<"Warning! Message not encrypted.\n"<<endl; } cout << "Data Verify sucessfull. : \n" <<endl; return string((char *)out_buf->value,out_buf->length); } return MessagePacket().getStream(); }
int ArscImpl::initContext(){ if(auth()) { gss_buffer_desc send_token; gss_buffer_desc *token_ptr; gss_name_t target_name; MessagePacket msgIn , msgOut; OM_uint32 min_stat,maj_stat,init_sec_min_stat; OM_uint32 *ret_flags=(OM_uint32*)malloc(sizeof(OM_uint32)); string serviceName(SERVICENAME); send_token.value = (void *) serviceName.c_str(); send_token.length = serviceName.length(); maj_stat = gss_import_name(&min_stat,&send_token,(gss_OID) gss_nt_user_name ,&target_name); if(maj_stat != GSS_S_COMPLETE) { display_status("inicializing context",maj_stat,min_stat); (void) gss_release_name(&min_stat, &target_name); return 0; } token_ptr = GSS_C_NO_BUFFER; context = GSS_C_NO_CONTEXT; do { maj_stat = gss_init_sec_context(&init_sec_min_stat, GSS_C_NO_CREDENTIAL, &context, target_name, GSS_C_NULL_OID, GSS_C_MUTUAL_FLAG | GSS_C_REPLAY_FLAG, 0, NULL, // no chanel bindings token_ptr, NULL, // ignore mech type &send_token, ret_flags, NULL); // ignore time_rec if(send_token.length != 0){ msgOut = MessagePacket(std::string(id), std::string((char*)send_token.value,send_token.length)); try{ msgIn = (*arsmStub).initiateContext(msgOut); }catch(ContextInitiationException &e) { cerr << e.getMessage() << endl; return 0; } } (void) gss_release_buffer(&min_stat,&send_token); if(maj_stat!=GSS_S_COMPLETE && maj_stat != GSS_S_CONTINUE_NEEDED){ display_status("initializing context",maj_stat,init_sec_min_stat); (void) gss_release_name(&min_stat,&target_name); if(context != GSS_C_NO_CONTEXT){ // (void) gss_delete_sec_context(&min_stat,context, GSS_C_NO_BUFFER); } return 0; } if(maj_stat == GSS_S_CONTINUE_NEEDED){ free(token_ptr); token_ptr=(gss_buffer_desc*) malloc(sizeof(gss_buffer_desc)); token_ptr->value = (void *) msgIn.getMsg().c_str(); token_ptr->length = (int) msgIn.getMsg().length(); } } while( maj_stat == GSS_S_CONTINUE_NEEDED); (void) gss_release_name(&min_stat,&target_name); printf("Context created. %s\n",id.c_str()); return 1; } else { exit(2); } }