Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit c46f1ac

Browse files
committed
modify script to build libgit2 without linking to openssl and libssh2
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
1 parent 00cf5cd commit c46f1ac

File tree

2 files changed

+74
-17
lines changed

2 files changed

+74
-17
lines changed

hack/static.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,44 @@ function build_libgit2(){
188188
popd
189189
}
190190

191+
function build_libgit2_only(){
192+
download_source "${LIBGIT2_URL}" "${SRC_DIR}/libgit2"
193+
194+
pushd "${SRC_DIR}/libgit2"
195+
196+
mkdir -p build
197+
198+
pushd build
199+
200+
# Set osx arch only when cross compiling on darwin
201+
if [[ $OSTYPE == darwin* ]] && [ ! "${TARGET_ARCH}" = "$(uname -m)" ]; then
202+
CMAKE_PARAMS=-DCMAKE_OSX_ARCHITECTURES="${TARGET_ARCH}"
203+
fi
204+
205+
cmake "${CMAKE_PARAMS}" \
206+
-DCMAKE_C_COMPILER="${C_COMPILER}" \
207+
-DCMAKE_INSTALL_PREFIX="${TARGET_DIR}" \
208+
-DTHREADSAFE:BOOL=ON \
209+
-DBUILD_CLAR:BOOL=OFF \
210+
-DBUILD_SHARED_LIBS=OFF \
211+
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON \
212+
-DCMAKE_C_FLAGS=-fPIC \
213+
-DUSE_SSH:BOOL=OFF \
214+
-DHAVE_LIBSSH2_MEMORY_CREDENTIALS:BOOL=OFF \
215+
-DDEPRECATE_HARD:BOOL=ON \
216+
-DUSE_BUNDLED_ZLIB:BOOL=ON \
217+
-DUSE_HTTPS:STRING:BOOL=OFF \
218+
-DREGEX_BACKEND:STRING=builtin \
219+
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
220+
..
221+
222+
223+
cmake --build . --target install
224+
225+
popd
226+
popd
227+
}
228+
191229
function all(){
192230
build_libz
193231
build_openssl

tests/smoketest/main.go

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import (
1212
"os"
1313
"path/filepath"
1414
"strings"
15+
16+
"bytes"
17+
"crypto/sha256"
18+
"hash"
1519
"time"
1620

1721
// git2go must be aligned with libgit2 version:
@@ -25,6 +29,11 @@ import (
2529
"golang.org/x/crypto/ssh/knownhosts"
2630
)
2731

32+
const (
33+
TestUser = "test-user"
34+
TestPass = "test-pass"
35+
)
36+
2837
func main() {
2938
fmt.Println("Running tests...")
3039
testsDir, err := filepath.Abs("./build/tests")
@@ -45,7 +54,16 @@ func main() {
4554
test("HTTPS clone with no options",
4655
filepath.Join(testsDir, "/https-clone-no-options"),
4756
httpRepoURL,
48-
&git2go.CloneOptions{Bare: true})
57+
&git2go.CloneOptions{
58+
Bare: true,
59+
FetchOptions: git2go.FetchOptions{
60+
RemoteCallbacks: git2go.RemoteCallbacks{
61+
CredentialsCallback: func(url string, username string, allowedTypes git2go.CredentialType) (*git2go.Credential, error) {
62+
return git2go.NewCredentialUserpassPlaintext(TestUser, TestPass)
63+
},
64+
},
65+
},
66+
})
4967

5068
if err := server.ListenSSH(); err != nil {
5169
panic(fmt.Errorf("listenSSH: %w", err))
@@ -80,7 +98,11 @@ func main() {
8098
FetchOptions: git2go.FetchOptions{
8199
RemoteCallbacks: git2go.RemoteCallbacks{
82100
CredentialsCallback: func(url string, username string, allowedTypes git2go.CredentialType) (*git2go.Credential, error) {
83-
return git2go.NewCredentialSSHKeyFromMemory("git", string(rsa.PublicKey), string(rsa.PrivateKey), "")
101+
signer, err := cryptossh.ParsePrivateKey(rsa.PrivateKey)
102+
if err != nil {
103+
return nil, err
104+
}
105+
return git2go.NewCredentialSSHKeyFromSigner("git", signer)
84106
},
85107
CertificateCheckCallback: knownHostsCallback(u.Host, knownHosts),
86108
},
@@ -99,7 +121,11 @@ func main() {
99121
FetchOptions: git2go.FetchOptions{
100122
RemoteCallbacks: git2go.RemoteCallbacks{
101123
CredentialsCallback: func(url string, username string, allowedTypes git2go.CredentialType) (*git2go.Credential, error) {
102-
return git2go.NewCredentialSSHKeyFromMemory("git", string(ed25519.PublicKey), string(ed25519.PrivateKey), "")
124+
signer, err := cryptossh.ParsePrivateKey(ed25519.PrivateKey)
125+
if err != nil {
126+
return nil, err
127+
}
128+
return git2go.NewCredentialSSHKeyFromSigner("git", signer)
103129
},
104130
CertificateCheckCallback: knownHostsCallback(u.Host, knownHosts),
105131
},
@@ -117,7 +143,7 @@ func createTestServer(repoPath string) *gittestserver.GitServer {
117143
}
118144
defer os.RemoveAll(server.Root())
119145

120-
server.Auth("test-user", "test-pswd")
146+
server.Auth(TestUser, TestPass)
121147
server.AutoCreate()
122148
server.KeyDir(filepath.Join(server.Root(), "keys"))
123149

@@ -242,20 +268,13 @@ func (k knownKey) matches(host string, hostkey git2go.HostkeyCertificate) bool {
242268
return false
243269
}
244270

245-
if hostkey.Kind&git2go.HostkeySHA256 > 0 {
246-
knownFingerprint := cryptossh.FingerprintSHA256(k.key)
247-
returnedFingerprint := cryptossh.FingerprintSHA256(hostkey.SSHPublicKey)
248-
249-
fmt.Printf("known and found fingerprints:\n%q\n%q\n",
250-
knownFingerprint,
251-
returnedFingerprint)
252-
if returnedFingerprint == knownFingerprint {
253-
return true
254-
}
255-
}
271+
var fingerprint []byte
272+
var hasher hash.Hash
256273

257-
fmt.Println("host kind not supported")
258-
return false
274+
fingerprint = hostkey.HashSHA256[:]
275+
hasher = sha256.New()
276+
hasher.Write(k.key.Marshal())
277+
return bytes.Equal(hasher.Sum(nil), fingerprint)
259278
}
260279

261280
func containsHost(hosts []string, host string) bool {

0 commit comments

Comments
 (0)