// CreateJWTIdentity returns a signed string
482909
func CreateJWTIdentity(hostID, poolID string, admin, dfs bool, pubKeyPEM []byte, expiration time.Duration) (string, int64, error) {
	now := jwt.TimeFunc().UTC()
	claims := &jwtIdentity{
		Host:        hostID,
		Pool:        poolID,
		ExpiresAt:   now.Add(expiration).Unix(),
		IssuedAt:    now.Unix(),
		AdminAccess: admin,
		DFSAccess:   dfs,
		PubKey:      string(pubKeyPEM),
	}
	token := jwt.NewWithClaims(jwt.SigningMethodPS256, claims)
	masterPrivKey, err := getMasterPrivateKey()
	if err != nil {
		return "", 0, err
	}
	signed, err := token.SignedString(masterPrivKey)
	return signed, claims.ExpiresAt, err
}
1350095
func createDTOFromEntity(entity Entity) (resDTO rest.ResponseDTO) {
	copier.Copy(&resDTO, &entity)
	return resDTO
}
1328190
func (mgr *MockMSPManager) DeserializeIdentity(serializedIdentity []byte) (msp.Identity, error) {
	return nil, nil
}
1040265
func NewClientJWT(iss string, aud string) ClientJWT {
	jwt := ClientJWT{}
	jwt.ISS = iss
	jwt.SUB = iss
	jwt.AUD = aud
	now := time.Now()
	jwt.IAT = now.Unix()
	jwt.EXP = jwt.IAT + 60
	jwt.JTI = fake.CharactersN(50)
	return jwt
}
640836
func newJWTAuthentication(userName, password string) vstAuthentication {
	return &vstAuthenticationImpl{
		encryption: "jwt",
		userName:   userName,
		password:   password,
	}
}
16548
func CreateSignature(stringToSignature, accessKeySecret string) string {
	// Crypto by HMAC-SHA1
	hmacSha1 := hmac.New(sha1.New, []byte(accessKeySecret))
	hmacSha1.Write([]byte(stringToSignature))
	sign := hmacSha1.Sum(nil)

	// Encode to Base64
	base64Sign := base64.StdEncoding.EncodeToString(sign)

	return base64Sign
}
1038768
func builtinJWTVerifyRS256(a ast.Value, b ast.Value) (ast.Value, error) {
	return builtinJWTVerifyRSA(a, b, func(publicKey *rsa.PublicKey, digest []byte, signature []byte) error {
		return rsa.VerifyPKCS1v15(
			publicKey,
			crypto.SHA256,
			digest,
			signature)
	})
}
229955
func BuildJWT(subject string, ttl time.Duration, privateKey []byte) (token string, err error) {
	claims := jwt.StandardClaims{
		Issuer:    subject,
		Subject:   subject,
		IssuedAt:  time.Now().Add(-20 * time.Second).Unix(),
		NotBefore: time.Now().Add(-20 * time.Second).Unix(),
	}
	if ttl > 0 {
		claims.ExpiresAt = time.Now().Add(ttl).Unix()
	}
	tokenBuilder := jwt.NewWithClaims(jwt.SigningMethodES256, claims)
	var key *ecdsa.PrivateKey
	key, err = jwt.ParseECPrivateKeyFromPEM(privateKey)
	if err != nil {
		return
	}
	token, err = tokenBuilder.SignedString(key)
	if err != nil {
		return
	}
	return
}
1330935
func UserJWT(userCB UserJWTHandler, sigCB SignatureHandler) Option {
	return func(o *Options) error {
		if userCB == nil {
			return ErrNoUserCB
		}
		if sigCB == nil {
			return ErrUserButNoSigCB
		}
		o.UserJWT = userCB
		o.SignatureCB = sigCB
		return nil
	}
}
1076852
func (p *ProcessStorage) WriteIdentity(name string, id Identity) error {
	res := IdentityV2{
		ResourceHeader: services.ResourceHeader{
			Kind:    services.KindIdentity,
			Version: services.V2,
			Metadata: services.Metadata{
				Name: name,
			},
		},
		Spec: IdentitySpecV2{
			Key:        id.KeyBytes,
			SSHCert:    id.CertBytes,
			TLSCert:    id.TLSCertBytes,
			TLSCACerts: id.TLSCACertsBytes,
			SSHCACerts: id.SSHCACertBytes,
		},
	}
	if err := res.CheckAndSetDefaults(); err != nil {
		return trace.Wrap(err)
	}
	value, err := json.Marshal(res)
	if err != nil {
		return trace.Wrap(err)
	}
	item := backend.Item{
		Key:   backend.Key(idsPrefix, strings.ToLower(id.ID.Role.String()), name),
		Value: value,
	}
	_, err = p.Put(context.TODO(), item)
	return trace.Wrap(err)
}
1350726
func (m *Middleware) CreateToken(identity string) (string, error) {
	// For now, the header will be static
	header, err := encode(fmt.Sprintf(`{"typ":%q,"alg":%q}`, typ, alg))
	if err != nil {
		return "encoding header", ErrEncoding
	}

	// Generate claims for user
	claims, err := m.claims(identity)
	if err != nil {
		return "generating claims", err
	}

	claimsJSON, err := json.Marshal(claims)
	if err != nil {
		return "mashalling claims", ErrEncoding
	}

	claimsSet, err := encode(claimsJSON)
	if err != nil {
		return "encoding claims", ErrEncoding
	}

	toSig := strings.Join([]string{header, claimsSet}, ".")

	h := hmac.New(sha256.New, []byte(m.secret))
	h.Write([]byte(toSig))
	sig, err := encode(h.Sum(nil))
	if err != nil {
		return "encoding signature", ErrEncoding
	}

	response := strings.Join([]string{toSig, sig}, ".")
	return response, nil
}
26927
func CreateAndSign(server string, profile, scopes []string, id string, validity time.Duration, gkey interface{}) (string, error) {
	key, ok := gkey.(*ecdsa.PrivateKey)
	if !ok {
		return "", fmt.Errorf("Not a valid private key format")
	}
	if token, err := localCache.Get(id); err == nil {
		return token.(string), nil
	}
	claims := &JWTClaims{
		StandardClaims: jwt.StandardClaims{
			Issuer:    server,
			ExpiresAt: time.Now().Add(validity).Unix(),
			Subject:   id,
		},
		Profile: profile,
		Scopes:  scopes,
	}

	token, err := jwt.NewWithClaims(jwt.SigningMethodES256, claims).SignedString(key)
	if err != nil {
		return "", err
	}

	localCache.AddOrUpdate(id, token)
	return token, nil
}
759318
func CreateConfigSignature(ctx context.Client, config []byte) (*common.ConfigSignature, error) {
	cfd, e := GetConfigSignatureData(ctx, config)
	if e != nil {
		return nil, e
	}

	signingMgr := ctx.SigningManager()
	signature, err := signingMgr.Sign(cfd.SigningBytes, ctx.PrivateKey())
	if err != nil {
		return nil, errors.WithMessage(err, "signing of channel config failed")
	}

	// build the return object
	configSignature := common.ConfigSignature{
		SignatureHeader: cfd.SignatureHeaderBytes,
		Signature:       signature,
	}
	return &configSignature, nil
}
322307
func (p *provisioningIdentityMapper) createIdentityAndMapping(ctx context.Context, info authapi.UserIdentityInfo) (kuser.Info, error) {
	// Build the part of the identity we know about
	identity := &userapi.Identity{
		ObjectMeta: metav1.ObjectMeta{
			Name: info.GetIdentityName(),
		},
		ProviderName:     info.GetProviderName(),
		ProviderUserName: info.GetProviderUserName(),
		Extra:            info.GetExtra(),
	}

	// GetIdentities or create a persisted user pointing to the identity
	persistedUser, err := p.provisioningStrategy.UserForNewIdentity(ctx, getPreferredUserName(identity), identity)
	if err != nil {
		return nil, err
	}

	// CreateIdentity the identity pointing to the persistedUser
	identity.User = corev1.ObjectReference{
		Name: persistedUser.Name,
		UID:  persistedUser.UID,
	}
	if _, err := p.identity.Create(identity); err != nil {
		return nil, err
	}

	return userToInfo(persistedUser), nil
}
1284574
func createSignature(message string, secret string) string {
	key := []byte(secret)
	h := hmac.New(sha256.New, key)
	h.Write([]byte(message))
	return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
1374482
func (rc *Client) CreateConfigSignature(signer msp.SigningIdentity, channelConfigPath string) (*common.ConfigSignature, error) {
	chConfig, err := readChConfigData(channelConfigPath)
	if err != nil {
		return nil, err
	}

	sigs, err := rc.createCfgSigFromIDs(chConfig, signer)
	if err != nil {
		return nil, err
	}

	if len(sigs) != 1 {
		return nil, errors.New("creating a config signature for 1 identity did not return 1 signature")
	}

	return sigs[0], nil
}
119138
func (s *SetIdentityDkimEnabledInput) SetIdentity(v string) *SetIdentityDkimEnabledInput {
	s.Identity = &v
	return s
}