19 using std::stringstream;
22 static const char *source_filename =
"ca-bundle.crt";
23 static const char *target_filename =
"ca_bundle_data_src.c";
26 main(
int argc,
char *argv[]) {
27 FILE *fin = fopen(source_filename,
"r");
29 cerr <<
"Couldn't open " << source_filename <<
" for reading.\n";
34 OpenSSLWrapper::get_global_ptr();
39 STACK_OF(X509_INFO) *inf;
40 inf = PEM_X509_INFO_read(fin,
nullptr,
nullptr,
nullptr);
44 cerr <<
"Couldn't read PEM file in " << source_filename <<
"\n";
48 cerr <<
"PEM_X509_INFO_read() found " << sk_X509_INFO_num(inf)
52 std::stringstream der_stream;
55 int num_entries = sk_X509_INFO_num(inf);
56 for (
int i = 0; i < num_entries; i++) {
57 X509_INFO *itmp = sk_X509_INFO_value(inf, i);
60 X509 *cert = itmp->x509;
62 int der_len = i2d_X509(cert,
nullptr);
63 unsigned char *der_buf =
new unsigned char[der_len];
64 unsigned char *p = der_buf;
66 der_stream.write((
const char *)der_buf, der_len);
71 sk_X509_INFO_pop_free(inf, X509_INFO_free);
78 Filename target = Filename::text_filename(
string(target_filename));
80 cerr <<
"Couldn't open " << target_filename <<
" for writing.\n";
85 std::istream &in = der_stream;
87 string table_type =
"const unsigned char ";
88 string length_type =
"const int ";
89 string table_name =
"ca_bundle_data";
90 string static_keyword =
"static ";
91 static const int col_width = 11;
95 <<
" * This table was generated by the command:\n" 97 <<
" * make_ca_bundle\n" 99 <<
" * which is a \"test\" program in the express directory; it reads\n" 100 <<
" * ca-bundle.crt and produces this file.\n" 102 <<
" * This file represents the set of well-known certificate authorities\n" 103 <<
" * in DER form, for compiling into OpenSSLWrapper.\n" 105 << static_keyword << table_type << table_name <<
"[] = {";
106 out << std::hex << std::setfill(
'0');
111 while (!in.fail() && ch != EOF) {
114 }
else if (col == col_width) {
120 out <<
"0x" << std::setw(2) << ch;
126 << static_keyword << length_type << table_name <<
"_len = " 127 << std::dec << count <<
";\n\n";
129 cerr <<
"Wrote " << cert_count <<
" certificates to " 130 << target_filename <<
"\n";
bool open_write(std::ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.