-
Notifications
You must be signed in to change notification settings - Fork 838
/
config_openssl.go
111 lines (100 loc) · 3.45 KB
/
config_openssl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2022 CFC4N <cfc4n.cs@gmail.com>. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package config
import (
"os"
"path/filepath"
"syscall"
"golang.org/x/sys/unix"
)
/*
关于CGroup路径问题,可以自己创建,也可以使用系统的。不限制CGroup版本, v1、v2都可以。
ubuntu系统上,默认在/sys/fs/cgroup ,CentOS上,可以自己创建。 代码中已经实现。
或使用如下命令:
创建命令:mkdir /mnt/ecapture_cgroupv2
mount -t cgroup2 none /mnt/ecapture_cgroupv2
*/
const (
cgroupPath = "/sys/fs/cgroup" // ubuntu
cgroupPathCentos = "/mnt/ecapture_cgroupv2" // centos
)
// 最终使用openssl参数
type OpensslConfig struct {
eConfig
// Curlpath string `json:"curlPath"` //curl的文件路径
Openssl string `json:"openssl"`
Pthread string `json:"pThread"` // /lib/x86_64-linux-gnu/libpthread.so.0
Model string `json:"model"` // eCapture Openssl capture model. text:pcap:keylog
PcapFile string `json:"pcapFile"` // pcapFile the raw packets to file rather than parsing and printing them out.
KeylogFile string `json:"keylog"` // Keylog The file stores SSL/TLS keys, and eCapture captures these keys during encrypted traffic communication and saves them to the file.
Ifname string `json:"ifName"` // (TC Classifier) Interface name on which the probe will be attached.
PcapFilter string `json:"pcapFilter"` // pcap filter
SslVersion string `json:"sslVersion"` // openssl version like 1.1.1a/1.1.1f/boringssl_1.1.1
CGroupPath string `json:"CGroupPath"` // cgroup path, used for filter process
ElfType uint8 //
IsAndroid bool // is Android OS ?
AndroidVer string // Android OS version
}
func NewOpensslConfig() *OpensslConfig {
config := &OpensslConfig{}
config.PerCpuMapSize = DefaultMapSizePerCpu
return config
}
func (oc *OpensslConfig) checkModel() string {
var m string
switch oc.Model {
case TlsCaptureModelKeylog, TlsCaptureModelKey:
m = TlsCaptureModelKey
case TlsCaptureModelPcap, TlsCaptureModelPcapng:
m = TlsCaptureModelPcap
default:
m = TlsCaptureModelText
}
return m
}
func checkCgroupPath(cp string) (string, error) {
var st syscall.Statfs_t
err := syscall.Statfs(cp, &st)
if err != nil {
return "", err
}
newPath := cp
isCgroupV2Enabled := st.Type == unix.CGROUP2_SUPER_MAGIC
if !isCgroupV2Enabled {
newPath = filepath.Join(cgroupPath, "unified")
}
// 判断老路径是否存在,正常的返回
err = syscall.Statfs(newPath, &st)
if err == nil {
return newPath, nil
}
// 若老路径不存在,则改用新路径
// for CentOS
newPath = cgroupPathCentos
err = syscall.Statfs(newPath, &st)
if err == nil {
// TODO 判断是否已经mount
return newPath, nil
}
// 若新路径不存在,重新创建
err = os.Mkdir(newPath, os.FileMode(0o755))
if err != nil {
return "", err
}
err = syscall.Mount("none", newPath, "cgroup2", 0, "")
if err != nil {
return "", err
}
return newPath, nil
}