-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Juju 7405/add fingerprint endpoint (#1530)
* hook everything up and add fingerprint endpoint
- Loading branch information
1 parent
c0b0b11
commit d97f72e
Showing
10 changed files
with
160 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ services: | |
container_name: jimm | ||
ports: | ||
- 17070:80 | ||
- 17022:17022 | ||
- 2345:2345 | ||
volumes: | ||
- ./:/jimm/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2025 Canonical. | ||
|
||
package jimmhttp | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/juju/zaputil/zapctx" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// WriteFingerprints writes a map as JSON to the response. | ||
func WriteFingerprints(m map[string]string) func(http.ResponseWriter, *http.Request) { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
b, err := json.Marshal(m) | ||
if err != nil { | ||
zapctx.Error(ctx, "failed to marshal map", zap.Error(err)) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
w.Header().Set("Content-Type", "application/json") | ||
_, err = w.Write(b) | ||
if err != nil { | ||
zapctx.Error(ctx, "failed to write response", zap.Error(err)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2025 Canonical. | ||
|
||
package ssh | ||
|
||
import ( | ||
gossh "golang.org/x/crypto/ssh" | ||
) | ||
|
||
// GetFingerprintsFromPrivateKey returns the fingerprints of the host key. | ||
func GetFingerprintsFromPrivateKey(privateKey []byte) (map[string]string, error) { | ||
key, err := gossh.ParsePrivateKey(privateKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return map[string]string{ | ||
"SHA256": gossh.FingerprintSHA256(key.PublicKey()), | ||
"MD5": gossh.FingerprintLegacyMD5(key.PublicKey()), | ||
}, nil | ||
} |