libcouchbase 1.2.8 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -4
  3. data/README.md +16 -8
  4. data/ext/libcouchbase/CMakeLists.txt +34 -32
  5. data/ext/libcouchbase/RELEASE_NOTES.markdown +277 -6
  6. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +14 -0
  7. data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibevent.cmake +2 -0
  8. data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibuv.cmake +2 -1
  9. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +2 -0
  10. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +8 -1
  11. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  12. data/ext/libcouchbase/cmake/config-cmake.h.in +14 -0
  13. data/ext/libcouchbase/cmake/configure +8 -26
  14. data/ext/libcouchbase/cmake/defs.mk.in +2 -2
  15. data/ext/libcouchbase/cmake/libcouchbase.stp.in +829 -0
  16. data/ext/libcouchbase/cmake/source_files.cmake +11 -2
  17. data/ext/libcouchbase/contrib/cbsasl/CMakeLists.txt +18 -2
  18. data/ext/libcouchbase/contrib/cbsasl/include/cbsasl/cbsasl.h +44 -2
  19. data/ext/libcouchbase/contrib/cbsasl/src/client.c +285 -73
  20. data/ext/libcouchbase/contrib/cbsasl/src/common.c +4 -0
  21. data/ext/libcouchbase/contrib/cbsasl/src/scram-sha/scram_utils.c +500 -0
  22. data/ext/libcouchbase/contrib/cbsasl/src/scram-sha/scram_utils.h +99 -0
  23. data/ext/libcouchbase/contrib/cliopts/CMakeLists.txt +1 -1
  24. data/ext/libcouchbase/contrib/cliopts/cliopts.h +14 -1
  25. data/ext/libcouchbase/contrib/snappy/CMakeLists.txt +2 -3
  26. data/ext/libcouchbase/contrib/snappy/snappy-sinksource.cc +4 -0
  27. data/ext/libcouchbase/contrib/snappy/snappy-stubs-public.h +7 -5
  28. data/ext/libcouchbase/contrib/snappy/snappy.cc +7 -2
  29. data/ext/libcouchbase/example/crypto/.gitignore +2 -0
  30. data/ext/libcouchbase/example/crypto/Makefile +13 -0
  31. data/ext/libcouchbase/example/crypto/common_provider.c +24 -0
  32. data/ext/libcouchbase/example/crypto/common_provider.h +31 -0
  33. data/ext/libcouchbase/example/crypto/openssl_symmetric_decrypt.c +139 -0
  34. data/ext/libcouchbase/example/crypto/openssl_symmetric_encrypt.c +147 -0
  35. data/ext/libcouchbase/example/crypto/openssl_symmetric_provider.c +281 -0
  36. data/ext/libcouchbase/example/crypto/openssl_symmetric_provider.h +29 -0
  37. data/ext/libcouchbase/example/tracing/.gitignore +2 -0
  38. data/ext/libcouchbase/example/tracing/Makefile +8 -0
  39. data/ext/libcouchbase/example/tracing/cJSON.c +1 -0
  40. data/ext/libcouchbase/example/tracing/cJSON.h +1 -0
  41. data/ext/libcouchbase/example/tracing/tracing.c +439 -0
  42. data/ext/libcouchbase/example/tracing/views.c +444 -0
  43. data/ext/libcouchbase/include/libcouchbase/auth.h +56 -4
  44. data/ext/libcouchbase/include/libcouchbase/cbft.h +8 -0
  45. data/ext/libcouchbase/include/libcouchbase/cntl-private.h +55 -1
  46. data/ext/libcouchbase/include/libcouchbase/cntl.h +101 -1
  47. data/ext/libcouchbase/include/libcouchbase/configuration.h.in +6 -0
  48. data/ext/libcouchbase/include/libcouchbase/couchbase.h +109 -6
  49. data/ext/libcouchbase/include/libcouchbase/crypto.h +140 -0
  50. data/ext/libcouchbase/include/libcouchbase/error.h +38 -2
  51. data/ext/libcouchbase/include/libcouchbase/kvbuf.h +6 -1
  52. data/ext/libcouchbase/include/libcouchbase/metrics.h +79 -0
  53. data/ext/libcouchbase/include/libcouchbase/n1ql.h +9 -0
  54. data/ext/libcouchbase/include/libcouchbase/tracing.h +319 -0
  55. data/ext/libcouchbase/include/libcouchbase/vbucket.h +1 -1
  56. data/ext/libcouchbase/include/libcouchbase/views.h +8 -0
  57. data/ext/libcouchbase/include/memcached/protocol_binary.h +40 -10
  58. data/ext/libcouchbase/packaging/rpm/libcouchbase.spec.in +6 -14
  59. data/ext/libcouchbase/plugins/io/libuv/plugin-internal.h +3 -0
  60. data/ext/libcouchbase/plugins/io/libuv/plugin-libuv.c +1 -0
  61. data/ext/libcouchbase/plugins/io/select/plugin-select.c +4 -1
  62. data/ext/libcouchbase/src/auth-priv.h +36 -4
  63. data/ext/libcouchbase/src/auth.cc +66 -27
  64. data/ext/libcouchbase/src/bootstrap.cc +1 -1
  65. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +12 -7
  66. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +26 -17
  67. data/ext/libcouchbase/src/bucketconfig/bc_http.h +1 -1
  68. data/ext/libcouchbase/src/bucketconfig/clconfig.h +4 -2
  69. data/ext/libcouchbase/src/bucketconfig/confmon.cc +6 -3
  70. data/ext/libcouchbase/src/cbft.cc +48 -0
  71. data/ext/libcouchbase/src/cntl.cc +138 -2
  72. data/ext/libcouchbase/src/config_static.h +17 -0
  73. data/ext/libcouchbase/src/connspec.cc +54 -6
  74. data/ext/libcouchbase/src/connspec.h +9 -1
  75. data/ext/libcouchbase/src/crypto.cc +386 -0
  76. data/ext/libcouchbase/src/ctx-log-inl.h +23 -6
  77. data/ext/libcouchbase/src/dump.cc +4 -0
  78. data/ext/libcouchbase/src/getconfig.cc +1 -2
  79. data/ext/libcouchbase/src/handler.cc +65 -27
  80. data/ext/libcouchbase/src/hostlist.cc +35 -7
  81. data/ext/libcouchbase/src/hostlist.h +7 -0
  82. data/ext/libcouchbase/src/http/http-priv.h +2 -0
  83. data/ext/libcouchbase/src/http/http.cc +77 -37
  84. data/ext/libcouchbase/src/http/http_io.cc +19 -2
  85. data/ext/libcouchbase/src/instance.cc +90 -17
  86. data/ext/libcouchbase/src/internal.h +5 -0
  87. data/ext/libcouchbase/src/lcbio/connect.cc +39 -4
  88. data/ext/libcouchbase/src/lcbio/connect.h +27 -0
  89. data/ext/libcouchbase/src/lcbio/ctx.c +49 -23
  90. data/ext/libcouchbase/src/lcbio/ioutils.cc +30 -3
  91. data/ext/libcouchbase/src/lcbio/ioutils.h +2 -0
  92. data/ext/libcouchbase/src/lcbio/manager.cc +44 -8
  93. data/ext/libcouchbase/src/lcbio/manager.h +2 -0
  94. data/ext/libcouchbase/src/lcbio/rw-inl.h +1 -0
  95. data/ext/libcouchbase/src/lcbio/ssl.h +3 -5
  96. data/ext/libcouchbase/src/logging.c +1 -1
  97. data/ext/libcouchbase/src/logging.h +2 -0
  98. data/ext/libcouchbase/src/mc/compress.cc +164 -0
  99. data/ext/libcouchbase/src/mc/compress.h +7 -12
  100. data/ext/libcouchbase/src/mc/mcreq-flush-inl.h +5 -1
  101. data/ext/libcouchbase/src/mc/mcreq.c +11 -1
  102. data/ext/libcouchbase/src/mc/mcreq.h +35 -4
  103. data/ext/libcouchbase/src/mcserver/mcserver.cc +30 -7
  104. data/ext/libcouchbase/src/mcserver/mcserver.h +7 -0
  105. data/ext/libcouchbase/src/mcserver/negotiate.cc +103 -57
  106. data/ext/libcouchbase/src/mcserver/negotiate.h +2 -2
  107. data/ext/libcouchbase/src/mctx-helper.h +11 -0
  108. data/ext/libcouchbase/src/metrics.cc +132 -0
  109. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +2 -1
  110. data/ext/libcouchbase/src/n1ql/n1ql.cc +66 -0
  111. data/ext/libcouchbase/src/newconfig.cc +9 -2
  112. data/ext/libcouchbase/src/operations/counter.cc +2 -1
  113. data/ext/libcouchbase/src/operations/durability-cas.cc +11 -0
  114. data/ext/libcouchbase/src/operations/durability-seqno.cc +3 -0
  115. data/ext/libcouchbase/src/operations/durability.cc +24 -2
  116. data/ext/libcouchbase/src/operations/durability_internal.h +19 -0
  117. data/ext/libcouchbase/src/operations/get.cc +4 -2
  118. data/ext/libcouchbase/src/operations/observe-seqno.cc +1 -0
  119. data/ext/libcouchbase/src/operations/observe.cc +113 -62
  120. data/ext/libcouchbase/src/operations/ping.cc +246 -67
  121. data/ext/libcouchbase/src/operations/remove.cc +2 -1
  122. data/ext/libcouchbase/src/operations/store.cc +17 -14
  123. data/ext/libcouchbase/src/operations/touch.cc +3 -0
  124. data/ext/libcouchbase/src/packetutils.h +68 -4
  125. data/ext/libcouchbase/src/probes.d +132 -161
  126. data/ext/libcouchbase/src/rdb/bigalloc.c +1 -1
  127. data/ext/libcouchbase/src/retryq.cc +6 -2
  128. data/ext/libcouchbase/src/rnd.cc +68 -0
  129. data/ext/libcouchbase/src/rnd.h +39 -0
  130. data/ext/libcouchbase/src/settings.c +27 -0
  131. data/ext/libcouchbase/src/settings.h +67 -3
  132. data/ext/libcouchbase/src/ssl/CMakeLists.txt +0 -12
  133. data/ext/libcouchbase/src/ssl/ssl_common.c +23 -4
  134. data/ext/libcouchbase/src/strcodecs/base64.c +141 -16
  135. data/ext/libcouchbase/src/strcodecs/strcodecs.h +16 -1
  136. data/ext/libcouchbase/src/trace.h +68 -61
  137. data/ext/libcouchbase/src/tracing/span.cc +289 -0
  138. data/ext/libcouchbase/src/tracing/threshold_logging_tracer.cc +171 -0
  139. data/ext/libcouchbase/src/tracing/tracer.cc +53 -0
  140. data/ext/libcouchbase/src/tracing/tracing-internal.h +213 -0
  141. data/ext/libcouchbase/src/utilities.c +5 -0
  142. data/ext/libcouchbase/src/vbucket/CMakeLists.txt +2 -2
  143. data/ext/libcouchbase/src/vbucket/vbucket.c +50 -18
  144. data/ext/libcouchbase/src/views/docreq.cc +26 -1
  145. data/ext/libcouchbase/src/views/docreq.h +17 -0
  146. data/ext/libcouchbase/src/views/viewreq.cc +64 -1
  147. data/ext/libcouchbase/src/views/viewreq.h +21 -0
  148. data/ext/libcouchbase/tests/CMakeLists.txt +6 -6
  149. data/ext/libcouchbase/tests/basic/t_base64.cc +34 -6
  150. data/ext/libcouchbase/tests/basic/t_connstr.cc +14 -0
  151. data/ext/libcouchbase/tests/basic/t_creds.cc +10 -10
  152. data/ext/libcouchbase/tests/basic/t_host.cc +22 -2
  153. data/ext/libcouchbase/tests/basic/t_scram.cc +514 -0
  154. data/ext/libcouchbase/tests/check-all.cc +6 -2
  155. data/ext/libcouchbase/tests/iotests/mock-environment.cc +64 -0
  156. data/ext/libcouchbase/tests/iotests/mock-environment.h +27 -1
  157. data/ext/libcouchbase/tests/iotests/t_confmon.cc +2 -2
  158. data/ext/libcouchbase/tests/iotests/t_forward.cc +8 -0
  159. data/ext/libcouchbase/tests/iotests/t_netfail.cc +124 -0
  160. data/ext/libcouchbase/tests/iotests/t_smoke.cc +1 -1
  161. data/ext/libcouchbase/tests/iotests/t_snappy.cc +316 -0
  162. data/ext/libcouchbase/tests/socktests/socktest.cc +2 -2
  163. data/ext/libcouchbase/tests/socktests/t_basic.cc +6 -6
  164. data/ext/libcouchbase/tests/socktests/t_manager.cc +1 -1
  165. data/ext/libcouchbase/tests/socktests/t_ssl.cc +1 -1
  166. data/ext/libcouchbase/tools/CMakeLists.txt +1 -1
  167. data/ext/libcouchbase/tools/cbc-handlers.h +17 -0
  168. data/ext/libcouchbase/tools/cbc-n1qlback.cc +7 -4
  169. data/ext/libcouchbase/tools/cbc-pillowfight.cc +408 -100
  170. data/ext/libcouchbase/tools/cbc-proxy.cc +134 -3
  171. data/ext/libcouchbase/tools/cbc-subdoc.cc +1 -2
  172. data/ext/libcouchbase/tools/cbc.cc +113 -8
  173. data/ext/libcouchbase/tools/common/histogram.cc +1 -0
  174. data/ext/libcouchbase/tools/common/options.cc +28 -1
  175. data/ext/libcouchbase/tools/common/options.h +5 -0
  176. data/ext/libcouchbase/tools/docgen/docgen.h +36 -10
  177. data/ext/libcouchbase/tools/docgen/loc.h +5 -4
  178. data/ext/libcouchbase/tools/docgen/seqgen.h +28 -0
  179. data/lib/libcouchbase/ext/libcouchbase/enums.rb +10 -0
  180. data/lib/libcouchbase/n1ql.rb +6 -1
  181. data/lib/libcouchbase/version.rb +1 -1
  182. data/spec/connection_spec.rb +6 -6
  183. metadata +38 -5
  184. data/ext/libcouchbase/cmake/Modules/FindCouchbaseSnappy.cmake +0 -11
  185. data/ext/libcouchbase/src/mc/compress.c +0 -90
  186. data/ext/libcouchbase/tools/common/my_inttypes.h +0 -22
