INJECT PKI KEY

Command Description

The INJECT PKI KEY command is used to personalize/update or clear the PKI keys.

Instance: PIV

Access Condition: PIN or PIV PIN, see VERIFY PIN or PIV VERIFY PIN

Command Message

The following table lists the coding for the INJECT PKI KEY command message.

For an RSA private key, five consecutive INJECT PKI KEY APDUs are used, each containing one of the CRT key components (p, q, dp. dq, coefficient). The p component must be the first component injected, and the coefficient must be the last component injected.

CLA

80h

INS

D8h

P1

Reference Control Parameter P1

P2

Key Reference, see PIV Data Containers

Lc

Data Field Length

Data Field

Key Data, see Coding of the Data Field for INJECT PKI RSA KEY (RSA) and Coding of the Data Field for INJECT PKI EC KEY (EC)

Le

Empty

Coding of the Data Field for INJECT PKI RSA KEY

Length Value Description

01h

00h

RFU

01h

A3h

Algorithm Identifier

01h-02h

  • 0 bytes to remove the corresponding key, in this case the following bytes are absent

  • 81h 82h to inject a new component value

Length of Key Data Value Field (BER-TLV format)

 

02h

81h 80h  to inject a new component value

Length of the real Key Data Value

80h

Key value

Key value

01h

00h

Length of Key check value

Coding of the Data Field for INJECT PKI EC KEY

Length Value Description

01h

00h

RFU

01h

B1h

Algorithm Identifier

01h

  • 0 bytes to remove the corresponding key, in this case the following bytes are absent

  • Xx+1h

Length of Key Data Value Field

 

01h

xxh

Length of the real Key Data Value

xxh

PrivateKeyInfo(1) object, as defined in RFC 5208 Public-Key Cryptography Standards (PKCS) #8: Private-Key Information Syntax Specification Version 1.2

Key Data value

01h

00h

Length of Key check value

(1)

PrivateKeyInfo ::= SEQUENCE {
version		Version,
privateKeyAlgorithm    PrivateKeyAlgorithmIdentifier,
privateKey		PrivateKey,
attributes		[0]  IMPLICIT Attributes OPTIONAL
}

Distributing an EC private key with PKCS#8 [RFC 5208 Public-Key Cryptography Standards (PKCS) #8: Private-Key Information Syntax Specification Version 1.2] involves including:

  1. id-ecPublicKey, id-ecDH, or id-ecMQV (from [RFC 5480]) with the namedCurve as the parameters in the privateKeyAlgorithm field; and

  2. ECPrivateKey in the PrivateKey field, which is an OCTET STRING.

ECPrivateKey ::= SEQUENCE {
     version        INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
     privateKey     OCTET STRING,
     parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
     publicKey  [1] BIT STRING OPTIONAL
}

Example of PrivateKeyInfo (256-bit EC):

SEQUENCE(3 elem)
    INTEGER0
    SEQUENCE(2 elem)
        OBJECT IDENTIFIER 1.2.840.10045.2.1        // key type ecPublicKey
        OBJECT IDENTIFIER 1.2.840.10045.3.1.7    // named Curve prime256v1
OCTET STRING(1 elem)
        SEQUENCE(2 elem)             INTEGER 1    // version             
OCTET STRING    // PrivateKey

Example of Data Field in 256-bit EC case

RFU

00

Algorithm  Identifier

B1

Length of Key Data Value Field

44

Key Data Value field

Length of the real Key Data Value

43

SEQUENCE

30

Length of sequence

41

 

INTEGER

02

Length

01

Value

00

SEQUENCE

Private Key Algorithm   

30

Length

13

 

OBJECT IDENTIFIER

06

Length

07

Value

2A8648CE3D0201 (1.2.840.10045.2.1 ecPublicKey(ANSI X9.62 public key type))

OBJECT IDENTIFIER

06

Length

08

value

2A8648CE3D030107 (1.2.840.10045.3.1.7 prime256v1(ANSI X9.62 named elliptic curve))

 

OCTET STRING

EC Private Key

04

Length

27

 

SEQUENCE

30

Length

25

 

INTEGER

02

Length

01

Value

01 (version)

OCTET STRING

04

Length

20

Value

FEFDDC4167E4D203FAA42864A08FDD7631AB1E47BBE86ACD86789B3F888C89CB (private key)

Key check value

00

Reference Control Parameter P1

The Reference control parameter P1 of the INJECT PKI KEY command message defines the type of the key to be updated and if additional INJECT PKI KEY commands will follow this one (in the case of an RSA key).

P1 definition for INJECT PKI KEY command

b7 b6 b5 b4 b3 b2 b1 b0 Meaning

0

X

X

X

X

X

X

X

Last (or only) command

1

X

X

X

X

X

X

X

More PUT KEY command

X

0

0

0

0

0

0

0

RSA component key

X

0

0

0

0

0

1

1

EC key

Response Message

Data Field Returned in the Response Message

The response message is always empty.

Processing State Returned in the Response Message

The following table lists the processing state returned in the response message.

Status Meaning

6982h

Access condition not satisfied: the PIN has not been authenticated

6A80h

Invalid key length

6A86h

Invalid P1 value

6A88h

Key Reference not found: P2 value is incorrect

9000h

Successful Execution