func()

in yubikey/pkg/value/encryption/envelope/piv/card.go [58:85]


func (c *pivCard) SharedKey(peer *ecdsa.PublicKey, prompt Prompter) ([]byte, error) {
	// Check arguments
	if c.card == nil {
		return nil, errors.New("card is not initialized")
	}
	if peer == nil {
		return nil, errors.New("unable to proceed with a nil peer public key")
	}

	// Extract certificate private key.
	priv, err := c.card.PrivateKey(c.slot, c.pub, gopiv.KeyAuth{
		PINPrompt: func() (string, error) {
			return prompt(fmt.Sprintf("Enter PIN for Yubikey with serial %d", c.serial))
		},
	})
	if err != nil {
		return nil, fmt.Errorf("cannot get PIV private key handle: %w", err)
	}

	// Compute ECDH shared secret from key.
	shared, err := priv.(*gopiv.ECDSAPrivateKey).SharedKey(peer)
	if err != nil {
		return nil, fmt.Errorf("PIV ECDHE error: %w", err)
	}

	// No error
	return shared, nil
}