| 24 */ |
24 */ |
| 25 |
25 |
| 26 #include "oauth.h" |
26 #include "oauth.h" |
| 27 |
27 |
| 28 #include "oauth-parameter.h" |
28 #include "oauth-parameter.h" |
| 29 #include <cipher.h> |
29 #include "ciphers/hmac.h" |
| |
30 #include "ciphers/sha1.h" |
| 30 |
31 |
| 31 char *gg_oauth_static_nonce; /* dla unit testów */ |
32 char *gg_oauth_static_nonce; /* dla unit testów */ |
| 32 char *gg_oauth_static_timestamp; /* dla unit testów */ |
33 char *gg_oauth_static_timestamp; /* dla unit testów */ |
| 33 |
34 |
| 34 static void gg_oauth_generate_nonce(char *buf, int len) |
35 static void gg_oauth_generate_nonce(char *buf, int len) |
| 46 *buf = 0; |
47 *buf = 0; |
| 47 } |
48 } |
| 48 |
49 |
| 49 static gchar *gg_hmac_sha1(const char *key, const char *message) |
50 static gchar *gg_hmac_sha1(const char *key, const char *message) |
| 50 { |
51 { |
| 51 PurpleCipherContext *context; |
52 PurpleCipher *cipher, *hash; |
| 52 guchar digest[20]; |
53 guchar digest[20]; |
| 53 |
54 |
| 54 context = purple_cipher_context_new_by_name("hmac", NULL); |
55 hash = purple_sha1_cipher_new(); |
| 55 purple_cipher_context_set_option(context, "hash", "sha1"); |
56 cipher = purple_hmac_cipher_new(hash); |
| 56 purple_cipher_context_set_key(context, (guchar *)key, strlen(key)); |
57 |
| 57 purple_cipher_context_append(context, (guchar *)message, strlen(message)); |
58 purple_cipher_set_key(cipher, (guchar *)key, strlen(key)); |
| 58 purple_cipher_context_digest(context, digest, sizeof(digest)); |
59 purple_cipher_append(cipher, (guchar *)message, strlen(message)); |
| 59 purple_cipher_context_destroy(context); |
60 purple_cipher_digest(cipher, digest, sizeof(digest)); |
| |
61 |
| |
62 g_object_unref(cipher); |
| |
63 g_object_unref(hash); |
| 60 |
64 |
| 61 return purple_base64_encode(digest, sizeof(digest)); |
65 return purple_base64_encode(digest, sizeof(digest)); |
| 62 } |
66 } |
| 63 |
67 |
| 64 static char *gg_oauth_generate_signature(const char *method, const char *url, const char *request, const char *consumer_secret, const char *token_secret) |
68 static char *gg_oauth_generate_signature(const char *method, const char *url, const char *request, const char *consumer_secret, const char *token_secret) |