/*
SSSD - certificate handling utils - NSS version
The calls defined here should be useable outside of SSSD as well, e.g. in
libsss_certmap.
Copyright (C) Sumit Bose <sbose@redhat.com> 2017
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <nss.h>
#include <cert.h>
#include <base64.h>
#include <prerror.h>
#include <secport.h>
#include <secerr.h>
#include <prprf.h>
#include <prnetdb.h>
#include <talloc.h>
#include "util/crypto/sss_crypto.h"
#include "util/crypto/nss/nss_util.h"
#include "lib/certmap/sss_certmap.h"
#include "lib/certmap/sss_certmap_int.h"
* because CERT_AddAVA is not exported. I just renamed it and made it static
* to avoid issues if the call gets exported some time in future. */
static void **
{
unsigned count;
void **ap;
/* Count up number of slots already in use in the array */
count = 0;
if (ap) {
while (*ap++) {
count++;
}
}
if (array) {
(count + 1) * sizeof(void *),
(count + 2) * sizeof(void *));
} else {
}
if (array) {
}
return array;
}
static SECStatus
{
}
static SECItem *
{
int i;
for (i = 0;
i++)
return NULL;
}
const char ***_oids)
{
size_t c;
char *tmp_str;
int ret;
pool = PORT_NewArena(sizeof(double));
ext);
if (rv != SECSuccess) {
goto done;
}
}
return ENOMEM;
}
/* it is expected that NSS OID strings start with "OID." but we
* prefer the plain dotted-decimal version so the prefix is skipped */
goto done;
}
goto done;
}
}
ret = 0;
done:
if (ret == 0) {
} else {
}
return ret;
}
const char **rdn_str)
{
size_t c;
int ret;
goto done;
}
/* Multiple AVAs should be avoided because there is no general ordering
* rule and the RDN strings are not reproducible */
if (rv != SECSuccess) {
goto done;
}
}
goto done;
}
goto done;
}
goto done;
}
ret = 0;
done:
if (ret == 0) {
} else {
}
return ret;
}
const char ***rdn_list)
{
int ret;
size_t c;
goto done;
}
&(list[c]));
if (ret != 0) {
goto done;
}
}
ret = 0;
done:
if (ret == 0) {
} else {
}
return ret;
}
{
switch (type) {
case certOtherName:
return SAN_OTHER_NAME;
case certRFC822Name:
return SAN_RFC822_NAME;
case certDNSName:
return SAN_DNS_NAME;
case certX400Address:
return SAN_X400_ADDRESS;
case certDirectoryName:
return SAN_DIRECTORY_NAME;
case certEDIPartyName:
return SAN_EDIPART_NAME;
case certURI:
return SAN_URI;
case certIPAddress:
return SAN_IP_ADDRESS;
case certRegisterID:
return SAN_REGISTERED_ID;
default:
return SAN_INVALID;
}
}
/* taken from pkinit_crypto_nss.c of MIT Kerberos */
/* KerberosString: RFC 4120, 5.2.1. */
{
0,
NULL,
sizeof(SECItem),
}
};
/* Realm: RFC 4120, 5.2.2. */
struct realm {
};
{
0,
NULL,
sizeof(SECItem),
}
};
/* PrincipalName: RFC 4120, 5.2.2. */
{
0,
0,
}
};
struct principal_name {
};
{
0,
NULL,
sizeof(struct principal_name),
},
{
sizeof(SECItem),
},
{
sizeof(struct SECItem **),
},
{0, 0, NULL, 0},
};
/* KRB5PrincipalName: RFC 4556, 3.2.2. */
struct kerberos_principal_name {
};
{
0,
NULL,
sizeof(struct kerberos_principal_name),
},
{
sizeof(struct realm),
},
{
sizeof(struct principal_name),
},
{0, 0, NULL, 0}
};
{
int ret;
char *tmp_str;
/* it is expected that NSS OID strings start with "OID." but we
* prefer the plain dotted-decimal version so the prefix is skipped */
return EINVAL;
}
if (i == NULL) {
return ENOMEM;
}
if (i->other_name_oid == NULL) {
goto done;
}
goto done;
}
ret = 0;
done:
if (ret == 0) {
*item = i;
} else {
talloc_free(i);
}
return ret;
}
{
int ret;
if (rv != SECSuccess) {
return EINVAL;
}
if (i == NULL) {
return ENOMEM;
}
goto done;
}
if (ret != 0) {
goto done;
}
ret = 0;
done:
if (ret == 0) {
*item = i;
} else {
talloc_free(i);
}
return ret;
}
{
/* To avoid 'Wmissing-braces' warnings with older versions of
* gcc kerberos_principal_name cannot be initialized with { 0 }
* but must be initialized with memset().
*/
int ret;
size_t c;
if (rv != SECSuccess) {
return EINVAL;
}
if (i == NULL) {
return ENOMEM;
}
goto done;
}
if (c > 0) {
goto done;
}
}
goto done;
}
}
goto done;
}
if (ret != 0) {
goto done;
}
}
ret = 0;
done:
if (ret == 0) {
*item = i;
} else {
talloc_free(i);
}
return ret;
}
{
char *tmp_str;
/* it is expected that NSS OID strings start with "OID." but we
* prefer the plain dotted-decimal version so the prefix is skipped */
return EINVAL;
}
if (i == NULL) {
return ENOMEM;
}
talloc_free(i);
return ENOMEM;
}
*item = i;
return 0;
}
{
int ret;
if (i == NULL) {
return ENOMEM;
}
if (ret != 0) {
talloc_free(i);
return ret;
}
*item = i;
return 0;
}
{
struct san_list *i;
return EINVAL;
}
/* taken from secu_PrintIPAddress() */
if (len == 4) {
} else if (len == 16) {
/* convert to IPv4. */
}
} else {
return EINVAL;
}
if (st != PR_SUCCESS) {
return EIO;
}
if (i == NULL) {
return ENOMEM;
}
talloc_free(i);
return ENOMEM;
}
*item = i;
return 0;
}
{
int ret;
&subAltName);
if (rv != SECSuccess) {
if (rv == SECFailure
&& PORT_GetError() == SEC_ERROR_EXTENSION_NOT_FOUND) {
} else {
}
goto done;
}
goto done;
}
goto done;
}
do {
case certOtherName:
if (ret != 0) {
goto done;
}
&item_p);
if (ret != 0) {
goto done;
}
if (ret != 0) {
goto done;
}
}
if (ret != 0) {
goto done;
}
}
break;
case certRFC822Name:
case certDNSName:
case certURI:
if (ret != 0) {
goto done;
}
? '@' : '.'),
&(item->short_name));
if (ret != 0) {
goto done;
}
}
break;
case certIPAddress:
if (ret != 0) {
goto done;
}
break;
case certDirectoryName:
if (ret != 0) {
goto done;
}
break;
case certRegisterID:
if (ret != 0) {
goto done;
}
break;
case certX400Address:
case certEDIPartyName:
if (ret != 0) {
goto done;
}
break;
default:
goto done;
}
goto done;
}
done:
/* Don't free nameList, it's part of the arena. */
}
}
}
return ret;
}
struct sss_cert_content **content)
{
int ret;
return EINVAL;
}
return EIO;
}
return ENOMEM;
}
goto done;
}
goto done;
}
if (ret != 0) {
goto done;
}
goto done;
}
if (ret != 0) {
goto done;
}
&(cont->extended_key_usage_oids));
if (ret != 0) {
goto done;
}
if (ret != 0) {
goto done;
}
goto done;
}
done:
} else {
}
return ret;
}