/* * Report Identity header * param trans Transaction handle * return 0 success, -1 failure */ static int ospReportIdentity( OSPTTRANHANDLE trans) { char encoded[OSP_SIGNBUF_SIZE]; unsigned signsize; unsigned char sign[OSP_SIGNBUF_SIZE]; char alg[OSP_ALGBUF_SIZE]; char info[OSP_STRBUF_SIZE]; char type[OSP_STRBUF_SIZE]; unsigned canonsize; unsigned char canon[OSP_STRBUF_SIZE]; int result = 0; if (ospGetAVP(_osp_idsign_avpid, _osp_idsign_avptype, encoded, sizeof(encoded)) == 0) { signsize = sizeof(sign); if (OSPPBase64Decode(encoded, strlen(encoded), sign, &signsize) != OSPC_ERR_NO_ERROR) { signsize = 0; } } else { signsize = 0; } if (ospGetAVP(_osp_idalg_avpid, _osp_idalg_avptype, alg, sizeof(alg)) != 0) { alg[0] = '\0'; } if (ospGetAVP(_osp_idinfo_avpid, _osp_idinfo_avptype, info, sizeof(info)) != 0) { info[0] = '\0'; } if (ospGetAVP(_osp_idtype_avpid, _osp_idtype_avptype, type, sizeof(type)) != 0) { type[0] = '\0'; } if (ospGetAVP(_osp_idcanon_avpid, _osp_idcanon_avptype, encoded, sizeof(encoded)) == 0) { canonsize = sizeof(canon); if (OSPPBase64Decode(encoded, strlen(encoded), canon, &canonsize) != OSPC_ERR_NO_ERROR) { canonsize = 0; } } else { canonsize = 0; } if (OSPPTransactionSetIdentity(trans, signsize, sign, alg, info, type, canonsize, canon) != OSPC_ERR_NO_ERROR) { result = -1; } return result; }
/* * Get OSP token from SIP message * param msg SIP message * param token OSP authorization token * param tokensize Size of OSP authorization token * return 0 success, -1 failure */ int ospGetOspHeader( struct sip_msg* msg, unsigned char* token, unsigned int* tokensize) { struct hdr_field* hf; int errorcode; int result = -1; parse_headers(msg, HDR_EOH_F, 0); for (hf = msg->headers; hf; hf = hf->next) { if ((hf->type == HDR_OTHER_T) && (hf->name.len == OSP_HEADER_SIZE - 2)) { // possible hit if (strncasecmp(hf->name.s, OSP_TOKEN_HEADER, OSP_HEADER_SIZE) == 0) { if ((errorcode = OSPPBase64Decode(hf->body.s, hf->body.len, token, tokensize)) == OSPC_ERR_NO_ERROR) { result = 0; } else { LM_ERR("failed to base64 decode token (%d)\n", errorcode); LM_ERR("header '%.*s' length %d\n", hf->body.len, hf->body.s, hf->body.len); } break; } } } return result; }
int getOspHeader(struct sip_msg* msg, char* token, int* sizeoftoken) { struct hdr_field *hf; int code; int retVal = 1; parse_headers(msg, HDR_EOH, 0); for (hf=msg->headers; hf; hf=hf->next) { if ( (hf->type == HDR_OTHER) && (hf->name.len == OSP_HEADER_LEN-2)) { // possible hit if (strncasecmp(hf->name.s, OSP_HEADER, OSP_HEADER_LEN) == 0) { if ( (code=OSPPBase64Decode(hf->body.s, hf->body.len, token, sizeoftoken)) == 0) { retVal = 0; } else { LOG(L_ERR, "ERROR: osp: getOspHeader: failed to base64 decode OSP token, reason - %d\n",code); LOG(L_ERR, "ERROR: osp: header '%.*s' length %d\n",hf->body.len,hf->body.s,hf->body.len); } break; } } } return retVal; }
/* * Get OSP token from SIP message * param msg SIP message * param token OSP authorization token * param tokensize Size of OSP authorization token * return 0 success, -1 failure */ int ospGetOspHeader( struct sip_msg* msg, unsigned char* token, unsigned int* tokensize) { struct hdr_field* hf; int errorcode; int result = -1; if (parse_headers(msg, HDR_EOH_F, 0) != 0) { LM_ERR("failed to parse all headers\n"); } else { hf = get_header_by_name(msg, OSP_TOKEN_HEADER, OSP_HEADER_SIZE); if (hf) { if ((errorcode = OSPPBase64Decode(hf->body.s, hf->body.len, token, tokensize)) == OSPC_ERR_NO_ERROR) { result = 0; } else { LM_ERR("failed to base64 decode token (%d)\n", errorcode); LM_ERR("header '%.*s' length %d\n", hf->body.len, hf->body.s, hf->body.len); } } } return result; }