示例#1
0
// Store all the data of all the entities in the list including their properties in the secure storage
func (el *EntityManager) StoreInfo(filePath string, secret []byte) error {
	lock.Lock()
	defer lock.Unlock()

	prefix := ""
	storage, err := ss.NewStorage(secret)
	if err != nil {
		logger.Error.Printf("Fatal error: can't create storage, error: %v", err)
		return fmt.Errorf("Fatal error: can't create storage, error: %v", err)
	}
	for name, e := range el.Users {
		err := addUserResourceToStorage(userTypeStr, name, e.Entity, prefix, storage)
		if err != nil {
			return err
		}
	}
	for name, e := range el.Groups {
		err := addGroupToStorage(groupTypeStr, name, e, prefix, storage)
		if err != nil {
			return err
		}
	}
	for name, e := range el.Resources {
		err := addUserResourceToStorage(resourceTypeStr, name, e.Entity, prefix, storage)
		if err != nil {
			return err
		}
	}
	logger.Info.Println("Store Security Tool data to file:", filePath)
	return storage.StoreInfo(filePath)
}
func (s *ssRestful) restCreateSecureStorage(request *restful.Request, response *restful.Response) {
	secret := request.HeaderParameter(secretIdParam)
	data, err := ss.NewStorage([]byte(secret))
	if err != nil {
		s.setError(response, http.StatusBadRequest, err)
		return
	}
	s.st.SecureStorage = data
	response.WriteHeader(http.StatusCreated)
	response.WriteEntity(s.getUrlPath(request))
}
func generateSecureStorage() (*ss.SecureStorage, []byte) {
	var secret []byte

	secret = make([]byte, aesSecretLen)
	io.ReadFull(rand.Reader, secret)
	storage, _ := ss.NewStorage(secret)
	for i := 0; i < 10; i++ {
		keyText := fmt.Sprintf(keyFmt, i)
		dataText := fmt.Sprintf(dataFmt, i*10+1)
		storage.AddItem(keyText, dataText)
	}
	return storage, secret
}
func init() {
	logger.Init(ioutil.Discard, ioutil.Discard, ioutil.Discard, ioutil.Discard)

	ServicePath = cr.ServicePathPrefix + cr.Version + SsPrefix
	resourcePath = listener + ServicePath + StoragePath
	itemPath = listener + ServicePath + StorageItemPath

	baseHeaderInfo[secretIdParam] = secretCode

	usersList := en.NewEntityManager()
	stRestful = libsecurity_restful.NewLibsecurityRestful()
	secureStorage, _ := ss.NewStorage([]byte(secretCode))
	stRestful.SetData(usersList, nil, nil, nil, secureStorage)
	stRestful.SetToFilterFlag(false)

	go runServer()
	time.Sleep(100 * time.Millisecond)
}