step client's API call log #1264
-
Is it possible to log/view the API calls made by step client while sending commands to step-ca. Would be great if I can see request/response data. Since its tls communication with strong ciphers, difficult to decrypt traffic with wireshark. Any help would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Could you describe what you are trying to accomplish here? There's no simple way to view the full API calls with |
Beta Was this translation helpful? Give feedback.
-
We're considering replacing the log library that one that allows you to log everything. If you are specifically interested in viewing something specific, you can change the code to do something like this to your CA: diff --git a/logging/handler.go b/logging/handler.go
index a8b77d60..e06c9e42 100644
--- a/logging/handler.go
+++ b/logging/handler.go
@@ -1,6 +1,9 @@
package logging
import (
+ "bytes"
+ "encoding/json"
+ "io"
"net"
"net/http"
"os"
@@ -47,11 +50,34 @@ func NewLoggerHandler(name string, logger *Logger, next http.Handler) http.Handl
func (l *LoggerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
t := time.Now()
rw := NewResponseLogger(w)
+ logBody(rw, r)
l.next.ServeHTTP(rw, r)
d := time.Since(t)
l.writeEntry(rw, r, t, d)
}
+func logBody(w ResponseLogger, r *http.Request) {
+ if r.Body == nil || r.Body == http.NoBody {
+ return
+ }
+ var buf bytes.Buffer
+ if _, err := buf.ReadFrom(r.Body); err != nil {
+ panic(err)
+ }
+ if err := r.Body.Close(); err != nil {
+ panic(err)
+ }
+ m := make(map[string]interface{})
+ if err := json.Unmarshal(buf.Bytes(), &m); err == nil {
+ if b, err := json.Marshal(m); err == nil {
+ w.WithFields(map[string]interface{}{
+ "body": string(b),
+ })
+ }
+ }
+ r.Body = io.NopCloser(&buf)
+}
+
// writeEntry writes to the Logger writer the request information in the logger.
func (l *LoggerHandler) writeEntry(w ResponseLogger, r *http.Request, t time.Time, d time.Duration) {
var reqID, user string |
Beta Was this translation helpful? Give feedback.
We're considering replacing the log library that one that allows you to log everything. If you are specifically interested in viewing something specific, you can change the code to do something like this to your CA: