// Creates a ephemeral key storage and installs it into G.
542208
func NewEphemeralStorageAndInstall(mctx libkb.MetaContext) {
	mctx.G().SetDeviceEKStorage(NewDeviceEKStorage(mctx))
	mctx.G().SetUserEKBoxStorage(NewUserEKBoxStorage())
	mctx.G().SetTeamEKBoxStorage(NewTeamEKBoxStorage())
	ekLib := NewEKLib(mctx)
	mctx.G().SetEKLib(ekLib)
	mctx.G().AddLoginHook(ekLib)
	mctx.G().AddLogoutHook(ekLib, "ekLib")
	mctx.G().AddDbNukeHook(ekLib, "ekLib")
	mctx.G().PushShutdownHook(func() error {
		mctx.Debug("stopping background eklib loop")
		ekLib.Shutdown()
		return nil
	})
}
495786
func (s *KeyManagementServer) CreateKey(ctx context.Context, req *pb.CreateKeyRequest) (*pb.PublicKey, error) {
	service := s.CryptoServices[req.Algorithm]

	logger := ctxu.GetLogger(ctx)

	if service == nil {
		logger.Error("CreateKey: unsupported algorithm: ", req.Algorithm)
		return nil, fmt.Errorf("algorithm %s not supported for create key", req.Algorithm)
	}

	var tufKey data.PublicKey
	var err error

	tufKey, err = service.Create(data.RoleName(req.Role), data.GUN(req.Gun), req.Algorithm)
	if err != nil {
		logger.Error("CreateKey: failed to create key: ", err)
		return nil, grpc.Errorf(codes.Internal, "Key creation failed")
	}
	logger.Info("CreateKey: Created KeyID ", tufKey.ID())

	return &pb.PublicKey{
		KeyInfo: &pb.KeyInfo{
			KeyID:     &pb.KeyID{ID: tufKey.ID()},
			Algorithm: &pb.Algorithm{Algorithm: tufKey.Algorithm()},
		},
		PublicKey: tufKey.Public(),
	}, nil
}
1046525
func NewKeyMemoryStore(p notary.PassRetriever) *GenericKeyStore {
	memStore := store.NewMemoryStore(nil)
	return NewGenericKeyStore(memStore, p)
}
1121058
func (k *KeyManager) InstallKey(key string) (*KeyResponse, error) {
	return k.InstallKeyWithOptions(key, nil)
}
572018
func GeneratePrivateKey() [keySize]byte {
	var b [keySize]byte
	rand.Read(b[:])

	return b
}
704754
func (c *ConfigLocal) MakeDiskMDCacheIfNotExists() error {
	c.lock.Lock()
	defer c.lock.Unlock()
	if c.diskMDCache != nil {
		return nil
	}
	return c.resetDiskMDCacheLocked()
}
1266137
func (s *storage) RootKey() ([]byte, []byte, error) {
	storage, closer := s.getStorage()
	defer closer()
	return storage.RootKey()
}
232813
func CreateGatewayCache(p *redis.Pool, gw Gateway) error {
	var buf bytes.Buffer
	if err := gob.NewEncoder(&buf).Encode(gw); err != nil {
		return errors.Wrap(err, "gob encode gateway error")
	}

	c := p.Get()
	defer c.Close()

	key := fmt.Sprintf(gatewayKeyTempl, gw.GatewayID)
	exp := int64(deviceSessionTTL) / int64(time.Millisecond)

	_, err := c.Do("PSETEX", key, exp, buf.Bytes())
	if err != nil {
		return errors.Wrap(err, "set gateway error")
	}

	return nil
}
998744
func (s *StoragePacker) BucketKeyHashByKey(bucketKey string) string {
	hf := md5.New()
	hf.Write([]byte(bucketKey))
	return hex.EncodeToString(hf.Sum(nil))
}
1292378
func NewKeyServerMemory(config KeyServerConfig, log logger.Logger) (
	*KeyServerLocal, error) {
	return newKeyServerLocal(config, log, storage.NewMemStorage(), nil)
}
622787
func (a *Agent) InstallKey(key string) (*KeyringResponse, error) {
	args := KeyringRequest{
		Key: key,
	}
	var resp KeyringResponse
	_, err := a.client.write("/v1/agent/keyring/install", &args, &resp, nil)
	return &resp, err
}
246280
func (gce *Cloud) AddSSHKeyToAllInstances(user string, keyData []byte) error {
	return wait.Poll(2*time.Second, 30*time.Second, func() (bool, error) {
		project, err := gce.service.Projects.Get(gce.projectID).Do()
		if err != nil {
			glog.Errorf("Could not get project: %v", err)
			return false, nil
		}
		keyString := fmt.Sprintf("%s:%s %s@%s", user, strings.TrimSpace(string(keyData)), user, user)
		found := false
		for _, item := range project.CommonInstanceMetadata.Items {
			if item.Key == "sshKeys" {
				if strings.Contains(*item.Value, keyString) {
					// We've already added the key
					glog.Info("SSHKey already in project metadata")
					return true, nil
				}
				value := *item.Value + "\n" + keyString
				item.Value = &value
				found = true
				break
			}
		}
		if !found {
			// This is super unlikely, so log.
			glog.Infof("Failed to find sshKeys metadata, creating a new item")
			project.CommonInstanceMetadata.Items = append(project.CommonInstanceMetadata.Items,
				&compute.MetadataItems{
					Key:   "sshKeys",
					Value: &keyString,
				})
		}
		op, err := gce.service.Projects.SetCommonInstanceMetadata(gce.projectID, project.CommonInstanceMetadata).Do()
		if err != nil {
			glog.Errorf("Could not Set Metadata: %v", err)
			return false, nil
		}
		if err := gce.waitForGlobalOp(op); err != nil {
			glog.Errorf("Could not Set Metadata: %v", err)
			return false, nil
		}
		glog.Infof("Successfully added sshKey to project metadata")
		return true, nil
	})
}
491276
func (g Generationer) StorageGeneration() (initTime time.Time, random string, err error) {
	f, err := os.Open(g.generationFile())
	if os.IsNotExist(err) {
		if err = g.ResetStorageGeneration(); err != nil {
			return
		}
		f, err = os.Open(g.generationFile())
	}
	if err != nil {
		return
	}
	defer f.Close()
	bs, err := ioutil.ReadAll(f)
	if err != nil {
		return
	}
	if i := bytes.IndexByte(bs, '\n'); i != -1 {
		bs = bs[:i]
	}
	if fi, err := f.Stat(); err == nil {
		initTime = fi.ModTime()
	}
	random = string(bs)
	return
}
904901
func (c *Client) CreateBlockStorage(name string, regionID, size int) (BlockStorage, error) {
	values := url.Values{
		"label":   {name},
		"DCID":    {fmt.Sprintf("%v", regionID)},
		"size_gb": {fmt.Sprintf("%v", size)},
	}

	var storage BlockStorage
	if err := c.post(`block/create`, values, &storage); err != nil {
		return BlockStorage{}, err
	}
	storage.RegionID = regionID
	storage.Name = name
	storage.SizeGB = size

	return storage, nil
}
1212682
func InstallMockGCECloud(region string, project string) *mockGCECloud {
	i := buildMockGCECloud(region, project)
	gceCloudInstances[region+"::"+project] = i
	return i
}
31991
func New(params *stripe.EphemeralKeyParams) (*stripe.EphemeralKey, error) {
	return getC().New(params)
}
659429
func (b *gcePersistentDiskMounter) SetUp(fsGroup *int64) error {
	return b.SetUpAt(b.GetPath(), fsGroup)
}