예제 #1
0
func main() {
	runtime.LockOSThread()
	if srpc.Enabled() {
		go srpc.ServeRuntime()
	}

	w, err := av.Init(av.SubsystemVideo, 512, 512)
	if err != nil {
		log.Exitf("av.Init: %s", err)
	}

	go quitter(w.QuitChan())

	var m SpacewarPDP1
	m.Init(w)
	m.PC = 4
	f := bytes.NewBuffer(strings.Bytes(spacewarCode))
	if err = m.Load(f); err != nil {
		log.Exitf("loading %s: %s", "spacewar.lst", err)
	}
	for err == nil {
		//fmt.Printf("step PC=%06o ", m.PC);
		//fmt.Printf("inst=%06o AC=%06o IO=%06o OV=%o\n",
		//	m.Mem[m.PC], m.AC, m.IO, m.OV);
		err = m.Step()
	}
	log.Exitf("step: %s", err)
}
예제 #2
0
파일: camput.go 프로젝트: marsch/camlistore
func main() {
	flag.Parse()

	if sumSet(flagFile, flagBlob, flagPermanode, flagInit, flagShare) != 1 {
		// TODO: say which ones are conflicting
		usage("Conflicting mode options.")
	}

	client := client.NewOrFail()
	if !*flagVerbose {
		client.SetLogger(nil)
	}
	uploader := &Uploader{client}

	switch {
	case *flagInit:
		doInit()
		return
	case *flagPermanode:
		if flag.NArg() > 0 {
			log.Exitf("--permanode doesn't take any additional arguments")
		}
		pr, err := uploader.UploadNewPermanode()
		handleResult("permanode", pr, err)
	case *flagFile || *flagBlob:
		for n := 0; n < flag.NArg(); n++ {
			if *flagBlob {
				pr, err := uploader.UploadFileBlob(flag.Arg(n))
				handleResult("blob", pr, err)
			} else {
				pr, err := uploader.UploadFile(flag.Arg(n))
				handleResult("file", pr, err)
			}
		}
	case *flagShare:
		if flag.NArg() != 1 {
			log.Exitf("--share only supports one blobref")
		}
		br := blobref.Parse(flag.Arg(0))
		if br == nil {
			log.Exitf("BlobRef is invalid: %q", flag.Arg(0))
		}
		pr, err := uploader.UploadShare(br, *flagTransitive)
		handleResult("share", pr, err)
	}

	if *flagVerbose {
		stats := uploader.Stats()
		log.Printf("Client stats: %s", stats.String())
	}
	if wereErrors {
		os.Exit(2)
	}
}
예제 #3
0
func main() {
	flag.Parse()

	urandom, err := os.Open("/dev/urandom", os.O_RDONLY, 0)
	if err != nil {
		log.Exitf("failed to open /dev/urandom: %s", err)
		return
	}

	priv, err := rsa.GenerateKey(urandom, 1024)
	if err != nil {
		log.Exitf("failed to generate private key: %s", err)
		return
	}

	now := time.Seconds()

	template := x509.Certificate{
		SerialNumber: []byte{0},
		Subject: x509.Name{
			CommonName:   *hostName,
			Organization: "Acme Co",
		},
		NotBefore: time.SecondsToUTC(now - 300),
		NotAfter:  time.SecondsToUTC(now + 60*60*24*365), // valid for 1 year.

		SubjectKeyId: []byte{1, 2, 3, 4},
		KeyUsage:     x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
	}

	derBytes, err := x509.CreateCertificate(urandom, &template, &template, &priv.PublicKey, priv)
	if err != nil {
		log.Exitf("Failed to create certificate: %s", err)
		return
	}

	certOut, err := os.Open("cert.pem", os.O_WRONLY|os.O_CREAT, 0644)
	if err != nil {
		log.Exitf("failed to open cert.pem for writing: %s", err)
		return
	}
	pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
	certOut.Close()
	log.Print("written cert.pem\n")

	keyOut, err := os.Open("key.pem", os.O_WRONLY|os.O_CREAT, 0600)
	if err != nil {
		log.Print("failed to open key.pem for writing:", err)
		return
	}
	pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)})
	keyOut.Close()
	log.Print("written key.pem\n")
}
예제 #4
0
파일: helpers.go 프로젝트: nono/Goldorak.Go
func StaticUrl(filename string) string {
	file, err := os.Open(GetConfig("docroot") + "/" + filename, os.O_RDONLY, 0444)
	if err != nil {
		log.Exitf("Impossible to open %s", filename, err)
	}
	dir, err := file.Stat()
	if err != nil {
		log.Exitf("Impossible to stat %s", filename, err)
	}
	secs := dir.Mtime_ns / 1e9
	return fmt.Sprintf("/%s?%d", filename, secs)
}
예제 #5
0
파일: camweb.go 프로젝트: marsch/camlistore
func readTemplate(name string) *template.Template {
	fileName := path.Join(*root, "tmpl", name)
	data, err := ioutil.ReadFile(fileName)
	if err != nil {
		log.Exitf("ReadFile %s: %v", fileName, err)
	}
	t, err := template.Parse(string(data), fmap)
	if err != nil {
		log.Exitf("%s: %v", fileName, err)
	}
	return t
}
예제 #6
0
func readTemplate(name string) *template.Template {
	path := pathutil.Join(*tmplroot, name)
	data, err := ioutil.ReadFile(path)
	if err != nil {
		log.Exitf("ReadFile %s: %v", path, err)
	}
	t, err := template.Parse(string(data), fmap)
	if err != nil {
		log.Exitf("%s: %v", name, err)
	}
	return t
}
예제 #7
0
파일: config.go 프로젝트: stefanha/bouncin
func WriteConfig(config *Config) {
	buf := &bytes.Buffer{}
	err := json.Marshal(buf, *config)
	if err != nil {
		log.Exitf("Failed to marshal config file: %s\n", err)
	}

	// TODO atomic update without truncating file
	err = io.WriteFile(configFilename, buf.Bytes(), configPerms)
	if err != nil {
		log.Exitf("Can't write config file: %s\n", err)
	}
}
예제 #8
0
파일: camget.go 프로젝트: marsch/camlistore
func main() {
	flag.Parse()

	client := client.NewOrFail()
	if *flagCheck {
		// Simply do HEAD requests checking if the blobs exists.
		return
	}

	var w io.Writer = os.Stdout

	for n := 0; n < flag.NArg(); n++ {
		arg := flag.Arg(n)
		br := blobref.Parse(arg)
		if br == nil {
			log.Exitf("Failed to parse argument \"%s\" as a blobref.", arg)
		}
		if *flagVerbose {
			log.Printf("Need to fetch %s", br.String())
		}
		var (
			r   blobref.ReadSeekCloser
			err os.Error
		)

		if len(*flagVia) > 0 {
			vs := strings.Split(*flagVia, ",", -1)
			abr := make([]*blobref.BlobRef, len(vs))
			for i, sbr := range vs {
				abr[i] = blobref.Parse(sbr)
				if abr[i] == nil {
					log.Exitf("Invalid -via blobref: %q", sbr)
				}
				if *flagVerbose {
					log.Printf("via: %s", sbr)
				}
			}
			r, _, err = client.FetchVia(br, abr)
		} else {
			r, _, err = client.Fetch(br)
		}
		if err != nil {
			log.Exitf("Failed to fetch %q: %s", br, err)
		}
		_, err = io.Copy(w, r)
		if err != nil {
			log.Exitf("Failed transferring %q: %s", br, err)
		}
	}

}
예제 #9
0
파일: config.go 프로젝트: nono/Goldorak.Go
func ReadConfig(filename string) {
	contents, err := ioutil.ReadFile(filename)
	if err != nil {
		log.Exitf("Impossible to read %s", filename, err)
	}
	data, err := json.Decode(string(contents))
	if err != nil {
		log.Exitf("Can't parse %s as JSON", filename, err)
	}
	config = map[string]string{}
	for key, value := range data.(map[string]interface{}) {
		config[key] = value.(string)
	}
}
예제 #10
0
func main() {
	nlmsg, err := netlink.NewMessage(rtnetlink.RTM_GETADDR, netlink.NLM_F_DUMP|netlink.NLM_F_REQUEST, &addr.Header{}, 4)
	if err != nil {
		log.Exitf("Couldn't construct message: %v", err)
	}
	log.Printf("Dialing: %v", nlmsg)
	nlsock, err := netlink.Dial(netlink.NETLINK_ROUTE)
	if err != nil {
		log.Exitf("Couldn't dial netlink: %v", err)
	}
	h := netlink.NewHandler(nlsock)
	ec := make(chan os.Error)
	go logec(ec)
	go h.Start(ec)
	log.Printf("Sending query: %v", nlmsg)
	c, err := h.Query(*nlmsg, 1, 4)
	log.Printf("Sent query: %v", nlmsg.Header)
	if err != nil {
		log.Exitf("Couldn't write netlink: %v", err)
	}
	for i := range c {
		if i.Header.MessageType() == netlink.NLMSG_DONE {
			break
		}
		switch i.Header.MessageType() {
		case rtnetlink.RTM_NEWADDR:
			hdr := &addr.Header{}
			msg := rtnetlink.NewMessage(hdr, nil)
			err = msg.UnmarshalNetlink(i.Body, 4)
			if err == nil {
				log.Printf("Family: %v; Length: %d; Flags: %v; Scope: %v; IFIndex: %d",
					hdr.AddressFamily(), hdr.PrefixLength(), hdr.Flags(), hdr.Scope(),
					hdr.InterfaceIndex())

				for i := range msg.Attributes {
					log.Printf("Attribute[%d] = %v", i, msg.Attributes[i])
				}
			} else {
				log.Printf("Unmarshal error: %v", err)
			}
		default:
			log.Printf("Unknown type: %v", i)
		}
		if err != nil {
			log.Printf("Handler error: %v", err)
		}
	}
}
예제 #11
0
func main() {
	var address, key string
	var count, delay, step int
	flag.StringVar(&address, "address", "127.0.0.1:6311", "Set the port (+optional address) to send packets to")
	flag.StringVar(&key, "key", "profile", "Set the key name (pakets data will be \"key:idx\")")
	flag.IntVar(&count, "count", 1000, "Set the number of packets to send")
	flag.IntVar(&delay, "delay", 1000000, "Set the delay between packets in nanoseconds (10^-9)")
	flag.IntVar(&step, "step", 100, "Log step (how many packets to send between logging)")
	flag.Parse()

	udp_address, error := net.ResolveUDPAddr(address)
	if error != nil {
		log.Exitf("Cannot parse \"%s\": %s", address, error)
	}

	log.Stdout(udp_address)

	ticker := time.NewTicker(int64(delay))
	defer ticker.Stop()

	for sent := 1; sent <= count; sent++ {
		<-ticker.C
		send(udp_address, key, sent)
		if sent%step == 0 {
			log.Stdoutf("Processed %d packets of %d", sent, count)
		}
	}
}
예제 #12
0
파일: call.go 프로젝트: bradfitz/goman
func (c *client) CallWithProgress(method string, data []byte, progress ProgressHandler) []byte {
	// TODO: implement

	// TODO: shard onto a c.hosts[] entry, wait for its connection state, etc.
	log.Exitf("TODO: implement CallWithProgress")
	return nil
}
예제 #13
0
파일: config.go 프로젝트: stefanha/bouncin
func ReadConfig() *Config {
	content, err := io.ReadFile(configFilename)
	if err != nil {
		log.Exitf("Can't open config file: %s\n", err)
	}
	return ParseConfig(string(content))
}
예제 #14
0
파일: camweb.go 프로젝트: marsch/camlistore
func main() {
	flag.Parse()
	readTemplates()

	if *root == "" {
		var err os.Error
		*root, err = os.Getwd()
		if err != nil {
			log.Exitf("Failed to getwd: %v", err)
		}
	}

	mux := http.DefaultServeMux
	mux.Handle("/favicon.ico", http.FileServer(path.Join(*root, "static"), "/"))
	mux.Handle("/robots.txt", http.FileServer(path.Join(*root, "static"), "/"))
	mux.Handle("/static/", http.FileServer(path.Join(*root, "static"), "/static/"))

	testCgi := &CgiHandler{ExecutablePath: path.Join(*root, "test.cgi"),
		Root: "/test.cgi",
	}
	mux.Handle("/test.cgi", testCgi)
	mux.Handle("/test.cgi/foo", testCgi)

	mux.Handle("/code", http.RedirectHandler("/code/", http.StatusFound))
	if *gitwebScript != "" {
		env := os.Environ()
		env = append(env, "GITWEB_CONFIG="+path.Join(*root, "gitweb-camli.conf"))
		env = append(env, "CAMWEB_ROOT="+path.Join(*root))
		mux.Handle("/code/", &gitwebHandler{
			Cgi: &CgiHandler{
				ExecutablePath: *gitwebScript,
				Root:           "/code/",
				Environ:        env,
			},
			Static: http.FileServer(*gitwebFiles, "/code/"),
		})
	}
	mux.HandleFunc("/", mainHandler)

	var handler http.Handler = &noWwwHandler{Handler: mux}
	if *logDir != "" || *logStdout {
		handler = NewLoggingHandler(handler, *logDir, *logStdout)
	}
	if err := http.ListenAndServe(*httpAddr, handler); err != nil {
		log.Exitf("ListenAndServe %s: %v", *httpAddr, err)
	}
}
예제 #15
0
파일: config.go 프로젝트: stefanha/bouncin
func ParseConfig(config string) *Config {
	var c = &Config{}
	ok, errtok := json.Unmarshal(config, c)
	if !ok {
		log.Exitf("Config syntax error: %s\n", errtok)
	}
	return c
}
예제 #16
0
func main() {
	flag.Parse()
	ls, e := net.Listen("tcp", fmt.Sprintf(":%d", *port))
	if e != nil {
		log.Exitf("Got an error:  %s", e)
	}

	waitForConnections(ls)
}
예제 #17
0
파일: simple.go 프로젝트: kpumuk/gorrd
func main() {
	err := rrd.Create("test.rrd", 10, time.Seconds()-10, []string{
		"DS:ok:GAUGE:600:0:U",
		"RRA:AVERAGE:0.5:1:25920",
	})
	if err != nil {
		log.Exitf("Error: %s", err)
	}

	err = rrd.Update("test.rrd", "ok", []string{
		fmt.Sprintf("%d:%d", time.Seconds(), 15),
	})
	if err != nil {
		log.Exitf("Error: %s", err)
	}

	log.Stdout("Everything is OK")
}
예제 #18
0
func startServer(done chan<- string) {
	c, e := net.ListenPacket("udp", ":0")
	if e != nil {
		log.Exitf("net.ListenPacket failed udp :0 %v", e)
	}
	serverAddr = c.LocalAddr().String()
	c.SetReadTimeout(10e6) // 10ms
	go runSyslog(c, done)
}
예제 #19
0
func startServer() {
	l, e := net.Listen("tcp", ":0") // any available address
	if e != nil {
		log.Exitf("net.Listen tcp :0 %v", e)
	}
	serverAddr = l.Addr().String()
	log.Stderr("Test WebSocket server listening on ", serverAddr)
	http.Handle("/echo", Handler(echoServer))
	go http.Serve(l, nil)
}
예제 #20
0
func main() {
	rtmsg := route.NewHeader(0, 0, 0, 0, 0, 0, 0, 0, 0)
	nlmsg, err := netlink.NewMessage(rtnetlink.RTM_GETROUTE, netlink.NLM_F_DUMP|netlink.NLM_F_REQUEST, rtmsg, 2)
	if err != nil {
		log.Exitf("Couldn't construct message: %v", err)
	}
	nlsock, err := netlink.Dial(netlink.NETLINK_ROUTE)
	if err != nil {
		log.Exitf("Couldn't dial netlink: %v", err)
	}
	h := netlink.NewHandler(nlsock)
	ec := make(chan os.Error)
	go h.Start(ec)
	c, err := h.Query(*nlmsg, 1, 4)
	if err != nil {
		log.Exitf("Couldn't write netlink: %v", err)
	}
	for i := range c {
		if i.Header.MessageType() == netlink.NLMSG_DONE {
			break
		}
		switch i.Header.MessageType() {
		case rtnetlink.RTM_NEWROUTE:
			hdr := &route.Header{}
			msg := rtnetlink.NewMessage(hdr, nil)
			err = msg.UnmarshalNetlink(i.Body, 4)

			if err == nil {
				log.Printf("Route: %v (%d/%d) TOS: %d; (Table: %v; Origin: %v; Scope: %v; Type: %v; Flags: %v",
					hdr.AddressFamily(), hdr.AddressDestLength(), hdr.AddressSourceLength(),
					hdr.TOS(), hdr.RoutingTable(), hdr.RouteOrigin(), hdr.AddressScope(),
					hdr.RouteType(), hdr.Flags())
				for i := range msg.Attributes {
					log.Printf("Attribute[%d]: %v", i, msg.Attributes[i])
				}
			} else {
				log.Printf("Unmarshal error: %v", err)
			}
		default:
			log.Printf("Unknown type: %v", i)
		}
	}
}
예제 #21
0
func addError(msg string) {
	errorMutex.Lock()
	defer errorMutex.Unlock()
	errors = append(errors, msg)
	if *flagSloppy {
		log.Printf("ERROR: %s", msg)
	} else {
		log.Exitf("ERROR: %s", msg)
	}
}
예제 #22
0
파일: av.go 프로젝트: rapgamer/golang-china
// If using SRPC, the runtime will call this method to pass in two file descriptors,
// one to mmap to get the display memory, and another to use for SRPCs back
// to the main process.
func (multimediaBridge) Run(arg, ret []interface{}, size []int) srpc.Errno {
	bridge.displayFd = arg[0].(int)
	bridge.rpcFd = arg[1].(int)

	var st syscall.Stat_t
	if errno := syscall.Fstat(bridge.displayFd, &st); errno != 0 {
		log.Exitf("mmbridge stat display: %s", os.Errno(errno))
	}

	addr, _, errno := syscall.Syscall6(syscall.SYS_MMAP,
		0,
		uintptr(st.Size),
		syscall.PROT_READ|syscall.PROT_WRITE,
		syscall.MAP_SHARED,
		uintptr(bridge.displayFd),
		0)
	if errno != 0 {
		log.Exitf("mmap display: %s", os.Errno(errno))
	}

	bridge.share = (*videoShare)(unsafe.Pointer(addr))

	// Overestimate frame buffer size
	// (must use a compile-time constant)
	// and then reslice.  256 megapixels (1 GB) should be enough.
	fb := (*[256 * 1024 * 1024]Color)(unsafe.Pointer(addr + videoShareSize))
	bridge.pixel = fb[0 : (st.Size-videoShareSize)/4]

	// Configure RPC connection back to client.
	var err os.Error
	bridge.client, err = srpc.NewClient(bridge.rpcFd)
	if err != nil {
		log.Exitf("NewClient: %s", err)
	}
	bridge.flushRPC = bridge.client.NewRPC(nil)

	// Notify waiters that the bridge is ready.
	println("bridged", bridge.share.revision)
	bridge.c <- true

	return srpc.OK
}
예제 #23
0
func main() {
	flag.Parse()

	if *flagDest == "" {
		log.Exitf("No --dest given.")
	}
	if *flagBase == "" {
		log.Exitf("No --base URL given.")
	}

	networkOpGate = make(chan bool, *flagMaxNetwork)

	log.Printf("Starting.")

	if *flagProfile != "" {
		log.Printf("Listening on http://%s", *flagProfile)
		go http.ListenAndServe(*flagProfile, nil)
	}

	page := 1
	for {
		countBefore := knownGalleries()
		fetchGalleryPage(page)
		countAfter := knownGalleries()
		log.Printf("Galleries known: %d", countAfter)
		if countAfter == countBefore {
			log.Printf("No new galleries, stopping.")
			break
		}
		page++
	}

	for {
		n := OperationsInFlight()
		if n == 0 {
			break
		}
		log.Printf("%d Operations in-flight.  Waiting.", n)
		time.Sleep(5 * 1e9)
	}
	log.Printf("Done.")
}
예제 #24
0
func readOpenPGPPacketFromArmoredFileOrDie(fileName string, armorType string) (p packet.Packet) {
	data, err := ioutil.ReadFile(fileName)
	if err != nil {
		log.Exit("Cannot open '%s': %s", fileName, err)
	}

	block, _ := armor.Decode(data)
	if block == nil {
		log.Exit("cannot parse armor")
	}
	if block.Type != armorType {
		log.Exitf("bad type in '%s' (got: %s, want: %s)", fileName, block.Type, armorType)
	}
	buf := bytes.NewBuffer(block.Bytes)
	p, err = packet.ReadPacket(buf)
	if err != nil {
		log.Exitf("failed to parse packet from '%s': %s", fileName, err)
	}
	return
}
예제 #25
0
func pipeFromEnvFd(env string) *os.File {
	fdStr := os.Getenv(env)
	if fdStr == "" {
		return nil
	}
	fd, err := strconv.Atoi(fdStr)
	if err != nil {
		log.Exitf("Bogus test harness fd '%s': %v", fdStr, err)
	}
	return os.NewFile(fd, "testingpipe-"+env)
}
예제 #26
0
func main() {
	nlmsg, err := netlink.NewMessage(rtnetlink.RTM_GETLINK, netlink.NLM_F_DUMP|netlink.NLM_F_REQUEST, &link.Header{}, 4)
	if err != nil {
		log.Exitf("Couldn't construct message: %v", err)
	}
	nlsock, err := netlink.Dial(netlink.NETLINK_ROUTE)
	if err != nil {
		log.Exitf("Couldn't dial netlink: %v", err)
	}
	h := netlink.NewHandler(nlsock)
	ec := make(chan os.Error)
	go h.Start(ec)
	c, err := h.Query(*nlmsg, 1, 4)
	if err != nil {
		log.Exitf("Couldn't write netlink: %v", err)
	}
	for i := range c {
		if i.Header.MessageType() == netlink.NLMSG_DONE {
			break
		}
		switch i.Header.MessageType() {
		case rtnetlink.RTM_NEWLINK:
			hdr := &link.Header{}
			msg := rtnetlink.NewMessage(hdr, nil)
			err = msg.UnmarshalNetlink(i.Body, 4)
			if err == nil {
				log.Printf("Link[%d] (Family: %v; Type: %v; Flags: %v; Changes: %v)",
					hdr.InterfaceIndex(),
					hdr.InterfaceFamily(), hdr.InterfaceType(), hdr.Flags(),
					hdr.InterfaceChanges())
				for i := range msg.Attributes {
					log.Printf("Attribute[%d]: %v", i, msg.Attributes[i])
				}
			} else {
				log.Printf("Unmarshal error: %v", err)
			}
		default:
			log.Printf("Unknown type: %v", i)
		}
	}
}
예제 #27
0
func main() {
	flag.Parse()
	nlsock, err := netlink.Dial(netlink.NETLINK_ROUTE)
	if err != nil {
		log.Exitf("Couldn't dial netlink: %v", err)
	}
	h := netlink.NewHandler(nlsock)
	ec := make(chan os.Error)
	go func() {
		for e := range ec {
			log.Printf("Netlink error: %v", e)
		}
	}()
	go h.Start(ec)
	lf := rtmanip.NewLinkFinder(h)
	l, err := lf.GetLinkByName(*ifName)
	if err == nil {
		if *doDown {
			err = l.SetLinkState(^link.IFF_UP, link.IFF_UP)
			if err != nil {
				log.Printf("Couldn't turn down interface: %v", err)
			}
			l.Refresh()
		}
		if *doUp {
			err = l.SetLinkState(link.IFF_UP, link.IFF_UP)
			if err != nil {
				log.Printf("Couldn't turn up interface: %v", err)
			}
			l.Refresh()
		}
		log.Printf("Link Index: %d", l.LinkIndex())
		log.Printf("Link Name: %s", l.LinkName())
		log.Printf("Link Flags: %s", l.LinkFlags())
		log.Printf("Link MTU: %d", l.LinkMTU())
		log.Printf("Link (l2) Address: %x", l.LinkAddress())
		log.Printf("Link (l2) Broadcast: %x", l.LinkBroadcastAddress())
	} else {
		log.Exitf("Couldn't get link: %v", err)
	}
}
예제 #28
0
func main() {
	signedData, err := ioutil.ReadFile("signed-file")
	if err != nil {
		log.Exitf("Cannot open 'signed-file': %s", err)
	}

	p := readOpenPGPPacketFromArmoredFileOrDie("public-key", "PGP PUBLIC KEY BLOCK")
	pk, ok := p.(packet.PublicKeyPacket)
	if !ok {
		log.Exit("didn't find a public key in the public key file")
	}

	p = readOpenPGPPacketFromArmoredFileOrDie("signed-file.asc", "PGP SIGNATURE")
	sig, ok := p.(packet.SignaturePacket)
	if !ok {
		log.Exit("didn't find a signature in the signature file")
	}

	if sig.Hash != packet.HashFuncSHA1 {
		log.Exit("I only do SHA1")
	}
	if sig.SigType != packet.SigTypeBinary {
		log.Exit("I only do binary signatures")
	}

	hash := sha1.New()
	hash.Write(signedData)
	hash.Write(sig.HashSuffix)
	hashBytes := hash.Sum()

	if hashBytes[0] != sig.HashTag[0] || hashBytes[1] != sig.HashTag[1] {
		log.Exit("hash tag doesn't match")
	}

	err = rsa.VerifyPKCS1v15(&pk.PublicKey, rsa.HashSHA1, hashBytes, sig.Signature)
	if err != nil {
		log.Exitf("bad signature: %s", err)
	}

	log.Print("good signature")
}
예제 #29
0
파일: elb.go 프로젝트: tkawachi/GoAWS
func main() {
	flag.Parse()
	ep, err := elb.GetEndpoint(*region, nil)
	if err != nil {
		log.Exitf("ERROR: %v", err)
	}
	zones := strings.Split(*zonestr, ",", -1)
	listners := []elb.ELBListener{}
	if *listnersstr != "" {
		listnerstrs := strings.Split(*listnersstr, ",", -1)
		for i := range listnerstrs {
			l := elb.ELBListener{}
			_, err = fmt.Sscanf(listnerstrs[i], "%d:%d:%s", &l.LoadBalancerPort, &l.InstancePort, &l.Protocol)
			if err == nil {
				listners = append(listners, l)
			} else {
				log.Exitf("Invalid listener: %v", err)
			}
		}
	}
	ch := aws.NewConnection(ep, "tcp", "", true)
	auth, err := aws.NewIdentity("sha256", *accessKey, *secretKey)
	if err != nil {
		log.Exitf("ERROR: %v", err)
	}

	elbh := elb.NewHandler(ch, auth)
	if *doCreate {
		out, err := elbh.CreateLoadBalancer(zones, listners, *lbName)
		if err != nil {
			log.Exitf("ERROR: %v", err)
		}
		log.Printf("DNSName: %s", out)
	}
	if *doDelete {
		err := elbh.DeleteLoadBalancer(*lbName)
		if err != nil {
			log.Exitf("ERROR: %v", err)
		}
	}
}
예제 #30
0
func fetchGalleryPage(page int) {
	log.Printf("Fetching gallery page %d", page)
	res, finalUrl, err := http.Get(fmt.Sprintf("%s/?sort=alpha&page=%d",
		*flagBase, page))
	if err != nil {
		log.Exitf("Error fetching gallery page %d: %v", page, err)
	}
	log.Printf("Fetched page %d: %s", page, finalUrl)
	htmlBytes, err := ioutil.ReadAll(res.Body)
	if err != nil {
		log.Exitf("Error reading gallery page %d's HTML: %v", page, err)
	}
	res.Body.Close()

	log.Printf("read %d bytes", len(htmlBytes))

	matches := galleryPattern.FindAllSubmatch(htmlBytes, -1)
	for _, match := range matches {
		noteGallery(string(match[1]))
	}
}