@@ -0,0 +1,99 @@
1
+ /*
2
+ * Copyright 2018 Couchbase, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
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 OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #ifndef SRC_SCRAM_SHA_SCRAM_UILS_H_
18
+ #define SRC_SCRAM_SHA_SCRAM_UILS_H_
19
+
20
+ #include <stddef.h>
21
+ #include "cbsasl/cbsasl.h"
22
+
23
+ #ifdef __cplusplus
24
+ extern "C" {
25
+ #endif
26
+
27
+ /**
28
+ * Ensures the seed for OpenSSL's RAND_bytes function is correctly filled.
29
+ * Please note: as we use it only for the generation of the client nonce,
30
+ * we don't need a strong entropy.
31
+ */
32
+ void seed_rand(void);
33
+
34
+ /**
35
+ * Generates a binary nonce of 'buffer_length' bytes at the given buffer address.
36
+ * The buffer must be already allocated with enough space in it.
37
+ */
38
+ void generate_nonce(char *buffer, int buffer_length);
39
+
40
+ /**
41
+ * Computes the number of comma (',') and equal ('=') characters in the input string
42
+ * for further substitution.
43
+ * If return value is negative, it means the buffer contains an invalid (control) character.
44
+ */
45
+ int compute_special_chars(const char *buffer, int buffer_length);
46
+
47
+ /**
48
+ * Copies 'n' bytes from 'src' to 'dest', replacing comma and equal characters by their
49
+ * substitution strings in the destination.
50
+ */
51
+ void usernmcpy(char *dest, const char *src, size_t n);
52
+
53
+ /**
54
+ * Parses the server's first reply to extract the nonce, the salt and the iteration count.
55
+ */
56
+ cbsasl_error_t parse_server_challenge(const char *serverin, unsigned int serverinlen, const char **nonce,
57
+ unsigned int *noncelength, const char **salt, unsigned int *saltlength,
58
+ unsigned int *itcount);
59
+
60
+ /**
61
+ * Generates the salted password.
62
+ */
63
+ cbsasl_error_t generate_salted_password(cbsasl_auth_mechanism_t auth_mech, const cbsasl_secret_t *passwd,
64
+ const char *salt, unsigned int saltlen, unsigned int itcount,
65
+ unsigned char *outbuffer, unsigned int *outlength);
66
+
67
+ /**
68
+ * Computes the client proof. It is computed as:
69
+ *
70
+ * ClientKey := HMAC(SaltedPassword, "Client Key")
71
+ * StoredKey := H(ClientKey)
72
+ * AuthMessage := client-first-message-bare + "," +
73
+ * server-first-message + "," +
74
+ * client-final-message-without-proof
75
+ * ClientSignature := HMAC(StoredKey, AuthMessage)
76
+ * ClientProof := ClientKey XOR ClientSignature
77
+ */
78
+ cbsasl_error_t compute_client_proof(cbsasl_auth_mechanism_t auth_mech, const unsigned char *saltedpassword,
79
+ unsigned int saltedpasslen, const char *clientfirstbare, unsigned int cfblen,
80
+ const char *serverfirstmess, unsigned int sfmlen,
81
+ const char *clientfinalwithoutproof, unsigned int cfwplen, char **authmessage,
82
+ char *outclientproof, unsigned int outprooflen);
83
+
84
+ /**
85
+ * Computes the Server Signature. It is computed as:
86
+ *
87
+ * SaltedPassword := Hi(Normalize(password), salt, i)
88
+ * ServerKey := HMAC(SaltedPassword, "Server Key")
89
+ * ServerSignature := HMAC(ServerKey, AuthMessage)
90
+ */
91
+ cbsasl_error_t compute_server_signature(cbsasl_auth_mechanism_t auth_mech, const unsigned char *saltedpassword,
92
+ unsigned int saltedpasslen, const char *authmessage, char *outserversign,
93
+ unsigned int outsignlen);
94
+
95
+ #ifdef __cplusplus
96
+ }
97
+ #endif
98
+
99
+ #endif /* SRC_SCRAM_SHA_SCRAM_UILS_H_ */
@@ -1,2 +1,2 @@
1
1
  ADD_LIBRARY(cliopts OBJECT cliopts.c)
