customcerttostore

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Rendered for windows/amd64

Index

Constants

View Source
const (

	// ProviderMSPlatform represents the Microsoft Platform Crypto Provider
	ProviderMSPlatform = "Microsoft Platform Crypto Provider"
	// ProviderMSSoftware represents the Microsoft Software Key Storage Provider
	ProviderMSSoftware = "Microsoft Software Key Storage Provider"
	// ProviderMSLegacy represents the CryptoAPI compatible Enhanced Cryptographic Provider
	ProviderMSLegacy = "Microsoft Enhanced Cryptographic Provider v1.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Credential

type Credential interface {
	// Public returns the public key corresponding to the leaf certificate.
	Public() crypto.PublicKey
	// Sign signs digest with the private key.
	Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) (signature []byte, err error)
	// Decrypt decrypts msg. Returns an error if not implemented.
	Decrypt(rand io.Reader, msg []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error)
}

Credential provides access to a certificate and is a crypto.Signer and crypto.Decrypter.

type DecrypterOpts

type DecrypterOpts struct {
	// Hashfunc represents the hashing function that was used during
	// encryption and is mapped to the Microsoft equivalent LPCWSTR.
	Hashfunc crypto.Hash
	// Flags represents the dwFlags parameter for NCryptDecrypt
	Flags uint32
}

DecrypterOpts implements crypto.DecrypterOpts and contains the flags required for the NCryptDecrypt system call.

type Key

type Key struct {
	Container       string
	LegacyContainer string
	AlgorithmGroup  string
	// contains filtered or unexported fields
}

Key implements crypto.Signer and crypto.Decrypter for key based operations.

func (Key) Decrypt

func (k Key) Decrypt(rand io.Reader, blob []byte, opts crypto.DecrypterOpts) ([]byte, error)

Decrypt returns the decrypted contents of the encrypted blob, and implements crypto.Decrypter for Key.

func (Key) Public

func (k Key) Public() crypto.PublicKey

Public exports a public key to implement crypto.Signer

func (Key) Sign

func (k Key) Sign(_ io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error)

Sign returns the signature of a hash to implement crypto.Signer

type WinCertStore

type WinCertStore struct {
	Prov     uintptr
	ProvName string
	// contains filtered or unexported fields
}

WinCertStore is a CertStorage implementation for the Windows Certificate Store.

func OpenWinCertStore

func OpenWinCertStore(provider, container string, issuers, intermediateIssuers []string, legacyKey, openStoreWithHandle bool) (*WinCertStore, error)

OpenWinCertStore creates a WinCertStore. when using openStoreWithHandle with handle, it is the responsbility of the caller to call Cstore.Close from the returned object

func (*WinCertStore) CertBySubjectName

func (w *WinCertStore) CertBySubjectName(subjectName string) (*x509.Certificate, *windows.CertContext, error)

cert is a function to lookup certificates based on a subject name.

func (*WinCertStore) CertKey

func (w *WinCertStore) CertKey(cert *windows.CertContext) (*Key, error)

CertKey wraps CryptAcquireCertificatePrivateKey. It obtains the CNG private key of a known certificate and returns a pointer to a Key which implements both crypto.Signer and crypto.Decrypter. When a nil cert context is passed a nil key is intentionally returned, to model the expected behavior of a non-existent cert having no private key. https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptacquirecertificateprivatekey

func (*WinCertStore) Key

func (w *WinCertStore) Key() (Credential, error)

Key opens a handle to an existing private key and returns key. Key implements both crypto.Signer and crypto.Decrypter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL