Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
AD-Control-Golang
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陶腾飞
AD-Control-Golang
Commits
f07c0656
Commit
f07c0656
authored
Apr 05, 2022
by
陶腾飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2022-04-05
parent
3f3b8850
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
64 additions
and
71 deletions
+64
-71
README.MD
+1
-0
public/AD-Control.ico
+0
-0
public/error.go
+11
-11
public/go.mod
+0
-1
public/ldap.go
+5
-1
public/msg_deal.go
+0
-1
public/msg_init.go
+0
-1
public/user.go
+3
-12
public/win.go
+10
-10
public/wol.go
+3
-3
public/wxwork.go
+31
-31
No files found.
README.MD
View file @
f07c0656
...
@@ -84,6 +84,7 @@
...
@@ -84,6 +84,7 @@
-
2022/03/31 v2.2.0 知微运维平台功能完善,修复cmdb的位置错误问题,修复用户会属于多个主要计算机的问题,修复内存条DDR4无法显示的问题,清除扫描硬盘出现U盘的情况
-
2022/03/31 v2.2.0 知微运维平台功能完善,修复cmdb的位置错误问题,修复用户会属于多个主要计算机的问题,修复内存条DDR4无法显示的问题,清除扫描硬盘出现U盘的情况
-
2022/04/04 v2.2.1 修复远程管理主机失败的问题,增加对操作系统的判断、为Cmdb Automatic Update Tool的自动更新工具(专用于非情报部门的主机的cmdb同步工具)做铺垫。
-
2022/04/04 v2.2.1 修复远程管理主机失败的问题,增加对操作系统的判断、为Cmdb Automatic Update Tool的自动更新工具(专用于非情报部门的主机的cmdb同步工具)做铺垫。
-
2022/04/04 v2.2.2 使用go mod
-
2022/04/04 v2.2.2 使用go mod
-
2022/04/05 v2.2.3 语法优化
## 五、其他说明
## 五、其他说明
...
...
public/AD-Control.ico
deleted
100644 → 0
View file @
3f3b8850
File deleted
public/error.go
View file @
f07c0656
...
@@ -4,19 +4,19 @@ import (
...
@@ -4,19 +4,19 @@ import (
"errors"
"errors"
)
)
var
Error_Json_Parse
=
errors
.
New
(
"
ERROR JSON PARSE
"
)
var
Error_Json_Parse
=
errors
.
New
(
"
error json parse
"
)
var
Error_Lost_Parameter
=
errors
.
New
(
"
Lost P
aramter"
)
var
Error_Lost_Parameter
=
errors
.
New
(
"
lost p
aramter"
)
var
Error_Null_Command
=
errors
.
New
(
"
NULL COMMAND
"
)
var
Error_Null_Command
=
errors
.
New
(
"
null command
"
)
var
Error_Null_RegQuery
=
errors
.
New
(
"
Null Reg Q
uery"
)
var
Error_Null_RegQuery
=
errors
.
New
(
"
null reg q
uery"
)
var
Error_Null_File
=
errors
.
New
(
"
Not Find F
ile"
)
var
Error_Null_File
=
errors
.
New
(
"
not find f
ile"
)
var
Error_Null_Folder
=
errors
.
New
(
"
Not File F
older"
)
var
Error_Null_Folder
=
errors
.
New
(
"
not file f
older"
)
var
Error_Null_Icon_File
=
errors
.
New
(
"
Not File Icon F
ile"
)
var
Error_Null_Icon_File
=
errors
.
New
(
"
not file icon f
ile"
)
var
Error_Null_Reg_Query
=
errors
.
New
(
"
Not Found Reg Query R
esult"
)
var
Error_Null_Reg_Query
=
errors
.
New
(
"
not found reg query r
esult"
)
var
Error_Fail_File_Open
=
errors
.
New
(
"
Fail File O
pen"
)
var
Error_Fail_File_Open
=
errors
.
New
(
"
fail file o
pen"
)
var
Error_Fail_Token
=
errors
.
New
(
"
Get Token F
ail"
)
var
Error_Fail_Token
=
errors
.
New
(
"
get token f
ail"
)
var
Error_Fail_File_Write
=
errors
.
New
(
"
Fail File W
rite"
)
var
Error_Fail_File_Write
=
errors
.
New
(
"
fail file w
rite"
)
var
Error_Not_Msg
=
errors
.
New
(
"isn't defined msg"
)
var
Error_Not_Msg
=
errors
.
New
(
"isn't defined msg"
)
var
Error_WXWork_Down
=
errors
.
New
(
Error_WXWork_Fail_ReTry
)
var
Error_WXWork_Down
=
errors
.
New
(
Error_WXWork_Fail_ReTry
)
...
...
public/go.mod
View file @
f07c0656
...
@@ -2,7 +2,6 @@ module git.zhiweidata.top/taotengfei/AD-Control-Golang/public
...
@@ -2,7 +2,6 @@ module git.zhiweidata.top/taotengfei/AD-Control-Golang/public
go 1.18
go 1.18
require (
require (
github.com/go-ldap/ldap/v3 v3.4.2
github.com/go-ldap/ldap/v3 v3.4.2
github.com/gookit/color v1.5.0
github.com/gookit/color v1.5.0
...
...
public/ldap.go
View file @
f07c0656
...
@@ -50,6 +50,11 @@ func LDAP_Get_PCGroup() []string {
...
@@ -50,6 +50,11 @@ func LDAP_Get_PCGroup() []string {
func
LDAP_nameTopinyin
(
name
string
)
string
{
func
LDAP_nameTopinyin
(
name
string
)
string
{
l
,
err
:=
ldapBase
()
l
,
err
:=
ldapBase
()
if
err
!=
nil
{
LOG
(
ERROR
,
"LDAP"
,
err
)
}
defer
l
.
Close
()
searchRequest
:=
ldap
.
NewSearchRequest
(
searchRequest
:=
ldap
.
NewSearchRequest
(
//"ou=情报部门,dc=zhiweireach,dc=com",
//"ou=情报部门,dc=zhiweireach,dc=com",
"ou=情报部门,dc=zhiweireach,dc=com"
,
"ou=情报部门,dc=zhiweireach,dc=com"
,
...
@@ -63,7 +68,6 @@ func LDAP_nameTopinyin(name string) string {
...
@@ -63,7 +68,6 @@ func LDAP_nameTopinyin(name string) string {
if
err
!=
nil
{
if
err
!=
nil
{
LOG
(
ERROR
,
NULL
,
err
)
LOG
(
ERROR
,
NULL
,
err
)
}
}
defer
l
.
Close
()
return
sr
.
Entries
[
0
]
.
GetAttributeValue
(
"sAMAccountName"
)
return
sr
.
Entries
[
0
]
.
GetAttributeValue
(
"sAMAccountName"
)
}
}
...
...
public/msg_deal.go
View file @
f07c0656
...
@@ -371,7 +371,6 @@ func (wxwork *MJwxwork) MsgDealSend() {
...
@@ -371,7 +371,6 @@ func (wxwork *MJwxwork) MsgDealSend() {
}(
wxwork
.
Name
,
wxwork
.
UserID
)
}(
wxwork
.
Name
,
wxwork
.
UserID
)
wxwork
.
Result
=
"开始重启,请等待~"
wxwork
.
Result
=
"开始重启,请等待~"
break
// 芝麻关机
// 芝麻关机
case
WXEK_zwDevopsPowerTurnOFF
:
case
WXEK_zwDevopsPowerTurnOFF
:
...
...
public/msg_init.go
View file @
f07c0656
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
// msg env ////////////////////////////////////////////////////////////////
// msg env ////////////////////////////////////////////////////////////////
const
EndSign
byte
=
125
const
EndSign
byte
=
125
const
msgerror
string
=
"error"
// msg status //////////////////////////////////////////////////////////////
// msg status //////////////////////////////////////////////////////////////
const
Msg_status_commit
string
=
"commit"
const
Msg_status_commit
string
=
"commit"
...
...
public/user.go
View file @
f07c0656
...
@@ -30,17 +30,11 @@ func getOSType() int {
...
@@ -30,17 +30,11 @@ func getOSType() int {
return
r
return
r
}
}
func
Windows
()
bool
{
func
Windows
()
bool
{
if
OS_Type
==
OS_Type_Windows
{
return
OS_Type
==
OS_Type_Windows
return
true
}
return
false
}
}
func
PublicUser
()
bool
{
func
PublicUser
()
bool
{
if
strings
.
Index
(
User_name_display
,
"专用账户"
)
!=
-
1
{
return
strings
.
Contains
(
User_name_display
,
"专用账户"
)
return
true
}
return
false
}
}
// computer
// computer
...
@@ -52,10 +46,7 @@ func DomainComputer() bool {
...
@@ -52,10 +46,7 @@ func DomainComputer() bool {
// 判断当前主机是否为主控
// 判断当前主机是否为主控
func
Adserver
()
bool
{
func
Adserver
()
bool
{
if
Host_adserver
==
User_computername
{
return
Host_adserver
==
User_computername
return
true
}
return
false
}
}
// 判断当前主机是否为域控
// 判断当前主机是否为域控
...
...
public/win.go
View file @
f07c0656
...
@@ -32,7 +32,7 @@ func GetEnvFqdn(s string) string {
...
@@ -32,7 +32,7 @@ func GetEnvFqdn(s string) string {
}
}
for
_
,
each
:=
range
strings
.
Split
(
string
(
out
),
","
)
{
for
_
,
each
:=
range
strings
.
Split
(
string
(
out
),
","
)
{
if
strings
.
Index
(
each
,
s
)
!=
-
1
{
if
strings
.
Contains
(
each
,
s
)
{
return
each
[
3
:
]
return
each
[
3
:
]
}
}
}
}
...
@@ -327,15 +327,15 @@ func getHardwareCPUForPS() (string, string, string, string) {
...
@@ -327,15 +327,15 @@ func getHardwareCPUForPS() (string, string, string, string) {
var
cpuCount
,
cpuName
,
cpuCores
,
cpuLogicalProcessors
string
var
cpuCount
,
cpuName
,
cpuCores
,
cpuLogicalProcessors
string
cpuUN
,
_
:=
PSCommandOutputNoSplit
(
"Get-WmiObject -Class Win32_Processor | select Name,NumberOfCores,NumberOfLogicalProcessors | format-list"
)
cpuUN
,
_
:=
PSCommandOutputNoSplit
(
"Get-WmiObject -Class Win32_Processor | select Name,NumberOfCores,NumberOfLogicalProcessors | format-list"
)
for
_
,
line
:=
range
strings
.
Split
(
cpuUN
,
"
\n
"
)
{
for
_
,
line
:=
range
strings
.
Split
(
cpuUN
,
"
\n
"
)
{
if
strings
.
Index
(
line
,
"Name"
)
!=
-
1
{
if
strings
.
Contains
(
line
,
"Name"
)
{
mi
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
mi
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
cpuName
=
mi
cpuName
=
mi
c
++
c
++
}
else
if
strings
.
Index
(
line
,
"NumberOfCores"
)
!=
-
1
{
}
else
if
strings
.
Contains
(
line
,
"NumberOfCores"
)
{
mi
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
mi
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
cpuCores
=
mi
cpuCores
=
mi
c
++
c
++
}
else
if
strings
.
Index
(
line
,
"NumberOfLogicalProcessors"
)
!=
-
1
{
}
else
if
strings
.
Contains
(
line
,
"NumberOfLogicalProcessors"
)
{
mi
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
mi
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
cpuLogicalProcessors
=
mi
cpuLogicalProcessors
=
mi
c
++
c
++
...
@@ -359,7 +359,7 @@ func getHardwareMemoryForPS() ([]int, []string, []string, int) {
...
@@ -359,7 +359,7 @@ func getHardwareMemoryForPS() ([]int, []string, []string, int) {
menUN
,
_
:=
PSCommandOutputNoSplit
(
"Get-WmiObject -Class Win32_PhysicalMemory -Property Capacity,Speed,MemoryType"
)
menUN
,
_
:=
PSCommandOutputNoSplit
(
"Get-WmiObject -Class Win32_PhysicalMemory -Property Capacity,Speed,MemoryType"
)
for
_
,
line
:=
range
strings
.
Split
(
menUN
,
"
\n
"
)
{
for
_
,
line
:=
range
strings
.
Split
(
menUN
,
"
\n
"
)
{
if
strings
.
Index
(
line
,
"Capacity"
)
!=
-
1
{
if
strings
.
Contains
(
line
,
"Capacity"
)
{
mi
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
mi
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
m
,
_
:=
strconv
.
ParseInt
(
mi
,
10
,
64
)
m
,
_
:=
strconv
.
ParseInt
(
mi
,
10
,
64
)
...
@@ -370,7 +370,7 @@ func getHardwareMemoryForPS() ([]int, []string, []string, int) {
...
@@ -370,7 +370,7 @@ func getHardwareMemoryForPS() ([]int, []string, []string, int) {
}
}
c
++
c
++
}
else
if
strings
.
Index
(
line
,
"Speed"
)
!=
-
1
{
}
else
if
strings
.
Contains
(
line
,
"Speed"
)
{
m
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
m
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
if
j
>=
2
{
if
j
>=
2
{
Speed
=
append
(
Speed
,
m
)
Speed
=
append
(
Speed
,
m
)
...
@@ -378,7 +378,7 @@ func getHardwareMemoryForPS() ([]int, []string, []string, int) {
...
@@ -378,7 +378,7 @@ func getHardwareMemoryForPS() ([]int, []string, []string, int) {
Speed
[
j
]
=
m
Speed
[
j
]
=
m
}
}
c
++
c
++
}
else
if
strings
.
Index
(
line
,
"MemoryType"
)
!=
-
1
{
}
else
if
strings
.
Contains
(
line
,
"MemoryType"
)
{
m
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
m
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
switch
m
{
switch
m
{
case
"21"
:
case
"21"
:
...
@@ -419,7 +419,7 @@ func getHardwareHardDiskForPS(mini bool) ([]string, []int64, []string, int) {
...
@@ -419,7 +419,7 @@ func getHardwareHardDiskForPS(mini bool) ([]string, []int64, []string, int) {
var
c
,
j
int
var
c
,
j
int
diskUN
,
_
:=
PSCommandOutputNoSplit
(
"Get-PhysicalDisk |select mediaType,FriendlyName,Size | format-list"
)
diskUN
,
_
:=
PSCommandOutputNoSplit
(
"Get-PhysicalDisk |select mediaType,FriendlyName,Size | format-list"
)
for
_
,
line
:=
range
strings
.
Split
(
diskUN
,
"
\n
"
)
{
for
_
,
line
:=
range
strings
.
Split
(
diskUN
,
"
\n
"
)
{
if
strings
.
Index
(
line
,
"MediaType"
)
!=
-
1
{
if
strings
.
Contains
(
line
,
"MediaType"
)
{
m
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
m
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
// 如果是小白
// 如果是小白
...
@@ -443,7 +443,7 @@ func getHardwareHardDiskForPS(mini bool) ([]string, []int64, []string, int) {
...
@@ -443,7 +443,7 @@ func getHardwareHardDiskForPS(mini bool) ([]string, []int64, []string, int) {
}
}
c
++
c
++
}
else
if
strings
.
Index
(
line
,
"FriendlyName"
)
!=
-
1
{
}
else
if
strings
.
Contains
(
line
,
"FriendlyName"
)
{
m
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
m
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
if
j
>=
2
{
if
j
>=
2
{
...
@@ -457,7 +457,7 @@ func getHardwareHardDiskForPS(mini bool) ([]string, []int64, []string, int) {
...
@@ -457,7 +457,7 @@ func getHardwareHardDiskForPS(mini bool) ([]string, []int64, []string, int) {
c
=
2
c
=
2
}
}
c
++
c
++
}
else
if
strings
.
Index
(
line
,
"Size"
)
!=
-
1
{
}
else
if
strings
.
Contains
(
line
,
"Size"
)
{
Size
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
Size
:=
strings
.
TrimSpace
(
strings
.
Split
(
line
,
":"
)[
1
])
Sizei
,
_
:=
strconv
.
ParseInt
(
Size
,
10
,
64
)
Sizei
,
_
:=
strconv
.
ParseInt
(
Size
,
10
,
64
)
m
:=
Sizei
/
1024
/
1024
/
1024
m
:=
Sizei
/
1024
/
1024
/
1024
...
...
public/wol.go
View file @
f07c0656
...
@@ -25,12 +25,12 @@ func wol(mac string) error {
...
@@ -25,12 +25,12 @@ func wol(mac string) error {
hw
:=
strings
.
Replace
(
strings
.
Replace
(
mac
,
":"
,
""
,
-
1
),
"-"
,
""
,
-
1
)
hw
:=
strings
.
Replace
(
strings
.
Replace
(
mac
,
":"
,
""
,
-
1
),
"-"
,
""
,
-
1
)
if
len
(
hw
)
!=
12
{
if
len
(
hw
)
!=
12
{
return
fmt
.
Errorf
(
"MAC: [%s] 输入不正确
.
\n
"
,
mac
)
return
fmt
.
Errorf
(
"MAC: [%s] 输入不正确"
,
mac
)
}
}
macHex
,
err
:=
hex
.
DecodeString
(
hw
)
macHex
,
err
:=
hex
.
DecodeString
(
hw
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"MAC: [%s] 输入不正确
.
\n
"
,
mac
)
return
fmt
.
Errorf
(
"MAC: [%s] 输入不正确"
,
mac
)
}
}
// 广播MAC地址 FF:FF:FF:FF:FF:FF
// 广播MAC地址 FF:FF:FF:FF:FF:FF
...
@@ -44,7 +44,7 @@ func wol(mac string) error {
...
@@ -44,7 +44,7 @@ func wol(mac string) error {
// 获得唤醒魔包
// 获得唤醒魔包
mp
:=
buff
.
Bytes
()
mp
:=
buff
.
Bytes
()
if
len
(
mp
)
!=
102
{
if
len
(
mp
)
!=
102
{
return
fmt
.
Errorf
(
"MAC: [%s] 输入不正确
.
\n
"
,
mac
)
return
fmt
.
Errorf
(
"MAC: [%s] 输入不正确"
,
mac
)
}
}
return
sendMagicPacket
(
mp
,
""
)
return
sendMagicPacket
(
mp
,
""
)
...
...
public/wxwork.go
View file @
f07c0656
...
@@ -85,7 +85,7 @@ type WXBizMsgCrypt struct {
...
@@ -85,7 +85,7 @@ type WXBizMsgCrypt struct {
type
XmlProcessor
struct
{
type
XmlProcessor
struct
{
}
}
func
(
self
*
XmlProcessor
)
parse
(
src_data
[]
byte
)
(
*
WXBizMsg4Recv
,
*
CryptError
)
{
func
(
wxstruct
*
XmlProcessor
)
parse
(
src_data
[]
byte
)
(
*
WXBizMsg4Recv
,
*
CryptError
)
{
var
msg4_recv
WXBizMsg4Recv
var
msg4_recv
WXBizMsg4Recv
err
:=
xml
.
Unmarshal
(
src_data
,
&
msg4_recv
)
err
:=
xml
.
Unmarshal
(
src_data
,
&
msg4_recv
)
if
nil
!=
err
{
if
nil
!=
err
{
...
@@ -94,7 +94,7 @@ func (self *XmlProcessor) parse(src_data []byte) (*WXBizMsg4Recv, *CryptError) {
...
@@ -94,7 +94,7 @@ func (self *XmlProcessor) parse(src_data []byte) (*WXBizMsg4Recv, *CryptError) {
return
&
msg4_recv
,
nil
return
&
msg4_recv
,
nil
}
}
func
(
self
*
XmlProcessor
)
serialize
(
msg4_send
*
WXBizMsg4Send
)
([]
byte
,
*
CryptError
)
{
func
(
wxstruct
*
XmlProcessor
)
serialize
(
msg4_send
*
WXBizMsg4Send
)
([]
byte
,
*
CryptError
)
{
xml_msg
,
err
:=
xml
.
Marshal
(
msg4_send
)
xml_msg
,
err
:=
xml
.
Marshal
(
msg4_send
)
if
nil
!=
err
{
if
nil
!=
err
{
return
nil
,
NewCryptError
(
GenXmlError
,
err
.
Error
())
return
nil
,
NewCryptError
(
GenXmlError
,
err
.
Error
())
...
@@ -113,7 +113,7 @@ func NewWXBizMsgCrypt(token, encoding_aeskey, receiver_id string, protocol_type
...
@@ -113,7 +113,7 @@ func NewWXBizMsgCrypt(token, encoding_aeskey, receiver_id string, protocol_type
return
&
WXBizMsgCrypt
{
token
:
token
,
encoding_aeskey
:
(
encoding_aeskey
+
"="
),
receiver_id
:
receiver_id
,
protocol_processor
:
protocol_processor
}
return
&
WXBizMsgCrypt
{
token
:
token
,
encoding_aeskey
:
(
encoding_aeskey
+
"="
),
receiver_id
:
receiver_id
,
protocol_processor
:
protocol_processor
}
}
}
func
(
self
*
WXBizMsgCrypt
)
randString
(
n
int
)
string
{
func
(
wxstruct
*
WXBizMsgCrypt
)
randString
(
n
int
)
string
{
b
:=
make
([]
byte
,
n
)
b
:=
make
([]
byte
,
n
)
for
i
:=
range
b
{
for
i
:=
range
b
{
b
[
i
]
=
letterBytes
[
rand
.
Int63
()
%
int64
(
len
(
letterBytes
))]
b
[
i
]
=
letterBytes
[
rand
.
Int63
()
%
int64
(
len
(
letterBytes
))]
...
@@ -121,7 +121,7 @@ func (self *WXBizMsgCrypt) randString(n int) string {
...
@@ -121,7 +121,7 @@ func (self *WXBizMsgCrypt) randString(n int) string {
return
string
(
b
)
return
string
(
b
)
}
}
func
(
self
*
WXBizMsgCrypt
)
pKCS7Padding
(
plaintext
string
,
block_size
int
)
[]
byte
{
func
(
wxstruct
*
WXBizMsgCrypt
)
pKCS7Padding
(
plaintext
string
,
block_size
int
)
[]
byte
{
padding
:=
block_size
-
(
len
(
plaintext
)
%
block_size
)
padding
:=
block_size
-
(
len
(
plaintext
)
%
block_size
)
padtext
:=
bytes
.
Repeat
([]
byte
{
byte
(
padding
)},
padding
)
padtext
:=
bytes
.
Repeat
([]
byte
{
byte
(
padding
)},
padding
)
var
buffer
bytes
.
Buffer
var
buffer
bytes
.
Buffer
...
@@ -130,7 +130,7 @@ func (self *WXBizMsgCrypt) pKCS7Padding(plaintext string, block_size int) []byte
...
@@ -130,7 +130,7 @@ func (self *WXBizMsgCrypt) pKCS7Padding(plaintext string, block_size int) []byte
return
buffer
.
Bytes
()
return
buffer
.
Bytes
()
}
}
func
(
self
*
WXBizMsgCrypt
)
pKCS7Unpadding
(
plaintext
[]
byte
,
block_size
int
)
([]
byte
,
*
CryptError
)
{
func
(
wxstruct
*
WXBizMsgCrypt
)
pKCS7Unpadding
(
plaintext
[]
byte
,
block_size
int
)
([]
byte
,
*
CryptError
)
{
plaintext_len
:=
len
(
plaintext
)
plaintext_len
:=
len
(
plaintext
)
if
nil
==
plaintext
||
plaintext_len
==
0
{
if
nil
==
plaintext
||
plaintext_len
==
0
{
return
nil
,
NewCryptError
(
DecryptAESError
,
"pKCS7Unpadding error nil or zero"
)
return
nil
,
NewCryptError
(
DecryptAESError
,
"pKCS7Unpadding error nil or zero"
)
...
@@ -142,13 +142,13 @@ func (self *WXBizMsgCrypt) pKCS7Unpadding(plaintext []byte, block_size int) ([]b
...
@@ -142,13 +142,13 @@ func (self *WXBizMsgCrypt) pKCS7Unpadding(plaintext []byte, block_size int) ([]b
return
plaintext
[
:
plaintext_len
-
padding_len
],
nil
return
plaintext
[
:
plaintext_len
-
padding_len
],
nil
}
}
func
(
self
*
WXBizMsgCrypt
)
cbcEncrypter
(
plaintext
string
)
([]
byte
,
*
CryptError
)
{
func
(
wxstruct
*
WXBizMsgCrypt
)
cbcEncrypter
(
plaintext
string
)
([]
byte
,
*
CryptError
)
{
aeskey
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
self
.
encoding_aeskey
)
aeskey
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
wxstruct
.
encoding_aeskey
)
if
nil
!=
err
{
if
nil
!=
err
{
return
nil
,
NewCryptError
(
DecodeBase64Error
,
err
.
Error
())
return
nil
,
NewCryptError
(
DecodeBase64Error
,
err
.
Error
())
}
}
const
block_size
=
32
const
block_size
=
32
pad_msg
:=
self
.
pKCS7Padding
(
plaintext
,
block_size
)
pad_msg
:=
wxstruct
.
pKCS7Padding
(
plaintext
,
block_size
)
block
,
err
:=
aes
.
NewCipher
(
aeskey
)
block
,
err
:=
aes
.
NewCipher
(
aeskey
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -167,8 +167,8 @@ func (self *WXBizMsgCrypt) cbcEncrypter(plaintext string) ([]byte, *CryptError)
...
@@ -167,8 +167,8 @@ func (self *WXBizMsgCrypt) cbcEncrypter(plaintext string) ([]byte, *CryptError)
return
base64_msg
,
nil
return
base64_msg
,
nil
}
}
func
(
self
*
WXBizMsgCrypt
)
cbcDecrypter
(
base64_encrypt_msg
string
)
([]
byte
,
*
CryptError
)
{
func
(
wxstruct
*
WXBizMsgCrypt
)
cbcDecrypter
(
base64_encrypt_msg
string
)
([]
byte
,
*
CryptError
)
{
aeskey
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
self
.
encoding_aeskey
)
aeskey
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
wxstruct
.
encoding_aeskey
)
if
nil
!=
err
{
if
nil
!=
err
{
return
nil
,
NewCryptError
(
DecodeBase64Error
,
err
.
Error
())
return
nil
,
NewCryptError
(
DecodeBase64Error
,
err
.
Error
())
}
}
...
@@ -200,8 +200,8 @@ func (self *WXBizMsgCrypt) cbcDecrypter(base64_encrypt_msg string) ([]byte, *Cry
...
@@ -200,8 +200,8 @@ func (self *WXBizMsgCrypt) cbcDecrypter(base64_encrypt_msg string) ([]byte, *Cry
return
encrypt_msg
,
nil
return
encrypt_msg
,
nil
}
}
func
(
self
*
WXBizMsgCrypt
)
calSignature
(
timestamp
,
nonce
,
data
string
)
string
{
func
(
wxstruct
*
WXBizMsgCrypt
)
calSignature
(
timestamp
,
nonce
,
data
string
)
string
{
sort_arr
:=
[]
string
{
self
.
token
,
timestamp
,
nonce
,
data
}
sort_arr
:=
[]
string
{
wxstruct
.
token
,
timestamp
,
nonce
,
data
}
sort
.
Strings
(
sort_arr
)
sort
.
Strings
(
sort_arr
)
var
buffer
bytes
.
Buffer
var
buffer
bytes
.
Buffer
for
_
,
value
:=
range
sort_arr
{
for
_
,
value
:=
range
sort_arr
{
...
@@ -214,9 +214,9 @@ func (self *WXBizMsgCrypt) calSignature(timestamp, nonce, data string) string {
...
@@ -214,9 +214,9 @@ func (self *WXBizMsgCrypt) calSignature(timestamp, nonce, data string) string {
return
string
(
signature
)
return
string
(
signature
)
}
}
func
(
self
*
WXBizMsgCrypt
)
ParsePlainText
(
plaintext
[]
byte
)
([]
byte
,
uint32
,
[]
byte
,
[]
byte
,
*
CryptError
)
{
func
(
wxstruct
*
WXBizMsgCrypt
)
ParsePlainText
(
plaintext
[]
byte
)
([]
byte
,
uint32
,
[]
byte
,
[]
byte
,
*
CryptError
)
{
const
block_size
=
32
const
block_size
=
32
plaintext
,
err
:=
self
.
pKCS7Unpadding
(
plaintext
,
block_size
)
plaintext
,
err
:=
wxstruct
.
pKCS7Unpadding
(
plaintext
,
block_size
)
if
nil
!=
err
{
if
nil
!=
err
{
return
nil
,
0
,
nil
,
nil
,
err
return
nil
,
0
,
nil
,
nil
,
err
}
}
...
@@ -237,32 +237,32 @@ func (self *WXBizMsgCrypt) ParsePlainText(plaintext []byte) ([]byte, uint32, []b
...
@@ -237,32 +237,32 @@ func (self *WXBizMsgCrypt) ParsePlainText(plaintext []byte) ([]byte, uint32, []b
return
random
,
msg_len
,
msg
,
receiver_id
,
nil
return
random
,
msg_len
,
msg
,
receiver_id
,
nil
}
}
func
(
self
*
WXBizMsgCrypt
)
VerifyURL
(
msg_signature
,
timestamp
,
nonce
,
echostr
string
)
([]
byte
,
*
CryptError
)
{
func
(
wxstruct
*
WXBizMsgCrypt
)
VerifyURL
(
msg_signature
,
timestamp
,
nonce
,
echostr
string
)
([]
byte
,
*
CryptError
)
{
signature
:=
self
.
calSignature
(
timestamp
,
nonce
,
echostr
)
signature
:=
wxstruct
.
calSignature
(
timestamp
,
nonce
,
echostr
)
if
strings
.
Compare
(
signature
,
msg_signature
)
!=
0
{
if
strings
.
Compare
(
signature
,
msg_signature
)
!=
0
{
return
nil
,
NewCryptError
(
ValidateSignatureError
,
"signature not equal"
)
return
nil
,
NewCryptError
(
ValidateSignatureError
,
"signature not equal"
)
}
}
plaintext
,
err
:=
self
.
cbcDecrypter
(
echostr
)
plaintext
,
err
:=
wxstruct
.
cbcDecrypter
(
echostr
)
if
nil
!=
err
{
if
nil
!=
err
{
return
nil
,
err
return
nil
,
err
}
}
_
,
_
,
msg
,
receiver_id
,
err
:=
self
.
ParsePlainText
(
plaintext
)
_
,
_
,
msg
,
receiver_id
,
err
:=
wxstruct
.
ParsePlainText
(
plaintext
)
if
nil
!=
err
{
if
nil
!=
err
{
return
nil
,
err
return
nil
,
err
}
}
if
len
(
self
.
receiver_id
)
>
0
&&
strings
.
Compare
(
string
(
receiver_id
),
self
.
receiver_id
)
!=
0
{
if
len
(
wxstruct
.
receiver_id
)
>
0
&&
strings
.
Compare
(
string
(
receiver_id
),
wxstruct
.
receiver_id
)
!=
0
{
return
nil
,
NewCryptError
(
ValidateCorpidError
,
"receiver_id is not equil"
)
return
nil
,
NewCryptError
(
ValidateCorpidError
,
"receiver_id is not equil"
)
}
}
return
msg
,
nil
return
msg
,
nil
}
}
func
(
self
*
WXBizMsgCrypt
)
EncryptMsg
(
reply_msg
,
timestamp
,
nonce
string
)
([]
byte
,
*
CryptError
)
{
func
(
wxstruct
*
WXBizMsgCrypt
)
EncryptMsg
(
reply_msg
,
timestamp
,
nonce
string
)
([]
byte
,
*
CryptError
)
{
rand_str
:=
self
.
randString
(
16
)
rand_str
:=
wxstruct
.
randString
(
16
)
var
buffer
bytes
.
Buffer
var
buffer
bytes
.
Buffer
buffer
.
WriteString
(
rand_str
)
buffer
.
WriteString
(
rand_str
)
...
@@ -270,43 +270,43 @@ func (self *WXBizMsgCrypt) EncryptMsg(reply_msg, timestamp, nonce string) ([]byt
...
@@ -270,43 +270,43 @@ func (self *WXBizMsgCrypt) EncryptMsg(reply_msg, timestamp, nonce string) ([]byt
binary
.
BigEndian
.
PutUint32
(
msg_len_buf
,
uint32
(
len
(
reply_msg
)))
binary
.
BigEndian
.
PutUint32
(
msg_len_buf
,
uint32
(
len
(
reply_msg
)))
buffer
.
Write
(
msg_len_buf
)
buffer
.
Write
(
msg_len_buf
)
buffer
.
WriteString
(
reply_msg
)
buffer
.
WriteString
(
reply_msg
)
buffer
.
WriteString
(
self
.
receiver_id
)
buffer
.
WriteString
(
wxstruct
.
receiver_id
)
tmp_ciphertext
,
err
:=
self
.
cbcEncrypter
(
buffer
.
String
())
tmp_ciphertext
,
err
:=
wxstruct
.
cbcEncrypter
(
buffer
.
String
())
if
nil
!=
err
{
if
nil
!=
err
{
return
nil
,
err
return
nil
,
err
}
}
ciphertext
:=
string
(
tmp_ciphertext
)
ciphertext
:=
string
(
tmp_ciphertext
)
signature
:=
self
.
calSignature
(
timestamp
,
nonce
,
ciphertext
)
signature
:=
wxstruct
.
calSignature
(
timestamp
,
nonce
,
ciphertext
)
msg4_send
:=
NewWXBizMsg4Send
(
ciphertext
,
signature
,
timestamp
,
nonce
)
msg4_send
:=
NewWXBizMsg4Send
(
ciphertext
,
signature
,
timestamp
,
nonce
)
return
self
.
protocol_processor
.
serialize
(
msg4_send
)
return
wxstruct
.
protocol_processor
.
serialize
(
msg4_send
)
}
}
func
(
self
*
WXBizMsgCrypt
)
DecryptMsg
(
msg_signature
,
timestamp
,
nonce
string
,
post_data
[]
byte
)
([]
byte
,
*
CryptError
)
{
func
(
wxstruct
*
WXBizMsgCrypt
)
DecryptMsg
(
msg_signature
,
timestamp
,
nonce
string
,
post_data
[]
byte
)
([]
byte
,
*
CryptError
)
{
msg4_recv
,
crypt_err
:=
self
.
protocol_processor
.
parse
(
post_data
)
msg4_recv
,
crypt_err
:=
wxstruct
.
protocol_processor
.
parse
(
post_data
)
if
nil
!=
crypt_err
{
if
nil
!=
crypt_err
{
return
nil
,
crypt_err
return
nil
,
crypt_err
}
}
signature
:=
self
.
calSignature
(
timestamp
,
nonce
,
msg4_recv
.
Encrypt
)
signature
:=
wxstruct
.
calSignature
(
timestamp
,
nonce
,
msg4_recv
.
Encrypt
)
if
strings
.
Compare
(
signature
,
msg_signature
)
!=
0
{
if
strings
.
Compare
(
signature
,
msg_signature
)
!=
0
{
return
nil
,
NewCryptError
(
ValidateSignatureError
,
"signature not equal"
)
return
nil
,
NewCryptError
(
ValidateSignatureError
,
"signature not equal"
)
}
}
plaintext
,
crypt_err
:=
self
.
cbcDecrypter
(
msg4_recv
.
Encrypt
)
plaintext
,
crypt_err
:=
wxstruct
.
cbcDecrypter
(
msg4_recv
.
Encrypt
)
if
nil
!=
crypt_err
{
if
nil
!=
crypt_err
{
return
nil
,
crypt_err
return
nil
,
crypt_err
}
}
_
,
_
,
msg
,
receiver_id
,
crypt_err
:=
self
.
ParsePlainText
(
plaintext
)
_
,
_
,
msg
,
receiver_id
,
crypt_err
:=
wxstruct
.
ParsePlainText
(
plaintext
)
if
nil
!=
crypt_err
{
if
nil
!=
crypt_err
{
return
nil
,
crypt_err
return
nil
,
crypt_err
}
}
if
len
(
self
.
receiver_id
)
>
0
&&
strings
.
Compare
(
string
(
receiver_id
),
self
.
receiver_id
)
!=
0
{
if
len
(
wxstruct
.
receiver_id
)
>
0
&&
strings
.
Compare
(
string
(
receiver_id
),
wxstruct
.
receiver_id
)
!=
0
{
return
nil
,
NewCryptError
(
ValidateCorpidError
,
"receiver_id is not equil"
)
return
nil
,
NewCryptError
(
ValidateCorpidError
,
"receiver_id is not equil"
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment