1 | /** |
---|
2 | ** abac_util_cert.c |
---|
3 | ** utility code related process/handling of certificate_t |
---|
4 | **/ |
---|
5 | #include <err.h> |
---|
6 | #include <stdlib.h> |
---|
7 | #include <string.h> |
---|
8 | #include <stdio.h> |
---|
9 | #include <assert.h> |
---|
10 | #include <stdarg.h> |
---|
11 | #include <sys/stat.h> |
---|
12 | #include <termios.h> |
---|
13 | #include <unistd.h> |
---|
14 | #include <sys/types.h> |
---|
15 | |
---|
16 | #include <credentials/certificates/certificate.h> |
---|
17 | #include <credentials/certificates/x509.h> |
---|
18 | #include <credentials/keys/private_key.h> |
---|
19 | |
---|
20 | #include "abac_util.h" |
---|
21 | |
---|
22 | static int debug=0; |
---|
23 | |
---|
24 | char *cert_get_keyid(certificate_t *cert) { |
---|
25 | // get the keyid |
---|
26 | x509_t *x509 = (x509_t *)cert; |
---|
27 | chunk_t keyid = x509->get_subjectKeyIdentifier(x509); |
---|
28 | chunk_t string = chunk_to_hex(keyid, NULL, 0); |
---|
29 | return (char *)string.ptr; |
---|
30 | } |
---|
31 | |
---|
32 | certificate_t *cert_get_id_cert_from_file(char *filename) |
---|
33 | { |
---|
34 | certificate_t *cert = lib->creds->create(lib->creds, |
---|
35 | CRED_CERTIFICATE, CERT_X509, |
---|
36 | BUILD_FROM_FILE, filename, |
---|
37 | BUILD_X509_FLAG, X509_AA, // attribute authority, dumb |
---|
38 | BUILD_END |
---|
39 | ); |
---|
40 | return cert; |
---|
41 | } |
---|
42 | |
---|
43 | certificate_t *cert_get_id_cert_from_chunk(chunk_t chunk) |
---|
44 | { |
---|
45 | certificate_t *cert = lib->creds->create(lib->creds, |
---|
46 | CRED_CERTIFICATE, CERT_X509, |
---|
47 | BUILD_BLOB_ASN1_DER, chunk, |
---|
48 | BUILD_X509_FLAG, X509_AA, |
---|
49 | BUILD_END |
---|
50 | ); |
---|
51 | return cert; |
---|
52 | } |
---|
53 | |
---|
54 | certificate_t *cert_get_id_cert_from_pem_chunk(chunk_t chunk) |
---|
55 | { |
---|
56 | certificate_t *cert = lib->creds->create(lib->creds, |
---|
57 | CRED_CERTIFICATE, CERT_X509, |
---|
58 | BUILD_BLOB_PEM, chunk, |
---|
59 | BUILD_X509_FLAG, X509_AA, |
---|
60 | BUILD_END |
---|
61 | ); |
---|
62 | return cert; |
---|
63 | } |
---|
64 | |
---|
65 | certificate_t *cert_get_attr_cert_from_file(char *filename) |
---|
66 | { |
---|
67 | certificate_t *cert = lib->creds->create(lib->creds, |
---|
68 | CRED_CERTIFICATE, CERT_X509_AC, |
---|
69 | BUILD_FROM_FILE, filename, |
---|
70 | BUILD_END |
---|
71 | ); |
---|
72 | return cert; |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | certificate_t *cert_get_attr_cert_from_chunk(chunk_t chunk) |
---|
77 | { |
---|
78 | certificate_t *cert = lib->creds->create(lib->creds, |
---|
79 | CRED_CERTIFICATE, CERT_X509_AC, |
---|
80 | BUILD_BLOB_ASN1_DER, chunk, |
---|
81 | BUILD_END |
---|
82 | ); |
---|
83 | return cert; |
---|
84 | } |
---|
85 | |
---|
86 | |
---|