AusweisApp2
KeyAgreement.h
gehe zur Dokumentation dieser Datei
1 
7 #pragma once
8 
9 #include "CardConnectionWorker.h"
12 
13 #include <QSharedPointer>
14 
15 namespace governikus
16 {
17 
19 {
20  SUCCESS,
23  FAILED,
25 };
26 
28 {
29  protected:
30  struct CardResult
31  {
32  CardReturnCode mReturnCode = CardReturnCode::UNDEFINED;
33  QByteArray mData = QByteArray();
34  };
35 
36  private:
37  const QSharedPointer<CardConnectionWorker> mCardConnectionWorker;
38  QByteArray mEncryptionKey;
39  QByteArray mMacKey;
40  QByteArray mCarCurr;
41  QByteArray mCarPrev;
42  const QSharedPointer<const PaceInfo> mPaceInfo;
43  KeyDerivationFunction mKeyDerivationFunction;
44 
45 
46  CardResult createTransmitResult(CardReturnCode pReturnCode,
47  const ResponseApdu& pResponseApdu,
48  const QByteArray& pResultData,
49  const char* pLogMessage) const;
50 
57  CardResult determineNonce(const QByteArray& pPin);
58 
65  virtual CardResult determineSharedSecret(const QByteArray& pNonce) = 0;
66 
72  virtual QByteArray getUncompressedTerminalPublicKey() = 0;
73 
78  CardResult transmitGAEncryptedNonce();
79 
85  KeyAgreementStatus performMutualAuthenticate();
86 
87  protected:
88  KeyAgreement(const QSharedPointer<const PaceInfo>& pPaceInfo, const QSharedPointer<CardConnectionWorker>& pCardConnectionWorker);
89 
95  [[nodiscard]] CardResult transmitGAMappingData(const QByteArray& pMappingData) const;
96 
102  CardResult transmitGAEphemeralPublicKey(const QByteArray& pEphemeralPublicKey);
103 
109  GAMutualAuthenticationResponse transmitGAMutualAuthentication(const QByteArray& pMutualAuthenticationData);
110 
111  [[nodiscard]] const QSharedPointer<const PaceInfo>& getPaceInfo() const;
112 
113  public:
120  static QSharedPointer<KeyAgreement> create(const QSharedPointer<const PaceInfo>& pPaceInfo,
121  QSharedPointer<CardConnectionWorker> pCardConnectionWorker);
122 
123  virtual ~KeyAgreement();
124 
130  virtual QByteArray getUncompressedCardPublicKey() = 0;
131 
137  virtual QByteArray getCompressedCardPublicKey() = 0;
138 
144  KeyAgreementStatus perform(const QByteArray& pPin);
145 
151  [[nodiscard]] const QByteArray& getEncryptionKey() const;
152 
158  [[nodiscard]] const QByteArray& getMacKey() const;
159 
164  [[nodiscard]] const QByteArray& getCarCurr() const;
165 
170  [[nodiscard]] const QByteArray& getCarPrev() const;
171 };
172 
173 } // namespace governikus
Definition: GeneralAuthenticateResponse.h:130
Definition: KeyAgreement.h:28
const QByteArray & getEncryptionKey() const
Subsequent to the key agreement an encryption key is determined.
Definition: KeyAgreement.cpp:242
CardResult transmitGAMappingData(const QByteArray &pMappingData) const
Transmit the General Authenticate (Mapping Data) command to the card.
Definition: KeyAgreement.cpp:207
KeyAgreement(const QSharedPointer< const PaceInfo > &pPaceInfo, const QSharedPointer< CardConnectionWorker > &pCardConnectionWorker)
Definition: KeyAgreement.cpp:72
const QByteArray & getCarPrev() const
Subsequent to the key agreement a certificate authority reference (CAR) may be determined.
Definition: KeyAgreement.cpp:254
GAMutualAuthenticationResponse transmitGAMutualAuthentication(const QByteArray &pMutualAuthenticationData)
Transmit the General Authenticate (Mutual Authentication) command to the card.
Definition: KeyAgreement.cpp:221
KeyAgreementStatus perform(const QByteArray &pPin)
Perform the key agreement.
Definition: KeyAgreement.cpp:87
virtual QByteArray getUncompressedCardPublicKey()=0
Returns the uncompressed card's ephemeral public key calculated during key agreement.
const QByteArray & getCarCurr() const
Subsequent to the key agreement a certificate authority reference (CAR) may be determined.
Definition: KeyAgreement.cpp:248
const QByteArray & getMacKey() const
Subsequent to the key agreement a MAC key is determined.
Definition: KeyAgreement.cpp:260
const QSharedPointer< const PaceInfo > & getPaceInfo() const
Definition: KeyAgreement.cpp:236
virtual QByteArray getCompressedCardPublicKey()=0
Returns the compressed card's ephemeral public key calculated during key agreement.
CardResult transmitGAEphemeralPublicKey(const QByteArray &pEphemeralPublicKey)
Transmit the General Authenticate (Ephemeral Public Key) command to the card.
Definition: KeyAgreement.cpp:194
static QSharedPointer< KeyAgreement > create(const QSharedPointer< const PaceInfo > &pPaceInfo, QSharedPointer< CardConnectionWorker > pCardConnectionWorker)
Factory method to create an instance of KeyAgreement.
Definition: KeyAgreement.cpp:57
Definition: KeyDerivationFunction.h:18
Implementation of GeneralAuthenticate response APDUs.
Definition: CommandApdu.h:16
KeyAgreementStatus
Definition: KeyAgreement.h:19
Definition: KeyAgreement.h:31
QByteArray mData
Definition: KeyAgreement.h:33
CardReturnCode mReturnCode
Definition: KeyAgreement.h:32