cert_sig.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // This file is part of BOINC.
  2. // http://boinc.berkeley.edu
  3. // Copyright (C) 2008 University of California
  4. //
  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.
  9. //
  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.
  14. //
  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/>.
  17. #ifndef BOINC_CERT_SIG_H
  18. #define BOINC_CERT_SIG_H
  19. #include <vector>
  20. #include "parse.h"
  21. #define MAX_CERT_SIG_LEN 4096
  22. #define MAX_SUBJECT_LEN 256
  23. #define MD5_HASH 0
  24. #define SHA1_HASH 1
  25. struct CERT_SIG {
  26. char signature[MAX_CERT_SIG_LEN]; // RSA signature expected.
  27. int type; // MD5_HASH or SHA1_HASH. Not used yet.
  28. char subject[MAX_SUBJECT_LEN];
  29. char hash[9]; // 8 + '\0'...
  30. CERT_SIG();
  31. ~CERT_SIG();
  32. void clear();
  33. };
  34. struct CERT_SIGS {
  35. std::vector<CERT_SIG> signatures;
  36. CERT_SIGS();
  37. ~CERT_SIGS();
  38. //
  39. // Parses an .xml signature file with the following structure:
  40. //
  41. //<signatures>
  42. // <entry>
  43. // <signature>
  44. //%signature%
  45. // </signature>
  46. // <subject>%certificate_subject%</subject>
  47. // <type>%md5_or_sha1(_with_rsa)%</type>
  48. // <hash>%certificate_hash%</hash>
  49. // </entry>
  50. // <entry>
  51. // ...
  52. // </entry>
  53. // ...
  54. //</signatures>
  55. int parse_file(const char* filename);
  56. int parse_buffer(char* buf);
  57. int write(MIOFILE &f);
  58. int parse_buffer_embed(char* buf);
  59. void clear();
  60. int count(); // return the total number of signatures.
  61. int parse(XML_PARSER &xp);
  62. };
  63. #endif // BOINC_CERT_SIG_H