openpgp

package
v0.0.0-...-15d4781 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2019 License: ISC Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Tag_PrivateUse0101           = 0x0101
	Tag_PrivateUse0102           = 0x0102
	Tag_PrivateUse0103           = 0x0103
	Tag_PrivateUse0104           = 0x0104
	Tag_ApplicationID            = 0x4F
	Tag_LoginData                = 0x5E
	Tag_PublicKeyURL             = 0x5F50
	Tag_HistoricalBytes          = 0x5F52
	Tag_ExtendedLengthInfo       = 0x7F66
	Tag_GeneralFeatureManagement = 0x7F74
	Tag_CardholderRelatedData    = 0x0065
	Tag_ApplicationReferenceData = 0x6E
	Tag_DiscretionaryDataObjects = 0x73
	Tag_ExtendedCapabilities     = 0xC0
	Tag_AlgorithmAttributes_Sig  = 0xC1
	Tag_ALgorithmAttributes_Dec  = 0xC2
	Tag_AlgorithmAttributes_Aut  = 0xC3
	Tag_PasswordStatusBytes      = 0xC4
	Tag_Fingerprints             = 0xC5
	Tag_CAFingerprints           = 0xC6
	Tag_KeyGenerationTImestamps  = 0xCD
	Tag_UserInteractionFlag_Sig  = 0xD6
	Tag_UserInteractionFlag_Dec  = 0xD7
	Tag_UserInteractionFlag_Aut  = 0xD8
	Tag_SecuritySupportTemplate  = 0x7A
	Tag_DigitalSignatureCounter  = 0x93
	Tag_CardholderCertificate    = 0x7F21
	Tag_KDFDataObject            = 0xF9
)

Tags

View Source
const (
	File_PrivateUse0101 = Tag_PrivateUse0101
	File_PrivateUse0102 = Tag_PrivateUse0102
	File_PrivateUse0103 = Tag_PrivateUse0103
	File_PrivateUse0104 = Tag_PrivateUse0104

	File_ApplicationID = Tag_ApplicationID
	File_LoginData     = Tag_LoginData
	File_PublicKeyURL  = Tag_PublicKeyURL

	File_HistoricalBytes    = Tag_HistoricalBytes
	File_ExtendedLengthInfo = Tag_ExtendedLengthInfo

	File_CardholderRelatedData    = Tag_CardholderRelatedData
	File_ApplicationReferenceData = Tag_ApplicationReferenceData

	File_UserInteractionFlag_Sig = Tag_UserInteractionFlag_Sig
	File_UserInteractionFlag_Dec = Tag_UserInteractionFlag_Dec
	File_UserInteractionFlag_Aut = Tag_UserInteractionFlag_Aut
	File_SecuritySupportTemplate = Tag_SecuritySupportTemplate
	File_CardholderCertificate   = Tag_CardholderCertificate
	File_KDFDataObject           = Tag_KDFDataObject

	File_SigFingerprint = 0xC7
	File_EncFingerprint = 0xC8
	File_AutFingerprint = 0xC9

	File_SigCAFingerprint = 0xCA
	File_EncCAFingerprint = 0xCB
	File_AutCAFingerprint = 0xCC

	File_SigGenerationTimestamp = 0xCE
	File_EncGenerationTimestamp = 0xCF
	File_AutGenerationTimestamp = 0xD0
)

File IDs Access using card.(Get|Set)FileData

View Source
const (
	SigningKey        Key = 0xB6
	EncryptionKey     Key = 0xB8
	DecryptionKey         = EncryptionKey
	AuthenticationKey Key = 0xA4

	SigKey = SigningKey
	EncKey = EncryptionKey
	DecKey = DecryptionKey
	AutKey = AuthenticationKey
)

Variables

View Source
var AID = []byte{0xD2, 0x76, 0x00, 0x01, 0x24, 0x01}

AID is the OpenPGP Application ID

Functions

func Activate

func Activate(c *card.Card) error

Activate shall send an ACTIVATE DF command to the card If the application is currently uninitialized, it will initialize it. If it is initialized, does nothing

func AlgorithmName

func AlgorithmName(alg packet.PublicKeyAlgorithm) string

func ComputeDigitalSignature

func ComputeDigitalSignature(c *card.Card, data []byte) ([]byte, error)

func GeneratePublicKey

func GeneratePublicKey(c *card.Card, k Key, algAttr AlgorithmAttributes) (crypto.PublicKey, error)

GeneratePublicKey generates a new public key on the card

func GetPublicKey

