示例#1
0
int addOspHeader(struct sip_msg* msg, char* token, int sizeoftoken) {

	char headerBuffer[3500];
	char encodedToken[3000];
	int  sizeofencodedToken = sizeof(encodedToken);
	str  headerVal;
	int  retVal = 1;

	if (OSPPBase64Encode(token, sizeoftoken, encodedToken, &sizeofencodedToken) == 0) {
		snprintf(headerBuffer,
			 sizeof(headerBuffer),
			 "%s%.*s\r\n", 
			 OSP_HEADER,
			 sizeofencodedToken,
			 encodedToken);

		headerVal.s = headerBuffer;
		headerVal.len = strlen(headerBuffer);

		DBG("osp: Setting osp token header field - (%s)\n", headerBuffer);

		if (append_hf(msg,(char *)&headerVal,NULL) > 0) {
			retVal = 0;
		} else {
			LOG(L_ERR, "ERROR: osp: addOspHeader: failed to append osp header to the message\n");
		}
	} else {
		LOG(L_ERR, "ERROR: osp: addOspHeader: base64 encoding failed\n");
	}

	return retVal;
}
示例#2
0
/*
 * Concates the message From, To, Call-ID, Cseq, Date,  Contact header fields
 * and the message body to digest-string, signs with the domain private-key,
 * BASE64 encodes that, and finally adds it to the message as the 'Identity'
 * header value. RFC4474 [5] Step 4
 *
 * Adds Identity-Info header to the message which contains an URI from which
 * its certificate can be acquired. RFC4474 [5] Step 4
 */
static int add_identity(struct sip_msg* msg, char* srt1, char* str2)
{
    int iRes;
    str sstr;


    if (glb_authservice_disabled) {
        LOG(L_WARN, "AUTH_IDENTITY:add_identity: Authentication Service is disabled\n");
        return -1;
    }

    /* check Date */
    iRes=datehdr_proc(NULL, NULL, msg);
    switch (iRes) {
    case AUTH_ERROR:
        return -1;
    case AUTH_NOTFOUND:
        if (!getstr_dynstr(&glb_sdate).len) {
            /*
             * date_proc() must be called before add_identity() because
             * that function initializes the Date if that not exists
             * in the SIP message
             */
            LOG(L_ERR, "AUTH_IDENTITY:add_identity: Date header is not found (has auth_date_proc been called?)\n");
            return -2;
        }
        /*  assemble the digest string and the DATE header is missing in the orignal message */
        if (digeststr_asm(&glb_sdgst,
                          msg,
                          &getstr_dynstr(&glb_sdate),
                          AUTH_OUTGOING_BODY | AUTH_ADD_DATE))
            return -3;
        break;
    default:
        /*  assemble the digest string and the DATE header is available in the message */
        if (digeststr_asm(&glb_sdgst, msg, NULL, AUTH_OUTGOING_BODY))
            return -4;
        break;
    }

    /* calculate the SHA1 hash and encrypt with our provate key */
    if (rsa_sha1_enc(&glb_sdgst, &glb_encedmsg, &glb_b64encedmsg, glb_hmyprivkey))
        return -5;

    /* we assemble the value of the Identity haader */
    sstr.s=IDENTITY_FIRST_PART;
    sstr.len=strlen(IDENTITY_FIRST_PART);
    if (cpy2dynstr(&glb_sidentity, &sstr))
        return -6;

    if (app2dynstr(&glb_sidentity, &getstr_dynstr(&glb_b64encedmsg)))
        return -7;

    sstr.s=IDENTITY_LAST_PART;
    /* +1 : we need the trailing \0 character too */
    sstr.len=strlen(IDENTITY_LAST_PART) + 1;
    if (app2dynstr(&glb_sidentity, &sstr))
        return -8;

    if (append_hf(msg, getstr_dynstr(&glb_sidentity).s, HDR_IDENTITY_T))
        return -9;

    if (append_hf(msg, getstr_dynstr(&glb_sidentityinfo).s, HDR_IDENTITY_INFO_T))
        return -10;

    return 1;
}