15 #include "pandabase.h" 16 #include "openSSLWrapper.h" 19 static const char *source_filename =
"ca-bundle.crt";
20 static const char *target_filename =
"ca_bundle_data_src.c";
23 main(
int argc,
char *argv[]) {
24 FILE *fin = fopen(source_filename,
"r");
26 cerr <<
"Couldn't open " << source_filename <<
" for reading.\n";
31 OpenSSLWrapper::get_global_ptr();
36 STACK_OF(X509_INFO) *inf;
37 inf = PEM_X509_INFO_read(fin, NULL, NULL, NULL);
41 cerr <<
"Couldn't read PEM file in " << source_filename <<
"\n";
45 cerr <<
"PEM_X509_INFO_read() found " << sk_X509_INFO_num(inf)
52 int num_entries = sk_X509_INFO_num(inf);
53 for (
int i = 0; i < num_entries; i++) {
54 X509_INFO *itmp = sk_X509_INFO_value(inf, i);
57 X509 *cert = itmp->x509;
59 int der_len = i2d_X509(cert, NULL);
60 unsigned char *der_buf =
new unsigned char[der_len];
61 unsigned char *p = der_buf;
63 der_stream.write((
const char *)der_buf, der_len);
68 sk_X509_INFO_pop_free(inf, X509_INFO_free);
75 Filename target = Filename::text_filename(
string(target_filename));
77 cerr <<
"Couldn't open " << target_filename <<
" for writing.\n";
82 istream &in = der_stream;
84 string table_type =
"const unsigned char ";
85 string length_type =
"const int ";
86 string table_name =
"ca_bundle_data";
87 string static_keyword =
"static ";
88 static const int col_width = 11;
92 <<
" * This table was generated by the command:\n" 94 <<
" * make_ca_bundle\n" 96 <<
" * which is a \"test\" program in the express directory; it reads\n" 97 <<
" * ca-bundle.crt and produces this file.\n" 99 <<
" * This file represents the set of well-known certificate authorities\n" 100 <<
" * in DER form, for compiling into OpenSSLWrapper.\n" 102 << static_keyword << table_type << table_name <<
"[] = {";
103 out << hex << setfill(
'0');
108 while (!in.fail() && !in.eof()) {
111 }
else if (col == col_width) {
117 out <<
"0x" << setw(2) << ch;
123 << static_keyword << length_type << table_name <<
"_len = " 124 << dec << count <<
";\n\n";
126 cerr <<
"Wrote " << cert_count <<
" certificates to " 127 << target_filename <<
"\n";
bool open_write(ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
The name of a file, such as a texture file or an Egg file.