-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Root certs are not used on Windows #67
Open
Kurlee
wants to merge
15
commits into
github:main
Choose a base branch
from
Kurlee:BugFix/RootCerts_windows
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c6e2b3c
Bug fix for windows where the root store was not being parsed, and in…
a07e162
Split the root store parsing function into two different functions th…
af31508
Fixed errors with OSX with windows specific syscalls. Split the funct…
9e78f91
Forgot to include dependancies in the parse_root unix implementation
aa2798c
Merge branch 'main' into BugFix/RootCerts_windows
lgarron 071351b
Update tests to allow chains in any order. Fixes #68.
lgarron 80e6d29
Change `BEGING_SIGNING` to `BEGIN_SIGNING`.
lgarron 2e17a57
Update dependencies and references for v0.1.0
lgarron d02f769
Set Appveyor branch to `main`.
lgarron a76a9f1
Update build status link.
lgarron 4b058f1
Resolved conflicts from rebase with upstream repo
2639b83
Merge branch 'main' into BugFix/RootCerts_windows
Kurlee aacfb7e
Added a defer statement to ensure that there is a syscall to close th…
1517782
Use gocertifi certificate pool as a baseline and add system trusted r…
2e16ab6
Merge branch 'BugFix/RootCerts_windows' of github.com:Kurlee/smimesig…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,22 @@ | ||
// +build !windows | ||
|
||
package main | ||
|
||
import ( | ||
"crypto/x509" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func parseRoots(roots *x509.CertPool ) error{ | ||
roots, err := x509.SystemCertPool() | ||
if err != nil { | ||
return errors.Wrap(err, "Failed to parse root store") | ||
} | ||
|
||
for _, ident := range idents { | ||
if cert, err := ident.Certificate(); err == nil { | ||
roots.AddCert(cert) | ||
} | ||
} | ||
return nil | ||
} |
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,65 @@ | ||
// +build windows | ||
|
||
package main | ||
|
||
import ( | ||
"crypto/x509" | ||
"github.com/certifi/gocertifi" | ||
"github.com/pkg/errors" | ||
"syscall" | ||
"unsafe" | ||
) | ||
|
||
const ( | ||
CryptENotFound = 0x80092004 | ||
) | ||
|
||
func parseRoots(roots *x509.CertPool) error{ | ||
|
||
// The windows trust store is dynamically populated, to prevent issues with generally trusted | ||
// roots not being enumerated, use the mozilla trust store as a baseline | ||
roots, err := gocertifi.CACerts() | ||
if err != nil { | ||
roots = x509.NewCertPool() | ||
} | ||
|
||
// Enumerate the local machine trust store and add any missing certificates. | ||
storeName, err:= syscall.UTF16PtrFromString("Root") | ||
if err != nil { | ||
return errors.Wrap(err, "Failed to get root store name") | ||
} | ||
storeHandle, err := syscall.CertOpenSystemStore(0, storeName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see a call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a defered call to |
||
if err != nil { | ||
return errors.New(syscall.GetLastError().Error()) | ||
} | ||
defer syscall.CertCloseStore(storeHandle, 0) | ||
|
||
var cert *syscall.CertContext | ||
for { | ||
cert, err = syscall.CertEnumCertificatesInStore(storeHandle, cert) | ||
if err != nil { | ||
if errno, ok := err.(syscall.Errno); ok { | ||
if errno == CryptENotFound { | ||
break | ||
} | ||
} | ||
return errors.New(syscall.GetLastError().Error()) | ||
} | ||
if cert == nil { | ||
break | ||
} | ||
// Copy the buf, since ParseCertificate does not create its own copy. | ||
buf := (*[1 << 20]byte)(unsafe.Pointer(cert.EncodedCert))[:] | ||
buf2 := make([]byte, cert.Length) | ||
copy(buf2, buf) | ||
if c, err := x509.ParseCertificate(buf2); err == nil { | ||
// AddCert contains logic to prevent adding a duplicate certificate to the pool | ||
roots.AddCert(c) | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
return nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also continue to fallback to
gocertifi.CACerts()
if we cannot open theSystemCertPool
on macOS / Linux.While the fallback path was primarily there for Windows support, macOS could still have a non-nil
err
if opening the root store failed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I’ll go ahead and get to work on implementing this