blob: a684490fbbbc4b13381e2844073d2dc91df8c385 [file] [log] [blame]
Benny Prijono708725a2008-03-09 12:55:00 +00001/* $Id$ */
2/*
3 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJ_TURN_SRV_AUTH_H__
20#define __PJ_TURN_SRV_AUTH_H__
21
22#include <pjnath.h>
23
24/**
25 * Initialize TURN authentication subsystem.
26 *
27 * @return PJ_SUCCESS on success.
28 */
29PJ_DECL(pj_status_t) pj_turn_auth_init(const char *realm);
30
31/**
32 * Shutdown TURN authentication subsystem.
33 */
34PJ_DECL(void) pj_turn_auth_dinit(void);
35
36/**
37 * This function is called by pj_stun_verify_credential() when
38 * server needs to challenge the request with 401 response.
39 *
40 * @param user_data Should be ignored.
41 * @param pool Pool to allocate memory.
42 * @param realm On return, the function should fill in with
43 * realm if application wants to use long term
44 * credential. Otherwise application should set
45 * empty string for the realm.
46 * @param nonce On return, if application wants to use long
47 * term credential, it MUST fill in the nonce
48 * with some value. Otherwise if short term
49 * credential is wanted, it MAY set this value.
50 * If short term credential is wanted and the
51 * application doesn't want to include NONCE,
52 * then it must set this to empty string.
53 *
54 * @return The callback should return PJ_SUCCESS, or
55 * otherwise response message will not be
56 * created.
57 */
58PJ_DECL(pj_status_t) pj_turn_get_auth(void *user_data,
59 pj_pool_t *pool,
60 pj_str_t *realm,
61 pj_str_t *nonce);
62
63/**
Benny Prijono708725a2008-03-09 12:55:00 +000064 * This function is called to get the password for the specified username.
65 * This function is also used to check whether the username is valid.
66 *
67 * @param msg The STUN message where the password will be
68 * applied to.
69 * @param user_data Should be ignored.
70 * @param realm The realm as specified in the message.
71 * @param username The username as specified in the message.
72 * @param pool Pool to allocate memory when necessary.
73 * @param data_type On return, application should fill up this
74 * argument with the type of data (which should
75 * be zero if data is a plaintext password).
76 * @param data On return, application should fill up this
77 * argument with the password according to
78 * data_type.
79 *
80 * @return The callback should return PJ_SUCCESS if
81 * username has been successfully verified
82 * and password was obtained. If non-PJ_SUCCESS
83 * is returned, it is assumed that the
84 * username is not valid.
85 */
86PJ_DECL(pj_status_t) pj_turn_get_password(const pj_stun_msg *msg,
87 void *user_data,
88 const pj_str_t *realm,
89 const pj_str_t *username,
90 pj_pool_t *pool,
Benny Prijono68854002008-03-20 19:21:27 +000091 pj_stun_passwd_type *data_type,
Benny Prijono708725a2008-03-09 12:55:00 +000092 pj_str_t *data);
93
94/**
95 * This function will be called to verify that the NONCE given
96 * in the message can be accepted. If this callback returns
97 * PJ_FALSE, 438 (Stale Nonce) response will be created.
98 *
99 * @param msg The STUN message where the nonce was received.
100 * @param user_data Should be ignored.
101 * @param realm The realm as specified in the message.
102 * @param username The username as specified in the message.
103 * @param nonce The nonce to be verified.
104 *
105 * @return The callback MUST return non-zero if the
106 * NONCE can be accepted.
107 */
Benny Prijono9e6d60a2008-03-20 16:32:06 +0000108PJ_DECL(pj_bool_t) pj_turn_verify_nonce(const pj_stun_msg *msg,
109 void *user_data,
110 const pj_str_t *realm,
111 const pj_str_t *username,
112 const pj_str_t *nonce);
Benny Prijono708725a2008-03-09 12:55:00 +0000113
114#endif /* __PJ_TURN_SRV_AUTH_H__ */
115