Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gumble
- import (
- "time"
- "layeh.com/gumble/gumble"
- _ "layeh.com/gumble/opus"
- "crypto/tls"
- "fmt"
- "os"
- "log"
- "path/filepath"
- "crypto/rsa"
- "crypto/rand"
- "crypto/x509"
- "net"
- "github.com/Stonetium/stonetium/errs"
- )
- func GumbleInit(server, user, pass string, nocert bool) *StonetiumVoice {
- // Initialize
- s := NewStonetiumVoice(nil)
- s.Config = gumble.NewConfig()
- s.Server = server
- //Set AudioInterval to 40ms from default 10ms for improving audio quality
- s.Config.AudioInterval = time.Millisecond * 60
- s.Config.AudioDataBytes = 80
- s.Config.Username = user
- s.Config.Password = pass
- s.TLSConfig.InsecureSkipVerify = true
- dirPath, err := filepath.Abs(filepath.Dir(os.Args[0]))
- if err != nil {
- log.Println("Cannot find dir path:", dirPath)
- }
- if _, err := os.Stat(dirPath + "/certificate.pem"); os.IsNotExist(err) {
- log.Println("Mumble certificate file not found! generating one for you")
- // generate a new key-pair
- rootKey, err := rsa.GenerateKey(rand.Reader, 2048)
- if err != nil {
- log.Fatalf("generating random key: %v", err)
- }
- f, err := os.Create(dirPath + "/private.key")
- defer f.Close()
- privkeyPEM := ExportRsaPrivateKeyAsPemStr(rootKey)
- _, err = f.Write([]byte(privkeyPEM))
- if err != nil {
- log.Println("cannot write privKey bytes to file:", errs.Stack(err))
- }
- rootCertTmpl, err := CertTemplate()
- if err != nil {
- log.Fatalf("creating cert template: %v", err)
- }
- // describe what the certificate will be used for
- rootCertTmpl.IsCA = true
- rootCertTmpl.KeyUsage = x509.KeyUsageCertSign | x509.KeyUsageDigitalSignature
- rootCertTmpl.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth}
- rootCertTmpl.IPAddresses = []net.IP{net.ParseIP("127.0.0.1")}
- rootCert, rootCertPEM, err := CreateCert(rootCertTmpl, rootCertTmpl, &rootKey.PublicKey, rootKey)
- if err != nil {
- log.Fatalf("error creating cert: %v", err)
- }
- fmt.Printf("%s\n", rootCertPEM)
- fmt.Printf("%#x\n", rootCert.Signature) // more ugly binary
- f, err = os.Create(dirPath + "/certificate.pem")
- defer f.Close()
- _, err = f.Write(rootCertPEM)
- if err != nil {
- log.Println(errs.Stack(err))
- }
- } else {
- log.Println("Found certificate.pem! Loading into Mumble client...")
- }
- cert, err := tls.LoadX509KeyPair(dirPath + "/certificate.pem", dirPath + "/private.key")
- if err != nil {
- fmt.Fprintf(os.Stderr, "%s\n", err)
- os.Exit(1)
- }
- s.TLSConfig.Certificates = append(s.TLSConfig.Certificates, cert)
- go s.start()
- return s
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement