Ejemplo n.º 1
0
Archivo: server.go Proyecto: CPSSD/MDFS
func getPerm(filepath string) (owner uint64, groups []uint64, permissions []bool, err error) {

	var tmpPerm utils.Perm

	err = utils.FileToStruct(filepath+"/.perm", &tmpPerm)
	owner = tmpPerm.Owner
	groups = tmpPerm.Groups
	permissions = tmpPerm.Permissions

	return
}
Ejemplo n.º 2
0
Archivo: server.go Proyecto: CPSSD/MDFS
func getFile(fileout string) (hash, unid string, protected bool, owner uint64, groups []uint64, permissions []bool, err error) {

	var tmpFileDesc utils.FileDesc

	err = utils.FileToStruct(fileout, &tmpFileDesc)
	hash = tmpFileDesc.Hash
	unid = tmpFileDesc.Stnode
	protected = tmpFileDesc.Protected
	owner = tmpFileDesc.Owner
	groups = tmpFileDesc.Groups
	permissions = tmpFileDesc.Permissions

	return
}
Ejemplo n.º 3
0
func setup(r *bufio.Reader, w *bufio.Writer, thisUser *utils.User) (err error) {

	fmt.Println("Please enter your username:\n")
	fmt.Print("Username: "******"/.mdfs/client/" + uname + "/.user_data")
	if exists != nil { // not exist

		// Make sure the local user dir exists
		err := os.MkdirAll(utils.GetUserHome()+"/.mdfs/client/"+uname+"/files", 0777)
		if err != nil {
			return err
		}

		// notify mdservice that this is a new user (SENDCODE 10)
		err = w.WriteByte(10) //
		if err != nil {
			return err
		}
		w.Flush()

		// local user setup
		utils.GenUserKeys(utils.GetUserHome() + "/.mdfs/client/" + uname + "/.private_key")

		err = utils.FileToStruct(utils.GetUserHome()+"/.mdfs/client/"+uname+"/.private_key", &thisUser.Privkey)
		if err != nil {
			return err
		}
		thisUser.Pubkey = &thisUser.Privkey.PublicKey

		// send username and keys
		w.WriteString(uname + "\n")
		w.Write([]byte(thisUser.Pubkey.N.String() + "\n"))
		w.Write([]byte(strconv.Itoa(thisUser.Pubkey.E) + "\n"))
		w.Flush()

		uuid, _ := r.ReadString('\n')
		thisUser.Uuid, err = strconv.ParseUint(strings.TrimSpace(uuid), 10, 64)
		if err != nil {
			return err
		}

		err = utils.StructToFile(*thisUser, utils.GetUserHome()+"/.mdfs/client/"+uname+"/.user_data")
		if err != nil {
			return err
		}

		//NOTE: NOT COMPLETE

	} else {

		err = utils.FileToStruct(utils.GetUserHome()+"/.mdfs/client/"+uname+"/.user_data", &thisUser)
		w.WriteByte(9)
		w.Flush()

	}

	return err

	// if none exist, will send a code to mdserv to notify as new user,
	// and get a uuid, create userkeys, send pubkey to mdserv

}
Ejemplo n.º 4
0
func CheckCrypto() (success bool, err error) {

	usrHome := utils.GetUserHome()

	path := "/.testing_files/"

	keys := usrHome + path + ".private_key_mdfs"
	source1 := usrHome + path + "test.txt"
	encryp1 := usrHome + path + "test.enc"
	result1 := usrHome + path + "result.txt"

	source2 := usrHome + path + "test.jpg"
	encryp2 := usrHome + path + "test.jpg.enc"
	result2 := usrHome + path + "result.jpg"

	utils.GenUserKeys(keys)

	var prk *rsa.PrivateKey
	var puk *rsa.PublicKey

	err = utils.FileToStruct(keys, &prk)
	if err != nil {
		return false, err
	}
	puk = &prk.PublicKey

	user1 := utils.User{Uuid: 1, Pubkey: puk, Privkey: prk}
	user2 := utils.User{Uuid: 2, Pubkey: puk, Privkey: prk}

	//test two files for encryption and then decryption

	// Test 1st file
	users := []utils.User{user1, user2}

	err = utils.EncryptFile(source1, encryp1, users...)
	if err != nil {
		return false, err
	}
	err = utils.DecryptFile(encryp1, result1, user1)
	if err != nil {
		return false, err
	}
	err = utils.DecryptFile(encryp1, result1, user2)
	if err != nil {
		return false, err
	}

	test1 := compareFiles(source1, result1)

	// Test 2nd file
	err = utils.EncryptFile(source2, encryp2, user1)
	if err != nil {
		return false, err
	}
	err = utils.DecryptFile(encryp2, result2, user1)
	if err != nil {
		return false, err
	}

	test2 := compareFiles(source2, result2)

	return test1 && test2, err
}