For educational reasons I've decided to create my own CA. Here is what I learned.
Lets get some context first.
package main | |
import ( | |
"net" | |
"os/exec" | |
"github.com/k0kubun/pp" | |
) | |
func Hosts(cidr string) ([]string, error) { |
package main | |
import ( | |
"context" | |
"log" | |
"net/http" | |
"os" | |
"os/signal" | |
"time" | |
) |
#include <netinet/in.h> | |
#include <string.h> | |
#include <sys/socket.h> | |
#include <sys/kern_control.h> | |
#include <sys/ioctl.h> | |
#include <sys/sys_domain.h> | |
#include <sys/kern_event.h> | |
#include <sys/errno.h> | |
#define UTUN_CONTROL_NAME "com.apple.net.utun_control" |
macos: | |
1. networksetup -getcomputername | |
2. scutil --get ComputerName | |
windows: | |
1. echo %ComputerName% |
package main | |
import ( | |
"crypto" | |
"crypto/rsa" | |
"crypto/sha1" | |
"crypto/x509" | |
"encoding/base64" | |
"fmt" | |
) |
// Convert string to bytes array, don't allocate extra memory | |
// General: []byte(string), this may allocate memory more than len(string) | |
func StringToBytes(s string) []byte { | |
b := make([]byte, len(s)) | |
copy(b[:], s) | |
return b | |
} |
import ( | |
"bufio" | |
"io" | |
) | |
type FileLineFunc func(line []byte) (isExit bool, err error) | |
func ReadLines(file io.Reader, bufLen int, f FileLineFunc) error { | |
buffer := make([]byte, 0, bufLen) | |
scanner := bufio.NewScanner(file) |
func readLine(path string) { | |
inFile, _ := os.Open(path) | |
defer inFile.Close() | |
scanner := bufio.NewScanner(inFile) | |
scanner.Split(bufio.ScanLines) | |
for scanner.Scan() { | |
fmt.Println(scanner.Text()) | |
} | |
} |
package main | |
import ( | |
"fmt" | |
"labix.org/v2/mgo" | |
"labix.org/v2/mgo/bson" | |
"time" | |
) | |
type Person struct { |