100-polarssl_compat.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. --- a/src/openvpn/ssl_polarssl.h
  2. +++ b/src/openvpn/ssl_polarssl.h
  3. @@ -38,6 +38,8 @@
  4. #include <polarssl/pkcs11.h>
  5. #endif
  6. +#include <polarssl/compat-1.2.h>
  7. +
  8. typedef struct _buffer_entry buffer_entry;
  9. struct _buffer_entry {
  10. --- a/src/openvpn/ssl_polarssl.c
  11. +++ b/src/openvpn/ssl_polarssl.c
  12. @@ -46,7 +46,7 @@
  13. #include "manage.h"
  14. #include "ssl_common.h"
  15. -#include <polarssl/sha2.h>
  16. +#include <polarssl/sha256.h>
  17. #include <polarssl/havege.h>
  18. #include "ssl_verify_polarssl.h"
  19. @@ -212,13 +212,13 @@ tls_ctx_load_dh_params (struct tls_root_
  20. {
  21. if (!strcmp (dh_file, INLINE_FILE_TAG) && dh_inline)
  22. {
  23. - if (0 != x509parse_dhm(ctx->dhm_ctx, (const unsigned char *) dh_inline,
  24. + if (0 != dhm_parse_dhm(ctx->dhm_ctx, (const unsigned char *) dh_inline,
  25. strlen(dh_inline)))
  26. msg (M_FATAL, "Cannot read inline DH parameters");
  27. }
  28. else
  29. {
  30. - if (0 != x509parse_dhmfile(ctx->dhm_ctx, dh_file))
  31. + if (0 != dhm_parse_dhmfile(ctx->dhm_ctx, dh_file))
  32. msg (M_FATAL, "Cannot read DH parameters from file %s", dh_file);
  33. }
  34. @@ -253,13 +253,13 @@ tls_ctx_load_cert_file (struct tls_root_
  35. if (!strcmp (cert_file, INLINE_FILE_TAG) && cert_inline)
  36. {
  37. - if (0 != x509parse_crt(ctx->crt_chain,
  38. + if (0 != x509_crt_parse(ctx->crt_chain,
  39. (const unsigned char *) cert_inline, strlen(cert_inline)))
  40. msg (M_FATAL, "Cannot load inline certificate file");
  41. }
  42. else
  43. {
  44. - if (0 != x509parse_crtfile(ctx->crt_chain, cert_file))
  45. + if (0 != x509_crt_parse_file(ctx->crt_chain, cert_file))
  46. msg (M_FATAL, "Cannot load certificate file %s", cert_file);
  47. }
  48. }
  49. @@ -277,7 +277,7 @@ tls_ctx_load_priv_file (struct tls_root_
  50. status = x509parse_key(ctx->priv_key,
  51. (const unsigned char *) priv_key_inline, strlen(priv_key_inline),
  52. NULL, 0);
  53. - if (POLARSSL_ERR_X509_PASSWORD_REQUIRED == status)
  54. + if (POLARSSL_ERR_PK_PASSWORD_REQUIRED == status)
  55. {
  56. char passbuf[512] = {0};
  57. pem_password_callback(passbuf, 512, 0, NULL);
  58. @@ -289,7 +289,7 @@ tls_ctx_load_priv_file (struct tls_root_
  59. else
  60. {
  61. status = x509parse_keyfile(ctx->priv_key, priv_key_file, NULL);
  62. - if (POLARSSL_ERR_X509_PASSWORD_REQUIRED == status)
  63. + if (POLARSSL_ERR_PK_PASSWORD_REQUIRED == status)
  64. {
  65. char passbuf[512] = {0};
  66. pem_password_callback(passbuf, 512, 0, NULL);
  67. @@ -480,14 +480,14 @@ void tls_ctx_load_ca (struct tls_root_ct
  68. if (ca_file && !strcmp (ca_file, INLINE_FILE_TAG) && ca_inline)
  69. {
  70. - if (0 != x509parse_crt(ctx->ca_chain, (const unsigned char *) ca_inline,
  71. + if (0 != x509_crt_parse(ctx->ca_chain, (const unsigned char *) ca_inline,
  72. strlen(ca_inline)))
  73. msg (M_FATAL, "Cannot load inline CA certificates");
  74. }
  75. else
  76. {
  77. /* Load CA file for verifying peer supplied certificate */
  78. - if (0 != x509parse_crtfile(ctx->ca_chain, ca_file))
  79. + if (0 != x509_crt_parse_file(ctx->ca_chain, ca_file))
  80. msg (M_FATAL, "Cannot load CA certificate file %s", ca_file);
  81. }
  82. }
  83. @@ -501,14 +501,14 @@ tls_ctx_load_extra_certs (struct tls_roo
  84. if (!strcmp (extra_certs_file, INLINE_FILE_TAG) && extra_certs_inline)
  85. {
  86. - if (0 != x509parse_crt(ctx->crt_chain,
  87. + if (0 != x509_crt_parse(ctx->crt_chain,
  88. (const unsigned char *) extra_certs_inline,
  89. strlen(extra_certs_inline)))
  90. msg (M_FATAL, "Cannot load inline extra-certs file");
  91. }
  92. else
  93. {
  94. - if (0 != x509parse_crtfile(ctx->crt_chain, extra_certs_file))
  95. + if (0 != x509_crt_parse_file(ctx->crt_chain, extra_certs_file))
  96. msg (M_FATAL, "Cannot load extra-certs file: %s", extra_certs_file);
  97. }
  98. }
  99. @@ -724,7 +724,7 @@ void key_state_ssl_init(struct key_state
  100. external_key_len );
  101. else
  102. #endif
  103. - ssl_set_own_cert( ks_ssl->ctx, ssl_ctx->crt_chain, ssl_ctx->priv_key );
  104. + ssl_set_own_cert_rsa( ks_ssl->ctx, ssl_ctx->crt_chain, ssl_ctx->priv_key );
  105. /* Initialise SSL verification */
  106. #if P2MP_SERVER
  107. @@ -1068,7 +1068,7 @@ print_details (struct key_state_ssl * ks
  108. cert = ssl_get_peer_cert(ks_ssl->ctx);
  109. if (cert != NULL)
  110. {
  111. - openvpn_snprintf (s2, sizeof (s2), ", " counter_format " bit RSA", (counter_type) cert->rsa.len * 8);
  112. + openvpn_snprintf (s2, sizeof (s2), ", " counter_format " bit RSA", (counter_type) pk_rsa(cert->pk)->len * 8);
  113. }
  114. msg (D_HANDSHAKE, "%s%s", s1, s2);
  115. --- a/src/openvpn/crypto_polarssl.c
  116. +++ b/src/openvpn/crypto_polarssl.c
  117. @@ -487,7 +487,12 @@ cipher_ctx_get_cipher_kt (const cipher_c
  118. int cipher_ctx_reset (cipher_context_t *ctx, uint8_t *iv_buf)
  119. {
  120. - return 0 == cipher_reset(ctx, iv_buf);
  121. + int retval = cipher_reset(ctx);
  122. +
  123. + if (0 == retval)
  124. + cipher_set_iv(ctx, iv_buf, ctx->cipher_info->iv_size);
  125. +
  126. + return 0 == retval;
  127. }
  128. int cipher_ctx_update (cipher_context_t *ctx, uint8_t *dst, int *dst_len,
  129. --- a/src/openvpn/ssl_verify_polarssl.h
  130. +++ b/src/openvpn/ssl_verify_polarssl.h
  131. @@ -34,6 +34,7 @@
  132. #include "misc.h"
  133. #include "manage.h"
  134. #include <polarssl/x509.h>
  135. +#include <polarssl/compat-1.2.h>
  136. #ifndef __OPENVPN_X509_CERT_T_DECLARED
  137. #define __OPENVPN_X509_CERT_T_DECLARED
  138. --- a/src/openvpn/ssl_verify_polarssl.c
  139. +++ b/src/openvpn/ssl_verify_polarssl.c
  140. @@ -40,6 +40,7 @@
  141. #include "ssl_verify.h"
  142. #include <polarssl/error.h>
  143. #include <polarssl/bignum.h>
  144. +#include <polarssl/oid.h>
  145. #include <polarssl/sha1.h>
  146. #define MAX_SUBJECT_LENGTH 256
  147. @@ -102,7 +103,7 @@ x509_get_username (char *cn, int cn_len,
  148. /* Find common name */
  149. while( name != NULL )
  150. {
  151. - if( memcmp( name->oid.p, OID_CN, OID_SIZE(OID_CN) ) == 0)
  152. + if( memcmp( name->oid.p, OID_AT_CN, OID_SIZE(OID_AT_CN) ) == 0)
  153. break;
  154. name = name->next;
  155. @@ -224,60 +225,18 @@ x509_setenv (struct env_set *es, int cer
  156. while( name != NULL )
  157. {
  158. char name_expand[64+8];
  159. + const char *shortname;
  160. - if( name->oid.len == 2 && memcmp( name->oid.p, OID_X520, 2 ) == 0 )
  161. + if( 0 == oid_get_attr_short_name(&name->oid, &shortname) )
  162. {
  163. - switch( name->oid.p[2] )
  164. - {
  165. - case X520_COMMON_NAME:
  166. - openvpn_snprintf (name_expand, sizeof(name_expand), "X509_%d_CN",
  167. - cert_depth); break;
  168. -
  169. - case X520_COUNTRY:
  170. - openvpn_snprintf (name_expand, sizeof(name_expand), "X509_%d_C",
  171. - cert_depth); break;
  172. -
  173. - case X520_LOCALITY:
  174. - openvpn_snprintf (name_expand, sizeof(name_expand), "X509_%d_L",
  175. - cert_depth); break;
  176. -
  177. - case X520_STATE:
  178. - openvpn_snprintf (name_expand, sizeof(name_expand), "X509_%d_ST",
  179. - cert_depth); break;
  180. -
  181. - case X520_ORGANIZATION:
  182. - openvpn_snprintf (name_expand, sizeof(name_expand), "X509_%d_O",
  183. - cert_depth); break;
  184. -
  185. - case X520_ORG_UNIT:
  186. - openvpn_snprintf (name_expand, sizeof(name_expand), "X509_%d_OU",
  187. - cert_depth); break;
  188. -
  189. - default:
  190. - openvpn_snprintf (name_expand, sizeof(name_expand),
  191. - "X509_%d_0x%02X", cert_depth, name->oid.p[2]);
  192. - break;
  193. - }
  194. + openvpn_snprintf (name_expand, sizeof(name_expand), "X509_%d_%s",
  195. + cert_depth, shortname);
  196. + }
  197. + else
  198. + {
  199. + openvpn_snprintf (name_expand, sizeof(name_expand), "X509_%d_\?\?",
  200. + cert_depth);
  201. }
  202. - else if( name->oid.len == 8 && memcmp( name->oid.p, OID_PKCS9, 8 ) == 0 )
  203. - {
  204. - switch( name->oid.p[8] )
  205. - {
  206. - case PKCS9_EMAIL:
  207. - openvpn_snprintf (name_expand, sizeof(name_expand),
  208. - "X509_%d_emailAddress", cert_depth); break;
  209. -
  210. - default:
  211. - openvpn_snprintf (name_expand, sizeof(name_expand),
  212. - "X509_%d_0x%02X", cert_depth, name->oid.p[8]);
  213. - break;
  214. - }
  215. - }
  216. - else
  217. - {
  218. - openvpn_snprintf (name_expand, sizeof(name_expand), "X509_%d_\?\?",
  219. - cert_depth);
  220. - }
  221. for( i = 0; i < name->val.len; i++ )
  222. {
  223. --- a/configure.ac
  224. +++ b/configure.ac
  225. @@ -832,13 +832,13 @@ if test "${with_crypto_library}" = "pola
  226. #include <polarssl/version.h>
  227. ]],
  228. [[
  229. -#if POLARSSL_VERSION_NUMBER < 0x01020A00 || POLARSSL_VERSION_NUMBER >= 0x01030000
  230. +#if POLARSSL_VERSION_NUMBER < 0x01030000
  231. #error invalid version
  232. #endif
  233. ]]
  234. )],
  235. [AC_MSG_RESULT([ok])],
  236. - [AC_MSG_ERROR([PolarSSL 1.2.x required and must be 1.2.10 or later])]
  237. + [AC_MSG_ERROR([PolarSSL 1.3.x required])]
  238. )
  239. polarssl_with_pkcs11="no"