1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#ifndef _PKGWEB_H
28#define	_PKGWEB_H
29
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#include <netdb.h>
36#include <boot_http.h>
37
38/* shortest backoff delay possible (in seconds) */
39#define	MIN_BACKOFF	1
40
41/* how much to increase backoff time after each failure */
42#define	BACKOFF_FACTOR	2
43
44/* Maximum amount of backoff for a heavy network or flaky server */
45#define	MAX_BACKOFF	128
46
47typedef enum {
48	HTTP_REQ_TYPE_HEAD,
49	HTTP_REQ_TYPE_GET
50} HTTPRequestType;
51
52typedef enum {
53	OCSPSuccess,
54	OCSPMem,
55	OCSPParse,
56	OCSPConnect,
57	OCSPRequest,
58	OCSPResponder,
59	OCSPUnsupported,
60	OCSPVerify,
61	OCSPInternal,
62	OCSPNoURI
63} OCSPStatus;
64
65typedef enum {
66	none,
67	web_http,
68	web_https,
69	web_ftp
70} WebScheme;
71
72typedef enum {
73    WEB_OK,
74    WEB_TIMEOUT,
75    WEB_CONNREFUSED,
76    WEB_HOSTDOWN,
77    WEB_VERIFY_SETUP,
78    WEB_NOCONNECT,
79    WEB_GET_FAIL
80} WebStatus;
81
82typedef struct {
83	ulong_t prev_cont_length;
84	ulong_t content_length;
85	ulong_t cur_pos;
86} DwnldData;
87
88typedef struct {
89	keystore_handle_t keystore;
90	char *certfile;
91	char *uniqfile;
92	char *link;
93	char *errstr;
94	char *dwnld_dir;
95	boolean_t	spool;
96	void *content;
97	int timeout;
98	url_hport_t proxy;
99	url_t url;
100	DwnldData data;
101	http_respinfo_t *resp;
102	boot_http_ver_t *http_vers;
103	http_handle_t *hps;
104} WEB_SESSION;
105
106extern boolean_t web_session_control(PKG_ERR *, char *, char *,
107    keystore_handle_t, char *, ushort_t, int, int, int, char **);
108extern boolean_t get_signature(PKG_ERR *, char *, struct pkgdev *,
109    PKCS7 **);
110extern boolean_t validate_signature(PKG_ERR *, char *, BIO *, PKCS7 *,
111    STACK_OF(X509) *, url_hport_t *, int);
112extern boolean_t ds_validate_signature(PKG_ERR *, struct pkgdev *, char **,
113    char *, PKCS7 *, STACK_OF(X509) *, url_hport_t *, int);
114extern boolean_t get_proxy_port(PKG_ERR *, char **, ushort_t *);
115extern boolean_t path_valid(char *);
116extern void web_cleanup(void);
117extern ushort_t strip_port(char *proxy);
118extern void set_web_install(void);
119extern int is_web_install(void);
120extern void echo_out(int, char *, ...);
121extern void backoff(void);
122extern void reset_backoff(void);
123extern char *get_endof_string(char *, char);
124extern char *get_startof_string(char *, char);
125
126#ifdef __cplusplus
127}
128#endif
129
130#endif /* _PKGWEB_H */
131