Initial commit

This commit is contained in:
2020-02-15 09:02:23 -05:00
commit cc2cd013be
9 changed files with 197 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
conf.json
priv.key
emailBot
Keybase-Email.log
*.eml
*.sig

6
conf.json.example Normal file
View File

@ -0,0 +1,6 @@
{
"email": "rudi@nmare.net",
"smtp_server":"oogieboogie.nightmare.haus:587",
"auth_server":"oogieboogie.nightmare.haus",
"private_key":""
}

1
default.sig.example Normal file
View File

@ -0,0 +1 @@
This email message and attachment(s) may contain sensitive and/or proprietary information and is intended only for the person(s) to whom this email message is addressed. If you have received this email message in error, please notify the sender immediately and destroy the original message without making a copy. Please do not transmit any sensitive, proprietary, ITARS or FOUO data via e-mail without using approved encryption techniques.

31
mailHelper.go Normal file
View File

@ -0,0 +1,31 @@
package main
import "fmt"
import "net/smtp"
func send(e Email) {
e.Body = signMessage(e.Body)
message := fmt.Sprintf("From: %s\n", conf.MyEmail)
for _, recipient := range e.Recipients {
message += fmt.Sprintf("To: %s\n", recipient)
}
for _, cc := range e.Cc {
message += fmt.Sprintf("Cc: %s\n", cc)
}
for _, bcc := range e.Bcc {
message += fmt.Sprintf("Bcc: %s\n", bcc)
}
message += fmt.Sprintf("Subject: %s\n", e.Subject)
message += e.Body
log.LogInfo("Message created")
log.LogDebug(message)
log.LogInfo("Sending message")
err := smtp.SendMail(conf.SmtpServer,
smtp.PlainAuth("", conf.MyEmail, conf.EmailPass, conf.AuthServer),
conf.MyEmail, e.Recipients, []byte(message))
if err != nil {
log.LogErrorType(err)
}
log.LogInfo("Email Sent")
}

78
main.go Normal file
View File

@ -0,0 +1,78 @@
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
"syscall"
"time"
"github.com/rudi9719/loggy"
"golang.org/x/crypto/ssh/terminal"
"samhofi.us/x/keybase"
)
var (
k = keybase.NewKeybase()
logOpts = loggy.LogOpts{
//OutFile: "Keybase-Email.log",
//KBTeam: "nightmarehaus.logs",
//KBChann: "general",
//ProgName: "KB-Email",
Level: 5,
UseStdout: true,
}
log = loggy.NewLogger(logOpts)
conf = Config{}
)
func main() {
if !k.LoggedIn {
log.LogPanic("Keybase not logged in.")
}
log.LogInfo(fmt.Sprintf("Bot started using account %s", k.Username))
conf = loadConfig()
setupCredentials()
em := Email{
Recipients: []string{"rudi@nmare.net"},
Subject: "Test Email",
Body: "Hello, world!",
}
send(em)
time.Sleep(2 * time.Second)
}
func loadConfig() Config {
var c Config
bytes, err := ioutil.ReadFile("conf.json")
if err != nil {
log.LogErrorType(err)
}
err = json.Unmarshal(bytes, &c)
if err != nil {
log.LogErrorType(err)
}
bytes, err = ioutil.ReadFile("priv.key")
if err != nil {
log.LogErrorType(err)
}
c.PrivateKey = string(bytes)
return c
}
func setupCredentials() {
log.LogCritical("Enter pgp key passphrase:")
bytePass, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
log.LogCritical(fmt.Sprintf("Error reading pgp password:\n```%+v```", err))
}
conf.KeyPass = strings.TrimSpace(string(bytePass))
log.LogCritical("Enter email passphrase:")
bytePass, err = terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
log.LogCritical(fmt.Sprintf("Error reading email password:\n```%+v```", err))
}
conf.EmailPass = strings.TrimSpace(string(bytePass))
}

52
pgpHelper.go Normal file
View File

