summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2007-01-12 12:58:25 (UTC)
committer Michael Krelin <hacker@klever.net>2007-01-12 12:58:25 (UTC)
commite79687a3d9a1631613de02d8e12bae36302b46ab (patch) (unidiff)
tree4238c0d8d61f5e70ed1e98debb01315babb21686
parent4cc2e58186e8cd9b96a3573c92f6664064cf11fe (diff)
downloadlibopkele-e79687a3d9a1631613de02d8e12bae36302b46ab.zip
libopkele-e79687a3d9a1631613de02d8e12bae36302b46ab.tar.gz
libopkele-e79687a3d9a1631613de02d8e12bae36302b46ab.tar.bz2
eliminated mimetic dependency and made use of openssl base64 encoder instead
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--configure.ac11
-rw-r--r--include/opkele/util.h5
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/consumer.cc16
-rw-r--r--lib/params.cc7
-rw-r--r--lib/secret.cc22
-rw-r--r--lib/server.cc6
-rw-r--r--lib/util.cc67
-rw-r--r--libopkele.pc.in2
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
@@ -41,17 +41,6 @@ if test "${WANT_KONFORKA}" = "yes" ; then
41 ) 41 )
42fi 42fi
43 43
44AC_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 )
53AC_LANG_POP([C++])
54
55WANT_DOXYGEN="yes" 44WANT_DOXYGEN="yes"
56AC_ARG_ENABLE([doxygen], 45AC_ARG_ENABLE([doxygen],
57 AC_HELP_STRING([--disable-doxygen],[do not generate documentation]), 46 AC_HELP_STRING([--disable-doxygen],[do not generate documentation]),
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
@@ -3,11 +3,13 @@
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
9namespace opkele { 10namespace opkele {
10 using std::string; 11 using std::string;
12 using std::vector;
11 13
12 namespace util { 14 namespace util {
13 15
@@ -52,6 +54,9 @@ namespace opkele {
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}
diff --git a/lib/Makefile.am b/lib/Makefile.am
index bdadd44..ec63c25 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -4,13 +4,11 @@ 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}
10LDADD = \ 9LDADD = \
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
diff --git a/lib/consumer.cc b/lib/consumer.cc
index b215aa8..331b1e9 100644
--- a/lib/consumer.cc
+++ b/lib/consumer.cc
@@ -1,25 +1,16 @@
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
25namespace opkele { 16namespace opkele {
@@ -166,11 +157,8 @@ namespace opkele {
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;
diff --git a/lib/params.cc b/lib/params.cc
index 14f1a53..03867d5 100644
--- a/lib/params.cc
+++ b/lib/params.cc
@@ -3,7 +3,6 @@
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
8namespace opkele { 7namespace opkele {
9 using namespace std; 8 using namespace std;
@@ -60,11 +59,7 @@ namespace opkele {
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 {
diff --git a/lib/secret.cc b/lib/secret.cc
index ae8a3c5..632a2ca 100644
--- a/lib/secret.cc
+++ b/lib/secret.cc
@@ -2,7 +2,7 @@
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
7namespace opkele { 7namespace opkele {
8 using namespace std; 8 using namespace std;
@@ -23,18 +23,12 @@ namespace opkele {
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,
@@ -45,17 +39,11 @@ namespace opkele {
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,7 +1,6 @@
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>
@@ -113,11 +112,8 @@ namespace opkele {
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"));
diff --git a/lib/util.cc b/lib/util.cc
index d78b5e0..d9abca7 100644
--- a/lib/util.cc
+++ b/lib/util.cc
@@ -2,7 +2,8 @@
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"
@@ -13,15 +14,64 @@ namespace opkele {
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()");
@@ -38,12 +88,7 @@ namespace opkele {
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 /*
diff --git a/libopkele.pc.in b/libopkele.pc.in
index 60bca34..286720e 100644
--- a/libopkele.pc.in
+++ b/libopkele.pc.in
@@ -8,4 +8,4 @@ Description: C++ implementation of OpenID protocol
8Version: @VERSION@ 8Version: @VERSION@
9Requires: openssl @KONFORKA_KONFORKA@ 9Requires: openssl @KONFORKA_KONFORKA@
10Cflags: -I${includedir} @LIBCURL_CPPFLAGS@ @PCREPP_CFLAGS@ 10Cflags: -I${includedir} @LIBCURL_CPPFLAGS@ @PCREPP_CFLAGS@
11Libs: -L${libdir} -lopkele @LIBCURL@ @PCREPP_LIBS@ @MIMETIC_LIBS@ 11Libs: -L${libdir} -lopkele @LIBCURL@ @PCREPP_LIBS@