-
Notifications
You must be signed in to change notification settings - Fork 256
/
crypto_none.c
242 lines (201 loc) · 5.46 KB
/
crypto_none.c
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
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2005-2011 Free Software Foundation Europe e.V.
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program 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
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
/*
* crypto_none.c Encryption support functions when no backend.
*
* Author: Landon Fuller <landonf@opendarwin.org>
*/
#include "bareos.h"
#if !defined(HAVE_CRYPTO)
#include "jcr.h"
#include <assert.h>
/* Message Digest Structure */
struct Digest {
crypto_digest_t type;
JCR *jcr;
union {
SHA1_CTX sha1;
MD5_CTX md5;
};
};
/* Dummy Signature Structure */
struct Signature {
JCR *jcr;
};
DIGEST *crypto_digest_new(JCR *jcr, crypto_digest_t type)
{
DIGEST *digest;
digest = (DIGEST *)malloc(sizeof(DIGEST));
digest->type = type;
digest->jcr = jcr;
switch (type) {
case CRYPTO_DIGEST_MD5:
MD5_Init(&digest->md5);
break;
case CRYPTO_DIGEST_SHA1:
SHA1Init(&digest->sha1);
break;
default:
Jmsg1(jcr, M_ERROR, 0, _("Unsupported digest type=%d specified\n"), type);
free(digest);
return NULL;
}
return (digest);
}
bool crypto_digest_update(DIGEST *digest, const uint8_t *data, uint32_t length)
{
switch (digest->type) {
case CRYPTO_DIGEST_MD5:
/* Doesn't return anything ... */
MD5_Update(&digest->md5, (unsigned char *) data, length);
return true;
case CRYPTO_DIGEST_SHA1:
/* Doesn't return anything ... */
SHA1Update(&digest->sha1, (const u_int8_t *) data, (unsigned int)length);
return true;
default:
return false;
}
}
bool crypto_digest_finalize(DIGEST *digest, uint8_t *dest, uint32_t *length)
{
switch (digest->type) {
case CRYPTO_DIGEST_MD5:
/* Guard against programmer error by either the API client or
* an out-of-sync CRYPTO_DIGEST_MAX_SIZE */
assert(*length >= CRYPTO_DIGEST_MD5_SIZE);
*length = CRYPTO_DIGEST_MD5_SIZE;
/* Doesn't return anything ... */
MD5_Final((unsigned char *)dest, &digest->md5);
return true;
case CRYPTO_DIGEST_SHA1:
/* Guard against programmer error by either the API client or
* an out-of-sync CRYPTO_DIGEST_MAX_SIZE */
assert(*length >= CRYPTO_DIGEST_SHA1_SIZE);
*length = CRYPTO_DIGEST_SHA1_SIZE;
SHA1Final((u_int8_t *) dest, &digest->sha1);
return true;
default:
return false;
}
return false;
}
void crypto_digest_free(DIGEST *digest)
{
free(digest);
}
SIGNATURE *crypto_sign_new(JCR *jcr)
{
return NULL;
}
crypto_error_t crypto_sign_get_digest(SIGNATURE *sig, X509_KEYPAIR *keypair,
crypto_digest_t &type, DIGEST **digest)
{
return CRYPTO_ERROR_INTERNAL;
}
crypto_error_t crypto_sign_verify(SIGNATURE *sig, X509_KEYPAIR *keypair, DIGEST *digest)
{
return CRYPTO_ERROR_INTERNAL;
}
int crypto_sign_add_signer(SIGNATURE *sig, DIGEST *digest, X509_KEYPAIR *keypair)
{
return false;
}
int crypto_sign_encode(SIGNATURE *sig, uint8_t *dest, uint32_t *length)
{
return false;
}
SIGNATURE *crypto_sign_decode(JCR *jcr, const uint8_t *sigData, uint32_t length)
{
return NULL;
}
void crypto_sign_free(SIGNATURE *sig)
{
}
X509_KEYPAIR *crypto_keypair_new(void)
{
return NULL;
}
X509_KEYPAIR *crypto_keypair_dup(X509_KEYPAIR *keypair)
{
return NULL;
}
int crypto_keypair_load_cert(X509_KEYPAIR *keypair, const char *file)
{
return false;
}
bool crypto_keypair_has_key(const char *file)
{
return false;
}
int crypto_keypair_load_key(X509_KEYPAIR *keypair, const char *file, CRYPTO_PEM_PASSWD_CB *pem_callback, const void *pem_userdata)
{
return false;
}
void crypto_keypair_free(X509_KEYPAIR *keypair)
{
}
CRYPTO_SESSION *crypto_session_new(crypto_cipher_t cipher, alist *pubkeys)
{
return NULL;
}
void crypto_session_free(CRYPTO_SESSION *cs)
{
}
bool crypto_session_encode(CRYPTO_SESSION *cs, uint8_t *dest, uint32_t *length)
{
return false;
}
crypto_error_t crypto_session_decode(const uint8_t *data, uint32_t length, alist *keypairs, CRYPTO_SESSION **session)
{
return CRYPTO_ERROR_INTERNAL;
}
CIPHER_CONTEXT *crypto_cipher_new(CRYPTO_SESSION *cs, bool encrypt, uint32_t *blocksize)
{
return NULL;
}
bool crypto_cipher_update(CIPHER_CONTEXT *cipher_ctx, const uint8_t *data, uint32_t length, const uint8_t *dest, uint32_t *written)
{
return false;
}
bool crypto_cipher_finalize(CIPHER_CONTEXT *cipher_ctx, uint8_t *dest, uint32_t *written)
{
return false;
}
void crypto_cipher_free(CIPHER_CONTEXT *cipher_ctx)
{
}
const char *crypto_digest_name(DIGEST *digest)
{
return crypto_digest_name(digest->type);
}
#endif /* HAVE_CRYPTO */
#if !defined(HAVE_OPENSSL) && \
!defined(HAVE_GNUTLS) && \
!defined(HAVE_NSS)
/*
* Dummy initialization functions when no crypto framework found.
*/
int init_crypto(void)
{
return 0;
}
int cleanup_crypto(void)
{
return 0;
}
#endif /* !HAVE_OPENSSL && !HAVE_GNUTLS && !HAVE_NSS */