libpurple/protocols/gg/oauth/oauth.c

Fri, 26 Feb 2021 00:12:08 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Fri, 26 Feb 2021 00:12:08 -0600
changeset 40782
1ea760e56414
parent 40439
e9838d634d5e
permissions
-rw-r--r--

Remove gg_oauth_parameter_t

Use variadic function gg_oauth_generate_request instead.

This is a repost of https://reviews.imfreedom.org/r/516/ but reviewboard wouldn't let me update it directly.

Original patch was from Arkadiy Illarionov with updates from Gary Kramlich.

Testing Done:
Compile only.

Reviewed at https://reviews.imfreedom.org/r/525/

33349
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
1 /* purple
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
2 *
33349
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
3 * Purple is the legal property of its developers, whose names are too numerous
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
5 * source distribution.
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
6 *
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
7 * Code adapted from libgadu (C) 2008 Wojtek Kaniewski <wojtekka@irc.pl>
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
8 * (http://toxygen.net/libgadu/) during Google Summer of Code 2012
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
9 * by Tomek Wasilczyk (http://www.wasilczyk.pl).
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
10 *
33349
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
11 * This program is free software; you can redistribute it and/or modify
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
12 * it under the terms of the GNU General Public License as published by
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
14 * (at your option) any later version.
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
15 *
33349
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
16 * This program is distributed in the hope that it will be useful,
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
19 * GNU General Public License for more details.
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
20 *
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
21 * You should have received a copy of the GNU General Public License
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
22 * along with this program; if not, write to the Free Software
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
24 */
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
25
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
26 #include "oauth.h"
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
27
40439
e9838d634d5e Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents: 40094
diff changeset
28 #include <time.h>
e9838d634d5e Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents: 40094
diff changeset
29
e9838d634d5e Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents: 40094
diff changeset
30 #include <glib.h>
e9838d634d5e Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents: 40094
diff changeset
31
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
32 char *gg_oauth_static_nonce; /* dla unit testów */
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
33 char *gg_oauth_static_timestamp; /* dla unit testów */
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
34
40782
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
35 static char *gg_oauth_generate_request(gboolean header, ...) G_GNUC_NULL_TERMINATED;
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
36
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
37 static void gg_oauth_generate_nonce(char *buf, int len)
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
38 {
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
39 const char charset[] = "0123456789";
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
40
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
41 if (buf == NULL || len < 1)
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
42 return;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
43
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
44 while (len > 1) {
38197
4e604f83f847 Fix coverity 1244226
Gary Kramlich <grim@reaperworld.com>
parents: 35359
diff changeset
45 *buf++ = charset[(unsigned) (((float) sizeof(charset) - 1.0) * g_random_int() / (RAND_MAX + 1.0))];
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
46 len--;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
47 }
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
48
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
49 *buf = 0;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
50 }
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
51
40782
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
52 /* Returns a comma separated header value if header is true,
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
53 * or a url-encoded request otherwise
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
54 */
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
55 static char *
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
56 gg_oauth_generate_request(gboolean header, ...)
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
57 {
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
58 GString *res = g_string_new(NULL);
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
59 va_list params;
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
60 const gchar *key;
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
61 gboolean truncate = FALSE;
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
62
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
63 if(header) {
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
64 res = g_string_append(res, "OAuth ");
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
65 }
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
66
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
67 va_start(params, header);
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
68 while((key = va_arg(params, const gchar *))) {
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
69 const gchar *value = va_arg(params, const gchar *);
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
70 gchar *escaped = g_uri_escape_string(value, NULL, FALSE);
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
71
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
72 if(header) {
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
73 g_string_append_printf(res, "%s=\"%s\",", key, escaped);
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
74 } else {
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
75 g_string_append_printf(res, "%s=%s&", key, escaped);
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
76 }
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
77
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
78 g_free(escaped);
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
79
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
80 truncate = TRUE;
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
81 }
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
82 va_end(params);
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
83
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
84 if(truncate) {
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
85 /* remove trailing separator */
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
86 res = g_string_truncate(res, res->len - 1);
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
87 }
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
88
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
89 return g_string_free(res, FALSE);
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
90 }
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
91
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
92 static gchar *gg_hmac_sha1(const char *key, const char *message)
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
93 {
38305
016572eb1295 gg: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents: 35359
diff changeset
94 GHmac *hmac;
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
95 guchar digest[20];
38305
016572eb1295 gg: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents: 35359
diff changeset
96 gsize digest_len = 20;
34556
087db73b115d Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 33909
diff changeset
97
38305
016572eb1295 gg: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents: 35359
diff changeset
98 hmac = g_hmac_new(G_CHECKSUM_SHA1, (guchar *)key, strlen(key));
016572eb1295 gg: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents: 35359
diff changeset
99 g_hmac_update(hmac, (guchar *)message, -1);
016572eb1295 gg: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents: 35359
diff changeset
100 g_hmac_get_digest(hmac, digest, &digest_len);
016572eb1295 gg: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents: 35359
diff changeset
101 g_hmac_unref(hmac);
35359
d8aa47a78f55 Style: fix all remaining gg warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35030
diff changeset
102
38341
3da74e727e78 Remove purple_base64_encode/decode() wrappers
Mike Ruprecht <cmaiku@gmail.com>
parents: 38311
diff changeset
103 return g_base64_encode(digest, sizeof(digest));
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
104 }
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
105
35359
d8aa47a78f55 Style: fix all remaining gg warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35030
diff changeset
106 static char *
d8aa47a78f55 Style: fix all remaining gg warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35030
diff changeset
107 gg_oauth_generate_signature(const char *method, const char *url,
d8aa47a78f55 Style: fix all remaining gg warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35030
diff changeset
108 const char *request, const char *consumer_secret,
d8aa47a78f55 Style: fix all remaining gg warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35030
diff changeset
109 const char *token_secret)
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
110 {
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
111 char *text, *key, *res;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
112 gchar *url_e, *request_e, *consumer_secret_e, *token_secret_e;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
113
33346
3b4cbb0e10d6 Gadu-Gadu: public directory search with gg10.5 api
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
diff changeset
114 url_e = g_uri_escape_string(url, "?", FALSE);
3b4cbb0e10d6 Gadu-Gadu: public directory search with gg10.5 api
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
diff changeset
115 g_strdelimit(url_e, "?", '\0');
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
116 request_e = g_uri_escape_string(request, NULL, FALSE);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
117 text = g_strdup_printf("%s&%s&%s", method, url_e, request_e);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
118 g_free(url_e);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
119 g_free(request_e);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
120
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
121 consumer_secret_e = g_uri_escape_string(consumer_secret, NULL, FALSE);
33343
09f740724036 Gadu-Gadu: extended OAuth support, initial support for gg10.5 public directory
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33329
diff changeset
122 token_secret_e = token_secret ? g_uri_escape_string(token_secret, NULL, FALSE) : NULL;
09f740724036 Gadu-Gadu: extended OAuth support, initial support for gg10.5 public directory
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33329
diff changeset
123 key = g_strdup_printf("%s&%s", consumer_secret_e, token_secret ? token_secret_e : "");
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
124 g_free(consumer_secret_e);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
125 g_free(token_secret_e);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
126
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
127 res = gg_hmac_sha1(key, text);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
128
39916
6a79856cb8f5 Fix inconsistent malloc/free calls.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38341
diff changeset
129 g_free(key);
6a79856cb8f5 Fix inconsistent malloc/free calls.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38341
diff changeset
130 g_free(text);
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
131
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
132 return res;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
133 }
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
134
35359
d8aa47a78f55 Style: fix all remaining gg warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35030
diff changeset
135 char *
d8aa47a78f55 Style: fix all remaining gg warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35030
diff changeset
136 gg_oauth_generate_header(const char *method, const char *url,
d8aa47a78f55 Style: fix all remaining gg warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35030
diff changeset
137 const char *consumer_key, const char *consumer_secret,
d8aa47a78f55 Style: fix all remaining gg warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35030
diff changeset
138 const char *token, const char *token_secret)
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
139 {
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
140 char *request, *signature, *res;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
141 char nonce[80], timestamp[16];
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
142
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
143 if (gg_oauth_static_nonce == NULL)
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
144 gg_oauth_generate_nonce(nonce, sizeof(nonce));
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
145 else {
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
146 strncpy(nonce, gg_oauth_static_nonce, sizeof(nonce) - 1);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
147 nonce[sizeof(nonce) - 1] = 0;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
148 }
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
149
40094
8e6d91e4dd8f Use g_(v)snprintf so we need less wrappers.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40021
diff changeset
150 if (gg_oauth_static_timestamp == NULL) {
8e6d91e4dd8f Use g_(v)snprintf so we need less wrappers.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40021
diff changeset
151 g_snprintf(timestamp, sizeof(timestamp), "%ld", time(NULL));
8e6d91e4dd8f Use g_(v)snprintf so we need less wrappers.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40021
diff changeset
152 } else {
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
153 strncpy(timestamp, gg_oauth_static_timestamp, sizeof(timestamp) - 1);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
154 timestamp[sizeof(timestamp) - 1] = 0;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
155 }
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
156
40782
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
157 request = gg_oauth_generate_request(FALSE,
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
158 "oauth_consumer_key", consumer_key,
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
159 "oauth_nonce", nonce,
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
160 "oauth_signature_method", "HMAC-SHA1",
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
161 "oauth_timestamp", timestamp,
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
162 "oauth_token", token,
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
163 "oauth_version", "1.0",
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
164 NULL);
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
165
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
166 signature = gg_oauth_generate_signature(method, url, request, consumer_secret, token_secret);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
167
40021
6b1b05adda03 Use correct memory functions for GG oauth.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39916
diff changeset
168 g_free(request);
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
169
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
170 if (signature == NULL)
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
171 return NULL;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
172
40782
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
173 res = gg_oauth_generate_request(TRUE,
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
174 "oauth_version", "1.0",
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
175 "oauth_nonce", nonce,
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
176 "oauth_timestamp", timestamp,
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
177 "oauth_consumer_key", consumer_key,
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
178 "oauth_token", token,
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
179 "oauth_signature_method", "HMAC-SHA1",
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
180 "oauth_signature", signature,
1ea760e56414 Remove gg_oauth_parameter_t
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
181 NULL);
40021
6b1b05adda03 Use correct memory functions for GG oauth.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39916
diff changeset
182 g_free(signature);
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
183
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
184 return res;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
185 }

mercurial