1
// This file is part of BOINC.
2
// http://boinc.berkeley.edu
3
// Copyright (C) 2008 University of California
5
// BOINC is free software; you can redistribute it and/or modify it
6
// under the terms of the GNU Lesser General Public License
7
// as published by the Free Software Foundation,
8
// either version 3 of the License, or (at your option) any later version.
10
// BOINC is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
// See the GNU Lesser General Public License for more details.
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
19
#include "error_numbers.h"
22
CERT_SIG::CERT_SIG() {
26
CERT_SIG::~CERT_SIG() {
30
void CERT_SIG::clear() {
31
this->type = MD5_HASH; // md5 hash by default
32
memset(this->subject, 0, sizeof(this->subject));
33
memset(this->signature, 0, sizeof(this->signature));
36
CERT_SIGS::CERT_SIGS() {
40
CERT_SIGS::~CERT_SIGS() {
44
void CERT_SIGS::clear() {
45
this->signatures.clear();
48
int CERT_SIGS::count() {
49
return (int)(this->signatures.size());
52
int CERT_SIGS::parse(XML_PARSER &xp) {
57
int parsed_one = false;
61
while (!xp.get(tag, sizeof(tag), (bool&)is_tag)) {
62
if (!strcmp(tag, "/signatures")) {
63
//printf("CERT_SIGS::parse() ends.\n");
65
return !in_entry && !in_sig && parsed_one;
69
snprintf(sig.signature, sizeof(sig.signature), "%s", tag);
73
printf("(CERT_SIGS): unexpected text: %s\n", tag);
77
if (!strcmp(tag, "/entry")) {
80
if (strlen(sig.subject) == 0) {
81
printf("ERROR: subject is not set.\n");
84
if (strlen(sig.signature) == 0) {
85
printf("ERROR: signature is not set.\n");
88
this->signatures.push_back(sig);
93
if (!strcmp(tag, "signature")) {
97
if (!strcmp(tag, "/signature")) {
101
if (xp.parse_str(tag, "subject", sig.subject, sizeof(sig.subject)))
103
else if (xp.parse_str(tag, "hash", sig.hash, sizeof(sig.hash)))
105
else if (xp.parse_str(tag, "type", buf, sizeof(buf))) {
106
if ((!strcmp(buf,"md5")) || (!strcmp(buf,"MD5"))) {
108
} else if ((!strcmp(buf,"sha1")) || (!strcmp(buf,"SHA1"))) {
109
sig.type = SHA1_HASH;
114
if (strstr(tag, "entry")) {
124
int CERT_SIGS::parse_miofile_embed(MIOFILE &mf) {
126
return this->parse(xp);
129
int CERT_SIGS::parse_file(const char* filename) {
133
f = fopen(filename, "r");
139
if (!xp.parse_start("signatures")) {
140
return ERR_XML_PARSE;
142
retval = this->parse(xp);
147
int CERT_SIGS::parse_buffer(char* buf) {
151
mf.init_buf_read(buf);
153
retval = this->parse(xp);
157
int CERT_SIGS::parse_buffer_embed(char* buf) {
163
mf.init_buf_read(buf);
165
while (!xp.get(tag, sizeof(tag), (bool&)is_tag)) {
166
if (!strcmp(tag, "signatures")) {
172
return this->parse(xp);
177
int CERT_SIGS::write(MIOFILE &f) {
178
if (this->signatures.size()==0) return true;
179
f.printf("<signatures>\n");
180
for(unsigned int i=0;i < this->signatures.size(); i++) {
181
f.printf(" <entry>\n");
182
f.printf(" <signature>\n%s\n", this->signatures.at(i).signature);
183
f.printf(" </signature>\n");
184
f.printf(" <subject>%s</subject>\n", this->signatures.at(i).subject);
185
f.printf(" <type>%s</type>\n", (this->signatures.at(i).type == MD5_HASH) ? "md5" : "sha1");
186
f.printf(" <hash>%s</hash>\n", this->signatures.at(i).hash);
187
f.printf(" </entry>\n");
189
f.printf("</signatures>\n");
1
// This file is part of BOINC.
2
// http://boinc.berkeley.edu
3
// Copyright (C) 2008 University of California
5
// BOINC is free software; you can redistribute it and/or modify it
6
// under the terms of the GNU Lesser General Public License
7
// as published by the Free Software Foundation,
8
// either version 3 of the License, or (at your option) any later version.
10
// BOINC is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
// See the GNU Lesser General Public License for more details.
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
18
#if defined(_WIN32) && !defined(__STDWX_H__)
19
#include "boinc_win.h"
20
#elif defined(_WIN32) && defined(__STDWX_H__)
25
#include "boinc_fcgi.h"
32
#define snprintf _snprintf
36
#include "error_numbers.h"
39
CERT_SIG::CERT_SIG() {
43
CERT_SIG::~CERT_SIG() {
47
void CERT_SIG::clear() {
48
this->type = MD5_HASH; // md5 hash by default
49
memset(this->subject, 0, sizeof(this->subject));
50
memset(this->signature, 0, sizeof(this->signature));
53
CERT_SIGS::CERT_SIGS() {
57
CERT_SIGS::~CERT_SIGS() {
61
void CERT_SIGS::clear() {
62
this->signatures.clear();
65
int CERT_SIGS::count() {
66
return (int)(this->signatures.size());
69
int CERT_SIGS::parse(XML_PARSER &xp) {
72
bool in_entry = false;
74
bool parsed_one = false;
78
while (!xp.get(tag, sizeof(tag), is_tag)) {
79
if (!strcmp(tag, "/signatures")) {
80
//printf("CERT_SIGS::parse() ends.\n");
82
return !in_entry && !in_sig && parsed_one;
86
snprintf(sig.signature, sizeof(sig.signature), "%s", tag);
90
printf("(CERT_SIGS): unexpected text: %s\n", tag);
94
if (!strcmp(tag, "/entry")) {
97
if (strlen(sig.subject) == 0) {
98
printf("ERROR: subject is not set.\n");
101
if (strlen(sig.signature) == 0) {
102
printf("ERROR: signature is not set.\n");
105
this->signatures.push_back(sig);
110
if (!strcmp(tag, "signature")) {
114
if (!strcmp(tag, "/signature")) {
118
if (xp.parse_str(tag, "subject", sig.subject, sizeof(sig.subject)))
120
else if (xp.parse_str(tag, "hash", sig.hash, sizeof(sig.hash)))
122
else if (xp.parse_str(tag, "type", buf, sizeof(buf))) {
123
if ((!strcmp(buf,"md5")) || (!strcmp(buf,"MD5"))) {
125
} else if ((!strcmp(buf,"sha1")) || (!strcmp(buf,"SHA1"))) {
126
sig.type = SHA1_HASH;
131
if (strstr(tag, "entry")) {
141
int CERT_SIGS::parse_miofile_embed(MIOFILE &mf) {
143
return this->parse(xp);
146
int CERT_SIGS::parse_file(const char* filename) {
150
FILE *f = fopen(filename, "r");
152
FCGI_FILE *f = FCGI::fopen(filename, "r");
159
if (!xp.parse_start("signatures")) {
160
return ERR_XML_PARSE;
162
retval = this->parse(xp);
167
int CERT_SIGS::parse_buffer(char* buf) {
171
mf.init_buf_read(buf);
173
retval = this->parse(xp);
177
int CERT_SIGS::parse_buffer_embed(char* buf) {
183
mf.init_buf_read(buf);
185
while (!xp.get(tag, sizeof(tag), is_tag)) {
186
if (!strcmp(tag, "signatures")) {
192
return this->parse(xp);
197
int CERT_SIGS::write(MIOFILE &f) {
198
if (this->signatures.size()==0) return true;
199
f.printf("<signatures>\n");
200
for(unsigned int i=0;i < this->signatures.size(); i++) {
201
f.printf(" <entry>\n");
202
f.printf(" <signature>\n%s\n", this->signatures.at(i).signature);
203
f.printf(" </signature>\n");
204
f.printf(" <subject>%s</subject>\n", this->signatures.at(i).subject);
205
f.printf(" <type>%s</type>\n", (this->signatures.at(i).type == MD5_HASH) ? "md5" : "sha1");
206
f.printf(" <hash>%s</hash>\n", this->signatures.at(i).hash);
207
f.printf(" </entry>\n");
209
f.printf("</signatures>\n");