import_ca.lua 751 B

123456789101112131415161718192021222324252627
  1. local ssl = require "ssl"
  2. local dbi = require "DBI"
  3. local date = require "3rdparty/date"
  4. local sql = require "sql"
  5. require "certs"
  6. local sha512 = require("util.hashes").sha512;
  7. local sha256 = require("util.hashes").sha256;
  8. dbh = assert(dbi.Connect("PostgreSQL", "xmppoke", "xmppoke", "xmppoke", "localhost", 5432));
  9. local file = io.open("/etc/ssl/certs/ca-certificates.crt", "r");
  10. local str = file:read("*a");
  11. file:close();
  12. local stm = assert(dbh:prepare("UPDATE certificates SET trusted_root = ?;"));
  13. assert(stm:execute(false));
  14. for cert in str:gmatch("-----BEGIN CERTIFICATE-----\n[^-]*\n-----END CERTIFICATE-----\n") do
  15. print(ssl.x509.load(cert));
  16. assert(sql.insert_cert(dbh, ssl.x509.load(cert), nil, nil, nil, true));
  17. end
  18. dbh:commit();