whitespace only changes
This commit is contained in:
@@ -26,10 +26,10 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"syscall"
|
||||
@@ -134,8 +134,8 @@ type UserMeta struct {
|
||||
}
|
||||
|
||||
type GroupMeta struct {
|
||||
XMLName xml.Name `xml:"group"`
|
||||
Title string `xml:"title"`
|
||||
XMLName xml.Name `xml:"group"`
|
||||
Title string `xml:"title"`
|
||||
Persons PersonGroup `xml:"person"`
|
||||
}
|
||||
|
||||
@@ -214,11 +214,11 @@ func (c *ObsClient) ObsRequest(method string, url string, body io.Reader) (*http
|
||||
return nil, err
|
||||
}
|
||||
if body != nil {
|
||||
req.Body = io.NopCloser(body)
|
||||
}
|
||||
req.Body = io.NopCloser(body)
|
||||
}
|
||||
if c.cookie != "" {
|
||||
req.Header.Add("cookie", c.cookie)
|
||||
}
|
||||
}
|
||||
res, err := c.client.Do(req)
|
||||
if err == nil && res.StatusCode == 200 {
|
||||
auth_cookie := res.Header.Get("set-cookie")
|
||||
@@ -226,69 +226,69 @@ func (c *ObsClient) ObsRequest(method string, url string, body io.Reader) (*http
|
||||
c.cookie = auth_cookie
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
}
|
||||
|
||||
if res.StatusCode == 401 {
|
||||
// log.Printf("new authentication is needed ...")
|
||||
if res.StatusCode == 401 {
|
||||
// log.Printf("new authentication is needed ...")
|
||||
if c.sshkey == "" {
|
||||
req.SetBasicAuth(c.user, c.password)
|
||||
} else {
|
||||
req.SetBasicAuth(c.user, c.password)
|
||||
} else {
|
||||
www := res.Header.Get("www-authenticate")
|
||||
// log.Printf("www-authenticate %s", www)
|
||||
re := regexp.MustCompile(`Signature realm="(.*?)",headers="\(created\)`)
|
||||
match := re.FindStringSubmatch(www)
|
||||
if len(match) < 1 {
|
||||
return nil, errors.New("No realm found")
|
||||
}
|
||||
// log.Printf("www-authenticate %s", www)
|
||||
re := regexp.MustCompile(`Signature realm="(.*?)",headers="\(created\)`)
|
||||
match := re.FindStringSubmatch(www)
|
||||
if len(match) < 1 {
|
||||
return nil, errors.New("No realm found")
|
||||
}
|
||||
realm := string(match[1])
|
||||
sshKeygenPath, err := exec.LookPath("ssh-keygen")
|
||||
if err != nil {
|
||||
fmt.Println("ssh-keygen not found")
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println("ssh-keygen not found")
|
||||
}
|
||||
|
||||
// SSH Sign
|
||||
cmd := exec.Command(sshKeygenPath, "-Y", "sign", "-f", c.sshkeyfile, "-n", realm, "-q")
|
||||
now := time.Now().Unix()
|
||||
sigdata := fmt.Sprintf("(created): %d", now)
|
||||
cmd.Stdin = strings.NewReader(sigdata)
|
||||
stdout, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Panic("SSH sign error:%s", cmd.Stderr)
|
||||
if exitError, ok := err.(*exec.ExitError); ok {
|
||||
waitStatus := exitError.Sys().(syscall.WaitStatus)
|
||||
exitCode := waitStatus.ExitStatus()
|
||||
return nil, errors.New(fmt.Sprintf("ssh-keygen signature creation failed: %d", exitCode))
|
||||
}
|
||||
return nil, errors.New("ssh-keygen signature creation failed")
|
||||
}
|
||||
sigdata := fmt.Sprintf("(created): %d", now)
|
||||
cmd.Stdin = strings.NewReader(sigdata)
|
||||
stdout, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Panic("SSH sign error:%s", cmd.Stderr)
|
||||
if exitError, ok := err.(*exec.ExitError); ok {
|
||||
waitStatus := exitError.Sys().(syscall.WaitStatus)
|
||||
exitCode := waitStatus.ExitStatus()
|
||||
return nil, errors.New(fmt.Sprintf("ssh-keygen signature creation failed: %d", exitCode))
|
||||
}
|
||||
return nil, errors.New("ssh-keygen signature creation failed")
|
||||
}
|
||||
reg := regexp.MustCompile("(?s)-----BEGIN SSH SIGNATURE-----\n(.*?)\n-----END SSH SIGNATURE-----")
|
||||
match = reg.FindStringSubmatch(string(stdout))
|
||||
if len(match) < 2 {
|
||||
return nil, errors.New("could not extract ssh signature")
|
||||
}
|
||||
|
||||
signature, err := base64.StdEncoding.DecodeString(string(match[1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
match = reg.FindStringSubmatch(string(stdout))
|
||||
if len(match) < 2 {
|
||||
return nil, errors.New("could not extract ssh signature")
|
||||
}
|
||||
|
||||
signature, err := base64.StdEncoding.DecodeString(string(match[1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
signatureBase64 := base64.StdEncoding.EncodeToString(signature)
|
||||
authorization := fmt.Sprintf(`keyId="%s",algorithm="ssh",headers="(created)",created=%d,signature="%s"`,
|
||||
c.user, now, signatureBase64)
|
||||
|
||||
// log.Printf("Add Authorization Signature ", authorization)
|
||||
req.Header.Add("Authorization", "Signature " + authorization)
|
||||
}
|
||||
}
|
||||
c.user, now, signatureBase64)
|
||||
|
||||
// log.Printf("Add Authorization Signature ", authorization)
|
||||
req.Header.Add("Authorization", "Signature "+authorization)
|
||||
}
|
||||
}
|
||||
|
||||
// Another time with authentification header
|
||||
// log.Printf("Trying again with authorization: %s", req.Header.Get("Authorization"))
|
||||
// log.Printf("Trying again with authorization: %s", req.Header.Get("Authorization"))
|
||||
|
||||
res, err = c.client.Do(req)
|
||||
if err != nil {
|
||||
log.Panic("Authentification failed: %d", res.StatusCode)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Store the cookie for next call
|
||||
auth_cookie := res.Header.Get("set-cookie")
|
||||
|
Reference in New Issue
Block a user