tfPkiCertificateAdd

Jump to: navigation, search

Table of Contents >> Optional Protocols >> Cryptography


#include <trsecapi.h>


int tfPkiCertificateAdd (
ttUserVoidPtr fileNamePtr,
int typeFormat,
int typeHeader,
ttUserVoidPtr idPtr,
int idLength,
ttUserVoidPtr caIdPtr
);


Function Description

This function adds an entry to the certificate database. The user must define TM_USE_PKI to use this function. If a certificate needs to be verified (the use must NOT define TM_PKI_CERT_NOT_VERIFY). The CA's certificate chain must be added before the certificate is added. In addition, to add a local certificate, tfPkiOwnKeyPairAdd() must be called first in order to add the private/public key pair for that local certificate. If multiple local certificates are going to be added, the user needs to call the functions in the following order:

tfPkiOwnKeyPairAdd(keypair1);
tfPkiCertificateAdd(certificate1);
tfPkiOwnKeyPairAdd(keypair2);
tfPkiCertificateAdd(certificate2);
...and so on.



Parameters

  • fileNamePtr
    Pointer to a certificate file name with directory information or PEM string of the certificate according to the 'typeFormat' value. Treck PKI currently supports PEM and DER certificate file formats, and the user must have a file system.
  • typeFormat
    The type and format of 'fileNamePtr' (see below).
  • typeHeader
    The certificate holder type flags (see below).
  • idPtr
    A pointer to the ID of this certificate.
  • idLength
    The length of the ID.
  • caIdPtr
    Pointer to the ID of the CA. If it is non-NULL, PKI will search the existing certificate database using this identification. If it is NULL, then Treck PKI will search the existing certificate database using the distinguished name. This search could result in nothing, in which case TM_CERTFLAG_UNKNOWNCA error will be returned unless TM_PKI_CERT_ROOTCA flag is set in 'certType'.


Possible 'typeFormat' Values

Name Value Description
TM_PKI_CERTIFICATE_PEM (ttUser8Bit)0x01 Certificate with PEM (Privacy Enhanced Mail) format.
TM_PKI_CERTIFICATE_DER (ttUser8Bit)0x02 Certificate with DER encoding format.
TM_PKI_CERTIFICATE_STRING (ttUser8Bit)0x04 The 'fileNamePtr' variable points to a string instead of a file. If this flag is used then the string should only contain the characters between the -----BEGIN... and -----END... tags.

Possible 'certType' Values

Name Value Description
TM_PKI_CERT_LOCAL (ttUser8Bit)0x01 This certificate is local.
TM_PKI_CERT_NONLOCAL (ttUser8Bit)0x02 This certificate is a general one (i.e. a CA or a peer's certificate).
TM_PKI_CERT_CRL (ttUser8Bit)0x04 This is a CRL (Certificate Revocation List).
TM_PKI_CERT_ROOTCA (ttUser8Bit)0x08 This certificate is a root CA's certificate. This must be used in conjunction with the TM_PKI_CERT_NONLOCAL flag.


Returns

  • TM_ENOERROR
    Success.
  • (Other)
    Any combination of the following flags:
  • TM_CERTFLAG_BADCERT (0x01): Critical error
  • TM_CERTFLAG_REVOKED (0x02): Revoked certificate
  • TM_CERTFLAG_EXPIRED (0x04): Expired certificate
  • TM_CERTFLAG_UNMATCHED (0x08): Identity not matched
  • TM_CERTFLAG_UNKNOWNCA (0x10): CA unknown
  • TM_CERTFLAG_NOTVERIFIED (0x20): Issuer CA fails to verify the certificate


Table of Contents >> Optional Protocols >> Cryptography