// Copyright 2015-2016 Brian Smith. // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above // copyright notice and this permission notice appear in all copies. // // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern crate ring; extern crate webpki; extern crate untrusted; use std::fs::{File, read_dir}; use std::io::{Read, Write}; use std::path::Path; use webpki::trust_anchor_util::*; /// This build script reads all the DER-encoded X.509 certificates in /// trust-anchors/*.crt and generates a the source code for an array of /// TrustAnchors. That snippet is written to a file that is then included by /// verify_tls_cert.rs. /// /// This demonstrates the intended usage of `webpki::trust_anchor_util`. fn main() { let mut certs = Vec::>::new(); for dir_entry in read_dir(&Path::new("trust-anchors")).unwrap() { let path = dir_entry.unwrap().path(); println!("{}", path.display()); if path.extension().unwrap() != "crt" { println!("skipping"); continue; } let mut cert_der = Vec::::new(); let mut f = File::open(path).unwrap(); f.read_to_end(&mut cert_der).unwrap(); certs.push(cert_der); } let trust_anchors: Vec<_> = certs.iter() .map(|der| { cert_der_as_trust_anchor(untrusted::Input::from(der)).unwrap() }).collect(); let code = generate_code_for_trust_anchors(&"TRUST_ANCHORS", &trust_anchors); let out_dir = std::env::var("OUT_DIR").unwrap(); let dest_path = Path::new(&out_dir).join("trust_anchors.rs"); let mut f = File::create(&dest_path).unwrap(); f.write_all(code.as_bytes()).unwrap(); }