Skip to content

Commit

Permalink
x509: make Windows policy parameter type version-specific (#286)
Browse files Browse the repository at this point in the history
Go 1.11 needs syscall.CertChainPolicyPara.ExtraPolicyPara to
have type syscall.Pointer, but in previous versions of Go this
had type uintptr.

As we have a fork of crypto/x509, our source code for x509 can be
a different version than the current compiler.

To allow our code to work with both 1.11 and earlier versions,
encapsulate the cast into a version-specific function.

Fixes #284
  • Loading branch information
daviddrysdale committed Jul 5, 2018
1 parent 3b560b3 commit 37a384c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
20 changes: 20 additions & 0 deletions x509/ptr_sysptr_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build go1.11

package x509

import (
"syscall"
"unsafe"
)

// For Go versions >= 1.11, the ExtraPolicyPara field in
// syscall.CertChainPolicyPara is of type syscall.Pointer. See:
// https://github.com/golang/go/commit/4869ec00e87ef

func convertToPolicyParaType(p unsafe.Pointer) syscall.Pointer {
return (syscall.Pointer)(p)
}
17 changes: 17 additions & 0 deletions x509/ptr_uint_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !go1.11

package x509

import "unsafe"

// For Go versions before 1.11, the ExtraPolicyPara field in
// syscall.CertChainPolicyPara was of type uintptr. See:
// https://github.com/golang/go/commit/4869ec00e87ef

func convertToPolicyParaType(p unsafe.Pointer) uintptr {
return uintptr(p)
}
2 changes: 1 addition & 1 deletion x509/root_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func checkChainSSLServerPolicy(c *Certificate, chainCtx *syscall.CertChainContex
sslPara.Size = uint32(unsafe.Sizeof(*sslPara))

para := &syscall.CertChainPolicyPara{
ExtraPolicyPara: uintptr(unsafe.Pointer(sslPara)),
ExtraPolicyPara: convertToPolicyParaType(unsafe.Pointer(sslPara)),
}
para.Size = uint32(unsafe.Sizeof(*para))

Expand Down

0 comments on commit 37a384c

Please sign in to comment.