-rw-r--r-- | src/eyefiservice.cc | 21 |
1 files changed, 16 insertions, 5 deletions
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, |