1ZCERT(3)                          CZMQ Manual                         ZCERT(3)
2
3
4

NAME

6       zcert - work with CURVE security certificates
7

SYNOPSIS

9       //  This is a stable class, and may not change except for emergencies. It
10       //  is provided in stable builds.
11       //  This class has draft methods, which may change over time. They are not
12       //  in stable releases, by default. Use --enable-drafts to enable.
13       //  Create and initialize a new certificate in memory
14       CZMQ_EXPORT zcert_t *
15           zcert_new (void);
16
17       //  Accepts public/secret key pair from caller
18       CZMQ_EXPORT zcert_t *
19           zcert_new_from (const byte *public_key, const byte *secret_key);
20
21       //  Load certificate from file
22       CZMQ_EXPORT zcert_t *
23           zcert_load (const char *filename);
24
25       //  Destroy a certificate in memory
26       CZMQ_EXPORT void
27           zcert_destroy (zcert_t **self_p);
28
29       //  Return public part of key pair as 32-byte binary string
30       CZMQ_EXPORT const byte *
31           zcert_public_key (zcert_t *self);
32
33       //  Return secret part of key pair as 32-byte binary string
34       CZMQ_EXPORT const byte *
35           zcert_secret_key (zcert_t *self);
36
37       //  Return public part of key pair as Z85 armored string
38       CZMQ_EXPORT const char *
39           zcert_public_txt (zcert_t *self);
40
41       //  Return secret part of key pair as Z85 armored string
42       CZMQ_EXPORT const char *
43           zcert_secret_txt (zcert_t *self);
44
45       //  Set certificate metadata from formatted string.
46       CZMQ_EXPORT void
47           zcert_set_meta (zcert_t *self, const char *name, const char *format, ...) CHECK_PRINTF (3);
48
49       //  Get metadata value from certificate; if the metadata value doesn't
50       //  exist, returns NULL.
51       CZMQ_EXPORT const char *
52           zcert_meta (zcert_t *self, const char *name);
53
54       //  Get list of metadata fields from certificate. Caller is responsible for
55       //  destroying list. Caller should not modify the values of list items.
56       CZMQ_EXPORT zlist_t *
57           zcert_meta_keys (zcert_t *self);
58
59       //  Save full certificate (public + secret) to file for persistent storage
60       //  This creates one public file and one secret file (filename + "_secret").
61       CZMQ_EXPORT int
62           zcert_save (zcert_t *self, const char *filename);
63
64       //  Save public certificate only to file for persistent storage
65       CZMQ_EXPORT int
66           zcert_save_public (zcert_t *self, const char *filename);
67
68       //  Save secret certificate only to file for persistent storage
69       CZMQ_EXPORT int
70           zcert_save_secret (zcert_t *self, const char *filename);
71
72       //  Apply certificate to socket, i.e. use for CURVE security on socket.
73       //  If certificate was loaded from public file, the secret key will be
74       //  undefined, and this certificate will not work successfully.
75       CZMQ_EXPORT void
76           zcert_apply (zcert_t *self, void *socket);
77
78       //  Return copy of certificate; if certificate is NULL or we exhausted
79       //  heap memory, returns NULL.
80       //  Caller owns return value and must destroy it when done.
81       CZMQ_EXPORT zcert_t *
82           zcert_dup (zcert_t *self);
83
84       //  Return true if two certificates have the same keys
85       CZMQ_EXPORT bool
86           zcert_eq (zcert_t *self, zcert_t *compare);
87
88       //  Print certificate contents to stdout
89       CZMQ_EXPORT void
90           zcert_print (zcert_t *self);
91
92       //  Self test of this class
93       CZMQ_EXPORT void
94           zcert_test (bool verbose);
95
96       #ifdef CZMQ_BUILD_DRAFT_API
97       //  *** Draft method, for development use, may change without warning ***
98       //  Unset certificate metadata.
99       CZMQ_EXPORT void
100           zcert_unset_meta (zcert_t *self, const char *name);
101
102       #endif // CZMQ_BUILD_DRAFT_API
103       Please add '@interface' section in './../src/zcert.c'.
104