2
- SET_TARGET_PROPERTIES(cbsasl PROPERTIES COMPILE_FLAGS "${LCB_CORE_CFLAGS}")
2
+ SET_TARGET_PROPERTIES(cbsasl-lcb PROPERTIES COMPILE_FLAGS "${LCB_CORE_CFLAGS}")
@@ -222,7 +222,20 @@ public:
222
222
  bool passed() const { return found != 0; }
223
223
  void setPassed(bool val = true) { found = val ? 1 : 0; }
224
224
  int numSpecified() const { return found; }
225
- Option() { memset(this, 0, sizeof (cliopts_entry)); }
225
+
226
+ Option()
227
+ {
228
+ kshort = 0;
229
+ klong = NULL;
230
+ ktype = CLIOPTS_ARGT_NONE;
231
+ dest = NULL;
232
+ help = NULL;
233
+ vdesc = NULL;
234
+ required = 0;
235
+ hidden = 0;
236
+ found = 0;
237
+ }
238
+
226
239
  private:
227
240
  friend class Parser;
228
241
  };
@@ -1,8 +1,7 @@
1
- PROJECT(lcbsnappy)
2
1
  FILE(GLOB SNAPPY_SRC *.cc)
3
- ADD_LIBRARY(lcbsnappy STATIC ${SNAPPY_SRC})
2
+ ADD_LIBRARY(lcb_snappy OBJECT ${SNAPPY_SRC})
4
3
 