@ -0,0 +1,52 @@
package main
import (
"bytes"
// "encoding/base64"
"fmt"
"golang.org/x/crypto/openpgp"
"golang.org/x/crypto/openpgp/clearsign"
"strings"
)
func getPrivateKey() *openpgp.Entity {
pp := conf.KeyPass
ppb := []byte(pp)
log.LogInfo("Getting entityList")
entitylist, err := openpgp.ReadArmoredKeyRing(strings.NewReader(conf.PrivateKey))
if err != nil {
log.LogErrorType(err)
}
log.LogInfo(fmt.Sprintf("Getting entity 0 ```%+v```", entitylist))
entity := entitylist[0]
log.LogInfo("if PrivateKey != nil")
if entity.PrivateKey != nil && entity.PrivateKey.Encrypted {
err := entity.PrivateKey.Decrypt(ppb)
if err != nil {
fmt.Println("Failed to decrypt key")
}
}
for _, subkey := range entity.Subkeys {
if subkey.PrivateKey != nil && subkey.PrivateKey.Encrypted {
err := subkey.PrivateKey.Decrypt(ppb)
if err != nil {
fmt.Println("Failed to decrypt subkey")
}
}
}
return entity
}
func signMessage(m string) string {
pk := getPrivateKey()
out := new(bytes.Buffer)
in, err := clearsign.Encode(out, pk.PrivateKey, nil)
//in, err := openpgp.Sign(out, pk, nil, nil)
if err != nil {
log.LogErrorType(err)
}
in.Write([]byte(m))
in.Close()
return out.String()
}

1
priv.key.example Normal file
View File

@ -0,0 +1 @@

2
test.pgp Normal file
View File

@ -0,0 +1,2 @@
LS0tLS1CRUdJTiBQR1AgU0lHTkVEIE1FU1NBR0UtLS0tLQpIYXNoOiBTSEEyNTYKCkhlbGxvLCB3b3JsZCEKLS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0KCndzRmNCQUVCQ0FBUUJRSmVSd0JMQ1JBYXUrNnl2c3RBZXdBQVFTa1FBQ3YzcEF0T1JyTnJUbjRGdG0xajN0ZFAKNk5SUHBuYXZNN0pBSVczR2V6d2RSY05VdENTaFI4dW5SUGMzWGY3RUdyeFVPK21BR1BOamhGZy9IU3p6cysrRAo0aTBmOGJBUDl3SnpqTE5maklPdXZrZll1M1ZMbEk2eStDZGNUQWZuTVhJa1Z0akJDaS9QcmNJVWhGay9NSXRmCnpxSUtQREloMnhOcG9PRWJhanFlR3hxS3c5cGJQcUhsSzBLMlpHUE9FcVJkZ3YzKy9YQWovcW1pdk41VDNVZlYKeUtXTDlybldoVktaZytUVUVSbEdmV3I5d1FvM3R4czFvMFZkQ3IrREd6OEFZUE5vZ2o2TytrSGZ3MU5yWm0xWQpmaGw5T1Z0MlkyQ3BsWnNaQ3IrRDAvRTVPY3FLZXdzZWptMmQ4NSs4VUFUMHJ0ZThvTnd2YnJON3dzQWl6emlrCm45Tk02eTBvVFo1bDVNR1ZiYjMvNW9lMmd1OVh3elc1YTl1YUdUb2tlWXRNYWdHV3RCeFl1UHprSmxYTDliREcKSlNiUDZpQXB6TW81UnRub0xKblduQ3Nya1Y5Z0w4NUd3RlZCM1dQTUdhdmtQNDBkWjY2YWFxdXh2UWdSQkpEUAowNWx6QVR1Z1cyYkJVUDRiVHpKWUtuNmZ4Y2o2QXFaSTI4RnFpdEhReHBqb2dzSUw2UjFzUjdxS3cwZ3pSY1V1CkJqajFtbnUwNFplVlBhVmZDakRGRDVRZS9tRDhtb2VTMzlLdFQ5azdYaTRNdHNKdnZub0tDUkh1R1FVV2M1R2IKVFNsZ04xc2tacjNYOHUzQUU5TjVCQ3kreVlGL3RRbnljTGZjd2RQb0RIZ2dyTkdSUHRRWHVQeE5nbmtmbmYzNApXYjNuWGJkS3UwOUlIUXlnSUIzTQo9WXdvdgotLS0tLUVORCBQR1AgU0lHTkFUVVJFLS0tLS0=

20
types.go Normal file
View File

@ -0,0 +1,20 @@
package main
// Email for sending
type Email struct {
Recipients []string
Subject string
Cc []string
Bcc []string
Body string
}
// Config struct
type Config struct {
PrivateKey string `json:"private_key"`
KeyPass string `json:"key_pass,omitempty"`
MyEmail string `json:"email"`
EmailPass string `json:"email_pass,omitempty"`
SmtpServer string `json:"smtp_server"`
AuthServer string `json:"auth_server"`
}