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) (side-by-side diff)
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) (ignore 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
)
fi
-AC_LANG_PUSH([C++])
- AC_CHECK_LIB([mimetic],[main],[
- MIMETIC_LIBS=-lmimetic
- AC_SUBST([MIMETIC_CFLAGS])
- AC_SUBST([MIMETIC_LIBS])
- ],[
- AC_MSG_ERROR([no mimetic library found. get one from http://codesink.org/mimetic_mime_library.html])
- ]
- )
-AC_LANG_POP([C++])
-
WANT_DOXYGEN="yes"
AC_ARG_ENABLE([doxygen],
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 @@
#include <time.h>
#include <string>
+#include <vector>
#include <openssl/bn.h>
#include <openssl/dh.h>
namespace opkele {
using std::string;
+ using std::vector;
namespace util {
@@ -52,6 +54,9 @@ namespace opkele {
string long_to_string(long l);
long string_to_long(const string& s);
+
+ string encode_base64(const void *data,size_t length);
+ void decode_base64(const string& data,vector<unsigned char>& rv);
}
}
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 = \
-I${top_srcdir}/include/ \
${KONFORKA_CFLAGS} \
${OPENSSL_CFLAGS} \
- ${MIMETIC_CFLAGS} \
${LIBCURL_CPPFLAGS} \
${PCREPP_CFLAGS}
LDADD = \
${LIBCURL} \
${PCREPP_LIBS} \
- ${MIMETIC_LIBS} \
${OPENSSL_LIBS} \
${KONFORKA_LIBS}
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 @@
#include <algorithm>
+#include <cassert>
#include <opkele/util.h>
#include <opkele/exception.h>
#include <opkele/data.h>
#include <opkele/consumer.h>
#include <openssl/sha.h>
#include <openssl/hmac.h>
-#include <mimetic/mimetic.h>
#include <curl/curl.h>
#include <pcre++.h>
#include <iostream>
-/* silly mimetic */
-#undef PACKAGE
-#undef PACKAGE_BUGREPORT
-#undef PACKAGE_NAME
-#undef PACKAGE_STRING
-#undef PACKAGE_TARNAME
-#undef PACKAGE_VERSION
-#undef VERSION
-
#include "config.h"
namespace opkele {
@@ -166,11 +157,8 @@ namespace opkele {
try {
assoc_t assoc = retrieve_assoc(server,pin.get_param("openid.assoc_handle"));
const string& sigenc = pin.get_param("openid.sig");
- mimetic::Base64::Decoder b;
vector<unsigned char> sig;
- mimetic::decode(
- sigenc.begin(),sigenc.end(), b,
- back_insert_iterator<vector<unsigned char> >(sig) );
+ util::decode_base64(sigenc,sig);
const string& slist = pin.get_param("openid.signed");
string kv;
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 @@
#include <opkele/util.h>
#include <openssl/sha.h>
#include <openssl/hmac.h>
-#include <mimetic/mimetic.h>
namespace opkele {
using namespace std;
@@ -60,11 +59,7 @@ namespace opkele {
&(secret.front()),secret.size(),
(const unsigned char *)kv.data(),kv.length(),
0,&md_len);
- mimetic::Base64::Encoder b(0);
- sig.erase();
- mimetic::encode(
- md,md+md_len, b,
- back_insert_iterator<string>(sig) );
+ sig = util::encode_base64(md,md_len);
}
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 @@
#include <functional>
#include <opkele/types.h>
#include <opkele/exception.h>
-#include <mimetic/mimetic.h>
+#include <opkele/util.h>
namespace opkele {
using namespace std;
@@ -23,18 +23,12 @@ namespace opkele {
key_sha1,
back_insert_iterator<vector<unsigned char> >(tmp),
bitwise_xor<unsigned char,unsigned char,unsigned char>() );
- mimetic::Base64::Encoder b(0);
- mimetic::encode(
- tmp.begin(),tmp.end(), b,
- back_insert_iterator<string>(rv) );
+ rv = util::encode_base64(&(tmp.front()),tmp.size());
}
void secret_t::enxor_from_base64(const unsigned char *key_sha1,const string& b64) {
- mimetic::Base64::Decoder b;
clear();
- mimetic::decode(
- b64.begin(),b64.end(), b,
- back_insert_iterator<secret_t>(*this) );
+ util::decode_base64(b64,*this);
transform(
begin(), end(),
key_sha1,
@@ -45,17 +39,11 @@ namespace opkele {
void secret_t::to_base64(string& rv) const {
if(size()!=20)
throw bad_input(OPKELE_CP_ "wrong secret size");
- mimetic::Base64::Encoder b(0);
- mimetic::encode(
- begin(),end(), b,
- back_insert_iterator<string>(rv) );
+ rv = util::encode_base64(&(front()),size());
}
void secret_t::from_base64(const string& b64) {
- mimetic::Base64::Decoder b;
- mimetic::decode(
- b64.begin(),b64.end(), b,
- back_insert_iterator<secret_t>(*this) );
+ util::decode_base64(b64,*this);
}
}
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 @@
#include <vector>
#include <openssl/sha.h>
#include <openssl/hmac.h>
-#include <mimetic/mimetic.h>
#include <opkele/util.h>
#include <opkele/exception.h>
#include <opkele/server.h>
@@ -113,11 +112,8 @@ namespace opkele {
void server_t::check_authentication(const params_t& pin,params_t& pout) {
vector<unsigned char> sig;
- mimetic::Base64::Decoder b;
const string& sigenc = pin.get_param("openid.sig");
- mimetic::decode(
- sigenc.begin(),sigenc.end(), b,
- back_insert_iterator<vector<unsigned char> >(sig));
+ util::decode_base64(sigenc,sig);
assoc_t assoc;
try {
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 @@
#include <cassert>
#include <vector>
#include <string>
-#include <mimetic/mimetic.h>
+#include <openssl/bio.h>
+#include <openssl/evp.h>
#include <curl/curl.h>
#include "opkele/util.h"
#include "opkele/exception.h"
@@ -13,15 +14,64 @@ namespace opkele {
namespace util {
/*
+ * base64
+ */
+ string encode_base64(const void *data,size_t length) {
+ BIO *b64 = 0, *bmem = 0;
+ try {
+ b64 = BIO_new(BIO_f_base64());
+ if(!b64)
+ throw exception_openssl(OPKELE_CP_ "failed to BIO_new() base64 encoder");
+ BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL);
+ bmem = BIO_new(BIO_s_mem());
+ BIO_set_flags(b64,BIO_CLOSE);
+ if(!bmem)
+ throw exception_openssl(OPKELE_CP_ "failed to BIO_new() memory buffer");
+ BIO_push(b64,bmem);
+ if(BIO_write(b64,data,length)!=length)
+ throw exception_openssl(OPKELE_CP_ "failed to BIO_write()");
+ BIO_flush(b64);
+ char *rvd;
+ long rvl = BIO_get_mem_data(bmem,&rvd);
+ string rv(rvd,rvl);
+ BIO_free_all(b64);
+ return rv;
+ }catch(...) {
+ if(b64) BIO_free_all(b64);
+ throw;
+ }
+ }
+
+ void decode_base64(const string& data,vector<unsigned char>& rv) {
+ BIO *b64 = 0, *bmem = 0;
+ rv.clear();
+ try {
+ bmem = BIO_new_mem_buf((void*)data.data(),data.size());
+ if(!bmem)
+ throw exception_openssl(OPKELE_CP_ "failed to BIO_new_mem_buf()");
+ b64 = BIO_new(BIO_f_base64());
+ if(!b64)
+ throw exception_openssl(OPKELE_CP_ "failed to BIO_new() base64 decoder");
+ BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL);
+ BIO_push(b64,bmem);
+ unsigned char tmp[512];
+ size_t rb = 0;
+ while((rb=BIO_read(b64,tmp,sizeof(tmp)))>0)
+ rv.insert(rv.end(),tmp,&tmp[rb]);
+ BIO_free_all(b64);
+ }catch(...) {
+ if(b64) BIO_free_all(b64);
+ throw;
+ }
+ }
+
+ /*
* big numerics
*/
BIGNUM *base64_to_bignum(const string& b64) {
vector<unsigned char> bin;
- mimetic::Base64::Decoder b;
- mimetic::decode(
- b64.begin(),b64.end(), b,
- back_insert_iterator<vector<unsigned char> >(bin) );
+ decode_base64(b64,bin);
BIGNUM *rv = BN_bin2bn(&(bin.front()),bin.size(),0);
if(!rv)
throw failed_conversion(OPKELE_CP_ "failed to BN_bin2bn()");
@@ -38,12 +88,7 @@ namespace opkele {
string bignum_to_base64(const BIGNUM *bn) {
vector<unsigned char> bin(BN_num_bytes(bn));
int l = BN_bn2bin(bn,&(bin.front()));
- string rv;
- mimetic::Base64::Encoder b(0);
- mimetic::encode(
- bin.begin(),bin.begin()+l, b,
- back_insert_iterator<string>(rv) );
- return rv;
+ return encode_base64(&(bin.front()),l);
}
/*
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
Version: @VERSION@
Requires: openssl @KONFORKA_KONFORKA@
Cflags: -I${includedir} @LIBCURL_CPPFLAGS@ @PCREPP_CFLAGS@
-Libs: -L${libdir} -lopkele @LIBCURL@ @PCREPP_LIBS@ @MIMETIC_LIBS@
+Libs: -L${libdir} -lopkele @LIBCURL@ @PCREPP_LIBS@