TrustCore SDK NanoCert API reference  version 7.0
moccms.h
Go to the documentation of this file.
1 /*
2  * moccms.h
3  *
4  * Declarations and definitions for the Digicert CMS handling
5  *
6  * Copyright 2019-2024 DigiCert, Inc. All Rights Reserved.
7  * Proprietary and Confidential Material.
8  *
9  */
10 
25 #ifndef __MOCANA_CMS_HEADER__
26 #define __MOCANA_CMS_HEADER__
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
38 typedef enum MOC_CMS_ContentType
39 {
40  E_MOC_CMS_ct_undetermined = 0,
41  E_MOC_CMS_ct_data = 1,
42  E_MOC_CMS_ct_signedData = 2,
43  E_MOC_CMS_ct_envelopedData = 3,
44  E_MOC_CMS_ct_signedAndEnvelopedData = 4,
45  E_MOC_CMS_ct_digestedData = 5,
46  E_MOC_CMS_ct_encryptedData = 6,
47  E_MOC_CMS_ct_authData = 102,
48  E_MOC_CMS_ct_invalid = 999,
50 
54 typedef enum MOC_CMS_UpdateType
55 {
56  E_MOC_CMS_ut_invalid = 0,
57  E_MOC_CMS_ut_update = 1,
58  E_MOC_CMS_ut_final = 2,
59  E_MOC_CMS_ut_result = 3,
61 
65 typedef enum MOC_CMS_action
66 {
67  E_MOC_CMS_sa_none = 0,
68  E_MOC_CMS_sa_addCert = 1,
70 
74 typedef sbyte4 MOC_CMS_signerID;
75 
76 /* The value to identify 'all' signers */
77 #define MOC_CMS_signerID_ALL (-1)
78 
90 {
91  ubyte* pIssuer;
92  ubyte4 issuerLen;
93  ubyte* pSerialNumber;
94  ubyte4 serialNumberLen;
96 
114 {
115  ubyte* pAlgoOID;
116  ubyte4 algoOIDLen;
117  ubyte* pAlgoParameters;
118  ubyte4 algoParametersLen;
119  ubyte* pPublicKey;
120  ubyte4 publicKeyLen;
122 
127 {
128  ubyte* pIdentifier;
129  ubyte4 identifierLen;
131 
136 {
137  ubyte4 type;
138  union
139  {
140  MOC_CMS_IssuerSerialNumber issuerAndSerialNumber; /* type = NO_TAG */
141  MOC_CMS_SubjectKeyIdentifier subjectKeyIdentifier; /* type = 0 OCTETSTRING */
142  } u;
144 
149 {
150  ubyte4 type;
151  union
152  {
153  MOC_CMS_IssuerSerialNumber issuerAndSerialNumber; /* type = NO_TAG */
154  MOC_CMS_SubjectKeyIdentifier subjectKeyIdentifier; /* type = 0 OCTETSTRING */
155  MOC_CMS_OriginatorPublicKey originatorKey; /* type = 1 */
156  } u;
158 
163 typedef struct MOC_CMS_RecipientId
164 {
165  ubyte4 type;
166  union
167  {
168  MOC_CMS_KeyTransRecipientId ktrid; /* type = NO_TAG */
169  MOC_CMS_KeyAgreeRecipientId karid; /* type = 1 */
170 #if 0
171  MOC_CMS_KEKRecipientId kekrid; /* type = 2 */
172  MOC_CMS_PasswordRecipientId pwrdi; /* type = 3 */
173  MOC_CMS_OtherRecipientId orid; /* type = 4 */
174 #endif
175  } ri;
177 
184 typedef struct MOC_CMS_MsgSignInfo
185 {
186  ubyte* pASN1;
187  ubyte4 ASN1Len;
188  ubyte* pMsgSigDigest;
189  ubyte4 msgSigDigestLen;
190  intBoolean verifies;
191  TimeDate* pSigningTime;
193 
194 /* Recipient id tag value used to represent that the CMS id data was not tagged. */
195 #define NO_TAG (0xFFFFFFFF)
196 
204 typedef void* MOC_CMS_context;
205 
216 typedef MSTATUS (*MOC_CMS_GetPrivateKey)(const void* arg,
217  ubyte* pSerialNumber,
218  ubyte4 serialNumberLen,
219  ubyte* pIssuer,
220  ubyte4 issuerLen,
221  struct AsymmetricKey* pKey);
222 
230 typedef MSTATUS (*MOC_CMS_GetPrivateKeyEx)(const void* arg,
231  const MOC_CMS_RecipientId* pRecipientId,
232  struct AsymmetricKey* pKey);
233 
240 typedef MSTATUS (*MOC_CMS_ValidateRootCertificate)(const void* arg,
241  ubyte* pCertificate,
242  ubyte4 certificateLen,
243  MOC_CMS_MsgSignInfo *pSigInfo);
244 
252 typedef MSTATUS (*MOC_CMS_GetCertificate)(const void* arg,
253  ubyte* pSerialNumber,
254  ubyte4 serialNumberLen,
255  ubyte* pIssuer,
256  ubyte4 issuerLen,
257  ubyte** ppCertificate,
258  ubyte4* pCertificateLen);
259 
275 typedef MSTATUS (*MOC_CMS_UpdateData)(const void* arg,
276  MOC_CMS_context pCtx,
277  MOC_CMS_UpdateType type,
278  ubyte* pBuf,
279  ubyte4 bufLen);
280 
281 typedef struct MOC_CMS_Callbacks
282 {
287  MOC_CMS_GetPrivateKey getPrivKeyFun;
292  MOC_CMS_GetPrivateKeyEx getPrivKeyFunEx;
302  MOC_CMS_GetCertificate getCertFun;
307  MOC_CMS_UpdateData dataUpdateFun;
308 } MOC_CMS_Callbacks;
309 
327 MOC_EXTERN MSTATUS MOC_CMS_newContext (MOC_CMS_context* pNewContext,
328  const void* callbackArg,
329  const MOC_CMS_Callbacks* pCallbacks);
330 
366 MOC_EXTERN MSTATUS MOC_CMS_newContextOut (MOC_CMS_context *pNewContext,
367  MOC_CMS_ContentType type,
368  RNGFun rngFun,
369  void *rngFunArg,
370  intBoolean isStreaming,
371  const void *callbackArg,
372  MOC_CMS_UpdateData dataUpdateFun);
373 
391 MOC_EXTERN MSTATUS MOC_CMS_updateContext (MOC_CMS_context context,
392  const ubyte* input,
393  ubyte4 inputLen,
394  intBoolean* pFinished);
395 
412 MOC_EXTERN MSTATUS MOC_CMS_updateContextOut (MOC_CMS_context context,
413  const ubyte* output,
414  ubyte4 outputLen,
415  intBoolean last);
416 
429 MOC_EXTERN MSTATUS MOC_CMS_finalizeContextOut (MOC_CMS_context context);
430 
444 MOC_EXTERN MSTATUS MOC_CMS_deleteContext (MOC_CMS_context* pContext);
445 
460 MOC_EXTERN MSTATUS MOC_CMS_getContentType (MOC_CMS_context context,
461  MOC_CMS_ContentType* cmsContentType);
462 
479 MOC_EXTERN MSTATUS MOC_CMS_getCallbacks (MOC_CMS_context context,
480  MOC_CMS_Callbacks* pCB);
481 
496 MOC_EXTERN MSTATUS MOC_CMS_getNumRecipients (MOC_CMS_context context,
497  sbyte4* pNumRecipients);
498 
518 MOC_EXTERN MSTATUS MOC_CMS_getRecipientId (MOC_CMS_context context,
519  sbyte4 idxRecipient,
520  MOC_CMS_RecipientId* pRecipient);
521 
534 MOC_EXTERN MSTATUS MOC_CMS_deleteRecipientId (MOC_CMS_RecipientId* pRecipient);
535 
550 MOC_EXTERN MSTATUS MOC_CMS_getNumSigners (MOC_CMS_context context,
551  sbyte4* pNumSigners);
552 
573 MOC_EXTERN MSTATUS MOC_CMS_getSignerInfo (MOC_CMS_context context,
574  sbyte4 idxSigner,
575  MOC_CMS_MsgSignInfo* pSigner);
576 
591 MOC_EXTERN MSTATUS MOC_CMS_getNumSignatures (MOC_CMS_context context,
592  sbyte4* pNumSigs);
593 
606 MOC_EXTERN MSTATUS MOC_CMS_deleteSignerInfo (MOC_CMS_MsgSignInfo* pSigner);
607 
625 MOC_EXTERN MSTATUS MOC_CMS_getCertificates (MOC_CMS_context context,
626  const ubyte **ppCerts,
627  ubyte4 *pCertLen);
628 
646 MOC_EXTERN MSTATUS MOC_CMS_getCRLs (MOC_CMS_context context,
647  const ubyte **ppCRLs,
648  ubyte4 *pCRLsLen);
649 
664 MOC_EXTERN MSTATUS MOC_CMS_getNumDigests (MOC_CMS_context context,
665  ubyte4* pNumDigests);
666 
686 MOC_EXTERN MSTATUS MOC_CMS_getDigestID (MOC_CMS_context context,
687  ubyte4 idx,
688  const ubyte** pDigestAlgoOID);
689 
711 MOC_EXTERN MSTATUS MOC_CMS_setPayloadLength (MOC_CMS_context context,
712  ubyte4 len);
713 
740 MOC_EXTERN MSTATUS MOC_CMS_addSigner (MOC_CMS_context context,
741  ubyte* pCert,
742  ubyte4 certLen,
743  const AsymmetricKey* pKey,
744  const ubyte* pDigestAlgoOID,
745  ubyte4 digestAlgoOIDLen,
746  MOC_CMS_action action,
747  MOC_CMS_signerID *pSignID);
748 
773 MOC_EXTERN MSTATUS MOC_CMS_addSignerAttribute (MOC_CMS_context context,
774  MOC_CMS_signerID signId,
775  const ubyte* idOID,
776  ubyte4 oidLen,
777  ubyte4 typeID,
778  const ubyte* value,
779  ubyte4 valueLen,
780  intBoolean authenticated);
781 
799 MOC_EXTERN MSTATUS MOC_CMS_addCertificate (MOC_CMS_context context,
800  ubyte* pCert,
801  ubyte4 certLen);
802 
820 MOC_EXTERN MSTATUS MOC_CMS_addCRL (MOC_CMS_context context,
821  ubyte* pCRL,
822  ubyte4 CRLLen);
823 
844 MOC_EXTERN MSTATUS MOC_CMS_addSignatureRaw (MOC_CMS_context context,
845  const ubyte* pSig,
846  ubyte4 sigLen);
847 
868 MOC_EXTERN MSTATUS MOC_CMS_addDigest (MOC_CMS_context context,
869  const ubyte* digestAlgoOID,
870  ubyte4 digestAlgoOIDLen);
871 
893 MOC_EXTERN MSTATUS MOC_CMS_setEncryption (MOC_CMS_context context,
894  const ubyte* encryptAlgoOID,
895  ubyte4 encryptAlgoOIDLen,
896  RNGFun rngFun,
897  void* rngFunArg);
898 
916 MOC_EXTERN MSTATUS MOC_CMS_addRecipient (MOC_CMS_context context,
917  const ubyte* pCert,
918  ubyte4 certLen);
919 
941 MOC_EXTERN MSTATUS MOC_CMS_addUnprotectedAttribute (MOC_CMS_context context,
942  const ubyte* idOID,
943  ubyte4 oidLen,
944  ubyte4 typeID,
945  const ubyte* value,
946  ubyte4 valueLen);
947 
948 #ifdef __cplusplus
949 }
950 #endif
951 
952 #endif /* __MOCANA_CMS_HEADER__ */
MSTATUS(* MOC_CMS_UpdateData)(const void *arg, MOC_CMS_context pCtx, MOC_CMS_UpdateType type, ubyte *pBuf, ubyte4 bufLen)
Callback type when the CMS engine has acquired payload data and intends to pass it on to user code...
Definition: moccms.h:275
MOC_EXTERN MSTATUS MOC_CMS_addDigest(MOC_CMS_context context, const ubyte *digestAlgoOID, ubyte4 digestAlgoOIDLen)
Add a digest to the CMS output context, should it not exits.
MOC_EXTERN MSTATUS MOC_CMS_setPayloadLength(MOC_CMS_context context, ubyte4 len)
Sets the pay load length for the CMS output context.
MOC_EXTERN MSTATUS MOC_CMS_finalizeContextOut(MOC_CMS_context context)
Finalize CMS output and flush all data.
MOC_EXTERN MSTATUS MOC_CMS_getCRLs(MOC_CMS_context context, const ubyte **ppCRLs, ubyte4 *pCRLsLen)
Return the CRLs inside the CMS data context.
The 'SubjectKeyIdentifier' of a certificate.
Definition: moccms.h:126
MOC_CMS_action
Action type when adding a certificate to the output CMS.
Definition: moccms.h:65
MOC_EXTERN MSTATUS MOC_CMS_deleteRecipientId(MOC_CMS_RecipientId *pRecipient)
Delete an instance of 'MOC_CMS_RecipientId'.
The general 'RecipientId' structure for all CMS recipient data.
Definition: moccms.h:163
MOC_EXTERN MSTATUS MOC_CMS_addUnprotectedAttribute(MOC_CMS_context context, const ubyte *idOID, ubyte4 oidLen, ubyte4 typeID, const ubyte *value, ubyte4 valueLen)
Add an attribute to the CMS output context.
MOC_EXTERN MSTATUS MOC_CMS_getCallbacks(MOC_CMS_context context, MOC_CMS_Callbacks *pCB)
Return the values inside the callback structure.
MOC_EXTERN MSTATUS MOC_CMS_getCertificates(MOC_CMS_context context, const ubyte **ppCerts, ubyte4 *pCertLen)
Return the certificates inside the CMS data context.
MOC_EXTERN MSTATUS MOC_CMS_deleteSignerInfo(MOC_CMS_MsgSignInfo *pSigner)
Delete an instance of 'MOC_CMS_MsgSignInfo'.
MOC_EXTERN MSTATUS MOC_CMS_getNumSigners(MOC_CMS_context context, sbyte4 *pNumSigners)
Return the number of signers, if applicable.
MOC_EXTERN MSTATUS MOC_CMS_addSigner(MOC_CMS_context context, ubyte *pCert, ubyte4 certLen, const AsymmetricKey *pKey, const ubyte *pDigestAlgoOID, ubyte4 digestAlgoOIDLen, MOC_CMS_action action, MOC_CMS_signerID *pSignID)
Add a 'signer' to the CMS output context.
void * MOC_CMS_context
Definition: moccms.h:204
The 'signer info' structure.
Definition: moccms.h:184
MOC_EXTERN MSTATUS MOC_CMS_updateContextOut(MOC_CMS_context context, const ubyte *output, ubyte4 outputLen, intBoolean last)
Add pay load data to the context for CMS output.
MOC_EXTERN MSTATUS MOC_CMS_getRecipientId(MOC_CMS_context context, sbyte4 idxRecipient, MOC_CMS_RecipientId *pRecipient)
Return the recipient id for 'idxRecipient' value, if applicable.
MOC_EXTERN MSTATUS MOC_CMS_newContext(MOC_CMS_context *pNewContext, const void *callbackArg, const MOC_CMS_Callbacks *pCallbacks)
Create a new context to parse a CMS.
MSTATUS(* MOC_CMS_GetPrivateKeyEx)(const void *arg, const MOC_CMS_RecipientId *pRecipientId, struct AsymmetricKey *pKey)
Callback type when the CMS engine needs the private key data identified by the given MOC_CMS_Recipien...
Definition: moccms.h:230
The 'originatorKey' of a certificate, as defined in RFC-5652 for the 'KeyAgreeRecipientInfo' sequence...
Definition: moccms.h:113
MOC_EXTERN MSTATUS MOC_CMS_getSignerInfo(MOC_CMS_context context, sbyte4 idxSigner, MOC_CMS_MsgSignInfo *pSigner)
Return the signing info for 'idxSigner' value, if applicable.
MOC_EXTERN MSTATUS MOC_CMS_addSignatureRaw(MOC_CMS_context context, const ubyte *pSig, ubyte4 sigLen)
Add a 'raw' signature to the CMS output context.
MOC_EXTERN MSTATUS MOC_CMS_getNumSignatures(MOC_CMS_context context, sbyte4 *pNumSigs)
Return the number of signatures, if applicable.
MOC_EXTERN MSTATUS MOC_CMS_addRecipient(MOC_CMS_context context, const ubyte *pCert, ubyte4 certLen)
Add a 'recipient' to the CMS output context.
MOC_EXTERN MSTATUS MOC_CMS_getContentType(MOC_CMS_context context, MOC_CMS_ContentType *cmsContentType)
Return the value of type 'CMS_ContentType'.
The 'RecipientId' structure for the 'KeyTrans' type.
Definition: moccms.h:135
The 'issuer' and 'serial number' of a certificate.
Definition: moccms.h:89
MSTATUS(* MOC_CMS_ValidateRootCertificate)(const void *arg, ubyte *pCertificate, ubyte4 certificateLen, MOC_CMS_MsgSignInfo *pSigInfo)
Callback type when the CMS engine needs to validate a certificate with the user.
Definition: moccms.h:240
MOC_EXTERN MSTATUS MOC_CMS_deleteContext(MOC_CMS_context *pContext)
Delete the context.
MOC_EXTERN MSTATUS MOC_CMS_getDigestID(MOC_CMS_context context, ubyte4 idx, const ubyte **pDigestAlgoOID)
Return the OID value for a digest, if applicable.
MOC_EXTERN MSTATUS MOC_CMS_newContextOut(MOC_CMS_context *pNewContext, MOC_CMS_ContentType type, RNGFun rngFun, void *rngFunArg, intBoolean isStreaming, const void *callbackArg, MOC_CMS_UpdateData dataUpdateFun)
Create a new context to output data in a CMS format.
MOC_CMS_ContentType
Content type of a received or created CMS.
Definition: moccms.h:38
The 'RecipientId' structure for the 'KeyAgree' type.
Definition: moccms.h:148
MOC_EXTERN MSTATUS MOC_CMS_addCertificate(MOC_CMS_context context, ubyte *pCert, ubyte4 certLen)
Add a certificate to the CMS output context.
MOC_EXTERN MSTATUS MOC_CMS_getNumDigests(MOC_CMS_context context, ubyte4 *pNumDigests)
Return the number of digests, if applicable.
MOC_EXTERN MSTATUS MOC_CMS_getNumRecipients(MOC_CMS_context context, sbyte4 *pNumRecipients)
Return the number of recipients, if applicable.
MOC_EXTERN MSTATUS MOC_CMS_addCRL(MOC_CMS_context context, ubyte *pCRL, ubyte4 CRLLen)
Add a certificate revocation list to the CMS output context.
MOC_EXTERN MSTATUS MOC_CMS_addSignerAttribute(MOC_CMS_context context, MOC_CMS_signerID signId, const ubyte *idOID, ubyte4 oidLen, ubyte4 typeID, const ubyte *value, ubyte4 valueLen, intBoolean authenticated)
Add an attribute to the CMS output context.
MOC_EXTERN MSTATUS MOC_CMS_setEncryption(MOC_CMS_context context, const ubyte *encryptAlgoOID, ubyte4 encryptAlgoOIDLen, RNGFun rngFun, void *rngFunArg)
Sets the encryption algorithm for the CMS output context.
sbyte4 MOC_CMS_signerID
The type for a signer's ID value.
Definition: moccms.h:74
MOC_CMS_UpdateType
Payload update type.
Definition: moccms.h:54
MSTATUS(* MOC_CMS_GetPrivateKey)(const void *arg, ubyte *pSerialNumber, ubyte4 serialNumberLen, ubyte *pIssuer, ubyte4 issuerLen, struct AsymmetricKey *pKey)
Callback type when the CMS engine needs the private key data identified by the given serial number an...
Definition: moccms.h:216
MOC_EXTERN MSTATUS MOC_CMS_updateContext(MOC_CMS_context context, const ubyte *input, ubyte4 inputLen, intBoolean *pFinished)
Add CMS message data to the context.
MSTATUS(* MOC_CMS_GetCertificate)(const void *arg, ubyte *pSerialNumber, ubyte4 serialNumberLen, ubyte *pIssuer, ubyte4 issuerLen, ubyte **ppCertificate, ubyte4 *pCertificateLen)
Callback type when the CMS engine needs the public certificate data identified by the given serial nu...
Definition: moccms.h:252