ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Loading...
Searching...
No Matches
secure.h
Go to the documentation of this file.
1// Copyright (C) 2010-2014 David Sugar, Tycho Softworks.
2// Copyright (C) 2015 Cherokees of Idaho.
3//
4// This file is part of GNU uCommon C++.
5//
6// GNU uCommon C++ is free software: you can redistribute it and/or modify
7// it under the terms of the GNU Lesser General Public License as published
8// by the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// GNU uCommon C++ is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
18
19/**
20 * This library holds basic cryptographic functions and secure socket support
21 * for use with GNU uCommon C++. This library might be used in conjunction
22 * with openssl, gnutls, etc. If no secure socket library is available, then
23 * a stub library may be used with very basic cryptographic support.
24 * @file ucommon/secure.h
25 */
26
27/**
28 * Example of SSL socket code.
29 * @example ssl.cpp
30 */
31
32/**
33 * Example of cryptographic digest code.
34 * @example digest.cpp
35 */
36
37/**
38 * Example of cipher code.
39 * @example cipher.cpp
40 */
41
42#ifndef _UCOMMON_SECURE_H_
43#define _UCOMMON_SECURE_H_
44
45#ifndef _UCOMMON_CONFIG_H_
46#include <ucommon/platform.h>
47#endif
48
49#ifndef _UCOMMON_UCOMMON_H_
50#include <ucommon/ucommon.h>
51#endif
52
53#define MAX_CIPHER_KEYSIZE 512
54#define MAX_DIGEST_HASHSIZE 512
55
56namespace ucommon {
57
59{
60private:
62
63protected:
64 size_t size;
65 void *pointer;
66
67 AutoClear(size_t alloc);
68
69public:
70 virtual ~AutoClear();
71};
72
73template<typename T>
74class autoclear : public AutoClear
75{
76private:
78
79public:
80 autoclear() : AutoClear(sizeof(T)) {};
81
82 inline operator T() {
83 return *(static_cast<T*>(pointer));
84 }
85
86 inline T& operator*() {
87 return *(static_cast<T*>(pointer));
88 }
89
90 inline T* operator->() {
91 return static_cast<T*>(pointer);
92 }
93};
94
95template <>
96class autoclear<char *> : public AutoClear
97{
98private:
100
101public:
102 autoclear(size_t len) : AutoClear(len) {};
103
104 inline char *operator*() {
105 return (char *)pointer;
106 }
107};
108
109template <>
110class autoclear<uint8_t *> : public AutoClear
111{
112private:
114
115public:
116 autoclear(size_t len) : AutoClear(len) {};
117
118 inline char *operator*() {
119 return (char *)pointer;
120 }
121};
122
123/**
124 * Common secure socket support. This offers common routines needed for
125 * secure/ssl socket support code.
126 * @author David Sugar <dyfet@gnutelephony.org>
127 */
129{
130public:
131 /**
132 * Different error states of the security context.
133 */
134 typedef enum {OK=0, INVALID, MISSING_CERTIFICATE, MISSING_PRIVATEKEY, INVALID_CERTIFICATE, INVALID_AUTHORITY, INVALID_PEERNAME, INVALID_CIPHER} error_t;
135
136 typedef enum {NONE, SIGNED, VERIFIED} verify_t;
137
139
141
142private:
144
145protected:
146 /**
147 * Last error flagged for this context.
148 */
150
151 inline secure() {error = OK;}
152
153public:
154 /**
155 * This is derived in different back-end libraries, and will be used to
156 * clear certificate credentials.
157 */
158 virtual ~secure();
159
160 /**
161 * Convenience type to represent a security context.
162 */
163 typedef secure *client_t;
164
165 typedef secure *server_t;
166
167 /**
168 * Convenience type to represent a secure socket session.
169 */
170 typedef void *session_t;
171
172 /**
173 * Convenience type to represent a ssl certificate object.
174 */
175 typedef void *cert_t;
176
177 /**
178 * Convenience type to represent a secure socket buf i/o stream.
179 */
180 typedef void *bufio_t;
181
182 /**
183 * Initialize secure stack for first use, and report if SSL support is
184 * compiled in.
185 * @return true if ssl support is available, false if not.
186 */
187 static bool init(void);
188
189 /**
190 * Initialize secure stack with fips support. If fips support is not
191 * successfully enabled, the secure stack is also not initialized. Hence
192 * init() can be used for non-fips certified operation if fips fails.
193 * @return true if fips support enabled and stack initialized.
194 */
195 static bool fips(void);
196
197 /**
198 * Copy system certificates to a local path.
199 * @param path to copy to.
200 * @return 0 or error number on failure.
201 */
202 static int oscerts(const char *path);
203
204 /**
205 * Get path to system certificates.
206 * @return path to system certificates.
207 */
208 static const char *oscerts(void);
209
210 /**
211 * Create a sever context. The certificate file used will be based on
212 * the init() method name. This may often be /etc/ssl/certs/initname.pem.
213 * Similarly, a matching private key certificate will also be loaded. An
214 * optional certificate authority document can be used when we are
215 * establishing a service which ssl clients have their own certificates.
216 * @param authority path to use or NULL if none.
217 * @return a security context that is cast from derived library.
218 */
219 static server_t server(const char *keyfile = NULL, const char *authority = NULL);
220
221 /**
222 * Create an anonymous client context with an optional authority to
223 * validate.
224 * @param authority path to use or NULL if none.
225 * @param paths of certificates to use.
226 * @return a basic client security context.
227 */
228 static client_t client(const char *authority = NULL, const char *paths = NULL);
229
230 /**
231 * Create a peer user client context. This assumes a user certificate
232 * in ~/.ssl/certs and the user private key in ~/.ssl/private. The
233 * path to an authority is also sent.
234 * @param authority path to use.
235 */
236 static client_t user(const char *authority);
237
238 /**
239 * Assign a non-default cipher to the context.
240 * @param context to set cipher for.
241 * @param ciphers to set.
242 */
243 static void cipher(secure *context, const char *ciphers);
244
245 /**
246 * Determine if the current security context is valid.
247 * @return true if valid, -1 if not.
248 */
249 inline bool is_valid(void) const {
250 return error == OK;
251 };
252
253 /**
254 * Get last error code associated with the security context.
255 * @return last error code or 0/OK if none.
256 */
257 inline error_t err(void) const {
258 return error;
259 };
260
261 /**
262 * Create 36 character traditional version 1 uuid.
263 * @param string to write uuid into, must be 37 bytes or more.
264 */
265 static void uuid(char *string);
266
267 static secure::string pass(const char *prompt, size_t size);
268
269 static secure::string uuid(void);
270
271 inline operator bool() const {
272 return is_valid();
273 }
274
275 inline bool operator!() const {
276 return !is_valid();
277 }
278};
279
280/**
281 * A generic data ciphering class. This is used to construct cryptographic
282 * ciphers to encode and decode data as needed. The cipher type is specified
283 * by the key object. This class can be used to send output streaming to
284 * memory or in a fixed size buffer. If the latter is used, a push() method
285 * is called through a virtual when the buffer is full. Since block ciphers
286 * are used, buffers should be aligned to the block size.
287 * @author David Sugar <dyfet@gnutelephony.org>
288 */
290{
291public:
292 typedef enum {ENCRYPT = 1, DECRYPT = 0} mode_t;
293
294 /**
295 * Cipher key formed by hash algorithm. This can generate both a
296 * key and iv table based on the algorithms used and required. Normally
297 * it is used from a pass-phrase, though any block of data may be
298 * supplied.
299 * @author David Sugar <dyfet@gnutelephony.org>
300 */
302 {
303 protected:
304 friend class Cipher;
305
306 union {
307 const void *algotype;
309 };
310
311 union {
312 const void *hashtype;
314 };
315
317
318 // assume 512 bit cipher keys possible...
319 uint8_t keybuf[MAX_CIPHER_KEYSIZE / 8], ivbuf[MAX_CIPHER_KEYSIZE / 8];
320
321 // generated keysize
322 size_t keysize, blksize;
323
324 Key(const char *ciper);
325
326 void set(const char *cipher);
327
328 public:
329 Key();
330
331 Key(const char *cipher, const char *digest, const char *text, size_t size = 0, const uint8_t *salt = NULL, unsigned rounds = 1);
332
333 Key(const char *cipher, const uint8_t *iv, size_t ivsize);
334
335 Key(const char *cipher, secure::keybytes& iv);
336
337 Key(const char *cipher, const char *digest);
338
339 ~Key();
340
341 void set(const uint8_t *key, size_t size);
342
344 return secure::keybytes(keybuf, keysize);
345 }
346
348 return secure::keybytes(ivbuf, blksize);
349 }
350
351 bool set(const secure::keybytes& key);
352
353 void set(const char *cipher, const char *digest);
354
355 void set(const char *cipher, const uint8_t *iv, size_t ivsize);
356
357 void assign(const char *key, size_t size, const uint8_t *salt, unsigned rounds);
358
359 bool set(const char *cipher, const secure::keybytes& iv);
360
361 void assign(const char *key, size_t size = 0);
362
363 void clear(void);
364
365 secure::string b64(void);
366
367 void b64(const char *string);
368
369 size_t get(uint8_t *key, uint8_t *ivout = NULL);
370
371 inline size_t size(void) const {
372 return keysize;
373 }
374
375 inline size_t iosize(void) const {
376 return blksize;
377 }
378
379 inline operator bool() const {
380 return keysize > 0;
381 }
382
383 inline bool operator!() const {
384 return keysize == 0;
385 }
386
387 inline Key& operator=(const char *pass) {
388 assign(pass);
389 return *this;
390 }
391
392 bool operator==(const Key& other) const;
393
394 inline bool operator!=(const Key& other) const {
395 return !operator==(other);
396 }
397
398 static void options(const uint8_t *salt = NULL, unsigned rounds = 1);
399 };
400
401 typedef Key *key_t;
402
403private:
405 size_t bufsize, bufpos;
407 uint8_t *bufaddr;
408 void *context;
409
411
412protected:
413 virtual void push(uint8_t *address, size_t size);
414
415 void release(void);
416
417public:
418 Cipher();
419
420 Cipher(const key_t key, mode_t mode, uint8_t *address = NULL, size_t size = 0);
421
422 virtual ~Cipher();
423
424 void set(uint8_t *address, size_t size = 0);
425
426 void set(const key_t key, mode_t mode, uint8_t *address, size_t size = 0);
427
429 return keys.iv();
430 }
431
433 return keys.key();
434 }
435
436 /**
437 * Push a final cipher block. This is used to push the final buffer into
438 * the push method for any remaining data.
439 */
440 size_t flush(void);
441
442 /**
443 * Process cipher data. This requires the size to be a multiple of the
444 * cipher block size. If an unaligned sized block of data is used, it
445 * will be ignored and the size returned will be 0.
446 * @param data to process.
447 * @param size of data to process.
448 * @return size of processed output, should be same as size or 0 if error.
449 */
450 size_t put(const uint8_t *data, size_t size);
451
452 /**
453 * This essentially encrypts a single string and pads with NULL bytes
454 * as needed.
455 * @param string to encrypt.
456 * @return total encrypted size.
457 */
458 size_t puts(const char *string);
459
460 /**
461 * This is used to process any data unaligned to the blocksize at the end
462 * of a cipher session. On an encryption, it will add padding or an
463 * entire padding block with the number of bytes to strip. On decryption
464 * it will remove padding at the end. The pkcs5 method of padding with
465 * removal count is used. This also sets the address buffer to NULL
466 * to prevent further puts until reset.
467 * @param address of data to add before final pad.
468 * @param size of data to add before final pad.
469 * @return actual bytes encrypted or decrypted.
470 */
471 size_t pad(const uint8_t *address, size_t size);
472
473 /**
474 * Process encrypted data in-place. This assumes no need to set the
475 * address buffer.
476 * @param address of data to process.
477 * @param size of data to process.
478 * @param flag if to pad data.
479 * @return bytes processed and written back to buffer.
480 */
481 size_t process(uint8_t *address, size_t size, bool flag = false);
482
483 inline size_t size(void) const {
484 return bufsize;
485 }
486
487 inline size_t pos(void) const {
488 return bufpos;
489 }
490
491 inline size_t align(void) const {
492 return keys.iosize();
493 }
494
495 /**
496 * Check if a specific cipher is supported.
497 * @param name of cipher to check.
498 * @return true if supported, false if not.
499 */
500 static bool has(const char *name);
501};
502
503/**
504 * A cryptographic digest class. This class can support md5 digests, sha1,
505 * sha256, etc, depending on what the underlying library supports. The
506 * hash class accumulates the hash in the object.
507 * @author David Sugar <dyfet@gnutelephony.org>
508 */
510{
511private:
512 void *context;
513
514 union {
515 const void *hashtype;
517 };
518
519 unsigned bufsize;
521 char textbuf[MAX_DIGEST_HASHSIZE / 8 + 1];
522
524
525protected:
526 void release(void);
527
528 const uint8_t *get(void);
529
530public:
531 Digest(const char *type);
532
533 Digest();
534
535 ~Digest();
536
537 inline bool puts(const char *str) {
538 return put(str, strlen(str));
539 }
540
541 inline Digest &operator<<(const char *str) {
542 puts(str);
543 return *this;
544 }
545
546 inline Digest &operator<<(int16_t value) {
547 int16_t v = htons(value);
548 put(&v, 2);
549 return *this;
550 }
551
552 inline Digest &operator<<(int32_t value) {
553 int32_t v = htonl(value);
554 put(&v, 4);
555 return *this;
556 }
557
558 inline Digest &operator<<(const PrintProtocol& p) {
559 const char *cp = p._print();
560 if(cp)
561 puts(cp);
562 return *this;
563 }
564
565 bool put(const void *memory, size_t size);
566
567 inline unsigned size() const {
568 return bufsize;
569 }
570
571 secure::keybytes key(void);
572
573 secure::string str(void);
574
575 inline operator secure::string() {
576 return str();
577 }
578
579 void set(const char *id);
580
581 inline Digest& operator=(const char *id) {
582 set(id);
583 return *this;
584 };
585
586 inline bool operator *=(const char *text) {
587 return puts(text);
588 }
589
590 inline bool operator +=(const char *text) {
591 return puts(text);
592 }
593
595 return str();
596 }
597
598 inline bool operator!() const {
599 return !bufsize && context == NULL;
600 }
601
602 inline operator bool() const {
603 return bufsize > 0 || context != NULL;
604 }
605
606 /**
607 * Finalize and recycle current digest to start a new
608 * digest.
609 * @param binary digest used rather than text if true.
610 */
611 void recycle(bool binary = false);
612
613 /**
614 * Reset and restart digest object.
615 */
616 void reset(void);
617
618 /**
619 * Test to see if a specific digest type is supported.
620 * @param name of digest we want to check.
621 * @return true if supported, false if not.
622 */
623 static bool has(const char *name);
624
625 static secure::string uuid(const char *name, const uint8_t *ns = NULL);
626
627 /**
628 * Shortcut for short md5 digests if supported...
629 * @param text to create a digest for.
630 * @return digest string.
631 */
632 static secure::string md5(const char *text);
633
634 static secure::string sha1(const char *text);
635
636 static secure::string sha256(const char *text);
637
638 static secure::string sha384(const char *text);
639
640 static secure::keybytes md5(const uint8_t *mem, size_t size);
641
642 static secure::keybytes sha1(const uint8_t *mem, size_t size);
643
644 static secure::keybytes sha256(const uint8_t *mem, size_t size);
645
646 static secure::keybytes sha384(const uint8_t *mem, size_t size);
647
648};
649
650/**
651 * A cryptographic message authentication code class. This class can support
652 * md5 digests, sha1, sha256, etc, depending on what the underlying library
653 * supports.
654 * @author David Sugar <dyfet@gnutelephony.org>
655 */
657{
658private:
659 void *context;
660
661 union {
662 const void *hmactype;
664 };
665
666 unsigned bufsize;
668 char textbuf[MAX_DIGEST_HASHSIZE / 8 + 1];
669
671
672protected:
673 void release(void);
674
675 const uint8_t *get(void);
676
677public:
678 HMAC(const char *digest, const secure::keybytes& key);
679
680 HMAC();
681
682 ~HMAC();
683
684 inline bool puts(const char *str) {
685 return put(str, strlen(str));
686 }
687
688 inline HMAC &operator<<(const char *str) {
689 puts(str);
690 return *this;
691 }
692
693 inline HMAC &operator<<(int16_t value) {
694 int16_t v = htons(value);
695 put(&v, 2);
696 return *this;
697 }
698
699 inline HMAC &operator<<(int32_t value) {
700 int32_t v = htonl(value);
701 put(&v, 4);
702 return *this;
703 }
704
705 inline HMAC &operator<<(const PrintProtocol& p) {
706 const char *cp = p._print();
707 if(cp)
708 puts(cp);
709 return *this;
710 }
711
712 bool put(const void *memory, size_t size);
713
714 inline unsigned size() const {
715 return bufsize;
716 }
717
718 secure::string str(void);
719
720 secure::keybytes key(void);
721
722 inline operator secure::string() {
723 return str();
724 }
725
726 inline bool operator *=(const char *text) {
727 return puts(text);
728 }
729
730 void set(const char *digest, const secure::keybytes& key);
731
732 inline bool operator +=(const char *text) {
733 return puts(text);
734 }
735
737 return str();
738 }
739
740 inline bool operator!() const {
741 return !bufsize && context == NULL;
742 }
743
744 inline operator bool() const {
745 return bufsize > 0 || context != NULL;
746 }
747
748 /**
749 * Test to see if a specific digest type is supported.
750 * @param name of digest we want to check.
751 * @return true if supported, false if not.
752 */
753 static bool has(const char *name);
754
755 static secure::keybytes sha256(secure::keybytes key, const uint8_t *mem, size_t size);
756
757 static secure::keybytes sha384(secure::keybytes key, const uint8_t *mem, size_t soze);
758};
759
760/**
761 * Cryptographically relevant random numbers. This is used both to gather
762 * entropy pools and pseudo-random values.
763 * @author David Sugar <dyfet@gnutelephony.org>
764 */
766{
767private:
769
770public:
771 /**
772 * Push entropic seed.
773 * @param buffer of random data to push.
774 * @param size of buffer.
775 * @return true if successful.
776 */
777 static bool seed(const uint8_t *buffer, size_t size);
778
779 /**
780 * Re-seed pseudo-random generation and entropy pools.
781 */
782 static void seed(void);
783
784 /**
785 * Get high-entropy random data. This is often used to
786 * initialize keys. This operation may block if there is
787 * insufficient entropy immediately available.
788 * @param memory buffer to fill.
789 * @param size of buffer.
790 * @return number of bytes filled.
791 */
792 static size_t key(uint8_t *memory, size_t size);
793
794 /**
795 * Fill memory with pseudo-random values. This is used
796 * as the basis for all get and real operations and does
797 * not depend on seed entropy.
798 * @param memory buffer to fill.
799 * @param size of buffer to fill.
800 * @return number of bytes set.
801 */
802 static size_t fill(uint8_t *memory, size_t size);
803
804 /**
805 * Get a pseudo-random integer, range 0 - 32767.
806 * @return random integer.
807 */
808 static int get(void);
809
810 /**
811 * Get a pseudo-random integer in a preset range.
812 * @param min value of random integer.
813 * @param max value of random integer.
814 * @return random value from min to max.
815 */
816 static int get(int min, int max);
817
818 /**
819 * Get a pseudo-random floating point value.
820 * @return psudo-random value 0 to 1.
821 */
822 static double real(void);
823
824 /**
825 * Get a pseudo-random floating point value in a preset range.
826 * @param min value of random floating point number.
827 * @param max value of random floating point number.
828 * @return random value from min to max.
829 */
830 static double real(double min, double max);
831
832 /**
833 * Determine if we have sufficient entropy to return random
834 * values.
835 * @return true if sufficient entropy.
836 */
837 static bool status(void);
838
839 /**
840 * Create 36 character random uuid string.
841 * @param string to write uuid into, must be 37 bytes or more.
842 */
843 static void uuid(char *string);
844
845 static secure::string uuid(void);
846
847 template <class T>
848 inline static T value(void) {
849 T tmp;
850 Random::key(reinterpret_cast<uint8_t *>(&tmp), sizeof(tmp));
851 return tmp;
852 }
853
854 template <class T>
855 inline static T value(T max) {
856 T slice;
857 T value;
858
859 value = 0xffffffff;
860 slice = 0xffffffff / max;
861 while(value >= max) {
862 value = Random::value<T>() / slice;
863 }
864 return value;
865 }
866
867 template <class T>
868 inline static T value(T min, T max)
869 {
870 return min + Random::value<T>(max - min);
871 }
872};
873
874
875/**
876 * Convenience type for generic digests.
877 */
879
880/**
881 * Convenience type for generic digests.
882 */
883typedef HMAC hmac_t;
884
885/**
886 * Convenience type for generic ciphers.
887 */
889
890/**
891 * Convenience type for generic cipher key.
892 */
894
895inline void zerofill(void *addr, size_t size)
896{
897 ::memset(addr, 0, size);
898}
899
900#ifndef UCOMMON_SYSRUNTIME
901
902/**
903 * Secure socket using std::iostream. Being based on tcpstream, it also
904 * inherits the character protocol. If no context is given or the handshake
905 * fails, then the stream defaults to insecure TCP connection behavior.
906 * @author David Sugar <dyfet@gnutelephony.org>
907 */
909{
910private:
912
913protected:
918 bool server;
919
920 ssize_t _write(const char *address, size_t size) __OVERRIDE;
921
922 ssize_t _read(char *address, size_t size) __OVERRIDE;
923
924 bool _wait(void) __OVERRIDE;
925
926public:
927 /**
928 * Construct a ssl client stream. The context will be loaded with
929 * relevant certificates from secure::client().
930 * @param context to use
931 */
932 sstream(secure::client_t context);
933
934 /**
935 * Construct a ssl server stream. The context will be loaded with
936 * relevant certificates from secure::server().
937 * @param server instance of tcp socket.
938 * @param context to use.
939 * @param size of streaming buffer.
940 */
941 sstream(const TCPServer *server, secure::server_t context, size_t size = 536);
942
943 /**
944 * Destroy ssl stream. Clean up any resources used.
945 */
946 ~sstream();
947
948 /**
949 * Open a connection to a ssl server.
950 * @param host name to connect with.
951 * @param service id to connect to.
952 * @param size of stream buffer to use.
953 */
954 void open(const char *host, const char *service, size_t size = 536);
955
956 /**
957 * Close a connection with a ssl server.
958 */
959 void close(void);
960
961 /**
962 * Release all ssl resources.
963 */
964 void release(void);
965
966 int sync() __OVERRIDE;
967
968 inline void flush(void) {
969 sync();
970 }
971
972 /**
973 * Get peer (x509) certificate for current stream if present.
974 * @return certificate of peer or nullptr if none.
975 */
976 inline secure::cert_t certificate(void) const {
977 return cert;
978 }
979
980 /**
981 * Check if ssl session active, otherwise pure tcp.
982 * @return true if ssl session.
983 */
984 inline bool is_secure(void) const {
985 return bio != NULL;
986 }
987
988 /**
989 * Check if a peer certificate is present.
990 * @return true if peer certificate.
991 */
992 inline bool is_certificate(void) const {
993 return cert != NULL;
994 }
995
996 /**
997 * Check if peer certificate is verified through an authority.
998 * @return true if verified peer.
999 */
1000 inline bool is_verified(void) const {
1001 return verified == secure::VERIFIED;
1002 }
1003
1004 /**
1005 * Check if peer certificate is present and at least self-signed.
1006 * @return true if signed or verified peer.
1007 */
1008 inline bool is_signed(void) const {
1009 return verified != secure::NONE;
1010 }
1011};
1012
1013#endif
1014
1015// can be specialized...
1016template<typename T>
1017void clearmem(T &var)
1018{
1019 memset(&var, 0, sizeof(var));
1020}
1021
1023
1024} // namespace ucommon
1025
1026#endif
static bool binary
Definition: car.cpp:38
static cipher_t cipher
Definition: car.cpp:42
static void process(void)
Definition: car.cpp:232
void * pointer
Definition: secure.h:65
__DELETE_DEFAULTS(AutoClear)
Cipher key formed by hash algorithm.
Definition: secure.h:302
bool operator!() const
Definition: secure.h:383
secure::keybytes iv()
Definition: secure.h:347
bool operator!=(const Key &other) const
Definition: secure.h:394
Key & operator=(const char *pass)
Definition: secure.h:387
secure::keybytes key()
Definition: secure.h:343
const void * hashtype
Definition: secure.h:312
size_t size(void) const
Definition: secure.h:371
size_t iosize(void) const
Definition: secure.h:375
const void * algotype
Definition: secure.h:307
A generic data ciphering class.
Definition: secure.h:290
mode_t bufmode
Definition: secure.h:406
Key * key_t
Definition: secure.h:401
size_t size(void) const
Definition: secure.h:483
void * context
Definition: secure.h:408
secure::keybytes key()
Definition: secure.h:432
uint8_t * bufaddr
Definition: secure.h:407
size_t pos(void) const
Definition: secure.h:487
size_t align(void) const
Definition: secure.h:491
secure::keybytes iv()
Definition: secure.h:428
size_t bufpos
Definition: secure.h:405
__DELETE_COPY(Cipher)
A cryptographic digest class.
Definition: secure.h:510
unsigned bufsize
Definition: secure.h:519
Digest & operator<<(int32_t value)
Definition: secure.h:552
unsigned size() const
Definition: secure.h:567
Digest & operator<<(const PrintProtocol &p)
Definition: secure.h:558
__DELETE_COPY(Digest)
const void * hashtype
Definition: secure.h:515
secure::string operator*()
Definition: secure.h:594
Digest & operator=(const char *id)
Definition: secure.h:581
Digest & operator<<(int16_t value)
Definition: secure.h:546
Digest & operator<<(const char *str)
Definition: secure.h:541
bool operator!() const
Definition: secure.h:598
void * context
Definition: secure.h:512
bool puts(const char *str)
Definition: secure.h:537
A cryptographic message authentication code class.
Definition: secure.h:657
bool operator!() const
Definition: secure.h:740
void * context
Definition: secure.h:659
__DELETE_COPY(HMAC)
unsigned bufsize
Definition: secure.h:666
const void * hmactype
Definition: secure.h:662
HMAC & operator<<(int32_t value)
Definition: secure.h:699
bool puts(const char *str)
Definition: secure.h:684
HMAC & operator<<(int16_t value)
Definition: secure.h:693
int hmacid
Definition: secure.h:663
secure::string operator*()
Definition: secure.h:736
unsigned size() const
Definition: secure.h:714
HMAC & operator<<(const char *str)
Definition: secure.h:688
HMAC & operator<<(const PrintProtocol &p)
Definition: secure.h:705
Used for forming stream output.
Definition: protocols.h:135
virtual const char * _print(void) const =0
Extract formatted string for object.
Cryptographically relevant random numbers.
Definition: secure.h:766
static T value(void)
Definition: secure.h:848
__DELETE_DEFAULTS(Random)
static T value(T max)
Definition: secure.h:855
static T value(T min, T max)
Definition: secure.h:868
A generic tcp server class.
Definition: socket.h:1901
T & operator*()
Definition: secure.h:86
T * operator->()
Definition: secure.h:90
__DELETE_COPY(autoclear)
Traditional keypair config file parsing class.
Definition: keydata.h:161
Generic smart pointer class.
Definition: generics.h:55
Common secure socket support.
Definition: secure.h:129
error_t error
Last error flagged for this context.
Definition: secure.h:149
void * session_t
Convenience type to represent a secure socket session.
Definition: secure.h:170
__DELETE_COPY(secure)
bool operator!() const
Definition: secure.h:275
static secure::string pass(const char *prompt, size_t size)
bool is_valid(void) const
Determine if the current security context is valid.
Definition: secure.h:249
secure * server_t
Definition: secure.h:165
static client_t user(const char *authority)
Create a peer user client context.
error_t
Different error states of the security context.
Definition: secure.h:134
void * bufio_t
Convenience type to represent a secure socket buf i/o stream.
Definition: secure.h:180
void * cert_t
Convenience type to represent a ssl certificate object.
Definition: secure.h:175
byteref< secure_release > keybytes
Definition: secure.h:140
secure * client_t
Convenience type to represent a security context.
Definition: secure.h:163
stringref< secure_release > string
Definition: secure.h:138
error_t err(void) const
Get last error code associated with the security context.
Definition: secure.h:257
Secure socket using std::iostream.
Definition: secure.h:909
secure::cert_t cert
Definition: secure.h:916
bool is_certificate(void) const
Check if a peer certificate is present.
Definition: secure.h:992
secure::bufio_t bio
Definition: secure.h:915
secure::session_t ssl
Definition: secure.h:914
secure::cert_t certificate(void) const
Get peer (x509) certificate for current stream if present.
Definition: secure.h:976
secure::verify_t verified
Definition: secure.h:917
bool is_secure(void) const
Check if ssl session active, otherwise pure tcp.
Definition: secure.h:984
bool is_signed(void) const
Check if peer certificate is present and at least self-signed.
Definition: secure.h:1008
bool is_verified(void) const
Check if peer certificate is verified through an authority.
Definition: secure.h:1000
__DELETE_COPY(sstream)
Streamable tcp connection between client and server.
Definition: stream.h:115
static void digest(const char *path=NULL)
Definition: mdsum.cpp:97
Common namespace for all ucommon objects.
Definition: access.cpp:23
T &() min(T &o1, T &o2)
Convenience function to return min of two objects.
Definition: generics.h:456
Cipher cipher_t
Convenience type for generic ciphers.
Definition: secure.h:888
T &() max(T &o1, T &o2)
Convenience function to return max of two objects.
Definition: generics.h:445
void clearmem(T &var)
Definition: secure.h:1017
Digest digest_t
Convenience type for generic digests.
Definition: secure.h:878
secure::string keystring_t
Definition: secure.h:1022
HMAC hmac_t
Convenience type for generic digests.
Definition: secure.h:883
Cipher::Key skey_t
Convenience type for generic cipher key.
Definition: secure.h:893
const struct sockaddr * addr(Socket::address &address)
A convenience function to convert a socket address list into a socket address.
Definition: socket.h:2089
T & clear(T &o)
Definition: generics.h:416
String str(Socket &so, size_t size)
Definition: socket.cpp:3507
static shell::stringopt error('e', "--error", _TEXT("stderr path to use"), "filename")
Various miscellaneous platform specific headers and defines.
#define __OVERRIDE
Definition: platform.h:158
T * init(T *memory)
Template function to initialize memory by invoking default constructor.
Definition: platform.h:551
#define __SHARED
Definition: platform.h:299
#define MAX_CIPHER_KEYSIZE
Definition: secure.h:53
#define MAX_DIGEST_HASHSIZE
Definition: secure.h:54
void sha256(unsigned char hval[], const unsigned char data[], unsigned long len)
Definition: sha2.cpp:419
void sha384(unsigned char hval[], const unsigned char data[], unsigned long len)
Definition: sha2.cpp:635
Top level include file for the GNU uCommon C++ core library.
static shell::flagopt verified('V', NULL, _TEXT("requires verification"))
static uint8_t buffer[65536]
Definition: zerofill.cpp:27
static void zerofill(void)
Definition: zerofill.cpp:40