コード例 #1
0
ファイル: main.go プロジェクト: pennello/go_steg
func init() {
	atomSizeUsage := "atom size (1, 2, or 3)"
	atomSize := flag.Uint("atomsize", 1, atomSizeUsage)

	carrierUsage := "path to message carrier"
	carrier := flag.String("carrier", "", carrierUsage)

	inputUsage := "path to input; can be - for standard in"
	input := flag.String("input", "-", inputUsage)

	boxUsage := "use size-checking encapsulation format"
	box := flag.Bool("box", false, boxUsage)

	offsetUsage := "read/write offset"
	offset := flag.Int64("offset", 0, offsetUsage)

	flag.Parse()

	if *atomSize < 1 || *atomSize > 3 {
		log.Fatalf("atom size must be 1, 2, or 3")
	}

	if *offset < 0 {
		log.Fatalf("offset must be positive")
	}

	state = new(cmd.State)
	state.Ctx = steg.NewCtx(uint8(*atomSize))
	state.Carrier, state.CarrierSize = getCarrier(*carrier)
	state.Input, state.InputSize = getInput(*input)
	state.Box = *box
	state.Offset = *offset
}
コード例 #2
0
ファイル: parse.go プロジェクト: pennello/go_steg
func parseForm(req *http.Request) (s *cmd.State, err error) {
	contenttype, ok := req.Header["Content-Type"]
	if !ok {
		return nil, errors.New("content-type required")
	}
	mediatype, params, err := mime.ParseMediaType(contenttype[0])
	if err != nil {
		return nil, err
	}
	if mediatype != "multipart/form-data" {
		return nil, errors.New("multipart/form-data required")
	}
	boundary, ok := params["boundary"]
	if !ok {
		return nil, errors.New("form boundary required")
	}

	// XXX This can behave poorly if the input is weird.  For
	// example, if the input provides two parts with carrier files,
	// one will be orphaned and never closed.

	mpr := multipart.NewReader(req.Body, boundary)
	s = new(cmd.State)

	var atomSize uint8
	var carrier *url.URL
	var carrierReader io.ReadCloser
	var input *url.URL
	var inputReader io.ReadCloser

	for {
		part, err := mpr.NextPart()
		if err != nil {
			if err == io.EOF {
				break
			}
			return nil, err
		}

		switch part.FormName() {

		// This includes the empty string, returned when there
		// is no form name present.
		default:
			continue

		case "atom-size":
			{
				atomSizeBytes, err := ioutil.ReadAll(part)
				if err != nil {
					return nil, err
				}
				// No default handling--form should provide the
				// default of 1.
				atomSize, err = parseAtomSize(string(atomSizeBytes))
				if err != nil {
					return nil, err
				}
			}

		case "carrier":
			{
				carrier, carrierReader, err = parsePart(part)
				if err != nil {
					return nil, err
				}
			}

		case "input":
			{
				input, inputReader, err = parsePart(part)
				if err != nil {
					return nil, err
				}
			}

		case "box":
			{
				boxBytes, err := ioutil.ReadAll(part)
				if err != nil {
					return nil, err
				}
				boxStr := string(boxBytes)
				if boxStr == "on" {
					boxStr = "1"
				}
				box, err := parseBox(boxStr)
				if err != nil {
					return nil, err
				}
				s.Box = box
			}

		case "offset":
			{
				offsetBytes, err := ioutil.ReadAll(part)
				if err != nil {
					return nil, err
				}
				offset, err := parseOffset(string(offsetBytes))
				if err != nil {
					return nil, err
				}
				s.Offset = offset
			}
		}
	}

	if atomSize == 0 {
		return nil, errors.New("atom-size required")
	}
	s.Ctx = steg.NewCtx(atomSize)

	if carrierReader != nil {
		s.Carrier, s.CarrierSize = carrierReader, -1
	} else if carrier != nil {
		s.Carrier, s.CarrierSize, err = getURL(carrier)
		if err != nil {
			return nil, err
		}
	} else {
		// No carrier, no problem--we just won't do any muxing.
	}

	if inputReader != nil {
		s.Input, s.InputSize = inputReader, -1
	} else if input != nil {
		s.Input, s.InputSize, err = getURL(input)
		if err != nil {
			err2 := s.Carrier.Close()
			if err2 != nil {
				log.Print(err2)
			}
			return nil, err
		}
	} else {
		return nil, errors.New("input required")
	}

	return s, nil
}
コード例 #3
0
ファイル: parse.go プロジェクト: pennello/go_steg
func parseApi(req *http.Request) (s *cmd.State, err error) {
	atomSizeStr := getHeader(req, "Atom-Size")
	if atomSizeStr == "" {
		atomSizeStr = "1"
	}
	atomSize, err := parseAtomSize(atomSizeStr)
	if err != nil {
		return nil, err
	}

	var carrier *url.URL
	carrierStr := getHeader(req, "Carrier")
	if carrierStr == "" {
		// No muxing.
		carrier = nil
	} else {
		carrier, err = parseURL(carrierStr)
		if err != nil {
			return nil, err
		}
	}

	var input *url.URL
	inputStr := getHeader(req, "Input")
	if inputStr == "" {
		// We'll just use the request body.
		input = nil
	} else {
		input, err = parseURL(inputStr)
		if err != nil {
			return nil, err
		}
	}

	boxStr := getHeader(req, "Box")
	if boxStr == "" {
		boxStr = "false"
	}
	box, err := parseBox(boxStr)
	if err != nil {
		return nil, err
	}

	offsetStr := getHeader(req, "Offset")
	if offsetStr == "" {
		offsetStr = "0"
	}
	offset, err := parseOffset(offsetStr)
	if err != nil {
		return nil, err
	}

	s = new(cmd.State)
	s.Ctx = steg.NewCtx(atomSize)
	s.Carrier, s.CarrierSize, err = getCarrier(carrier)
	if err != nil {
		return nil, err
	}
	s.Input, s.InputSize, err = getInput(req, input)
	if err != nil {
		err2 := s.Carrier.Close()
		if err2 != nil {
			log.Print(err2)
		}
		return nil, err
	}
	s.Box = box
	s.Offset = offset

	return s, nil
}