Documentation ¶
Overview ¶
Package openpgp implements the interface to the OpenPGP application on ISO Smart Card Operating Systems v3.4.1 See: https://gnupg.org/ftp/specs/OpenPGP-smart-card-application-3.4.1.pdf
Index ¶
- Constants
- Variables
- type AID
- type AlgHash
- type AlgKDF
- type AlgPubkey
- type AlgSymmetric
- type AlgorithmAttributes
- func (a AlgorithmAttributes) Compatible(b AlgorithmAttributes) bool
- func (a AlgorithmAttributes) Curve() Curve
- func (a *AlgorithmAttributes) Decode(b []byte) error
- func (a AlgorithmAttributes) Encode() (b []byte)
- func (a AlgorithmAttributes) Equal(b AlgorithmAttributes) bool
- func (a AlgorithmAttributes) String() string
- type ApplicationRelated
- type AuthError
- type BlockCipher
- type Card
- func (c *Card) AlgorithmAttributes(key KeyRef) (attrs AlgorithmAttributes, err error)
- func (c *Card) BlockCipher() *BlockCipher
- func (c *Card) Challenge(cnt int) ([]byte, error)
- func (c *Card) ChangePassword(pwType byte, pwCurrent, pwNew string) error
- func (c *Card) ChangeResettingCode(rc string) error
- func (c *Card) ClearPasswordState(pwType byte) error
- func (c *Card) ClearResettingCode() error
- func (c *Card) Close() error
- func (c *Card) FactoryReset() error
- func (c *Card) GenerateKey(key KeyRef, attrs AlgorithmAttributes) (crypto.PrivateKey, error)
- func (c *Card) GetApplicationRelatedData() (ar *ApplicationRelated, err error)
- func (c *Card) GetCardholder() (ch *Cardholder, err error)
- func (c *Card) GetCardholderCertificate(key KeyRef) ([]byte, error)
- func (c *Card) GetCardholderCertificates() ([][]byte, error)
- func (c *Card) GetKDF() (k *KDF, err error)
- func (c *Card) GetLoginData() (string, error)
- func (c *Card) GetPasswordStatus() (*PasswordStatus, error)
- func (c *Card) GetPublicKeyURL() (*url.URL, error)
- func (c *Card) GetSecuritySupportTemplate() (sst *SecuritySupportTemplate, err error)
- func (c *Card) GetSignatureCounter() (int, error)
- func (c *Card) ImportKey(key KeyRef, skImport crypto.PrivateKey) (crypto.PrivateKey, error)
- func (c *Card) ImportKeyAES(key []byte) error
- func (c *Card) ManageSecurityEnvironment(op SecurityOperation, key KeyRef) error
- func (c *Card) PasswordState(pwType byte) (bool, error)
- func (c *Card) PrivateData(index int) ([]byte, error)
- func (c *Card) PrivateKey(key KeyRef, pkHint crypto.PublicKey) (crypto.PrivateKey, error)
- func (c *Card) ResetRetryCounter(newPw string) error
- func (c *Card) ResetRetryCounterWithResettingCode(rc, newPw string) error
- func (c *Card) Select() error
- func (c *Card) SetCardholder(ch Cardholder) error
- func (c *Card) SetLanguage(lang string) error
- func (c *Card) SetLoginData(login string) error
- func (c *Card) SetName(name string) error
- func (c *Card) SetPasswordMode(mode PasswordMode) error
- func (c *Card) SetPrivateData(index int, b []byte) error
- func (c *Card) SetPublicKeyURL(url *url.URL) error
- func (c *Card) SetRetryCounters(pw1, rc, pw3 byte) error
- func (c *Card) SetSex(sex Sex) error
- func (c *Card) SetUserInteractionMode(op SecurityOperation, mode UserInteractionMode, feat GeneralFeatures) error
- func (c *Card) SetupKDF(alg AlgKDF, iterations int, pw1, pw3 string) (err error)
- func (c *Card) SupportedAlgorithms() (map[KeyRef][]AlgorithmAttributes, error)
- func (c *Card) VerifyPassword(pwType byte, pw string) (err error)
- type Cardholder
- type Curve
- type ExtendedCapabilities
- type ExtendedCapabilitiesFlag
- type ExtendedLengthInfo
- type Fingerprint
- type GeneralFeatures
- type ImportFormat
- type KDF
- type KeyInfo
- type KeyRef
- type KeyStatus
- type LifeCycleStatus
- type Manufacturer
- type PasswordMode
- type PasswordStatus
- type PrivateKeyECDH
- type PrivateKeyECDSA
- type PrivateKeyEdDSA
- type PrivateKeyRSA
- type SecurityOperation
- type SecuritySupportTemplate
- type Sex
- type UIF
- type UserInteractionMode
Constants ¶
const ( PW1 byte = 0x81 // User PIN (PSO:CDS command only) PW1forPSO byte = 0x82 // User PIN for PSO: DECIPHER RC byte = 0x82 // Resetting code PW3 byte = 0x83 // Admin PIN )
const ( GeneralFeatureTouchscreen byte = (1 << iota) GeneralFeatureMicrophone GeneralFeatureSpeaker GeneralFeatureLED GeneralFeatureKeyPad GeneralFeatureButton GeneralFeatureBiometric GeneralFeatureDisplay )
Variables ¶
var ( DefaultPW = map[byte]string{ RC: DefaultPW1, PW3: DefaultPW3, } DefaultPW1 = "123456" DefaultPW3 = "12345678" )
var ( // ErrMismatchingAlgorithms is returned when a cryptographic operation // is given keys using different algorithms. ErrMismatchingAlgorithms = errors.New("mismatching key algorithms") ErrInvalidLength = errors.New("invalid length") ErrUnsupported = errors.New("unsupported") ErrUnsupportedKeyType = fmt.Errorf("%w key attributes", ErrUnsupported) ErrUnsupportedCurve = fmt.Errorf("%w curve", ErrUnsupported) ErrAlgAttrsNotChangeable = errors.New("algorithm attributes are not changeable") )
var ErrPubkeyRequired = fmt.Errorf("missing public key: not present on card")
var ICV = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
ICV is the Initial Chaining Value used by OpenPGP cards for symmetric encryption using AES-CBC
Functions ¶
This section is empty.
Types ¶
type AID ¶ added in v0.2.1
type AlgPubkey ¶
type AlgPubkey byte
const ( AlgPubkeyRSA AlgPubkey = 1 // RSA (Encrypt or Sign) AlgPubkeyRSAEncOnly AlgPubkey = 2 // RSA Encrypt-Only (legacy) AlgPubkeyRSASignOnly AlgPubkey = 3 // RSA Sign-Only (legacy) AlgPubkeyElgamalEncOnly AlgPubkey = 16 // Elgamal (Encrypt-Only) AlgPubkeyDSA AlgPubkey = 17 // DSA (Digital Signature Algorithm) AlgPubkeyECDH AlgPubkey = 18 // RFC-6637 AlgPubkeyECDSA AlgPubkey = 19 // RFC-6637 AlgPubkeyElgamalEncSignOnly AlgPubkey = 20 // Elgamal encrypt+sign, reserved by OpenPGP (legacy) AlgPubkeyEdDSA AlgPubkey = 22 // EdDSA AlgPubkeyKy768_25519 AlgPubkey = 29 // Kyber768 + X25519 AlgPubkeyKy1024_448 AlgPubkey = 30 // Kyber1024 + X448 AlgPubkeyDil3_25519 AlgPubkey = 35 // Dilithium3 + Ed25519 AlgPubkeyDil5_448 AlgPubkey = 36 // Dilithium5 + Ed448 AlgPubkeySPHINXSHA2 AlgPubkey = 41 // SPHINX+-simple-SHA2 )
type AlgSymmetric ¶
type AlgSymmetric byte
const ( AlgSymPlaintext AlgSymmetric = iota // Plaintext or unencrypted data AlgSymIDEA // IDEA AlgSymTripleDES // TripleDES (DES-EDE, - 168 bit key derived from 192) AlgSymCAST5 // CAST5 (128 bit key, as per RFC2144) AlgSymBlowfish // Blowfish (128 bit key, 16 rounds) AlgSymAES128 // AES with 128-bit key AlgSymAES192 // AES with 192-bit key AlgSymAES256 // AES with 256-bit key AlgSymTwofish // Twofish with 256-bit key )
type AlgorithmAttributes ¶
type AlgorithmAttributes struct { Algorithm AlgPubkey ImportFormat ImportFormat // Relevant for RSA LengthModulus int LengthExponent int // Relevant for ECDSA/ECDH/EdDSA OID []byte }
func EC ¶
func EC(curve Curve) AlgorithmAttributes
func RSA ¶
func RSA(bits int) AlgorithmAttributes
func (AlgorithmAttributes) Compatible ¶ added in v0.2.1
func (a AlgorithmAttributes) Compatible(b AlgorithmAttributes) bool
func (AlgorithmAttributes) Curve ¶
func (a AlgorithmAttributes) Curve() Curve
func (*AlgorithmAttributes) Decode ¶
func (a *AlgorithmAttributes) Decode(b []byte) error
func (AlgorithmAttributes) Encode ¶
func (a AlgorithmAttributes) Encode() (b []byte)
func (AlgorithmAttributes) Equal ¶
func (a AlgorithmAttributes) Equal(b AlgorithmAttributes) bool
func (AlgorithmAttributes) String ¶
func (a AlgorithmAttributes) String() string
type ApplicationRelated ¶
type ApplicationRelated struct { AID AID HistoricalBytes iso.HistoricalBytes LengthInfo ExtendedLengthInfo Capabilities ExtendedCapabilities Features GeneralFeatures PasswordStatus PasswordStatus Keys map[KeyRef]KeyInfo }
func (*ApplicationRelated) Decode ¶
func (ar *ApplicationRelated) Decode(b []byte) (err error)
type AuthError ¶
type AuthError struct { // Retries is the number of retries remaining if this error resulted from a retry-able // authentication attempt. If the authentication method is blocked or does not support // retries, this will be 0. Retries int }
AuthError is an error indicating an authentication error occurred (wrong PIN or blocked).
type BlockCipher ¶ added in v0.2.1
type BlockCipher struct {
// contains filtered or unexported fields
}
func (BlockCipher) BlockSize ¶ added in v0.2.1
func (k BlockCipher) BlockSize() int
BlockSize returns the cipher's block size.
func (*BlockCipher) Decrypt ¶ added in v0.2.1
func (k *BlockCipher) Decrypt(ct []byte) ([]byte, error)
Decrypt decrypts the provided ciphertext using AES in Cipher Block Chaining (CBC) mode using an Initial Chaining Value (ICV) of zero bytes.
See: OpenPGP Smart Card Application - Section 7.2.11 PSO: DECIPHER
func (*BlockCipher) Encrypt ¶ added in v0.2.1
func (k *BlockCipher) Encrypt(pt []byte) ([]byte, error)
Encrypt encrypts the provided plaintext using AES in Cipher Block Chaining (CBC) mode using an Initial Chaining Value (ICV) of zero bytes ([IV]).
See: OpenPGP Smart Card Application - Section 7.2.12 PSO: ENCIPHER
type Card ¶
type Card struct { *iso.Card Rand io.Reader Clock func() time.Time *ApplicationRelated *Cardholder *SecuritySupportTemplate // contains filtered or unexported fields }
func (*Card) AlgorithmAttributes ¶
func (c *Card) AlgorithmAttributes(key KeyRef) (attrs AlgorithmAttributes, err error)
AlgorithmAttributes returns the currently configured algorithm attributes for the given key.
func (*Card) BlockCipher ¶ added in v0.2.1
func (c *Card) BlockCipher() *BlockCipher
BlockCipher returns a block cipher object for symmetric AES de/encipherment.
func (*Card) Challenge ¶
Challenge generates a random number of cnt bytes.
See: OpenPGP Smart Card Application - Section 7.2.15 GET CHALLENGE
func (*Card) ChangePassword ¶
ChangePassword changes the user or admin password.
Access condition: Always Access level: None (current password must be provided) See: OpenPGP Smart Card Application - Section 7.2.3 CHANGE REFERENCE DATA
func (*Card) ChangeResettingCode ¶
ChangeResettingCode sets the resetting code of the cards.
Access condition: Admin/PW3 See: OpenPGP Smart Card Application - Section 4.3.4 Resetting Code
func (*Card) ClearPasswordState ¶
ClearPasswordState clears the passwort unlock state from the card.
Access condition: Always Note: Appears to be broken on YubiKey 5 See: OpenPGP Smart Card Application - Section 7.2.2 VERIFY
func (*Card) ClearResettingCode ¶
func (*Card) FactoryReset ¶
FactoryReset resets the applet to its original state
Access condition: Admin/PW3
Alternatively, we will try to block the Admin PIN by repeatedly calling VerifyPassword() with a wrong password to enable TERMINATE DF without Admin PIN.
See: OpenPGP Smart Card Application - Section 7.2.16 TERMINATE DF & 7.2.17 ACTIVATE FILE
func (*Card) GenerateKey ¶
func (c *Card) GenerateKey(key KeyRef, attrs AlgorithmAttributes) (crypto.PrivateKey, error)
func (*Card) GetApplicationRelatedData ¶
func (c *Card) GetApplicationRelatedData() (ar *ApplicationRelated, err error)
GetApplicationRelatedData fetches the application related data from the card.
func (*Card) GetCardholder ¶
func (c *Card) GetCardholder() (ch *Cardholder, err error)
GetCardholder fetches the card holder information from the card.
func (*Card) GetCardholderCertificate ¶
func (*Card) GetCardholderCertificates ¶
func (*Card) GetLoginData ¶
func (*Card) GetPasswordStatus ¶
func (c *Card) GetPasswordStatus() (*PasswordStatus, error)
func (*Card) GetSecuritySupportTemplate ¶
func (c *Card) GetSecuritySupportTemplate() (sst *SecuritySupportTemplate, err error)
GetSecuritySupportTemplate fetches the the security template from the card.
func (*Card) GetSignatureCounter ¶
func (*Card) ImportKey ¶
func (c *Card) ImportKey(key KeyRef, skImport crypto.PrivateKey) (crypto.PrivateKey, error)
func (*Card) ImportKeyAES ¶ added in v0.2.1
ImportKeyAES stores an AES key for symmetric encryption on the card. The Key length must be 16 or 32 Byte for AES128 and AES256 respectively. For encryption and decryption, use the block cipher object returned by Card.BlockCipher.
func (*Card) ManageSecurityEnvironment ¶
func (c *Card) ManageSecurityEnvironment(op SecurityOperation, key KeyRef) error
See: OpenPGP Smart Card Application - Section 7.2.18 MANAGE SECURITY ENVIRONMENT
func (*Card) PasswordState ¶
PasswordState returns true if the given password is unlocked.
Access condition: Always Note: Appears to be broken on YubiKey 5 See: OpenPGP Smart Card Application - Section 7.2.2 VERIFY
func (*Card) PrivateKey ¶
func (*Card) ResetRetryCounter ¶
ResetRetryCounter reset the PIN retry counter and a new password.
Access condition: Admin/PW3 See: OpenPGP Smart Card Application - Section 7.2.4 RESET RETRY COUNTER
func (*Card) ResetRetryCounterWithResettingCode ¶
ResetRetryCounterWithResettingCode resets the PIN retry counter using a reset code.
Access condition: None (reset code is required) See: OpenPGP Smart Card Application - Section 7.2.4 RESET RETRY COUNTER
func (*Card) Select ¶
Select selects the OpenPGP applet.
See: OpenPGP Smart Card Application - Section 7.2.1 SELECT
func (*Card) SetCardholder ¶
func (c *Card) SetCardholder(ch Cardholder) error
func (*Card) SetLanguage ¶
func (*Card) SetLoginData ¶
func (*Card) SetPasswordMode ¶ added in v0.2.1
func (c *Card) SetPasswordMode(mode PasswordMode) error
func (*Card) SetRetryCounters ¶
SetRetryCounters sets the number of PIN attempts to allow before blocking.
Access condition: Admin/PW3 Note: This is a YubiKey extensions Warning: On YubiKey NEO this will reset the PINs to their default values.
func (*Card) SetUserInteractionMode ¶ added in v0.2.1
func (c *Card) SetUserInteractionMode(op SecurityOperation, mode UserInteractionMode, feat GeneralFeatures) error
func (*Card) SetupKDF ¶
SetupKDF initialize the KDF data object and updates passwords to work with it.
Resetting code must be set again. User/PW1 and Admin/PW3 are unchanged.
Access condition: Admin/PW3 (User/PW1 and AdminPW3 must be passed as arguments) See: OpenPGP Smart Card Application - Section 4.3.2 Key derived format
func (*Card) SupportedAlgorithms ¶
func (c *Card) SupportedAlgorithms() (map[KeyRef][]AlgorithmAttributes, error)
SupportedAlgorithms returns the list of supported algorithms by each key type.
type Cardholder ¶
func (*Cardholder) Decode ¶
func (ch *Cardholder) Decode(b []byte) (err error)
type Curve ¶
type Curve byte
func (Curve) AlgAttrs ¶ added in v0.2.1
func (c Curve) AlgAttrs() AlgorithmAttributes
type ExtendedCapabilities ¶
type ExtendedCapabilities struct { Flags ExtendedCapabilitiesFlag AlgSM byte MaxLenChallenge uint16 MaxLenCardholderCert uint16 MaxLenSpecialDO uint16 Pin2BlockFormat byte CommandMSE byte }
func (*ExtendedCapabilities) Decode ¶
func (ec *ExtendedCapabilities) Decode(b []byte) error
type ExtendedCapabilitiesFlag ¶
type ExtendedCapabilitiesFlag byte
const ( CapKDF ExtendedCapabilitiesFlag = (1 << iota) CapAES CapAlgAttrsChangeable CapPrivateDO CapPasswordStatusChangeable CapKeyImport CapGetChallenge CapSecureMessaging )
type ExtendedLengthInfo ¶
func (*ExtendedLengthInfo) Decode ¶
func (li *ExtendedLengthInfo) Decode(b []byte) error
type Fingerprint ¶
type Fingerprint [20]byte
type GeneralFeatures ¶
type GeneralFeatures byte
func (*GeneralFeatures) Decode ¶
func (gf *GeneralFeatures) Decode(b []byte) error
type ImportFormat ¶
type ImportFormat byte
const ( ImportFormatRSAStd ImportFormat = iota ImportFormatRSAStdWithModulus ImportFormatRSACRT ImportFormatRSACRTWithModulus ImportFormatECDSAStdWithPublicKey ImportFormat = 0xff )
type KDF ¶
type KDF struct { Algorithm AlgKDF HashAlgorithm AlgHash Iterations int SaltPW1 [8]byte SaltPW3 [8]byte SaltRC [8]byte InitialHashPW1 []byte InitialHashPW3 []byte }
KDF contains the Parameters for the Key Derivation Function (KDF).
type LifeCycleStatus ¶
type LifeCycleStatus byte
See: OpenPGP Smart Card Application - Section 6 Historical Bytes
const ( LifeCycleStatusNoInfo LifeCycleStatus = 0x00 LifeCycleStatusInitialized LifeCycleStatus = 0x03 LifeCycleStatusOperational LifeCycleStatus = 0x05 )
type Manufacturer ¶
type Manufacturer uint16
const (
ManufacturerYubico Manufacturer = 0x0006
)
From: https://github.com/gpg/gnupg/blob/9e4d52223945d677c1ffcb0e20dae48299e9aae1/scd/app-openpgp.c#L293
func (Manufacturer) String ¶
func (m Manufacturer) String() string
type PasswordMode ¶ added in v0.2.1
type PasswordStatus ¶
type PasswordStatus struct { ValidityPW1 uint8 LengthPW1 uint8 LengthRC uint8 LengthPW3 uint8 AttemptsPW1 uint8 AttemptsRC uint8 AttemptsPW3 uint8 }
func (*PasswordStatus) Decode ¶
func (ps *PasswordStatus) Decode(b []byte) error
type PrivateKeyECDH ¶ added in v0.2.1
type PrivateKeyECDH struct {
// contains filtered or unexported fields
}
func (*PrivateKeyECDH) ECDH ¶ added in v0.2.1
func (k *PrivateKeyECDH) ECDH(peer *ecdh.PublicKey) ([]byte, error)
ECDH performs a Diffie-Hellman key agreement with the peer to produce a shared secret key.
See: OpenPGP Smart Card Application - Section 7.2.11 PSO: DECIPHER
func (*PrivateKeyECDH) Public ¶ added in v0.2.1
func (k *PrivateKeyECDH) Public() crypto.PublicKey
type PrivateKeyECDSA ¶ added in v0.2.1
type PrivateKeyECDSA struct {
// contains filtered or unexported fields
}
func (*PrivateKeyECDSA) Decrypt ¶ added in v0.2.1
func (k *PrivateKeyECDSA) Decrypt(_ io.Reader, _ []byte, _ crypto.DecrypterOpts) (plaintext []byte, err error)
See: OpenPGP Smart Card Application - Section 7.2.11 PSO: DECIPHER
func (*PrivateKeyECDSA) Public ¶ added in v0.2.1
func (k *PrivateKeyECDSA) Public() crypto.PublicKey
func (*PrivateKeyECDSA) Sign ¶ added in v0.2.1
func (k *PrivateKeyECDSA) Sign(_ io.Reader, digest []byte, opts crypto.SignerOpts) (signature []byte, err error)
See: OpenPGP Smart Card Application - Section 7.2.10 PSO: COMPUTE DIGITAL SIGNATURE
type PrivateKeyEdDSA ¶ added in v0.2.1
type PrivateKeyEdDSA struct {
// contains filtered or unexported fields
}
func (PrivateKeyEdDSA) Public ¶ added in v0.2.1
func (k PrivateKeyEdDSA) Public() crypto.PublicKey
func (PrivateKeyEdDSA) Sign ¶ added in v0.2.1
func (k PrivateKeyEdDSA) Sign(_ io.Reader, digest []byte, opts crypto.SignerOpts) (signature []byte, err error)
See: OpenPGP Smart Card Application - Section 7.2.10 PSO: COMPUTE DIGITAL SIGNATURE
type PrivateKeyRSA ¶ added in v0.2.1
type PrivateKeyRSA struct {
// contains filtered or unexported fields
}
func (*PrivateKeyRSA) Bits ¶ added in v0.2.1
func (k *PrivateKeyRSA) Bits() int
func (*PrivateKeyRSA) Decrypt ¶ added in v0.2.1
func (k *PrivateKeyRSA) Decrypt(_ io.Reader, _ []byte, _ crypto.DecrypterOpts) (plaintext []byte, err error)
See: OpenPGP Smart Card Application - Section 7.2.11 PSO: DECIPHER
func (*PrivateKeyRSA) Public ¶ added in v0.2.1
func (k *PrivateKeyRSA) Public() crypto.PublicKey
func (*PrivateKeyRSA) Sign ¶ added in v0.2.1
func (k *PrivateKeyRSA) Sign(_ io.Reader, _ []byte, _ crypto.SignerOpts) (signature []byte, err error)
See: OpenPGP Smart Card Application - Section 7.2.10 PSO: COMPUTE DIGITAL SIGNATURE
type SecurityOperation ¶
type SecurityOperation byte
const ( SecurityOperationSign SecurityOperation = iota SecurityOperationAuthenticate // Authentication SecurityOperationDecrypt // Confidentiality SecurityOperationAttest )
type SecuritySupportTemplate ¶
func (*SecuritySupportTemplate) Decode ¶
func (sst *SecuritySupportTemplate) Decode(b []byte) (err error)
type UIF ¶ added in v0.2.1
type UIF struct { Mode UserInteractionMode Feature GeneralFeatures }
UIF configures the required user interaction for certain security operations.
type UserInteractionMode ¶
type UserInteractionMode byte
const ( UserInteractionDisabled UserInteractionMode = 0x00 UserInteractionEnabled UserInteractionMode = 0x01 UserInteractionEnabledFixed UserInteractionMode = 0x02 UserInteractionCached UserInteractionMode = 0x03 UserInteractionCachedFixed UserInteractionMode = 0x04 )