Update docs with download links instead of file contents
This commit is contained in:
parent
bee38d4f9d
commit
efe0b21d7b
|
@ -8,42 +8,6 @@ We're creating our web server file, building it and signing the application.
|
|||
|
||||
## Creating the Server File
|
||||
|
||||
Download `server.go` by running the following in a command prompt:
|
||||
|
||||
```
|
||||
# Download the config file.
|
||||
powershell "Invoke-WebRequest -OutFile b0x.json https://git.rootprojects.org/josh/code-signing-final/raw/branch/master/All/server.go"
|
||||
```
|
||||
https://git.rootprojects.org/josh/code-signing-final/raw/branch/master/All/serve.go
|
||||
|
||||
Create a file named `server.go` and add the following:
|
||||
|
||||
```
|
||||
//go:generate goversioninfo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
port := flag.String("p", "8100", "port to serve on")
|
||||
directory := flag.String("d", ".", "the directory of static file to host")
|
||||
flag.Parse()
|
||||
|
||||
http.Handle("/", http.FileServer(http.Dir(*directory)))
|
||||
|
||||
log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)
|
||||
log.Fatal(http.ListenAndServe(":"+*port, nil))
|
||||
}
|
||||
```
|
||||
|
||||
*Windows 10 will happily create server.go.txt if you don't turn off hidden file extensions and leave you wondering what's wrong with your Go install.*
|
||||
|
||||
First of all, you'll want to install Golang: https://golang.org/dl/
|
||||
Then you'll want to install [goversioninfo](https://github.com/josephspurrier/goversioninfo) by running the following in a command prompt:
|
||||
|
||||
|
@ -53,9 +17,12 @@ go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo
|
|||
|
||||
This will allow us to set the name of the program, version, publisher name, etc.
|
||||
|
||||
Download `server.go` by running the following in a command prompt:
|
||||
|
||||
```
|
||||
# Add this to the top of your server go file.
|
||||
//go:generate goversioninfo
|
||||
# Download the server file.
|
||||
powershell -Command Invoke-WebRequest -OutFile server.go https://git.rootprojects.org/josh/code-signing-final/raw/branch/master/All/server.go
|
||||
|
||||
# Then generate the configuration by running the following in a command prompt:
|
||||
go generate
|
||||
```
|
||||
|
@ -78,7 +45,7 @@ go build -o server.exe -ldflags "-s -w -H=windowsgui"
|
|||
|
||||
You will want to sign your application, the next section will show you how.
|
||||
|
||||
## Signing the Setup File
|
||||
# Signing the Setup File
|
||||
|
||||
### Getting a Code Signing Certificate
|
||||
|
||||
|
@ -101,7 +68,7 @@ Choose the "Universal Windows Platform Development" workload. After you have fin
|
|||
|
||||
```
|
||||
# Sign a file with your certificate.
|
||||
SignTool sign /t http://timestamp.comodoca.com /f codesigning.p12 /p <Password> file.exe
|
||||
SignTool sign /t http://timestamp.comodoca.com /f codesigning.p12 /p <Password> server.exe
|
||||
```
|
||||
|
||||
![](signfile.png)
|
||||
|
@ -116,79 +83,11 @@ Now we're going to create the setup file that will create the firewall rule we n
|
|||
|
||||
## Firewall Rule
|
||||
|
||||
Create a file named `setup.go` and include the following:
|
||||
|
||||
```
|
||||
//go:generate goversioninfo -manifest=setup.exe.manifest
|
||||
//Add new firewall rule in Go.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"io/ioutil"
|
||||
"syscall"
|
||||
"fmt"
|
||||
"log"
|
||||
"static" // Your fileb0x.
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// Grab files from virtual filesystem
|
||||
files, err := static.WalkDirs("", false)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Println("ALL FILES", files)
|
||||
}
|
||||
|
||||
// here we'll read the file from the virtual file system
|
||||
b, err := static.ReadFile("server.exe")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Copy file from virtual filesystem to real filesystem
|
||||
err = ioutil.WriteFile("server.exe", b, 0644)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating", "server.exe")
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Get current working directory and set it to 'dir'.
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Set server file path to 'file'
|
||||
var file = "-Program '" + dir + "\\server.exe'"
|
||||
//Create firewall rule
|
||||
cmdinstance := exec.Command("powershell.exe", "-WindowStyle", "Hidden", "-Command", "New-NetFirewallRule", "-DisplayName", "'Go Web Server'", "-Direction", "Inbound", file, "-Action", "Allow")
|
||||
cmdinstance.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // Make it silent.
|
||||
cmdoutput, cmderr := cmdinstance.Output()
|
||||
if cmderr != nil {
|
||||
fmt.Println(cmderr)
|
||||
fmt.Println(cmdoutput)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then create another file called `setup.exe.manifest` containing:
|
||||
|
||||
```
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<security>
|
||||
<requestedPrivileges>
|
||||
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
|
||||
</requestedPrivileges>
|
||||
</security>
|
||||
</trustInfo>
|
||||
</assembly>
|
||||
# Download the server file.
|
||||
powershell -Command Invoke-WebRequest -OutFile setup.go https://git.rootprojects.org/josh/code-signing-final/raw/branch/master/All/setup.go
|
||||
# And the manifest file to allow it to have administrator privileges.
|
||||
powershell -Command Invoke-WebRequest -OutFile setup.exe.manifest https://git.rootprojects.org/josh/code-signing-final/raw/branch/master/All/setup.exe.manifest
|
||||
```
|
||||
|
||||
Rename `server.go` to `server.go_`
|
||||
|
@ -203,9 +102,10 @@ go get -u github.com/UnnoTed/fileb0x
|
|||
```
|
||||
|
||||
Download a pre-made configuration file by running this in the command prompt:
|
||||
|
||||
```
|
||||
# Download the config file.
|
||||
powershell "Invoke-WebRequest -OutFile b0x.json https://git.rootprojects.org/josh/code-signing-final/raw/branch/master/All/b0x.json"
|
||||
powershell -Command Invoke-WebRequest -OutFile b0x.json https://git.rootprojects.org/josh/code-signing-final/raw/branch/master/All/b0x.json
|
||||
```
|
||||
|
||||
```
|
||||
|
@ -213,14 +113,16 @@ powershell "Invoke-WebRequest -OutFile b0x.json https://git.rootprojects.org/jos
|
|||
fileb0x b0x.json
|
||||
```
|
||||
|
||||
This will create a folder named `static` with a file in it. You will then need to copy that folder to your `$GOPATH/src/` (usually C:\Users\Username\Go\src\).
|
||||
This will create a folder named `static` with a file in it. You will then need to copy that folder to your `$GOPATH/src/` (usually `C:\Users\<Username>\go\src\`).
|
||||
|
||||
```
|
||||
# Build the setup application.
|
||||
go build -o setup.exe -ldflags "-s -w -H=windowsgui"
|
||||
```
|
||||
|
||||
## WIP
|
||||
Refer back to the instructions on [How to Sign a File](#signing-the-setup -file) to sign your setup file as well. Then you're done!
|
||||
|
||||
## WIP: Service
|
||||
|
||||
Service: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-service?view=powershell-6
|
||||
Credential seems to be what makes it admin or not: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-service?view=powershell-6
|
||||
|
|
Loading…
Reference in New Issue