talimat 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. # Description: Certificate Authority certificates, the Public Key Infrastructure.
  2. # URL: http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt?raw=1
  3. # Packager: milisarge@gmail.com
  4. name=ca-certificates
  5. version=20160110
  6. release=1
  7. source=(http://downloads.nutyx.org/files/$name-$version.tar.gz)
  8. build() {
  9. mkdir -p $PKG/{bin,etc/ssl}
  10. cp $SRC/ca-bundle.crt $PKG/etc/ssl/
  11. cp -a $SRC/certs $PKG/etc/ssl/certs
  12. # script to reformat a certificate into a form needed by openssl.
  13. cat > $PKG/bin/make-cert.pl << "EOF"
  14. #!/usr/bin/perl -w
  15. # Used to generate PEM encoded files from Mozilla certdata.txt.
  16. # Run as ./mkcrt.pl > certificate.crt
  17. #
  18. # Parts of this script courtesy of RedHat (mkcabundle.pl)
  19. #
  20. # This script modified for use with single file data (tempfile.cer) extracted
  21. # from certdata.txt, taken from the latest version in the Mozilla NSS source.
  22. # mozilla/security/nss/lib/ckfw/builtins/certdata.txt
  23. #
  24. # Authors: DJ Lucas
  25. # Bruce Dubbs
  26. #
  27. # Version 20120211
  28. my $certdata = './tempfile.cer';
  29. open( IN, "cat $certdata|" )
  30. || die "could not open $certdata";
  31. my $incert = 0;
  32. while ( <IN> )
  33. {
  34. if ( /^CKA_VALUE MULTILINE_OCTAL/ )
  35. {
  36. $incert = 1;
  37. open( OUT, "|openssl x509 -text -inform DER -fingerprint" )
  38. || die "could not pipe to openssl x509";
  39. }
  40. elsif ( /^END/ && $incert )
  41. {
  42. close( OUT );
  43. $incert = 0;
  44. print "\n\n";
  45. }
  46. elsif ($incert)
  47. {
  48. my @bs = split( /\\/ );
  49. foreach my $b (@bs)
  50. {
  51. chomp $b;
  52. printf( OUT "%c", oct($b) ) unless $b eq '';
  53. }
  54. }
  55. }
  56. EOF
  57. chmod +x $PKG/bin/make-cert.pl
  58. # script to creates the certificates and a bundle of all the certificates.
  59. cat > $PKG/bin/make-ca.sh << "EOF"
  60. #!/bin/bash
  61. # Begin make-ca.sh
  62. # Script to populate OpenSSL's CApath from a bundle of PEM formatted CAs
  63. #
  64. # The file certdata.txt must exist in the local directory
  65. # Version number is obtained from the version of the data.
  66. #
  67. # Authors: DJ Lucas
  68. # Bruce Dubbs
  69. #
  70. # Version 20120211
  71. certdata="certdata.txt"
  72. if [ ! -r $certdata ]; then
  73. echo "$certdata must be in the local directory"
  74. exit 1
  75. fi
  76. REVISION=$(grep CVS_ID $certdata | cut -f4 -d'$')
  77. if [ -z "${REVISION}" ]; then
  78. echo "$certfile has no 'Revision' in CVS_ID"
  79. exit 1
  80. fi
  81. VERSION=$(echo $REVISION | cut -f2 -d" ")
  82. TEMPDIR=$(mktemp -d)
  83. TRUSTATTRIBUTES="CKA_TRUST_SERVER_AUTH"
  84. BUNDLE="BLFS-ca-bundle-${VERSION}.crt"
  85. CONVERTSCRIPT="/bin/make-cert.pl"
  86. SSLDIR="/etc/ssl"
  87. mkdir "${TEMPDIR}/certs"
  88. # Get a list of staring lines for each cert
  89. CERTBEGINLIST=$(grep -n "^# Certificate" "${certdata}" | cut -d ":" -f1)
  90. # Get a list of ending lines for each cert
  91. CERTENDLIST=`grep -n "^CKA_TRUST_STEP_UP_APPROVED" "${certdata}" | cut -d ":" -f 1`
  92. # Start a loop
  93. for certbegin in ${CERTBEGINLIST}; do
  94. for certend in ${CERTENDLIST}; do
  95. if test "${certend}" -gt "${certbegin}"; then
  96. break
  97. fi
  98. done
  99. # Dump to a temp file with the name of the file as the beginning line number
  100. sed -n "${certbegin},${certend}p" "${certdata}" > "${TEMPDIR}/certs/${certbegin}.tmp"
  101. done
  102. unset CERTBEGINLIST CERTDATA CERTENDLIST certebegin certend
  103. mkdir -p certs
  104. rm certs/* # Make sure the directory is clean
  105. for tempfile in ${TEMPDIR}/certs/*.tmp; do
  106. # Make sure that the cert is trusted...
  107. grep "CKA_TRUST_SERVER_AUTH" "${tempfile}" | \
  108. egrep "TRUST_UNKNOWN|NOT_TRUSTED" > /dev/null
  109. if test "${?}" = "0"; then
  110. # Throw a meaningful error and remove the file
  111. cp "${tempfile}" tempfile.cer
  112. perl ${CONVERTSCRIPT} > tempfile.crt
  113. keyhash=$(openssl x509 -noout -in tempfile.crt -hash)
  114. echo "Certificate ${keyhash} is not trusted! Removing..."
  115. rm -f tempfile.cer tempfile.crt "${tempfile}"
  116. continue
  117. fi
  118. # If execution made it to here in the loop, the temp cert is trusted
  119. # Find the cert data and generate a cert file for it
  120. cp "${tempfile}" tempfile.cer
  121. perl ${CONVERTSCRIPT} > tempfile.crt
  122. keyhash=$(openssl x509 -noout -in tempfile.crt -hash)
  123. mv tempfile.crt "certs/${keyhash}.pem"
  124. rm -f tempfile.cer "${tempfile}"
  125. echo "Created ${keyhash}.pem"
  126. done
  127. # Remove blacklisted files
  128. # MD5 Collision Proof of Concept CA
  129. if test -f certs/8f111d69.pem; then
  130. echo "Certificate 8f111d69 is not trusted! Removing..."
  131. rm -f certs/8f111d69.pem
  132. fi
  133. # Finally, generate the bundle and clean up.
  134. cat certs/*.pem > ${BUNDLE}
  135. rm -r "${TEMPDIR}"
  136. EOF
  137. chmod +x $PKG/bin/make-ca.sh
  138. # script to remove expired certificates from a directory
  139. cat > $PKG/bin/remove-expired-certs.sh << "EOF"
  140. #!/bin/bash
  141. # Begin /bin/remove-expired-certs.sh
  142. #
  143. # Version 20120211
  144. # Make sure the date is parsed correctly on all systems
  145. function mydate()
  146. {
  147. local y=$( echo $1 | cut -d" " -f4 )
  148. local M=$( echo $1 | cut -d" " -f1 )
  149. local d=$( echo $1 | cut -d" " -f2 )
  150. local m
  151. if [ ${d} -lt 10 ]; then d="0${d}"; fi
  152. case $M in
  153. Jan) m="01";;
  154. Feb) m="02";;
  155. Mar) m="03";;
  156. Apr) m="04";;
  157. May) m="05";;
  158. Jun) m="06";;
  159. Jul) m="07";;
  160. Aug) m="08";;
  161. Sep) m="09";;
  162. Oct) m="10";;
  163. Nov) m="11";;
  164. Dec) m="12";;
  165. esac
  166. certdate="${y}${m}${d}"
  167. }
  168. OPENSSL="`which openssl`"
  169. DIR=/etc/ssl/certs
  170. if [ $# -gt 0 ]; then
  171. DIR="$1"
  172. fi
  173. certs=$( find ${DIR} -type f -name "*.pem" -o -name "*.crt" )
  174. today=$( date +%Y%m%d )
  175. for cert in $certs; do
  176. notafter=$( $OPENSSL x509 -enddate -in "${cert}" -noout )
  177. date=$( echo ${notafter} | sed 's/^notAfter=//' )
  178. mydate "$date"
  179. if [ ${certdate} -lt ${today} ]; then
  180. echo "${cert} expired on ${certdate}! Removing..."
  181. rm -f "${cert}"
  182. fi
  183. done
  184. EOF
  185. chmod +x $PKG/bin/remove-expired-certs.sh
  186. }