author | Michael Krelin <hacker@klever.net> | 2007-01-12 12:58:25 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-01-12 12:58:25 (UTC) |
commit | e79687a3d9a1631613de02d8e12bae36302b46ab (patch) (unidiff) | |
tree | 4238c0d8d61f5e70ed1e98debb01315babb21686 | |
parent | 4cc2e58186e8cd9b96a3573c92f6664064cf11fe (diff) | |
download | libopkele-e79687a3d9a1631613de02d8e12bae36302b46ab.zip libopkele-e79687a3d9a1631613de02d8e12bae36302b46ab.tar.gz libopkele-e79687a3d9a1631613de02d8e12bae36302b46ab.tar.bz2 |
eliminated mimetic dependency and made use of openssl base64 encoder instead
-rw-r--r-- | configure.ac | 11 | ||||
-rw-r--r-- | include/opkele/util.h | 5 | ||||
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/consumer.cc | 16 | ||||
-rw-r--r-- | lib/params.cc | 7 | ||||
-rw-r--r-- | lib/secret.cc | 22 | ||||
-rw-r--r-- | lib/server.cc | 6 | ||||
-rw-r--r-- | lib/util.cc | 67 | ||||
-rw-r--r-- | libopkele.pc.in | 2 |
9 files changed, 71 insertions, 67 deletions
diff --git a/configure.ac b/configure.ac index af7a301..2ce5f71 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -32,35 +32,24 @@ if test "${WANT_KONFORKA}" = "yes" ; then | |||
32 | AC_MSG_RESULT([yes]) | 32 | AC_MSG_RESULT([yes]) |
33 | AC_SUBST([KONFORKA_CFLAGS]) | 33 | AC_SUBST([KONFORKA_CFLAGS]) |
34 | AC_SUBST([KONFORKA_LIBS]) | 34 | AC_SUBST([KONFORKA_LIBS]) |
35 | AC_DEFINE([HAVE_KONFORKA],,[defined in presence of konforka library]) | 35 | AC_DEFINE([HAVE_KONFORKA],,[defined in presence of konforka library]) |
36 | AC_DEFINE([OPKELE_HAVE_KONFORKA],,[defined in presence of konforka library]) | 36 | AC_DEFINE([OPKELE_HAVE_KONFORKA],,[defined in presence of konforka library]) |
37 | AC_SUBST([KONFORKA_KONFORKA],[konforka]) | 37 | AC_SUBST([KONFORKA_KONFORKA],[konforka]) |
38 | ],[ | 38 | ],[ |
39 | AC_MSG_RESULT([no]) | 39 | AC_MSG_RESULT([no]) |
40 | ] | 40 | ] |
41 | ) | 41 | ) |
42 | fi | 42 | fi |
43 | 43 | ||
44 | AC_LANG_PUSH([C++]) | ||
45 | AC_CHECK_LIB([mimetic],[main],[ | ||
46 | MIMETIC_LIBS=-lmimetic | ||
47 | AC_SUBST([MIMETIC_CFLAGS]) | ||
48 | AC_SUBST([MIMETIC_LIBS]) | ||
49 | ],[ | ||
50 | AC_MSG_ERROR([no mimetic library found. get one from http://codesink.org/mimetic_mime_library.html]) | ||
51 | ] | ||
52 | ) | ||
53 | AC_LANG_POP([C++]) | ||
54 | |||
55 | WANT_DOXYGEN="yes" | 44 | WANT_DOXYGEN="yes" |
56 | AC_ARG_ENABLE([doxygen], | 45 | AC_ARG_ENABLE([doxygen], |
57 | AC_HELP_STRING([--disable-doxygen],[do not generate documentation]), | 46 | AC_HELP_STRING([--disable-doxygen],[do not generate documentation]), |
58 | [ | 47 | [ |
59 | test "${enableval}" = "no" && WANT_DOXYGEN="no" | 48 | test "${enableval}" = "no" && WANT_DOXYGEN="no" |
60 | ] | 49 | ] |
61 | ) | 50 | ) |
62 | if test "${WANT_DOXYGEN}" = "yes" ; then | 51 | if test "${WANT_DOXYGEN}" = "yes" ; then |
63 | AC_WITH_DOXYGEN | 52 | AC_WITH_DOXYGEN |
64 | AC_WITH_DOT | 53 | AC_WITH_DOT |
65 | else | 54 | else |
66 | AM_CONDITIONAL([HAVE_DOXYGEN],[false]) | 55 | AM_CONDITIONAL([HAVE_DOXYGEN],[false]) |
diff --git a/include/opkele/util.h b/include/opkele/util.h index 5372498..80d8b03 100644 --- a/include/opkele/util.h +++ b/include/opkele/util.h | |||
@@ -1,22 +1,24 @@ | |||
1 | #ifndef __OPKELE_UTIL_H | 1 | #ifndef __OPKELE_UTIL_H |
2 | #define __OPKELE_UTIL_H | 2 | #define __OPKELE_UTIL_H |
3 | 3 | ||
4 | #include <time.h> | 4 | #include <time.h> |
5 | #include <string> | 5 | #include <string> |
6 | #include <vector> | ||
6 | #include <openssl/bn.h> | 7 | #include <openssl/bn.h> |
7 | #include <openssl/dh.h> | 8 | #include <openssl/dh.h> |
8 | 9 | ||
9 | namespace opkele { | 10 | namespace opkele { |
10 | using std::string; | 11 | using std::string; |
12 | using std::vector; | ||
11 | 13 | ||
12 | namespace util { | 14 | namespace util { |
13 | 15 | ||
14 | class bignum_t { | 16 | class bignum_t { |
15 | public: | 17 | public: |
16 | BIGNUM *_bn; | 18 | BIGNUM *_bn; |
17 | 19 | ||
18 | bignum_t() : _bn(0) { } | 20 | bignum_t() : _bn(0) { } |
19 | bignum_t(BIGNUM *bn) : _bn(bn) { } | 21 | bignum_t(BIGNUM *bn) : _bn(bn) { } |
20 | ~bignum_t() throw() { if(_bn) BN_free(_bn); } | 22 | ~bignum_t() throw() { if(_bn) BN_free(_bn); } |
21 | 23 | ||
22 | bignum_t& operator=(BIGNUM *bn) { if(_bn) BN_free(_bn); _bn = bn; return *this; } | 24 | bignum_t& operator=(BIGNUM *bn) { if(_bn) BN_free(_bn); _bn = bn; return *this; } |
@@ -43,17 +45,20 @@ namespace opkele { | |||
43 | 45 | ||
44 | BIGNUM *base64_to_bignum(const string& b64); | 46 | BIGNUM *base64_to_bignum(const string& b64); |
45 | BIGNUM *dec_to_bignum(const string& dec); | 47 | BIGNUM *dec_to_bignum(const string& dec); |
46 | string bignum_to_base64(const BIGNUM *bn); | 48 | string bignum_to_base64(const BIGNUM *bn); |
47 | 49 | ||
48 | string time_to_w3c(time_t t); | 50 | string time_to_w3c(time_t t); |
49 | time_t w3c_to_time(const string& w); | 51 | time_t w3c_to_time(const string& w); |
50 | 52 | ||
51 | string url_encode(const string& str); | 53 | string url_encode(const string& str); |
52 | 54 | ||
53 | string long_to_string(long l); | 55 | string long_to_string(long l); |
54 | long string_to_long(const string& s); | 56 | long string_to_long(const string& s); |
57 | |||
58 | string encode_base64(const void *data,size_t length); | ||
59 | void decode_base64(const string& data,vector<unsigned char>& rv); | ||
55 | } | 60 | } |
56 | 61 | ||
57 | } | 62 | } |
58 | 63 | ||
59 | #endif /* __OPKELE_UTIL_H */ | 64 | #endif /* __OPKELE_UTIL_H */ |
diff --git a/lib/Makefile.am b/lib/Makefile.am index bdadd44..ec63c25 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
@@ -1,25 +1,23 @@ | |||
1 | lib_LTLIBRARIES = libopkele.la | 1 | lib_LTLIBRARIES = libopkele.la |
2 | 2 | ||
3 | INCLUDES = \ | 3 | INCLUDES = \ |
4 | -I${top_srcdir}/include/ \ | 4 | -I${top_srcdir}/include/ \ |
5 | ${KONFORKA_CFLAGS} \ | 5 | ${KONFORKA_CFLAGS} \ |
6 | ${OPENSSL_CFLAGS} \ | 6 | ${OPENSSL_CFLAGS} \ |
7 | ${MIMETIC_CFLAGS} \ | ||
8 | ${LIBCURL_CPPFLAGS} \ | 7 | ${LIBCURL_CPPFLAGS} \ |
9 | ${PCREPP_CFLAGS} | 8 | ${PCREPP_CFLAGS} |
10 | LDADD = \ | 9 | LDADD = \ |
11 | ${LIBCURL} \ | 10 | ${LIBCURL} \ |
12 | ${PCREPP_LIBS} \ | 11 | ${PCREPP_LIBS} \ |
13 | ${MIMETIC_LIBS} \ | ||
14 | ${OPENSSL_LIBS} \ | 12 | ${OPENSSL_LIBS} \ |
15 | ${KONFORKA_LIBS} | 13 | ${KONFORKA_LIBS} |
16 | 14 | ||
17 | libopkele_la_SOURCES = \ | 15 | libopkele_la_SOURCES = \ |
18 | params.cc \ | 16 | params.cc \ |
19 | util.cc \ | 17 | util.cc \ |
20 | server.cc \ | 18 | server.cc \ |
21 | secret.cc \ | 19 | secret.cc \ |
22 | data.cc \ | 20 | data.cc \ |
23 | consumer.cc \ | 21 | consumer.cc \ |
24 | exception.cc \ | 22 | exception.cc \ |
25 | extension.cc \ | 23 | extension.cc \ |
diff --git a/lib/consumer.cc b/lib/consumer.cc index b215aa8..331b1e9 100644 --- a/lib/consumer.cc +++ b/lib/consumer.cc | |||
@@ -1,34 +1,25 @@ | |||
1 | #include <algorithm> | 1 | #include <algorithm> |
2 | #include <cassert> | ||
2 | #include <opkele/util.h> | 3 | #include <opkele/util.h> |
3 | #include <opkele/exception.h> | 4 | #include <opkele/exception.h> |
4 | #include <opkele/data.h> | 5 | #include <opkele/data.h> |
5 | #include <opkele/consumer.h> | 6 | #include <opkele/consumer.h> |
6 | #include <openssl/sha.h> | 7 | #include <openssl/sha.h> |
7 | #include <openssl/hmac.h> | 8 | #include <openssl/hmac.h> |
8 | #include <mimetic/mimetic.h> | ||
9 | #include <curl/curl.h> | 9 | #include <curl/curl.h> |
10 | #include <pcre++.h> | 10 | #include <pcre++.h> |
11 | 11 | ||
12 | #include <iostream> | 12 | #include <iostream> |
13 | 13 | ||
14 | /* silly mimetic */ | ||
15 | #undef PACKAGE | ||
16 | #undef PACKAGE_BUGREPORT | ||
17 | #undef PACKAGE_NAME | ||
18 | #undef PACKAGE_STRING | ||
19 | #undef PACKAGE_TARNAME | ||
20 | #undef PACKAGE_VERSION | ||
21 | #undef VERSION | ||
22 | |||
23 | #include "config.h" | 14 | #include "config.h" |
24 | 15 | ||
25 | namespace opkele { | 16 | namespace opkele { |
26 | using namespace std; | 17 | using namespace std; |
27 | 18 | ||
28 | class curl_t { | 19 | class curl_t { |
29 | public: | 20 | public: |
30 | CURL *_c; | 21 | CURL *_c; |
31 | 22 | ||
32 | curl_t() : _c(0) { } | 23 | curl_t() : _c(0) { } |
33 | curl_t(CURL *c) : _c(c) { } | 24 | curl_t(CURL *c) : _c(c) { } |
34 | ~curl_t() throw() { if(_c) curl_easy_cleanup(_c); } | 25 | ~curl_t() throw() { if(_c) curl_easy_cleanup(_c); } |
@@ -157,29 +148,26 @@ namespace opkele { | |||
157 | return p.append_query(server); | 148 | return p.append_query(server); |
158 | } | 149 | } |
159 | 150 | ||
160 | void consumer_t::id_res(const params_t& pin,const string& identity,extension_t *ext) { | 151 | void consumer_t::id_res(const params_t& pin,const string& identity,extension_t *ext) { |
161 | if(pin.has_param("openid.user_setup_url")) | 152 | if(pin.has_param("openid.user_setup_url")) |
162 | throw id_res_setup(OPKELE_CP_ "assertion failed, setup url provided",pin.get_param("openid.user_setup_url")); | 153 | throw id_res_setup(OPKELE_CP_ "assertion failed, setup url provided",pin.get_param("openid.user_setup_url")); |
163 | string server,delegate; | 154 | string server,delegate; |
164 | retrieve_links(identity.empty()?pin.get_param("openid.identity"):canonicalize(identity),server,delegate); | 155 | retrieve_links(identity.empty()?pin.get_param("openid.identity"):canonicalize(identity),server,delegate); |
165 | params_t ps; | 156 | params_t ps; |
166 | try { | 157 | try { |
167 | assoc_t assoc = retrieve_assoc(server,pin.get_param("openid.assoc_handle")); | 158 | assoc_t assoc = retrieve_assoc(server,pin.get_param("openid.assoc_handle")); |
168 | const string& sigenc = pin.get_param("openid.sig"); | 159 | const string& sigenc = pin.get_param("openid.sig"); |
169 | mimetic::Base64::Decoder b; | ||
170 | vector<unsigned char> sig; | 160 | vector<unsigned char> sig; |
171 | mimetic::decode( | 161 | util::decode_base64(sigenc,sig); |
172 | sigenc.begin(),sigenc.end(), b, | ||
173 | back_insert_iterator<vector<unsigned char> >(sig) ); | ||
174 | const string& slist = pin.get_param("openid.signed"); | 162 | const string& slist = pin.get_param("openid.signed"); |
175 | string kv; | 163 | string kv; |
176 | string::size_type p = 0; | 164 | string::size_type p = 0; |
177 | while(true) { | 165 | while(true) { |
178 | string::size_type co = slist.find(',',p); | 166 | string::size_type co = slist.find(',',p); |
179 | string f = (co==string::npos)?slist.substr(p):slist.substr(p,co-p); | 167 | string f = (co==string::npos)?slist.substr(p):slist.substr(p,co-p); |
180 | kv += f; | 168 | kv += f; |
181 | kv += ':'; | 169 | kv += ':'; |
182 | f.insert(0,"openid."); | 170 | f.insert(0,"openid."); |
183 | kv += pin.get_param(f); | 171 | kv += pin.get_param(f); |
184 | kv += '\n'; | 172 | kv += '\n'; |
185 | if(ext) ps[f.substr(sizeof("openid.")-1)] = pin.get_param(f); | 173 | if(ext) ps[f.substr(sizeof("openid.")-1)] = pin.get_param(f); |
diff --git a/lib/params.cc b/lib/params.cc index 14f1a53..03867d5 100644 --- a/lib/params.cc +++ b/lib/params.cc | |||
@@ -1,18 +1,17 @@ | |||
1 | #include <opkele/types.h> | 1 | #include <opkele/types.h> |
2 | #include <opkele/exception.h> | 2 | #include <opkele/exception.h> |
3 | #include <opkele/util.h> | 3 | #include <opkele/util.h> |
4 | #include <openssl/sha.h> | 4 | #include <openssl/sha.h> |
5 | #include <openssl/hmac.h> | 5 | #include <openssl/hmac.h> |
6 | #include <mimetic/mimetic.h> | ||
7 | 6 | ||
8 | namespace opkele { | 7 | namespace opkele { |
9 | using namespace std; | 8 | using namespace std; |
10 | 9 | ||
11 | bool params_t::has_param(const string& n) const { | 10 | bool params_t::has_param(const string& n) const { |
12 | return find(n)!=end(); | 11 | return find(n)!=end(); |
13 | } | 12 | } |
14 | const string& params_t::get_param(const string& n) const { | 13 | const string& params_t::get_param(const string& n) const { |
15 | const_iterator i = find(n); | 14 | const_iterator i = find(n); |
16 | if(i==end()) | 15 | if(i==end()) |
17 | throw failed_lookup(OPKELE_CP_ n+": no such parameter"); | 16 | throw failed_lookup(OPKELE_CP_ n+": no such parameter"); |
18 | return i->second; | 17 | return i->second; |
@@ -51,29 +50,25 @@ namespace opkele { | |||
51 | kv += get_param(f); | 50 | kv += get_param(f); |
52 | kv += '\n'; | 51 | kv += '\n'; |
53 | if(co==string::npos) | 52 | if(co==string::npos) |
54 | break; | 53 | break; |
55 | p = co+1; | 54 | p = co+1; |
56 | } | 55 | } |
57 | unsigned int md_len = 0; | 56 | unsigned int md_len = 0; |
58 | unsigned char *md = HMAC( | 57 | unsigned char *md = HMAC( |
59 | EVP_sha1(), | 58 | EVP_sha1(), |
60 | &(secret.front()),secret.size(), | 59 | &(secret.front()),secret.size(), |
61 | (const unsigned char *)kv.data(),kv.length(), | 60 | (const unsigned char *)kv.data(),kv.length(), |
62 | 0,&md_len); | 61 | 0,&md_len); |
63 | mimetic::Base64::Encoder b(0); | 62 | sig = util::encode_base64(md,md_len); |
64 | sig.erase(); | ||
65 | mimetic::encode( | ||
66 | md,md+md_len, b, | ||
67 | back_insert_iterator<string>(sig) ); | ||
68 | } | 63 | } |
69 | 64 | ||
70 | string params_t::append_query(const string& url,const char *prefix) const { | 65 | string params_t::append_query(const string& url,const char *prefix) const { |
71 | string rv = url; | 66 | string rv = url; |
72 | bool p = true; | 67 | bool p = true; |
73 | if(rv.find('?')==string::npos) { | 68 | if(rv.find('?')==string::npos) { |
74 | rv += '?'; | 69 | rv += '?'; |
75 | p = false; | 70 | p = false; |
76 | } | 71 | } |
77 | for(const_iterator i=begin();i!=end();++i) { | 72 | for(const_iterator i=begin();i!=end();++i) { |
78 | if(p) | 73 | if(p) |
79 | rv += '&'; | 74 | rv += '&'; |
diff --git a/lib/secret.cc b/lib/secret.cc index ae8a3c5..632a2ca 100644 --- a/lib/secret.cc +++ b/lib/secret.cc | |||
@@ -1,61 +1,49 @@ | |||
1 | #include <algorithm> | 1 | #include <algorithm> |
2 | #include <functional> | 2 | #include <functional> |
3 | #include <opkele/types.h> | 3 | #include <opkele/types.h> |
4 | #include <opkele/exception.h> | 4 | #include <opkele/exception.h> |
5 | #include <mimetic/mimetic.h> | 5 | #include <opkele/util.h> |
6 | 6 | ||
7 | namespace opkele { | 7 | namespace opkele { |
8 | using namespace std; | 8 | using namespace std; |
9 | 9 | ||
10 | template<class __a1,class __a2,class __r> | 10 | template<class __a1,class __a2,class __r> |
11 | struct bitwise_xor : public binary_function<__a1,__a2,__r> { | 11 | struct bitwise_xor : public binary_function<__a1,__a2,__r> { |
12 | __r operator() (const __a1& a1,const __a2& a2) const { | 12 | __r operator() (const __a1& a1,const __a2& a2) const { |
13 | return a1^a2; | 13 | return a1^a2; |
14 | } | 14 | } |
15 | }; | 15 | }; |
16 | 16 | ||
17 | void secret_t::enxor_to_base64(const unsigned char *key_sha1,string& rv) const { | 17 | void secret_t::enxor_to_base64(const unsigned char *key_sha1,string& rv) const { |
18 | if(size()!=20) | 18 | if(size()!=20) |
19 | throw bad_input(OPKELE_CP_ "wrong secret size"); | 19 | throw bad_input(OPKELE_CP_ "wrong secret size"); |
20 | vector<unsigned char> tmp; | 20 | vector<unsigned char> tmp; |
21 | transform( | 21 | transform( |
22 | begin(), end(), | 22 | begin(), end(), |
23 | key_sha1, | 23 | key_sha1, |
24 | back_insert_iterator<vector<unsigned char> >(tmp), | 24 | back_insert_iterator<vector<unsigned char> >(tmp), |
25 | bitwise_xor<unsigned char,unsigned char,unsigned char>() ); | 25 | bitwise_xor<unsigned char,unsigned char,unsigned char>() ); |
26 | mimetic::Base64::Encoder b(0); | 26 | rv = util::encode_base64(&(tmp.front()),tmp.size()); |
27 | mimetic::encode( | ||
28 | tmp.begin(),tmp.end(), b, | ||
29 | back_insert_iterator<string>(rv) ); | ||
30 | } | 27 | } |
31 | 28 | ||
32 | void secret_t::enxor_from_base64(const unsigned char *key_sha1,const string& b64) { | 29 | void secret_t::enxor_from_base64(const unsigned char *key_sha1,const string& b64) { |
33 | mimetic::Base64::Decoder b; | ||
34 | clear(); | 30 | clear(); |
35 | mimetic::decode( | 31 | util::decode_base64(b64,*this); |
36 | b64.begin(),b64.end(), b, | ||
37 | back_insert_iterator<secret_t>(*this) ); | ||
38 | transform( | 32 | transform( |
39 | begin(), end(), | 33 | begin(), end(), |
40 | key_sha1, | 34 | key_sha1, |
41 | begin(), | 35 | begin(), |
42 | bitwise_xor<unsigned char,unsigned char,unsigned char>() ); | 36 | bitwise_xor<unsigned char,unsigned char,unsigned char>() ); |
43 | } | 37 | } |
44 | 38 | ||
45 | void secret_t::to_base64(string& rv) const { | 39 | void secret_t::to_base64(string& rv) const { |
46 | if(size()!=20) | 40 | if(size()!=20) |
47 | throw bad_input(OPKELE_CP_ "wrong secret size"); | 41 | throw bad_input(OPKELE_CP_ "wrong secret size"); |
48 | mimetic::Base64::Encoder b(0); | 42 | rv = util::encode_base64(&(front()),size()); |
49 | mimetic::encode( | ||
50 | begin(),end(), b, | ||
51 | back_insert_iterator<string>(rv) ); | ||
52 | } | 43 | } |
53 | 44 | ||
54 | void secret_t::from_base64(const string& b64) { | 45 | void secret_t::from_base64(const string& b64) { |
55 | mimetic::Base64::Decoder b; | 46 | util::decode_base64(b64,*this); |
56 | mimetic::decode( | ||
57 | b64.begin(),b64.end(), b, | ||
58 | back_insert_iterator<secret_t>(*this) ); | ||
59 | } | 47 | } |
60 | 48 | ||
61 | } | 49 | } |
diff --git a/lib/server.cc b/lib/server.cc index 8c29abb..e81d4b6 100644 --- a/lib/server.cc +++ b/lib/server.cc | |||
@@ -1,16 +1,15 @@ | |||
1 | #include <vector> | 1 | #include <vector> |
2 | #include <openssl/sha.h> | 2 | #include <openssl/sha.h> |
3 | #include <openssl/hmac.h> | 3 | #include <openssl/hmac.h> |
4 | #include <mimetic/mimetic.h> | ||
5 | #include <opkele/util.h> | 4 | #include <opkele/util.h> |
6 | #include <opkele/exception.h> | 5 | #include <opkele/exception.h> |
7 | #include <opkele/server.h> | 6 | #include <opkele/server.h> |
8 | #include <opkele/data.h> | 7 | #include <opkele/data.h> |
9 | 8 | ||
10 | namespace opkele { | 9 | namespace opkele { |
11 | using namespace std; | 10 | using namespace std; |
12 | 11 | ||
13 | void server_t::associate(const params_t& pin,params_t& pout) { | 12 | void server_t::associate(const params_t& pin,params_t& pout) { |
14 | util::dh_t dh; | 13 | util::dh_t dh; |
15 | util::bignum_t c_pub; | 14 | util::bignum_t c_pub; |
16 | unsigned char key_sha1[SHA_DIGEST_LENGTH]; | 15 | unsigned char key_sha1[SHA_DIGEST_LENGTH]; |
@@ -104,29 +103,26 @@ namespace opkele { | |||
104 | /* TODO: eventually remove deprecated stuff */ | 103 | /* TODO: eventually remove deprecated stuff */ |
105 | time_t now = time(0); | 104 | time_t now = time(0); |
106 | pout["issued"] = util::time_to_w3c(now); | 105 | pout["issued"] = util::time_to_w3c(now); |
107 | pout["valid_to"] = util::time_to_w3c(now+120); | 106 | pout["valid_to"] = util::time_to_w3c(now+120); |
108 | pout["exipres_in"] = "120"; | 107 | pout["exipres_in"] = "120"; |
109 | pout["signed"]="mode,identity,return_to"; | 108 | pout["signed"]="mode,identity,return_to"; |
110 | if(ext) ext->checkid_hook(pin,pout); | 109 | if(ext) ext->checkid_hook(pin,pout); |
111 | pout.sign(assoc->secret(),pout["sig"],pout["signed"]); | 110 | pout.sign(assoc->secret(),pout["sig"],pout["signed"]); |
112 | } | 111 | } |
113 | 112 | ||
114 | void server_t::check_authentication(const params_t& pin,params_t& pout) { | 113 | void server_t::check_authentication(const params_t& pin,params_t& pout) { |
115 | vector<unsigned char> sig; | 114 | vector<unsigned char> sig; |
116 | mimetic::Base64::Decoder b; | ||
117 | const string& sigenc = pin.get_param("openid.sig"); | 115 | const string& sigenc = pin.get_param("openid.sig"); |
118 | mimetic::decode( | 116 | util::decode_base64(sigenc,sig); |
119 | sigenc.begin(),sigenc.end(), b, | ||
120 | back_insert_iterator<vector<unsigned char> >(sig)); | ||
121 | assoc_t assoc; | 117 | assoc_t assoc; |
122 | try { | 118 | try { |
123 | assoc = retrieve_assoc(pin.get_param("openid.assoc_handle")); | 119 | assoc = retrieve_assoc(pin.get_param("openid.assoc_handle")); |
124 | }catch(failed_lookup& fl) { | 120 | }catch(failed_lookup& fl) { |
125 | throw failed_assertion(OPKELE_CP_ "invalid handle or handle not specified"); | 121 | throw failed_assertion(OPKELE_CP_ "invalid handle or handle not specified"); |
126 | } | 122 | } |
127 | if(!assoc->stateless()) | 123 | if(!assoc->stateless()) |
128 | throw stateful_handle(OPKELE_CP_ "will not do check_authentication on a stateful handle"); | 124 | throw stateful_handle(OPKELE_CP_ "will not do check_authentication on a stateful handle"); |
129 | const string& slist = pin.get_param("openid.signed"); | 125 | const string& slist = pin.get_param("openid.signed"); |
130 | string kv; | 126 | string kv; |
131 | string::size_type p =0; | 127 | string::size_type p =0; |
132 | while(true) { | 128 | while(true) { |
diff --git a/lib/util.cc b/lib/util.cc index d78b5e0..d9abca7 100644 --- a/lib/util.cc +++ b/lib/util.cc | |||
@@ -1,58 +1,103 @@ | |||
1 | #include <errno.h> | 1 | #include <errno.h> |
2 | #include <cassert> | 2 | #include <cassert> |
3 | #include <vector> | 3 | #include <vector> |
4 | #include <string> | 4 | #include <string> |
5 | #include <mimetic/mimetic.h> | 5 | #include <openssl/bio.h> |
6 | #include <openssl/evp.h> | ||
6 | #include <curl/curl.h> | 7 | #include <curl/curl.h> |
7 | #include "opkele/util.h" | 8 | #include "opkele/util.h" |
8 | #include "opkele/exception.h" | 9 | #include "opkele/exception.h" |
9 | 10 | ||
10 | namespace opkele { | 11 | namespace opkele { |
11 | using namespace std; | 12 | using namespace std; |
12 | 13 | ||
13 | namespace util { | 14 | namespace util { |
14 | 15 | ||
15 | /* | 16 | /* |
17 | * base64 | ||
18 | */ | ||
19 | string encode_base64(const void *data,size_t length) { | ||
20 | BIO *b64 = 0, *bmem = 0; | ||
21 | try { | ||
22 | b64 = BIO_new(BIO_f_base64()); | ||
23 | if(!b64) | ||
24 | throw exception_openssl(OPKELE_CP_ "failed to BIO_new() base64 encoder"); | ||
25 | BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL); | ||
26 | bmem = BIO_new(BIO_s_mem()); | ||
27 | BIO_set_flags(b64,BIO_CLOSE); | ||
28 | if(!bmem) | ||
29 | throw exception_openssl(OPKELE_CP_ "failed to BIO_new() memory buffer"); | ||
30 | BIO_push(b64,bmem); | ||
31 | if(BIO_write(b64,data,length)!=length) | ||
32 | throw exception_openssl(OPKELE_CP_ "failed to BIO_write()"); | ||
33 | BIO_flush(b64); | ||
34 | char *rvd; | ||
35 | long rvl = BIO_get_mem_data(bmem,&rvd); | ||
36 | string rv(rvd,rvl); | ||
37 | BIO_free_all(b64); | ||
38 | return rv; | ||
39 | }catch(...) { | ||
40 | if(b64) BIO_free_all(b64); | ||
41 | throw; | ||
42 | } | ||
43 | } | ||
44 | |||
45 | void decode_base64(const string& data,vector<unsigned char>& rv) { | ||
46 | BIO *b64 = 0, *bmem = 0; | ||
47 | rv.clear(); | ||
48 | try { | ||
49 | bmem = BIO_new_mem_buf((void*)data.data(),data.size()); | ||
50 | if(!bmem) | ||
51 | throw exception_openssl(OPKELE_CP_ "failed to BIO_new_mem_buf()"); | ||
52 | b64 = BIO_new(BIO_f_base64()); | ||
53 | if(!b64) | ||
54 | throw exception_openssl(OPKELE_CP_ "failed to BIO_new() base64 decoder"); | ||
55 | BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL); | ||
56 | BIO_push(b64,bmem); | ||
57 | unsigned char tmp[512]; | ||
58 | size_t rb = 0; | ||
59 | while((rb=BIO_read(b64,tmp,sizeof(tmp)))>0) | ||
60 | rv.insert(rv.end(),tmp,&tmp[rb]); | ||
61 | BIO_free_all(b64); | ||
62 | }catch(...) { | ||
63 | if(b64) BIO_free_all(b64); | ||
64 | throw; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | /* | ||
16 | * big numerics | 69 | * big numerics |
17 | */ | 70 | */ |
18 | 71 | ||
19 | BIGNUM *base64_to_bignum(const string& b64) { | 72 | BIGNUM *base64_to_bignum(const string& b64) { |
20 | vector<unsigned char> bin; | 73 | vector<unsigned char> bin; |
21 | mimetic::Base64::Decoder b; | 74 | decode_base64(b64,bin); |
22 | mimetic::decode( | ||
23 | b64.begin(),b64.end(), b, | ||
24 | back_insert_iterator<vector<unsigned char> >(bin) ); | ||
25 | BIGNUM *rv = BN_bin2bn(&(bin.front()),bin.size(),0); | 75 | BIGNUM *rv = BN_bin2bn(&(bin.front()),bin.size(),0); |
26 | if(!rv) | 76 | if(!rv) |
27 | throw failed_conversion(OPKELE_CP_ "failed to BN_bin2bn()"); | 77 | throw failed_conversion(OPKELE_CP_ "failed to BN_bin2bn()"); |
28 | return rv; | 78 | return rv; |
29 | } | 79 | } |
30 | 80 | ||
31 | BIGNUM *dec_to_bignum(const string& dec) { | 81 | BIGNUM *dec_to_bignum(const string& dec) { |
32 | BIGNUM *rv = 0; | 82 | BIGNUM *rv = 0; |
33 | if(!BN_dec2bn(&rv,dec.c_str())) | 83 | if(!BN_dec2bn(&rv,dec.c_str())) |
34 | throw failed_conversion(OPKELE_CP_ "failed to BN_dec2bn()"); | 84 | throw failed_conversion(OPKELE_CP_ "failed to BN_dec2bn()"); |
35 | return rv; | 85 | return rv; |
36 | } | 86 | } |
37 | 87 | ||
38 | string bignum_to_base64(const BIGNUM *bn) { | 88 | string bignum_to_base64(const BIGNUM *bn) { |
39 | vector<unsigned char> bin(BN_num_bytes(bn)); | 89 | vector<unsigned char> bin(BN_num_bytes(bn)); |
40 | int l = BN_bn2bin(bn,&(bin.front())); | 90 | int l = BN_bn2bin(bn,&(bin.front())); |
41 | string rv; | 91 | return encode_base64(&(bin.front()),l); |
42 | mimetic::Base64::Encoder b(0); | ||
43 | mimetic::encode( | ||
44 | bin.begin(),bin.begin()+l, b, | ||
45 | back_insert_iterator<string>(rv) ); | ||
46 | return rv; | ||
47 | } | 92 | } |
48 | 93 | ||
49 | /* | 94 | /* |
50 | * w3c times | 95 | * w3c times |
51 | */ | 96 | */ |
52 | 97 | ||
53 | string time_to_w3c(time_t t) { | 98 | string time_to_w3c(time_t t) { |
54 | struct tm tm_t; | 99 | struct tm tm_t; |
55 | if(!gmtime_r(&t,&tm_t)) | 100 | if(!gmtime_r(&t,&tm_t)) |
56 | throw failed_conversion(OPKELE_CP_ "failed to BN_dec2bn()"); | 101 | throw failed_conversion(OPKELE_CP_ "failed to BN_dec2bn()"); |
57 | char rv[25]; | 102 | char rv[25]; |
58 | if(!strftime(rv,sizeof(rv)-1,"%Y-%m-%dT%H:%M:%SZ",&tm_t)) | 103 | if(!strftime(rv,sizeof(rv)-1,"%Y-%m-%dT%H:%M:%SZ",&tm_t)) |
diff --git a/libopkele.pc.in b/libopkele.pc.in index 60bca34..286720e 100644 --- a/libopkele.pc.in +++ b/libopkele.pc.in | |||
@@ -1,11 +1,11 @@ | |||
1 | prefix=@prefix@ | 1 | prefix=@prefix@ |
2 | exec_prefix=@exec_prefix@ | 2 | exec_prefix=@exec_prefix@ |
3 | libdir=@libdir@ | 3 | libdir=@libdir@ |
4 | includedir=@includedir@ | 4 | includedir=@includedir@ |
5 | 5 | ||
6 | Name: libopkele | 6 | Name: libopkele |
7 | Description: C++ implementation of OpenID protocol | 7 | Description: C++ implementation of OpenID protocol |
8 | Version: @VERSION@ | 8 | Version: @VERSION@ |
9 | Requires: openssl @KONFORKA_KONFORKA@ | 9 | Requires: openssl @KONFORKA_KONFORKA@ |
10 | Cflags: -I${includedir} @LIBCURL_CPPFLAGS@ @PCREPP_CFLAGS@ | 10 | Cflags: -I${includedir} @LIBCURL_CPPFLAGS@ @PCREPP_CFLAGS@ |
11 | Libs: -L${libdir} -lopkele @LIBCURL@ @PCREPP_LIBS@ @MIMETIC_LIBS@ | 11 | Libs: -L${libdir} -lopkele @LIBCURL@ @PCREPP_LIBS@ |