File size: 4,565 Bytes
7791ca1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#pragma once
/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

#include <aws/crt/Types.h>

#include <memory>

struct aws_http_proxy_strategy;

namespace Aws
{
    namespace Crt
    {
        namespace Http
        {
            enum class AwsHttpProxyConnectionType;

            /**
             * Configuration for a proxy strategy that performs basic authentication
             */
            struct AWS_CRT_CPP_API HttpProxyStrategyBasicAuthConfig
            {
                HttpProxyStrategyBasicAuthConfig();

                /**
                 * Basic auth can be applied either to forwarding or tunneling proxy connections, but we need
                 * to know the type ahead of time
                 */
                AwsHttpProxyConnectionType ConnectionType;

                /**
                 * Username to apply to the basic authentication process
                 */
                String Username;

                /**
                 * Password to apply to the basic authentication process
                 */
                String Password;
            };

            using KerberosGetTokenFunction = std::function<bool(String &)>;
            using NtlmGetTokenFunction = std::function<bool(const String &, String &)>;

            /**
             * Configuration for a proxy strategy that attempts to use kerberos and ntlm, based on authentication
             * failure feedback from the proxy's responses to CONNECT attempts.  The kerberos/ntlm callbacks are
             * currently synchronous but invoked potentially from within event loop threads.  This is not optimal
             * but transitioning to fully async hasn't been a need yet.
             *
             * The adapative strategy will skip an authentication method whose callbacks are not supplied, so you
             * can use this for purely kerberos or ntlm as well.
             */
            struct AWS_CRT_CPP_API HttpProxyStrategyAdaptiveConfig
            {
                HttpProxyStrategyAdaptiveConfig() : KerberosGetToken(), NtlmGetCredential(), NtlmGetToken() {}

                /**
                 * User-supplied callback for fetching kerberos tokens
                 */
                KerberosGetTokenFunction KerberosGetToken;

                /**
                 * User-supplied callback for fetching an ntlm credential
                 */
                KerberosGetTokenFunction NtlmGetCredential;

                /**
                 * User-supplied callback for fetching an ntlm token
                 */
                NtlmGetTokenFunction NtlmGetToken;
            };

            /**
             * Wrapper class for a C-level proxy strategy - an object that allows the user to transform or modify
             * the authentication logic when connecting to a proxy.
             */
            class AWS_CRT_CPP_API HttpProxyStrategy
            {
              public:
                HttpProxyStrategy(struct aws_http_proxy_strategy *strategy);
                virtual ~HttpProxyStrategy();

                /// @private
                struct aws_http_proxy_strategy *GetUnderlyingHandle() const noexcept { return m_strategy; }

                /**
                 * Creates a proxy strategy that performs basic authentication
                 * @param config basic authentication configuration options
                 * @param allocator allocator to use
                 * @return a new basic authentication proxy strategy
                 */
                static std::shared_ptr<HttpProxyStrategy> CreateBasicHttpProxyStrategy(
                    const HttpProxyStrategyBasicAuthConfig &config,
                    Allocator *allocator = ApiAllocator());

                /**
                 * Creates a proxy strategy that, depending on configuration, can attempt kerberos and/or ntlm
                 * authentication when connecting to the proxy
                 * @param config the adaptive strategy configuration options
                 * @param allocator allocator to use
                 * @return a new adaptive proxy strategy
                 */
                static std::shared_ptr<HttpProxyStrategy> CreateAdaptiveHttpProxyStrategy(
                    const HttpProxyStrategyAdaptiveConfig &config,
                    Allocator *allocator = ApiAllocator());

              protected:
                struct aws_http_proxy_strategy *m_strategy;
            };
        } // namespace Http
    } // namespace Crt
} // namespace Aws