Skip to content

Instantly share code, notes, and snippets.

@svicknesh
svicknesh / client.go
Created August 13, 2019 00:39 — forked from xjdrew/client.go
golang tls client and server, require and verify certificate in double direction
package main
import (
"crypto/tls"
"crypto/x509"
"flag"
"io"
"io/ioutil"
"log"
"os"
@svicknesh
svicknesh / csr.go
Created July 30, 2019 04:29
Golang - create CSR (from stack overflow)
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/asn1"
"encoding/pem"
"os"
@svicknesh
svicknesh / gen_ca_csr.go
Created July 30, 2019 04:24
Golang - Create CA and build CSR for signing
//
// createCertificateAuthority generates a certificate authority request ready to be signed
//
func (r *secretStore) createCertificateAuthority(names pkix.Name, expiration time.Duration, size int) (*caCertificate, error) {
// step: generate a keypair
keys, err := rsa.GenerateKey(rand.Reader, size)
if err != nil {
return nil, fmt.Errorf("unable to genarate private keys, error: %s", err)
}
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
// Generate a self-signed X.509 certificate for a TLS server. Outputs to
// 'cert.pem' and 'key.pem' and will overwrite existing files.
package main
@svicknesh
svicknesh / 1_simple.go
Created July 24, 2019 03:18 — forked from sosedoff/1_simple.go
Golang Custom Struct Tags Example
package main
import (
"fmt"
"reflect"
)
// Name of the struct tag used in examples
const tagName = "validate"
@svicknesh
svicknesh / bitmask.go
Created March 13, 2018 11:38 — forked from josephspurrier/bitmask.go
Golang - Determine if bitmask is set
/*
fmt.Println(Bitmask(0x6).IsSet(0x2))
fmt.Println(Bitmask(f.FileHeader.Characteristics).ListDescriptions(charValues))
fmt.Println(Bitmask(f.FileHeader.Characteristics).ListValues(charValues))
*/
type Bitmask uint16
// BitValue is a value and a description
type BitValue struct {
@svicknesh
svicknesh / keys.go
Created March 13, 2018 07:42 — forked from sdorra/keys.go
Golang RSA Key Generation
/*
* Genarate rsa keys.
*/
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
LANG=en_US.utf-8
LC_ALL=en_US.utf-8
@svicknesh
svicknesh / htpasswd-ssl.sh
Created October 6, 2017 03:07 — forked from samba/htpasswd-ssl.sh
htpasswd replacement with openssl
#!/bin/sh
# Writes an APR1-format password hash to the provided <htpasswd-file> for a provided <username>
# This is useful where an alternative web server (e.g. nginx) supports APR1 but no `htpasswd` is installed.
# The APR1 format provides signifcantly stronger password validation, and is described here:
# http://httpd.apache.org/docs/current/misc/password_encryptions.html
help (){
cat <<EOF
Usage: $0 <htpasswd-file> <username>
export VPN_NAME="my_private_vpn"
export MY_NAME="raspi"
export VPN_IP="172.16.1.2" # change this to be different for each node
export CONNECTION="LAN" # is this server connected to a "WAN" or "LAN"
export TINC_PORT="655"
export AUTO_TRUE="YES"