github.com/psiphon-labs/psiphon-tunnel-core@v2.0.28+incompatible/psiphon/common/quic/gquic-go/quic-go-certificates/createCertSets.rb (about)

     1  #!/usr/bin/env ruby
     2  #
     3  # Extract the common certificate sets from the chromium source to go
     4  #
     5  # Usage:
     6  # createCertSets.rb 1 ~/src/chromium/src/net/quic/crypto/common_cert_set_1*
     7  # createCertSets.rb 2 ~/src/chromium/src/net/quic/crypto/common_cert_set_2*
     8  
     9  n = ARGV.shift
    10  mainFile = ARGV.shift
    11  dataFiles = ARGV
    12  
    13  data = "package certsets\n"
    14  data += File.read(mainFile)
    15  data += (dataFiles.map{|p| File.read(p)}).join
    16  
    17  # Good enough
    18  data.gsub!(/\/\*(.*?)\*\//m, '')
    19  data.gsub!(/^#include.+/, '')
    20  data.gsub!(/^#if 0(.*?)\n#endif/m, '')
    21  
    22  data.gsub!(/^static const size_t kNumCerts.+/, '')
    23  data.gsub!(/static const size_t kLens[^}]+};/m, '')
    24  
    25  data.gsub!('static const unsigned char* const kCerts[] = {', "var CertSet#{n} = [][]byte{")
    26  data.gsub!('static const uint64_t kHash = UINT64_C', "const CertSet#{n}Hash uint64 = ")
    27  
    28  data.gsub!(/static const unsigned char kDERCert(\d+)\[\] = /, "var kDERCert\\1 = []byte")
    29  
    30  data.gsub!(/kDERCert(\d+)/, "certSet#{n}Cert\\1")
    31  
    32  File.write("cert_set_#{n}.go", data)
    33  
    34  system("gofmt -w -s cert_set_#{n}.go")