forked from cyolosecurity/certstore
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcertstore.go
More file actions
71 lines (56 loc) · 1.91 KB
/
certstore.go
File metadata and controls
71 lines (56 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package certstore
import (
"crypto"
"crypto/x509"
"errors"
)
var (
// ErrUnsupportedHash is returned by Signer.Sign() when the provided hash
// algorithm isn't supported.
ErrUnsupportedHash = errors.New("unsupported hash algorithm")
)
// StoreLocation defines the store location to look certificates in.
type StoreLocation int
const (
// User is the user scoped certificate store. "CURRENT_USER" on Windows or
// "login" on MacOS
User StoreLocation = iota
// System is the system scoped certificate store. "LOCAL_MACHINE" on Windows
// or "System" on MacOS
System
)
// StorePermission defines the store permission to open the store with
type StorePermission int
const (
// ReadOnly is the store permission allows reading and using certificates
ReadOnly StorePermission = iota
// ReadWrite is the store permission that allows importing certificates
ReadWrite
)
// Open opens the system's certificate store.
func Open(location StoreLocation, permissions ...StorePermission) (Store, error) {
return openStore(location, permissions...)
}
// Store represents the system's certificate store.
type Store interface {
// Identities gets a list of identities from the store.
Identities() ([]Identity, error)
// Import imports a PKCS#12 (PFX) blob containing a certificate and private
// key.
Import(data []byte, password string) error
// Close closes the store.
Close()
}
// Identity is a X.509 certificate and its corresponding private key.
type Identity interface {
// Certificate gets the identity's certificate.
Certificate() (*x509.Certificate, error)
// CertificateChain attempts to get the identity's full certificate chain.
CertificateChain() ([]*x509.Certificate, error)
// Signer gets a crypto.Signer that uses the identity's private key.
Signer() (crypto.Signer, error)
// Delete deletes this identity from the system.
Delete() error
// Close any manually managed memory held by the Identity.
Close()
}