GstRTSPAuth: Add client certificate authentication support
[platform/upstream/gstreamer.git] / gst / rtsp-server / rtsp-auth.h
1 /* GStreamer
2  * Copyright (C) 2010 Wim Taymans <wim.taymans at gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include <gst/gst.h>
21
22 #ifndef __GST_RTSP_AUTH_H__
23 #define __GST_RTSP_AUTH_H__
24
25 typedef struct _GstRTSPAuth GstRTSPAuth;
26 typedef struct _GstRTSPAuthClass GstRTSPAuthClass;
27 typedef struct _GstRTSPAuthPrivate GstRTSPAuthPrivate;
28
29 #include "rtsp-client.h"
30 #include "rtsp-token.h"
31
32 G_BEGIN_DECLS
33
34 #define GST_TYPE_RTSP_AUTH              (gst_rtsp_auth_get_type ())
35 #define GST_IS_RTSP_AUTH(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTSP_AUTH))
36 #define GST_IS_RTSP_AUTH_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTSP_AUTH))
37 #define GST_RTSP_AUTH_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTSP_AUTH, GstRTSPAuthClass))
38 #define GST_RTSP_AUTH(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTSP_AUTH, GstRTSPAuth))
39 #define GST_RTSP_AUTH_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTSP_AUTH, GstRTSPAuthClass))
40 #define GST_RTSP_AUTH_CAST(obj)         ((GstRTSPAuth*)(obj))
41 #define GST_RTSP_AUTH_CLASS_CAST(klass) ((GstRTSPAuthClass*)(klass))
42
43 /**
44  * GstRTSPAuth:
45  *
46  * The authentication structure.
47  */
48 struct _GstRTSPAuth {
49   GObject       parent;
50
51   /*< private >*/
52   GstRTSPAuthPrivate *priv;
53   gpointer _gst_reserved[GST_PADDING];
54 };
55
56 /**
57  * GstRTSPAuthClass:
58  * @authenticate: check the authentication of a client. The default implementation
59  *         checks if the authentication in the header matches one of the basic
60  *         authentication tokens. This function should set the authgroup field
61  *         in the context.
62  * @check: check if a resource can be accessed. this function should
63  *         call authenticate to authenticate the client when needed. The method
64  *         should also construct and send an appropriate response message on
65  *         error.
66  *
67  * The authentication class.
68  */
69 struct _GstRTSPAuthClass {
70   GObjectClass  parent_class;
71
72   gboolean           (*authenticate) (GstRTSPAuth *auth, GstRTSPContext *ctx);
73   gboolean           (*check)        (GstRTSPAuth *auth, GstRTSPContext *ctx,
74                                       const gchar *check);
75   gboolean           (*accept_certificate) (GstRTSPAuth *auth,
76                                             GTlsConnection *connection,
77                                             GTlsCertificate *peer_cert,
78                                             GTlsCertificateFlags errors);
79   /*< private >*/
80   gpointer            _gst_reserved[GST_PADDING - 1];
81 };
82
83 GType               gst_rtsp_auth_get_type          (void);
84
85 GstRTSPAuth *       gst_rtsp_auth_new               (void);
86
87 void                gst_rtsp_auth_set_tls_certificate (GstRTSPAuth *auth, GTlsCertificate *cert);
88 GTlsCertificate *   gst_rtsp_auth_get_tls_certificate (GstRTSPAuth *auth);
89
90 void                gst_rtsp_auth_set_tls_database (GstRTSPAuth *auth, GTlsDatabase *database);
91 GTlsDatabase *      gst_rtsp_auth_get_tls_database (GstRTSPAuth *auth);
92
93 void                gst_rtsp_auth_set_tls_authentication_mode (GstRTSPAuth *auth, GTlsAuthenticationMode mode);
94 GTlsAuthenticationMode gst_rtsp_auth_get_tls_authentication_mode (GstRTSPAuth *auth);
95
96 void                gst_rtsp_auth_set_default_token (GstRTSPAuth *auth, GstRTSPToken *token);
97 GstRTSPToken *      gst_rtsp_auth_get_default_token (GstRTSPAuth *auth);
98
99 void                gst_rtsp_auth_add_basic         (GstRTSPAuth *auth, const gchar * basic,
100                                                      GstRTSPToken *token);
101 void                gst_rtsp_auth_remove_basic      (GstRTSPAuth *auth, const gchar * basic);
102
103 gboolean            gst_rtsp_auth_check             (const gchar *check);
104
105
106 /* helpers */
107 gchar *             gst_rtsp_auth_make_basic        (const gchar * user, const gchar * pass);
108
109 /* checks */
110 /**
111  * GST_RTSP_AUTH_CHECK_CONNECT:
112  *
113  * Check a new connection
114  */
115 #define GST_RTSP_AUTH_CHECK_CONNECT                  "auth.check.connect"
116 /**
117  * GST_RTSP_AUTH_CHECK_URL:
118  *
119  * Check the URL and methods
120  */
121 #define GST_RTSP_AUTH_CHECK_URL                      "auth.check.url"
122 /**
123  * GST_RTSP_AUTH_CHECK_MEDIA_FACTORY_ACCESS:
124  *
125  * Check if access is allowed to a factory.
126  * When access is not allowed an 404 Not Found is sent in the response.
127  */
128 #define GST_RTSP_AUTH_CHECK_MEDIA_FACTORY_ACCESS     "auth.check.media.factory.access"
129 /**
130  * GST_RTSP_AUTH_CHECK_MEDIA_FACTORY_CONSTRUCT:
131  *
132  * Check if media can be constructed from a media factory
133  * A response should be sent on error.
134  */
135 #define GST_RTSP_AUTH_CHECK_MEDIA_FACTORY_CONSTRUCT  "auth.check.media.factory.construct"
136 /**
137  * GST_RTSP_AUTH_CHECK_TRANSPORT_CLIENT_SETTINGS:
138  *
139  * Check if the client can specify TTL, destination and
140  * port pair in multicast. No response is sent when the check returns
141  * %FALSE.
142  */
143 #define GST_RTSP_AUTH_CHECK_TRANSPORT_CLIENT_SETTINGS  "auth.check.transport.client-settings"
144
145
146 /* tokens */
147 /**
148  * GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE:
149  *
150  * G_TYPE_STRING, the role to use when dealing with media factories
151  *
152  * The default #GstRTSPAuth object uses this string in the token to find the
153  * role of the media factory. It will then retrieve the #GstRTSPPermissions of
154  * the media factory and retrieve the role with the same name.
155  */
156 #define GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE      "media.factory.role"
157 /**
158  * GST_RTSP_TOKEN_TRANSPORT_CLIENT_SETTINGS:
159  *
160  * G_TYPE_BOOLEAN, %TRUE if the client can specify TTL, destination and
161  *     port pair in multicast.
162  */
163 #define GST_RTSP_TOKEN_TRANSPORT_CLIENT_SETTINGS   "transport.client-settings"
164
165 /* permissions */
166 /**
167  * GST_RTSP_PERM_MEDIA_FACTORY_ACCESS:
168  *
169  * G_TYPE_BOOLEAN, %TRUE if the media can be accessed, %FALSE will
170  * return a 404 Not Found error when trying to access the media.
171  */
172 #define GST_RTSP_PERM_MEDIA_FACTORY_ACCESS      "media.factory.access"
173 /**
174  * GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT:
175  *
176  * G_TYPE_BOOLEAN, %TRUE if the media can be constructed, %FALSE will
177  * return a 404 Not Found error when trying to access the media.
178  */
179 #define GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT   "media.factory.construct"
180
181 G_END_DECLS
182
183 #endif /* __GST_RTSP_AUTH_H__ */