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
572
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
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
|
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <future>
#include <memory>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>
#include <boost/optional.hpp>
#include <boost/serialization/optional.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/unordered_map.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/weak_ptr.hpp>
#include <httplib.h>
#include "common/thread.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/shared_memory.h"
#include "core/hle/service/service.h"
namespace Core {
class System;
}
namespace IPC {
class RequestParser;
}
namespace Service::HTTP {
enum class RequestMethod : u8 {
None = 0x0,
Get = 0x1,
Post = 0x2,
Head = 0x3,
Put = 0x4,
Delete = 0x5,
PostEmpty = 0x6,
PutEmpty = 0x7,
};
/// The number of request methods, any valid method must be less than this.
constexpr u32 TotalRequestMethods = 8;
enum class RequestState : u8 {
NotStarted = 0x1, // Request has not started yet.
ConnectingToServer = 0x5, // Request in progress, connecting to server.
SendingRequest = 0x6, // Request in progress, sending HTTP request.
ReceivingResponse = 0x7, // Request in progress, receiving HTTP response.
ReadyToDownloadContent = 0x8, // Ready to download the content.
TimedOut = 0xA, // Request timed out?
};
enum class PostDataEncoding : u8 {
Auto = 0x0,
AsciiForm = 0x1,
MultipartForm = 0x2,
};
enum class PostDataType : u8 {
AsciiForm = 0x0,
MultipartForm = 0x1,
Raw = 0x2,
};
enum class ClientCertID : u32 {
Default = 0x40, // Default client cert
};
struct URLInfo {
bool is_https;
std::string host;
int port;
std::string path;
};
/// Represents a client certificate along with its private key, stored as a byte array of DER data.
/// There can only be at most one client certificate context attached to an HTTP context at any
/// given time.
struct ClientCertContext {
using Handle = u32;
Handle handle;
u32 session_id;
u8 cert_id;
std::vector<u8> certificate;
std::vector<u8> private_key;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& handle;
ar& session_id;
ar& cert_id;
ar& certificate;
ar& private_key;
}
friend class boost::serialization::access;
};
/// Represents a root certificate chain, it contains a list of DER-encoded certificates for
/// verifying HTTP requests. An HTTP context can have at most one root certificate chain attached to
/// it, but the chain may contain an arbitrary number of certificates in it.
struct RootCertChain {
struct RootCACert {
using Handle = u32;
Handle handle;
u32 session_id;
std::vector<u8> certificate;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& handle;
ar& session_id;
ar& certificate;
}
friend class boost::serialization::access;
};
using Handle = u32;
Handle handle;
u32 session_id;
std::vector<RootCACert> certificates;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& handle;
ar& session_id;
ar& certificates;
}
friend class boost::serialization::access;
};
struct ClCertAData {
std::vector<u8> certificate;
std::vector<u8> private_key;
bool init = false;
};
/// Represents an HTTP context.
class Context final {
public:
using Handle = u32;
Context() = default;
Context(const Context&) = delete;
Context& operator=(const Context&) = delete;
struct Proxy {
std::string url;
std::string username;
std::string password;
u16 port;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& url;
ar& username;
ar& password;
ar& port;
}
friend class boost::serialization::access;
};
struct BasicAuth {
std::string username;
std::string password;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& username;
ar& password;
}
friend class boost::serialization::access;
};
struct RequestHeader {
RequestHeader(std::string name, std::string value) : name(name), value(value){};
std::string name;
std::string value;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& name;
ar& value;
}
friend class boost::serialization::access;
};
struct SSLConfig {
u32 options;
std::weak_ptr<ClientCertContext> client_cert_ctx;
std::weak_ptr<RootCertChain> root_ca_chain;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& options;
ar& client_cert_ctx;
ar& root_ca_chain;
}
friend class boost::serialization::access;
};
struct Param {
Param(const std::vector<u8>& value)
: name(value.begin(), value.end()), value(value.begin(), value.end()){};
Param(const std::string& name, const std::string& value) : name(name), value(value){};
Param(const std::string& name, const std::vector<u8>& value)
: name(name), value(value.begin(), value.end()), is_binary(true){};
std::string name;
std::string value;
bool is_binary = false;
httplib::MultipartFormData ToMultipartForm() const {
httplib::MultipartFormData form;
form.name = name;
form.content = value;
if (is_binary) {
form.content_type = "application/octet-stream";
// TODO(DaniElectra): httplib doesn't support setting Content-Transfer-Encoding,
// while the 3DS sets Content-Transfer-Encoding: binary if a binary value is set
}
return form;
}
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& name;
ar& value;
ar& is_binary;
}
friend class boost::serialization::access;
};
using Params = std::multimap<std::string, Param>;
Handle handle;
u32 session_id;
std::string url;
RequestMethod method;
std::atomic<RequestState> state = RequestState::NotStarted;
std::optional<Proxy> proxy;
std::optional<BasicAuth> basic_auth;
SSLConfig ssl_config{};
u32 socket_buffer_size;
std::vector<RequestHeader> headers;
const ClCertAData* clcert_data;
Params post_data;
std::string post_data_raw;
PostDataEncoding post_data_encoding = PostDataEncoding::Auto;
PostDataType post_data_type;
std::string multipart_boundary;
bool force_multipart = false;
bool chunked_request = false;
u32 chunked_content_length;
std::future<void> request_future;
std::atomic<u64> current_download_size_bytes;
std::atomic<u64> total_download_size_bytes;
std::size_t current_copied_data;
bool uses_default_client_cert{};
httplib::Response response;
Common::Event finish_post_data;
void ParseAsciiPostData();
std::string ParseMultipartFormData();
void MakeRequest();
void MakeRequestNonSSL(httplib::Request& request, const URLInfo& url_info,
std::vector<Context::RequestHeader>& pending_headers);
void MakeRequestSSL(httplib::Request& request, const URLInfo& url_info,
std::vector<Context::RequestHeader>& pending_headers);
bool ContentProvider(size_t offset, size_t length, httplib::DataSink& sink);
bool ChunkedContentProvider(size_t offset, httplib::DataSink& sink);
std::size_t HandleHeaderWrite(std::vector<Context::RequestHeader>& pending_headers,
httplib::Stream& strm, httplib::Headers& httplib_headers);
};
struct SessionData : public Kernel::SessionRequestHandler::SessionDataBase {
/// The HTTP context that is currently bound to this session, this can be empty if no context
/// has been bound. Certain commands can only be called on a session with a bound context.
boost::optional<Context::Handle> current_http_context;
u32 session_id;
/// Number of HTTP contexts that are currently opened in this session.
u32 num_http_contexts = 0;
/// Number of ClientCert contexts that are currently opened in this session.
u32 num_client_certs = 0;
/// Whether this session has been initialized in some way, be it via Initialize or
/// InitializeConnectionSession.
bool initialized = false;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler::SessionDataBase>(
*this);
ar& current_http_context;
ar& session_id;
ar& num_http_contexts;
ar& num_client_certs;
ar& initialized;
}
friend class boost::serialization::access;
};
class HTTP_C final : public ServiceFramework<HTTP_C, SessionData> {
public:
HTTP_C();
const ClCertAData& GetClCertA() const {
return ClCertA;
}
private:
/**
* HTTP_C::Initialize service function
* Inputs:
* 1 : POST buffer size
* 2 : 0x20
* 3 : 0x0 (Filled with process ID by ARM11 Kernel)
* 4 : 0x0
* 5 : POST buffer memory block handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void Initialize(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::CreateContext service function
* Inputs:
* 1 : URL buffer size, including null-terminator
* 2 : RequestMethod
* 3 : (URLSize << 4) | 10
* 4 : URL data pointer
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : HTTP context handle
*/
void CreateContext(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::CreateContext service function
* Inputs:
* 1 : Context handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void CloseContext(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::CancelConnection service function
* Inputs:
* 1 : Context handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void CancelConnection(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::GetRequestState service function
* Inputs:
* 1 : Context handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Request state
*/
void GetRequestState(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::GetDownloadSizeState service function
* Inputs:
* 1 : Context handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Total content data downloaded so far
* 3 : Total content size from the "Content-Length" response header
*/
void GetDownloadSizeState(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::InitializeConnectionSession service function
* Inputs:
* 1 : HTTP context handle
* 2 : 0x20, processID translate-header for the ARM11-kernel
* 3 : processID set by the ARM11-kernel
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void InitializeConnectionSession(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::BeginRequest service function
* Inputs:
* 1 : Context handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void BeginRequest(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::BeginRequestAsync service function
* Inputs:
* 1 : Context handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void BeginRequestAsync(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::SetProxyDefault service function
* Inputs:
* 1 : Context handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SetProxyDefault(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::ReceiveData service function
* Inputs:
* 1 : Context handle
* 2 : Buffer size
* 3 : (OutSize<<4) | 12
* 4 : Output data pointer
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void ReceiveData(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::ReceiveDataTimeout service function
* Inputs:
* 1 : Context handle
* 2 : Buffer size
* 3-4 : u64 nanoseconds delay
* 5 : (OutSize<<4) | 12
* 6 : Output data pointer
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void ReceiveDataTimeout(Kernel::HLERequestContext& ctx);
/**
* ReceiveDataImpl:
* Implements ReceiveData and ReceiveDataTimeout service functions
*/
void ReceiveDataImpl(Kernel::HLERequestContext& ctx, bool timeout);
/**
* HTTP_C::AddRequestHeader service function
* Inputs:
* 1 : Context handle
* 2 : Header name buffer size, including null-terminator.
* 3 : Header value buffer size, including null-terminator.
* 4 : (HeaderNameSize<<14) | 0xC02
* 5 : Header name data pointer
* 6 : (HeaderValueSize<<4) | 10
* 7 : Header value data pointer
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void AddRequestHeader(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::AddPostDataAscii service function
* Inputs:
* 1 : Context handle
* 2 : Form name buffer size, including null-terminator.
* 3 : Form value buffer size, including null-terminator.
* 4 : (FormNameSize<<14) | 0xC02
* 5 : Form name data pointer
* 6 : (FormValueSize<<4) | 10
* 7 : Form value data pointer
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void AddPostDataAscii(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::AddPostDataBinary service function
* Inputs:
* 1 : Context handle
* 2 : Form name buffer size, including null-terminator.
* 3 : Form value buffer size
* 4 : (FormNameSize<<14) | 0xC02
* 5 : Form name data pointer
* 6 : (FormValueSize<<4) | 10
* 7 : Form value data pointer
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void AddPostDataBinary(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::AddPostDataRaw service function
* Inputs:
* 1 : Context handle
* 2 : Post data length
* 3-4: (Mapped buffer) Post data
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2-3: (Mapped buffer) Post data
*/
void AddPostDataRaw(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::SetPostDataType service function
* Inputs:
* 1 : Context handle
* 2 : Post data type
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SetPostDataType(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::SendPostDataAscii service function
* Inputs:
* 1 : Context handle
* 2 : Form name buffer size, including null-terminator.
* 3 : Form value buffer size, including null-terminator.
* 4 : (FormNameSize<<14) | 0xC02
* 5 : Form name data pointer
* 6 : (FormValueSize<<4) | 10
* 7 : Form value data pointer
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SendPostDataAscii(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::SendPostDataAsciiTimeout service function
* Inputs:
* 1 : Context handle
* 2 : Form name buffer size, including null-terminator.
* 3 : Form value buffer size, including null-terminator.
* 4-5 : u64 nanoseconds delay
* 6 : (FormNameSize<<14) | 0xC02
* 7 : Form name data pointer
* 8 : (FormValueSize<<4) | 10
* 9 : Form value data pointer
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SendPostDataAsciiTimeout(Kernel::HLERequestContext& ctx);
/**
* SendPostDataAsciiImpl:
* Implements SendPostDataAscii and SendPostDataAsciiTimeout service functions
*/
void SendPostDataAsciiImpl(Kernel::HLERequestContext& ctx, bool timeout);
/**
* HTTP_C::SendPostDataBinary service function
* Inputs:
* 1 : Context handle
* 2 : Form name buffer size, including null-terminator.
* 3 : Form value buffer size
* 4 : (FormNameSize<<14) | 0xC02
* 5 : Form name data pointer
* 6 : (FormValueSize<<4) | 10
* 7 : Form value data pointer
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SendPostDataBinary(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::SendPostDataBinaryTimeout service function
* Inputs:
* 1 : Context handle
* 2 : Form name buffer size, including null-terminator.
* 3 : Form value buffer size
* 4-5 : u64 nanoseconds delay
* 6 : (FormNameSize<<14) | 0xC02
* 7 : Form name data pointer
* 8 : (FormValueSize<<4) | 10
* 9 : Form value data pointer
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SendPostDataBinaryTimeout(Kernel::HLERequestContext& ctx);
/**
* SendPostDataBinaryImpl:
* Implements SendPostDataBinary and SendPostDataBinaryTimeout service functions
*/
void SendPostDataBinaryImpl(Kernel::HLERequestContext& ctx, bool timeout);
/**
* HTTP_C::SendPostDataRaw service function
* Inputs:
* 1 : Context handle
* 2 : Post data length
* 3-4: (Mapped buffer) Post data
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2-3: (Mapped buffer) Post data
*/
void SendPostDataRaw(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::SendPostDataRawTimeout service function
* Inputs:
* 1 : Context handle
* 2 : Post data length
* 3-4: u64 nanoseconds delay
* 5-6: (Mapped buffer) Post data
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2-3: (Mapped buffer) Post data
*/
void SendPostDataRawTimeout(Kernel::HLERequestContext& ctx);
/**
* SendPostDataRawImpl:
* Implements SendPostDataRaw and SendPostDataRawTimeout service functions
*/
void SendPostDataRawImpl(Kernel::HLERequestContext& ctx, bool timeout);
/**
* HTTP_C::NotifyFinishSendPostData service function
* Inputs:
* 1 : Context handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void NotifyFinishSendPostData(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::SetPostDataEncoding service function
* Inputs:
* 1 : Context handle
* 2 : Post data encoding
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SetPostDataEncoding(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::GetResponseHeader service function
* Inputs:
* 1 : Context handle
* 2 : Header name length
* 3 : Return value length
* 4-5 : (Static buffer) Header name
* 6-7 : (Mapped buffer) Header value
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Header value copied size
* 3-4: (Mapped buffer) Header value
*/
void GetResponseHeader(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::GetResponseHeaderTimeout service function
* Inputs:
* 1 : Context handle
* 2 : Header name length
* 3 : Return value length
* 4-5 : u64 nanoseconds delay
* 6-7 : (Static buffer) Header name
* 8-9 : (Mapped buffer) Header value
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Header value copied size
* 3-4: (Mapped buffer) Header value
*/
void GetResponseHeaderTimeout(Kernel::HLERequestContext& ctx);
/**
* GetResponseHeaderImpl:
* Implements GetResponseHeader and GetResponseHeaderTimeout service functions
*/
void GetResponseHeaderImpl(Kernel::HLERequestContext& ctx, bool timeout);
/**
* HTTP_C::GetResponseStatusCode service function
* Inputs:
* 1 : Context handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : HTTP response status code
*/
void GetResponseStatusCode(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::GetResponseStatusCode service function
* Inputs:
* 1 : Context handle
* 2-3 : u64 nanoseconds timeout
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : HTTP response status code
*/
void GetResponseStatusCodeTimeout(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::AddTrustedRootCA service function
* Inputs:
* 1 : Context handle
* 2 : CA data length
* 3-4: (Mapped buffer) CA data
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2-3: (Mapped buffer) CA data
*/
void AddTrustedRootCA(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::AddDefaultCert service function
* Inputs:
* 1 : Context handle
* 2 : Cert ID
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void AddDefaultCert(Kernel::HLERequestContext& ctx);
/**
* GetResponseStatusCodeImpl:
* Implements GetResponseStatusCode and GetResponseStatusCodeTimeout service functions
*/
void GetResponseStatusCodeImpl(Kernel::HLERequestContext& ctx, bool timeout);
/**
* HTTP_C::SetDefaultClientCert service function
* Inputs:
* 1 : Context handle
* 2 : Client cert ID
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SetDefaultClientCert(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::SetClientCertContext service function
* Inputs:
* 1 : Context handle
* 2 : Cert context handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SetClientCertContext(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::GetSSLError service function
* Inputs:
* 1 : Context handle
* 2 : Unknown
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : SSL Error code
*/
void GetSSLError(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::SetSSLOpt service function
* Inputs:
* 1 : Context handle
* 2 : SSL Option
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SetSSLOpt(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::OpenClientCertContext service function
* Inputs:
* 1 : Cert size
* 2 : Key size
* 3 : (CertSize<<4) | 10
* 4 : Pointer to input cert
* 5 : (KeySize<<4) | 10
* 6 : Pointer to input key
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void OpenClientCertContext(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::OpenDefaultClientCertContext service function
* Inputs:
* 1 : CertID
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Client Cert context handle
*/
void OpenDefaultClientCertContext(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::CloseClientCertContext service function
* Inputs:
* 1 : ClientCert Handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void CloseClientCertContext(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::SetKeepAlive service function
* Inputs:
* 1 : Context handle
* 2 : Keep Alive Option
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SetKeepAlive(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::SetPostDataTypeSize service function
* Inputs:
* 1 : Context handle
* 2 : Post data type
* 3 : Content length size
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SetPostDataTypeSize(Kernel::HLERequestContext& ctx);
/**
* HTTP_C::Finalize service function
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void Finalize(Kernel::HLERequestContext& ctx);
[[nodiscard]] SessionData* EnsureSessionInitialized(Kernel::HLERequestContext& ctx,
IPC::RequestParser rp);
[[nodiscard]] bool PerformStateChecks(Kernel::HLERequestContext& ctx, IPC::RequestParser rp,
Context::Handle context_handle);
void DecryptClCertA();
std::shared_ptr<Kernel::SharedMemory> shared_memory = nullptr;
/// The next number to use when a new HTTP session is initalized.
u32 session_counter = 0;
/// The next handle number to use when a new HTTP context is created.
Context::Handle context_counter = 0;
/// The next handle number to use when a new ClientCert context is created.
ClientCertContext::Handle client_certs_counter = 0;
/// Global list of HTTP contexts currently opened.
std::unordered_map<Context::Handle, Context> contexts;
// Get context from its handle
inline Context& GetContext(const Context::Handle& handle) {
auto it = contexts.find(handle);
ASSERT(it != contexts.end());
return it->second;
}
/// Global list of ClientCert contexts currently opened.
std::unordered_map<ClientCertContext::Handle, std::shared_ptr<ClientCertContext>> client_certs;
ClCertAData ClCertA;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
// NOTE: Serialization of the HTTP service is on a 'best effort' basis.
// There is a very good chance that saving/loading during a network connection will break,
// regardless!
ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this);
ar& ClCertA.certificate;
ar& ClCertA.private_key;
ar& ClCertA.init;
ar& context_counter;
ar& client_certs_counter;
ar& client_certs;
// NOTE: `contexts` is not serialized because it contains non-serializable data. (i.e.
// handles to ongoing HTTP requests.) Serializing across HTTP contexts will break.
}
friend class boost::serialization::access;
};
std::shared_ptr<HTTP_C> GetService(Core::System& system);
void InstallInterfaces(Core::System& system);
} // namespace Service::HTTP
BOOST_CLASS_EXPORT_KEY(Service::HTTP::HTTP_C)
BOOST_CLASS_EXPORT_KEY(Service::HTTP::SessionData)
|