cfengine  3.15.4
About: CFEngine is a configuration management system for configuring and maintaining Unix-like computers (using an own high level policy language). Community version.
  Fossies Dox: cfengine-3.15.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

crypto.h
Go to the documentation of this file.
1 /*
2  Copyright 2019 Northern.tech AS
3 
4  This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
5 
6  This program is free software; you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by the
8  Free Software Foundation; version 3.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 
19  To the extent this program is licensed as part of the Enterprise
20  versions of CFEngine, the applicable Commercial Open Source License
21  (COSL) may apply to this file if you as a licensee so wish it. See
22  included file COSL.txt.
23 */
24 
25 #ifndef CFENGINE_CRYPTO_H
26 #define CFENGINE_CRYPTO_H
27 
28 #include <platform.h>
29 
30 #include <openssl/rsa.h>
31 
32 #include <logging.h>
33 
34 // This passphrase was used to encrypt private keys.
35 // We no longer encrypt new keys, but the passphrase is kept
36 // for backwards compatibility - old encrypted keys will still work.
37 #define PRIVKEY_PASSPHRASE "Cfengine passphrase"
38 #define PRIVKEY_PASSPHRASE_LEN 19
39 
40 void CryptoInitialize(void);
41 void CryptoDeInitialize(void);
42 
43 const char *CryptoLastErrorString(void);
44 void DebugBinOut(char *buffer, int len, char *com);
45 bool LoadSecretKeys(const char *const priv_key_path,
46  const char *const pub_key_path,
47  RSA **priv_key, RSA **pub_key);
48 void PolicyHubUpdateKeys(const char *policy_server);
49 int EncryptString(char *out, size_t out_size, const char *in, int plainlen,
50  char type, unsigned char *key);
51 size_t CipherBlockSizeBytes(const EVP_CIPHER *cipher);
52 size_t CipherTextSizeMax(const EVP_CIPHER* cipher, size_t plaintext_size);
53 size_t PlainTextSizeMax(const EVP_CIPHER* cipher, size_t ciphertext_size);
54 int DecryptString(char *out, size_t out_size, const char *in, int cipherlen,
55  char type, unsigned char *key);
56 RSA *HavePublicKey(const char *username, const char *ipaddress, const char *digest);
57 RSA *HavePublicKeyByIP(const char *username, const char *ipaddress);
58 bool SavePublicKey(const char *username, const char *digest, const RSA *key);
59 RSA *LoadPublicKey(const char *filename);
60 char *LoadPubkeyDigest(const char *pubkey);
61 char *GetPubkeyDigest(RSA *pubkey);
62 bool TrustKey(const char *pubkey, const char *ipaddress, const char *username);
63 
64 char *PublicKeyFile(const char *workdir);
65 char *PrivateKeyFile(const char *workdir);
67 
68 #endif
RSA * HavePublicKey(const char *username, const char *ipaddress, const char *digest)
Search for a key:
Definition: crypto.c:344
char * LoadPubkeyDigest(const char *pubkey)
Definition: crypto.c:522
char * GetPubkeyDigest(RSA *pubkey)
Definition: crypto.c:542
char * PublicKeyFile(const char *workdir)
Definition: crypto.c:749
void CryptoDeInitialize(void)
Definition: crypto.c:86
bool LoadSecretKeys(const char *const priv_key_path, const char *const pub_key_path, RSA **priv_key, RSA **pub_key)
Definition: crypto.c:170
RSA * LoadPublicKey(const char *filename)
Definition: crypto.c:482
void DebugBinOut(char *buffer, int len, char *com)
Definition: crypto.c:726
int EncryptString(char *out, size_t out_size, const char *in, int plainlen, char type, unsigned char *key)
Definition: crypto.c:593
bool TrustKey(const char *pubkey, const char *ipaddress, const char *username)
Definition: crypto.c:560
RSA * HavePublicKeyByIP(const char *username, const char *ipaddress)
Search for a key given an IP address, by getting the key hash value from lastseen db.
Definition: crypto.c:323
size_t CipherTextSizeMax(const EVP_CIPHER *cipher, size_t plaintext_size)
Definition: crypto.c:643
LogLevel CryptoGetMissingKeyLogLevel(void)
void CryptoInitialize(void)
Definition: crypto.c:71
const char * CryptoLastErrorString(void)
Definition: crypto.c:65
bool SavePublicKey(const char *username, const char *digest, const RSA *key)
Definition: crypto.c:429
void PolicyHubUpdateKeys(const char *policy_server)
Definition: crypto.c:276
char * PrivateKeyFile(const char *workdir)
Definition: crypto.c:757
int DecryptString(char *out, size_t out_size, const char *in, int cipherlen, char type, unsigned char *key)
Definition: crypto.c:675
size_t CipherBlockSizeBytes(const EVP_CIPHER *cipher)
Definition: crypto.c:638
size_t PlainTextSizeMax(const EVP_CIPHER *cipher, size_t ciphertext_size)
Definition: crypto.c:658
LogLevel
Definition: log.h:30