func GetPublicKey(c *card.Card, k Key, algAttr AlgorithmAttributes) (crypto.PublicKey, error)

GetPublicKey retrieves a public key from the card

func Login

func Login(c *card.Card, pinID PinID, pin []byte) error

Login will execute a VERIFY command against the card to verify a PIN

func LoginStatus

func LoginStatus(c *card.Card, pinID PinID) error

LoginStatus will return the PIN verification status for a given PIN Returns nil if authenticated, an error which matches card.PinAttempts if not

func Logout

func Logout(c *card.Card, pinID PinID) error

Logout Clears verification status for a given pin

func NewSigner

func NewSigner(
	card *card.Card,
	pubKey crypto.PublicKey,
	key Key,
	prompt func(c *card.Card) error,
) crypto.Signer

NewSigner creates a signer which is backed by the card

pubKey is the public key of the key that will be used for signing key is the key slot of said key prompt will be called if an authentication required error is returned and may be used to prompt the cardholder for a PIN

func SelectApp

func SelectApp(c *card.Card) error

SelectApp selects the PIV application

func Terminate

func Terminate(c *card.Card) error

Terminate shall send a TERMINATE DF command to the card This will clear all state of the application, if permitted (Permitted if pin blocked)

Types

type AlgorithmAttributes

type AlgorithmAttributes struct {
	Algorithm packet.PublicKeyAlgorithm
	Data      []byte
}

func (AlgorithmAttributes) MarshalBinary

func (a AlgorithmAttributes) MarshalBinary() ([]byte, error)

func (*AlgorithmAttributes) UnmarshalBinary

func (a *AlgorithmAttributes) UnmarshalBinary(buf []byte) error

type ApplicationReferenceData

type ApplicationReferenceData struct {
	ApplicationID            []byte                   `ber:"4f"`
	HistoricalBytes          []byte                   `ber:"5f52"`
	GeneralFeatureManagement GeneralFeatureManagement `ber:"7f74,ber"`
	DiscretionaryDataObjects DiscretionaryDataObjects `ber:"73,ber"`
}

func GetApplicationReferenceData

func GetApplicationReferenceData(c *card.Card) (*ApplicationReferenceData, error)

GetApplicationReferenceData returns the Application Reference Data object

func (ApplicationReferenceData) MarshalBinary

func (ard ApplicationReferenceData) MarshalBinary() ([]byte, error)

func (*ApplicationReferenceData) UnmarshalBinary

func (ard *ApplicationReferenceData) UnmarshalBinary(buf []byte) error

type CapabilityFlags

type CapabilityFlags byte
const (
	Cap_SecureMessaging                 CapabilityFlags = 1 << 7
	Cap_GetChallenge                    CapabilityFlags = 1 << 6
	Cap_KeyImport                       CapabilityFlags = 1 << 5
	Cap_PWStatusChangable               CapabilityFlags = 1 << 4
	Cap_PrivateUseObjects               CapabilityFlags = 1 << 3
	Cap_AlgorithmAttributesChangable    CapabilityFlags = 1 << 2
	Cap_EncryptDecryptAES               CapabilityFlags = 1 << 1
	Cap_KeyDerivationFunctionDataObject CapabilityFlags = 1 << 0
)

func (CapabilityFlags) MarshalJSON

func (flags CapabilityFlags) MarshalJSON() ([]byte, error)

func (CapabilityFlags) String

func (flags CapabilityFlags) String() string

func (CapabilityFlags) ToStringList

func (flags CapabilityFlags) ToStringList() (list []string)

func (*CapabilityFlags) UnmarshalJSON

func (flags *CapabilityFlags) UnmarshalJSON(buf []byte) error

type CardholderRelatedData

type CardholderRelatedData struct {
	Name               string `ber:"5B"`
	LanguagePreference string `ber:"5F2D"`
	Sex                string `ber:"5F35"`
}

Tag 0x65

func (CardholderRelatedData) MarshalBinary

func (d CardholderRelatedData) MarshalBinary() ([]byte, error)

func (*CardholderRelatedData) UnmarshalBinary

func (crd *CardholderRelatedData) UnmarshalBinary(buf []byte) error

type DiscretionaryDataObjects

