summaryrefslogtreecommitdiff
path: root/res/res_pjsip_outbound_authenticator_digest.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2013-07-30 18:14:50 +0000
committerMark Michelson <mmichelson@digium.com>2013-07-30 18:14:50 +0000
commit735b30ad71110c2a51404cb8686bbe3cf14b630c (patch)
tree76b1f10135c1b7f210e576be1359539de7e3476c /res/res_pjsip_outbound_authenticator_digest.c
parent895c8e0d2c97cd04299f3f179e99d8a3873c06c6 (diff)
The large GULP->PJSIP renaming effort.
The general gist is to have a clear boundary between old SIP stuff and new SIP stuff by having the word "SIP" for old stuff and "PJSIP" for new stuff. Here's a brief rundown of the changes: * The word "Gulp" in dialstrings, functions, and CLI commands is now "PJSIP" * chan_gulp.c is now chan_pjsip.c * Function names in chan_gulp.c that were "gulp_*" are now "chan_pjsip_*" * All files that were "res_sip*" are now "res_pjsip*" * The "res_sip" directory is now "res_pjsip" * Files in the "res_pjsip" directory that began with "sip_*" are now "pjsip_*" * The configuration file is now "pjsip.conf" instead of "res_sip.conf" * The module info for all PJSIP-related files now uses "PJSIP" instead of "SIP" * CLI and AMI commands created by Asterisk's PJSIP modules now have "pjsip" as the starting word instead of "sip" git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@395764 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_pjsip_outbound_authenticator_digest.c')
-rw-r--r--res/res_pjsip_outbound_authenticator_digest.c119
1 files changed, 119 insertions, 0 deletions
diff --git a/res/res_pjsip_outbound_authenticator_digest.c b/res/res_pjsip_outbound_authenticator_digest.c
new file mode 100644
index 000000000..0a262f354
--- /dev/null
+++ b/res/res_pjsip_outbound_authenticator_digest.c
@@ -0,0 +1,119 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*** MODULEINFO
+ <depend>pjproject</depend>
+ <depend>res_pjsip</depend>
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+#include <pjsip.h>
+
+#include "asterisk/res_pjsip.h"
+#include "asterisk/logger.h"
+#include "asterisk/module.h"
+#include "asterisk/strings.h"
+
+static int set_outbound_authentication_credentials(pjsip_auth_clt_sess *auth_sess, const struct ast_sip_auth_array *array)
+{
+ struct ast_sip_auth **auths = ast_alloca(array->num * sizeof(*auths));
+ pjsip_cred_info *auth_creds = ast_alloca(array->num * sizeof(*auth_creds));
+ int res = 0;
+ int i;
+
+ if (ast_sip_retrieve_auths(array, auths)) {
+ res = -1;
+ goto cleanup;
+ }
+
+ for (i = 0; i < array->num; ++i) {
+ pj_cstr(&auth_creds[i].realm, auths[i]->realm);
+ pj_cstr(&auth_creds[i].username, auths[i]->auth_user);
+ pj_cstr(&auth_creds[i].scheme, "digest");
+ switch (auths[i]->type) {
+ case AST_SIP_AUTH_TYPE_USER_PASS:
+ pj_cstr(&auth_creds[i].data, auths[i]->auth_pass);
+ auth_creds[i].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
+ break;
+ case AST_SIP_AUTH_TYPE_MD5:
+ pj_cstr(&auth_creds[i].data, auths[i]->md5_creds);
+ auth_creds[i].data_type = PJSIP_CRED_DATA_DIGEST;
+ break;
+ case AST_SIP_AUTH_TYPE_ARTIFICIAL:
+ ast_log(LOG_ERROR, "Trying to set artificial outbound auth credentials shouldn't happen.\n");
+ break;
+ }
+ }
+
+ pjsip_auth_clt_set_credentials(auth_sess, array->num, auth_creds);
+
+cleanup:
+ ast_sip_cleanup_auths(auths, array->num);
+ return res;
+}
+
+static int digest_create_request_with_auth(const struct ast_sip_auth_array *auths, pjsip_rx_data *challenge,
+ pjsip_transaction *tsx, pjsip_tx_data **new_request)
+{
+ pjsip_auth_clt_sess auth_sess;
+
+ if (pjsip_auth_clt_init(&auth_sess, ast_sip_get_pjsip_endpoint(),
+ tsx->pool, 0) != PJ_SUCCESS) {
+ ast_log(LOG_WARNING, "Failed to initialize client authentication session\n");
+ return -1;
+ }
+
+ if (set_outbound_authentication_credentials(&auth_sess, auths)) {
+ ast_log(LOG_WARNING, "Failed to set authentication credentials\n");
+ return -1;
+ }
+
+ if (pjsip_auth_clt_reinit_req(&auth_sess, challenge,
+ tsx->last_tx, new_request) != PJ_SUCCESS) {
+ ast_log(LOG_WARNING, "Failed to create new request with authentication credentials\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static struct ast_sip_outbound_authenticator digest_authenticator = {
+ .create_request_with_auth = digest_create_request_with_auth,
+};
+
+static int load_module(void)
+{
+ if (ast_sip_register_outbound_authenticator(&digest_authenticator)) {
+ return AST_MODULE_LOAD_DECLINE;
+ }
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+static int unload_module(void)
+{
+ ast_sip_unregister_outbound_authenticator(&digest_authenticator);
+ return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP authentication resource",
+ .load = load_module,
+ .unload = unload_module,
+ .load_pri = AST_MODPRI_CHANNEL_DEPEND,
+);