aboutsummaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-06-25 05:52:55 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-06-25 05:52:55 +0000
commit2880b1df66d522a3074402f1e0915c28a3dbada7 (patch)
tree6c1292d10168096e90fd3533b1abef631b86725c /res
parent6c4cb5454fdb3be753f731b1ec136bf1907fea90 (diff)
Add sample config file, implement verification
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3300 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rwxr-xr-xres/res_osp.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/res/res_osp.c b/res/res_osp.c
index 6270c4a72..c62735ede 100755
--- a/res/res_osp.c
+++ b/res/res_osp.c
@@ -420,6 +420,67 @@ static int loadPemPrivateKey(unsigned char *FileName, unsigned char *buffer, int
return retVal;
}
+int ast_osp_validate(char *provider, char *token, int *handle, unsigned int *timelimit, char *callerid, struct in_addr addr, char *extension)
+{
+ char tmp[256]="", *l, *n;
+ char ip[256];
+ char source[OSP_MAX]; /* Same length as osp->source */
+ char *token2;
+ int tokenlen;
+ struct osp_provider *osp;
+ int res = 0;
+ unsigned int authorised, dummy;
+
+ if (!provider || !strlen(provider))
+ provider = "default";
+
+ token2 = ast_strdupa(token);
+ if (!token2)
+ return -1;
+ tokenlen = ast_base64decode(token2, token, strlen(token));
+ *handle = -1;
+ if (!callerid)
+ callerid = "";
+ strncpy(tmp, callerid, sizeof(tmp) - 1);
+ ast_callerid_parse(tmp, &n, &l);
+ if (!l)
+ l = "";
+ else {
+ ast_shrink_phone_number(l);
+ if (!ast_isphonenumber(l))
+ l = "";
+ }
+ callerid = l;
+ ast_mutex_lock(&osplock);
+ strcpy(ip, inet_ntoa(addr));
+ osp = providers;
+ while(osp) {
+ if (!strcasecmp(osp->name, provider)) {
+ if (OSPPTransactionNew(osp->handle, handle)) {
+ ast_log(LOG_WARNING, "Unable to create OSP Transaction handle!\n");
+ } else {
+ strcpy(source, osp->source);
+ res = 1;
+ }
+ break;
+ }
+ osp = osp->next;
+ }
+ ast_mutex_unlock(&osplock);
+ if (res) {
+ res = 0;
+ dummy = 0;
+ if (!OSPPTransactionValidateAuthorisation(*handle, ip, source, NULL, NULL,
+ callerid, OSPC_E164, extension, OSPC_E164, 0, "", tokenlen, token2, &authorised, timelimit, &dummy, NULL, TOKEN_ALGO_BOTH)) {
+ if (authorised) {
+ ast_log(LOG_DEBUG, "Validated token for '%s' from '%s@%s'\n", extension, callerid, ip);
+ res = 1;
+ }
+ }
+ }
+ return res;
+}
+
int ast_osp_lookup(struct ast_channel *chan, char *provider, char *extension, char *callerid, struct ast_osp_result *result)
{
int cres;