Guest User

example redwax timestamping server & test case

a guest
Dec 25th, 2019
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. { config, lib, pkgs, resources, ... }:
  2. with lib;
  3. let
  4. tsWebRoot = "/data/http/ts";
  5. tsVhost = {
  6. hostName = "tss.local";
  7. documentRoot = "${tsWebRoot}/docroot";
  8. extraConfig = ''
  9. # backend configuration:
  10. #
  11. <IfModule mod_ca_simple.c>
  12. # use system clock as the time source
  13. CASimpleTime on
  14. # assign a random serial number
  15. CASimpleSerialRandom on
  16. </IfModule>
  17.  
  18. # frontend configuration
  19. <IfModule mod_timestamp.c>
  20. <Location /timestamp>
  21. SetHandler timestamp
  22. TimestampSigningCertificate "${tsWebRoot}/keys/fullchain.pem"
  23. TimestampSigningKey "${tsWebRoot}/keys/key.pem"
  24. TimestampDigest SHA256
  25. TimestampDefaultPolicy 1.2.3.4.5
  26. Require all granted
  27. </Location>
  28. </IfModule>
  29. '';
  30. };
  31. in {
  32. networking.firewall.enable = true;
  33. networking.firewall.rejectPackets = true;
  34. networking.firewall.allowPing = true;
  35. networking.firewall.allowedTCPPorts = [ 443 ];
  36.  
  37. services.httpd = {
  38. enable = true;
  39. hostName = "localhost4";
  40. adminAddr = "noc@localhost";
  41. extraModules = [
  42. { name = "ca"; path = "${pkgs.apacheHttpdPackages.mod_ca}/modules/mod_ca.so"; }
  43. { name = "ca_simple"; path = "${pkgs.apacheHttpdPackages.mod_ca}/modules/mod_ca_simple.so"; }
  44. { name = "timestamp"; path = "${pkgs.apacheHttpdPackages.mod_timestamp}/modules/mod_timestamp.so"; }
  45. ];
  46.  
  47. virtualHosts =
  48. [ {
  49. hostName = "localhost";
  50. globalRedirect = "https://localhost4/";
  51. }
  52.  
  53. (tsVhost // {
  54. enableSSL = true;
  55. sslServerKey = "${tsWebRoot}/keys/key.pem";
  56. sslServerCert = "${tsWebRoot}/keys/fullchain.pem";
  57. extraConfig = tsVhost.extraConfig +
  58. ''
  59. Header always set Strict-Transport-Security "max-age=15552000"
  60. SSLProtocol All -SSLv2 -SSLv3
  61. SSLCipherSuite HIGH:!aNULL:!MD5:!EXP
  62. SSLHonorCipherOrder on
  63. '';
  64. })
  65. ];
  66. };
  67. environment.systemPackages = [ pkgs.openssl ]; # pkgs.apacheHttpdPackages.mod_ca pkgs.apacheHttpdPackages.mod_timestamp ];
  68.  
  69. system.activationScripts.createDummyKey =
  70. let
  71. mkKeys = dir:
  72. ''
  73. dir=${dir}
  74. mkdir -m 0700 -p $dir
  75. if ! [[ -e $dir/key.pem ]]; then
  76. ${pkgs.openssl}/bin/openssl genrsa -out $dir/key-in.pem 1024
  77. ${pkgs.openssl}/bin/openssl req -new -key $dir/key-in.pem -out $dir/key.csr \
  78. -subj "/C=NL/ST=Zuid-Holland/L=Leiden/O=Koelie-Kerks/CN=Grote klokken doen bim-bam - timestamps server"
  79.  
  80. ${pkgs.openssl}/bin/openssl rsa -in $dir/key-in.pem -out $dir/key.pem
  81.  
  82. echo extendedKeyUsage=critical,timeStamping > $dir/ts.conf
  83. ${pkgs.openssl}/bin/openssl x509 -req -days 365 -in $dir/key.csr -signkey $dir/key.pem \
  84. -out $dir/fullchain.pem -extfile $dir/ts.conf
  85. fi
  86. '';
  87. in
  88. ''
  89. ${mkKeys "${tsWebRoot}/keys"}
  90. '';
  91. }
  92.  
  93. #
  94. # To test:
  95. #
  96. # 1. generate a file to sign
  97. # dd if=/dev/urandom of=data.raw count=1 bs=1024
  98. #
  99. # 2. create a signing request for this file.
  100. # openssl ts -query -data data.raw -cert -sha256 -no_nonce -out request.tsq
  101. #
  102. # 3. offer it to the signing server:
  103. # curl -k -H Content-type:application/timestamp-query -H Host:tts.local --data-binary @request.tsq https://127.0.0.1/timestamp > reply.tsq
  104. #
  105. # 4. dump the content of the reply
  106. # openssl ts -reply -text -in reply.tsq
  107. #
  108. # 5. verify that it is actually signed & valid - and matches the has of our file.
  109. # openssl ts -verify -in reqply.tsq -data data.raw -CAfile /data/http/ts/keys/fullchain.pem
  110. #
Advertisement
Add Comment
Please, Sign In to add comment