2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstring>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cassert>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-04-07 19:06:00 +00:00
|
|
|
#include "boinc_db.h"
|
2002-11-06 09:03:55 +00:00
|
|
|
#include "error_numbers.h"
|
2002-07-05 05:33:40 +00:00
|
|
|
#include "parse.h"
|
2004-09-24 21:28:12 +00:00
|
|
|
#include "sched_config.h"
|
2002-07-05 05:33:40 +00:00
|
|
|
#include "crypt.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-04-30 23:18:56 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
#include "fcgi_stdio.h"
|
|
|
|
#endif
|
|
|
|
|
2002-05-14 23:13:17 +00:00
|
|
|
#define OUTFILE_MACRO "<OUTFILE_"
|
|
|
|
#define UPLOAD_URL_MACRO "<UPLOAD_URL/>"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-11-06 09:03:55 +00:00
|
|
|
// compute an XML signature element for some text
|
|
|
|
//
|
|
|
|
int generate_signature(
|
|
|
|
char* signed_xml, char* signature_xml, R_RSA_PRIVATE_KEY& key
|
|
|
|
) {
|
|
|
|
DATA_BLOCK block, signature;
|
|
|
|
unsigned char signature_buf[SIGNATURE_SIZE_BINARY];
|
2004-05-13 18:18:22 +00:00
|
|
|
char buf[LARGE_BLOB_SIZE];
|
2002-11-06 09:03:55 +00:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
block.data = (unsigned char*)signed_xml;
|
|
|
|
block.len = strlen(signed_xml);
|
|
|
|
signature.data = signature_buf;
|
|
|
|
signature.len = SIGNATURE_SIZE_BINARY;
|
|
|
|
retval = sign_block(block, key, signature);
|
|
|
|
if (retval) return retval;
|
|
|
|
sprint_hex_data(buf, signature);
|
|
|
|
#if 0
|
|
|
|
printf("signing [\n%s]\n", signed_xml);
|
|
|
|
printf("signature: [\n%s]\n", buf);
|
|
|
|
#endif
|
|
|
|
sprintf(signature_xml,
|
|
|
|
"<xml_signature>\n%s</xml_signature>\n", buf
|
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// At the end of every <file_info> element,
|
|
|
|
// add a signature of its contents up to that point.
|
|
|
|
//
|
|
|
|
int add_signatures(char* xml, R_RSA_PRIVATE_KEY& key) {
|
2004-05-13 18:18:22 +00:00
|
|
|
char* p = xml, *q1, *q2, buf[LARGE_BLOB_SIZE], buf2[LARGE_BLOB_SIZE];;
|
|
|
|
char signature[LARGE_BLOB_SIZE];
|
2002-11-06 09:03:55 +00:00
|
|
|
int retval, len;
|
|
|
|
|
|
|
|
while (1) {
|
2002-11-09 20:26:50 +00:00
|
|
|
q1 = strstr(p, "<file_info>\n");
|
2002-11-06 09:03:55 +00:00
|
|
|
if (!q1) break;
|
|
|
|
q2 = strstr(q1, "</file_info>");
|
|
|
|
if (!q2) {
|
|
|
|
fprintf(stderr, "add_signatures: malformed XML: %s\n", xml);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2002-11-09 20:26:50 +00:00
|
|
|
q1 += strlen("<file_info>\n");
|
2002-11-06 09:03:55 +00:00
|
|
|
len = q2 - q1;
|
|
|
|
memcpy(buf, q1, len);
|
|
|
|
buf[len] = 0;
|
|
|
|
retval = generate_signature(buf, signature, key);
|
|
|
|
if (retval) return retval;
|
|
|
|
strcpy(buf2, q2);
|
2002-11-07 19:31:34 +00:00
|
|
|
strcpy(q1, buf);
|
|
|
|
strcat(q1, signature);
|
|
|
|
strcat(q1, buf2);
|
|
|
|
p = q1;
|
2002-11-06 09:03:55 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove file upload signatures from a result XML doc
|
|
|
|
//
|
|
|
|
int remove_signatures(char* xml) {
|
|
|
|
char* p, *q;
|
|
|
|
while (1) {
|
|
|
|
p = strstr(xml, "<xml_signature>");
|
|
|
|
if (!p) break;
|
|
|
|
q = strstr(p, "</xml_signature>");
|
|
|
|
if (!q) {
|
|
|
|
fprintf(stderr, "remove_signatures: invalid XML:\n%s", xml);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2003-04-04 20:56:51 +00:00
|
|
|
q += strlen("</xml_signature>\n");
|
2002-11-06 09:03:55 +00:00
|
|
|
strcpy(p, q);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// macro-substitute a result template:
|
|
|
|
// - replace OUTFILE_x with base_filename_x, etc.
|
|
|
|
// - add signatures for file uploads
|
|
|
|
//
|
2004-04-13 23:55:05 +00:00
|
|
|
// This is called only from the transitioner,
|
|
|
|
// to create a new result for a WU
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int process_result_template(
|
2002-11-06 09:03:55 +00:00
|
|
|
char* result_template,
|
2002-07-05 05:33:40 +00:00
|
|
|
R_RSA_PRIVATE_KEY& key,
|
2002-10-09 04:56:41 +00:00
|
|
|
char* base_filename,
|
2004-09-24 21:28:12 +00:00
|
|
|
SCHED_CONFIG& config
|
2002-04-30 22:22:54 +00:00
|
|
|
) {
|
2002-11-06 09:03:55 +00:00
|
|
|
char* p,*q;
|
2004-12-06 22:41:19 +00:00
|
|
|
char temp[LARGE_BLOB_SIZE], buf[256];
|
2004-12-08 07:03:43 +00:00
|
|
|
int retval;
|
2002-07-05 05:33:40 +00:00
|
|
|
|
2002-11-06 09:03:55 +00:00
|
|
|
while (1) {
|
|
|
|
p = strstr(result_template, OUTFILE_MACRO);
|
|
|
|
if (p) {
|
|
|
|
q = p+strlen(OUTFILE_MACRO);
|
2004-12-06 22:41:19 +00:00
|
|
|
char* endptr = strstr(q, "/>");
|
|
|
|
if (!endptr) return ERR_XML_PARSE;
|
|
|
|
if (strchr(q, '>') != endptr+1) return ERR_XML_PARSE;
|
|
|
|
*endptr = 0;
|
|
|
|
strcpy(buf, q);
|
|
|
|
strcpy(temp, endptr+2);
|
2002-11-06 09:03:55 +00:00
|
|
|
strcpy(p, base_filename);
|
2004-12-06 22:41:19 +00:00
|
|
|
strcat(p, buf);
|
2002-11-06 09:03:55 +00:00
|
|
|
strcat(p, temp);
|
2002-07-05 05:33:40 +00:00
|
|
|
continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-11-06 09:03:55 +00:00
|
|
|
p = strstr(result_template, UPLOAD_URL_MACRO);
|
|
|
|
if (p) {
|
|
|
|
strcpy(temp, p+strlen(UPLOAD_URL_MACRO));
|
2004-09-24 21:28:12 +00:00
|
|
|
strcpy(p, config.upload_url);
|
2002-11-06 09:03:55 +00:00
|
|
|
strcat(p, temp);
|
2002-07-05 05:33:40 +00:00
|
|
|
continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-11-06 09:03:55 +00:00
|
|
|
break;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-09-24 21:28:12 +00:00
|
|
|
if (!config.dont_generate_upload_certificates) {
|
|
|
|
retval = add_signatures(result_template, key);
|
|
|
|
if (retval) return retval;
|
|
|
|
}
|
|
|
|
return 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_e5e1e879f3 = "$Id$";
|