author | Michael Krelin <hacker@klever.net> | 2009-04-06 20:27:39 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2009-04-06 20:27:39 (UTC) |
commit | 51d8a8a4ac6ef6096c393fd602df34c6bf8f6366 (patch) (unidiff) | |
tree | 8126f60fac6562b14c965e41d19983d81312638a | |
parent | de964540e5a58b3a9195c642ef7a0745ee3b2344 (diff) | |
download | iii-51d8a8a4ac6ef6096c393fd602df34c6bf8f6366.zip iii-51d8a8a4ac6ef6096c393fd602df34c6bf8f6366.tar.gz iii-51d8a8a4ac6ef6096c393fd602df34c6bf8f6366.tar.bz2 |
better nonce generation and session credentials verification
based on the patch from Chris Davies
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/eyefiservice.cc | 21 | ||||
-rw-r--r-- | src/eyetil.cc | 17 | ||||
-rw-r--r-- | src/eyetil.h | 1 |
6 files changed, 43 insertions, 7 deletions
@@ -4,6 +4,7 @@ Klever dissected: | |||
4 | 4 | ||
5 | 5 | ||
6 | Thanks to: | 6 | Thanks to: |
7 | 7 | ||
8 | cdavies of Eye-Fi forums for integrity digest verification algorithm. | 8 | cdavies of Eye-Fi forums for integrity digest verification algorithm. |
9 | See http://forums.eye.fi/viewtopic.php?f=4&t=270&p=4074#p4074 | 9 | See http://forums.eye.fi/viewtopic.php?f=4&t=270&p=4074#p4074 |
10 | and session nonce verification patch | ||
diff --git a/configure.ac b/configure.ac index 2e66fc4..515d465 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -12,12 +12,18 @@ AC_HEADER_STDC | |||
12 | 12 | ||
13 | AC_PATH_PROG([XSLTPROC],[xsltproc],[true]) | 13 | AC_PATH_PROG([XSLTPROC],[xsltproc],[true]) |
14 | 14 | ||
15 | PKG_CHECK_MODULES([MODULES],[gsoap++ openssl libconfuse],,[ | 15 | PKG_CHECK_MODULES([MODULES],[gsoap++ openssl libconfuse],,[ |
16 | AC_MSG_ERROR([one of the build dependencies isn't satisfied]) | 16 | AC_MSG_ERROR([one of the build dependencies isn't satisfied]) |
17 | ]) | 17 | ]) |
18 | PKG_CHECK_MODULES([UUID],[uuid],[have_uuid=true],[have_uuid=false]) | ||
19 | AM_CONDITIONAL([HAVE_UUID],[$have_uuid]) | ||
20 | if $have_uuid ; then | ||
21 | AC_DEFINE([HAVE_LIBUUID],,[defined in presence of libuuid]) | ||
22 | AC_SUBST([UUID_UUID],[uuid]) | ||
23 | fi | ||
18 | 24 | ||
19 | AC_PATH_PROG([SOAPCPP2],[soapcpp2],[false]) | 25 | AC_PATH_PROG([SOAPCPP2],[soapcpp2],[false]) |
20 | test "$SOAPCPP2" = "false" && AC_MSG_ERROR([no soapcpp2 tool, part of gsoap package, found.]) | 26 | test "$SOAPCPP2" = "false" && AC_MSG_ERROR([no soapcpp2 tool, part of gsoap package, found.]) |
21 | 27 | ||
22 | notfound=false | 28 | notfound=false |
23 | AC_CHECK_HEADERS([archive.h],[ | 29 | AC_CHECK_HEADERS([archive.h],[ |
diff --git a/src/Makefile.am b/src/Makefile.am index 09f698e..b5b7d5c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -4,21 +4,21 @@ noinst_HEADERS = \ | |||
4 | eyekinfig.h eyetil.h \ | 4 | eyekinfig.h eyetil.h \ |
5 | eyefiworker.h | 5 | eyefiworker.h |
6 | 6 | ||
7 | AM_CPPFLAGS = ${CPPFLAGS_DEBUG} \ | 7 | AM_CPPFLAGS = ${CPPFLAGS_DEBUG} \ |
8 | -DEYEKIN_CONF_DIR=\"${sysconfdir}/${PACKAGE}\" | 8 | -DEYEKIN_CONF_DIR=\"${sysconfdir}/${PACKAGE}\" |
9 | DEFAULT_INCLUDES = -I${top_builddir} -I${builddir} -I${srcdir} | 9 | DEFAULT_INCLUDES = -I${top_builddir} -I${builddir} -I${srcdir} |
10 | INCLUDES = ${MODULES_CFLAGS} | 10 | INCLUDES = ${MODULES_CFLAGS} ${UUID_CFLAGS} |
11 | 11 | ||
12 | iiid_SOURCES = iiid.cc \ | 12 | iiid_SOURCES = iiid.cc \ |
13 | eyekinfig.cc eyetil.cc \ | 13 | eyekinfig.cc eyetil.cc \ |
14 | eyefiservice.cc eyefiworker.cc | 14 | eyefiservice.cc eyefiworker.cc |
15 | nodist_iiid_SOURCES = \ | 15 | nodist_iiid_SOURCES = \ |
16 | ${builddir}/soapC.cpp ${builddir}/soapeyefiService.cpp \ | 16 | ${builddir}/soapC.cpp ${builddir}/soapeyefiService.cpp \ |
17 | COPYING.cc | 17 | COPYING.cc |
18 | iiid_LDADD = ${MODULES_LIBS} | 18 | iiid_LDADD = ${MODULES_LIBS} ${UUID_LIBS} |
19 | 19 | ||
20 | COPYING.cc: ${top_srcdir}/COPYING | 20 | COPYING.cc: ${top_srcdir}/COPYING |
21 | echo "const char * COPYING = " >$@ || (rm $@;exit 1) | 21 | echo "const char * COPYING = " >$@ || (rm $@;exit 1) |
22 | sed -e 's/"/\\"/g' -e 's/^/\"/' -e 's/$$/\\n\"/' $< >>$@ || (rm $@;exit 1) | 22 | sed -e 's/"/\\"/g' -e 's/^/\"/' -e 's/$$/\\n\"/' $< >>$@ || (rm $@;exit 1) |
23 | echo ';' >>$@ || (rm $@;exit 1) | 23 | echo ';' >>$@ || (rm $@;exit 1) |
24 | 24 | ||
diff --git a/src/eyefiservice.cc b/src/eyefiservice.cc index d233a07..1a21c02 100644 --- a/src/eyefiservice.cc +++ b/src/eyefiservice.cc | |||
@@ -3,16 +3,19 @@ | |||
3 | #include <fstream> | 3 | #include <fstream> |
4 | #include <stdexcept> | 4 | #include <stdexcept> |
5 | #include <iterator> | 5 | #include <iterator> |
6 | #include <syslog.h> | 6 | #include <syslog.h> |
7 | #include <sys/wait.h> | 7 | #include <sys/wait.h> |
8 | #include <autosprintf.h> | 8 | #include <autosprintf.h> |
9 | #include <openssl/rand.h> | ||
9 | #include "eyekinfig.h" | 10 | #include "eyekinfig.h" |
10 | #include "eyetil.h" | 11 | #include "eyetil.h" |
11 | #include "soapeyefiService.h" | 12 | #include "soapeyefiService.h" |
12 | 13 | ||
14 | static binary_t session_nonce; | ||
15 | |||
13 | static bool detached_child() { | 16 | static bool detached_child() { |
14 | pid_t p = fork(); | 17 | pid_t p = fork(); |
15 | if(p<0) throw std::runtime_error("failed to fork()"); | 18 | if(p<0) throw std::runtime_error("failed to fork()"); |
16 | if(!p) { | 19 | if(!p) { |
17 | p = fork(); | 20 | p = fork(); |
18 | if(p<0) { | 21 | if(p<0) { |
@@ -43,15 +46,14 @@ int eyefiService::StartSession( | |||
43 | #ifndef NDEBUG | 46 | #ifndef NDEBUG |
44 | syslog(LOG_DEBUG, | 47 | syslog(LOG_DEBUG, |
45 | "StartSession request from %s with cnonce=%s, transfermode=%d, transfermodetimestamp=%ld", | 48 | "StartSession request from %s with cnonce=%s, transfermode=%d, transfermodetimestamp=%ld", |
46 | macaddress.c_str(), cnonce.c_str(), transfermode, transfermodetimestamp ); | 49 | macaddress.c_str(), cnonce.c_str(), transfermode, transfermodetimestamp ); |
47 | #endif | 50 | #endif |
48 | r.credential = binary_t(macaddress+cnonce+eyekinfig_t(macaddress).get_upload_key()).md5().hex(); | 51 | r.credential = binary_t(macaddress+cnonce+eyekinfig_t(macaddress).get_upload_key()).md5().hex(); |
49 | /* TODO: better nonce generator */ | 52 | |
50 | time_t t = time(0); | 53 | r.snonce = session_nonce.make_nonce().hex(); |
51 | r.snonce = binary_t(&t,sizeof(t)).md5().hex(); | ||
52 | r.transfermode=transfermode; | 54 | r.transfermode=transfermode; |
53 | r.transfermodetimestamp=transfermodetimestamp; | 55 | r.transfermodetimestamp=transfermodetimestamp; |
54 | r.upsyncallowed=false; | 56 | r.upsyncallowed=false; |
55 | 57 | ||
56 | std::string cmd = eyekinfig_t(macaddress).get_on_start_session(); | 58 | std::string cmd = eyekinfig_t(macaddress).get_on_start_session(); |
57 | if(!cmd.empty()) { | 59 | if(!cmd.empty()) { |
@@ -71,15 +73,24 @@ int eyefiService::StartSession( | |||
71 | int eyefiService::GetPhotoStatus( | 73 | int eyefiService::GetPhotoStatus( |
72 | std::string credential, std::string macaddress, | 74 | std::string credential, std::string macaddress, |
73 | std::string filename, long filesize, std::string filesignature, | 75 | std::string filename, long filesize, std::string filesignature, |
74 | struct rns__GetPhotoStatusResponse &r ) { | 76 | struct rns__GetPhotoStatusResponse &r ) { |
75 | #ifndef NDEBUG | 77 | #ifndef NDEBUG |
76 | syslog(LOG_DEBUG, | 78 | syslog(LOG_DEBUG, |
77 | "GetPhotoStatus request from %s with credential=%s, filename=%s, filesize=%ld, filesignature=%s", | 79 | "GetPhotoStatus request from %s with credential=%s, filename=%s, filesize=%ld, filesignature=%s; session nonce=%s", |
78 | macaddress.c_str(), credential.c_str(), filename.c_str(), filesize, filesignature.c_str() ); | 80 | macaddress.c_str(), credential.c_str(), filename.c_str(), filesize, filesignature.c_str(), session_nonce.hex().c_str() ); |
81 | #endif | ||
82 | |||
83 | std::string computed_credential = binary_t(macaddress+eyekinfig_t(macaddress).get_upload_key()+session_nonce.hex()).md5().hex(); | ||
84 | |||
85 | #ifndef NDEBUG | ||
86 | syslog(LOG_DEBUG, " computed credential=%s", computed_credential.c_str()); | ||
79 | #endif | 87 | #endif |
88 | |||
89 | if (credential != computed_credential) throw std::runtime_error("card authentication failed"); | ||
90 | |||
80 | r.fileid = 1; r.offset = 0; | 91 | r.fileid = 1; r.offset = 0; |
81 | return SOAP_OK; | 92 | return SOAP_OK; |
82 | } | 93 | } |
83 | 94 | ||
84 | int eyefiService::MarkLastPhotoInRoll( | 95 | int eyefiService::MarkLastPhotoInRoll( |
85 | std::string macaddress, int mergedelta, | 96 | std::string macaddress, int mergedelta, |
diff --git a/src/eyetil.cc b/src/eyetil.cc index fe816a6..7669cb6 100644 --- a/src/eyetil.cc +++ b/src/eyetil.cc | |||
@@ -6,12 +6,17 @@ | |||
6 | #include <stdexcept> | 6 | #include <stdexcept> |
7 | #include <algorithm> | 7 | #include <algorithm> |
8 | #include <numeric> | 8 | #include <numeric> |
9 | #include <openssl/md5.h> | 9 | #include <openssl/md5.h> |
10 | #include "eyetil.h" | 10 | #include "eyetil.h" |
11 | 11 | ||
12 | #include "config.h" | ||
13 | #ifdef HAVE_LIBUUID | ||
14 | # include <uuid/uuid.h> | ||
15 | #endif | ||
16 | |||
12 | binary_t& binary_t::from_hex(const std::string& h) { | 17 | binary_t& binary_t::from_hex(const std::string& h) { |
13 | std::string::size_type hs = h.length(); | 18 | std::string::size_type hs = h.length(); |
14 | if(hs&1) | 19 | if(hs&1) |
15 | throw std::runtime_error("odd number of characters in hexadecimal number"); | 20 | throw std::runtime_error("odd number of characters in hexadecimal number"); |
16 | int rvs = hs>>1; | 21 | int rvs = hs>>1; |
17 | resize(rvs); | 22 | resize(rvs); |
@@ -29,12 +34,24 @@ binary_t& binary_t::from_data(const void *d,size_t s) { | |||
29 | resize(s); | 34 | resize(s); |
30 | std::copy((const unsigned char*)d,(const unsigned char *)d+s, | 35 | std::copy((const unsigned char*)d,(const unsigned char *)d+s, |
31 | begin() ); | 36 | begin() ); |
32 | return *this; | 37 | return *this; |
33 | } | 38 | } |
34 | 39 | ||
40 | binary_t& binary_t::make_nonce() { | ||
41 | #ifdef HAVE_LIBUUID | ||
42 | uuid_t uuid; | ||
43 | uuid_generate(uuid); | ||
44 | from_data((unsigned char*)uuid,sizeof(uuid)); | ||
45 | #else | ||
46 | resize(16); | ||
47 | std::generate_n(begin(),16,rand); | ||
48 | #endif /* HAVE_LIBUUID */ | ||
49 | return *this; | ||
50 | } | ||
51 | |||
35 | std::string binary_t::hex() const { | 52 | std::string binary_t::hex() const { |
36 | std::string rv; | 53 | std::string rv; |
37 | rv.reserve((size()<<1)+1); | 54 | rv.reserve((size()<<1)+1); |
38 | char t[3] = {0,0,0}; | 55 | char t[3] = {0,0,0}; |
39 | for(const_iterator i=begin(),ie=end();i!=ie;++i) { | 56 | for(const_iterator i=begin(),ie=end();i!=ie;++i) { |
40 | int rc = snprintf(t,sizeof(t),"%02x",*i); | 57 | int rc = snprintf(t,sizeof(t),"%02x",*i); |
diff --git a/src/eyetil.h b/src/eyetil.h index 378f703..d946e71 100644 --- a/src/eyetil.h +++ b/src/eyetil.h | |||
@@ -12,12 +12,13 @@ class binary_t : public std::vector<unsigned char> { | |||
12 | binary_t(size_type n) : std::vector<unsigned char>(n) { } | 12 | binary_t(size_type n) : std::vector<unsigned char>(n) { } |
13 | binary_t(const std::string& h) { from_hex(h); } | 13 | binary_t(const std::string& h) { from_hex(h); } |
14 | binary_t(const void *d,size_t s) { from_data(d,s); } | 14 | binary_t(const void *d,size_t s) { from_data(d,s); } |
15 | 15 | ||
16 | binary_t& from_hex(const std::string& h); | 16 | binary_t& from_hex(const std::string& h); |
17 | binary_t& from_data(const void *d,size_t s); | 17 | binary_t& from_data(const void *d,size_t s); |
18 | binary_t& make_nonce(); | ||
18 | 19 | ||
19 | std::string hex() const; | 20 | std::string hex() const; |
20 | binary_t md5() const; | 21 | binary_t md5() const; |
21 | }; | 22 | }; |
22 | 23 | ||
23 | class tmpdir_t { | 24 | class tmpdir_t { |