Exemple #1
0
func NewUnsignedBList(title string) (
	sList *UnsignedBList, err error) {

	bList, err := xc.NewBuildList(title, 0)
	if err == nil {
		sList = &UnsignedBList{BuildList: *bList}
	}
	return
}
Exemple #2
0
// Read the header part of a signed list that has been serialized in disk
// format, returning a pointer to the deserialized object or an error.
// Subclasses should call this to get a pointer to the BuildList part
// of the subclass struct.  If the subclass is an XXXList, then expect
// the calling routine to be ParseXXXList()
//
func ParseUnsignedBList(in io.Reader) (uList *UnsignedBList, err error) {

	var (
		line  []byte
		title string
		t     xu.Timestamp // binary form
	)
	bin := bufio.NewReader(in)

	// Read the header part -----------------------------------------
	line, err = xc.NextLineWithoutCRLF(bin)
	if err == nil {
		title = string(line)
		line, err = xc.NextLineWithoutCRLF(bin)
		if err == nil {
			t, err = xu.ParseTimestamp(string(line))
			if err == nil {
				line, err = xc.NextLineWithoutCRLF(bin)
				if err == nil {
					if !bytes.Equal(line, xc.CONTENT_START) {
						err = xc.MissingContentStart
					}
				}
			}
		}
	}

	// Build and populate the SignedBList object ---------------------
	if err == nil {
		var bList *xc.BuildList
		bList, err = xc.NewBuildList(title, t)
		if err == nil {
			uList = &UnsignedBList{
				BuildList: *bList,
			}
			// Read the content lines and then any docHash line ------
			err = ReadContents(bin, uList, false) // true = is signed
			if err == nil {
				// try to read any docHash line
				var docHash []byte
				line, err = xc.NextLineWithoutCRLF(bin)
				if (err == nil || err == io.EOF) && (len(line) > 0) {
					docHash, err = base64.StdEncoding.DecodeString(string(line))
					if err == nil || err == io.EOF {
						uList.setDocHash(docHash)
						if err == io.EOF {
							err = nil
						}
					}
				}
			}

		}
	}
	return
}
Exemple #3
0
func NewSignedBList(title string, pubkey *rsa.PublicKey) (
	sList *SignedBList, err error) {

	if pubkey == nil {
		err = NilPublicKey
	} else if title == "" {
		err = NilTitle
	} else {
		// timestamp is set when it gets signed
		bList, err := xc.NewBuildList(title, 0)
		if err == nil {
			sList = &SignedBList{
				PubKey:    pubkey,
				BuildList: *bList,
			}
		}
	}
	return
}
Exemple #4
0
// Read the header part of a signed list that has been serialized in disk
// format, returning a pointer to the deserialized object or an error.
// Subclasses should call this to get a pointer to the BuildList part
// of the subclass struct.  If the subclass is an XXXList, then expect
// the calling routine to be ParseXXXList()
//
func ParseSignedBList(in io.Reader) (sList *SignedBList, err error) {

	var (
		line   []byte
		pubKey *rsa.PublicKey
		title  string
		t      xu.Timestamp // binary form
	)
	bin := bufio.NewReader(in)

	// Read the header part -----------------------------------------
	line, err = xc.NextLineWithoutCRLF(bin)
	if err == nil {
		title = string(line)
		line, err = xc.NextLineWithoutCRLF(bin)
		if err == nil {
			t, err = xu.ParseTimestamp(string(line))
			if err == nil {
				line, err = xc.NextLineWithoutCRLF(bin)
				if err == nil {
					line = append(line, 10) // NEWLINE
					pubKey, err = xc.RSAPubKeyFromDisk(line)
					if err == nil {
						line, err = xc.NextLineWithoutCRLF(bin)
						if err == nil {
							if !bytes.Equal(line, xc.CONTENT_START) {
								err = xc.MissingContentStart
							}
						}
					}
				}
			}
		}
	}

	// Build and populate the SignedBList object ---------------------
	if err == nil {
		var bList *xc.BuildList
		bList, err = xc.NewBuildList(title, t)
		if err == nil {
			sList = &SignedBList{
				PubKey:    pubKey,
				BuildList: *bList,
			}
			// Read the content lines and then the dig sig ----------
			err = ReadContents(bin, sList, true) // true = is signed
			if err == nil {
				// try to read the digital signature line
				var digSig []byte
				line, err = xc.NextLineWithoutCRLF(bin)
				if err == nil || err == io.EOF {
					digSig, err = base64.StdEncoding.DecodeString(string(line))
					if err == nil || err == io.EOF {
						sList.SetDigSig(digSig)
						if err == io.EOF {
							err = nil
						}
					}
				}
			}

		}
	}
	return
}