DESCRIPTION

106       The zcert class provides a way to create and work with security
107       certificates for the ZMQ CURVE mechanism. A certificate contains a
108       public + secret key pair, plus metadata. It can be used as a temporary
109       object in memory, or persisted to disk. On disk, a certificate is
110       stored as two files. One is public and contains only the public key.
111       The second is secret and contains both keys. The two have the same
112       filename, with the secret file adding "_secret". To exchange
113       certificates, send the public file via some secure route. Certificates
114       are not signed but are text files that can be verified by eye.
115
116       Certificates are stored in the ZPL (ZMQ RFC 4) format. They have two
117       sections, "metadata" and "curve". The first contains a list of name =
118       value pairs, one per line. Values may be enclosed in quotes. The curve
119       section has a public-key = keyvalue and, for secret certificates, a
120       secret-key = keyvalue line. The keyvalue is a Z85-encoded CURVE key.
121

EXAMPLE

123       From zcert_test method.
124
125           //  Create temporary directory for test files
126           #   define TESTDIR ".test_zcert"
127           zsys_dir_create (TESTDIR);
128
129           //  Create a simple certificate with metadata
130           zcert_t *cert = zcert_new ();
131           assert (cert);
132           zcert_set_meta (cert, "email", "ph@imatix.com");
133           zcert_set_meta (cert, "name", "Pieter Hintjens");
134           zcert_set_meta (cert, "organization", "iMatix Corporation");
135           zcert_set_meta (cert, "version", "%d", 1);
136           zcert_set_meta (cert, "delete_me", "now");
137           zcert_unset_meta (cert, "delete_me");
138           assert (streq (zcert_meta (cert, "email"), "ph@imatix.com"));
139           zlist_t *keys = zcert_meta_keys (cert);
140           assert (zlist_size (keys) == 4);
141           zlist_destroy (&keys);
142
143           //  Check the dup and eq methods
144           zcert_t *shadow = zcert_dup (cert);
145           assert (zcert_eq (cert, shadow));
146           zcert_destroy (&shadow);
147
148           //  Check we can save and load certificate
149           zcert_save (cert, TESTDIR "/mycert.txt");
150           assert (zsys_file_exists (TESTDIR "/mycert.txt"));
151           assert (zsys_file_exists (TESTDIR "/mycert.txt_secret"));
152
153           //  Load certificate, will in fact load secret one
154           shadow = zcert_load (TESTDIR "/mycert.txt");
155           assert (shadow);
156           assert (zcert_eq (cert, shadow));
157           zcert_destroy (&shadow);
158
159           //  Delete secret certificate, load public one
160           int rc = zsys_file_delete (TESTDIR "/mycert.txt_secret");
161           assert (rc == 0);
162           shadow = zcert_load (TESTDIR "/mycert.txt");
163
164           //  32-byte null key encodes as 40 '0' characters
165           assert (streq (zcert_secret_txt (shadow), FORTY_ZEROES));
166
167           zcert_destroy (&shadow);
168           zcert_destroy (&cert);
169
170           //  Delete all test files
171           zdir_t *dir = zdir_new (TESTDIR, NULL);
172           assert (dir);
173           zdir_remove (dir, true);
174           zdir_destroy (&dir);
175
176

AUTHORS

178       The czmq manual was written by the authors in the AUTHORS file.
179

RESOURCES

181       Main web site:
182
183       Report bugs to the email <zeromq-dev@lists.zeromq.org[1]>
184
186       Copyright (c) the Contributors as noted in the AUTHORS file. This file
187       is part of CZMQ, the high-level C binding for 0MQ:
188       http://czmq.zeromq.org. This Source Code Form is subject to the terms
189       of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
190       distributed with this file, You can obtain one at
191       http://mozilla.org/MPL/2.0/. LICENSE included with the czmq
192       distribution.
193

NOTES

195        1. zeromq-dev@lists.zeromq.org
196           mailto:zeromq-dev@lists.zeromq.org
197
198
199
200CZMQ 4.0.2                        12/31/2016                          ZCERT(3)
Impressum