-rw-r--r-- | src/eyefiservice.cc | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/eyefiservice.cc b/src/eyefiservice.cc index 153a7c4..d233a07 100644 --- a/src/eyefiservice.cc +++ b/src/eyefiservice.cc | |||
@@ -124,2 +124,5 @@ int eyefiService::UploadPhoto( | |||
124 | 124 | ||
125 | std::string jf; | ||
126 | binary_t digest, idigest; | ||
127 | |||
125 | for(soap_multipart::iterator i=mime.begin(),ie=mime.end();i!=ie;++i) { | 128 | for(soap_multipart::iterator i=mime.begin(),ie=mime.end();i!=ie;++i) { |
@@ -131,8 +134,9 @@ int eyefiService::UploadPhoto( | |||
131 | 134 | ||
132 | #ifndef NDEBUG | ||
133 | if((*i).id && !strcmp((*i).id,"INTEGRITYDIGEST")) { | 135 | if((*i).id && !strcmp((*i).id,"INTEGRITYDIGEST")) { |
134 | std::string idigest((*i).ptr,(*i).size); | 136 | std::string idigestr((*i).ptr,(*i).size); |
135 | syslog(LOG_DEBUG, " INTEGRITYDIGEST=%s", idigest.c_str()); | 137 | #ifndef NDEBUG |
136 | } | 138 | syslog(LOG_DEBUG, " INTEGRITYDIGEST=%s", idigestr.c_str()); |
137 | #endif | 139 | #endif |
140 | idigest.from_hex(idigestr); | ||
141 | } | ||
138 | if( (*i).id && !strcmp((*i).id,"FILENAME") ) { | 142 | if( (*i).id && !strcmp((*i).id,"FILENAME") ) { |
@@ -145,2 +149,10 @@ int eyefiService::UploadPhoto( | |||
145 | #endif | 149 | #endif |
150 | |||
151 | if(!jf.empty()) throw std::runtime_error("already seen tarball"); | ||
152 | if(!digest.empty()) throw std::runtime_error("already have integrity digest"); | ||
153 | digest = integrity_digest((*i).ptr,(*i).size,eyekinfig.get_upload_key()); | ||
154 | #ifndef NDEBUG | ||
155 | syslog(LOG_DEBUG," computed integrity digest=%s", digest.hex().c_str()); | ||
156 | #endif | ||
157 | |||
146 | tarchive_t a((*i).ptr,(*i).size); | 158 | tarchive_t a((*i).ptr,(*i).size); |
@@ -148,5 +160,3 @@ int eyefiService::UploadPhoto( | |||
148 | throw std::runtime_error("failed to tarchive_t::read_next_header())"); | 160 | throw std::runtime_error("failed to tarchive_t::read_next_header())"); |
149 | std::string jf = indir.get_file(a.entry_pathname()); | 161 | jf = indir.get_file(a.entry_pathname()); |
150 | std::string::size_type ls = jf.rfind('/'); | ||
151 | std::string jbn = (ls==std::string::npos)?jf:jf.substr(ls+1); | ||
152 | int fd=open(jf.c_str(),O_CREAT|O_WRONLY,0666); | 162 | int fd=open(jf.c_str(),O_CREAT|O_WRONLY,0666); |
@@ -155,2 +165,10 @@ int eyefiService::UploadPhoto( | |||
155 | close(fd); | 165 | close(fd); |
166 | } | ||
167 | } | ||
168 | |||
169 | if(jf.empty()) throw std::runtime_error("haven't seen jpeg file"); | ||
170 | if(digest!=idigest) throw std::runtime_error("integrity digest verification failed"); | ||
171 | |||
172 | std::string::size_type ls = jf.rfind('/'); | ||
173 | std::string jbn = (ls==std::string::npos)?jf:jf.substr(ls+1); | ||
156 | std::string tf = td+'/'+jbn; | 174 | std::string tf = td+'/'+jbn; |
@@ -180,4 +198,3 @@ int eyefiService::UploadPhoto( | |||
180 | } | 198 | } |
181 | } | 199 | |
182 | } | ||
183 | r.success = true; | 200 | r.success = true; |