Skip to content
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

UseCertAndKey added. #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,29 @@ func (c *Ctx) UsePrivateKey(key PrivateKey) error {
return nil
}

// UserCertAndKey configures the context to use the given certificate
// and private key for the SSL handshakes.
// It allows you to use private keys that are never accessible directly
// e.g.: to which openssl has access only via Engine module.
// https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_use_cert_and_key.html
func (c *Ctx) UseCertAndKey(cert *Certificate, key *PrivateKey) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if key == nil {
//this is the case where the private key cannot be accessed here, e.g.:
//comes from the Engine (for instance a hw security module)
if int(C.SSL_CTX_use_cert_and_key(c.ctx, cert.x, nil, nil, 0)) != 1 {
return errorFromErrorQueue()
}
return nil
}
c.key = *key
if int(C.SSL_CTX_use_cert_and_key(c.ctx, cert.x, (*key).evpPKey(), nil, 0)) != 1 {
return errorFromErrorQueue()
}
return nil
}

type CertificateStore struct {
store *C.X509_STORE
// for GC
Expand Down