Paraslash Audio Streaming | |
About News Download Documentation Development |
Crypto functions independent of openssl/libgcrypt. More...
#include <regex.h>
#include "para.h"
#include "error.h"
#include "string.h"
#include "crypt.h"
#include "crypt_backend.h"
#include "portable_io.h"
#include "fd.h"
#include "base64.h"
Macros | |
#define | KEY_TYPE_TXT "ssh-rsa" |
If the key begins with this text, we treat it as an ssh key. More... | |
#define | PRIVATE_PEM_KEY_HEADER "-----BEGIN RSA PRIVATE KEY-----" |
Private PEM keys (legacy format) start with this header. More... | |
#define | PRIVATE_OPENSSH_KEY_HEADER "-----BEGIN OPENSSH PRIVATE KEY-----" |
Private OPENSSH keys (RFC4716) start with this header. More... | |
#define | PRIVATE_PEM_KEY_FOOTER "-----END RSA PRIVATE KEY-----" |
Private PEM keys (legacy format) end with this footer. More... | |
#define | PRIVATE_OPENSSH_KEY_FOOTER "-----END OPENSSH PRIVATE KEY-----" |
Private OPENSSH keys (RFC4716) end with this footer. More... | |
Functions | |
int | decode_public_key (const char *filename, unsigned char **blob, size_t *decoded_size) |
Perform sanity checks and base64-decode an ssh-rsa key. More... | |
int | check_private_key_file (const char *file) |
Check existence and permissions of a private key file. More... | |
void | hash_to_asc (const unsigned char *hash, char *asc) |
Convert a hash value to ascii format. More... | |
int | hash_compare (const unsigned char *h1, const unsigned char *h2) |
Compare two hashes. More... | |
void | hash2_to_asc (const unsigned char *hash, char *asc) |
Convert a hash2 value to ascii format. More... | |
int | hash2_compare (const unsigned char *h1, const unsigned char *h2) |
Compare two version 2 hashes. More... | |
int | find_openssh_bignum_offset (const unsigned char *data, int len) |
Check header of an openssh private key and compute bignum offset. More... | |
int | decode_private_key (const char *key_file, unsigned char **result, size_t *blob_size) |
Decode an openssh-v1 (aka RFC4716) or PEM (aka ASN.1) private key. More... | |
Crypto functions independent of openssl/libgcrypt.
#define KEY_TYPE_TXT "ssh-rsa" |
If the key begins with this text, we treat it as an ssh key.
#define PRIVATE_PEM_KEY_HEADER "-----BEGIN RSA PRIVATE KEY-----" |
Private PEM keys (legacy format) start with this header.
#define PRIVATE_OPENSSH_KEY_HEADER "-----BEGIN OPENSSH PRIVATE KEY-----" |
Private OPENSSH keys (RFC4716) start with this header.
#define PRIVATE_PEM_KEY_FOOTER "-----END RSA PRIVATE KEY-----" |
Private PEM keys (legacy format) end with this footer.
#define PRIVATE_OPENSSH_KEY_FOOTER "-----END OPENSSH PRIVATE KEY-----" |
Private OPENSSH keys (RFC4716) end with this footer.
int decode_public_key | ( | const char * | filename, |
unsigned char ** | blob, | ||
size_t * | decoded_size | ||
) |
Perform sanity checks and base64-decode an ssh-rsa key.
filename | The public key file (usually id_rsa.pub). |
blob | Pointer to base64-decoded blob is returned here. |
decoded_size | The size of the decoded blob. |
The memory pointed at by the returned blob pointer has to be freed by the caller.
References mmap_full_file().
Referenced by apc_get_pubkey().
int check_private_key_file | ( | const char * | file | ) |
Check existence and permissions of a private key file.
file | The path of the key file. |
This checks whether the file exists and its permissions are restrictive enough. It is considered an error if we own the file and it is readable for others.
References ERRNO_TO_PARA_ERROR.
Referenced by apc_priv_decrypt().
void hash_to_asc | ( | const unsigned char * | hash, |
char * | asc | ||
) |
Convert a hash value to ascii format.
hash | the hash value. |
asc | Result pointer. |
asc must point to an area of at least 2 * HASH_SIZE
+ 1 bytes which will be filled by the function with the ascii representation of the hash value given by hash, and a terminating NULL
byte.
References HASH_SIZE.
int hash_compare | ( | const unsigned char * | h1, |
const unsigned char * | h2 | ||
) |
Compare two hashes.
h1 | Pointer to the first hash value. |
h2 | Pointer to the second hash value. |
References HASH_SIZE.
void hash2_to_asc | ( | const unsigned char * | hash, |
char * | asc | ||
) |
Convert a hash2 value to ascii format.
hash | the hash value. |
asc | Result pointer. |
asc must point to an area of at least 2 * HASH2_SIZE
+ 1 bytes which will be filled by the function with the ascii representation of the hash value given by hash, and a terminating NULL
byte.
References HASH2_SIZE.
int hash2_compare | ( | const unsigned char * | h1, |
const unsigned char * | h2 | ||
) |
Compare two version 2 hashes.
h1 | Pointer to the first hash value. |
h2 | Pointer to the second hash value. |
References HASH2_SIZE.
int find_openssh_bignum_offset | ( | const unsigned char * | data, |
int | len | ||
) |
Check header of an openssh private key and compute bignum offset.
data | The base64-decoded key. |
len | The size of the decoded key. |
Several assumptions are made about the key. Most notably, we only support single unencrypted keys without comments.
int decode_private_key | ( | const char * | key_file, |
unsigned char ** | result, | ||
size_t * | blob_size | ||
) |
Decode an openssh-v1 (aka RFC4716) or PEM (aka ASN.1) private key.
key_file | The private key file (usually id_rsa). |
result | Pointer to base64-decoded blob is returned here. |
blob_size | The size of the decoded blob. |
This only checks header and footer and base64-decodes the part in between. No attempt to read the decoded part is made.
References alloc(), base64_decode(), mmap_full_file(), PARA_INFO_LOG, para_isspace, para_munmap(), PARA_WARNING_LOG, PKT_OPENSSH, PKT_PEM, PRIVATE_OPENSSH_KEY_FOOTER, PRIVATE_OPENSSH_KEY_HEADER, PRIVATE_PEM_KEY_FOOTER, and PRIVATE_PEM_KEY_HEADER.