Skip to content
This repository was archived by the owner on Oct 5, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
skip_branch_with_pr: true
os: 'Visual Studio 2015'

build: off

environment:
matrix:
- ARCH: x64
MSYS2_ARCH: x86_64
MSYS2_DIR: msys64
MSYSTEM: MINGW64
GOPATH: c:\gopath
GOROOT: c:\go
GOARCH: amd64
EXTLD: x86_64-w64-mingw32-gcc
- ARCH: x86
MSYS2_ARCH: i686
MSYS2_DIR: msys64
MSYSTEM: MINGW32
GOPATH: c:\gopath
GOROOT: c:\go
GOARCH: 386
EXTLD: i686-w64-mingw32-gcc

clone_folder: C:\gopath\src\github.com\mastahyeti\certstore

before_test:
# Ensure CGO is enabled
- set CGO_ENABLED=1
# Go paths
- set PATH=%GOROOT%\bin;C:\%GOPATH%\bin;%PATH%
# MSYS paths
- set PATH=C:\%MSYS2_DIR%\%MSYSTEM%\bin;C:\%MSYS2_DIR%\usr\bin;%PATH%
# Install build deps
- bash -lc "for n in `seq 1 3`; do pacman --noconfirm -S mingw-w64-%MSYS2_ARCH%-libtool && break || sleep 15; done"
# Install Go deps
- go get -t -v ./...

test_script:
- go test -v ./...
13 changes: 0 additions & 13 deletions appveyor.yml

This file was deleted.

17 changes: 12 additions & 5 deletions certstore_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,18 @@ func (s *winStore) Identities() ([]Identity, error) {
goto fail
}

// maximum chain length. this is arbitrary
const maxChain = 1 << 30
// not sure why this isn't 1 << 29
const maxPointerArray = 1 << 28

// rgpChain is actually an array, but we only care about the first one.
simpleChain := *chainCtx.rgpChain
if simpleChain.cElement < 1 || simpleChain.cElement > maxChain {
if simpleChain.cElement < 1 || simpleChain.cElement > maxPointerArray {
err = errors.New("bad chain")
goto fail
}

// Hacky way to get chain elements (c array) as a slice.
chainElts := (*[maxChain]C.PCERT_CHAIN_ELEMENT)(unsafe.Pointer(simpleChain.rgpElement))[:simpleChain.cElement:simpleChain.cElement]
chainElts := (*[maxPointerArray]C.PCERT_CHAIN_ELEMENT)(unsafe.Pointer(simpleChain.rgpElement))[:simpleChain.cElement:simpleChain.cElement]

// Build chain of certificates from each elt's certificate context.
chain := make([]C.PCCERT_CONTEXT, len(chainElts))
Expand Down Expand Up @@ -654,10 +654,17 @@ func (ss securityStatus) Error() string {
}

func stringToUTF16(s string) C.LPCWSTR {
// Not sure why this isn't 1 << 30...
const maxUint16Array = 1 << 29

if len(s) > maxUint16Array {
panic("string too long")
}

wstr := utf16.Encode([]rune(s))

p := C.calloc(C.size_t(len(wstr)+1), C.size_t(unsafe.Sizeof(uint16(0))))
pp := (*[1 << 30]uint16)(p)
pp := (*[maxUint16Array]uint16)(p)
copy(pp[:], wstr)

return (C.LPCWSTR)(p)
Expand Down