summaryrefslogtreecommitdiffstats
path: root/nanohttp/nanohttp-ssl.h
blob: f79635623643669d0dbcac2a4feba6c0504f3806 (plain)
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
/******************************************************************
*  $Id: nanohttp-ssl.h,v 1.20 2006/11/23 15:27:33 m0gg Exp $
*
* CSOAP Project:  A http client/server library in C
* Copyright (C) 2001-2005  Rochester Institute of Technology
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA  02111-1307, USA.
*
* Author: Matt Campbell
******************************************************************/
#ifndef __nanohttp_ssl_h
#define __nanohttp_ssl_h

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef HAVE_SSL

#ifdef HAVE_OPENSSL_SSL_H
#include <openssl/ssl.h>
#endif

/**
 *
 * Commandline argument to enabled SSL in the nanoHTTP server.
 *
 */
#define NHTTPD_ARG_HTTPS	"-NHTTPS"

#ifdef __cplusplus
extern "C"
{
#endif

/**
 *
 * Initialization and shutdown of the SSL module
 *
 */
extern herror_t hssl_module_init(int argc, char **argv);
extern void hssl_module_destroy(void);

extern void hssl_set_certificate(char *c);
extern void hssl_set_certpass(char *c);
extern void hssl_set_ca(char *c);

extern void hssl_enable(void);

extern int hssl_enabled(void);

/**
 *
 * Socket initialization and shutdown
 *
 */
extern herror_t hssl_client_ssl(struct hsocket_t * sock);
extern herror_t hssl_server_ssl(struct hsocket_t * sock);

extern void hssl_cleanup(struct hsocket_t * sock);

/*
 * Callback for password checker
 */
/* static int pw_cb(char* buf, int num, int rwflag, void *userdata); */

/*
 * Quick function for verifying a portion of the cert
 * nid is any NID_ defined in <openssl/objects.h>
 * returns non-zero if everything went ok
 */
#define CERT_SUBJECT	1

extern int verify_sn(X509 * cert, int who, int nid, char *str);

/*
 * Called by framework for verify
 */

/* static int verify_cb(int prev_ok, X509_STORE_CTX* ctx); */

extern void hssl_set_user_verify(int func(X509 * cert));

#ifdef __cplusplus
}
#endif

#else /* HAVE_SSL */

static inline herror_t
hssl_module_init(int argc, char **argv)
{
  return H_OK;
}

static inline void
hssl_module_destroy(void)
{
  return;
}

static inline int
hssl_enabled(void)
{
  return 0;
}

static inline herror_t
hssl_client_ssl(struct hsocket_t *sock)
{
  return H_OK;
}

static inline herror_t
hssl_server_ssl(struct hsocket_t *sock)
{
  return H_OK;
}

static inline void
hssl_cleanup(struct hsocket_t *sock)
{
  return;
}

#endif /* HAVE_SSL */

#ifdef __cplusplus
extern "C"
{
#endif

extern herror_t hssl_read(struct hsocket_t * sock, char *buf, size_t len, size_t * received);
extern herror_t hssl_write(struct hsocket_t * sock, const char *buf, size_t len, size_t * sent);

#ifdef __cplusplus
}
#endif

#endif