Guardtime KSI c SDK
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ksi.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013-2015 Guardtime, Inc.
3  *
4  * This file is part of the Guardtime client SDK.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License").
7  * You may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  * http://www.apache.org/licenses/LICENSE-2.0
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES, CONDITIONS, OR OTHER LICENSES OF ANY KIND, either
13  * express or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  * "Guardtime" and "KSI" are trademarks or registered trademarks of
16  * Guardtime, Inc., and no license to trademarks is granted; Guardtime
17  * reserves and retains all trademark rights.
18  */
19 
20 #ifndef _KSI_BASE_H_
21 #define _KSI_BASE_H_
22 
23 #include <stdio.h>
24 #include <stdint.h>
25 
26 #include "version.h"
27 #include "types.h"
28 #include "hash.h"
29 #include "publicationsfile.h"
30 #include "log.h"
31 #include "signature.h"
32 #include "verification.h"
33 #include "policy.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
48 /* RETURN CODES WHICH ARE NOT ERRORS */
49  KSI_OK = 0,
50 
71 
72 /* SYNTAX ERRORS */
124  /*
125  * The hash algorithm has been marked as deprecated at given time.
126  */
128  /*
129  * The hash algorithm has been marked as obsolete at given time.
130  */
132 /* SYSTEM ERRORS */
140  KSI_IO_ERROR = 0x201,
160  KSI_HTTP_ERROR = 0x206,
187 
192 
197 
202 
207 
212 
217 
222 
223  /* Generic service errors. */
224 
253 
254  /* Aggregator errors. */
255 
277 
282 
283  /* Extender status codes. */
284 
305 
310 
315 
320 
321  /* Async status codes. */
322 
327 
332 
333 
338 };
339 
344  KSI_ENUM_DEPRECATED(KSI_PDU_VERSION_1, Only PDU v2 is supported.) = 1,
346 };
347 
348 #define KSI_CTX_PUBFILE_CACHE_DEFAULT_TTL (8 * 60 * 60)
349 
350 #define KSI_CTX_HA_MAX_SUBSERVICES 3
351 
358 typedef int (*KSI_Config_Callback)(KSI_CTX *ctx, KSI_Config *conf);
359 
360 typedef enum KSI_Option_en {
373 
384 
390 
405 
414 
423 
425 } KSI_Option;
426 
432 const char *KSI_getVersion(void);
433 
443 const char *KSI_getErrorString(int statusCode);
444 
456 int KSI_CTX_new(KSI_CTX **ctx);
457 
465 void KSI_CTX_free(KSI_CTX *ctx);
466 
481 int KSI_CTX_registerGlobals(KSI_CTX *ctx, int (*initFn)(void), void (*cleanupFn)(void));
482 
491 int KSI_ERR_statusDump(KSI_CTX *ctx, FILE *f);
492 
501 char *KSI_ERR_toString(KSI_CTX *ctx, char *buf, size_t buf_len);
502 
515 int KSI_ERR_getBaseErrorMessage(KSI_CTX *ctx, char *buf, size_t len, int *error, int *ext);
516 
524 void *KSI_malloc(size_t size);
525 
534 void *KSI_calloc(size_t num, size_t size);
535 
540 void KSI_free(void *ptr);
541 
551 
552 #define KSI_sendSignRequest(ctx, request, handle) KSI_sendAggregatorRequest(ctx, request, handle)
553 
562 int KSI_sendExtenderRequest(KSI_CTX *ctx, KSI_ExtendReq *request, KSI_RequestHandle **handle);
563 
564 #define KSI_sendExtendRequest(ctx, request, handle) KSI_sendExtenderRequest(ctx, request, handle)
565 
575 int KSI_sendPublicationRequest(KSI_CTX *ctx, const unsigned char *request, size_t request_length, KSI_RequestHandle **handle);
576 
594 
603 
611 
618 int KSI_receiveExtenderConfig(KSI_CTX *ctx, KSI_Config **config);
619 
628 
637 int KSI_verifyDataHash(KSI_CTX *ctx, KSI_Signature *sig, const KSI_DataHash *hsh);
647 int KSI_createSignature(KSI_CTX *ctx, KSI_DataHash *dataHash, KSI_Signature **sig);
648 
661 int KSI_extendSignatureWithPolicy(KSI_CTX *ctx, const KSI_Signature *sig, const KSI_Policy *policy, KSI_VerificationContext *context, KSI_Signature **extended);
662 
663 #define KSI_extendSignature(ctx, sig, extended) KSI_extendSignatureWithPolicy(ctx, sig, KSI_VERIFICATION_POLICY_INTERNAL, NULL, extended)
664 
673 int KSI_CTX_setLogLevel(KSI_CTX *ctx, int level);
674 
686 int KSI_CTX_setLoggerCallback(KSI_CTX *ctx, KSI_LoggerCallback cb, void *logCtx);
687 
697 
705 int KSI_CTX_setPublicationUrl(KSI_CTX *ctx, const char *uri);
706 
715 int KSI_CTX_setExtender(KSI_CTX *ctx, const char *uri, const char *loginId, const char *key);
716 
725 int KSI_CTX_setAggregator(KSI_CTX *ctx, const char *uri, const char *loginId, const char *key);
726 
736 int KSI_CTX_setOption(KSI_CTX *ctx, KSI_Option opt, void *param);
737 
738 #define KSI_CTX_setAggregatorHmacAlgorithm(ctx, alg_id) KSI_CTX_setOption(ctx, KSI_OPT_AGGR_HMAC_ALGORITHM, (void*)(alg_id))
739 #define KSI_CTX_setExtenderHmacAlgorithm(ctx, alg_id) KSI_CTX_setOption(ctx, KSI_OPT_EXT_HMAC_ALGORITHM, (void*)(alg_id))
740 
745 #define KSI_CTX_FLAG_AGGR_PDU_VER KSI_OPT_AGGR_PDU_VER
746 #define KSI_CTX_FLAG_EXT_PDU_VER KSI_OPT_EXT_PDU_VER
747 #define KSI_CtxFlag KSI_Option_en
748 #define KSI_CTX_setFlag(ctx, flag, param) KSI_CTX_setOption((ctx), (flag), (param))
749 
756 int KSI_CTX_setTransferTimeoutSeconds(KSI_CTX *ctx, int timeout);
757 
764 int KSI_CTX_setConnectionTimeoutSeconds(KSI_CTX *ctx, int timeout);
765 
773 
781 
789 
791 
792 #define KSI_CERT_EMAIL "1.2.840.113549.1.9.1"
793 #define KSI_CERT_COMMON_NAME "2.5.4.3"
794 #define KSI_CERT_COUNTRY "2.5.4.6"
795 #define KSI_CERT_ORGANIZATION "2.5.4.10"
796 
817 
825 
833 
842 int KSI_CTX_getPublicationCertEmail(KSI_CTX *ctx, const char **address);
843 
852 
856 #ifdef __cplusplus
857 }
858 #endif
859 
860 #endif
Definition: ksi.h:95
Definition: ksi.h:206
Definition: ksi.h:144
Definition: ksi.h:156
int KSI_receiveAggregatorConfig(KSI_CTX *ctx, KSI_Config **config)
enum KSI_Option_en KSI_Option
Definition: ksi.h:172
Definition: ksi.h:140
const KSI_Policy * KSI_VERIFICATION_POLICY_EMPTY
int KSI_CTX_getPublicationsFile(KSI_CTX *ctx, KSI_PublicationsFile **var)
int KSI_CTX_setRequestHeaderCallback(KSI_CTX *ctx, KSI_RequestHeaderCallback cb)
const char * KSI_getVersion(void)
Definition: ksi.h:196
int KSI_sendAggregatorRequest(KSI_CTX *ctx, KSI_AggregationReq *request, KSI_RequestHandle **handle)
char * KSI_ERR_toString(KSI_CTX *ctx, char *buf, size_t buf_len)
int KSI_CTX_getPKITruststore(KSI_CTX *ctx, KSI_PKITruststore **pki)
Definition: ksi.h:136
int(* KSI_LoggerCallback)(void *logCtx, int level, const char *message)
Definition: types_base.h:115
int KSI_CTX_registerGlobals(KSI_CTX *ctx, int(*initFn)(void), void(*cleanupFn)(void))
Definition: ksi.h:49
int KSI_CTX_setConnectionTimeoutSeconds(KSI_CTX *ctx, int timeout)
Definition: ksi.h:326
Definition: ksi.h:54
struct KSI_PublicationsFile_st KSI_PublicationsFile
Definition: publicationsfile.h:45
Definition: ksi.h:123
Definition: ksi.h:148
Definition: ksi.h:344
Definition: ksi.h:383
Definition: ksi.h:107
KSI_StatusCode
Definition: ksi.h:47
struct KSI_NetHandle_st KSI_RequestHandle
Definition: types.h:115
int KSI_sendPublicationRequest(KSI_CTX *ctx, const unsigned char *request, size_t request_length, KSI_RequestHandle **handle)
int KSI_CTX_setTransferTimeoutSeconds(KSI_CTX *ctx, int timeout)
int KSI_verifySignature(KSI_CTX *ctx, KSI_Signature *sig)
void KSI_CTX_free(KSI_CTX *ctx)
int KSI_extendSignatureWithPolicy(KSI_CTX *ctx, const KSI_Signature *sig, const KSI_Policy *policy, KSI_VerificationContext *context, KSI_Signature **extended)
const char * KSI_getErrorString(int statusCode)
int KSI_CTX_setAggregator(KSI_CTX *ctx, const char *uri, const char *loginId, const char *key)
struct KSI_ExtendReq_st KSI_ExtendReq
Definition: types.h:54
Definition: ksi.h:228
int KSI_verifyPublicationsFile(KSI_CTX *ctx, const KSI_PublicationsFile *pubFile)
Definition: ksi.h:131
void * KSI_malloc(size_t size)
#define KSI_CERT_EMAIL
Definition: ksi.h:792
int KSI_CTX_getPublicationCertEmail(KSI_CTX *ctx, const char **address)
Definition: ksi.h:176
int KSI_sendExtenderRequest(KSI_CTX *ctx, KSI_ExtendReq *request, KSI_RequestHandle **handle)
struct KSI_DataHash_st KSI_DataHash
Definition: hash.h:52
int KSI_ERR_statusDump(KSI_CTX *ctx, FILE *f)
struct KSI_AggregationReq_st KSI_AggregationReq
Definition: types.h:51
Definition: ksi.h:115
int KSI_CTX_setPublicationCertEmail(KSI_CTX *ctx, const char *email)
Definition: ksi.h:424
int KSI_CTX_setNetworkProvider(KSI_CTX *ctx, KSI_NetworkClient *net)
int KSI_CTX_new(KSI_CTX **ctx)
#define KSI_FN_DEPRECATED(decl, comment)
Definition: common.h:50
void * KSI_calloc(size_t num, size_t size)
Definition: ksi.h:372
Definition: ksi.h:337
struct KSI_Config_st KSI_Config
Definition: types.h:50
Definition: ksi.h:221
int KSI_CTX_setOption(KSI_CTX *ctx, KSI_Option opt, void *param)
Definition: ksi.h:248
void KSI_free(void *ptr)
Definition: ksi.h:216
Definition: ksi.h:152
Definition: ksi.h:58
int KSI_CTX_setLogLevel(KSI_CTX *ctx, int level)
Definition: ksi.h:378
int KSI_CTX_setExtender(KSI_CTX *ctx, const char *uri, const char *loginId, const char *key)
Definition: ksi.h:422
Definition: ksi.h:331
Definition: types.h:150
Definition: ksi.h:186
struct KSI_Signature_st KSI_Signature
Definition: types.h:67
Definition: ksi.h:99
Definition: ksi.h:345
int KSI_CTX_setLoggerCallback(KSI_CTX *ctx, KSI_LoggerCallback cb, void *logCtx)
Definition: policy.h:31
Definition: ksi.h:252
Definition: ksi.h:103
KSI_PDUver_en
Definition: ksi.h:343
int(* KSI_Config_Callback)(KSI_CTX *ctx, KSI_Config *conf)
Definition: ksi.h:358
int KSI_CTX_setPublicationsFile(KSI_CTX *ctx, KSI_PublicationsFile *var)
Definition: ksi.h:127
Definition: ksi.h:111
struct KSI_Policy_st KSI_Policy
Definition: types.h:70
Definition: ksi.h:389
int KSI_createSignature(KSI_CTX *ctx, KSI_DataHash *dataHash, KSI_Signature **sig)
KSI_Option_en
Definition: ksi.h:360
int KSI_ERR_getBaseErrorMessage(KSI_CTX *ctx, char *buf, size_t len, int *error, int *ext)
Definition: ksi.h:201
struct KSI_CTX_st KSI_CTX
Definition: types_base.h:124
Definition: ksi.h:244
int KSI_receivePublicationsFile(KSI_CTX *ctx, KSI_PublicationsFile **pubFile)
int(* KSI_RequestHeaderCallback)(KSI_Header *hdr)
Definition: types.h:83
int KSI_CTX_setDefaultPubFileCertConstraints(KSI_CTX *ctx, const KSI_CertConstraint *arr)
Definition: ksi.h:211
Definition: ksi.h:160
struct KSI_PKITruststore_st KSI_PKITruststore
Definition: types.h:103
Definition: ksi.h:119
Definition: ksi.h:272
Definition: ksi.h:240
struct KSI_NetworkClient_st KSI_NetworkClient
Definition: types.h:121
Definition: ksi.h:82
Definition: ksi.h:236
int KSI_CTX_getLastFailedSignature(KSI_CTX *ctx, KSI_Signature **lastFailedSignature)
Definition: ksi.h:87
int KSI_receiveExtenderConfig(KSI_CTX *ctx, KSI_Config **config)
Definition: ksi.h:91
Definition: ksi.h:164
Definition: ksi.h:191
Definition: ksi.h:366
int KSI_verifyDataHash(KSI_CTX *ctx, KSI_Signature *sig, const KSI_DataHash *hsh)
int KSI_CTX_setPublicationUrl(KSI_CTX *ctx, const char *uri)
int KSI_CTX_setPKITruststore(KSI_CTX *ctx, KSI_PKITruststore *pki)
Definition: ksi.h:70
Definition: ksi.h:77