Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
orangecat
ollama
Commits
fd962a36
"docs/EN/source/deploy_guides/lora_deploy.md" did not exist on "0c3f4bb1aa820e64571a4dd4da3d37f22a6e3bd5"
Commit
fd962a36
authored
Jul 04, 2023
by
Jeffrey Morgan
Browse files
client updates
parent
6292f4b6
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
63 deletions
+0
-63
signature/signature.go
signature/signature.go
+0
-63
No files found.
signature/signature.go
deleted
100644 → 0
View file @
6292f4b6
package
signature
import
(
"bytes"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"strings"
"golang.org/x/crypto/ssh"
)
type
SignatureData
struct
{
Method
string
Path
string
Data
[]
byte
}
func
GetBytesToSign
(
s
SignatureData
)
[]
byte
{
// contentHash = base64(hex(sha256(s.Data)))
hash
:=
sha256
.
Sum256
(
s
.
Data
)
hashHex
:=
make
([]
byte
,
hex
.
EncodedLen
(
len
(
hash
)))
hex
.
Encode
(
hashHex
,
hash
[
:
])
contentHash
:=
base64
.
StdEncoding
.
EncodeToString
(
hashHex
)
// bytesToSign e.g.: "GET,http://localhost,OTdkZjM1O...
bytesToSign
:=
[]
byte
(
strings
.
Join
([]
string
{
s
.
Method
,
s
.
Path
,
contentHash
},
","
))
return
bytesToSign
}
// SignData takes a SignatureData object and signs it with a raw private key
func
SignAuthData
(
s
SignatureData
,
rawKey
[]
byte
)
(
string
,
error
)
{
bytesToSign
:=
GetBytesToSign
(
s
)
// TODO replace this w/ a non-SSH based private key
privateKey
,
err
:=
ssh
.
ParseRawPrivateKey
(
rawKey
)
if
err
!=
nil
{
return
""
,
err
}
signer
,
err
:=
ssh
.
NewSignerFromKey
(
privateKey
)
if
err
!=
nil
{
return
""
,
err
}
// get the pubkey, but remove the type
pubKey
:=
ssh
.
MarshalAuthorizedKey
(
signer
.
PublicKey
())
parts
:=
bytes
.
Split
(
pubKey
,
[]
byte
(
" "
))
if
len
(
parts
)
<
2
{
return
""
,
fmt
.
Errorf
(
"malformed private key"
)
}
signedData
,
err
:=
signer
.
Sign
(
nil
,
bytesToSign
)
if
err
!=
nil
{
return
""
,
err
}
// signature is <pubkey>:<signature>
sig
:=
fmt
.
Sprintf
(
"%s:%s"
,
bytes
.
TrimSpace
(
parts
[
1
]),
base64
.
StdEncoding
.
EncodeToString
(
signedData
.
Blob
))
return
sig
,
nil
}
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment