aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2024-01-09 23:22:34 +0100
committerLibravatar Rutger Broekhoff2024-01-09 23:22:34 +0100
commitb07332d62c347326baade26e3a3c281b83172615 (patch)
tree0b7fc32b7ea54ff1d0a501258b4275b8af87886e /cmd
parentbc465de960aa5d53b28d51bd6bbead28433f2010 (diff)
downloadgitolfs3-b07332d62c347326baade26e3a3c281b83172615.tar.gz
gitolfs3-b07332d62c347326baade26e3a3c281b83172615.zip
Fix makehextag in git-lfs-authenticate (C)
Diffstat (limited to 'cmd')
-rw-r--r--cmd/git-lfs-authenticate/main.c22
-rw-r--r--cmd/git-lfs-authenticate/main.go11
2 files changed, 18 insertions, 15 deletions
diff --git a/cmd/git-lfs-authenticate/main.c b/cmd/git-lfs-authenticate/main.c
index 0f45e49..71481e9 100644
--- a/cmd/git-lfs-authenticate/main.c
+++ b/cmd/git-lfs-authenticate/main.c
@@ -62,15 +62,15 @@ void printescjson(const char *str) {
62void checkrepopath(const char *path) { 62void checkrepopath(const char *path) {
63 if (strstr(path, "//") || strstr(path, "/./") || strstr(path, "/../") 63 if (strstr(path, "//") || strstr(path, "/./") || strstr(path, "/../")
64 || hasprefix(path, "./") || hasprefix(path, "../") || hasprefix(path, "/../")) 64 || hasprefix(path, "./") || hasprefix(path, "../") || hasprefix(path, "/../"))
65 die("Bad repository name: is unresolved path"); 65 die("Bad repository name: Is unresolved path");
66 if (strlen(path) > 100) 66 if (strlen(path) > 100)
67 die("Bad repository name: longer than 100 characters"); 67 die("Bad repository name: Longer than 100 characters");
68 if (hassuffix(path, "/")) 68 if (hassuffix(path, "/"))
69 die("Bad repositry name: unexpected trailing slash"); 69 die("Bad repositry name: Unexpected trailing slash");
70 if (hasprefix(path, "/")) 70 if (hasprefix(path, "/"))
71 die("Bad repository name: unexpected absolute path"); 71 die("Bad repository name: Unexpected absolute path");
72 if (!hassuffix(path, ".git")) 72 if (!hassuffix(path, ".git"))
73 die("Bad repository name: expected '.git' repo path suffix"); 73 die("Bad repository name: Expected '.git' repo path suffix");
74 74
75 struct stat statbuf; 75 struct stat statbuf;
76 if (stat(path, &statbuf)) { 76 if (stat(path, &statbuf)) {
@@ -203,8 +203,8 @@ void makehextag(const taginfo_t info, uint8_t key[KEYSIZE], char dest[MAX_HEXTAG
203 memset(dest, 0, MAX_HEXTAG_STRLEN + 1); 203 memset(dest, 0, MAX_HEXTAG_STRLEN + 1);
204 for (size_t i = 0; i < rawtag_len; i++) { 204 for (size_t i = 0; i < rawtag_len; i++) {
205 uint8_t b = rawtag[i]; 205 uint8_t b = rawtag[i];
206 dest[i] = (b >> 4) + ((b >> 4) < 10 ? '0' : 'a'); 206 dest[i * 2] = (b >> 4) + ((b >> 4) < 10 ? '0' : 'a');
207 dest[i + 1] = (b & 0x0F) + ((b & 0x0F) < 10 ? '0' : 'a'); 207 dest[i*2 + 1] = (b & 0x0F) + ((b & 0x0F) < 10 ? '0' : 'a');
208 } 208 }
209} 209}
210 210
@@ -223,14 +223,14 @@ int main(int argc, char *argv[]) {
223 checkrepopath(repopath); 223 checkrepopath(repopath);
224 224
225 const char *hrefbase = getenv("GITOLFS3_HREF_BASE"); 225 const char *hrefbase = getenv("GITOLFS3_HREF_BASE");
226 const char *keypath = getenv("GITOLFS3_KEY_PATH"); 226 const char *keypath = getenv("GITOLFS3_KEY_PATH");
227 227
228 if (!hrefbase || strlen(hrefbase) == 0) 228 if (!hrefbase || strlen(hrefbase) == 0)
229 die("Incomplete configuration: base URL not provided"); 229 die("Incomplete configuration: Base URL not provided");
230 if (hrefbase[strlen(hrefbase) - 1] != '/') 230 if (hrefbase[strlen(hrefbase) - 1] != '/')
231 die("Bad configuration: base URL should end with slash"); 231 die("Bad configuration: Base URL should end with slash");
232 if (!keypath || strlen(keypath) == 0) 232 if (!keypath || strlen(keypath) == 0)
233 die("Incomplete configuration: key path not provided"); 233 die("Incomplete configuration: Key path not provided");
234 234
235 uint8_t key[64]; 235 uint8_t key[64];
236 readkey(keypath, key); 236 readkey(keypath, key);
diff --git a/cmd/git-lfs-authenticate/main.go b/cmd/git-lfs-authenticate/main.go
index 3db0efe..59ed978 100644
--- a/cmd/git-lfs-authenticate/main.go
+++ b/cmd/git-lfs-authenticate/main.go
@@ -59,7 +59,7 @@ func main() {
59 os.Exit(1) 59 os.Exit(1)
60 } 60 }
61 61
62 repo := strings.TrimPrefix(path.Clean(strings.TrimSuffix(os.Args[1], ".git")), "/") 62 repo := strings.TrimPrefix(path.Clean(os.Args[1]), "/")
63 operation := os.Args[2] 63 operation := os.Args[2]
64 if operation != "download" && operation != "upload" { 64 if operation != "download" && operation != "upload" {
65 fmt.Println(usage) 65 fmt.Println(usage)
@@ -68,8 +68,11 @@ func main() {
68 if repo == ".." || strings.HasPrefix(repo, "../") { 68 if repo == ".." || strings.HasPrefix(repo, "../") {
69 die("highly illegal repo name (Anzeige ist raus)") 69 die("highly illegal repo name (Anzeige ist raus)")
70 } 70 }
71 if !strings.HasSuffix(repo, ".git") {
72 die("expected repo name to have '.git' suffix")
73 }
71 74
72 repoDir := path.Join(repo + ".git") 75 repoDir := path.Join(repo)
73 finfo, err := os.Stat(repoDir) 76 finfo, err := os.Stat(repoDir)
74 if err != nil { 77 if err != nil {
75 if errors.Is(err, fs.ErrNotExist) { 78 if errors.Is(err, fs.ErrNotExist) {
@@ -125,12 +128,12 @@ func main() {
125 128
126 response := authenticateResponse{ 129 response := authenticateResponse{
127 Header: map[string]string{ 130 Header: map[string]string{
128 "Authorization": "Tag " + tagStr, 131 "Authorization": "Gitolfs3-Hmac-Sha256 " + tagStr,
129 }, 132 },
130 ExpiresIn: int64(expiresIn.Seconds()), 133 ExpiresIn: int64(expiresIn.Seconds()),
131 HRef: fmt.Sprintf("%s%s?p=1&te=%d", 134 HRef: fmt.Sprintf("%s%s?p=1&te=%d",
132 hrefBase, 135 hrefBase,
133 path.Join(repo+".git", "/info/lfs"), 136 path.Join(repo, "/info/lfs"),
134 expiresAtUnix, 137 expiresAtUnix,
135 ), 138 ),
136 } 139 }