mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-13 16:01:28 +05:30
Bump github.com/danieljoos/wincred to v1.1.2
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
+2
@@ -21,3 +21,5 @@ _testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
|
||||
coverage.txt
|
||||
|
||||
+50
-3
@@ -3,9 +3,11 @@ wincred
|
||||
|
||||
Go wrapper around the Windows Credential Manager API functions.
|
||||
|
||||

|
||||
[](https://godoc.org/github.com/danieljoos/wincred)
|
||||
|
||||
[](https://github.com/danieljoos/wincred/releases/latest)
|
||||
[](https://github.com/danieljoos/wincred/actions?query=workflow%3Atest)
|
||||
[](https://goreportcard.com/report/github.com/danieljoos/wincred)
|
||||
[](https://codecov.io/gh/danieljoos/wincred)
|
||||
[](https://pkg.go.dev/github.com/danieljoos/wincred)
|
||||
|
||||
Installation
|
||||
------------
|
||||
@@ -96,3 +98,48 @@ func main() {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Hints
|
||||
-----
|
||||
|
||||
### Encoding
|
||||
|
||||
The credential objects simply store byte arrays without specific meaning or encoding.
|
||||
For sharing between different applications, it might make sense to apply an explicit string encoding - for example **UTF-16 LE** (used nearly everywhere in the Win32 API).
|
||||
|
||||
```Go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/danieljoos/wincred"
|
||||
"golang.org/x/text/encoding/unicode"
|
||||
"golang.org/x/text/transform"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cred := wincred.NewGenericCredential("myGoApplication")
|
||||
|
||||
encoder := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM).NewEncoder()
|
||||
blob, _, err := transform.Bytes(encoder, []byte("mysecret"))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cred.CredentialBlob = blob
|
||||
err = cred.Write()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### Limitations
|
||||
|
||||
The size of a credential blob is limited to **2560 Bytes** by the Windows API.
|
||||
|
||||
+12
-27
@@ -5,30 +5,11 @@ package wincred
|
||||
import (
|
||||
"encoding/binary"
|
||||
"reflect"
|
||||
"syscall"
|
||||
"time"
|
||||
"unicode/utf16"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// uf16PtrToString creates a Go string from a pointer to a UTF16 encoded zero-terminated string.
|
||||
// Such pointers are returned from the Windows API calls.
|
||||
// The function creates a copy of the string.
|
||||
func utf16PtrToString(wstr *uint16) string {
|
||||
if wstr != nil {
|
||||
for len := 0; ; len++ {
|
||||
ptr := unsafe.Pointer(uintptr(unsafe.Pointer(wstr)) + uintptr(len)*unsafe.Sizeof(*wstr)) // see https://golang.org/pkg/unsafe/#Pointer (3)
|
||||
if *(*uint16)(ptr) == 0 {
|
||||
return string(utf16.Decode(*(*[]uint16)(unsafe.Pointer(&reflect.SliceHeader{
|
||||
Data: uintptr(unsafe.Pointer(wstr)),
|
||||
Len: len,
|
||||
Cap: len,
|
||||
}))))
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
syscall "golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// utf16ToByte creates a byte array from a given UTF 16 char array.
|
||||
func utf16ToByte(wstr []uint16) (result []byte) {
|
||||
@@ -41,7 +22,11 @@ func utf16ToByte(wstr []uint16) (result []byte) {
|
||||
|
||||
// utf16FromString creates a UTF16 char array from a string.
|
||||
func utf16FromString(str string) []uint16 {
|
||||
return syscall.StringToUTF16(str)
|
||||
res, err := syscall.UTF16FromString(str)
|
||||
if err != nil {
|
||||
return []uint16{}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// goBytes copies the given C byte array to a Go byte array (see `C.GoBytes`).
|
||||
@@ -65,10 +50,10 @@ func sysToCredential(cred *sysCREDENTIAL) (result *Credential) {
|
||||
return nil
|
||||
}
|
||||
result = new(Credential)
|
||||
result.Comment = utf16PtrToString(cred.Comment)
|
||||
result.TargetName = utf16PtrToString(cred.TargetName)
|
||||
result.TargetAlias = utf16PtrToString(cred.TargetAlias)
|
||||
result.UserName = utf16PtrToString(cred.UserName)
|
||||
result.Comment = syscall.UTF16PtrToString(cred.Comment)
|
||||
result.TargetName = syscall.UTF16PtrToString(cred.TargetName)
|
||||
result.TargetAlias = syscall.UTF16PtrToString(cred.TargetAlias)
|
||||
result.UserName = syscall.UTF16PtrToString(cred.UserName)
|
||||
result.LastWritten = time.Unix(0, cred.LastWritten.Nanoseconds())
|
||||
result.Persist = CredentialPersistence(cred.Persist)
|
||||
result.CredentialBlob = goBytes(cred.CredentialBlob, cred.CredentialBlobSize)
|
||||
@@ -80,7 +65,7 @@ func sysToCredential(cred *sysCREDENTIAL) (result *Credential) {
|
||||
}))
|
||||
for i, attr := range attrSlice {
|
||||
resultAttr := &result.Attributes[i]
|
||||
resultAttr.Keyword = utf16PtrToString(attr.Keyword)
|
||||
resultAttr.Keyword = syscall.UTF16PtrToString(attr.Keyword)
|
||||
resultAttr.Value = goBytes(attr.Value, attr.ValueSize)
|
||||
}
|
||||
return result
|
||||
|
||||
+4
-1
@@ -2,4 +2,7 @@ module github.com/danieljoos/wincred
|
||||
|
||||
go 1.13
|
||||
|
||||
require github.com/stretchr/testify v1.5.1
|
||||
require (
|
||||
github.com/stretchr/testify v1.7.0
|
||||
golang.org/x/sys v0.0.0-20210819135213-f52c844e1c1c
|
||||
)
|
||||
|
||||
+6
-4
@@ -4,9 +4,11 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
golang.org/x/sys v0.0.0-20210819135213-f52c844e1c1c h1:Lyn7+CqXIiC+LOR9aHD6jDK+hPcmAuCfuXztd1v4w1Q=
|
||||
golang.org/x/sys v0.0.0-20210819135213-f52c844e1c1c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
+3
-3
@@ -4,13 +4,13 @@ package wincred
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
syscall "golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var (
|
||||
modadvapi32 = syscall.NewLazyDLL("advapi32.dll")
|
||||
|
||||
modadvapi32 = syscall.NewLazyDLL("advapi32.dll")
|
||||
procCredRead proc = modadvapi32.NewProc("CredReadW")
|
||||
procCredWrite proc = modadvapi32.NewProc("CredWriteW")
|
||||
procCredDelete proc = modadvapi32.NewProc("CredDeleteW")
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ const (
|
||||
func GetGenericCredential(targetName string) (*GenericCredential, error) {
|
||||
cred, err := sysCredRead(targetName, sysCRED_TYPE_GENERIC)
|
||||
if cred != nil {
|
||||
return &GenericCredential{*cred}, err
|
||||
return &GenericCredential{Credential: *cred}, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func (t *GenericCredential) Delete() (err error) {
|
||||
func GetDomainPassword(targetName string) (*DomainPassword, error) {
|
||||
cred, err := sysCredRead(targetName, sysCRED_TYPE_DOMAIN_PASSWORD)
|
||||
if cred != nil {
|
||||
return &DomainPassword{*cred}, err
|
||||
return &DomainPassword{Credential: *cred}, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user