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) (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
@@ -43,13 +43,2 @@ fi
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"
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
@@ -5,2 +5,3 @@
5#include <string> 5#include <string>
6#include <vector>
6#include <openssl/bn.h> 7#include <openssl/bn.h>
@@ -10,2 +11,3 @@ namespace opkele {
10 using std::string; 11 using std::string;
12 using std::vector;
11 13
@@ -54,2 +56,5 @@ namespace opkele {
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 }
diff --git a/lib/Makefile.am b/lib/Makefile.am
index bdadd44..ec63c25 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -6,3 +6,2 @@ INCLUDES = \
6 ${OPENSSL_CFLAGS} \ 6 ${OPENSSL_CFLAGS} \
7 ${MIMETIC_CFLAGS} \
8 ${LIBCURL_CPPFLAGS} \ 7 ${LIBCURL_CPPFLAGS} \
@@ -12,3 +11,2 @@ LDADD = \
12 ${PCREPP_LIBS} \ 11 ${PCREPP_LIBS} \
13 ${MIMETIC_LIBS} \
14 ${OPENSSL_LIBS} \ 12 ${OPENSSL_LIBS} \
diff --git a/lib/consumer.cc b/lib/consumer.cc
index b215aa8..331b1e9 100644
--- a/lib/consumer.cc
+++ b/lib/consumer.cc
@@ -1,2 +1,3 @@
1#include <algorithm> 1#include <algorithm>
2#include <cassert>
2#include <opkele/util.h> 3#include <opkele/util.h>
@@ -7,3 +8,2 @@
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>
@@ -13,11 +13,2 @@
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"
@@ -168,7 +159,4 @@ namespace opkele {
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");
diff --git a/lib/params.cc b/lib/params.cc
index 14f1a53..03867d5 100644
--- a/lib/params.cc
+++ b/lib/params.cc
@@ -5,3 +5,2 @@
5#include <openssl/hmac.h> 5#include <openssl/hmac.h>
6#include <mimetic/mimetic.h>
7 6
@@ -62,7 +61,3 @@ namespace opkele {
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 }
diff --git a/lib/secret.cc b/lib/secret.cc
index ae8a3c5..632a2ca 100644
--- a/lib/secret.cc
+++ b/lib/secret.cc
@@ -4,3 +4,3 @@
4#include <opkele/exception.h> 4#include <opkele/exception.h>
5#include <mimetic/mimetic.h> 5#include <opkele/util.h>
6 6
@@ -25,6 +25,3 @@ namespace opkele {
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 }
@@ -32,7 +29,4 @@ namespace opkele {
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(
@@ -47,6 +41,3 @@ namespace opkele {
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 }
@@ -54,6 +45,3 @@ namespace opkele {
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 }
diff --git a/lib/server.cc b/lib/server.cc
index 8c29abb..e81d4b6 100644
--- a/lib/server.cc
+++ b/lib/server.cc
@@ -3,3 +3,2 @@
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>
@@ -115,7 +114,4 @@ namespace opkele {
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;
diff --git a/lib/util.cc b/lib/util.cc
index d78b5e0..d9abca7 100644
--- a/lib/util.cc
+++ b/lib/util.cc
@@ -4,3 +4,4 @@
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>
@@ -15,2 +16,54 @@ namespace opkele {
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
@@ -20,6 +73,3 @@ namespace opkele {
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);
@@ -40,8 +90,3 @@ namespace opkele {
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 }
diff --git a/libopkele.pc.in b/libopkele.pc.in
index 60bca34..286720e 100644
--- a/libopkele.pc.in
+++ b/libopkele.pc.in
@@ -10,2 +10,2 @@ Requires: 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@