func (e *Engine) GenerateKeypair(ctx context.Context, notifier *observer.Notifier,
	OrgID *identity.ID) error {

	n := notifier.Notifier(4)

	kp, err := e.crypto.GenerateKeyPairs(ctx)
	if err != nil {
		log.Printf("Error generating keypairs: %s", err)
		return err
	}

	n.Notify(observer.Progress, "Keypairs generated", true)

	pubsig, privsig, err := packageSigningKeypair(ctx, e.crypto, e.session.AuthID(),
		OrgID, kp)
	if err != nil {
		log.Printf("Error packaging signing keypair: %s", err)
		return err
	}

	sigclaim, err := e.crypto.SignedEnvelope(
		ctx, primitive.NewClaim(OrgID, e.session.AuthID(), pubsig.ID, pubsig.ID,
			primitive.SignatureClaimType),
		pubsig.ID, &kp.Signature)
	if err != nil {
		log.Printf("Error creating signature claim: %s", err)
		return err
	}

	n.Notify(observer.Progress, "Signing keys signed", true)

	pubsig, privsig, claims, err := e.client.KeyPairs.Post(ctx, pubsig,
		privsig, sigclaim)
	if err != nil {
		log.Printf("Error uploading signature keypair: %s", err)
		return err
	}

	objs := make([]envelope.Envelope, len(claims)+2)
	objs[0] = pubsig
	objs[1] = privsig
	for i, claim := range claims {
		objs[i+2] = &claim
	}
	err = e.db.Set(objs...)
	if err != nil {
		log.Printf("Error storing signing keys in local db: %s", err)
		return err
	}

	n.Notify(observer.Progress, "Signing keys uploaded", true)

	pubenc, privenc, err := packageEncryptionKeypair(ctx, e.crypto, e.session.AuthID(),
		OrgID, kp, pubsig)
	if err != nil {
		log.Printf("Error packaging encryption keypair: %s", err)
	}

	encclaim, err := e.crypto.SignedEnvelope(
		ctx, primitive.NewClaim(OrgID, e.session.AuthID(), pubenc.ID, pubenc.ID,
			primitive.SignatureClaimType),
		pubsig.ID, &kp.Signature)
	if err != nil {
		log.Printf("Error creating signature claim for encryption key: %s", err)
		return err
	}

	n.Notify(observer.Progress, "Encryption keys signed", true)

	pubenc, privenc, claims, err = e.client.KeyPairs.Post(ctx, pubenc,
		privenc, encclaim)
	if err != nil {
		log.Printf("Error uploading encryption keypair: %s", err)
		return err
	}

	objs = make([]envelope.Envelope, len(claims)+2)
	objs[0] = pubenc
	objs[1] = privenc
	for i, claim := range claims {
		objs[i+2] = &claim
	}
	err = e.db.Set(objs...)
	if err != nil {
		log.Printf("Error storing encryption keys in local db: %s", err)
		return err
	}

	return nil
}
// GenerateKeypair creates a signing and encrypting keypair for the current
// user for the given organization.
GenerateKeypair creates a signing and encrypting keypair for the current
user for the given organization.
// GenerateKeypair creates a signing and encrypting keypair for the current // user for the given organization .
func (e *Engine) GenerateKeypair(ctx context.Context, notifier *observer.Notifier,
	OrgID *identity.ID) error {
	n := notifier.Notifier(4)
	kp, err := e.crypto.GenerateKeyPairs(ctx)
	if err != nil {
		log.Printf("Error generating keypairs: %s", err)
		return err
	}
	n.Notify(observer.Progress, "Keypairs generated", true)
	pubsig, privsig, err := packageSigningKeypair(ctx, e.crypto, e.session.AuthID(),
		OrgID, kp)
	if err != nil {
		log.Printf("Error packaging signing keypair: %s", err)
		return err
	}
	sigclaim, err := e.crypto.SignedEnvelope(
		ctx, primitive.NewClaim(OrgID, e.session.AuthID(), pubsig.ID, pubsig.ID,
			primitive.SignatureClaimType),
		pubsig.ID, &kp.Signature)
	if err != nil {
		log.Printf("Error creating signature claim: %s", err)
		return err
	}
	n.Notify(observer.Progress, "Signing keys signed", true)
	pubsig, privsig, claims, err := e.client.KeyPairs.Post(ctx, pubsig,
		privsig, sigclaim)
	if err != nil {
		log.Printf("Error uploading signature keypair: %s", err)
		return err
	}
	objs := make([]envelope.Envelope, len(claims)+2)
	objs[0] = pubsig
	objs[1] = privsig
	for i, claim := range claims {
		objs[i+2] = &claim
	}
	err = e.db.Set(objs...)
	if err != nil {
		log.Printf("Error storing signing keys in local db: %s", err)
		return err
	}
	n.Notify(observer.Progress, "Signing keys uploaded", true)
	pubenc, privenc, err := packageEncryptionKeypair(ctx, e.crypto, e.session.AuthID(),
		OrgID, kp, pubsig)
	if err != nil {
		log.Printf("Error packaging encryption keypair: %s", err)
	}
	encclaim, err := e.crypto.SignedEnvelope(
		ctx, primitive.NewClaim(OrgID, e.session.AuthID(), pubenc.ID, pubenc.ID,
			primitive.SignatureClaimType),
		pubsig.ID, &kp.Signature)
	if err != nil {
		log.Printf("Error creating signature claim for encryption key: %s", err)
		return err
	}
	n.Notify(observer.Progress, "Encryption keys signed", true)
	pubenc, privenc, claims, err = e.client.KeyPairs.Post(ctx, pubenc,
		privenc, encclaim)
	if err != nil {
		log.Printf("Error uploading encryption keypair: %s", err)
		return err
	}
	objs = make([]envelope.Envelope, len(claims)+2)
	objs[0] = pubenc
	objs[1] = privenc
	for i, claim := range claims {
		objs[i+2] = &claim
	}
	err = e.db.Set(objs...)
	if err != nil {
		log.Printf("Error storing encryption keys in local db: %s", err)
		return err
	}
	return nil
}
func ( e * Engine ) GenerateKeypair ( ctx context . Context , notifier * observer . Notifier , OrgID * identity . ID ) error { n := notifier . Notifier ( 4 ) kp , err := e . crypto . GenerateKeyPairs ( ctx ) if err != nil { log . Printf ( " " , err ) return err } n . Notify ( observer . Progress , " " , true ) pubsig , privsig , err := packageSigningKeypair ( ctx , e . crypto , e . session . AuthID ( ) , OrgID , kp ) if err != nil { log . Printf ( " " , err ) return err } sigclaim , err := e . crypto . SignedEnvelope ( ctx , primitive . NewClaim ( OrgID , e . session . AuthID ( ) , pubsig . ID , pubsig . ID , primitive . SignatureClaimType ) , pubsig . ID , & kp . Signature ) if err != nil { log . Printf ( " " , err ) return err } n . Notify ( observer . Progress , " " , true ) pubsig , privsig , claims , err := e . client . KeyPairs . Post ( ctx , pubsig , privsig , sigclaim ) if err != nil { log . Printf ( " " , err ) return err } objs := make ( [ ] envelope . Envelope , len ( claims ) + 2 ) objs [ 0 ] = pubsig objs [ 1 ] = privsig for i , claim := range claims { objs [ i + 2 ] = & claim } err = e . db . Set ( objs ... ) if err != nil { log . Printf ( " " , err ) return err } n . Notify ( observer . Progress , " " , true ) pubenc , privenc , err := packageEncryptionKeypair ( ctx , e . crypto , e . session . AuthID ( ) , OrgID , kp , pubsig ) if err != nil { log . Printf ( " " , err ) } encclaim , err := e . crypto . SignedEnvelope ( ctx , primitive . NewClaim ( OrgID , e . session . AuthID ( ) , pubenc . ID , pubenc . ID , primitive . SignatureClaimType ) , pubsig . ID , & kp . Signature ) if err != nil { log . Printf ( " " , err ) return err } n . Notify ( observer . Progress , " " , true ) pubenc , privenc , claims , err = e . client . KeyPairs . Post ( ctx , pubenc , privenc , encclaim ) if err != nil { log . Printf ( " " , err ) return err } objs = make ( [ ] envelope . Envelope , len ( claims ) + 2 ) objs [ 0 ] = pubenc objs [ 1 ] = privenc for i , claim := range claims { objs [ i + 2 ] = & claim } err = e . db . Set ( objs ... ) if err != nil { log . Printf ( " " , err ) return err } return nil }
GenerateKeypair creates a signing and encrypting keypair for the current
user for the given organization.
GenerateKeypair creates a signing and encrypting keypair for the current user for the given organization .