(mozilla-projects-nss-cert-findcertbyissuerandsn)=

# CERT_FindCertByIssuerAndSN

:::{container}
Find a certificate in the database with the given issuer and serial number.
:::

## Syntax

:::{container}

```{code}
#include <cert.h>
CERTCertificate *CERT_FindCertByIssuerAndSN (

    CERTCertDBHandle *handle,
    CERTIssuerAndSN *issuerAndSN            );
```

:::

## Parameters

:::{container}

```{eval-rst}
+-----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``handle``      | *in* pointer to a `CERTCertDBHandle </en-US/NSS/CERTCertDBHandle>`__ representing the certificate database to look in                                            |
|                 |                                                                                                                                                                  |
+-----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``issuerAndSN`` | *in* pointer to a `CERTIssuerAndSN </en-US/NSS/CERTIssuerAndSN>`__ that must be properly formed to contain the issuer name and the serial number (see [Example]) |
|                 |                                                                                                                                                                  |
|                 |                                                                                                                                                                  |
+-----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
```

:::

## Description

:::{container}
This function creates a certificate key using the `issuerAndSN` and it then uses the key to
find the matching certificate in the database.
:::

## Returns

:::{container}
A pointer to a [CERTCertificate](/en-US/NSS/CERTCertificate) representing the certificate in
the database that matched the issuer and serial number, or `NULL` if none was found. The
certificate is a shallow copy, use
[CERT_DestroyCertificate](/en-US/NSS/CERT_DestroyCertificate) to decrement the reference count
on the certificate instance.
:::

## Example

:::{container}

```{code}
CERTIssuerAndSN issuerSN;
issuerSN.derIssuer.data = caName->data;
issuerSN.derIssuer.len = caName->len;
issuerSN.serialNumber.data = authorityKeyID->authCertSerialNumber.data;
issuerSN.serialNumber.len = authorityKeyID->authCertSerialNumber.len;
issuerCert = CERT_FindCertByIssuerAndSN(cert->dbhandle, &issuerSN);
if ( issuerCert == NULL ) {
    PORT_SetError (SEC_ERROR_UNKNOWN_ISSUER);
}
```

:::

## See Also

:::{container}
Occurrences of
`` `CERT_FindCertByIssuerAndSN `` \<<http://lxr.mozilla.org/security/ident?i=CERT_FindCertByIssuerAndSN>>\`\_\_
in the current NSS source code (generated by [LXR](http://lxr.mozilla.org/security/)).
:::
