2002-04-30 22:22:54 +00:00
|
|
|
// The contents of this file are subject to the Mozilla Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2002-07-05 05:33:40 +00:00
|
|
|
// macro-substitute a result template file:
|
|
|
|
// - replace OUTFILE_x with base_filename_x,
|
|
|
|
// - WU_NAME with WU name
|
|
|
|
// - RESULT_NAME with result name
|
|
|
|
// - At the end of every <file_info> element, add a signature
|
|
|
|
// of its contents up to that point.
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2002-07-11 01:09:53 +00:00
|
|
|
#include <assert.h>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "db.h"
|
2002-07-05 05:33:40 +00:00
|
|
|
#include "parse.h"
|
|
|
|
#include "crypt.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-05-14 23:13:17 +00:00
|
|
|
#define WU_NAME_MACRO "<WU_NAME/>"
|
|
|
|
#define RESULT_NAME_MACRO "<RESULT_NAME/>"
|
|
|
|
#define OUTFILE_MACRO "<OUTFILE_"
|
|
|
|
#define UPLOAD_URL_MACRO "<UPLOAD_URL/>"
|
|
|
|
#define DOWNLOAD_URL_MACRO "<DOWNLOAD_URL/>"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
int process_result_template(
|
2002-07-05 05:33:40 +00:00
|
|
|
FILE* in, FILE* out,
|
|
|
|
R_RSA_PRIVATE_KEY& key,
|
2002-10-03 18:33:46 +00:00
|
|
|
char* base_filename, char* wu_name, char* result_name,
|
|
|
|
char* upload_url, char* download_url
|
2002-04-30 22:22:54 +00:00
|
|
|
) {
|
2002-07-05 05:33:40 +00:00
|
|
|
char* p,*q, *signed_xml=strdup("");
|
|
|
|
char buf[256], temp[256];
|
2002-07-09 00:10:58 +00:00
|
|
|
unsigned char signature_buf[SIGNATURE_SIZE_BINARY];
|
2002-07-05 05:33:40 +00:00
|
|
|
DATA_BLOCK block, signature;
|
2002-05-14 23:13:17 +00:00
|
|
|
char num;
|
2002-04-30 22:22:54 +00:00
|
|
|
int i;
|
|
|
|
bool found;
|
|
|
|
|
2002-07-11 01:09:53 +00:00
|
|
|
assert(in!=NULL);
|
|
|
|
assert(out!=NULL);
|
|
|
|
assert(base_filename!=NULL);
|
|
|
|
assert(wu_name!=NULL);
|
|
|
|
assert(result_name!=NULL);
|
2002-07-05 05:33:40 +00:00
|
|
|
while (fgets(buf, 256, in)) {
|
|
|
|
|
|
|
|
// when we reach the end of a <file_info> element,
|
|
|
|
// generate a signature for the contents thus far
|
|
|
|
//
|
|
|
|
if (match_tag(buf, "<file_info>")) {
|
|
|
|
free(signed_xml);
|
|
|
|
signed_xml = strdup("");
|
|
|
|
fputs(buf, out);
|
|
|
|
continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-07-05 05:33:40 +00:00
|
|
|
if (match_tag(buf, "</file_info>")) {
|
|
|
|
block.data = (unsigned char*)signed_xml;
|
|
|
|
block.len = strlen(signed_xml);
|
|
|
|
signature.data = signature_buf;
|
2002-07-09 00:10:58 +00:00
|
|
|
signature.len = SIGNATURE_SIZE_BINARY;
|
2002-07-05 05:33:40 +00:00
|
|
|
sign_block(block, key, signature);
|
2002-07-07 20:39:24 +00:00
|
|
|
fprintf(out, "<xml_signature>\n");
|
2002-07-05 05:33:40 +00:00
|
|
|
print_hex_data(out, signature);
|
2002-07-07 20:39:24 +00:00
|
|
|
#if 0
|
|
|
|
printf("signing [\n%s]\n", signed_xml);
|
|
|
|
printf("signature: [\n");
|
2002-07-05 05:33:40 +00:00
|
|
|
print_hex_data(stdout, signature);
|
2002-07-07 20:39:24 +00:00
|
|
|
printf("]\n");
|
|
|
|
#endif
|
|
|
|
fprintf(out, "</xml_signature>\n");
|
2002-07-05 05:33:40 +00:00
|
|
|
fprintf(out, "</file_info>\n");
|
|
|
|
continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-07-05 05:33:40 +00:00
|
|
|
while (1) {
|
|
|
|
found = false;
|
|
|
|
p = strstr(buf, OUTFILE_MACRO);
|
|
|
|
if (p) {
|
|
|
|
found = true;
|
|
|
|
i = atoi(p+strlen(OUTFILE_MACRO));
|
|
|
|
q = p+strlen(OUTFILE_MACRO);
|
|
|
|
num = q[0];
|
|
|
|
strcpy(temp, p+strlen(OUTFILE_MACRO)+1+2);
|
|
|
|
strcpy(p, base_filename);
|
|
|
|
strncat(p, &num, 1);
|
|
|
|
strcat(p, temp);
|
|
|
|
}
|
|
|
|
p = strstr(buf, UPLOAD_URL_MACRO);
|
|
|
|
if (p) {
|
|
|
|
found = true;
|
|
|
|
strcpy(temp, p+strlen(UPLOAD_URL_MACRO));
|
2002-10-03 18:33:46 +00:00
|
|
|
strcpy(p, upload_url);
|
2002-07-05 05:33:40 +00:00
|
|
|
strcat(p, temp);
|
|
|
|
}
|
|
|
|
p = strstr(buf, DOWNLOAD_URL_MACRO);
|
|
|
|
if (p) {
|
|
|
|
found = true;
|
|
|
|
strcpy(temp, p+strlen(DOWNLOAD_URL_MACRO));
|
2002-10-03 18:33:46 +00:00
|
|
|
strcpy(p, download_url);
|
2002-07-05 05:33:40 +00:00
|
|
|
strcat(p, temp);
|
|
|
|
}
|
|
|
|
p = strstr(buf, WU_NAME_MACRO);
|
|
|
|
if (p) {
|
|
|
|
found = true;
|
|
|
|
strcpy(temp, p+strlen(WU_NAME_MACRO));
|
|
|
|
strcpy(p, wu_name);
|
|
|
|
strcat(p, temp);
|
|
|
|
}
|
|
|
|
p = strstr(buf, RESULT_NAME_MACRO);
|
|
|
|
if (p) {
|
|
|
|
found = true;
|
|
|
|
strcpy(temp, p+strlen(RESULT_NAME_MACRO));
|
|
|
|
strcpy(p, result_name);
|
|
|
|
strcat(p, temp);
|
|
|
|
}
|
|
|
|
if (!found) break;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-07-05 05:33:40 +00:00
|
|
|
strcatdup(signed_xml, buf);
|
|
|
|
fputs(buf, out);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|