-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SSL certificate verify GitHub action (#13697)
* Implement SSL/TLS certificate checking #782 * SSL: Add nimDisableCertificateValidation Remove NIM_SSL_CERT_VALIDATION env var tests/untestable/thttpclient_ssl.nim ran successfully on Linux with libssl 1.1.1d * SSL: update integ test to skip flapping tests * Revert .travis.yml change * nimDisableCertificateValidation disable imports Prevent loading symbols that are not defined on older SSL libs * SSL: disable verification in net.nim ..when nimDisableCertificateValidation is set * Update changelog * Fix peername type * Add define check for windows * Disable test on windows * Add exprimental GitHub action CI for SSL * Test nimDisableCertificateValidation
- Loading branch information
Federico Ceratto
authored
Mar 20, 2020
1 parent
1d665ad
commit 5b85444
Showing
13 changed files
with
872 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: Nim SSL CI | ||
on: | ||
pull_request: | ||
# Run only on changes on related files | ||
paths: | ||
- 'lib/pure/httpclient.nim' | ||
- 'lib/pure/net.nim' | ||
- 'lib/pure/ssl_certs.nim' | ||
- 'lib/wrappers/openssl.nim' | ||
- 'tests/stdlib/thttpclient_ssl*' | ||
- 'tests/untestable/thttpclient_ssl*' | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-18.04, macos-10.15, windows-2019] | ||
cpu: [amd64] | ||
name: '${{ matrix.os }} (${{ matrix.cpu }})' | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: 'Checkout' | ||
uses: actions/checkout@v2 | ||
|
||
- name: 'Checkout csources' | ||
uses: actions/checkout@v2 | ||
with: | ||
repository: nim-lang/csources | ||
path: csources | ||
|
||
- name: 'Install dependencies (Linux amd64)' | ||
if: runner.os == 'Linux' && matrix.cpu == 'amd64' | ||
run: | | ||
sudo apt-fast update -qq | ||
DEBIAN_FRONTEND='noninteractive' \ | ||
sudo apt-fast install --no-install-recommends -y libssl1.1 | ||
- name: 'Install dependencies (macOS)' | ||
if: runner.os == 'macOS' | ||
run: brew install make | ||
- name: 'Install dependencies (Windows)' | ||
if: runner.os == 'Windows' | ||
shell: bash | ||
run: | | ||
mkdir dist | ||
curl -L https://nim-lang.org/download/mingw64.7z -o dist/mingw64.7z | ||
curl -L https://nim-lang.org/download/dlls.zip -o dist/dlls.zip | ||
7z x dist/mingw64.7z -odist | ||
7z x dist/dlls.zip -obin | ||
echo "::add-path::${{ github.workspace }}/dist/mingw64/bin" | ||
- name: 'Add build binaries to PATH' | ||
shell: bash | ||
run: echo "::add-path::${{ github.workspace }}/bin" | ||
|
||
- name: 'Build 1-stage compiler from csources' | ||
shell: bash | ||
run: | | ||
ncpu= | ||
case '${{ runner.os }}' in | ||
'Linux') | ||
ncpu=$(nproc) | ||
;; | ||
'macOS') | ||
ncpu=$(sysctl -n hw.ncpu) | ||
;; | ||
'Windows') | ||
ncpu=$NUMBER_OF_PROCESSORS | ||
;; | ||
esac | ||
[[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1 | ||
make -C csources -j $ncpu CC=gcc ucpu='${{ matrix.cpu }}' | ||
- name: 'Build koch' | ||
shell: bash | ||
run: nim c koch | ||
|
||
- name: 'Build the real compiler' | ||
shell: bash | ||
run: ./koch boot | ||
|
||
- name: 'Run SSL nimDisableCertificateValidation integration tests' | ||
shell: bash | ||
run: nim c -d:nimDisableCertificateValidation -d:ssl -r -p:. tests/untestable/thttpclient_ssl_disabled.nim | ||
|
||
- name: 'Run SSL certificate check integration tests' | ||
# Not supported on Windows due to old openssl version | ||
if: runner.os != 'Windows' | ||
shell: bash | ||
run: nim c -d:ssl -p:. --threads:on -r tests/untestable/thttpclient_ssl.nim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ install: | |
- cd .. | ||
|
||
build_script: | ||
- openssl version | ||
- openssl version -d | ||
- bin\nim c koch | ||
- koch runCI | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# | ||
# | ||
# Nim's Runtime Library | ||
# (c) Copyright 2017 Nim contributors | ||
# | ||
# See the file "copying.txt", included in this | ||
# distribution, for details about the copyright. | ||
# | ||
## Scan for SSL/TLS CA certificates on disk | ||
## The default locations can be overridden using the SSL_CERT_FILE and | ||
## SSL_CERT_DIR environment variables. | ||
|
||
import os, strutils | ||
from ospaths import existsEnv, getEnv | ||
import strutils | ||
|
||
# SECURITY: this unnecessarily scans through dirs/files regardless of the | ||
# actual host OS/distribution. Hopefully all the paths are writeble only by | ||
# root. | ||
|
||
# FWIW look for files before scanning entire dirs. | ||
|
||
const certificate_paths = [ | ||
# Debian, Ubuntu, Arch: maintained by update-ca-certificates, SUSE, Gentoo | ||
# NetBSD (security/mozilla-rootcerts) | ||
# SLES10/SLES11, https://golang.org/issue/12139 | ||
"/etc/ssl/certs/ca-certificates.crt", | ||
# OpenSUSE | ||
"/etc/ssl/ca-bundle.pem", | ||
# Red Hat 5+, Fedora, Centos | ||
"/etc/pki/tls/certs/ca-bundle.crt", | ||
# Red Hat 4 | ||
"/usr/share/ssl/certs/ca-bundle.crt", | ||
# FreeBSD (security/ca-root-nss package) | ||
"/usr/local/share/certs/ca-root-nss.crt", | ||
# CentOS/RHEL 7 | ||
"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", | ||
# OpenBSD, FreeBSD (optional symlink) | ||
"/etc/ssl/cert.pem", | ||
# Mac OS X | ||
"/System/Library/OpenSSL/certs/cert.pem", | ||
# Fedora/RHEL | ||
"/etc/pki/tls/certs", | ||
# Android | ||
"/system/etc/security/cacerts", | ||
# FreeBSD | ||
"/usr/local/share/certs", | ||
# NetBSD | ||
"/etc/openssl/certs", | ||
] | ||
|
||
iterator scanSSLCertificates*(useEnvVars = false): string = | ||
## Scan for SSL/TLS CA certificates on disk. | ||
## | ||
## if `useEnvVars` is true, the SSL_CERT_FILE and SSL_CERT_DIR | ||
## environment variables can be used to override the certificate | ||
## directories to scan or specify a CA certificate file. | ||
if existsEnv("SSL_CERT_FILE"): | ||
yield getEnv("SSL_CERT_FILE") | ||
|
||
elif existsEnv("SSL_CERT_DIR"): | ||
let p = getEnv("SSL_CERT_DIR") | ||
for fn in joinPath(p, "*").walkFiles(): | ||
yield fn | ||
|
||
else: | ||
for p in certificate_paths: | ||
if p.endsWith(".pem") or p.endsWith(".crt"): | ||
if existsFile(p): | ||
yield p | ||
elif existsDir(p): | ||
for fn in joinPath(p, "*").walkFiles(): | ||
yield fn | ||
|
||
# Certificates management on windows | ||
# when defined(windows) or defined(nimdoc): | ||
# | ||
# import openssl | ||
# | ||
# type | ||
# PCCertContext {.final, pure.} = pointer | ||
# X509 {.final, pure.} = pointer | ||
# CertStore {.final, pure.} = pointer | ||
# | ||
# # OpenSSL cert store | ||
# | ||
# {.push stdcall, dynlib: "kernel32", importc.} | ||
# | ||
# proc CertOpenSystemStore*(hprov: pointer=nil, szSubsystemProtocol: cstring): CertStore | ||
# | ||
# proc CertEnumCertificatesInStore*(hCertStore: CertStore, pPrevCertContext: PCCertContext): pointer | ||
# | ||
# proc CertFreeCertificateContext*(pContext: PCCertContext): bool | ||
# | ||
# proc CertCloseStore*(hCertStore:CertStore, flags:cint): bool | ||
# | ||
# {.pop.} |
Oops, something went wrong.