5
- SET_TARGET_PROPERTIES(lcbsnappy
4
+ SET_TARGET_PROPERTIES(lcb_snappy
6
5
  PROPERTIES
7
6
  POSITION_INDEPENDENT_CODE TRUE
8
7
  COMPILE_FLAGS "${LCB_CORE_CXXFLAGS}")
@@ -1,3 +1,7 @@
1
+ #if defined(__clang__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
2
+ #pragma GCC diagnostic ignored "-Wunused-parameter"
3
+ #endif
4
+
1
5
  // Copyright 2011 Google Inc. All Rights Reserved.
2
6
  //
3
7
  // Redistribution and use in source and binary forms, with or without
@@ -36,15 +36,17 @@
36
36
  #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
37
37
  #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
38
38
 
39
- #if 1
39
+ #include "config.h"
40
+
41
+ #ifdef HAVE_STDINT_H
40
42
  #include <stdint.h>
41
43
  #endif
42
44
 
43
- #if 1
45
+ #ifdef HAVE_STDDEF_H
44
46
  #include <stddef.h>
45
47
  #endif
46
48
 
47
- #if 0
49
+ #ifdef HAVE_SYS_UIO_H
48
50
  #include <sys/uio.h>
49
51
  #endif
50
52
 
@@ -58,7 +60,7 @@
58
60
 
59
61
  namespace snappy {
60
62
 
61
- #if 1
63
+ #ifdef HAVE_STDINT_H
62
64
  typedef int8_t int8;
63
65
  typedef uint8_t uint8;
64
66
  typedef int16_t int16;
@@ -84,7 +86,7 @@ typedef std::string string;
84
86
  TypeName(const TypeName&); \
85
87
  void operator=(const TypeName&)
86
88
 
87
- #if !0
89
+ #ifndef HAVE_SYS_UIO_H
88
90
  // Windows does not have an iovec type, yet the concept is universally useful.
89
91
  // It is simple to define it ourselves, so we put it inside our own namespace.
90
92
  struct iovec {
@@ -1,3 +1,9 @@
1
+ #if defined(__clang__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
2
+ #pragma GCC diagnostic ignored "-Wunused-parameter"
3
+ #pragma GCC diagnostic ignored "-Wunused-function"
4
+ #pragma GCC diagnostic ignored "-Wsign-compare"
5
+ #endif
6
+
1
7
  // Copyright 2005 Google Inc. All Rights Reserved.
2
8
  //
3
9
  // Redistribution and use in source and binary forms, with or without
@@ -26,10 +32,10 @@
26
32
  // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
33
  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
34
 
35
+ #include "snappy-lcb-msvc.h" // Added by libcouchbase
29
36
  #include "snappy.h"
30
37
  #include "snappy-internal.h"
31
38
  #include "snappy-sinksource.h"
32
- #include "snappy-lcb-msvc.h" // Added by libcouchbase
33
39
 
34
40
  #include <stdio.h>
35
41
 
@@ -1304,4 +1310,3 @@ size_t Compress(const char* input, size_t input_length, string* compressed) {
1304
1310
 
1305
1311
 
1306
1312
  } // end namespace snappy
1307
-
@@ -0,0 +1,2 @@
1
+ openssl_symmetric_decrypt
2
+ openssl_symmetric_encrypt
@@ -0,0 +1,13 @@
1
+ LDFLAGS=-lcouchbase -lm
2
+ CFLAGS=-g
3
+
4
+ OPENSSL_LDFLAGS=$(shell pkg-config --libs openssl) ${LDFLAGS}
5
+ OPENSSL_CFLAGS=$(shell pkg-config --cflags openssl) ${CFLAGS}
6
+
7
+ all: openssl_symmetric_encrypt openssl_symmetric_decrypt
8
+
9
+ openssl_symmetric_encrypt: openssl_symmetric_encrypt.c openssl_symmetric_provider.c common_provider.c
10
+ ${CC} ${OPENSSL_CFLAGS} ${OPENSSL_LDFLAGS} -o $@ $^
11
+
12
+ openssl_symmetric_decrypt: openssl_symmetric_decrypt.c openssl_symmetric_provider.c common_provider.c
13
+ ${CC} ${OPENSSL_CFLAGS} ${OPENSSL_LDFLAGS} -o $@ $^
@@ -0,0 +1,24 @@
1
+ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2018 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #include "common_provider.h"
19
+
20
+ uint8_t *common_hmac_sha256_key = "myauthpassword";
21
+
22
+ uint8_t common_aes256_key[AES256_KEY_SIZE] = "!mysecretkey#9^5usdk39d&dlf)03sL";
23
+ uint8_t common_aes256_iv[AES256_IV_SIZE] = {0x65, 0xe7, 0x66, 0xbe, 0x35, 0xb2, 0xd2, 0x52,
24
+ 0x2b, 0x2e, 0x7e, 0x8e, 0x99, 0x9, 0x8d, 0xa9};
@@ -0,0 +1,31 @@
1
+ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2018 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #ifndef _COMMON_PROVIDER_H
19
+ #define _COMMON_PROVIDER_H
20
+
21
+ #include <libcouchbase/couchbase.h>
22
+
23
+ #define AES256_KEY_SIZE 32
24
+ #define AES256_IV_SIZE 16
25
+
26
+ extern uint8_t common_aes256_key[AES256_KEY_SIZE];
27
+ extern uint8_t common_aes256_iv[AES256_IV_SIZE];
28
+
29
+ extern uint8_t *common_hmac_sha256_key;
30
+
31
+ #endif
@@ -0,0 +1,139 @@
1
+ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2018 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #include <stdio.h>
19
+ #include <libcouchbase/couchbase.h>
20
+ #include <libcouchbase/crypto.h>
21
+ #include <stdlib.h>
22
+ #include <string.h> /* strlen */
23
+ #ifdef _WIN32
24
+ #define PRIx64 "I64x"
25
+ #else
26
+ #include <inttypes.h>
27
+ #endif
28
+
29
+ #include "openssl_symmetric_provider.h"
30
+
31
+ static void die(lcb_t instance, const char *msg, lcb_error_t err)
32
+ {
33
+ fprintf(stderr, "%s. Received code 0x%X (%s)\n", msg, err, lcb_strerror(instance, err));
34
+ exit(EXIT_FAILURE);
35
+ }
36
+
37
+ static void op_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
38
+ {
39
+ if (rb->rc == LCB_SUCCESS) {
40
+ const lcb_RESPGET *rg = (const lcb_RESPGET *)rb;
41
+ lcbcrypto_CMDDECRYPT dcmd = {};
42
+ lcb_error_t err;
43
+
44
+ printf("VALUE: %.*s\n", (int)rg->nvalue, rg->value);
45
+ dcmd.version = 0;
46
+ dcmd.prefix = NULL;
47
+ dcmd.doc = rg->value;
48
+ dcmd.ndoc = rg->nvalue;
49
+ dcmd.out = NULL;
50
+ dcmd.nout = 0;
51
+ err = lcbcrypto_decrypt_fields(instance, &dcmd);
52
+ if (err != LCB_SUCCESS) {
53
+ die(instance, "Couldn't decrypt field 'message'", err);
54
+ }
55
+ if (dcmd.out == NULL) {
56
+ die(instance, "Crypto provider returned success, but document is NULL", LCB_EINVAL);
57
+ }
58
+ /* chop trailing LF for nicer look */
59
+ if (dcmd.out[dcmd.nout - 1] == '\n') {
60
+ dcmd.out[dcmd.nout - 1] = ' ';
61
+ }
62
+ printf("PLAIN: %.*s\n", (int)dcmd.nout, dcmd.out);
63
+ free(dcmd.out); // NOTE: it should be compatible with what providers use to allocate memory
64
+ printf("CAS: 0x%" PRIx64 "\n", rb->cas);
65
+ } else {
66
+ die(instance, lcb_strcbtype(cbtype), rb->rc);
67
+ }
68
+ }
69
+
70
+ static void get_encrypted(lcb_t instance, const char *key)
71
+ {
72
+ lcb_CMDGET cmd = {};
73
+ lcb_error_t err;
74
+ LCB_CMD_SET_KEY(&cmd, key, strlen(key));
75
+ printf("KEY: %s\n", key);
76
+ err = lcb_get3(instance, NULL, &cmd);
77
+ if (err != LCB_SUCCESS) {
78
+ die(instance, "Couldn't schedule get operation", err);
79
+ }
80
+ lcb_wait(instance);
81
+ }
82
+
83
+ int main(int argc, char *argv[])
84
+ {
85
+ lcb_error_t err;
86
+ lcb_t instance;
87
+
88
+ {
89
+ struct lcb_create_st create_options = {};
90
+ create_options.version = 3;
91
+
92
+ if (argc < 2) {
93
+ fprintf(stderr, "Usage: %s couchbase://host/bucket [ password [ username ] ]\n", argv[0]);
94
+ exit(EXIT_FAILURE);
95
+ }
96
+
97
+ create_options.v.v3.connstr = argv[1];
98
+ if (argc > 2) {
99
+ create_options.v.v3.passwd = argv[2];
100
+ }
101
+ if (argc > 3) {
102
+ create_options.v.v3.username = argv[3];
103
+ }
104
+
105
+ err = lcb_create(&instance, &create_options);
106
+ if (err != LCB_SUCCESS) {
107
+ die(NULL, "Couldn't create couchbase handle", err);
108
+ }
109
+
110
+ err = lcb_connect(instance);
111
+ if (err != LCB_SUCCESS) {
112
+ die(instance, "Couldn't schedule connection", err);
113
+ }
114
+
115
+ lcb_wait(instance);
116
+
117
+ err = lcb_get_bootstrap_status(instance);
118
+ if (err != LCB_SUCCESS) {
119
+ die(instance, "Couldn't bootstrap from cluster", err);
120
+ }
121
+
122
+ lcb_install_callback3(instance, LCB_CALLBACK_GET, op_callback);
123
+ }
124
+
125
+ lcbcrypto_register(instance, "AES-256-HMAC-SHA256", osp_create());
126
+
127
+ get_encrypted(instance, "secret-1");
128
+ printf("\n");
129
+ get_encrypted(instance, "secret-2");
130
+ printf("\n");
131
+ get_encrypted(instance, "secret-3");
132
+ printf("\n");
133
+ get_encrypted(instance, "secret-4");
134
+ printf("\n");
135
+ get_encrypted(instance, "secret-5");
136
+
137
+ lcb_destroy(instance);
138
+ return 0;
139
+ }
@@ -0,0 +1,147 @@
1
+ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2018 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #include <stdio.h>
19
+ #include <libcouchbase/couchbase.h>
20
+ #include <libcouchbase/crypto.h>
21
+ #include <stdlib.h>
22
+ #include <string.h> /* strlen */
23
+ #ifdef _WIN32
24
+ #define PRIx64 "I64x"
25
+ #else
26
+ #include <inttypes.h>
27
+ #endif
28
+
29
+ #include "openssl_symmetric_provider.h"
30
+
31
+ static void die(lcb_t instance, const char *msg, lcb_error_t err)
32
+ {
33
+ fprintf(stderr, "%s. Received code 0x%X (%s)\n", msg, err, lcb_strerror(instance, err));
34
+ exit(EXIT_FAILURE);
35
+ }
36
+
37
+ static void op_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
38
+ {
39
+ if (rb->rc == LCB_SUCCESS) {
40
+ fprintf(stderr, "CAS: 0x%" PRIx64 "\n", rb->cas);
41
+ } else {
42
+ die(instance, lcb_strcbtype(cbtype), rb->rc);
43
+ }
44
+ }
45
+
46
+ static void store_encrypted(lcb_t instance, const char *key, const char *val)
47
+ {
48
+ lcb_error_t err;
49
+ lcb_CMDSTORE cmd = {};
50
+ lcbcrypto_CMDENCRYPT ecmd = {};
51
+ lcbcrypto_FIELDSPEC field = {};
52
+
53
+ printf("KEY: %s\n", key);
54
+ printf("PLAIN: %s\n", val);
55
+
56
+ ecmd.version = 0;
57
+ ecmd.prefix = NULL;
58
+ ecmd.doc = val;
59
+ ecmd.ndoc = strlen(val);
60
+ ecmd.out = NULL;
61
+ ecmd.nout = 0;
62
+ ecmd.nfields = 1;
63
+ ecmd.fields = &field;
64
+ field.name = "message";
65
+ field.alg = "AES-256-HMAC-SHA256";
66
+ field.kid = "mypublickey";
67
+
68
+ err = lcbcrypto_encrypt_fields(instance, &ecmd);
69
+ if (err != LCB_SUCCESS) {
70
+ die(instance, "Couldn't encrypt field 'message'", err);
71
+ }
72
+ /* chop trailing LF for nicer look */
73
+ if (ecmd.out[ecmd.nout - 1] == '\n') {
74
+ ecmd.out[ecmd.nout - 1] = ' ';
75
+ }
76
+ printf("CIPHER: %s\n", ecmd.out);
77
+
78
+ LCB_CMD_SET_KEY(&cmd, key, strlen(key));
79
+ LCB_CMD_SET_VALUE(&cmd, ecmd.out, ecmd.nout);
80
+ cmd.operation = LCB_SET;
81
+ cmd.datatype = LCB_DATATYPE_JSON;
82
+
83
+ err = lcb_store3(instance, NULL, &cmd);
84
+ free(ecmd.out); // NOTE: it should be compatible with what providers use to allocate memory
85
+ if (err != LCB_SUCCESS) {
86
+ die(instance, "Couldn't schedule storage operation", err);
87
+ }
88
+ lcb_wait(instance);
89
+ }
90
+
91
+ int main(int argc, char *argv[])
92
+ {
93
+ lcb_error_t err;
94
+ lcb_t instance;
95
+
96
+ {
97
+ struct lcb_create_st create_options = {};
98
+ create_options.version = 3;
99
+
100
+ if (argc < 2) {
101
+ fprintf(stderr, "Usage: %s couchbase://host/bucket [ password [ username ] ]\n", argv[0]);
102
+ exit(EXIT_FAILURE);
103
+ }
104
+
105
+ create_options.v.v3.connstr = argv[1];
106
+ if (argc > 2) {
107
+ create_options.v.v3.passwd = argv[2];
108
+ }
109
+ if (argc > 3) {
110
+ create_options.v.v3.username = argv[3];
111
+ }
112
+
113
+ err = lcb_create(&instance, &create_options);
114
+ if (err != LCB_SUCCESS) {
115
+ die(NULL, "Couldn't create couchbase handle", err);
116
+ }
117
+
118
+ err = lcb_connect(instance);
119
+ if (err != LCB_SUCCESS) {
120
+ die(instance, "Couldn't schedule connection", err);
121
+ }
122
+
123
+ lcb_wait(instance);
124
+
125
+ err = lcb_get_bootstrap_status(instance);
126
+ if (err != LCB_SUCCESS) {
127
+ die(instance, "Couldn't bootstrap from cluster", err);
128
+ }
129
+
130
+ lcb_install_callback3(instance, LCB_CALLBACK_STORE, op_callback);
131
+ }
132
+
133
+ lcbcrypto_register(instance, "AES-256-HMAC-SHA256", osp_create());
134
+
135
+ store_encrypted(instance, "secret-1", "{\"message\":\"The old grey goose jumped over the wrickety gate.\"}");
136
+ printf("\n");
137
+ store_encrypted(instance, "secret-2", "{\"message\":10}");
138
+ printf("\n");
139
+ store_encrypted(instance, "secret-3", "{\"message\":\"10\"}");
140
+ printf("\n");
141
+ store_encrypted(instance, "secret-4", "{\"message\":[\"The\",\"Old\",\"Grey\",\"Goose\",\"Jumped\",\"over\",\"the\",\"wrickety\",\"gate\"]}");
142
+ printf("\n");
143
+ store_encrypted(instance, "secret-5", "{\"message\":{\"myValue\":\"The old grey goose jumped over the wrickety gate.\",\"myInt\":10}}");
144
+
145
+ lcb_destroy(instance);
146
+ return 0;
147
+ }