S3_authorisation.md 18.7 KB
Newer Older
Sophie Wenzel-Teuber's avatar
Sophie Wenzel-Teuber committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
# <a name='deimos-protocol-s3-S3_authorisation' /> public deimos::protocol::s3::S3_authorisation

class to perform an authorisation of an S3 request. 



The implementation of this class follows the guidelines from [https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html](https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html)

 




## Inheritance:
Inherits from [deimos::protocol::Authorisation][deimos-protocol-Authorisation].

## Helper functions
| Name | Description | 
| ---- | ---- |
| [search_for_user](#deimos-protocol-s3-S3_authorisation-search_for_user) | checks whether the user id saved in [m_user_identifier][deimos-protocol-s3-S3_authorisation-m_user_identifier] exists in the user database  |
| [has_signed_payload](#deimos-protocol-s3-S3_authorisation-has_signed_payload) | check if this message has a signed content body  |
| [log](#deimos-protocol-s3-S3_authorisation-log) | log current state of member variables  |


## Extract header information
| Name | Description | 
| ---- | ---- |
| [set_authorisation_info](#deimos-protocol-s3-S3_authorisation-set_authorisation_info) | get the information about authorisation from the header and save it to member variables  |
| [extract_string_part](#deimos-protocol-s3-S3_authorisation-extract_string_part) | Extract information from a string.  |
| [split_signed_headers](#deimos-protocol-s3-S3_authorisation-split_signed_headers) | split up the "SignedHeaders" value of the HTTP request  |
| [split_queries](#deimos-protocol-s3-S3_authorisation-split_queries) | split up the queries string of the HTTP request (thats the part of the request path after '?')  |
| [split_credentials](#deimos-protocol-s3-S3_authorisation-split_credentials) | split up the "Credential" value of the HTTP request  |


## Signature creation
| Name | Description | 
| ---- | ---- |
| [check](#deimos-protocol-s3-S3_authorisation-check) | checks the signature of the message  |
| [create_canonical_request](#deimos-protocol-s3-S3_authorisation-create_canonical_request) | create a canonical request  |
| [create_string_to_sign](#deimos-protocol-s3-S3_authorisation-create_string_to_sign) | create a string to sign  |
| [get_signature](#deimos-protocol-s3-S3_authorisation-get_signature) | create the signature  |


## Private Attributes
| Name | Description | 
| ---- | ---- |
| [m_status](#deimos-protocol-s3-S3_authorisation-m_status) | the current status of the authorisation  |
| [m_user_identifier](#deimos-protocol-s3-S3_authorisation-m_user_identifier) | the public key / identifier of the user that send the request  |
| [m_user_key](#deimos-protocol-s3-S3_authorisation-m_user_key) | the key that belongs to [m_user_identifier][deimos-protocol-s3-S3_authorisation-m_user_identifier]  |
| [m_date](#deimos-protocol-s3-S3_authorisation-m_date) | the date as saved in the credentials of the request  |
| [m_region](#deimos-protocol-s3-S3_authorisation-m_region) | the S3 region as saved in the credentials of the request  |
| [m_signed_headers](#deimos-protocol-s3-S3_authorisation-m_signed_headers) | a (sorted) list of the headers that have been used to sign the request  |
| [m_queries](#deimos-protocol-s3-S3_authorisation-m_queries) | a (sorted) list of all queries split up into key and value  |
| [m_signature](#deimos-protocol-s3-S3_authorisation-m_signature) | the signature stored in the request  |
| [m_payload](#deimos-protocol-s3-S3_authorisation-m_payload) | the payload of the request  |
| [m_error](#deimos-protocol-s3-S3_authorisation-m_error) | the error description if one occurred  |


## Public Functions
| Name | Description | 
| ---- | ---- |
| [authorise](#deimos-protocol-s3-S3_authorisation-authorise) | main method to run the authorisation algorithm  |
| [add_chunk](#deimos-protocol-s3-S3_authorisation-add_chunk) | add a chunk of data to the payload  |
| [is_valid](#deimos-protocol-s3-S3_authorisation-is_valid) | checks if the authorisation was successful  |
| [get_status](#deimos-protocol-s3-S3_authorisation-get_status) | returns the current status of the authorisation  |
| [get_error](#deimos-protocol-s3-S3_authorisation-get_error) | returns the internal error  |



## Helper functions
### <a name='deimos-protocol-s3-S3_authorisation-search_for_user' /> private bool deimos::protocol::s3::S3_authorisation::search_for_user ()

checks whether the user id saved in [m_user_identifier][deimos-protocol-s3-S3_authorisation-m_user_identifier] exists in the user database 




#### Returns: 
| Type | Description | 
| ---- | ---- |
| bool | true if the user has been found, false otherwise |









Sets 
[m_user_key][deimos-protocol-s3-S3_authorisation-m_user_key] on success 




[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-has_signed_payload' /> private bool deimos::protocol::s3::S3_authorisation::has_signed_payload (const S3_header &headers) const

check if this message has a signed content body 




#### Parameters: 
| Type | Name | Description | 
| ---- | ---- | ---- |
| const [S3_header][deimos-protocol-s3-S3_header] & | headers | the headers of the message to check |

#### Returns: 
| Type | Description | 
| ---- | ---- |
| bool | true if the message contains a signed body, false if it doesn't have any body of if it is unsigned  |












#### Qualifiers: 
* const


[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-log' /> private void deimos::protocol::s3::S3_authorisation::log () const

log current state of member variables 








#### Qualifiers: 
* const


[Go to Top](#deimos-protocol-s3-S3_authorisation)

## Extract header information
### <a name='deimos-protocol-s3-S3_authorisation-set_authorisation_info' /> private bool deimos::protocol::s3::S3_authorisation::set_authorisation_info (const S3_header &headers)

get the information about authorisation from the header and save it to member variables 




#### Parameters: 
| Type | Name | Description | 
| ---- | ---- | ---- |
| const [S3_header][deimos-protocol-s3-S3_header] & | headers | the header to extract the information from |

#### Returns: 
| Type | Description | 
| ---- | ---- |
| bool | true if all information was found, false if an error occurred  |












[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-extract_string_part' /> private std::string deimos::protocol::s3::S3_authorisation::extract_string_part (std::string complete, std::string identifier, std::string delimiter) const

Extract information from a string. 




#### Parameters: 
| Type | Name | Description | 
| ---- | ---- | ---- |
| std::string | complete | the complete string will all information  |
| std::string | identifier | the identifier of the specific piece of information required  |
| std::string | delimiter | the delimiter between the parts of information |

#### Returns: 
| Type | Description | 
| ---- | ---- |
| std::string | required information as string |











If there is for example a string of the form "id=info;id2=info2" then ';' is the delimiter, 'id' is the identifier and this function will return "info". 




#### Qualifiers: 
* const


[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-split_signed_headers' /> private void deimos::protocol::s3::S3_authorisation::split_signed_headers (std::string all_signed_headers)

split up the "SignedHeaders" value of the HTTP request 




#### Parameters: 
| Type | Name | Description | 
| ---- | ---- | ---- |
| std::string | all_signed_headers | the value of the SignedHeaders header |








This function saves the headers into 
[m_signed_headers][deimos-protocol-s3-S3_authorisation-m_signed_headers] 




[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-split_queries' /> private void deimos::protocol::s3::S3_authorisation::split_queries (std::string queries)

split up the queries string of the HTTP request (thats the part of the request path after '?') 




#### Parameters: 
| Type | Name | Description | 
| ---- | ---- | ---- |
| std::string | queries | the complete query string |








This function saves each query into 
[m_queries][deimos-protocol-s3-S3_authorisation-m_queries] 




[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-split_credentials' /> private void deimos::protocol::s3::S3_authorisation::split_credentials (std::string credentials)

split up the "Credential" value of the HTTP request 




#### Parameters: 
| Type | Name | Description | 
| ---- | ---- | ---- |
| std::string | credentials | the value of the Credential header |








This function saves the credentials into 
[m_user_identifier][deimos-protocol-s3-S3_authorisation-m_user_identifier], 
[m_date][deimos-protocol-s3-S3_authorisation-m_date] and 
[m_region][deimos-protocol-s3-S3_authorisation-m_region] 




[Go to Top](#deimos-protocol-s3-S3_authorisation)

## Signature creation
### <a name='deimos-protocol-s3-S3_authorisation-check' /> private bool deimos::protocol::s3::S3_authorisation::check (const S3_header &headers) const

checks the signature of the message 




#### Parameters: 
| Type | Name | Description | 
| ---- | ---- | ---- |
| const [S3_header][deimos-protocol-s3-S3_header] & | headers | the headers of the message to check |

#### Returns: 
| Type | Description | 
| ---- | ---- |
| bool | true if the signature was valid, false otherwise |











This function splits the message's contents into the needed parts, creates a signature and compares it with the one saved in the headers 




#### Qualifiers: 
* const


[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-create_canonical_request' /> private std::string deimos::protocol::s3::S3_authorisation::create_canonical_request (const S3_header &headers) const

create a canonical request 




#### Parameters: 
| Type | Name | Description | 
| ---- | ---- | ---- |
| const [S3_header][deimos-protocol-s3-S3_header] & | headers | the headers of the message to create the request from |

#### Returns: 
| Type | Description | 
| ---- | ---- |
| std::string | the canonical request |











For more information what this means, see: 
[https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html](https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html)

 




#### Qualifiers: 
* const


[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-create_string_to_sign' /> private std::string deimos::protocol::s3::S3_authorisation::create_string_to_sign (const S3_header &headers, std::string canonical_request) const

create a string to sign 




#### Parameters: 
| Type | Name | Description | 
| ---- | ---- | ---- |
| const [S3_header][deimos-protocol-s3-S3_header] & | headers | the headers of the message to create the request from  |
| std::string | canonical_request | the canonical request from [create_canonical_request][deimos-protocol-s3-S3_authorisation-create_canonical_request] |

#### Returns: 
| Type | Description | 
| ---- | ---- |
| std::string | the string to sign |











For more information what this means, see: 
[https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html](https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html)

 




#### Qualifiers: 
* const


[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-get_signature' /> private std::string deimos::protocol::s3::S3_authorisation::get_signature (std::string string_to_sign) const

create the signature 




#### Parameters: 
| Type | Name | Description | 
| ---- | ---- | ---- |
| std::string | string_to_sign | the string to sign from [create_string_to_sign][deimos-protocol-s3-S3_authorisation-create_string_to_sign] |

#### Returns: 
| Type | Description | 
| ---- | ---- |
| std::string | the signature |











For more information what this means, see: 
[https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html](https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html)

 




#### Qualifiers: 
* const


[Go to Top](#deimos-protocol-s3-S3_authorisation)

## Private Attributes
### <a name='deimos-protocol-s3-S3_authorisation-m_status' /> private deimos::protocol::s3::S3_authorisation::m_status  = 

the current status of the authorisation 








[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-m_user_identifier' /> private deimos::protocol::s3::S3_authorisation::m_user_identifier 

the public key / identifier of the user that send the request 








[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-m_user_key' /> private deimos::protocol::s3::S3_authorisation::m_user_key 

the key that belongs to [m_user_identifier][deimos-protocol-s3-S3_authorisation-m_user_identifier] 








[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-m_date' /> private deimos::protocol::s3::S3_authorisation::m_date 

the date as saved in the credentials of the request 








[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-m_region' /> private deimos::protocol::s3::S3_authorisation::m_region 

the S3 region as saved in the credentials of the request 








[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-m_signed_headers' /> private deimos::protocol::s3::S3_authorisation::m_signed_headers 

a (sorted) list of the headers that have been used to sign the request 








[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-m_queries' /> private deimos::protocol::s3::S3_authorisation::m_queries 

a (sorted) list of all queries split up into key and value 








[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-m_signature' /> private deimos::protocol::s3::S3_authorisation::m_signature 

the signature stored in the request 








[Go to Top](#deimos-protocol-s3-S3_authorisation)

572
### <a name='deimos-protocol-s3-S3_authorisation-m_payload' /> private deimos::protocol::s3::S3_authorisation::m_payload 
Sophie Wenzel-Teuber's avatar
Sophie Wenzel-Teuber committed
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778

the payload of the request 










This is the whole body since we do not support multiple chunked signatures 




[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-m_error' /> private deimos::protocol::s3::S3_authorisation::m_error  = access_denied

the error description if one occurred 








[Go to Top](#deimos-protocol-s3-S3_authorisation)

## Public Functions
### <a name='deimos-protocol-s3-S3_authorisation-authorise' /> public [Authorisation_status][deimos-protocol-Authorisation_status] deimos::protocol::s3::S3_authorisation::authorise (const Headers &headers) override

main method to run the authorisation algorithm 




#### Parameters: 
| Type | Name | Description | 
| ---- | ---- | ---- |
| const [Headers][deimos-protocol-Headers] & | headers | of the message to authenticate |

#### Returns: 
| Type | Description | 
| ---- | ---- |
| [Authorisation_status][deimos-protocol-Authorisation_status] | new status of the authorisation  |












#### Qualifiers: 
* virtual


[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-add_chunk' /> public void deimos::protocol::s3::S3_authorisation::add_chunk (std::string chunk) override

add a chunk of data to the payload 




#### Parameters: 
| Type | Name | Description | 
| ---- | ---- | ---- |
| std::string | chunk | the string to add |








Since the whole body has to be hashed in order to verify the signature of the message each chunk of data has to be added here in order.

It lies in the responsibily of the implementation of this function to decide if this functionality is used or not. 




#### Qualifiers: 
* virtual


[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-is_valid' /> public bool deimos::protocol::s3::S3_authorisation::is_valid () const override

checks if the authorisation was successful 




#### Returns: 
| Type | Description | 
| ---- | ---- |
| bool | true if it has been valid, false if it hasn't started, it is in progress, or if an error occurred.  |












#### Qualifiers: 
* const
* inline
* virtual


[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-get_status' /> public [Authorisation_status][deimos-protocol-Authorisation_status] deimos::protocol::s3::S3_authorisation::get_status () const override

returns the current status of the authorisation 




#### Returns: 
| Type | Description | 
| ---- | ---- |
| [Authorisation_status][deimos-protocol-Authorisation_status] | the current status of the authorisaton  |












#### Qualifiers: 
* const
* inline
* virtual


[Go to Top](#deimos-protocol-s3-S3_authorisation)

### <a name='deimos-protocol-s3-S3_authorisation-get_error' /> public const [Error_info][deimos-protocol-Error_info] * deimos::protocol::s3::S3_authorisation::get_error () const override

returns the internal error 




#### Returns: 
| Type | Description | 
| ---- | ---- |
| const [Error_info][deimos-protocol-Error_info] * | the error that might have occurred in the process  |












#### Qualifiers: 
* const
* inline
* virtual


[Go to Top](#deimos-protocol-s3-S3_authorisation)

[deimos-protocol-Authorisation]:./../Authorisation.md
[deimos-protocol-Authorisation_status]:./../index.md#deimos-protocol-Authorisation_status
[deimos-protocol-Error_info]:./../Error_info.md
[deimos-protocol-Headers]:./../Headers.md
[deimos-protocol-s3-S3_authorisation-create_canonical_request]:./S3_authorisation.md#deimos-protocol-s3-S3_authorisation-create_canonical_request
[deimos-protocol-s3-S3_authorisation-create_string_to_sign]:./S3_authorisation.md#deimos-protocol-s3-S3_authorisation-create_string_to_sign
[deimos-protocol-s3-S3_authorisation-m_date]:./S3_authorisation.md#deimos-protocol-s3-S3_authorisation-m_date
[deimos-protocol-s3-S3_authorisation-m_queries]:./S3_authorisation.md#deimos-protocol-s3-S3_authorisation-m_queries
[deimos-protocol-s3-S3_authorisation-m_region]:./S3_authorisation.md#deimos-protocol-s3-S3_authorisation-m_region
[deimos-protocol-s3-S3_authorisation-m_signed_headers]:./S3_authorisation.md#deimos-protocol-s3-S3_authorisation-m_signed_headers
[deimos-protocol-s3-S3_authorisation-m_user_identifier]:./S3_authorisation.md#deimos-protocol-s3-S3_authorisation-m_user_identifier
[deimos-protocol-s3-S3_authorisation-m_user_key]:./S3_authorisation.md#deimos-protocol-s3-S3_authorisation-m_user_key
[deimos-protocol-s3-S3_error_info]:./S3_error_info.md
[deimos-protocol-s3-S3_header]:./S3_header.md