Skip to content

Commit

Permalink
1, fix tls module run codition.
Browse files Browse the repository at this point in the history
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
  • Loading branch information
cfc4n committed Mar 22, 2022
1 parent 385512a commit cd6172a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
19 changes: 12 additions & 7 deletions cli/cmd/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func openSSLCommandFunc(command *cobra.Command, args []string) {

modNames := []string{user.MODULE_NAME_OPENSSL, user.MODULE_NAME_GNUTLS, user.MODULE_NAME_NSPR}

var runMods uint8
for _, modName := range modNames {
mod := user.GetModuleByName(modName)
if mod == nil {
Expand Down Expand Up @@ -88,28 +89,32 @@ func openSSLCommandFunc(command *cobra.Command, args []string) {
conf.SetHex(gConf.IsHex)

if e := conf.Check(); e != nil {
logger.Fatal(e)
os.Exit(1)
logger.Printf("%v", e)
break
}

//初始化
err := mod.Init(ctx, logger, conf)
if err != nil {
logger.Fatal(err)
os.Exit(1)
logger.Printf("%v", err)
break
}

// 加载ebpf,挂载到hook点上,开始监听
go func(module user.IModule) {
err := module.Run()
if err != nil {
logger.Fatalf("%v", err)
logger.Printf("%v", err)
return
}
}(mod)

runMods++
}

<-stopper
// needs runmods > 0
if runMods > 0 {
<-stopper
}
cancelFun()
os.Exit(0)
}
14 changes: 12 additions & 2 deletions user/probe_nspr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"golang.org/x/sys/unix"
"log"
"math"
"os"
)

type MNsprProbe struct {
Expand Down Expand Up @@ -46,7 +47,10 @@ func (this *MNsprProbe) start() error {
}

// setup the managers
this.setupManagers()
err = this.setupManagers()
if err != nil {
return errors.Wrap(err, "tls module couldn't find binPath.")
}

// initialize the bootstrap manager
if err := this.bpfManager.InitWithOptions(bytes.NewReader(byteBuf), this.bpfManagerOptions); err != nil {
Expand Down Expand Up @@ -93,7 +97,7 @@ func (e *MNsprProbe) constantEditor() []manager.ConstantEditor {
return editor
}

func (this *MNsprProbe) setupManagers() {
func (this *MNsprProbe) setupManagers() error {
var binaryPath string
switch this.conf.(*NsprConfig).elfType {
case ELF_TYPE_BIN:
Expand All @@ -105,6 +109,11 @@ func (this *MNsprProbe) setupManagers() {
binaryPath = "/lib/x86_64-linux-gnu/libnspr4.so"
}

_, err := os.Stat(binaryPath)
if err != nil {
return err
}

this.logger.Printf("HOOK type:%d, binrayPath:%s\n", this.conf.(*NsprConfig).elfType, binaryPath)

this.bpfManager = &manager.Manager{
Expand Down Expand Up @@ -191,6 +200,7 @@ func (this *MNsprProbe) setupManagers() {
// 填充 RewriteContants 对应map
ConstantEditors: this.constantEditor(),
}
return nil
}

func (this *MNsprProbe) DecodeFun(em *ebpf.Map) (IEventStruct, bool) {
Expand Down

0 comments on commit cd6172a

Please sign in to comment.