mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-13 00:04:53 +00:00
add token format specification support (issue #5199)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6580 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -14,6 +14,14 @@
|
|||||||
; on a reload.
|
; on a reload.
|
||||||
;
|
;
|
||||||
;accelerate=yes
|
;accelerate=yes
|
||||||
|
;
|
||||||
|
; Defines the token format that Asterisk can validate.
|
||||||
|
; 0 - signed tokens only
|
||||||
|
; 1 - unsigned tokens only
|
||||||
|
; 2 - both signed and unsigned
|
||||||
|
; The defaults to 0, i.e. the Asterisk can validate signed tokens only.
|
||||||
|
;
|
||||||
|
;tokenformat=0
|
||||||
|
|
||||||
;[default]
|
;[default]
|
||||||
;
|
;
|
||||||
|
@@ -63,6 +63,7 @@ AST_MUTEX_DEFINE_STATIC(osplock);
|
|||||||
|
|
||||||
static int initialized = 0;
|
static int initialized = 0;
|
||||||
static int hardware = 0;
|
static int hardware = 0;
|
||||||
|
static unsigned tokenformat = TOKEN_ALGO_SIGNED;
|
||||||
|
|
||||||
struct osp_provider {
|
struct osp_provider {
|
||||||
char name[OSP_MAX];
|
char name[OSP_MAX];
|
||||||
@@ -278,13 +279,28 @@ static int show_osp(int fd, int argc, char *argv[])
|
|||||||
char *search = NULL;
|
char *search = NULL;
|
||||||
int x;
|
int x;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
char *tokenalgo;
|
||||||
|
|
||||||
if ((argc < 2) || (argc > 3))
|
if ((argc < 2) || (argc > 3))
|
||||||
return RESULT_SHOWUSAGE;
|
return RESULT_SHOWUSAGE;
|
||||||
if (argc > 2)
|
if (argc > 2)
|
||||||
search = argv[2];
|
search = argv[2];
|
||||||
if (!search)
|
if (!search) {
|
||||||
ast_cli(fd, "OSP: %s %s\n", initialized ? "Initialized" : "Uninitialized", hardware ? "Accelerated" : "Normal");
|
switch (tokenformat) {
|
||||||
|
case TOKEN_ALGO_BOTH:
|
||||||
|
tokenalgo = "Both";
|
||||||
|
break;
|
||||||
|
case TOKEN_ALGO_UNSIGNED:
|
||||||
|
tokenalgo = "Unsigned";
|
||||||
|
break;
|
||||||
|
case TOKEN_ALGO_SIGNED:
|
||||||
|
default:
|
||||||
|
tokenalgo = "Signed";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ast_cli(fd, "OSP: %s %s %s\n", initialized ? "Initialized" : "Uninitialized", hardware ? "Accelerated" : "Normal", tokenalgo);
|
||||||
|
}
|
||||||
|
|
||||||
ast_mutex_lock(&osplock);
|
ast_mutex_lock(&osplock);
|
||||||
osp = providers;
|
osp = providers;
|
||||||
while(osp) {
|
while(osp) {
|
||||||
@@ -476,7 +492,7 @@ int ast_osp_validate(char *provider, char *token, int *handle, unsigned int *tim
|
|||||||
res = 0;
|
res = 0;
|
||||||
dummy = 0;
|
dummy = 0;
|
||||||
if (!OSPPTransactionValidateAuthorisation(*handle, iabuf, source, NULL, NULL,
|
if (!OSPPTransactionValidateAuthorisation(*handle, iabuf, source, NULL, NULL,
|
||||||
callerid, OSPC_E164, extension, OSPC_E164, 0, "", tokenlen, token2, &authorised, timelimit, &dummy, NULL, TOKEN_ALGO_BOTH)) {
|
callerid, OSPC_E164, extension, OSPC_E164, 0, "", tokenlen, token2, &authorised, timelimit, &dummy, NULL, tokenformat)) {
|
||||||
if (authorised) {
|
if (authorised) {
|
||||||
ast_log(LOG_DEBUG, "Validated token for '%s' from '%s@%s'\n", extension, callerid, iabuf);
|
ast_log(LOG_DEBUG, "Validated token for '%s' from '%s@%s'\n", extension, callerid, iabuf);
|
||||||
res = 1;
|
res = 1;
|
||||||
@@ -780,6 +796,13 @@ static int config_load(void)
|
|||||||
OSPPInit(0);
|
OSPPInit(0);
|
||||||
initialized = 1;
|
initialized = 1;
|
||||||
}
|
}
|
||||||
|
cat = ast_variable_retrieve(cfg, "general", "tokenformat");
|
||||||
|
if (cat) {
|
||||||
|
if ((sscanf(cat, "%d", &tokenformat) != 1) || (tokenformat < TOKEN_ALGO_SIGNED) || (tokenformat > TOKEN_ALGO_BOTH)) {
|
||||||
|
tokenformat = TOKEN_ALGO_SIGNED;
|
||||||
|
ast_log(LOG_WARNING, "tokenformat should be an integer from 0 to 2, not '%s'\n", cat);
|
||||||
|
}
|
||||||
|
}
|
||||||
cat = ast_category_browse(cfg, NULL);
|
cat = ast_category_browse(cfg, NULL);
|
||||||
while(cat) {
|
while(cat) {
|
||||||
if (strcasecmp(cat, "general"))
|
if (strcasecmp(cat, "general"))
|
||||||
|
Reference in New Issue
Block a user