]> git.saurik.com Git - apple/security.git/blob - Network/https-protocol.h
Security-28.tar.gz
[apple/security.git] / Network / https-protocol.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 //
20 // https-protocol - SSL based HTTP
21 //
22 #ifndef _H_HTTPS_PROTOCOL
23 #define _H_HTTPS_PROTOCOL
24
25 #include "http-protocol.h"
26 #include <Security/securetransport++.h>
27
28
29 namespace Security {
30 namespace Network {
31
32
33 //
34 // The protocol object for https.
35 // This is heavily based on the HTTP protocol, which provides hooks to filter
36 // the I/O channels to implement the crypto. Refer to HTTP for all the protocol
37 // stuff.
38 //
39 class SecureHTTPProtocol : public HTTPProtocol {
40 class SecureHTTPTransfer;
41 public:
42 static const IPPort defaultHttpsPort = 443;
43
44 SecureHTTPProtocol(Manager &mgr);
45
46 public:
47 const char *name() const;
48 SecureHTTPTransfer *makeTransfer(const Target &target, Operation operation);
49
50 private:
51 //
52 // Our persistent connection object
53 //
54 typedef SecureTransport<Socket> SSL;
55
56 class SecureHTTPConnection : public HTTPConnection, protected SSL {
57 public:
58 SecureHTTPConnection(Protocol &proto, const HostTarget &tgt);
59 ~SecureHTTPConnection();
60
61 void sslRequest();
62
63 protected:
64 enum {
65 sslConnecting, // awaiting transport level connection
66 sslStartup, // just connected
67 sslHandshaking, // SSL handshake proceeding
68 sslConnected // SSL established, I/O possible
69 } sslState;
70
71 void transit(Event event, char *input, size_t inputLength);
72 void startSSL();
73
74 bool validate();
75
76 protected:
77 bool deferStartSSL; // protocol break for sub-protocols
78
79 private:
80 bool sslActive; // using SSL for I/O
81
82 // override I/O methods for TransferEngine::Client
83 size_t read(void *data, size_t length);
84 size_t write(const void *data, size_t length);
85 bool atEnd() const;
86 };
87
88
89 //
90 // A generic Transfer object. All HTTP transfers are transactional (headers in, optional data in,
91 // headers out, optional data out), so there's no reason to distinguish subclasses.
92 //
93 class SecureHTTPTransfer : public HTTPTransfer {
94 public:
95 SecureHTTPTransfer(Protocol &proto,
96 const Target &tgt, Operation operation, IPPort defaultPort);
97
98 protected:
99 void start();
100 };
101 };
102
103
104 } // end namespace Network
105 } // end namespace Security
106
107
108 #endif //_H_HTTPS_PROTOCOL