- Timestamp:
- 2011-12-21T19:03:56Z (13 years ago)
- Branches:
- master
- Children:
- e306fbf
- Parents:
- 0dd6570
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/oauth.c
r0dd6570 r31db8165 38 38 const char *params, struct oauth_info *oi ) 39 39 { 40 sha1_state_t sha1;41 40 uint8_t hash[sha1_hash_size]; 42 uint8_t key[HMAC_BLOCK_SIZE+1]; 41 GString *payload = g_string_new( "" ); 42 char *key; 43 43 char *s; 44 int i; 45 46 /* Create K. If our current key is >64 chars we have to hash it, 47 otherwise just pad. */ 48 memset( key, 0, HMAC_BLOCK_SIZE ); 49 i = strlen( oi->sp->consumer_secret ) + 1 + ( oi->token_secret ? strlen( oi->token_secret ) : 0 ); 50 if( i > HMAC_BLOCK_SIZE ) 51 { 52 sha1_init( &sha1 ); 53 sha1_append( &sha1, (uint8_t*) oi->sp->consumer_secret, strlen( oi->sp->consumer_secret ) ); 54 sha1_append( &sha1, (uint8_t*) "&", 1 ); 55 if( oi->token_secret ) 56 sha1_append( &sha1, (uint8_t*) oi->token_secret, strlen( oi->token_secret ) ); 57 sha1_finish( &sha1, key ); 58 } 59 else 60 { 61 g_snprintf( (gchar*) key, HMAC_BLOCK_SIZE + 1, "%s&%s", 62 oi->sp->consumer_secret, oi->token_secret ? oi->token_secret : "" ); 63 } 64 65 /* Inner part: H(K XOR 0x36, text) */ 66 sha1_init( &sha1 ); 67 68 for( i = 0; i < HMAC_BLOCK_SIZE; i ++ ) 69 key[i] ^= 0x36; 70 sha1_append( &sha1, key, HMAC_BLOCK_SIZE ); 71 72 /* OAuth: text = method&url¶ms, all http_encoded. */ 73 sha1_append( &sha1, (const uint8_t*) method, strlen( method ) ); 74 sha1_append( &sha1, (const uint8_t*) "&", 1 ); 44 45 key = g_strdup_printf( "%s&%s", oi->sp->consumer_secret, oi->token_secret ? oi->token_secret : "" ); 46 47 g_string_append_printf( payload, "%s&", method ); 75 48 76 49 s = g_new0( char, strlen( url ) * 3 + 1 ); 77 50 strcpy( s, url ); 78 51 http_encode( s ); 79 sha1_append( &sha1, (const uint8_t*) s, strlen( s ) ); 80 sha1_append( &sha1, (const uint8_t*) "&", 1 ); 52 g_string_append_printf( payload, "%s&", s ); 81 53 g_free( s ); 82 54 … … 84 56 strcpy( s, params ); 85 57 http_encode( s ); 86 sha1_append( &sha1, (const uint8_t*) s, strlen( s ) ); 87 g_free( s ); 88 89 sha1_finish( &sha1, hash ); 90 91 /* Final result: H(K XOR 0x5C, inner stuff) */ 92 sha1_init( &sha1 ); 93 for( i = 0; i < HMAC_BLOCK_SIZE; i ++ ) 94 key[i] ^= 0x36 ^ 0x5c; 95 sha1_append( &sha1, key, HMAC_BLOCK_SIZE ); 96 sha1_append( &sha1, hash, sha1_hash_size ); 97 sha1_finish( &sha1, hash ); 58 g_string_append( payload, s ); 59 g_free( s ); 60 61 sha1_hmac( key, 0, payload->str, 0, hash ); 62 63 g_free( key ); 64 g_string_free( payload, TRUE ); 98 65 99 66 /* base64_encode + HTTP escape it (both consumers
Note: See TracChangeset
for help on using the changeset viewer.