Пример #1
0
func main() {
	var wg sync.WaitGroup

	doc, err := goquery.NewDocument(url)
	logging.CheckFatal(err)

	hashes, err = os.Create("hashes")
	logging.CheckFatal(err)
	defer hashes.Close()

	doc.Find("a").Each(
		func(i int, s *goquery.Selection) {
			link, found := s.Attr("href")
			title, _ := s.Attr("title")
			// if found && strings.HasSuffix(link, ".pdf") {
			if found {
				wg.Add(1)
				go fetchPDF(&wg, link, title)
			}
			return
		})
	wg.Wait()
	// log.Notice("Done")
	log.Println("Done")
}
Пример #2
0
func sendEmail(headers map[string]string, body string, address string, gConfig map[string]string) {

	host := gConfig["REMOTE_SMTP_HOST"]
	port := gConfig["REMOTE_SMTP_PORT"]
	user := gConfig["REMOTE_SMTP_USER"]
	password := gConfig["REMOTE_SMTP_PASS"]

	m := email.NewMessage(headers["Subject"], body)

	fromAddress := "Unknown"
	fromHeader, ok := headers["From"]
	if ok {
		from, _ := mail.ParseAddress(fromHeader)
		fromAddress = from.Address
	}

	to, _ := mail.ParseAddress(address)
	toAddress := to.Address

	m.From = fromAddress
	m.To = []string{toAddress}

	if gConfig["PGP_ATTACH_BODY"] == "Y" {
		m.AttachData("message.asc", []byte(body))
	}

	err := email.Send(host+":"+port, smtp.PlainAuth("", user, password, host), m)
	logging.CheckFatal(err)
}
Пример #3
0
func encrypt(input string, email string, gConfig map[string]string) string {

	os.MkdirAll(gConfig["PGP_KEY_FOLDER"], 0777)
	keyfileName := path.Join(gConfig["PGP_KEY_FOLDER"], email+".asc")
	keyfileExists, _ := exists(keyfileName)
	if !keyfileExists {

		key := publickey.GetKeyFromEmail(email, gConfig["PGP_KEYSERVER"], gConfig["PGP_KEYSERVER_QUERY"])
		if key == "no keys found" {
			return key + " on keyserver " + gConfig["PGP_KEYSERVER"] + " from query " + gConfig["PGP_KEYSERVER"] + gConfig["PGP_KEYSERVER_QUERY"] + email
		}

		if key == "invalid host" {
			return gConfig["PGP_KEYSERVER"] + " is offline and your key has not previously been cached."
		}

		f, err := os.Create(keyfileName)
		if err != nil {
			fmt.Println(err)
		}
		n, err := io.WriteString(f, key)
		if err != nil {
			fmt.Println(n, err)
		}
		f.Close()
	}

	to, err := os.Open(keyfileName)
	logging.CheckFatal(err)

	defer to.Close()

	entitylist, err := openpgp.ReadArmoredKeyRing(to)

	buf := new(bytes.Buffer)
	w, _ := armor.Encode(buf, encryptionType, nil)
	plaintext, _ := openpgp.Encrypt(w, entitylist, nil, nil, nil)

	fmt.Fprintf(plaintext, input)
	plaintext.Close()
	w.Close()

	return buf.String()

}
Пример #4
0
func sendEmail(body string) {
	// Set up authentication information.
	auth := smtp.PlainAuth(
		"",
		gConfig["REMOTE_SMTP_USER"],
		gConfig["REMOTE_SMTP_PASS"],
		gConfig["REMOTE_SMTP_HOST"],
	)
	// Connect to the server, authenticate, set the sender and recipient,
	// and send the email all in one step.
	err := smtp.SendMail(
		gConfig["REMOTE_SMTP_HOST"]+":"+gConfig["REMOTE_SMTP_PORT"],
		auth,
		"*****@*****.**",
		[]string{"*****@*****.**"},
		[]byte("\n"+body),
	)
	logging.CheckFatal(err)
}
Пример #5
0
func encrypt(input string, email string) string {

	to, err := os.Open(email + ".asc")
	logging.CheckFatal(err)
	defer to.Close()

	entitylist, err := openpgp.ReadArmoredKeyRing(to)

	buf := new(bytes.Buffer)
	w, _ := armor.Encode(buf, encryptionType, nil)
	plaintext, _ := openpgp.Encrypt(w, entitylist, nil, nil, nil)

	fmt.Fprintf(plaintext, input)
	plaintext.Close()
	w.Close()

	return buf.String()

}
Пример #6
0
func main2() {

	// open ascii armored private key
	from, err := os.Open("my.asc.key")
	logging.CheckFatal(err)
	defer from.Close()

	// decode armor and check key type
	fromBlock, err := armor.Decode(from)
	logging.CheckFatal(err)

	if fromBlock.Type != openpgp.PrivateKeyType {
		logging.CheckFatal(fmt.Errorf("from key type:%s", fromBlock.Type))
	}

	// parse and decrypt decoded key
	fromReader := packet.NewReader(fromBlock.Body)
	fromEntity, err := openpgp.ReadEntity(fromReader)
	logging.CheckFatal(err)

	log.Println("Enter Key Passphrase:")
	pw, err := terminal.ReadPassword(0)
	logging.CheckFatal(err)

	err = fromEntity.PrivateKey.Decrypt(pw)
	logging.CheckFatal(err)

	// open destination key (no ascii armor here)
	to, err := os.Open("mkd.pubkey")
	logging.CheckFatal(err)
	defer to.Close()

	toReader := packet.NewReader(to)
	toEntity, err := openpgp.ReadEntity(toReader)
	logging.CheckFatal(err)

	log.Printf("to: %x", toEntity.PrimaryKey.Fingerprint)
	log.Printf("from: %x", fromEntity.PrimaryKey.Fingerprint)

	// output file
	out, err := os.Create("out.enc")
	logging.CheckFatal(err)
	defer out.Close()

	hints := &openpgp.FileHints{
		IsBinary: true,
		FileName: "test.zip",
		ModTime:  time.Now(),
	}

	// prepare encryption pipe
	encOut, err := openpgp.Encrypt(out, []*openpgp.Entity{toEntity}, fromEntity, hints, nil)
	logging.CheckFatal(err)

	// for fun, lets write a zip file to it created inline
	zipW := zip.NewWriter(encOut)

	t1, err := zipW.Create("test1.de.txt")
	logging.CheckFatal(err)
	fmt.Fprintln(t1, "Hallo Welt")

	t2, err := zipW.Create("test1.en.txt")
	logging.CheckFatal(err)
	fmt.Fprintln(t2, "Hello World - the 2nd")

	logging.CheckFatal(zipW.Flush())
	logging.CheckFatal(zipW.Close())

	// close the encPipe to finish the process
	logging.CheckFatal(encOut.Close())
}