AusweisApp2
AuthContext.h
gehe zur Dokumentation dieser Datei
1 
7 #pragma once
8 
9 #include "ActivationContext.h"
10 #include "NetworkManager.h"
11 #include "TcToken.h"
12 #include "UrlUtil.h"
13 #include "asn1/CVCertificate.h"
20 #include "paos/invoke/StartPaos.h"
27 #include "paos/retrieve/Transmit.h"
28 
29 #include <QDebug>
30 #include <QPointer>
31 #include <QSharedPointer>
32 #include <QSslCertificate>
33 #include <QUrl>
34 
35 class test_StateRedirectBrowser;
36 class test_StatePreVerification;
37 class test_StateCertificateDescriptionCheck;
38 
39 namespace governikus
40 {
41 class TestAuthContext;
42 
44  : public WorkflowContext
45 {
46  Q_OBJECT
47  friend class ::test_StateRedirectBrowser;
48  friend class ::test_StatePreVerification;
49  friend class ::test_StateProcessCertificatesFromEac2;
50  friend class ::test_StateCertificateDescriptionCheck;
51  friend class TestAuthContext;
52 
53  private:
54  bool mTcTokenNotFound;
55  bool mErrorReportedToServer;
56  bool mSkipRedirect;
57  bool mShowChangePinView;
58 
59  QSharedPointer<ActivationContext> mActivationContext;
60  QUrl mTcTokenUrl;
61  QSharedPointer<const TcToken> mTcToken;
62  QUrl mRefreshUrl;
63  QString mReceivedMessageId;
64  QSharedPointer<StartPaos> mStartPaos;
65  QSharedPointer<InitializeFramework> mInitializeFramework;
66  QSharedPointer<InitializeFrameworkResponse> mInitializeFrameworkResponse;
67  QSharedPointer<DIDAuthenticateEAC1> mDIDAuthenticateEAC1;
68  QSharedPointer<DIDAuthenticateResponseEAC1> mDIDAuthenticateResponseEAC1;
69  QSharedPointer<DIDAuthenticateEAC2> mDIDAuthenticateEAC2;
70  QSharedPointer<DIDAuthenticateResponseEAC2> mDIDAuthenticateResponseEACAdditionalInputType;
71  QSharedPointer<DIDAuthenticateEACAdditional> mDIDAuthenticateEACAdditionalInputType;
72  QSharedPointer<DIDAuthenticateResponseEAC2> mDIDAuthenticateResponseEAC2;
73  QSharedPointer<Transmit> mTransmit;
74  QSharedPointer<TransmitResponse> mTransmitResponse;
75  QSharedPointer<StartPaosResponse> mStartPaosResponse;
76  QSharedPointer<AccessRightManager> mAccessRightManager;
77  QMultiMap<QUrl, QSslCertificate> mCertificates;
78  QSharedPointer<const CVCertificate> mDvCvc;
79  CVCertificateChainBuilder mCvcChainBuilderProd;
80  CVCertificateChainBuilder mCvcChainBuilderTest;
81  QByteArray mSslSession;
82 
83  Q_SIGNALS:
86  void fireAccessRightManagerCreated(QSharedPointer<AccessRightManager> pAccessRightManager);
87 
88  protected:
89  explicit AuthContext(const Action pAction, const QSharedPointer<ActivationContext>& pActivationContext);
90 
91  public:
92  explicit AuthContext(const QSharedPointer<ActivationContext>& pActivationContext);
93 
94  [[nodiscard]] bool isErrorReportedToServer() const
95  {
96  return mErrorReportedToServer;
97  }
98 
99 
100  void setErrorReportedToServer(bool pErrorReportedToServer)
101  {
102  mErrorReportedToServer = pErrorReportedToServer;
103  }
104 
105 
106  [[nodiscard]] bool showChangePinView() const
107  {
108  return mShowChangePinView;
109  }
110 
111 
112  void requestChangePinView();
113 
114 
115  [[nodiscard]] bool isTcTokenNotFound() const
116  {
117  return mTcTokenNotFound;
118  }
119 
120 
121  void setTcTokenNotFound(bool pTcTokenNotFound)
122  {
123  mTcTokenNotFound = pTcTokenNotFound;
124  }
125 
126 
127  [[nodiscard]] QVector<AcceptedEidType> getAcceptedEidTypes() const override
128  {
129 
130  if (isCanAllowedMode() || !mDIDAuthenticateEAC1)
131  {
132  return {AcceptedEidType::CARD_CERTIFIED};
133  }
134 
135  return mDIDAuthenticateEAC1->getAcceptedEidTypes();
136  }
137 
138 
139  [[nodiscard]] bool isSkipRedirect() const
140  {
141  return mSkipRedirect;
142  }
143 
144 
145  void setSkipRedirect(bool pSkipRedirect)
146  {
147  mSkipRedirect = pSkipRedirect;
148  }
149 
150 
151  [[nodiscard]] QList<QSslCertificate> getCertificateList() const
152  {
153  return mCertificates.values();
154  }
155 
156 
157  void addCertificateData(const QUrl& pUrl, const QSslCertificate& pCert)
158  {
159  QUrl originUrl = UrlUtil::getUrlOrigin(pUrl);
160  qDebug() << "Adding certificate CN=" << pCert.subjectInfo(QSslCertificate::CommonName) << "SN=" << pCert.serialNumber() << "for URL origin" << originUrl;
161  mCertificates.insert(originUrl, pCert);
162  }
163 
164 
166  {
167  return mActivationContext.data();
168  }
169 
170 
171  [[nodiscard]] const QUrl& getTcTokenUrl() const
172  {
173  return mTcTokenUrl;
174  }
175 
176 
177  void setTcTokenUrl(const QUrl& pTcTokenUrl)
178  {
179  mTcTokenUrl = pTcTokenUrl;
180  }
181 
182 
183  [[nodiscard]] const QSharedPointer<const TcToken>& getTcToken() const
184  {
185  return mTcToken;
186  }
187 
188 
189  void setTcToken(const QSharedPointer<const TcToken>& pTcToken)
190  {
191  mTcToken = pTcToken;
192  }
193 
194 
195  [[nodiscard]] const QString& getReceivedMessageId() const
196  {
197  return mReceivedMessageId;
198  }
199 
200 
201  void setReceivedMessageId(const QString& pReceivedMessageId)
202  {
203  mReceivedMessageId = pReceivedMessageId;
204  }
205 
206 
207  [[nodiscard]] const QUrl& getRefreshUrl() const
208  {
209  return mRefreshUrl;
210  }
211 
212 
213  void setRefreshUrl(const QUrl& pRefreshUrl)
214  {
215  mRefreshUrl = pRefreshUrl;
216  }
217 
218 
219  [[nodiscard]] const QSharedPointer<DIDAuthenticateEAC1>& getDidAuthenticateEac1() const
220  {
221  return mDIDAuthenticateEAC1;
222  }
223 
224 
225  void setDidAuthenticateEac1(const QSharedPointer<DIDAuthenticateEAC1>& pDIDAuthenticateEAC1)
226  {
227  mDIDAuthenticateEAC1 = pDIDAuthenticateEAC1;
229  Q_EMIT fireIsSmartCardAllowedChanged();
230  }
231 
232 
233  [[nodiscard]] const QSharedPointer<DIDAuthenticateEAC2>& getDidAuthenticateEac2() const
234  {
235  return mDIDAuthenticateEAC2;
236  }
237 
238 
239  void setDidAuthenticateEac2(const QSharedPointer<DIDAuthenticateEAC2>& pDidAuthenticateEac2)
240  {
241  mDIDAuthenticateEAC2 = pDidAuthenticateEac2;
242  }
243 
244 
245  [[nodiscard]] const QSharedPointer<DIDAuthenticateResponseEAC1>& getDidAuthenticateResponseEac1() const
246  {
247  return mDIDAuthenticateResponseEAC1;
248  }
249 
250 
251  void setDidAuthenticateResponseEac1(const QSharedPointer<DIDAuthenticateResponseEAC1>& pDidAuthenticateResponseEac1)
252  {
253  mDIDAuthenticateResponseEAC1 = pDidAuthenticateResponseEac1;
254  }
255 
256 
257  [[nodiscard]] const QSharedPointer<DIDAuthenticateResponseEAC2>& getDidAuthenticateResponseEacAdditionalInputType() const
258  {
259  return mDIDAuthenticateResponseEACAdditionalInputType;
260  }
261 
262 
263  void setDidAuthenticateResponseEacAdditionalInputType(const QSharedPointer<DIDAuthenticateResponseEAC2>& pDidAuthenticateResponseEacAdditionalInputType)
264  {
265  mDIDAuthenticateResponseEACAdditionalInputType = pDidAuthenticateResponseEacAdditionalInputType;
266  }
267 
268 
269  [[nodiscard]] const QSharedPointer<DIDAuthenticateEACAdditional>& getDidAuthenticateEacAdditional() const
270  {
271  return mDIDAuthenticateEACAdditionalInputType;
272  }
273 
274 
275  void setDidAuthenticateEacAdditional(const QSharedPointer<DIDAuthenticateEACAdditional>& pDidAuthenticateEacAdditionalInputType)
276  {
277  mDIDAuthenticateEACAdditionalInputType = pDidAuthenticateEacAdditionalInputType;
278  }
279 
280 
281  [[nodiscard]] const QSharedPointer<DIDAuthenticateResponseEAC2>& getDidAuthenticateResponseEac2() const
282  {
283  return mDIDAuthenticateResponseEAC2;
284  }
285 
286 
287  void setDidAuthenticateResponseEac2(const QSharedPointer<DIDAuthenticateResponseEAC2>& pDidAuthenticateResponseEac2)
288  {
289  mDIDAuthenticateResponseEAC2 = pDidAuthenticateResponseEac2;
290  }
291 
292 
293  [[nodiscard]] const QSharedPointer<InitializeFramework>& getInitializeFramework() const
294  {
295  return mInitializeFramework;
296  }
297 
298 
299  void setInitializeFramework(const QSharedPointer<InitializeFramework>& pInitializeFramework)
300  {
301  mInitializeFramework = pInitializeFramework;
302  }
303 
304 
305  [[nodiscard]] const QSharedPointer<InitializeFrameworkResponse>& getInitializeFrameworkResponse() const
306  {
307  return mInitializeFrameworkResponse;
308  }
309 
310 
311  void setInitializeFrameworkResponse(const QSharedPointer<InitializeFrameworkResponse>& pInitializeFrameworkResponse)
312  {
313  mInitializeFrameworkResponse = pInitializeFrameworkResponse;
314  }
315 
316 
317  [[nodiscard]] const QSharedPointer<StartPaosResponse>& getStartPaosResponse() const
318  {
319  return mStartPaosResponse;
320  }
321 
322 
323  void setStartPaosResponse(const QSharedPointer<StartPaosResponse>& pStartPaosResponse)
324  {
325  mStartPaosResponse = pStartPaosResponse;
326  }
327 
328 
329  [[nodiscard]] const QSharedPointer<TransmitResponse>& getTransmitResponse()
330  {
331  return mTransmitResponse;
332  }
333 
334 
335  void setTransmitResponse(const QSharedPointer<TransmitResponse>& pTransmitResponse)
336  {
337  Q_ASSERT(!pTransmitResponse.isNull());
338  mTransmitResponse = pTransmitResponse;
339  }
340 
341 
342  [[nodiscard]] const QSharedPointer<Transmit>& getTransmit()
343  {
344  return mTransmit;
345  }
346 
347 
348  void setTransmit(const QSharedPointer<Transmit>& pTransmit)
349  {
350  Q_ASSERT(!pTransmit.isNull());
351  mTransmit = pTransmit;
352  }
353 
354 
355  [[nodiscard]] QSharedPointer<AccessRightManager> getAccessRightManager() const
356  {
357  return mAccessRightManager;
358  }
359 
360 
361  [[nodiscard]] QByteArray encodeEffectiveChat();
362 
363 
364  [[nodiscard]] const QSharedPointer<StartPaos>& getStartPaos() const
365  {
366  return mStartPaos;
367  }
368 
369 
370  void setStartPaos(const QSharedPointer<StartPaos>& pStartPaos)
371  {
372  mStartPaos = pStartPaos;
373  }
374 
375 
376  [[nodiscard]] CVCertificateChain getChainStartingWith(const QSharedPointer<const CVCertificate>& pChainRoot) const;
377 
378 
379  [[nodiscard]] bool hasChainForCertificationAuthority(const EstablishPaceChannelOutput& pPaceOutput) const;
380 
381 
383 
384 
385  void initCvcChainBuilder(const QVector<QSharedPointer<const CVCertificate>>& pAdditionalCertificates = QVector<QSharedPointer<const CVCertificate>>());
386 
387 
388  [[nodiscard]] const QSharedPointer<const CVCertificate>& getDvCvc() const
389  {
390  return mDvCvc;
391  }
392 
393 
394  void setDvCvc(const QSharedPointer<const CVCertificate>& dvCvc)
395  {
396  mDvCvc = dvCvc;
397  }
398 
399 
400  void initAccessRightManager(const QSharedPointer<const CVCertificate>& pTerminalCvc);
401  [[nodiscard]] bool isCanAllowedMode() const override;
402 
403  [[nodiscard]] const QByteArray& getSslSession() const;
404  void setSslSession(const QByteArray& pSession);
405 };
406 
407 } // namespace governikus
Definition: ActivationContext.h:19
Definition: AuthContext.h:45
bool isSkipRedirect() const
Definition: AuthContext.h:139
const QSharedPointer< DIDAuthenticateEACAdditional > & getDidAuthenticateEacAdditional() const
Definition: AuthContext.h:269
AuthContext(const Action pAction, const QSharedPointer< ActivationContext > &pActivationContext)
Definition: AuthContext.cpp:16
const QSharedPointer< StartPaos > & getStartPaos() const
Definition: AuthContext.h:364
friend class TestAuthContext
Definition: AuthContext.h:51
bool isTcTokenNotFound() const
Definition: AuthContext.h:115
const QSharedPointer< InitializeFrameworkResponse > & getInitializeFrameworkResponse() const
Definition: AuthContext.h:305
QVector< AcceptedEidType > getAcceptedEidTypes() const override
Definition: AuthContext.h:127
const QSharedPointer< DIDAuthenticateEAC2 > & getDidAuthenticateEac2() const
Definition: AuthContext.h:233
void initCvcChainBuilder(const QVector< QSharedPointer< const CVCertificate >> &pAdditionalCertificates=QVector< QSharedPointer< const CVCertificate >>())
Definition: AuthContext.cpp:144
const QSharedPointer< const CVCertificate > & getDvCvc() const
Definition: AuthContext.h:388
void setTcTokenNotFound(bool pTcTokenNotFound)
Definition: AuthContext.h:121
void setTransmitResponse(const QSharedPointer< TransmitResponse > &pTransmitResponse)
Definition: AuthContext.h:335
ActivationContext * getActivationContext() const
Definition: AuthContext.h:165
void addCertificateData(const QUrl &pUrl, const QSslCertificate &pCert)
Definition: AuthContext.h:157
const QSharedPointer< DIDAuthenticateResponseEAC2 > & getDidAuthenticateResponseEac2() const
Definition: AuthContext.h:281
void setReceivedMessageId(const QString &pReceivedMessageId)
Definition: AuthContext.h:201
const QByteArray & getSslSession() const
Definition: AuthContext.cpp:83
void setTcToken(const QSharedPointer< const TcToken > &pTcToken)
Definition: AuthContext.h:189
void fireAccessRightManagerCreated(QSharedPointer< AccessRightManager > pAccessRightManager)
void setDidAuthenticateEacAdditional(const QSharedPointer< DIDAuthenticateEACAdditional > &pDidAuthenticateEacAdditionalInputType)
Definition: AuthContext.h:275
void setTcTokenUrl(const QUrl &pTcTokenUrl)
Definition: AuthContext.h:177
void setSkipRedirect(bool pSkipRedirect)
Definition: AuthContext.h:145
void setDidAuthenticateEac1(const QSharedPointer< DIDAuthenticateEAC1 > &pDIDAuthenticateEAC1)
Definition: AuthContext.h:225
void setErrorReportedToServer(bool pErrorReportedToServer)
Definition: AuthContext.h:100
const QSharedPointer< DIDAuthenticateResponseEAC2 > & getDidAuthenticateResponseEacAdditionalInputType() const
Definition: AuthContext.h:257
bool isCanAllowedMode() const override
Definition: AuthContext.cpp:77
QSharedPointer< AccessRightManager > getAccessRightManager() const
Definition: AuthContext.h:355
const QSharedPointer< Transmit > & getTransmit()
Definition: AuthContext.h:342
const QUrl & getTcTokenUrl() const
Definition: AuthContext.h:171
QList< QSslCertificate > getCertificateList() const
Definition: AuthContext.h:151
void setRefreshUrl(const QUrl &pRefreshUrl)
Definition: AuthContext.h:213
bool isErrorReportedToServer() const
Definition: AuthContext.h:94
QByteArray encodeEffectiveChat()
Definition: AuthContext.cpp:95
const QSharedPointer< TransmitResponse > & getTransmitResponse()
Definition: AuthContext.h:329
void setSslSession(const QByteArray &pSession)
Definition: AuthContext.cpp:89
void setStartPaos(const QSharedPointer< StartPaos > &pStartPaos)
Definition: AuthContext.h:370
const QSharedPointer< const TcToken > & getTcToken() const
Definition: AuthContext.h:183
const QSharedPointer< StartPaosResponse > & getStartPaosResponse() const
Definition: AuthContext.h:317
bool showChangePinView() const
Definition: AuthContext.h:106
void setDidAuthenticateEac2(const QSharedPointer< DIDAuthenticateEAC2 > &pDidAuthenticateEac2)
Definition: AuthContext.h:239
void setDvCvc(const QSharedPointer< const CVCertificate > &dvCvc)
Definition: AuthContext.h:394
const QSharedPointer< InitializeFramework > & getInitializeFramework() const
Definition: AuthContext.h:293
bool hasChainForCertificationAuthority(const EstablishPaceChannelOutput &pPaceOutput) const
Definition: AuthContext.cpp:126
void setInitializeFramework(const QSharedPointer< InitializeFramework > &pInitializeFramework)
Definition: AuthContext.h:299
CVCertificateChain getChainForCertificationAuthority(const EstablishPaceChannelOutput &pPaceOutput) const
Definition: AuthContext.cpp:132
void setDidAuthenticateResponseEac1(const QSharedPointer< DIDAuthenticateResponseEAC1 > &pDidAuthenticateResponseEac1)
Definition: AuthContext.h:251
void fireDidAuthenticateEac1Changed()
const QUrl & getRefreshUrl() const
Definition: AuthContext.h:207
const QSharedPointer< DIDAuthenticateEAC1 > & getDidAuthenticateEac1() const
Definition: AuthContext.h:219
void requestChangePinView()
Definition: AuthContext.cpp:55
const QSharedPointer< DIDAuthenticateResponseEAC1 > & getDidAuthenticateResponseEac1() const
Definition: AuthContext.h:245
void setInitializeFrameworkResponse(const QSharedPointer< InitializeFrameworkResponse > &pInitializeFrameworkResponse)
Definition: AuthContext.h:311
CVCertificateChain getChainStartingWith(const QSharedPointer< const CVCertificate > &pChainRoot) const
Definition: AuthContext.cpp:106
void setDidAuthenticateResponseEac2(const QSharedPointer< DIDAuthenticateResponseEAC2 > &pDidAuthenticateResponseEac2)
Definition: AuthContext.h:287
void initAccessRightManager(const QSharedPointer< const CVCertificate > &pTerminalCvc)
Definition: AuthContext.cpp:68
const QString & getReceivedMessageId() const
Definition: AuthContext.h:195
void setTransmit(const QSharedPointer< Transmit > &pTransmit)
Definition: AuthContext.h:348
void setDidAuthenticateResponseEacAdditionalInputType(const QSharedPointer< DIDAuthenticateResponseEAC2 > &pDidAuthenticateResponseEacAdditionalInputType)
Definition: AuthContext.h:263
void setStartPaosResponse(const QSharedPointer< StartPaosResponse > &pStartPaosResponse)
Definition: AuthContext.h:323
Definition: CVCertificateChainBuilder.h:20
Definition: CVCertificateChain.h:22
Definition: EstablishPaceChannelOutput.h:48
static QUrl getUrlOrigin(const QUrl &pUrl)
Determines the URL origin, i.e.
Definition: UrlUtil.cpp:19
A simple template renderer.
Definition: ActivationContext.h:15