93 */
94 int
95 get_cert_chain(PKG_ERR *err, X509 *cert, STACK_OF(X509) *clcerts,
96 STACK_OF(X509) *cas, STACK_OF(X509) **chain)
97 {
98 X509_STORE_CTX *store_ctx = NULL;
99 X509_STORE *ca_store = NULL;
100 X509 *ca_cert = NULL;
101 int i;
102 int ret = 0;
103
104 if ((ca_store = X509_STORE_new()) == NULL) {
105 pkgerr_add(err, PKGERR_NOMEM,
106 gettext(ERR_MEM));
107 ret = 1;
108 goto cleanup;
109 }
110
111 /* add all ca certs into the store */
112 for (i = 0; i < sk_X509_num(cas); i++) {
113 /* LINTED pointer cast may result in improper alignment */
114 ca_cert = sk_X509_value(cas, i);
115 if (X509_STORE_add_cert(ca_store, ca_cert) == 0) {
116 pkgerr_add(err, PKGERR_NOMEM, gettext(ERR_MEM));
117 ret = 1;
118 goto cleanup;
119 }
120 }
121
122 /* initialize context object used during the chain resolution */
123
124 if ((store_ctx = X509_STORE_CTX_new()) == NULL) {
125 pkgerr_add(err, PKGERR_NOMEM, gettext(ERR_MEM));
126 ret = 1;
127 goto cleanup;
128 }
129
130 (void) X509_STORE_CTX_init(store_ctx, ca_store, cert, clcerts);
131 /* attempt to verify the cert, which builds the cert chain */
132 if (X509_verify_cert(store_ctx) <= 0) {
133 pkgerr_add(err, PKGERR_CHAIN,
|
93 */
94 int
95 get_cert_chain(PKG_ERR *err, X509 *cert, STACK_OF(X509) *clcerts,
96 STACK_OF(X509) *cas, STACK_OF(X509) **chain)
97 {
98 X509_STORE_CTX *store_ctx = NULL;
99 X509_STORE *ca_store = NULL;
100 X509 *ca_cert = NULL;
101 int i;
102 int ret = 0;
103
104 if ((ca_store = X509_STORE_new()) == NULL) {
105 pkgerr_add(err, PKGERR_NOMEM,
106 gettext(ERR_MEM));
107 ret = 1;
108 goto cleanup;
109 }
110
111 /* add all ca certs into the store */
112 for (i = 0; i < sk_X509_num(cas); i++) {
113 ca_cert = sk_X509_value(cas, i);
114 if (X509_STORE_add_cert(ca_store, ca_cert) == 0) {
115 pkgerr_add(err, PKGERR_NOMEM, gettext(ERR_MEM));
116 ret = 1;
117 goto cleanup;
118 }
119 }
120
121 /* initialize context object used during the chain resolution */
122
123 if ((store_ctx = X509_STORE_CTX_new()) == NULL) {
124 pkgerr_add(err, PKGERR_NOMEM, gettext(ERR_MEM));
125 ret = 1;
126 goto cleanup;
127 }
128
129 (void) X509_STORE_CTX_init(store_ctx, ca_store, cert, clcerts);
130 /* attempt to verify the cert, which builds the cert chain */
131 if (X509_verify_cert(store_ctx) <= 0) {
132 pkgerr_add(err, PKGERR_CHAIN,
|