type DiscretionaryDataObjects struct {
	ExtendedCapabilities   ExtendedCapabilities `ber:"C0,big"`
	SigAlgorithmAttributes AlgorithmAttributes  `ber:"C1"`
	EncAlgorithmAttributes AlgorithmAttributes  `ber:"C2"`
	AutAlgorithmAttributes AlgorithmAttributes  `ber:"C3"`
	PasswordStatus         []byte               `ber:"C4"`
	Fingerprints           KeyFingerprints      `ber:"C5,big"`
	CAFingerprints         KeyFingerprints      `ber:"C6,big"`
	GenerationTimestamps   GenerationTimestamps `ber:"CD,big"`
}

func (*DiscretionaryDataObjects) GetAlgorithmAttributesForKey

func (ddo *DiscretionaryDataObjects) GetAlgorithmAttributesForKey(key Key) AlgorithmAttributes

func (*DiscretionaryDataObjects) GetKeyData

func (ddo *DiscretionaryDataObjects) GetKeyData(key Key) KeyData

type ExtendedCapabilities

type ExtendedCapabilities struct {
	Capabilities                     CapabilityFlags          `json:"capabilities"`
	SecureMessagingAlgorithm         SecureMessagingAlgorithm `json:"secure_messaging_algorithm,omitempty"`
	GetChallengeMaxLen               uint16                   `json:"get_challenge_max_length,omitempty"`
	CardholderCertificateMaxLen      uint16                   `json:"cardholder_certificate_max_length,omitempty"`
	SpecialDOMaxLen                  uint16                   `json:"specal_do_max_length,omitempty"`
	PinBlock2FormatSupported         bool                     `json:"pin_block_2_supported,omitempty"`
	ManageSecurityEnvEncDecSupported bool                     `json:"manage_security_env_enc_dec_supported,omitempty"`
}

type GeneralFeatureManagement

type GeneralFeatureManagement struct {
	UserInteractionFlags []byte `ber:"81"`
}

type GenerationTimestamps

type GenerationTimestamps struct {
	Sig uint32
	Enc uint32
	Aut uint32
}

func (*GenerationTimestamps) GetForKey

func (ts *GenerationTimestamps) GetForKey(key Key) uint32

func (*GenerationTimestamps) SetForKey

func (ts *GenerationTimestamps) SetForKey(key Key, s uint32)

type Key

type Key int

func (Key) GetCreationTimestamp

func (k Key) GetCreationTimestamp(gts GenerationTimestamps) time.Time

func (Key) GetFingerprint

func (k Key) GetFingerprint(fps KeyFingerprints) []byte

func (Key) GetInfo

func (k Key) GetInfo() KeyInfo

type KeyData

type KeyData struct {
	AlgorithmAttributes AlgorithmAttributes
	Fingerprint         []byte
	CAFingerprint       []byte
	GenerationTimestamp uint32
}

type KeyFingerprints

type KeyFingerprints struct {
	Sig [20]byte
	Enc [20]byte
	Aut [20]byte
}

func (*KeyFingerprints) GetForKey

func (fp *KeyFingerprints) GetForKey(key Key) []byte

func (*KeyFingerprints) SetForKey

func (fp *KeyFingerprints) SetForKey(key Key, fpr []byte)

type KeyInfo

type KeyInfo struct {
	Key             Key
	Name            string
	FingerprintID   uint32
	CAFingerprintID uint32
	TimestampID     uint32
}

func GetKeyInfo

func GetKeyInfo(name string) (KeyInfo, error)

type PinID

type PinID byte

PinID identifies one of the three card PINs

const (
	// MainPIN is PW1, used for most authentication purposes
	MainPin PinID = 0x81
	// SigningPin is PW1, used for signing
	SigningPin PinID = 0x82
	// AdminPin is PW3, used for card admin
	AdminPin PinID = 0x83
)

type RSAAttributes

type RSAAttributes struct {
	ModulusLength        uint16
	PublicExponentLength uint16
	ImportFormat         byte
}

type SecureMessagingAlgorithm

type SecureMessagingAlgorithm byte
const (
	SecureMessagingAlgorithm_Undefined SecureMessagingAlgorithm = 0
	SecureMessagingAlgorithm_AES128    SecureMessagingAlgorithm = 1
	SecureMessagingAlgorithm_AES256    SecureMessagingAlgorithm = 2
	SecureMessagingAlgorithm_SCP11b    SecureMessagingAlgorithm = 3
)

func (SecureMessagingAlgorithm) MarshalText

func (sma SecureMessagingAlgorithm) MarshalText() ([]byte, error)

func (SecureMessagingAlgorithm) String

func (sma SecureMessagingAlgorithm) String() string

func (*SecureMessagingAlgorithm) UnmarshalText

func (sma *SecureMessagingAlgorithm) UnmarshalText(str []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL