1781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki/*
2781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * Copyright (c) 2009-2013, Google Inc.
3781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * All rights reserved.
4781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki *
5781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * Redistribution and use in source and binary forms, with or without
6781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * modification, are permitted provided that the following conditions
7781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * are met:
8781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki *  * Redistributions of source code must retain the above copyright
9781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki *    notice, this list of conditions and the following disclaimer.
10781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki *  * Redistributions in binary form must reproduce the above copyright
11781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki *    notice, this list of conditions and the following disclaimer in
12781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki *    the documentation and/or other materials provided with the
13781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki *    distribution.
14781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki *  * Neither the name of Google, Inc. nor the names of its contributors
15781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki *    may be used to endorse or promote products derived from this
16781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki *    software without specific prior written permission.
17781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki *
18781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki * SUCH DAMAGE.
30781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki */
31781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki
32781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki#ifndef _FASTBOOTD_SECURE_H
33781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki#define _FASTBOOTD_SECURE_H
34781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki
35781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki#include <openssl/ssl.h>
36781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki#include <openssl/x509.h>
37781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki#include <openssl/x509v3.h>
38781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki#include <openssl/pem.h>
39781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki#include <openssl/cms.h>
40781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki
41781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzyckivoid cert_init_crypto();
42781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki
43781f9fc4af6002f5eb47b2bad852e1090d525298Szymon StarzyckiX509_STORE *cert_store_from_path(const char*stream);
44781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki
45781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzyckistatic inline void cert_release_store(X509_STORE *store) {
46781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki    X509_STORE_free(store);
47781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki}
48781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki
49781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzyckiint cert_read(int fd, CMS_ContentInfo **content, BIO **output);
50781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzyckiint cert_verify(BIO *content, CMS_ContentInfo *content_info, X509_STORE *store, int *out_fd);
51781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzyckivoid cert_release(BIO *content, CMS_ContentInfo *info);
52781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki
53781f9fc4af6002f5eb47b2bad852e1090d525298Szymon Starzycki#endif
54