* Alpine failed to read an encrypted password file if too many
[alpine.git] / pith / smkeys.h
blob0d3570bcfe9998f6789b6d0d6e4415c56ea539af
1 /*
2 * $Id: smkeys.h 1074 2008-06-04 00:08:43Z hubert@u.washington.edu $
4 * ========================================================================
5 * Copyrighr 2013-2014 Eduardo Chappa
6 * Copyright 2008 University of Washington
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * ========================================================================
17 #ifdef SMIME
18 #ifndef PITH_SMKEYS_INCLUDED
19 #define PITH_SMKEYS_INCLUDED
22 #include "../pith/state.h"
23 #include "../pith/send.h"
25 #include <openssl/objects.h>
26 #include <openssl/evp.h>
27 #include <openssl/x509.h>
28 #include <openssl/pkcs7.h>
29 #include <openssl/pem.h>
30 #include <openssl/err.h>
31 #include <openssl/bio.h>
32 #include <openssl/safestack.h>
34 #ifndef OPENSSL_1_1_0
35 #define X509_get0_notBefore(x) ((x) && (x)->cert_info \
36 ? (x)->cert_info->validity->notBefore \
37 : NULL)
38 #define X509_get0_notAfter(x) ((x) && (x)->cert_info \
39 ? (x)->cert_info->validity->notAfter \
40 : NULL)
41 #endif /* OPENSSL_1_1_0 */
43 #define EMAILADDRLEADER "emailAddress="
44 #define CACERTSTORELEADER "cacert="
47 typedef struct personal_cert {
48 X509 *cert;
49 EVP_PKEY *key;
50 char *name; /* name of key */
51 char *cname; /* name of cert */
52 char *keytext;
53 struct personal_cert *next;
54 } PERSONAL_CERT;
56 /* flags that tell us where to look for certificates/keys */
57 #define SM_NORMALCERT 0x1 /* look in normal user defined directory */
58 #define SM_BACKUPCERT 0x2 /* look in backup directory */
60 /* exported protoypes */
61 int add_certs_in_dir(X509_LOOKUP *lookup, char *path, char *ext, CertList **cdata);
62 X509_STORE *get_ca_store(void);
63 PERSONAL_CERT *get_personal_certs(char *d);
64 X509 *get_cert_for(char *email, WhichCerts ctype, int tolower);
65 void save_cert_for(char *email, X509 *cert, WhichCerts ctype);
66 char **get_x509_subject_email(X509 *x);
67 EVP_PKEY *load_key(PERSONAL_CERT *pc, char *pass, int flag);
68 CertList *mem_to_certlist(char *contents, WhichCerts ctype);
69 void add_to_end_of_certlist(CertList **cl, char *name, X509 *cert);
70 void free_certlist(CertList **cl);
71 PERSONAL_CERT *mem_to_personal_certs(char *contents);
72 void free_personal_certs(PERSONAL_CERT **pc);
73 void get_fingerprint(X509 *cert, const EVP_MD *type, char *buf, size_t maxLen, char *s);
74 int certlist_to_file(char *filename, CertList *certlist);
75 int load_cert_for_key(char *pathdir, EVP_PKEY *pkey, char **certfile, X509 **pcert);
76 char *smime_get_date(const ASN1_TIME *tm);
77 void resort_certificates(CertList **data, WhichCerts ctype);
78 int setup_certs_backup_by_type(WhichCerts ctype);
79 char *smime_get_cn(X509 *);
80 CertList *smime_X509_to_cert_info(X509 *, char *);
83 #endif /* PITH_SMKEYS_INCLUDED */
84 #endif /* SMIME */